Skip to content

Commit

Permalink
Merge pull request #46 from taikoxyz/rbuilderV3
Browse files Browse the repository at this point in the history
rbuilder integration with gwyneth-reth
  • Loading branch information
Brechtpd authored Oct 11, 2024
2 parents 6bf500f + d2beb2f commit be2e95a
Show file tree
Hide file tree
Showing 24 changed files with 1,240 additions and 969 deletions.
1,408 changes: 567 additions & 841 deletions Cargo.lock

Large diffs are not rendered by default.

20 changes: 7 additions & 13 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -409,10 +409,10 @@ revm-primitives = { version = "9.0.0", features = [

# eth
alloy-chains = "0.1.18"
alloy-dyn-abi = "0.8.0"
alloy-primitives = { version = "0.8.0", default-features = false }
alloy-dyn-abi = "0.8.2"
alloy-primitives = { version = "0.8.2", default-features = false }
alloy-rlp = "0.3.4"
alloy-sol-types = "0.8.0"
alloy-sol-types = "0.8.2"
alloy-trie = { version = "0.5", default-features = false }

alloy-consensus = { version = "0.3.0", default-features = false }
Expand All @@ -432,7 +432,7 @@ alloy-rpc-types = { version = "0.3.0", features = [
alloy-rpc-types-admin = { version = "0.3.0", default-features = false }
alloy-rpc-types-anvil = { version = "0.3.0", default-features = false }
alloy-rpc-types-beacon = { version = "0.3.0", default-features = false }
alloy-rpc-types-engine = { version = "0.3.0", default-features = false, features = ["std", "jwt"] }
alloy-rpc-types-engine = { version = "0.3.0", default-features = false }
alloy-rpc-types-eth = { version = "0.3.0", default-features = false }
alloy-rpc-types-mev = { version = "0.3.0", default-features = false }
alloy-rpc-types-trace = { version = "0.3.0", default-features = false }
Expand Down Expand Up @@ -566,14 +566,8 @@ tempfile = "3.8"
test-fuzz = "5"

[patch.crates-io]
revm = { git = "https://github.com/taikoxyz/revm.git", branch = "v43-gwyneth", features = [
"std",
"secp256k1",
"blst",
], default-features = false }
revm-primitives = { git = "https://github.com/taikoxyz/revm.git", branch = "v43-gwyneth", features = [
"std",
], default-features = false }
revm = { git = "https://github.com/taikoxyz/revm.git", branch = "v43-gwyneth" }
revm-primitives = { git = "https://github.com/taikoxyz/revm.git", branch = "v43-gwyneth" }
revm-interpreter = { git = "https://github.com/taikoxyz/revm.git", branch = "v43-gwyneth" }
revm-precompile = { git = "https://github.com/taikoxyz/revm.git", branch = "v43-gwyneth" }
revm-inspectors = { git = "https://github.com/taikoxyz/revm-inspectors.git", branch = "sync-database" }
revm-inspectors = { git = "https://github.com/taikoxyz/revm-inspectors.git", branch = "main-rbuilder" }
47 changes: 37 additions & 10 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -1,11 +1,10 @@
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"

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

# Builds a cargo-chef plan
FROM chef AS planner
Expand All @@ -17,36 +16,64 @@ COPY --from=planner /app/recipe.json recipe.json

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

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

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

# 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 reth

# ARG is not resolved in COPY so we have to hack around it by copying the
# binary to a temporary location
# Hack: Add a cache busting step (above steps are the more
# time consuming ones but we need to make sure the rbuilder is
# always freshly cloned and not cached !)
# Since the content of this file will change
# with each build, Docker will consider this
# layer (and all subsequent layers) as modified,
# forcing a re-execution of the following steps.
# ADD https://worldtimeapi.org/api/ip /tmp/bustcache

# Clone and build rbuilder (gwyneth branch)
RUN git clone -b gwyneth https://github.com/taikoxyz/rbuilder.git /app/rbuilder
WORKDIR /app/rbuilder
RUN cargo build --release

# Copy binaries to a temporary location
RUN cp /app/target/$BUILD_PROFILE/reth /app/reth
RUN cp /app/rbuilder/target/release/rbuilder /app/rbuilder

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

# Copy reth over from the build stage
# Install necessary runtime dependencies and Rust/Cargo
RUN apt-get update && apt-get install -y ca-certificates && rm -rf /var/lib/apt/lists/*

# Install Rust and Cargo
RUN curl --proto '=https' --tlsv1.2 -sSf https://sh.rustup.rs | sh -s -- -y
ENV PATH="/root/.cargo/bin:${PATH}"

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

# Copy the entire rbuilder repository
COPY --from=builder /app/rbuilder /app/rbuilder

# Copy licenses
COPY LICENSE-* ./

# Create start script
RUN echo '#!/bin/bash\nrbuilder run /app/rbuilder/config-gwyneth-reth.toml' > /app/start_rbuilder.sh && \
chmod +x /app/start_rbuilder.sh

EXPOSE 30303 30303/udp 9001 8545 8546
ENTRYPOINT ["/usr/local/bin/reth"]
37 changes: 37 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,40 @@
# Gwyneth

## Install

```sh
cd packages/protocol
pnpm install
make install
```

## Use

Add custom networks to your wallet:

```
chain_id: 167010
name: Gwyneth-1
rpc: http://127.0.0.1:32005
Currency: ETH
Block explorer: http://127.0.0.1:64003
```

```
chain_id: 160010
name: Gwyneth L1
rpc: http://127.0.0.1:32002
Currency: ETH
Block explorer: http://127.0.0.1:64001
```

Add test accounts that have some ETH to play with:
- 0x8943545177806ED17B9F23F0a21ee5948eCaa776 (private key: bcdf20249abf0ed6d944c0288fad489e33f66b3960d9e6229c1cd214ed3bbe31)
- 0xE25583099BA105D9ec0A67f5Ae86D90e50036425 (private key: 39725efee3fb28614de3bacaffe4cc4bd8c436257e2c8bb887c4b5c4be45e76d)
- 0x614561D2d143621E126e87831AEF287678B442b8 (private key: 53321db7c1e331d93a11a41d16f004d7ff63972ec8ec7c25db329728ceeb1710)

Rabby/Brave wallet works, but some issues with nonces so you may have to manually input the correct nonce.

# reth

[![CI status](https://github.com/paradigmxyz/reth/workflows/unit/badge.svg)][gh-ci]
Expand Down
7 changes: 0 additions & 7 deletions bin/reth/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -110,17 +110,10 @@ tempfile.workspace = true
backon.workspace = true
similar-asserts.workspace = true
itertools.workspace = true
once_cell = "1"
rusqlite = { version = "0.31.0", features = ["bundled"] }
foundry-blob-explorers = "0.5"

# p2p
discv5.workspace = true

# alloy
alloy-consensus = { version = "0.2", features = ["kzg"] }
alloy-sol-types = { workspace = true, features = ["json"] }

[target.'cfg(unix)'.dependencies]
tikv-jemallocator = { version = "0.5.0", optional = true }
libc = "0.2"
Expand Down
4 changes: 2 additions & 2 deletions bin/reth/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -37,12 +37,12 @@ fn main() -> eyre::Result<()> {
.with_chain(chain_spec.clone())
.with_network(network_config.clone())
.with_unused_ports()
.with_rpc(RpcServerArgs::default().with_unused_ports().with_static_l2_rpc_ip_and_port())
.with_rpc(RpcServerArgs::default().with_unused_ports().with_static_l2_rpc_ip_and_port(chain_spec.chain.id()))
.set_dev(true);

let NodeHandle { node: gwyneth_node, node_exit_future: _ } =
NodeBuilder::new(node_config.clone())
.testing_node(exec.clone())
.gwyneth_node(exec.clone(), chain_spec.chain.id())
.node(GwynethNode::default())
.launch()
.await?;
Expand Down
1 change: 1 addition & 0 deletions crates/ethereum/evm/src/execute.rs
Original file line number Diff line number Diff line change
Expand Up @@ -170,6 +170,7 @@ where
let mut cumulative_gas_used = 0;
let mut receipts = Vec::with_capacity(block.body.len());
for (sender, transaction) in block.transactions_with_sender() {
println!("Executing transaction from {:?}: {:?}", sender, transaction.chain_id());
// The sum of the transaction’s gas limit, Tg, and the gas utilized in this block prior,
// must be no greater than the block’s gasLimit.
let block_available_gas = block.header.gas_limit - cumulative_gas_used;
Expand Down
8 changes: 7 additions & 1 deletion crates/ethereum/payload/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -102,6 +102,8 @@ where

debug!(target: "payload_builder", parent_hash = ?parent_block.hash(), parent_number = parent_block.number, "building empty payload");

println!("brecht: empty payload builder for {}", chain_spec.chain.id());

let state = client.state_by_block_hash(parent_block.hash()).map_err(|err| {
warn!(target: "payload_builder",
parent_hash=%parent_block.hash(),
Expand Down Expand Up @@ -262,6 +264,8 @@ where
let block = Block { header, body: vec![], ommers: vec![], withdrawals, requests };
let sealed_block = block.seal_slow();

println!("empty payload done [{:?}]: {:?}", sealed_block.hash(), sealed_block.state_root);

Ok(EthBuiltPayload::new(attributes.payload_id(), sealed_block, U256::ZERO))
}
}
Expand Down Expand Up @@ -323,7 +327,6 @@ where

let block_number = initialized_block_env.number.to::<u64>();


// apply eip-4788 pre block contract call
pre_block_beacon_root_contract_call(
&mut db,
Expand Down Expand Up @@ -358,6 +361,7 @@ where
let mut receipts = Vec::new();
while let Some(pool_tx) = best_txs.next() {
// ensure we still have capacity for this transaction
println!("Brecht: pool tx! {:?}", pool_tx.hash());
if cumulative_gas_used + pool_tx.gas_limit() > block_gas_limit {
// we can't fit this transaction into the block, so we need to mark it as invalid
// which also removes all dependent transaction from the iterator before we can
Expand Down Expand Up @@ -588,6 +592,8 @@ where
let sealed_block = block.seal_slow();
debug!(target: "payload_builder", ?sealed_block, "sealed built block");

println!("default payload done [{:?}]: {:?}", sealed_block.hash(), sealed_block.state_root);

let mut payload = EthBuiltPayload::new(attributes.id, sealed_block, total_fees);

// extend the payload with the blob sidecars from the executed txs
Expand Down
1 change: 1 addition & 0 deletions crates/gwyneth/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@ reth-rpc-api.workspace = true
reth-rpc-layer.workspace = true
reth-db.workspace = true
reth-trie.workspace = true
reth-rpc-builder.workspace = true

# ethereum
reth-node-ethereum.workspace = true
Expand Down
2 changes: 1 addition & 1 deletion crates/gwyneth/TaikoL1.json

Large diffs are not rendered by default.

6 changes: 4 additions & 2 deletions crates/gwyneth/src/engine_api.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ use reth_rpc_types::{
ExecutionPayloadV3,
};
use std::{marker::PhantomData, net::Ipv4Addr};
use reth_rpc_builder::constants;

/// Helper for engine api operations
pub struct EngineApiContext<E> {
Expand Down Expand Up @@ -112,17 +113,18 @@ impl PayloadEnvelopeExt for ExecutionPayloadEnvelopeV3 {
}
}
pub trait RpcServerArgsExEx {
fn with_static_l2_rpc_ip_and_port(self) -> Self;
fn with_static_l2_rpc_ip_and_port(self, chain_id: u64) -> Self;
}

impl RpcServerArgsExEx for RpcServerArgs {
fn with_static_l2_rpc_ip_and_port(mut self) -> Self {
fn with_static_l2_rpc_ip_and_port(mut self, chain_id: u64) -> Self {
self.http = true;
// On the instance the program is running, we wanna have 10111 exposed as the (exex) L2's
// RPC port.
self.http_addr = Ipv4Addr::new(0, 0, 0, 0).into();
self.http_port = 10110u16;
self.ws_port = 10111u16;
self.ipcpath = format!("{}-{}", constants::DEFAULT_IPC_ENDPOINT, chain_id);
self
}
}
11 changes: 7 additions & 4 deletions crates/gwyneth/src/exex.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ use std::{marker::PhantomData, sync::Arc};
use alloy_rlp::Decodable;
use alloy_sol_types::{sol, SolEventInterface};

sol!(RollupContract, "TaikoL1.json");
use crate::{
engine_api::EngineApiContext, GwynethEngineTypes, GwynethNode, GwynethPayloadAttributes,
GwynethPayloadBuilderAttributes,
Expand Down Expand Up @@ -66,6 +65,8 @@ pub type GwynethFullNode = FullNode<
EthereumAddOns,
>;

sol!(RollupContract, "TaikoL1.json");

pub struct Rollup<Node: reth_node_api::FullNodeComponents> {
ctx: ExExContext<Node>,
node: GwynethFullNode,
Expand Down Expand Up @@ -111,11 +112,13 @@ impl<Node: reth_node_api::FullNodeComponents> Rollup<Node> {

if let RollupContractEvents::BlockProposed(BlockProposed {
blockId: block_number,
meta: _,
txList: tx_list,
meta,
}) = event
{
let transactions: Vec<TransactionSigned> = decode_transactions(&tx_list);
println!("block_number: {:?}", block_number);
println!("tx_list: {:?}", meta.txList);
let transactions: Vec<TransactionSigned> = decode_transactions(&meta.txList);
println!("transactions: {:?}", transactions);

let attrs = GwynethPayloadAttributes {
inner: EthPayloadAttributes {
Expand Down
35 changes: 34 additions & 1 deletion crates/node/builder/src/builder/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ mod states;
use reth_rpc_types::WithOtherFields;
pub use states::*;

use std::sync::Arc;
use std::{fs, path::PathBuf, sync::Arc};

use futures::Future;
use reth_chainspec::ChainSpec;
Expand Down Expand Up @@ -176,6 +176,39 @@ impl<DB> NodeBuilder<DB> {
WithLaunchContext { builder: self, task_executor }
}

/// Creates a Gwyneth node
pub fn gwyneth_node(
mut self,
task_executor: TaskExecutor,
chain_id: u64,
) -> WithLaunchContext<NodeBuilder<Arc<reth_db::test_utils::TempDatabase<reth_db::DatabaseEnv>>>>
{
let folder_name = format!("/data/reth/gwyneth-{}/", chain_id);
let path = reth_node_core::dirs::MaybePlatformPath::<DataDirPath>::from(
PathBuf::from(folder_name.clone()),
);

println!("path: {:?}", folder_name);

fs::create_dir_all(folder_name).expect("gwyneth db dir creation failed");

self.config = self.config.with_datadir_args(reth_node_core::args::DatadirArgs {
datadir: path.clone(),
..Default::default()
});

let data_dir =
path.unwrap_or_chain_default(self.config.chain.chain, self.config.datadir.clone());

println!("data_dir: {:?}", data_dir);

let db = reth_db::test_utils::create_test_rw_db_with_path(data_dir.db());

WithLaunchContext { builder: self.with_database(db), task_executor }
}



/// Creates an _ephemeral_ preconfigured node for testing purposes.
//#[cfg(feature = "test-utils")]
pub fn testing_node(
Expand Down
Loading

0 comments on commit be2e95a

Please sign in to comment.