Skip to content

Commit

Permalink
deps: bump reth (#27)
Browse files Browse the repository at this point in the history
* backfill

* discv5

* op-bridge

* remote

* rollup

* chain spec parser

* tests

* oracle

* add oracle to readme

* sigh

* fix test
  • Loading branch information
shekhirin authored Oct 7, 2024
1 parent 88ac91c commit bd1c173
Show file tree
Hide file tree
Showing 27 changed files with 1,973 additions and 1,075 deletions.
2,623 changes: 1,719 additions & 904 deletions Cargo.lock

Large diffs are not rendered by default.

14 changes: 8 additions & 6 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -36,16 +36,18 @@ reth-node-ethereum = { git = "https://github.com/paradigmxyz/reth" }
reth-primitives = { git = "https://github.com/paradigmxyz/reth" }
reth-provider = { git = "https://github.com/paradigmxyz/reth" }
reth-revm = { git = "https://github.com/paradigmxyz/reth" }
reth-rpc-types = { git = "https://github.com/paradigmxyz/reth" }
reth-transaction-pool = { git = "https://github.com/paradigmxyz/reth" }
reth-tracing = { git = "https://github.com/paradigmxyz/reth" }



# alloy
alloy-sol-types = { version = "0.8", features = ["json"] }
alloy-signer-local = "0.3"
alloy-signer = "0.3"
alloy-eips = "0.4"
alloy-consensus = "0.4"
alloy-primitives = "0.8"
alloy-rlp = "0.3"
alloy-rpc-types = "0.4"
alloy-signer = "0.4"
alloy-signer-local = "0.4"
alloy-sol-types = { version = "0.8", features = ["json"] }

# async
futures = "0.3"
Expand Down
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ for new developers.
| [In Memory State](./in-memory-state) | Tracks the plain state in memory | `cargo run --bin in-memory-state -- node` |
| [Minimal](./minimal) | Logs every chain commit, reorg and revert notification | `cargo run --bin minimal -- node` |
| [OP Bridge](./op-bridge) | Decodes Optimism deposit and withdrawal receipts from L1 | `cargo run --bin op-bridge -- node` |
| [Oracle](./oracle) | Oracle protocol that observes off-chain data and attests to it on-chain | `cargo run --bin oracle -- node` |
| [Remote](./remote) | Emits notifications using a gRPC server, and a consumer that receives them | `cargo run --bin remote-exex -- node` to start Reth node with the ExEx and a gRPC server<br><br>`cargo run --bin remote-consumer` to start a gRPC client |
| [Rollup](./rollup) | Rollup that derives the state from L1 | `cargo run --bin rollup -- node` |

Expand Down
3 changes: 3 additions & 0 deletions backfill/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,9 @@ reth-node-ethereum.workspace = true
reth-tracing.workspace = true
reth.workspace = true

# alloy
alloy-primitives.workspace = true

# async
eyre.workspace = true
futures.workspace = true
Expand Down
12 changes: 7 additions & 5 deletions backfill/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,14 @@ mod rpc;

use std::{collections::HashMap, ops::RangeInclusive, sync::Arc};

use alloy_primitives::BlockNumber;
use clap::{Args, Parser};
use eyre::OptionExt;
use futures::{FutureExt, StreamExt, TryStreamExt};
use jsonrpsee::tracing::instrument;
use reth::{
args::utils::DefaultChainSpecParser,
primitives::{BlockId, BlockNumber, BlockNumberOrTag},
chainspec::EthereumChainSpecParser,
primitives::{BlockId, BlockNumberOrTag},
providers::{BlockIdReader, BlockReader, HeaderProvider, StateProviderFactory},
};
use reth_evm::execute::BlockExecutorProvider;
Expand Down Expand Up @@ -107,7 +108,7 @@ impl<Node: FullNodeComponents> BackfillExEx<Node> {
if let Some(committed_chain) = notification.committed_chain() {
process_committed_chain(&committed_chain)?;

self.ctx.events.send(ExExEvent::FinishedHeight(committed_chain.tip().number))?;
self.ctx.events.send(ExExEvent::FinishedHeight(committed_chain.tip().num_hash()))?;
}

Ok(())
Expand Down Expand Up @@ -233,7 +234,8 @@ async fn backfill_with_job<
fn process_committed_chain(chain: &Chain) -> eyre::Result<()> {
// Calculate the number of blocks and transactions in the committed chain
let blocks = chain.blocks().len();
let transactions = chain.blocks().values().map(|block| block.body.len()).sum::<usize>();
let transactions =
chain.blocks().values().map(|block| block.body.transactions.len()).sum::<usize>();

info!(first_block = %chain.execution_outcome().first_block, %blocks, %transactions, "Processed committed blocks");
Ok(())
Expand All @@ -251,7 +253,7 @@ struct BackfillArgsExt {
}

fn main() -> eyre::Result<()> {
reth::cli::Cli::<DefaultChainSpecParser, BackfillArgsExt>::parse().run(
reth::cli::Cli::<EthereumChainSpecParser, BackfillArgsExt>::parse().run(
|builder, args| async move {
// Create a channel for backfill requests. Sender will go to the RPC server, receiver
// will be used by the ExEx.
Expand Down
2 changes: 1 addition & 1 deletion backfill/src/rpc.rs
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
use alloy_primitives::BlockNumber;
use async_trait::async_trait;
use jsonrpsee::{
core::RpcResult,
proc_macros::rpc,
types::{error::INTERNAL_ERROR_CODE, ErrorObject},
};
use reth::primitives::BlockNumber;
use tokio::sync::{mpsc, oneshot};

use crate::BackfillMessage;
Expand Down
2 changes: 1 addition & 1 deletion discv5/src/exex/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ impl<Node: FullNodeComponents> Future for ExEx<Node> {
if let Some(committed_chain) = notification.committed_chain() {
self.exex
.events
.send(ExExEvent::FinishedHeight(committed_chain.tip().number))?;
.send(ExExEvent::FinishedHeight(committed_chain.tip().num_hash()))?;
}
}
}
Expand Down
4 changes: 2 additions & 2 deletions discv5/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,14 @@ use clap::Parser;

use exex::ExEx;
use network::{cli_ext::Discv5ArgsExt, DiscV5ExEx};
use reth::args::utils::DefaultChainSpecParser;
use reth::chainspec::EthereumChainSpecParser;
use reth_node_ethereum::EthereumNode;

mod exex;
mod network;

fn main() -> eyre::Result<()> {
reth::cli::Cli::<DefaultChainSpecParser, Discv5ArgsExt>::parse().run(
reth::cli::Cli::<EthereumChainSpecParser, Discv5ArgsExt>::parse().run(
|builder, args| async move {
let tcp_port = args.tcp_port;
let udp_port = args.udp_port;
Expand Down
8 changes: 5 additions & 3 deletions in-memory-state/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,9 @@ impl<Node: FullNodeComponents + Unpin> Future for InMemoryStateExEx<Node> {
if let Some(committed_chain) = notification.committed_chain() {
// extend the state with the new chain
this.execution_outcome.extend(committed_chain.execution_outcome().clone());
this.ctx.events.send(ExExEvent::FinishedHeight(committed_chain.tip().number))?;
this.ctx
.events
.send(ExExEvent::FinishedHeight(committed_chain.tip().num_hash()))?;
}
}

Expand Down Expand Up @@ -97,7 +99,7 @@ mod tests {
let block_number_1 = block_1.number;
let execution_outcome1 = ExecutionOutcome::new(
BundleState::default(),
vec![random_receipt(&mut rng, &block_1.body[0], None)].into(),
vec![random_receipt(&mut rng, &block_1.body.transactions[0], None)].into(),
block_1.number,
vec![],
);
Expand All @@ -121,7 +123,7 @@ mod tests {
.ok_or(eyre::eyre!("failed to recover senders"))?;
let execution_outcome2 = ExecutionOutcome::new(
BundleState::default(),
vec![random_receipt(&mut rng, &block_2.body[0], None)].into(),
vec![random_receipt(&mut rng, &block_2.body.transactions[0], None)].into(),
block_2.number,
vec![],
);
Expand Down
1 change: 1 addition & 0 deletions minimal/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ reth-execution-types.workspace = true

eyre.workspace = true
futures.workspace = true
serde_json.workspace = true

[dev-dependencies]
reth-exex-test-utils.workspace = true
Expand Down
25 changes: 19 additions & 6 deletions minimal/src/main.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
use futures::{Future, StreamExt};
use reth_exex::{ExExContext, ExExEvent, ExExNotification};
use reth::primitives::BlockNumHash;
use reth_exex::{ExExContext, ExExEvent, ExExHead, ExExNotification};
use reth_node_api::FullNodeComponents;
use reth_node_ethereum::EthereumNode;
use reth_tracing::tracing::info;
Expand All @@ -18,22 +19,34 @@ async fn exex_init<Node: FullNodeComponents>(
///
/// This ExEx just prints out whenever either a new chain of blocks being added, or a chain of
/// blocks being re-orged. After processing the chain, emits an [ExExEvent::FinishedHeight] event.
async fn exex<Node: FullNodeComponents>(mut ctx: ExExContext<Node>) -> eyre::Result<()> {
while let Some(notification) = ctx.notifications.next().await {
match &notification {
async fn exex<Node: FullNodeComponents>(ctx: ExExContext<Node>) -> eyre::Result<()> {
let head: BlockNumHash = if std::fs::exists("exex_head.json")? {
serde_json::from_str(&std::fs::read_to_string("exex_head.json")?)?
} else {
(ctx.head.number, ctx.head.hash).into()
};

let mut notifications = ctx.notifications.with_head(ExExHead { block: head });
while let Some(notification) = notifications.next().await.transpose()? {
let exex_head: BlockNumHash = match &notification {
ExExNotification::ChainCommitted { new } => {
info!(committed_chain = ?new.range(), "Received commit");
new.tip().num_hash()
}
ExExNotification::ChainReorged { old, new } => {
info!(from_chain = ?old.range(), to_chain = ?new.range(), "Received reorg");
new.tip().num_hash()
}
ExExNotification::ChainReverted { old } => {
info!(reverted_chain = ?old.range(), "Received revert");
(old.first().number - 1, old.first().parent_hash).into()
}
};

std::fs::write("exex_head.json", serde_json::to_string(&exex_head)?)?;

if let Some(committed_chain) = notification.committed_chain() {
ctx.events.send(ExExEvent::FinishedHeight(committed_chain.tip().number))?;
ctx.events.send(ExExEvent::FinishedHeight(committed_chain.tip().num_hash()))?;
}
}

Expand Down Expand Up @@ -86,7 +99,7 @@ mod tests {

// Check that the Execution Extension emitted a `FinishedHeight` event with the correct
// height
handle.assert_event_finished_height(head.number)?;
handle.assert_event_finished_height((head.number, head.hash).into())?;

Ok(())
}
Expand Down
16 changes: 13 additions & 3 deletions op-bridge/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -6,23 +6,33 @@ edition.workspace = true
license.workspace = true

[dependencies]
reth.workspace = true
# reth
reth-execution-types.workspace = true
reth-exex.workspace = true
reth-node-api.workspace = true
reth-node-ethereum.workspace = true
reth-primitives.workspace = true
reth-execution-types.workspace = true
reth-tracing.workspace = true
reth.workspace = true

# alloy
alloy-primitives.workspace = true
alloy-sol-types.workspace = true

# misc
eyre.workspace = true
futures.workspace = true
alloy-sol-types.workspace = true
rusqlite = { version = "0.31.0", features = ["bundled"] }
tokio.workspace = true

[dev-dependencies]
# reth
reth-exex-test-utils.workspace = true
reth-testing-utils.workspace = true

# alloy
alloy-consensus.workspace = true

tokio.workspace = true
rand = "0.8"
tempfile = "3"
43 changes: 29 additions & 14 deletions op-bridge/src/main.rs
Original file line number Diff line number Diff line change
@@ -1,10 +1,11 @@
use alloy_primitives::{address, Address};
use alloy_sol_types::{sol, SolEventInterface};
use futures::{Future, StreamExt};
use futures::{Future, FutureExt, StreamExt};
use reth_execution_types::Chain;
use reth_exex::{ExExContext, ExExEvent};
use reth_node_api::FullNodeComponents;
use reth_node_ethereum::EthereumNode;
use reth_primitives::{address, Address, Log, SealedBlockWithSenders, TransactionSigned};
use reth_primitives::{Log, SealedBlockWithSenders, TransactionSigned};
use reth_tracing::tracing::info;
use rusqlite::Connection;

Expand Down Expand Up @@ -198,7 +199,7 @@ async fn op_bridge_exex<Node: FullNodeComponents>(

// Send a finished height event, signaling the node that we don't need any blocks below
// this height anymore
ctx.events.send(ExExEvent::FinishedHeight(committed_chain.tip().number))?;
ctx.events.send(ExExEvent::FinishedHeight(committed_chain.tip().num_hash()))?;
}
}

Expand All @@ -218,7 +219,7 @@ fn decode_chain_into_events(
.flat_map(|(block, receipts)| {
block
.body
.iter()
.transactions()
.zip(receipts.iter().flatten())
.map(move |(tx, receipt)| (block, tx, receipt))
})
Expand All @@ -242,9 +243,23 @@ fn main() -> eyre::Result<()> {
reth::cli::Cli::parse_args().run(|builder, _| async move {
let handle = builder
.node(EthereumNode::default())
.install_exex("OPBridge", |ctx| async move {
let connection = Connection::open("op_bridge.db")?;
init(ctx, connection).await
.install_exex("OPBridge", move |ctx| {
// Rust seems to trigger a bogus higher-ranked lifetime error when using
// just an async closure here -- using `spawn_blocking` avoids this
// particular issue.
//
// To avoid the higher ranked lifetime error we use `spawn_blocking`
// which will move the closure to another blocking-allowed thread,
// then execute.
//
// Source: https://github.com/vados-cosmonic/wasmCloud/commit/440e8c377f6b02f45eacb02692e4d2fabd53a0ec
tokio::task::spawn_blocking(move || {
tokio::runtime::Handle::current().block_on(async move {
let connection = Connection::open("op_bridge.db")?;
init(ctx, connection).await
})
})
.map(|result| result.map_err(Into::into).and_then(|result| result))
})
.launch()
.await?;
Expand All @@ -257,13 +272,14 @@ fn main() -> eyre::Result<()> {
mod tests {
use std::pin::pin;

use alloy_consensus::TxLegacy;
use alloy_primitives::{Address, TxKind, U256};
use alloy_sol_types::SolEvent;
use reth::revm::db::BundleState;
use reth_execution_types::{Chain, ExecutionOutcome};
use reth_exex_test_utils::{test_exex_context, PollOnce};
use reth_primitives::{
Address, Block, Header, Log, Receipt, Transaction, TransactionSigned, TxKind, TxLegacy,
TxType, U256,
Block, BlockBody, Header, Log, Receipt, Transaction, TransactionSigned, TxType,
};
use reth_testing_utils::generators::sign_tx_with_random_key_pair;
use rusqlite::Connection;
Expand Down Expand Up @@ -331,8 +347,7 @@ mod tests {
// Construct a block
let block = Block {
header: Header::default(),
body: vec![deposit_tx, withdrawal_tx],
..Default::default()
body: BlockBody { transactions: vec![deposit_tx, withdrawal_tx], ..Default::default() },
}
.seal_slow()
.seal_with_senders()
Expand All @@ -345,7 +360,7 @@ mod tests {
BundleState::default(),
vec![deposit_tx_receipt, withdrawal_tx_receipt].into(),
block.number,
vec![block.requests.clone().unwrap_or_default()],
vec![block.body.requests.clone().unwrap_or_default()],
),
None,
);
Expand Down Expand Up @@ -373,7 +388,7 @@ mod tests {
from_address.to_string(),
to_address.to_string(),
deposit_event.amount.to_string(),
block.body[0].hash().to_string()
block.body.transactions[0].hash().to_string()
)
);

Expand All @@ -393,7 +408,7 @@ mod tests {
from_address.to_string(),
to_address.to_string(),
withdrawal_event.amount.to_string(),
block.body[1].hash().to_string()
block.body.transactions[1].hash().to_string()
)
);

Expand Down
Loading

0 comments on commit bd1c173

Please sign in to comment.