Skip to content

Commit

Permalink
WIP: progress on issue dojoengine#2558 gas oracle feature on katana
Browse files Browse the repository at this point in the history
  • Loading branch information
augustin-v committed Dec 4, 2024
1 parent 9c974b6 commit 1a23175
Show file tree
Hide file tree
Showing 6 changed files with 29 additions and 7 deletions.
3 changes: 2 additions & 1 deletion crates/katana/cli/src/args.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ use clap::Parser;
use katana_core::constants::DEFAULT_SEQUENCER_ADDRESS;
use katana_core::service::messaging::MessagingConfig;
use katana_node::config::db::DbConfig;
use katana_node::config::dev::{DevConfig, FixedL1GasPriceConfig};
use katana_node::config::dev::{DevConfig, FixedL1GasPriceConfig, GasPriceWorkerConfig};
use katana_node::config::execution::ExecutionConfig;
use katana_node::config::fork::ForkingConfig;
use katana_node::config::metrics::MetricsConfig;
Expand Down Expand Up @@ -277,6 +277,7 @@ impl NodeArgs {
fixed_gas_prices,
fee: !self.development.no_fee,
account_validation: !self.development.no_account_validation,
l1_worker: self.gas_price_worker_config(),
}
}

Expand Down
4 changes: 3 additions & 1 deletion crates/katana/core/src/backend/gas_oracle.rs
Original file line number Diff line number Diff line change
Expand Up @@ -127,12 +127,14 @@ async fn update_gas_price<P: Provider<T>, T: Transport + Clone>(
) -> anyhow::Result<()> {
// Attempt to get the gas price from L1
let last_block_number = provider.get_block_number().await?;
<<<<<<< HEAD

=======
>>>>>>> 7c83e4d8 (WIP: progress on issue #2558 gas oracle feature on katana)
let fee_history =
provider.get_fee_history(1, BlockNumberOrTag::Number(last_block_number), &[]).await?;

let latest_gas_price = fee_history.base_fee_per_gas.last().context("Getting eth gas price")?;

buffer.add_sample(*latest_gas_price);

let blob_fee_history = fee_history.base_fee_per_blob_gas;
Expand Down
4 changes: 3 additions & 1 deletion crates/katana/core/src/backend/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ use katana_trie::compute_merkle_root;
use parking_lot::RwLock;
use starknet::macros::short_string;
use starknet_types_core::hash::{self, StarkHash};

use tracing::info;

pub mod contract;
Expand Down Expand Up @@ -117,6 +118,7 @@ impl<EF: ExecutorFactory> Backend<EF> {
pub fn update_block_gas_prices(&self, block_env: &mut BlockEnv) {
block_env.l1_gas_prices = self.gas_oracle.current_gas_prices();
block_env.l1_data_gas_prices = self.gas_oracle.current_data_gas_prices();

}

pub fn mine_empty_block(
Expand Down Expand Up @@ -278,4 +280,4 @@ where
class_trie_root,
])
}
}
}
20 changes: 19 additions & 1 deletion crates/katana/node/src/config/dev.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ use katana_core::constants::{
DEFAULT_STRK_L1_GAS_PRICE,
};
use katana_primitives::block::GasPrices;
use url::Url;

/// Development configuration.
#[derive(Debug, Clone)]
Expand Down Expand Up @@ -31,6 +32,11 @@ pub struct DevConfig {
///
/// These are the prices that will be used for calculating the gas fee for transactions.
pub fixed_gas_prices: Option<FixedL1GasPriceConfig>,

/// L1 gas oracle worker task configuration for real time gas sampling.
///
/// If sampling disabled, the system falls back to the hardcoded gas values.
pub l1_worker: Option<GasPriceWorkerConfig>,
}

/// Fixed gas prices for development.
Expand All @@ -40,6 +46,12 @@ pub struct FixedL1GasPriceConfig {
pub data_gas_price: GasPrices,
}

#[derive(Debug, Clone)]
pub struct GasPriceWorkerConfig {
pub l1_provider_url: Option<Url>,
pub no_sampling: bool,
}

impl std::default::Default for FixedL1GasPriceConfig {
fn default() -> Self {
Self {
Expand All @@ -54,6 +66,12 @@ impl std::default::Default for FixedL1GasPriceConfig {

impl std::default::Default for DevConfig {
fn default() -> Self {
Self { fee: true, account_validation: true, fixed_gas_prices: None }
Self { fee: true, account_validation: true, fixed_gas_prices: None, l1_worker: None }
}
}

impl std::default::Default for GasPriceWorkerConfig {
fn default() -> Self {
Self { l1_provider_url: None, no_sampling: true }
}
}
2 changes: 1 addition & 1 deletion crates/katana/node/src/config/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ pub mod rpc;
use std::sync::Arc;

use db::DbConfig;
use dev::DevConfig;
use dev::{DevConfig, GasPriceWorkerConfig};
use execution::ExecutionConfig;
use fork::ForkingConfig;
use katana_core::service::messaging::MessagingConfig;
Expand Down
3 changes: 1 addition & 2 deletions crates/katana/node/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ use hyper::{Method, Uri};
use jsonrpsee::server::middleware::proxy_get_request::ProxyGetRequestLayer;
use jsonrpsee::server::{AllowHosts, ServerBuilder, ServerHandle};
use jsonrpsee::RpcModule;
use katana_core::backend::gas_oracle::L1GasOracle;
use katana_core::backend::gas_oracle::{GasOracleWorker, L1GasOracle};
use katana_core::backend::storage::Blockchain;
use katana_core::backend::Backend;
use katana_core::constants::{
Expand Down Expand Up @@ -221,7 +221,6 @@ pub async fn build(mut config: Config) -> Result<Node> {
// Default to a sampled gas oracle using the given provider
L1GasOracle::sampled(config.l1_provider_url.clone())
};

let block_context_generator = BlockContextGenerator::default().into();
let backend = Arc::new(Backend {
gas_oracle,
Expand Down

0 comments on commit 1a23175

Please sign in to comment.