Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merge Katana dev branch #1444

Merged
merged 5 commits into from
Jan 17, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
123 changes: 65 additions & 58 deletions Cargo.lock

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,7 @@ scarb = { git = "https://github.com/software-mansion/scarb", tag = "v2.4.0" }
scarb-ui = { git = "https://github.com/software-mansion/scarb", tag = "v2.4.0" }
semver = "1.0.5"
serde = { version = "1.0.192", features = [ "derive" ] }
serde_json = "1.0"
serde_json = { version = "1.0", features = [ "arbitrary_precision" ] }
serde_with = "2.3.1"
smol_str = { version = "0.2.0", features = [ "serde" ] }
sqlx = { version = "0.7.2", features = [ "chrono", "macros", "regexp", "runtime-async-std", "runtime-tokio", "sqlite", "uuid" ] }
Expand Down
1 change: 1 addition & 0 deletions crates/dojo-test-utils/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ dojo-lang = { path = "../dojo-lang" }
dojo-world = { path = "../dojo-world", features = [ "manifest", "migration" ] }
jsonrpsee = { version = "0.16.2", features = [ "server" ] }
katana-core = { path = "../katana/core" }
katana-primitives = { path = "../katana/primitives" }
katana-rpc = { path = "../katana/rpc" }
scarb-ui.workspace = true
scarb.workspace = true
Expand Down
9 changes: 7 additions & 2 deletions crates/dojo-test-utils/src/sequencer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ use jsonrpsee::core::Error;
pub use katana_core::backend::config::{Environment, StarknetConfig};
use katana_core::sequencer::KatanaSequencer;
pub use katana_core::sequencer::SequencerConfig;
use katana_primitives::chain::ChainId;
use katana_rpc::api::ApiKind;
use katana_rpc::config::ServerConfig;
use katana_rpc::{spawn, NodeHandle};
Expand All @@ -30,7 +31,11 @@ pub struct TestSequencer {

impl TestSequencer {
pub async fn start(config: SequencerConfig, starknet_config: StarknetConfig) -> Self {
let sequencer = Arc::new(KatanaSequencer::new(config, starknet_config).await);
let sequencer = Arc::new(
KatanaSequencer::new(config, starknet_config)
.await
.expect("Failed to create sequencer"),
);

let handle = spawn(
Arc::clone(&sequencer),
Expand Down Expand Up @@ -79,7 +84,7 @@ impl TestSequencer {
pub fn get_default_test_starknet_config() -> StarknetConfig {
StarknetConfig {
disable_fee: true,
env: Environment { chain_id: "SN_GOERLI".into(), ..Default::default() },
env: Environment { chain_id: ChainId::GOERLI, ..Default::default() },
..Default::default()
}
}
1 change: 1 addition & 0 deletions crates/katana/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ clap.workspace = true
clap_complete.workspace = true
console.workspace = true
katana-core = { path = "core" }
katana-primitives = { path = "primitives" }
katana-rpc = { path = "rpc" }
metrics = { path = "../metrics" }
metrics-process.workspace = true
Expand Down
2 changes: 2 additions & 0 deletions crates/katana/core/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ repository.workspace = true
version.workspace = true

[dependencies]
katana-db = { path = "../storage/db" }
katana-executor = { path = "../executor" }
katana-primitives = { path = "../primitives" }
katana-provider = { path = "../storage/provider" }
Expand Down Expand Up @@ -37,6 +38,7 @@ url.workspace = true
[dev-dependencies]
assert_matches.workspace = true
hex = "0.4.3"
tempfile = "3.8.1"

[features]
messaging = [ "ethers" ]
Expand Down
49 changes: 16 additions & 33 deletions crates/katana/core/src/backend/config.rs
Original file line number Diff line number Diff line change
@@ -1,13 +1,12 @@
use blockifier::block_context::{BlockContext, FeeTokenAddresses, GasPrices};
use starknet_api::block::{BlockNumber, BlockTimestamp};
use starknet_api::core::ChainId;
use std::path::PathBuf;

use katana_primitives::block::GasPrices;
use katana_primitives::chain::ChainId;
use katana_primitives::env::BlockEnv;
use url::Url;

use crate::constants::{
DEFAULT_GAS_PRICE, DEFAULT_INVOKE_MAX_STEPS, DEFAULT_VALIDATE_MAX_STEPS, FEE_TOKEN_ADDRESS,
SEQUENCER_ADDRESS,
};
use crate::env::{get_default_vm_resource_fee_cost, BlockContextGenerator};
use crate::constants::{DEFAULT_GAS_PRICE, DEFAULT_INVOKE_MAX_STEPS, DEFAULT_VALIDATE_MAX_STEPS};
use crate::env::BlockContextGenerator;

#[derive(Debug, Clone)]
pub struct StarknetConfig {
Expand All @@ -18,31 +17,14 @@ pub struct StarknetConfig {
pub fork_rpc_url: Option<Url>,
pub fork_block_number: Option<u64>,
pub disable_validate: bool,
pub db_dir: Option<PathBuf>,
}

impl StarknetConfig {
pub fn block_context(&self) -> BlockContext {
BlockContext {
block_number: BlockNumber::default(),
chain_id: ChainId(self.env.chain_id.clone()),
block_timestamp: BlockTimestamp::default(),
sequencer_address: (*SEQUENCER_ADDRESS).into(),
// As the fee has two currencies, we also have to adjust their addresses.
// https://github.com/starkware-libs/blockifier/blob/51b343fe38139a309a69b2482f4b484e8caa5edf/crates/blockifier/src/block_context.rs#L34
fee_token_addresses: FeeTokenAddresses {
eth_fee_token_address: (*FEE_TOKEN_ADDRESS).into(),
strk_fee_token_address: Default::default(),
},
vm_resource_fee_cost: get_default_vm_resource_fee_cost().into(),
// Gas prices are dual too.
// https://github.com/starkware-libs/blockifier/blob/51b343fe38139a309a69b2482f4b484e8caa5edf/crates/blockifier/src/block_context.rs#L49
gas_prices: GasPrices {
eth_l1_gas_price: self.env.gas_price,
strk_l1_gas_price: Default::default(),
},
validate_max_n_steps: self.env.validate_max_steps,
invoke_tx_max_n_steps: self.env.invoke_max_steps,
max_recursion_depth: 1000,
pub fn block_env(&self) -> BlockEnv {
BlockEnv {
l1_gas_prices: GasPrices { eth: self.env.gas_price, ..Default::default() },
..Default::default()
}
}

Expand All @@ -61,14 +43,15 @@ impl Default for StarknetConfig {
fork_block_number: None,
env: Environment::default(),
disable_validate: false,
db_dir: None,
}
}
}

#[derive(Debug, Clone)]
pub struct Environment {
pub chain_id: String,
pub gas_price: u128,
pub chain_id: ChainId,
pub gas_price: u64,
pub invoke_max_steps: u32,
pub validate_max_steps: u32,
}
Expand All @@ -77,7 +60,7 @@ impl Default for Environment {
fn default() -> Self {
Self {
gas_price: DEFAULT_GAS_PRICE,
chain_id: "KATANA".to_string(),
chain_id: ChainId::parse("KATANA").unwrap(),
invoke_max_steps: DEFAULT_INVOKE_MAX_STEPS,
validate_max_steps: DEFAULT_VALIDATE_MAX_STEPS,
}
Expand Down
Loading
Loading