Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(executor): Execute block of transactions and return tx patches #238

Merged
merged 4 commits into from
Nov 22, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 3 additions & 2 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

30 changes: 30 additions & 0 deletions crates/common/rlp/src/encode.rs
Original file line number Diff line number Diff line change
Expand Up @@ -337,6 +337,21 @@ where
}
}

pub fn encode_iter<'a, K>(i: impl Iterator<Item = &'a K> + Clone, out: &mut dyn BufMut)
where
K: Encodable + 'a,
{
let mut h = Header { list: true, payload_length: 0 };
for x in i.clone() {
h.payload_length += x.length();
}

h.encode(out);
for x in i {
x.encode(out);
}
}

pub fn encode_fixed_size<E: MaxEncodedLen<LEN>, const LEN: usize>(v: &E) -> ArrayVec<u8, LEN> {
let mut out = ArrayVec::from([0_u8; LEN]);

Expand Down Expand Up @@ -379,6 +394,12 @@ mod tests {
out1
}

fn encoded_iter<'a, T: Encodable + 'a>(iter: impl Iterator<Item = &'a T> + Clone) -> BytesMut {
let mut out = BytesMut::new();
encode_iter(iter, &mut out);
out
}

#[test]
fn rlp_str() {
assert_eq!(encoded("")[..], hex!("80")[..]);
Expand Down Expand Up @@ -534,6 +555,15 @@ mod tests {
assert_eq!(encoded_list(&[0xFFCCB5_u64, 0xFFC0B5_u64]), &hex!("c883ffccb583ffc0b5")[..]);
}

#[test]
fn rlp_iter() {
assert_eq!(encoded_iter::<u64>([].iter()), &hex!("c0")[..]);
assert_eq!(
encoded_iter([0xFFCCB5_u64, 0xFFC0B5_u64].iter()),
&hex!("c883ffccb583ffc0b5")[..]
);
}

#[cfg(feature = "smol_str")]
#[test]
fn rlp_smol_str() {
Expand Down
4 changes: 2 additions & 2 deletions crates/common/rlp/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,8 @@ pub use bytes::BufMut;

pub use decode::{Decodable, DecodeError, Rlp};
pub use encode::{
const_add, encode_fixed_size, encode_list, length_of_length, list_length, Encodable,
MaxEncodedLen, MaxEncodedLenAssoc,
const_add, encode_fixed_size, encode_iter, encode_list, length_of_length, list_length,
Encodable, MaxEncodedLen, MaxEncodedLenAssoc,
};
pub use types::*;

Expand Down
4 changes: 3 additions & 1 deletion crates/executor/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,9 @@ reth-interfaces = { path = "../interfaces" }
reth-rlp = { path = "../common/rlp" }
reth-consensus = { path = "../consensus" }

revm = "2.1"
revm = "2.2"
# remove from reth and reexport from revm
hashbrown = "0.12"

# common
async-trait = "0.1.57"
Expand Down
82 changes: 81 additions & 1 deletion crates/executor/src/config.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,85 @@
//! Reth block execution/validation configuration and constants

use reth_primitives::{BlockNumber, U256};

/// Configuration for executor
#[derive(Debug, Clone)]
pub struct Config {}
pub struct Config {
/// Chain id.
pub chain_id: U256,
/// Spec upgrades.
pub spec_upgrades: SpecUpgrades,
}

impl Config {
/// Create new config for ethereum.
pub fn new_ethereum() -> Self {
Self { chain_id: 1.into(), spec_upgrades: SpecUpgrades::new_ethereum() }
}
}

/// Spec with there ethereum codenames.
#[derive(Debug, Clone)]
#[allow(missing_docs)]
pub struct SpecUpgrades {
pub frontier: BlockNumber,
//pub frontier_thawing: BlockNumber,
pub homestead: BlockNumber,
//pub dao_fork: BlockNumber,
pub tangerine_whistle: BlockNumber,
pub spurious_dragon: BlockNumber,
pub byzantium: BlockNumber,
//pub constantinople: BlockNumber,
pub petersburg: BlockNumber, //Overrider Constantinople
pub istanbul: BlockNumber,
//pub muir_glacier: BlockNumber,
pub berlin: BlockNumber,
pub london: BlockNumber,
//pub arrow_glacier: BlockNumber,
//pub gray_glacier: BlockNumber,
pub paris: BlockNumber, // Aka the merge
pub shanghai: BlockNumber,
}

impl SpecUpgrades {
/// Ethereum mainnet spec
pub fn new_ethereum() -> Self {
Self {
frontier: 0,
//frontier_thawing: 200000,
homestead: 1150000,
//dao_fork: 1920000,
tangerine_whistle: 2463000,
spurious_dragon: 2675000,
byzantium: 4370000,
//constantinople: 7280000,
petersburg: 7280000, //Overrider Constantinople
istanbul: 9069000,
//muir_glacier: 9200000,
berlin: 12244000,
london: 12965000,
//arrow_glacier: 13773000,
//gray_glacier: 15050000,
paris: 15537394, // TheMerge,
shanghai: u64::MAX,
}
}

/// return revm_spec from spec configuration.
pub fn revm_spec(&self, for_block: BlockNumber) -> revm::SpecId {
match for_block {
b if self.shanghai >= b => revm::MERGE_EOF,
b if self.paris >= b => revm::MERGE,
b if self.london >= b => revm::LONDON,
b if self.berlin >= b => revm::BERLIN,
b if self.istanbul >= b => revm::ISTANBUL,
b if self.petersburg >= b => revm::PETERSBURG,
b if self.byzantium >= b => revm::BYZANTIUM,
b if self.spurious_dragon >= b => revm::SPURIOUS_DRAGON,
b if self.tangerine_whistle >= b => revm::TANGERINE,
b if self.homestead >= b => revm::HOMESTEAD,
b if self.frontier >= b => revm::FRONTIER,
_ => panic!("wrong configuration"),
}
}
}
Loading