refactor: split consensus crate (#1814)

This commit is contained in:
Matthias Seitz
2023-03-17 13:20:00 +01:00
committed by GitHub
parent f08a70dad8
commit 1a317f20e4
15 changed files with 79 additions and 51 deletions

15
Cargo.lock generated
View File

@ -4569,7 +4569,7 @@ dependencies = [
"metrics-exporter-prometheus",
"metrics-util",
"proptest",
"reth-consensus",
"reth-beacon-consensus",
"reth-db",
"reth-discv4",
"reth-downloaders",
@ -4598,6 +4598,16 @@ dependencies = [
"tui",
]
[[package]]
name = "reth-beacon-consensus"
version = "0.1.0"
dependencies = [
"reth-consensus-common",
"reth-interfaces",
"reth-primitives",
"tokio",
]
[[package]]
name = "reth-codecs"
version = "0.1.0"
@ -4614,7 +4624,7 @@ dependencies = [
]
[[package]]
name = "reth-consensus"
name = "reth-consensus-common"
version = "0.1.0"
dependencies = [
"assert_matches",
@ -4622,7 +4632,6 @@ dependencies = [
"reth-interfaces",
"reth-primitives",
"reth-provider",
"tokio",
]
[[package]]

View File

@ -1,7 +1,8 @@
[workspace]
members = [
"bin/reth",
"crates/consensus",
"crates/consensus/beacon",
"crates/consensus/common",
"crates/executor",
"crates/interfaces",
"crates/metrics/metrics-derive",

View File

@ -9,22 +9,22 @@ readme = "README.md"
[dependencies]
# reth
reth-primitives = { path = "../../crates/primitives", features = ["arbitrary"] }
reth-db = {path = "../../crates/storage/db", features = ["mdbx", "test-utils"] }
reth-db = { path = "../../crates/storage/db", features = ["mdbx", "test-utils"] }
# TODO: Temporary use of the test-utils feature
reth-provider = { path = "../../crates/storage/provider", features = ["test-utils"] }
reth-staged-sync = { path = "../../crates/staged-sync" }
reth-stages = { path = "../../crates/stages"}
reth-interfaces = { path = "../../crates/interfaces", features = ["test-utils"] }
reth-transaction-pool = { path = "../../crates/transaction-pool", features = ["test-utils"] }
reth-consensus = { path = "../../crates/consensus" }
reth-beacon-consensus = { path = "../../crates/consensus/beacon" }
reth-executor = { path = "../../crates/executor" }
reth-rpc-engine-api = { path = "../../crates/rpc/rpc-engine-api" }
reth-rpc-builder = { path = "../../crates/rpc/rpc-builder" }
reth-rpc = { path = "../../crates/rpc/rpc" }
reth-rlp = { path = "../../crates/rlp" }
reth-network = {path = "../../crates/net/network", features = ["serde"] }
reth-network-api = {path = "../../crates/net/network-api" }
reth-downloaders = {path = "../../crates/net/downloaders", features = ["test-utils"] }
reth-network = { path = "../../crates/net/network", features = ["serde"] }
reth-network-api = { path = "../../crates/net/network-api" }
reth-downloaders = { path = "../../crates/net/downloaders", features = ["test-utils"] }
reth-tracing = { path = "../../crates/tracing" }
reth-tasks = { path = "../../crates/tasks" }
reth-net-nat = { path = "../../crates/net/nat" }

View File

@ -5,7 +5,7 @@ use crate::{
use clap::{crate_version, Parser};
use eyre::Context;
use futures::{Stream, StreamExt};
use reth_consensus::beacon::BeaconConsensus;
use reth_beacon_consensus::BeaconConsensus;
use reth_db::mdbx::{Env, WriteMap};
use reth_downloaders::{
bodies::bodies::BodiesDownloaderBuilder,

View File

@ -13,7 +13,7 @@ use events::NodeEvent;
use eyre::Context;
use fdlimit::raise_fd_limit;
use futures::{pin_mut, stream::select as stream_select, Stream, StreamExt};
use reth_consensus::beacon::BeaconConsensus;
use reth_beacon_consensus::BeaconConsensus;
use reth_db::{
database::Database,
mdbx::{Env, WriteMap},

View File

@ -7,7 +7,7 @@ use crate::{
prometheus_exporter,
};
use clap::{Parser, ValueEnum};
use reth_consensus::beacon::BeaconConsensus;
use reth_beacon_consensus::BeaconConsensus;
use reth_downloaders::bodies::bodies::BodiesDownloaderBuilder;
use reth_primitives::ChainSpec;
use reth_provider::{ShareableDatabase, Transaction};

View File

@ -1,22 +0,0 @@
[package]
name = "reth-consensus"
version = "0.1.0"
edition = "2021"
license = "MIT OR Apache-2.0"
repository = "https://github.com/paradigmxyz/reth"
readme = "README.md"
[dependencies]
# reth
reth-primitives = { path = "../primitives" }
reth-interfaces = { path = "../interfaces" }
reth-provider = { path = "../storage/provider" }
# async
tokio = { version = "1", features = ["sync"] }
[dev-dependencies]
reth-interfaces = { path = "../interfaces", features = ["test-utils"] }
reth-provider = { path = "../storage/provider", features = ["test-utils"] }
assert_matches = "1.5.0"
mockall = "0.11.3"

View File

@ -0,0 +1,19 @@
[package]
name = "reth-beacon-consensus"
version = "0.1.0"
edition = "2021"
license = "MIT OR Apache-2.0"
repository = "https://github.com/paradigmxyz/reth"
readme = "README.md"
[dependencies]
# reth
reth-consensus-common = { path = "../common" }
reth-primitives = { path = "../../primitives" }
reth-interfaces = { path = "../../interfaces" }
# async
tokio = { version = "1", features = ["sync"] }
[dev-dependencies]
reth-interfaces = { path = "../../interfaces", features = ["test-utils"] }

View File

@ -1,9 +1,8 @@
//! Consensus for ethereum network
use std::sync::Arc;
use crate::validation;
use reth_consensus_common::validation;
use reth_interfaces::consensus::{Consensus, ConsensusError, ForkchoiceState};
use reth_primitives::{ChainSpec, Hardfork, SealedBlock, SealedHeader, EMPTY_OMMER_ROOT, U256};
use std::sync::Arc;
use tokio::sync::watch;
use super::BeaconConsensusBuilder;

View File

@ -0,0 +1,13 @@
#![warn(missing_docs, unreachable_pub, unused_crate_dependencies)]
#![deny(unused_must_use, rust_2018_idioms)]
#![doc(test(
no_crate_inject,
attr(deny(warnings, rust_2018_idioms), allow(dead_code, unused_variables))
))]
//! Beacon consensus implementation.
mod beacon_consensus;
mod builder;
pub use beacon_consensus::BeaconConsensus;
pub use builder::BeaconConsensusBuilder;

View File

@ -0,0 +1,20 @@
[package]
name = "reth-consensus-common"
version = "0.1.0"
edition = "2021"
license = "MIT OR Apache-2.0"
repository = "https://github.com/paradigmxyz/reth"
readme = "README.md"
[dependencies]
# reth
reth-primitives = { path = "../../primitives" }
reth-interfaces = { path = "../../interfaces" }
reth-provider = { path = "../../storage/provider" }
[dev-dependencies]
reth-interfaces = { path = "../../interfaces", features = ["test-utils"] }
reth-provider = { path = "../../storage/provider", features = ["test-utils"] }
assert_matches = "1.5.0"
mockall = "0.11.3"

View File

@ -4,10 +4,8 @@
no_crate_inject,
attr(deny(warnings, rust_2018_idioms), allow(dead_code, unused_variables))
))]
//! Consensus algorithms for Ethereum.
/// Beacon consensus implementation.
pub mod beacon;
//! Commonly used consensus methods.
/// Collection of consensus validation methods.
pub mod validation;

View File

@ -1,8 +1,8 @@
//! Collection of methods for block validation.
use reth_interfaces::{consensus::ConsensusError, Result as RethResult};
use reth_primitives::{
BlockNumber, ChainSpec, Hardfork, Header, InvalidTransactionError, SealedBlock, SealedHeader,
Transaction, TransactionSignedEcRecovered, TxEip1559, TxEip2930, TxLegacy,
constants, BlockNumber, ChainSpec, Hardfork, Header, InvalidTransactionError, SealedBlock,
SealedHeader, Transaction, TransactionSignedEcRecovered, TxEip1559, TxEip2930, TxLegacy,
};
use reth_provider::{AccountProvider, HeaderProvider, WithdrawalsProvider};
use std::{
@ -10,8 +10,6 @@ use std::{
time::SystemTime,
};
use reth_primitives::constants;
/// Validate header standalone
pub fn validate_header_standalone(
header: &SealedHeader,

View File

@ -1,7 +0,0 @@
//! Beacon consensus implementation.
mod beacon_consensus;
mod builder;
pub use beacon_consensus::BeaconConsensus;
pub use builder::BeaconConsensusBuilder;