Skip to content
This repository has been archived by the owner on Feb 6, 2025. It is now read-only.

Commit

Permalink
fix: opbnb synchronization failure issue (#24)
Browse files Browse the repository at this point in the history
  • Loading branch information
j75689 authored Jun 3, 2024
1 parent b0189bd commit a4d7ef5
Show file tree
Hide file tree
Showing 7 changed files with 63 additions and 57 deletions.
8 changes: 4 additions & 4 deletions Cargo.lock

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

6 changes: 3 additions & 3 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -401,6 +401,6 @@ similar-asserts = "1.5.0"
test-fuzz = "5"

[patch.crates-io]
revm = { git = "https://github.com/bnb-chain/revm.git", rev = "4be2578" }
revm-primitives = { git = "https://github.com/bnb-chain/revm.git", rev = "4be2578" }
alloy-chains = { git = "https://github.com/alloy-rs/chains.git", rev = "906d6fb" }
revm = { git = "https://github.com/bnb-chain/revm.git", rev = "deb253b" }
revm-primitives = { git = "https://github.com/bnb-chain/revm.git", rev = "deb253b" }
alloy-chains = { git = "https://github.com/alloy-rs/chains.git", rev = "906d6fb" }
1 change: 1 addition & 0 deletions bin/reth/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,7 @@ reth-node-api.workspace = true
reth-node-ethereum.workspace = true
reth-node-optimism = { workspace = true, optional = true, features = [
"optimism",
"opbnb",
] }
reth-node-core.workspace = true
reth-node-builder.workspace = true
Expand Down
6 changes: 5 additions & 1 deletion crates/optimism/evm/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -35,4 +35,8 @@ optimism = [
"reth-provider/optimism",
"reth-interfaces/optimism",
"revm-primitives/optimism",
]
]
opbnb = [
"reth-primitives/opbnb",
"revm-primitives/opbnb",
]
91 changes: 44 additions & 47 deletions crates/optimism/evm/src/execute.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,8 @@ use reth_interfaces::{
provider::ProviderError,
};
use reth_primitives::{
BlockNumber, BlockWithSenders, ChainSpec, GotExpected, Hardfork, Header, PruneModes, Receipt,
Receipts, TxType, Withdrawals, U256,
Address, BlockNumber, BlockWithSenders, ChainSpec, GotExpected, Hardfork, Header, PruneModes,
Receipt, Receipts, TxType, Withdrawals, U256,
};
use reth_revm::{
batch::{BlockBatchRecord, BlockExecutorStats},
Expand All @@ -27,9 +27,9 @@ use reth_revm::{
};
use revm_primitives::{
db::{Database, DatabaseCommit},
BlockEnv, CfgEnvWithHandlerCfg, EnvWithHandlerCfg, ResultAndState,
BlockEnv, CfgEnvWithHandlerCfg, EnvWithHandlerCfg, ResultAndState, StorageSlot,
};
use std::sync::Arc;
use std::{collections::HashMap, str::FromStr, sync::Arc};
use tracing::{debug, trace};

/// Provides executors to execute regular ethereum blocks
Expand Down Expand Up @@ -357,49 +357,46 @@ where
block.withdrawals.as_ref().map(Withdrawals::as_ref),
);

// TODO: rebase with the fix
// #[cfg(all(feature = "optimism", feature = "opbnb"))]
// if self.chain_spec.fork(Hardfork::PreContractForkBlock).transitions_at_block(block.
// number) { // WBNBContract WBNB preDeploy contract address
// let w_bnb_contract_address =
// Address::from_str("0x4200000000000000000000000000000000000006").unwrap();
// let mut w_bnb_storage = PlainStorage::new();
// // insert storage for wBNB contract
// // nameSlot { Name: "Wrapped BNB" }
// w_bnb_storage.insert(
// U256::from_str(
// "0x0000000000000000000000000000000000000000000000000000000000000000",
// )
// .unwrap(),
// U256::from_str(
// "0x5772617070656420424e42000000000000000000000000000000000000000016",
// )
// .unwrap(),
// );
// // symbolSlot { Symbol: "wBNB" }
// w_bnb_storage.insert(
// U256::from_str(
// "0x0000000000000000000000000000000000000000000000000000000000000001",
// )
// .unwrap(),
// U256::from_str(
// "0x57424e4200000000000000000000000000000000000000000000000000000008",
// )
// .unwrap(),
// );
// // insert wBNB contract with storage
// self.db_mut().insert_account_with_storage(
// w_bnb_contract_address,
// AccountInfo::default(),
// w_bnb_storage,
// );
// // GovernanceToken contract address
// let governance_token_contract_address =
// Address::from_str("0x4200000000000000000000000000000000000042").unwrap();
// // destruct the governance token contract
// self.evm
// .selfdestruct(governance_token_contract_address,
// governance_token_contract_address); }
#[cfg(all(feature = "optimism", feature = "opbnb"))]
if self.chain_spec().fork(Hardfork::PreContractForkBlock).transitions_at_block(block.number)
{
// WBNBContract WBNB preDeploy contract address
let w_bnb_contract_address =
Address::from_str("0x4200000000000000000000000000000000000006").unwrap();
// GovernanceToken contract address
let governance_token_contract_address =
Address::from_str("0x4200000000000000000000000000000000000042").unwrap();
// touch in cache
let mut w_bnb_contract_account =
self.state.load_cache_account(w_bnb_contract_address).unwrap().clone();
let mut governance_token_account =
self.state.load_cache_account(governance_token_contract_address).unwrap().clone();
// change the token symbol and token name
let w_bnb_contract_change = w_bnb_contract_account.change(
w_bnb_contract_account.account_info().unwrap(), HashMap::from([
// nameSlot { Name: "Wrapped BNB" }
(
U256::from_str("0x0000000000000000000000000000000000000000000000000000000000000000").unwrap(),
StorageSlot { present_value: U256::from_str("0x5772617070656420424e42000000000000000000000000000000000000000016").unwrap(), ..Default::default() },
),
// symbolSlot { Symbol: "wBNB" }
(
U256::from_str("0x0000000000000000000000000000000000000000000000000000000000000001").unwrap(),
StorageSlot { present_value: U256::from_str("0x57424e4200000000000000000000000000000000000000000000000000000008").unwrap(), ..Default::default() },
),
])
);
// destroy governance token contract
let governance_token_change = governance_token_account.selfdestruct().unwrap();

if let Some(s) = self.state.transition_state.as_mut() {
let transitions = vec![
(w_bnb_contract_address, w_bnb_contract_change),
(governance_token_contract_address, governance_token_change),
];
s.add_transitions(transitions);
}
}

// increment balances
self.state
Expand Down
4 changes: 2 additions & 2 deletions crates/optimism/node/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -68,8 +68,8 @@ optimism = [
"reth-optimism-payload-builder/optimism",
"reth-beacon-consensus/optimism",
]

opbnb = [
"reth-primitives/opbnb",
"revm-primitives/opbnb"
"reth-evm-optimism/opbnb",
"reth-optimism-payload-builder/opbnb",
]
4 changes: 4 additions & 0 deletions crates/payload/optimism/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -40,4 +40,8 @@ optimism = [
"reth-provider/optimism",
"reth-rpc-types-compat/optimism",
"reth-evm-optimism/optimism",
]
opbnb = [
"reth-primitives/opbnb",
"reth-evm-optimism/opbnb",
]

0 comments on commit a4d7ef5

Please sign in to comment.