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

View File

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

View File

@ -16,7 +16,7 @@ reth-staged-sync = { path = "../../crates/staged-sync" }
reth-stages = { path = "../../crates/stages"} reth-stages = { path = "../../crates/stages"}
reth-interfaces = { path = "../../crates/interfaces", features = ["test-utils"] } reth-interfaces = { path = "../../crates/interfaces", features = ["test-utils"] }
reth-transaction-pool = { path = "../../crates/transaction-pool", 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-executor = { path = "../../crates/executor" }
reth-rpc-engine-api = { path = "../../crates/rpc/rpc-engine-api" } reth-rpc-engine-api = { path = "../../crates/rpc/rpc-engine-api" }
reth-rpc-builder = { path = "../../crates/rpc/rpc-builder" } reth-rpc-builder = { path = "../../crates/rpc/rpc-builder" }

View File

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

View File

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

View File

@ -7,7 +7,7 @@ use crate::{
prometheus_exporter, prometheus_exporter,
}; };
use clap::{Parser, ValueEnum}; use clap::{Parser, ValueEnum};
use reth_consensus::beacon::BeaconConsensus; use reth_beacon_consensus::BeaconConsensus;
use reth_downloaders::bodies::bodies::BodiesDownloaderBuilder; use reth_downloaders::bodies::bodies::BodiesDownloaderBuilder;
use reth_primitives::ChainSpec; use reth_primitives::ChainSpec;
use reth_provider::{ShareableDatabase, Transaction}; 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 //! Consensus for ethereum network
use std::sync::Arc; use reth_consensus_common::validation;
use crate::validation;
use reth_interfaces::consensus::{Consensus, ConsensusError, ForkchoiceState}; use reth_interfaces::consensus::{Consensus, ConsensusError, ForkchoiceState};
use reth_primitives::{ChainSpec, Hardfork, SealedBlock, SealedHeader, EMPTY_OMMER_ROOT, U256}; use reth_primitives::{ChainSpec, Hardfork, SealedBlock, SealedHeader, EMPTY_OMMER_ROOT, U256};
use std::sync::Arc;
use tokio::sync::watch; use tokio::sync::watch;
use super::BeaconConsensusBuilder; 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, no_crate_inject,
attr(deny(warnings, rust_2018_idioms), allow(dead_code, unused_variables)) attr(deny(warnings, rust_2018_idioms), allow(dead_code, unused_variables))
))] ))]
//! Consensus algorithms for Ethereum.
/// Beacon consensus implementation. //! Commonly used consensus methods.
pub mod beacon;
/// Collection of consensus validation methods. /// Collection of consensus validation methods.
pub mod validation; pub mod validation;

View File

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