Skip to content

Commit

Permalink
Merge pull request #120 from jbcaron/chain_id
Browse files Browse the repository at this point in the history
fix: 🐛 fetch chain_id from config
  • Loading branch information
antiyro authored Feb 12, 2024
2 parents a9ba8cd + 8fbebe3 commit c18e262
Show file tree
Hide file tree
Showing 4 changed files with 28 additions and 7 deletions.
2 changes: 1 addition & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,10 @@ git # Madara Changelog

## Next release

- fix: update and store ConfigFetch in l2 sync(), chainId rpc call
- fix: get_events paging with continuation_token
- fux(getStorageAt): #28
- fix(genesis): #107

- fix(class): #32 #33 #34
- fix(class): #116
- feat(class): download classes from sequencer
Expand Down
24 changes: 23 additions & 1 deletion crates/client/deoxys/src/l2.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ use std::sync::{Arc, Mutex};
use std::time::Duration;

use itertools::Itertools;
use lazy_static::lazy_static;
use mc_storage::OverrideHandle;
use mp_block::state_update::StateUpdateWrapper;
use mp_commitments::StateCommitment;
Expand Down Expand Up @@ -47,6 +46,14 @@ lazy_static! {
}));
}

use lazy_static::lazy_static;

// TODO: find a better place to store this
lazy_static! {
/// Store the configuration globally
static ref CONFIG: Arc<Mutex<FetchConfig>> = Arc::new(Mutex::new(FetchConfig::default()));
}

lazy_static! {
/// Shared latest block number and hash of chain
pub static ref STARKNET_HIGHEST_BLOCK_HASH_AND_NUMBER: Arc<Mutex<(FieldElement, u64)>> = Arc::new(Mutex::new((FieldElement::default(), 0)));
Expand Down Expand Up @@ -133,6 +140,7 @@ pub async fn sync<B: BlockT>(
rpc_port: u16,
backend: Arc<mc_db::Backend<B>>,
) {
update_config(&config);
let SenderConfig { block_sender, state_update_sender, class_sender, command_sink, overrides } = &mut sender_config;
let client = SequencerGatewayProvider::new(config.gateway.clone(), config.feeder_gateway.clone(), config.chain_id);

Expand Down Expand Up @@ -426,3 +434,17 @@ pub async fn verify_l2(_state_update: StateUpdateWrapper) -> Result<(), String>
// update_l2({block_number, block_hash, state_commitment})
Ok(())
}

pub fn get_highest_block_hash_and_number() -> (FieldElement, u64) {
STARKNET_HIGHEST_BLOCK_HASH_AND_NUMBER.lock().unwrap().clone()
}

fn update_config(config: &FetchConfig) {
let last_config = CONFIG.clone();
let mut new_config = last_config.lock().unwrap();
*new_config = config.clone();
}

pub fn get_config() -> FetchConfig {
CONFIG.lock().unwrap().clone()
}
8 changes: 3 additions & 5 deletions crates/client/rpc/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ use errors::StarknetRpcApiError;
use jsonrpsee::core::{async_trait, RpcResult};
use jsonrpsee::types::error::CallError;
use log::error;
use mc_deoxys::l2::get_config;
use mc_deoxys::utility::get_highest_block_hash_and_number;
use mc_genesis_data_provider::GenesisProvider;
pub use mc_rpc_core::utils::*;
Expand Down Expand Up @@ -993,12 +994,9 @@ where
/// defined by the Starknet protocol, indicating the particular network.
fn chain_id(&self) -> RpcResult<Felt> {
let best_block_hash = self.client.info().best_hash;
let chain_id = self.client.runtime_api().chain_id(best_block_hash).map_err(|e| {
error!("Failed to fetch chain_id with best_block_hash: {best_block_hash}, error: {e}");
StarknetRpcApiError::InternalServerError
})?;
let chain_id = get_config().chain_id;

Ok(Felt(chain_id.0))
Ok(Felt(chain_id))
}

/// Estimate the fee associated with transaction
Expand Down
1 change: 1 addition & 0 deletions crates/runtime/src/pallets.rs
Original file line number Diff line number Diff line change
Expand Up @@ -155,6 +155,7 @@ impl pallet_timestamp::Config for Runtime {
type WeightInfo = ();
}

// TODO: change the ChainId to the correct one which depends on the network
parameter_types! {
pub const UnsignedPriority: u64 = 1 << 20;
pub const TransactionLongevity: u64 = u64::MAX;
Expand Down

0 comments on commit c18e262

Please sign in to comment.