Skip to content

Commit

Permalink
chore: use chain info in stateful validator config (#99)
Browse files Browse the repository at this point in the history
  • Loading branch information
ArniStarkware authored Jul 31, 2024
1 parent 6f43f52 commit e4dd3b0
Show file tree
Hide file tree
Showing 4 changed files with 11 additions and 77 deletions.
6 changes: 3 additions & 3 deletions config/mempool/default_config.json
Original file line number Diff line number Diff line change
Expand Up @@ -24,12 +24,12 @@
"privacy": "Public",
"value": "0x0"
},
"gateway_config.stateful_tx_validator_config.chain_info.eth_fee_token_address": {
"gateway_config.stateful_tx_validator_config.chain_info.fee_token_addresses.eth_fee_token_address": {
"description": "Address of the ETH fee token.",
"privacy": "Public",
"value": "0x0"
},
"gateway_config.stateful_tx_validator_config.chain_info.strk_fee_token_address": {
"gateway_config.stateful_tx_validator_config.chain_info.fee_token_addresses.strk_fee_token_address": {
"description": "Address of the STRK fee token.",
"privacy": "Public",
"value": "0x0"
Expand Down Expand Up @@ -119,4 +119,4 @@
"privacy": "Public",
"value": ""
}
}
}
76 changes: 5 additions & 71 deletions crates/gateway/src/config.rs
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
use std::collections::BTreeMap;
use std::net::IpAddr;

use blockifier::context::{BlockContext, ChainInfo, FeeTokenAddresses};
use blockifier::context::ChainInfo;
use papyrus_config::dumping::{append_sub_config_name, ser_param, SerializeConfig};
use papyrus_config::{ParamPath, ParamPrivacyInput, SerializedParam};
use serde::{Deserialize, Serialize};
use starknet_api::core::{ChainId, ContractAddress, Nonce};
use starknet_api::core::Nonce;
use starknet_types_core::felt::Felt;
use validator::Validate;

Expand Down Expand Up @@ -174,78 +174,12 @@ impl SerializeConfig for RpcStateReaderConfig {
}
}

// TODO(Arni): Remove this struct once Chain info supports Papyrus serialization.
#[derive(Clone, Debug, Serialize, Deserialize, Validate, PartialEq)]
pub struct ChainInfoConfig {
pub chain_id: ChainId,
pub strk_fee_token_address: ContractAddress,
pub eth_fee_token_address: ContractAddress,
}

impl From<ChainInfoConfig> for ChainInfo {
fn from(chain_info: ChainInfoConfig) -> Self {
Self {
chain_id: chain_info.chain_id,
fee_token_addresses: FeeTokenAddresses {
strk_fee_token_address: chain_info.strk_fee_token_address,
eth_fee_token_address: chain_info.eth_fee_token_address,
},
}
}
}

impl From<ChainInfo> for ChainInfoConfig {
fn from(chain_info: ChainInfo) -> Self {
let FeeTokenAddresses { strk_fee_token_address, eth_fee_token_address } =
chain_info.fee_token_addresses;
Self { chain_id: chain_info.chain_id, strk_fee_token_address, eth_fee_token_address }
}
}

impl Default for ChainInfoConfig {
fn default() -> Self {
ChainInfo::default().into()
}
}

impl ChainInfoConfig {
#[cfg(any(test, feature = "testing"))]
pub fn create_for_testing() -> Self {
BlockContext::create_for_testing().chain_info().clone().into()
}
}

impl SerializeConfig for ChainInfoConfig {
fn dump(&self) -> BTreeMap<ParamPath, SerializedParam> {
BTreeMap::from_iter([
ser_param(
"chain_id",
&self.chain_id,
"The chain ID of the StarkNet chain.",
ParamPrivacyInput::Public,
),
ser_param(
"strk_fee_token_address",
&self.strk_fee_token_address,
"Address of the STRK fee token.",
ParamPrivacyInput::Public,
),
ser_param(
"eth_fee_token_address",
&self.eth_fee_token_address,
"Address of the ETH fee token.",
ParamPrivacyInput::Public,
),
])
}
}

#[derive(Clone, Debug, Serialize, Deserialize, Validate, PartialEq)]
pub struct StatefulTransactionValidatorConfig {
pub max_nonce_for_validation_skip: Nonce,
pub validate_max_n_steps: u32,
pub max_recursion_depth: usize,
pub chain_info: ChainInfoConfig,
pub chain_info: ChainInfo,
}

impl Default for StatefulTransactionValidatorConfig {
Expand All @@ -254,7 +188,7 @@ impl Default for StatefulTransactionValidatorConfig {
max_nonce_for_validation_skip: Nonce(Felt::ONE),
validate_max_n_steps: 1_000_000,
max_recursion_depth: 50,
chain_info: ChainInfoConfig::default(),
chain_info: ChainInfo::default(),
}
}
}
Expand Down Expand Up @@ -293,7 +227,7 @@ impl StatefulTransactionValidatorConfig {
max_nonce_for_validation_skip: Default::default(),
validate_max_n_steps: 1000000,
max_recursion_depth: 50,
chain_info: ChainInfoConfig::create_for_testing(),
chain_info: ChainInfo::create_for_testing(),
}
}
}
Expand Down
2 changes: 1 addition & 1 deletion crates/gateway/src/stateful_transaction_validator.rs
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,7 @@ impl StatefulTransactionValidator {
// able to read the block_hash of 10 blocks ago from papyrus.
let block_context = BlockContext::new(
block_info,
self.config.chain_info.clone().into(),
self.config.chain_info.clone(),
versioned_constants,
BouncerConfig::max(),
);
Expand Down
4 changes: 2 additions & 2 deletions crates/gateway/src/stateful_transaction_validator_test.rs
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ fn stateful_validator(block_context: BlockContext) -> StatefulTransactionValidat
max_nonce_for_validation_skip: Default::default(),
validate_max_n_steps: block_context.versioned_constants().validate_max_n_steps,
max_recursion_depth: block_context.versioned_constants().max_recursion_depth,
chain_info: block_context.chain_info().clone().into(),
chain_info: block_context.chain_info().clone(),
},
}
}
Expand Down Expand Up @@ -124,7 +124,7 @@ fn test_instantiate_validator() {
max_nonce_for_validation_skip: Default::default(),
validate_max_n_steps: block_context.versioned_constants().validate_max_n_steps,
max_recursion_depth: block_context.versioned_constants().max_recursion_depth,
chain_info: block_context.chain_info().clone().into(),
chain_info: block_context.chain_info().clone(),
},
};
let blockifier_validator = stateful_validator.instantiate_validator(&mock_state_reader_factory);
Expand Down

0 comments on commit e4dd3b0

Please sign in to comment.