From 5bb4fab2a728712660a857aad1bd16f977f9d01b Mon Sep 17 00:00:00 2001 From: Roshan <48975233+pythonberg1997@users.noreply.github.com> Date: Wed, 3 Jul 2024 17:51:46 +0800 Subject: [PATCH] fix: testnet hertz issue (#1) * ci: tag non-beta version as latest image (#51) * chore: add bsc and docker commands to readme (#50) * chore: add bsc commands to readme * fix review comments * fix op dockerfile issue * fix: spec mapping issue and snapshot overwrite issue (#52) * fix: system account status issue (#53) * test1 * test2 * test3 * test4 * test5 * test6 * test7 * test8 * update CI --------- Co-authored-by: dylanhuang Co-authored-by: forcodedancing --- .github/workflows/docker.yml | 20 +-- README.md | 135 +++++++++++++++--- crates/bsc/evm/src/execute.rs | 16 ++- crates/bsc/evm/src/post_execution.rs | 16 +-- crates/primitives/src/revm/config.rs | 6 +- .../bundle_state_with_receipts.rs | 2 +- op.Dockerfile | 2 +- 7 files changed, 154 insertions(+), 43 deletions(-) diff --git a/.github/workflows/docker.yml b/.github/workflows/docker.yml index 723640c4f6..fd7fa075ce 100644 --- a/.github/workflows/docker.yml +++ b/.github/workflows/docker.yml @@ -11,11 +11,11 @@ on: env: REPO_NAME: ${{ github.repository_owner }}/reth # IMAGE_NAME: ${{ github.repository_owner }}/reth - OP_IMAGE_NAME: ${{ github.repository_owner }}/op-reth +# OP_IMAGE_NAME: ${{ github.repository_owner }}/op-reth BSC_IMAGE_NAME: ${{ github.repository_owner }}/bsc-reth CARGO_TERM_COLOR: always # DOCKER_IMAGE_NAME: ghcr.io/${{ github.repository_owner }}/reth - OP_DOCKER_IMAGE_NAME: ghcr.io/${{ github.repository_owner }}/op-reth +# OP_DOCKER_IMAGE_NAME: ghcr.io/${{ github.repository_owner }}/op-reth BSC_DOCKER_IMAGE_NAME: ghcr.io/${{ github.repository_owner }}/bsc-reth DOCKER_USERNAME: ${{ github.actor }} @@ -46,15 +46,15 @@ jobs: # - name: Build and push reth image # if: ${{ ! contains(github.event.ref, 'beta') }} # run: make PROFILE=maxperf docker-build-push - - name: Build and push op-reth image, tag as "latest" - if: ${{ contains(github.event.ref, 'beta') }} - run: make IMAGE_NAME=$OP_IMAGE_NAME DOCKER_IMAGE_NAME=$OP_DOCKER_IMAGE_NAME PROFILE=maxperf op-docker-build-push-latest - - name: Build and push op-reth image - if: ${{ ! contains(github.event.ref, 'beta') }} - run: make IMAGE_NAME=$OP_IMAGE_NAME DOCKER_IMAGE_NAME=$OP_DOCKER_IMAGE_NAME PROFILE=maxperf op-docker-build-push +# - name: Build and push op-reth image, tag as "latest" +# if: ${{ ! contains(github.event.ref, 'beta') }} +# run: make IMAGE_NAME=$OP_IMAGE_NAME DOCKER_IMAGE_NAME=$OP_DOCKER_IMAGE_NAME PROFILE=maxperf op-docker-build-push-latest +# - name: Build and push op-reth image +# if: ${{ contains(github.event.ref, 'beta') }} +# run: make IMAGE_NAME=$OP_IMAGE_NAME DOCKER_IMAGE_NAME=$OP_DOCKER_IMAGE_NAME PROFILE=maxperf op-docker-build-push - name: Build and push bsc-reth image, tag as "latest" - if: ${{ contains(github.event.ref, 'beta') }} + if: ${{ ! contains(github.event.ref, 'beta') }} run: make IMAGE_NAME=$BSC_IMAGE_NAME DOCKER_IMAGE_NAME=$BSC_DOCKER_IMAGE_NAME PROFILE=maxperf bsc-docker-build-push-latest - name: Build and push bsc-reth image - if: ${{ ! contains(github.event.ref, 'beta') }} + if: ${{ contains(github.event.ref, 'beta') }} run: make IMAGE_NAME=$BSC_IMAGE_NAME DOCKER_IMAGE_NAME=$BSC_DOCKER_IMAGE_NAME PROFILE=maxperf bsc-docker-build-push \ No newline at end of file diff --git a/README.md b/README.md index 71510597f4..c79537222b 100644 --- a/README.md +++ b/README.md @@ -5,16 +5,20 @@ [![Discord Chat][discord-badge]][discord-url] [gh-ci]: https://github.com/bnb-chain/reth/actions/workflows/unit.yml + [gh-deny]: https://github.com/bnb-chain/reth/actions/workflows/deny.yml + [discord-badge]: https://img.shields.io/badge/discord-join%20chat-blue.svg + [discord-url]: https://discord.gg/z2VpC455eU -BNB Chain Reth is a cutting-edge rust client developed in collaboration with Paradigm, designed to provide seamless support -for [BNB Smart Chain(BSC)](https://github.com/bnb-chain/bsc) and [opBNB](https://github.com/bnb-chain/op-geth). +BNB Chain Reth is a cutting-edge rust client developed in collaboration with Paradigm, designed to provide seamless +support for [BNB Smart Chain(BSC)](https://github.com/bnb-chain/bsc) and [opBNB](https://github.com/bnb-chain/op-geth). ## Build from Source -For prerequisites and detailed build instructions please read the [Installation Instructions](https://paradigmxyz.github.io/reth/installation/source.html). +For prerequisites and detailed build instructions please read +the [Installation Instructions](https://paradigmxyz.github.io/reth/installation/source.html). With Rust and the dependencies installed, you're ready to build BNB Chain Reth. First, clone the repository: @@ -23,16 +27,16 @@ git clone https://github.com/bnb-chain/reth.git cd reth ``` -In the realm of BSC, you have the option to execute the following commands to compile reth: +In the realm of BSC, you have the option to execute the following commands to compile bsc-reth: ```shell -make build +make build-bsc ``` Alternatively, you can install reth using the following command: ```shell -make install +make install-bsc ``` When it comes to opBNB, you can run the following commands to compile op-reth: @@ -49,25 +53,70 @@ make install-op ## Run Reth for BSC -Coming soon...... +The command below is for an archive node. To run a full node, simply add the `--full` tag. -## Run Reth for opBNB +```shell +# for testnet +export network=bsc-testnet -The op-reth can function as both a full node and an archive node. Due to its unique storage advantages, it is primarily utilized for running archive nodes. +# for mainnet +# export network=bsc -### Hardware Requirements +./target/release/bsc-reth node \ + --datadir=./datadir \ + --chain=${network} \ + --http \ + --http.addr=0.0.0.0 \ + --http.port=8545 \ + --http.api="eth, net, txpool, web3, rpc" \ + --ws \ + --ws.addr=0.0.0.0 \ + --ws.port=8546 \ + --nat=any \ + --log.file.directory ./datadir/logs +``` + +You can run `bsc-reth --help` for command explanations. + +For running bsc-reth with docker, please use the following command: + +```shell +# for testnet +export network=bsc-testnet + +# for mainnet +# export network=bsc -* CPU with 16+ cores -* 128GB RAM -* High-performance NVMe SSD with at least 3TB of free space -* A broadband internet connection with upload/download speeds of 25 MB/s +# check this for version of the docker image, https://github.com/bnb-chain/reth/pkgs/container/bsc-reth +export version=latest -### Steps to Run op-reth +# the directory where reth data will be stored +export data_dir=/xxx/xxx -The op-reth is an [execution client](https://ethereum.org/en/developers/docs/nodes-and-clients/#execution-clients) for opBNB. +docker run -d -p 8545:8545 -p 8546:8546 -p 30303:30303 -p 30303:30303/udp -v ${data_dir}:/data \ + --name bsc-reth ghcr.io/bnb-chain/bsc-reth:${version} node \ + --datadir=/data \ + --chain=${network} \ + --http \ + --http.addr=0.0.0.0 \ + --http.port=8545 \ + --http.api="eth, net, txpool, web3, rpc" \ + --ws \ + --ws.addr=0.0.0.0 \ + --ws.port=8546 \ + --nat=any \ + --log.file.directory /data/logs +``` + +## Run Reth for opBNB + +The op-reth is an [execution client](https://ethereum.org/en/developers/docs/nodes-and-clients/#execution-clients) for +opBNB. You need to run op-node along with op-reth to synchronize with the opBNB network. -Here is the quick command for running the op-node. For more details, refer to the [opbnb repository](https://github.com/bnb-chain/opbnb). +Here is the quick command for running the op-node. For more details, refer to +the [opbnb repository](https://github.com/bnb-chain/opbnb). + ```shell git clone https://github.com/bnb-chain/opbnb cd opbnb @@ -110,8 +159,10 @@ export P2P_BOOTNODES="enr:-J24QGQBeMsXOaCCaLWtNFSfb2Gv50DjGOKToH2HUTAIn9yXImowlR --l2.jwt-secret=./jwt.txt ``` -Copy the JWT file generated when running the op-node to the current workspace. Here is a quick command for running op-reth. +Copy the JWT file generated when running the op-node to the current workspace. Here is a quick command for running +op-reth. The command below is for an archive node. To run a full node, simply add the `--full` tag. + ```shell # for testnet export network=testnet @@ -133,7 +184,7 @@ export TRUST_NODES="enode://1a8f2d3160ad6efd6591981c026bd31807b79844422d99107f8f --http \ --http.addr=0.0.0.0 \ --http.port=8545 \ - --http.api="admin, debug, eth, net, trace, txpool, web3, rpc, reth, ots, eth-call-bundle" \ + --http.api="eth, net, txpool, web3, rpc" \ --ws \ --ws.addr=0.0.0.0 \ --ws.port=8546 \ @@ -143,7 +194,48 @@ export TRUST_NODES="enode://1a8f2d3160ad6efd6591981c026bd31807b79844422d99107f8f --log.file.directory ./datadir/logs ``` -You can run `op-reth --help` for command explanations. More details on running opbnb nodes can be found [here](https://docs.bnbchain.org/opbnb-docs/docs/tutorials/running-a-local-node/). +You can run `op-reth --help` for command explanations. More details on running opbnb nodes can be +found [here](https://docs.bnbchain.org/opbnb-docs/docs/tutorials/running-a-local-node/). + +For running op-reth with docker, please use the following command: + +```shell +# for testnet +export network=testnet +export L2_RPC=https://opbnb-testnet-rpc.bnbchain.org + +# for mainnet +# export network=mainnet +# export L2_RPC=https://opbnb-mainnet-rpc.bnbchain.org + +# check this for version of the docker image, https://github.com/bnb-chain/reth/pkgs/container/op-reth +export version=latest + +# the directory where reth data will be stored +export data_dir=/xxx/xxx + +# the directory where the jwt.txt file is stored +export jwt_dir=/xxx/xxx + +docker run -d -p 8545:8545 -p 8546:8546 -p 30303:30303 -p 30303:30303/udp -v ${data_dir}:/data -v ${jwt_dir}:/jwt \ + --name op-reth ghcr.io/bnb-chain/op-reth:${version} node \ + --datadir=/data \ + --chain=opbnb-${network} \ + --rollup.sequencer-http=${L2_RPC} \ + --authrpc.addr="0.0.0.0" \ + --authrpc.port=8551 \ + --authrpc.jwtsecret=/jwt/jwt.txt \ + --http \ + --http.addr=0.0.0.0 \ + --http.port=8545 \ + --http.api="eth, net, txpool, web3, rpc" \ + --ws \ + --ws.addr=0.0.0.0 \ + --ws.port=8546 \ + --builder.gaslimit=150000000 \ + --nat=any \ + --log.file.directory /data/logs +``` ## Contribution @@ -152,7 +244,8 @@ from anyone on the internet, and are grateful for even the smallest of fixes! If you'd like to contribute to bnb chain reth, please fork, fix, commit and send a pull request for the maintainers to review and merge into the main code base. If you wish to submit -more complex changes though, please check up with the core devs first on [our discord channel](https://discord.gg/bnbchain) +more complex changes though, please check up with the core devs first +on [our discord channel](https://discord.gg/bnbchain) to ensure those changes are in line with the general philosophy of the project and/or get some early feedback which can make both your efforts much lighter as well as our review and merge procedures quick and simple. diff --git a/crates/bsc/evm/src/execute.rs b/crates/bsc/evm/src/execute.rs index 186edc5c06..308bc6e466 100644 --- a/crates/bsc/evm/src/execute.rs +++ b/crates/bsc/evm/src/execute.rs @@ -17,6 +17,7 @@ use reth_evm::{ ConfigureEvm, }; use reth_primitives::{ + b256, parlia::{ParliaConfig, Snapshot, VoteAddress, CHECKPOINT_INTERVAL}, system_contracts::get_upgrade_system_contracts, Address, BlockNumber, BlockWithSenders, Bytes, Header, Receipt, Transaction, TransactionSigned, @@ -201,7 +202,20 @@ where error: err.into(), } })?; - + if block.number == 35547819 && + transaction.recalculate_hash() == + b256!("5ebef67c81a8b0121c081056f10c17a3943eb59f74f53e2c54dc939d0bb06f55") + { + debug!("tx hash: {:?}", transaction.hash()); + debug!("tx state: {:?}", state); + } + if block.number == 35547779 && + transaction.recalculate_hash() == + b256!("7ce9a3cf77108fcc85c1e84e88e363e3335eca515dfcf2feb2011729878b13a7") + { + debug!("tx hash: {:?}", transaction.hash()); + debug!("tx state: {:?}", state); + } evm.db_mut().commit(state); // append gas used diff --git a/crates/bsc/evm/src/post_execution.rs b/crates/bsc/evm/src/post_execution.rs index a7057a21d1..42c15a01fd 100644 --- a/crates/bsc/evm/src/post_execution.rs +++ b/crates/bsc/evm/src/post_execution.rs @@ -13,7 +13,7 @@ use reth_primitives::{ Address, BlockWithSenders, GotExpected, Header, Receipt, TransactionSigned, U256, }; use reth_provider::ParliaProvider; -use reth_revm::{bsc::SYSTEM_ADDRESS, db::AccountStatus}; +use reth_revm::bsc::SYSTEM_ADDRESS; use revm_primitives::{db::Database, EnvWithHandlerCfg}; use std::collections::HashMap; use tracing::log::debug; @@ -269,17 +269,17 @@ where .state .load_cache_account(SYSTEM_ADDRESS) .map_err(|err| BscBlockExecutionError::ProviderInnerError { error: err.into() })?; - if system_account.status == AccountStatus::LoadedNotExisting || - system_account.status == AccountStatus::DestroyedAgain - { - return Ok(()); - } - let (mut block_reward, transition) = system_account.drain_balance(); - self.state.apply_transition(vec![(SYSTEM_ADDRESS, transition)]); if block_reward == 0 { + if header.number == 1 { + // We have to apply the transition to the system account + // even if the block reward is 0 + // because the system account is initialized in genesis. + self.state.apply_transition(vec![(SYSTEM_ADDRESS, transition)]); + } return Ok(()); } + self.state.apply_transition(vec![(SYSTEM_ADDRESS, transition)]); let mut balance_increment = HashMap::new(); balance_increment.insert(validator, block_reward); diff --git a/crates/primitives/src/revm/config.rs b/crates/primitives/src/revm/config.rs index 98e307baaf..928fd9bcb6 100644 --- a/crates/primitives/src/revm/config.rs +++ b/crates/primitives/src/revm/config.rs @@ -112,12 +112,16 @@ pub fn revm_spec(chain_spec: &ChainSpec, block: Head) -> revm_primitives::SpecId } else if chain_spec.fork(Hardfork::Gibbs).active_at_head(&block) { // bsc mainnet and testnet have different order for Moran, Nano and Gibbs return if chain_spec.fork(Hardfork::Moran).active_at_head(&block) { - revm_primitives::GIBBS + revm_primitives::MORAN } else if chain_spec.fork(Hardfork::Nano).active_at_head(&block) { revm_primitives::NANO } else { revm_primitives::EULER } + } else if chain_spec.fork(Hardfork::Moran).active_at_head(&block) { + return revm_primitives::MORAN + } else if chain_spec.fork(Hardfork::Nano).active_at_head(&block) { + return revm_primitives::NANO } else if chain_spec.fork(Hardfork::Euler).active_at_head(&block) { return revm_primitives::EULER } else if chain_spec.fork(Hardfork::Bruno).active_at_head(&block) { diff --git a/crates/storage/provider/src/bundle_state/bundle_state_with_receipts.rs b/crates/storage/provider/src/bundle_state/bundle_state_with_receipts.rs index 85452c5646..8d687a98da 100644 --- a/crates/storage/provider/src/bundle_state/bundle_state_with_receipts.rs +++ b/crates/storage/provider/src/bundle_state/bundle_state_with_receipts.rs @@ -62,7 +62,7 @@ impl StateWriter for ExecutionOutcome { if !self.snapshots.is_empty() { let mut snapshot_cursor = tx.cursor_write::()?; for snap in self.snapshots { - snapshot_cursor.insert(snap.block_hash, snap)?; + snapshot_cursor.upsert(snap.block_hash, snap)?; } } diff --git a/op.Dockerfile b/op.Dockerfile index a4692dad54..833ca9f693 100644 --- a/op.Dockerfile +++ b/op.Dockerfile @@ -43,7 +43,7 @@ FROM ubuntu AS runtime WORKDIR /app # Copy reth over from the build stage -COPY --from=builder /app/bsc-reth /usr/local/bin +COPY --from=builder /app/op-reth /usr/local/bin # Copy licenses COPY LICENSE-* ./