Skip to content

Commit

Permalink
fix: testnet hertz issue (#1)
Browse files Browse the repository at this point in the history
* ci: tag non-beta version as latest image (bnb-chain#51)

* chore: add bsc and docker commands to readme (bnb-chain#50)

* chore: add bsc commands to readme

* fix review comments

* fix op dockerfile issue

* fix: spec mapping issue and snapshot overwrite issue (bnb-chain#52)

* fix: system account status issue (bnb-chain#53)

* test1

* test2

* test3

* test4

* test5

* test6

* test7

* test8

* update CI

---------

Co-authored-by: dylanhuang <j75689@gmail.com>
Co-authored-by: forcodedancing <just.haha.it@gmail.com>
  • Loading branch information
3 people authored Jul 3, 2024
1 parent 9dab153 commit 5bb4fab
Show file tree
Hide file tree
Showing 7 changed files with 154 additions and 43 deletions.
20 changes: 10 additions & 10 deletions .github/workflows/docker.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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 }}

Expand Down Expand Up @@ -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
135 changes: 114 additions & 21 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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:

Expand All @@ -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:
Expand All @@ -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
Expand Down Expand Up @@ -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
Expand All @@ -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 \
Expand All @@ -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

Expand All @@ -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.
Expand Down
16 changes: 15 additions & 1 deletion crates/bsc/evm/src/execute.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -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
Expand Down
16 changes: 8 additions & 8 deletions crates/bsc/evm/src/post_execution.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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);
Expand Down
6 changes: 5 additions & 1 deletion crates/primitives/src/revm/config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ impl StateWriter for ExecutionOutcome {
if !self.snapshots.is_empty() {
let mut snapshot_cursor = tx.cursor_write::<tables::ParliaSnapshot>()?;
for snap in self.snapshots {
snapshot_cursor.insert(snap.block_hash, snap)?;
snapshot_cursor.upsert(snap.block_hash, snap)?;
}
}

Expand Down
2 changes: 1 addition & 1 deletion op.Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -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-* ./
Expand Down

0 comments on commit 5bb4fab

Please sign in to comment.