Skip to content

Commit c18e262

Browse files
authored
Merge pull request #120 from jbcaron/chain_id
fix: 🐛 fetch chain_id from config
2 parents a9ba8cd + 8fbebe3 commit c18e262

File tree

4 files changed

+28
-7
lines changed

4 files changed

+28
-7
lines changed

CHANGELOG.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,10 +2,10 @@ git # Madara Changelog
22

33
## Next release
44

5+
- fix: update and store ConfigFetch in l2 sync(), chainId rpc call
56
- fix: get_events paging with continuation_token
67
- fux(getStorageAt): #28
78
- fix(genesis): #107
8-
99
- fix(class): #32 #33 #34
1010
- fix(class): #116
1111
- feat(class): download classes from sequencer

crates/client/deoxys/src/l2.rs

Lines changed: 23 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@ use std::sync::{Arc, Mutex};
44
use std::time::Duration;
55

66
use itertools::Itertools;
7-
use lazy_static::lazy_static;
87
use mc_storage::OverrideHandle;
98
use mp_block::state_update::StateUpdateWrapper;
109
use mp_commitments::StateCommitment;
@@ -47,6 +46,14 @@ lazy_static! {
4746
}));
4847
}
4948

49+
use lazy_static::lazy_static;
50+
51+
// TODO: find a better place to store this
52+
lazy_static! {
53+
/// Store the configuration globally
54+
static ref CONFIG: Arc<Mutex<FetchConfig>> = Arc::new(Mutex::new(FetchConfig::default()));
55+
}
56+
5057
lazy_static! {
5158
/// Shared latest block number and hash of chain
5259
pub static ref STARKNET_HIGHEST_BLOCK_HASH_AND_NUMBER: Arc<Mutex<(FieldElement, u64)>> = Arc::new(Mutex::new((FieldElement::default(), 0)));
@@ -133,6 +140,7 @@ pub async fn sync<B: BlockT>(
133140
rpc_port: u16,
134141
backend: Arc<mc_db::Backend<B>>,
135142
) {
143+
update_config(&config);
136144
let SenderConfig { block_sender, state_update_sender, class_sender, command_sink, overrides } = &mut sender_config;
137145
let client = SequencerGatewayProvider::new(config.gateway.clone(), config.feeder_gateway.clone(), config.chain_id);
138146

@@ -426,3 +434,17 @@ pub async fn verify_l2(_state_update: StateUpdateWrapper) -> Result<(), String>
426434
// update_l2({block_number, block_hash, state_commitment})
427435
Ok(())
428436
}
437+
438+
pub fn get_highest_block_hash_and_number() -> (FieldElement, u64) {
439+
STARKNET_HIGHEST_BLOCK_HASH_AND_NUMBER.lock().unwrap().clone()
440+
}
441+
442+
fn update_config(config: &FetchConfig) {
443+
let last_config = CONFIG.clone();
444+
let mut new_config = last_config.lock().unwrap();
445+
*new_config = config.clone();
446+
}
447+
448+
pub fn get_config() -> FetchConfig {
449+
CONFIG.lock().unwrap().clone()
450+
}

crates/client/rpc/src/lib.rs

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ use errors::StarknetRpcApiError;
1515
use jsonrpsee::core::{async_trait, RpcResult};
1616
use jsonrpsee::types::error::CallError;
1717
use log::error;
18+
use mc_deoxys::l2::get_config;
1819
use mc_deoxys::utility::get_highest_block_hash_and_number;
1920
use mc_genesis_data_provider::GenesisProvider;
2021
pub use mc_rpc_core::utils::*;
@@ -993,12 +994,9 @@ where
993994
/// defined by the Starknet protocol, indicating the particular network.
994995
fn chain_id(&self) -> RpcResult<Felt> {
995996
let best_block_hash = self.client.info().best_hash;
996-
let chain_id = self.client.runtime_api().chain_id(best_block_hash).map_err(|e| {
997-
error!("Failed to fetch chain_id with best_block_hash: {best_block_hash}, error: {e}");
998-
StarknetRpcApiError::InternalServerError
999-
})?;
997+
let chain_id = get_config().chain_id;
1000998

1001-
Ok(Felt(chain_id.0))
999+
Ok(Felt(chain_id))
10021000
}
10031001

10041002
/// Estimate the fee associated with transaction

crates/runtime/src/pallets.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -155,6 +155,7 @@ impl pallet_timestamp::Config for Runtime {
155155
type WeightInfo = ();
156156
}
157157

158+
// TODO: change the ChainId to the correct one which depends on the network
158159
parameter_types! {
159160
pub const UnsignedPriority: u64 = 1 << 20;
160161
pub const TransactionLongevity: u64 = u64::MAX;

0 commit comments

Comments
 (0)