Small skeleton for executor abstraction (#14)

This commit is contained in:
rakita
2022-10-06 16:01:23 +02:00
committed by GitHub
parent 321683679a
commit 074f452275
12 changed files with 303 additions and 4 deletions

191
Cargo.lock generated
View File

@ -2,6 +2,17 @@
# It is not intended for manual editing. # It is not intended for manual editing.
version = 3 version = 3
[[package]]
name = "ahash"
version = "0.7.6"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "fcb51a0695d8f838b1ee009b3fbf66bda078cd64590202a864a8f3e8c4315c47"
dependencies = [
"getrandom",
"once_cell",
"version_check",
]
[[package]] [[package]]
name = "aho-corasick" name = "aho-corasick"
version = "0.7.19" version = "0.7.19"
@ -17,6 +28,12 @@ version = "1.0.65"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "98161a4e3e2184da77bb14f02184cdd111e83bbbcc9979dfee3c44b9a85f5602" checksum = "98161a4e3e2184da77bb14f02184cdd111e83bbbcc9979dfee3c44b9a85f5602"
[[package]]
name = "arrayref"
version = "0.3.6"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "a4c527152e37cf757a3f78aae5a06fbeefdb07ccc535c980a3208ee3060dd544"
[[package]] [[package]]
name = "arrayvec" name = "arrayvec"
version = "0.7.2" version = "0.7.2"
@ -610,6 +627,9 @@ name = "hashbrown"
version = "0.12.3" version = "0.12.3"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "8a9ee70c43aaf417c914396645a0fa852624801b24ebb7ae78fe8272889ac888" checksum = "8a9ee70c43aaf417c914396645a0fa852624801b24ebb7ae78fe8272889ac888"
dependencies = [
"ahash",
]
[[package]] [[package]]
name = "heck" name = "heck"
@ -884,6 +904,9 @@ name = "lazy_static"
version = "1.4.0" version = "1.4.0"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "e2abad23fbc42b3700f2f279844dc832adb2b2eb069b2df918f455c4e18cc646" checksum = "e2abad23fbc42b3700f2f279844dc832adb2b2eb069b2df918f455c4e18cc646"
dependencies = [
"spin",
]
[[package]] [[package]]
name = "lazycell" name = "lazycell"
@ -987,6 +1010,40 @@ dependencies = [
"minimal-lexical", "minimal-lexical",
] ]
[[package]]
name = "num"
version = "0.4.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "43db66d1170d347f9a065114077f7dccb00c1b9478c89384490a3425279a4606"
dependencies = [
"num-bigint",
"num-complex",
"num-integer",
"num-iter",
"num-rational",
"num-traits",
]
[[package]]
name = "num-bigint"
version = "0.4.3"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "f93ab6289c7b344a8a9f60f88d80aa20032336fe78da341afc91c8a2341fc75f"
dependencies = [
"autocfg",
"num-integer",
"num-traits",
]
[[package]]
name = "num-complex"
version = "0.4.2"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "7ae39348c8bc5fbd7f40c727a9925f03517afd2ab27d46702108b6a7e5414c19"
dependencies = [
"num-traits",
]
[[package]] [[package]]
name = "num-integer" name = "num-integer"
version = "0.1.45" version = "0.1.45"
@ -997,6 +1054,29 @@ dependencies = [
"num-traits", "num-traits",
] ]
[[package]]
name = "num-iter"
version = "0.1.43"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "7d03e6c028c5dc5cac6e2dec0efda81fc887605bb3d884578bb6d6bf7514e252"
dependencies = [
"autocfg",
"num-integer",
"num-traits",
]
[[package]]
name = "num-rational"
version = "0.4.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "0638a1c9d0a3c0914158145bc76cff373a75a627e6ecbfb71cbe6f453a5a19b0"
dependencies = [
"autocfg",
"num-bigint",
"num-integer",
"num-traits",
]
[[package]] [[package]]
name = "num-traits" name = "num-traits"
version = "0.2.15" version = "0.2.15"
@ -1016,6 +1096,27 @@ dependencies = [
"libc", "libc",
] ]
[[package]]
name = "num_enum"
version = "0.5.7"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "cf5395665662ef45796a4ff5486c5d41d29e0c09640af4c5f17fd94ee2c119c9"
dependencies = [
"num_enum_derive",
]
[[package]]
name = "num_enum_derive"
version = "0.5.7"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "3b0498641e53dd6ac1a4f22547548caa6864cc4933784319cd1775271c5a46ce"
dependencies = [
"proc-macro-crate",
"proc-macro2",
"quote",
"syn",
]
[[package]] [[package]]
name = "once_cell" name = "once_cell"
version = "1.15.0" version = "1.15.0"
@ -1277,12 +1378,21 @@ dependencies = [
[[package]] [[package]]
name = "reth-executor" name = "reth-executor"
version = "0.1.0" version = "0.1.0"
dependencies = [
"anyhow",
"async-trait",
"reth-interfaces",
"reth-primitives",
"revm",
"thiserror",
]
[[package]] [[package]]
name = "reth-interfaces" name = "reth-interfaces"
version = "0.1.0" version = "0.1.0"
dependencies = [ dependencies = [
"async-trait", "async-trait",
"auto_impl",
"reth-primitives", "reth-primitives",
"thiserror", "thiserror",
] ]
@ -1339,6 +1449,41 @@ dependencies = [
"thiserror", "thiserror",
] ]
[[package]]
name = "revm"
version = "2.1.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "87344ffd3eec06b568e1fc69c225e4cbd8d68d8d9051b6d2652d596947efa1ce"
dependencies = [
"arrayref",
"auto_impl",
"bytes",
"hashbrown",
"num_enum",
"primitive-types",
"revm_precompiles",
"rlp",
"sha3",
]
[[package]]
name = "revm_precompiles"
version = "1.1.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "00e68901326fe20437526cb6d64a2898d2976383b7d222329dfce1717902da50"
dependencies = [
"bytes",
"hashbrown",
"num",
"once_cell",
"primitive-types",
"ripemd",
"secp256k1",
"sha2",
"sha3",
"substrate-bn",
]
[[package]] [[package]]
name = "rfc6979" name = "rfc6979"
version = "0.3.0" version = "0.3.0"
@ -1350,6 +1495,15 @@ dependencies = [
"zeroize", "zeroize",
] ]
[[package]]
name = "ripemd"
version = "0.1.3"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "bd124222d17ad93a644ed9d011a40f4fb64aa54275c08cc216524a9ea82fb09f"
dependencies = [
"digest 0.10.5",
]
[[package]] [[package]]
name = "rlp" name = "rlp"
version = "0.5.1" version = "0.5.1"
@ -1435,6 +1589,24 @@ dependencies = [
"zeroize", "zeroize",
] ]
[[package]]
name = "secp256k1"
version = "0.24.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "b7649a0b3ffb32636e60c7ce0d70511eda9c52c658cd0634e194d5a19943aeff"
dependencies = [
"secp256k1-sys",
]
[[package]]
name = "secp256k1-sys"
version = "0.6.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "7058dc8eaf3f2810d7828680320acda0b25a288f6d288e19278e249bbf74226b"
dependencies = [
"cc",
]
[[package]] [[package]]
name = "semver" name = "semver"
version = "1.0.14" version = "1.0.14"
@ -1562,6 +1734,12 @@ dependencies = [
"sha-1", "sha-1",
] ]
[[package]]
name = "spin"
version = "0.5.2"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "6e63cff320ae2c57904679ba7cb63280a3dc4613885beafb148ee7bf9aa9042d"
[[package]] [[package]]
name = "spki" name = "spki"
version = "0.6.0" version = "0.6.0"
@ -1600,6 +1778,19 @@ dependencies = [
"syn", "syn",
] ]
[[package]]
name = "substrate-bn"
version = "0.6.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "72b5bbfa79abbae15dd642ea8176a21a635ff3c00059961d1ea27ad04e5b441c"
dependencies = [
"byteorder",
"crunchy",
"lazy_static",
"rand",
"rustc-hex",
]
[[package]] [[package]]
name = "subtle" name = "subtle"
version = "2.4.1" version = "2.4.1"

View File

@ -21,4 +21,4 @@ members = [
[[bin]] [[bin]]
path = "bin/reth.rs" path = "bin/reth.rs"
name = "reth" name = "reth"

View File

@ -7,3 +7,9 @@ repository = "https://github.com/foundry-rs/reth"
readme = "README.md" readme = "README.md"
[dependencies] [dependencies]
revm = "2.1"
reth-primitives = { path = "../primitives" }
reth-interfaces = { path = "../interfaces" }
async-trait = "0.1.57"
thiserror = "1.0.37"
anyhow = "1.0"

View File

@ -0,0 +1,6 @@
/// Configuration for executor (TODO)
#[derive(Debug, Clone)]
pub struct Config {
/// Example
pub example: bool,
}

View File

@ -0,0 +1,37 @@
#![allow(missing_debug_implementations)]
use crate::Config;
use reth_interfaces::{
consensus::Consensus,
executor::{BlockExecutor, Error, ExecutorDb},
};
use reth_primitives::Block;
/// Main block executor
pub struct Executor {
/// Configuration, Spec and optional flags.
config: Config,
/// Database
db: Box<dyn ExecutorDb>,
/// Consensus
consensus: Box<dyn Consensus>,
}
impl Executor {
/// Create new Executor
pub fn new(config: Config, db: Box<dyn ExecutorDb>, consensus: Box<dyn Consensus>) -> Self {
Self { config, db, consensus }
}
/// Verify block (TODO)
pub fn verify(&self, block: &Block) -> Result<(), Error> {
// TODO example
let _ = self.consensus.validate_header(&block.header);
if self.config.example {
let _block_exist = self.db.get_block(block.header.number);
}
Err(Error::VerificationFailed)
}
}
impl BlockExecutor for Executor {}

View File

@ -6,3 +6,9 @@
))] ))]
//! Reth executor executes transaction in block of data. //! Reth executor executes transaction in block of data.
mod cfg;
/// Executor
pub mod executor;
pub use cfg::Config;

View File

@ -9,4 +9,5 @@ readme = "README.md"
[dependencies] [dependencies]
reth-primitives = { path = "../primitives" } reth-primitives = { path = "../primitives" }
async-trait = "0.1.57" async-trait = "0.1.57"
thiserror = "1.0.37" thiserror = "1.0.37"
auto_impl = "1.0"

View File

@ -0,0 +1,21 @@
use async_trait::async_trait;
use reth_primitives::Header;
use thiserror::Error;
/// Consensus is a protocol that chooses canonical chain.
/// We are checking validity of block header here.
#[async_trait]
pub trait Consensus {
/// Validate if header is correct and follows consensus specification
fn validate_header(&self, _header: &Header) -> Result<(), Error> {
Ok(())
}
}
/// Consensus errors (TODO)
#[derive(Error, Debug)]
pub enum Error {
/// Explanatory
#[error("Example of consensus error")]
ConsensusError,
}

View File

@ -1,5 +1,5 @@
use async_trait::async_trait; use async_trait::async_trait;
use reth_primitives::Block; use reth_primitives::{Address, Block, BlockNumber, StorageKey, StorageValue};
use thiserror::Error; use thiserror::Error;
/// Takes block and executes it, returns error /// Takes block and executes it, returns error
@ -18,3 +18,12 @@ pub enum Error {
#[error("Example of error.")] #[error("Example of error.")]
VerificationFailed, VerificationFailed,
} }
/// Function needed for executor
pub trait ExecutorDb {
/// Get Block by BlockNumber.
fn get_block(&self, _height: BlockNumber) -> Option<Block>;
/// Get storage.
fn get_storage(&self, account: Address, storage_key: StorageKey) -> Option<StorageValue>;
}

View File

@ -9,3 +9,6 @@
/// Block Execution traits. /// Block Execution traits.
pub mod executor; pub mod executor;
/// Consensus traits.
pub mod consensus;

View File

@ -0,0 +1,9 @@
#[derive(Clone, Copy, Debug, PartialEq, Eq)]
pub struct Account {
pub nonce: u64,
pub balance: U256,
pub bytecode_hash: H256,
}

View File

@ -19,10 +19,20 @@ pub use log::Log;
pub use receipt::Receipt; pub use receipt::Receipt;
pub use transaction::{Transaction, TransactionSigned, TxType}; pub use transaction::{Transaction, TransactionSigned, TxType};
/// Block Number /// Block Number is height of chain
pub type BlockNumber = u64; pub type BlockNumber = u64;
/// Ethereum address /// Ethereum address
pub type Address = H160; pub type Address = H160;
/// BlockId is Keccak hash of the header
pub type BlockID = H256;
/// TxHash is Kecack hash of rlp encoded signed transaction
pub type TxHash = H256;
/// Storage Key
pub type StorageKey = H256;
/// Storage value
pub type StorageValue = H256;
// NOTE: There is a benefit of using wrapped Bytes as it gives us serde and debug // NOTE: There is a benefit of using wrapped Bytes as it gives us serde and debug
pub use ethers_core::{ pub use ethers_core::{