Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: implement bsc node with bsc provider #12

Merged
merged 33 commits into from
May 29, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
33 commits
Select commit Hold shift + click to select a range
7cbdb0a
feat: implement bsc node with bsc provider
forcodedancing May 16, 2024
169b8fa
implement more traits for BlockchainProvider
forcodedancing May 15, 2024
f1a65f5
temp commit for debug
forcodedancing May 16, 2024
072bf57
fix: update parlia abi setting and `BscExecutorProvider`
pythonberg1997 May 16, 2024
3f047d3
fix a panic issue
forcodedancing May 16, 2024
56907ab
fix: error when verifying headers in parlia
pythonberg1997 May 16, 2024
a52ab62
fix snapshot issue
forcodedancing May 16, 2024
b680c9f
fix some issues
forcodedancing May 17, 2024
8025b65
fix some issues
forcodedancing May 17, 2024
34c729b
fix some unpack and flag issues
forcodedancing May 17, 2024
7409d00
fix some issues
forcodedancing May 17, 2024
11ad08a
fix bsc evm config and other sync issues
pythonberg1997 May 20, 2024
d8bb895
fix parlia default config
forcodedancing May 21, 2024
d8c1e45
fix typo in `distribute_incoming`
pythonberg1997 May 20, 2024
8483cd7
fix system address issue
pythonberg1997 May 21, 2024
c3e3dc1
fix system address issue
pythonberg1997 May 21, 2024
cdf54e9
fix system address issue
pythonberg1997 May 22, 2024
c87ce91
remove some unused codes
forcodedancing May 22, 2024
c2995ca
optimize `DisplayHardforks`
pythonberg1997 May 22, 2024
6ba20a2
optimize hardforks check
pythonberg1997 May 22, 2024
1f16f1b
add docker files, update makefile
forcodedancing May 23, 2024
b1837a0
remove system gas reserve
forcodedancing May 23, 2024
50044a2
fix snapshot issue
pythonberg1997 May 23, 2024
5082875
update revm dependency
pythonberg1997 May 24, 2024
e103dc2
fix system contracts upgrade issue
pythonberg1997 May 26, 2024
4975f93
add stats to `BscBatchExecutor`
pythonberg1997 May 27, 2024
3090eeb
modify base fee setting for bsc
pythonberg1997 May 27, 2024
c35f06c
add patch for HertzFix hardfork
pythonberg1997 May 27, 2024
293e1b3
fix snapshot issue
forcodedancing May 27, 2024
9cc111f
fix snapshot issue
pythonberg1997 May 27, 2024
205bcfd
fix subprotocal disconnect error
forcodedancing May 27, 2024
7928667
fix `ProtocolMessage` error when decoding `NewBlock` from bsc
pythonberg1997 May 27, 2024
d2562f8
fix build warnings
pythonberg1997 May 27, 2024
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 8 additions & 8 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 @@ -410,7 +410,7 @@ test-fuzz = "5"


[patch.crates-io]
revm = { git = "https://github.com/bnb-chain/revm.git", rev = "d99a54e461d6e6506fc6707ed1d2547915bbf943", features = ["std", "secp256k1"], default-features = false }
revm-primitives = { git = "https://github.com/bnb-chain/revm.git", rev = "d99a54e461d6e6506fc6707ed1d2547915bbf943", features = ["std"], default-features = false }
alloy-chains = { git = "https://github.com/bnb-chain/alloy-chains-rs.git", branch = "feat/v0.1.15-opbnb", feature = ["serde", "rlp", "arbitrary"] }
revm = { git = "https://github.com/bnb-chain/revm.git", rev = "a5e76448cfa36a03762cbf91bd5a5040c2f49f17" }
revm-primitives = { git = "https://github.com/bnb-chain/revm.git", rev = "a5e76448cfa36a03762cbf91bd5a5040c2f49f17" }
alloy-chains = { git = "https://github.com/bnb-chain/alloy-chains-rs.git", branch = "feat/v0.1.15-opbnb" }
alloy-genesis = { git = "https://github.com/forcodedancing/alloy", branch = "feat/parlia-config" }
15 changes: 15 additions & 0 deletions DockerfileBsc.cross
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
# This image is meant to enable cross-architecture builds.
# It assumes the reth binary has already been compiled for `$TARGETPLATFORM` and is
# locatable in `./dist/bin/$TARGETARCH`
FROM --platform=$TARGETPLATFORM ubuntu:22.04

LABEL org.opencontainers.image.source=https://github.com/paradigmxyz/reth
LABEL org.opencontainers.image.licenses="MIT OR Apache-2.0"

# Filled by docker buildx
ARG TARGETARCH

COPY ./dist/bin/$TARGETARCH/bsc-reth /usr/local/bin/bsc-reth

EXPOSE 30303 30303/udp 9001 8545 8546
ENTRYPOINT ["/usr/local/bin/bsc-reth"]
59 changes: 59 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,13 @@ install-op: ## Build and install the op-reth binary under `~/.cargo/bin`.
--profile "$(PROFILE)" \
$(CARGO_INSTALL_EXTRA_FLAGS)

.PHONY: install-bsc
install-bsc: ## Build and install the op-reth binary under `~/.cargo/bin`.
cargo install --path bin/reth --bin bsc-reth --force --locked \
--features "bsc,$(FEATURES)" \
--profile "$(PROFILE)" \
$(CARGO_INSTALL_EXTRA_FLAGS)

.PHONY: build
build: ## Build the reth binary into `target` directory.
$(MAKE) build-native-$(shell rustc -Vv | grep host | cut -d ' ' -f2)
Expand All @@ -72,6 +79,9 @@ build-native-%:
op-build-native-%:
cargo build --bin op-reth --target $* --features "optimism,$(FEATURES)" --profile "$(PROFILE)"

bsc-build-native-%:
cargo build --bin bsc-reth --target $* --features "optimism,$(FEATURES)" --profile "$(PROFILE)"

# The following commands use `cross` to build a cross-compile.
#
# These commands require that:
Expand Down Expand Up @@ -107,6 +117,10 @@ op-build-%:
RUSTFLAGS="-C link-arg=-lgcc -Clink-arg=-static-libgcc" \
cross build --bin op-reth --target $* --features "optimism,$(FEATURES)" --profile "$(PROFILE)"

bsc-build-%:
RUSTFLAGS="-C link-arg=-lgcc -Clink-arg=-static-libgcc" \
cross build --bin bsc-reth --target $* --features "bsc,$(FEATURES)" --profile "$(PROFILE)"

# Unfortunately we can't easily use cross to build for Darwin because of licensing issues.
# If we wanted to, we would need to build a custom Docker image with the SDK available.
#
Expand Down Expand Up @@ -276,6 +290,51 @@ define op_docker_build_push
--push
endef

##@ BSC docker

# Note: This requires a buildx builder with emulation support. For example:
#
# `docker run --privileged --rm tonistiigi/binfmt --install amd64,arm64`
# `docker buildx create --use --driver docker-container --name cross-builder`
.PHONY: bsc-docker-build-push
bsc-docker-build-push: ## Build and push a cross-arch Docker image tagged with the latest git tag.
$(call bsc_docker_build_push,$(GIT_TAG),$(GIT_TAG))

# Note: This requires a buildx builder with emulation support. For example:
#
# `docker run --privileged --rm tonistiigi/binfmt --install amd64,arm64`
# `docker buildx create --use --driver docker-container --name cross-builder`
.PHONY: bsc-docker-build-push-latest
bsc-docker-build-push-latest: ## Build and push a cross-arch Docker image tagged with the latest git tag and `latest`.
$(call bsc_docker_build_push,$(GIT_TAG),latest)

# Note: This requires a buildx builder with emulation support. For example:
#
# `docker run --privileged --rm tonistiigi/binfmt --install amd64,arm64`
# `docker buildx create --use --name cross-builder`
.PHONY: bsc-docker-build-push-nightly
bsc-docker-build-push-nightly: ## Build and push cross-arch Docker image tagged with the latest git tag with a `-nightly` suffix, and `latest-nightly`.
$(call bsc_docker_build_push,$(GIT_TAG)-nightly,latest-nightly)

# Create a cross-arch Docker image with the given tags and push it
define bsc_docker_build_push
$(MAKE) bsc-build-x86_64-unknown-linux-gnu
mkdir -p $(BIN_DIR)/amd64
cp $(BUILD_PATH)/x86_64-unknown-linux-gnu/$(PROFILE)/bsc-reth $(BIN_DIR)/amd64/bsc-reth

$(MAKE) bsc-build-aarch64-unknown-linux-gnu
mkdir -p $(BIN_DIR)/arm64
cp $(BUILD_PATH)/aarch64-unknown-linux-gnu/$(PROFILE)/bsc-reth $(BIN_DIR)/arm64/bsc-reth

docker buildx build --file ./DockerfileBsc.cross . \
--platform linux/amd64,linux/arm64 \
--tag $(DOCKER_IMAGE_NAME):$(1) \
--tag $(DOCKER_IMAGE_NAME):$(2) \
--provenance=false \
--push
endef


##@ Other

.PHONY: clean
Expand Down
4 changes: 3 additions & 1 deletion bin/reth/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -148,7 +148,9 @@ bsc = [
"reth-rpc/bsc",
"reth-primitives/bsc",
"dep:reth-node-bsc",
"reth-node-core/bsc"
"reth-node-core/bsc",
"reth-stages/bsc",
"reth-node-builder/bsc"
]

# no-op feature flag for switching between the `optimism` and default functionality in CI matrices
Expand Down
7 changes: 5 additions & 2 deletions bin/reth/src/commands/debug_cmd/merkle.rs
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ use reth_network_api::NetworkInfo;
use reth_primitives::{fs, stage::StageCheckpoint, BlockHashOrNumber, ChainSpec, PruneModes};
use reth_provider::{
BlockNumReader, BlockWriter, BundleStateWithReceipts, HeaderProvider, LatestStateProviderRef,
OriginalValuesKnown, ProviderError, ProviderFactory, StateWriter,
OriginalValuesKnown, ProviderError, ProviderFactory, StateWriter, ParliaSnapshotWriter
};
use reth_revm::database::StateProviderDatabase;
use reth_stages::{
Expand Down Expand Up @@ -197,12 +197,15 @@ impl Command {
PruneModes::none(),
);
executor.execute_one((&sealed_block.clone().unseal(), td).into())?;
let BatchBlockExecutionOutput { bundle, receipts, first_block } = executor.finalize();
let BatchBlockExecutionOutput { bundle, receipts, first_block, snapshots } = executor.finalize();
BundleStateWithReceipts::new(bundle, receipts, first_block).write_to_storage(
provider_rw.tx_ref(),
None,
OriginalValuesKnown::Yes,
)?;
for snap in snapshots {
provider_rw.save_parlia_snapshot(snap)?;
}

let checkpoint = Some(StageCheckpoint::new(block_number - 1));

Expand Down
52 changes: 52 additions & 0 deletions bsc.Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
FROM lukemathwalker/cargo-chef:latest-rust-1 AS chef
WORKDIR /app

LABEL org.opencontainers.image.source=https://github.com/paradigmxyz/reth
LABEL org.opencontainers.image.licenses="MIT OR Apache-2.0"

# Builds a cargo-chef plan
FROM chef AS planner
COPY . .
RUN cargo chef prepare --recipe-path recipe.json

FROM chef AS builder
COPY --from=planner /app/recipe.json recipe.json

# Build profile, release by default
ARG BUILD_PROFILE=release
ENV BUILD_PROFILE $BUILD_PROFILE

# Extra Cargo flags
ARG RUSTFLAGS=""
ENV RUSTFLAGS "$RUSTFLAGS"

# Extra Cargo features
ARG FEATURES="bsc"
ENV FEATURES $FEATURES

# Install system dependencies
RUN apt-get update && apt-get -y upgrade && apt-get install -y libclang-dev pkg-config

# Builds dependencies
RUN cargo chef cook --profile $BUILD_PROFILE --features "$FEATURES" --recipe-path recipe.json

# Build application
COPY . .
RUN cargo build --profile $BUILD_PROFILE --features "$FEATURES" --locked --bin bsc-reth

# ARG is not resolved in COPY so we have to hack around it by copying the
# binary to a temporary location
RUN cp /app/target/$BUILD_PROFILE/bsc-reth /app/bsc-reth

# Use Ubuntu as the release image
FROM ubuntu AS runtime
WORKDIR /app

# Copy reth over from the build stage
COPY --from=builder /app/bsc-reth /usr/local/bin

# Copy licenses
COPY LICENSE-* ./

EXPOSE 30303 30303/udp 9001 8545 8546
ENTRYPOINT ["/usr/local/bin/bsc-reth"]
Loading
Loading