Skip to content

Commit

Permalink
Merge pull request #4 from chinyuchan/chinyuchan/fix/rpc/chain-id
Browse files Browse the repository at this point in the history
initialize chain id when creating evm runtime.
  • Loading branch information
chinyuchan authored May 29, 2023
2 parents 28b3641 + 8168816 commit a4c1bd2
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 1 deletion.
5 changes: 5 additions & 0 deletions crates/model/src/lazy.rs
Original file line number Diff line number Diff line change
@@ -1,8 +1,13 @@
use crate::types::Hex;
use arc_swap::ArcSwap;
use once_cell::sync::Lazy;
use std::sync::Arc;

pub static CHAIN_ID: Lazy<ArcSwap<u64>> =
Lazy::new(|| ArcSwap::from_pointee(Default::default()));
pub static PROTOCOL_VERSION: Lazy<ArcSwap<Hex>> =
Lazy::new(|| ArcSwap::from_pointee(Default::default()));

pub fn set_chain_id(id: u64) {
CHAIN_ID.store(Arc::from(id));
}
6 changes: 5 additions & 1 deletion crates/model/src/types/transaction.rs
Original file line number Diff line number Diff line change
Expand Up @@ -408,7 +408,11 @@ impl SignatureComponents {
}

pub fn extract_chain_id(v: u64) -> Option<u64> {
if v >= 35 { Some((v - 35) / 2u64) } else { None }
if v >= 35 {
Some((v - 35) / 2u64)
} else {
None
}
}

#[allow(clippy::len_without_is_empty)]
Expand Down
3 changes: 3 additions & 0 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ use model::{
types::{Basic, Block, H160, U256},
};
use once_cell::sync::Lazy;
use rt_evm_model::lazy::set_chain_id;
use ruc::*;
use std::{fs, io::ErrorKind, mem::size_of, path::PathBuf, sync::Arc};
use storage::{get_account_by_backend, save_account_by_backend, MptStore, Storage};
Expand Down Expand Up @@ -62,6 +63,8 @@ impl EvmRuntime {
#[cfg(feature = "benchmark")]
const MEM_POOL_CAP: u64 = 200_0000;

set_chain_id(chain_id);

let trie_db = Arc::new(t);
let storage = Arc::new(s);

Expand Down

0 comments on commit a4c1bd2

Please sign in to comment.