Skip to content

Commit

Permalink
feat: configurable chain config (#255)
Browse files Browse the repository at this point in the history
  • Loading branch information
azurwastaken committed Sep 18, 2024
1 parent bccdccf commit 8be242a
Show file tree
Hide file tree
Showing 30 changed files with 883 additions and 214 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

## Next release

- feat: add config file and preset configure chain
- refactor: change default chain id and add custom flag to override
- fix: generate a fixed set of public and private keys for devnet
- fix: defaulted l1 gas price in devnet mode
Expand Down
32 changes: 32 additions & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -159,6 +159,7 @@ reqwest = { version = "0.12", features = ["json"] }
rstest = "0.18"
serde = { version = "1.0", default-features = false, features = ["std"] }
serde_json = { version = "1.0", default-features = false, features = ["std"] }
serde_yaml = { version = "0.9.34" }
thiserror = "1.0"
tokio = { version = "1.34", features = ["signal"] }
url = "2.4"
Expand Down
62 changes: 62 additions & 0 deletions config.example.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
# Name of the blockchain network
chain_name: "Starknet Mainnet"

# Unique identifier for the blockchain network
chain_id: "SN_MAIN"

# Contract address of the token used to pay transaction fees on this network (STRK)
native_fee_token_address: "0x04718f5a0fc34cc1af16a1cdee98ffb20c31f5cd61d6ab07201858f4287c938d"

# Contract address of the token used for fees on the parent chain (ETH)
parent_fee_token_address: "0x049d36570d4e46f48e99674bd3fcc84644ddd6b96f7c741b1562b82f9e004dc7"

# Paths to JSON files containing blockifier's constants for different versions
versioned_constants:
"0.13.0": "crates/primitives/chain_config/resources/versioned_constants_13_0.json"
"0.13.1": "crates/primitives/chain_config/resources/versioned_constants_13_1.json"
"0.13.1.1": "crates/primitives/chain_config/resources/versioned_constants_13_1_1.json"
"0.13.2": "crates/primitives/chain_config/resources/versioned_constants_13_2.json"

# Address of the core contract on the L1 network that interacts with this L2 network
eth_core_contract_address: "0xc662c410C0ECf747543f5bA90660f6ABeBD9C8c4"

# Most recent version supported
latest_protocol_version: "0.13.2"

# Target time interval between blocks, in seconds
block_time: 360

# How often the pending block is updated, in seconds
pending_block_update_time: 2

# Settings for the transaction bouncer
bouncer_config:
block_max_capacity:
# Limits for various built-in operations (set to max uint64 value)
builtin_count:
add_mod: 18446744073709551615
bitwise: 18446744073709551615
ecdsa: 18446744073709551615
ec_op: 18446744073709551615
keccak: 18446744073709551615
mul_mod: 18446744073709551615
pedersen: 18446744073709551615
poseidon: 18446744073709551615
range_check: 18446744073709551615
range_check96: 18446744073709551615
# Maximum gas limit per block
gas: 5000000
# Maximum number of steps per block
n_steps: 40000000
# Maximum length of message segments
message_segment_length: 18446744073709551615
# Maximum number of events per block
n_events: 18446744073709551615
# Maximum size of state differences per block
state_diff_size: 131072

# Address of the sequencer (0x0 for a full node).
sequencer_address: "0x0"

# Maximum nonce difference allowed for skipping validation of intermediate transactions
max_nonce_for_validation_skip: 2
1 change: 1 addition & 0 deletions crates/client/db/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ bincode = { workspace = true }
log = { workspace = true, default-features = true }
rayon = { workspace = true }
rocksdb.workspace = true
rstest = { workspace = true }
serde = { workspace = true }
tempfile = { workspace = true, optional = true }
thiserror = { workspace = true }
Expand Down
2 changes: 1 addition & 1 deletion crates/client/db/tests/common/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,6 @@ use tempfile::TempDir;

pub async fn temp_db() -> DatabaseService {
let temp_dir = TempDir::new().unwrap();
let chain_config = std::sync::Arc::new(ChainConfig::test_config());
let chain_config = std::sync::Arc::new(ChainConfig::test_config().expect("failed to retrieve test chain config"));
DatabaseService::new(temp_dir.path(), None, false, chain_config).await.unwrap()
}
37 changes: 25 additions & 12 deletions crates/client/db/tests/test_block.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
mod common;
use common::temp_db;

use common::*;
use mc_db::db_block_id::DbBlockIdResolvable;
use mc_db::{block_db::TxIndex, db_block_id::DbBlockId};
use mp_block::BlockId;
Expand All @@ -17,17 +18,21 @@ use mp_transactions::{
DeployAccountTransactionV3, DeployTransaction, InvokeTransactionV0, InvokeTransactionV1, InvokeTransactionV3,
L1HandlerTransaction,
};
use mp_utils::tests_common::*;
use rstest::*;
use starknet_types_core::felt::Felt;

#[rstest]
#[tokio::test]
async fn test_chain_info() {
async fn test_chain_info(_set_workdir: ()) {
let db = temp_db().await;
let chain_config = db.backend().chain_config();
assert_eq!(chain_config.chain_id, ChainConfig::test_config().chain_id);
assert_eq!(chain_config.chain_id, ChainConfig::test_config().unwrap().chain_id);
}

#[rstest]
#[tokio::test]
async fn test_block_id() {
async fn test_block_id(_set_workdir: ()) {
let db = temp_db().await;
let backend = db.backend();

Expand All @@ -43,16 +48,18 @@ async fn test_block_id() {
assert_eq!(backend.resolve_block_id(&DbBlockId::Pending).unwrap().unwrap(), DbBlockId::Pending);
}

#[rstest]
#[tokio::test]
async fn test_block_id_not_found() {
async fn test_block_id_not_found(_set_workdir: ()) {
let db = temp_db().await;
let backend = db.backend();

assert!(backend.resolve_block_id(&BlockId::Hash(Felt::from(0))).unwrap().is_none());
}

#[rstest]
#[tokio::test]
async fn test_store_block() {
async fn test_store_block(_set_workdir: ()) {
const BLOCK_ID_0: DbBlockId = DbBlockId::BlockN(0);

let db = temp_db().await;
Expand All @@ -74,8 +81,9 @@ async fn test_store_block() {
assert_eq!(backend.get_block_state_diff(&BLOCK_ID_0).unwrap().unwrap(), state_diff);
}

#[rstest]
#[tokio::test]
async fn test_store_pending_block() {
async fn test_store_pending_block(_set_workdir: ()) {
const BLOCK_ID_PENDING: DbBlockId = DbBlockId::Pending;

let db = temp_db().await;
Expand All @@ -95,8 +103,9 @@ async fn test_store_pending_block() {
assert_eq!(backend.get_block_state_diff(&BLOCK_ID_PENDING).unwrap().unwrap(), state_diff);
}

#[rstest]
#[tokio::test]
async fn test_erase_pending_block() {
async fn test_erase_pending_block(_set_workdir: ()) {
const BLOCK_ID_PENDING: DbBlockId = DbBlockId::Pending;

let db = temp_db().await;
Expand Down Expand Up @@ -126,8 +135,9 @@ async fn test_erase_pending_block() {
assert_eq!(backend.get_block_state_diff(&BLOCK_ID_PENDING).unwrap().unwrap(), state_diff);
}

#[rstest]
#[tokio::test]
async fn test_store_latest_block() {
async fn test_store_latest_block(_set_workdir: ()) {
let db = temp_db().await;
let backend = db.backend();

Expand All @@ -139,8 +149,9 @@ async fn test_store_latest_block() {
assert_eq!(backend.get_latest_block_n().unwrap().unwrap(), 1);
}

#[rstest]
#[tokio::test]
async fn test_latest_confirmed_block() {
async fn test_latest_confirmed_block(_set_workdir: ()) {
let db = temp_db().await;
let backend = db.backend();

Expand All @@ -151,8 +162,9 @@ async fn test_latest_confirmed_block() {
assert_eq!(backend.get_l1_last_confirmed_block().unwrap().unwrap(), 0);
}

#[rstest]
#[tokio::test]
async fn test_store_block_transactions() {
async fn test_store_block_transactions(_set_workdir: ()) {
let db = temp_db().await;
let backend = db.backend();

Expand All @@ -166,8 +178,9 @@ async fn test_store_block_transactions() {
assert_eq!(backend.find_tx_hash_block(&tx_hash_1).unwrap().unwrap(), (block, TxIndex(1)));
}

#[rstest]
#[tokio::test]
async fn test_store_block_transactions_pending() {
async fn test_store_block_transactions_pending(_set_workdir: ()) {
let db = temp_db().await;
let backend = db.backend();

Expand Down
16 changes: 11 additions & 5 deletions crates/client/db/tests/test_open.rs
Original file line number Diff line number Diff line change
@@ -1,21 +1,27 @@
mod common;

use common::temp_db;
use common::*;
use mc_db::DatabaseService;
use mp_chain_config::ChainConfig;
use mp_utils::tests_common::*;
use rstest::*;

#[rstest]
#[tokio::test]
async fn test_open_db() {
async fn test_open_db(_set_workdir: ()) {
temp_db().await;
}

#[rstest]
#[tokio::test]
async fn test_open_different_chain_id() {
async fn test_open_different_chain_id(_set_workdir: ()) {
let temp_dir = tempfile::TempDir::new().unwrap();
{
let chain_config = std::sync::Arc::new(ChainConfig::starknet_integration());
let chain_config = std::sync::Arc::new(
ChainConfig::starknet_integration().expect("failed to retrieve integration chain config"),
);
let _db = DatabaseService::new(temp_dir.path(), None, false, chain_config).await.unwrap();
}
let chain_config = std::sync::Arc::new(ChainConfig::test_config());
let chain_config = std::sync::Arc::new(ChainConfig::test_config().expect("failed to retrieve test chain config"));
assert!(DatabaseService::new(temp_dir.path(), None, false, chain_config).await.is_err());
}
1 change: 1 addition & 0 deletions crates/client/devnet/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ mp-convert.workspace = true
mp-receipt.workspace = true
mp-state-update.workspace = true
mp-transactions.workspace = true
mp-utils.workspace = true

# Starknet
blockifier.workspace = true
Expand Down
Loading

0 comments on commit 8be242a

Please sign in to comment.