Skip to content

Commit

Permalink
Accept ommers on ethereum block primitive
Browse files Browse the repository at this point in the history
  • Loading branch information
Lohann committed Nov 24, 2023
1 parent c293115 commit d5de484
Show file tree
Hide file tree
Showing 42 changed files with 4,605 additions and 162 deletions.
253 changes: 174 additions & 79 deletions Cargo.lock

Large diffs are not rendered by default.

27 changes: 24 additions & 3 deletions chains/ethereum/backend/src/jsonrpsee.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ use jsonrpsee_core::{
rpc_params, Error,
};
use rosetta_ethereum_primitives::{
rpc::RpcTransaction, Address, Block, BlockIdentifier, Bytes, EIP1186ProofResponse, Log,
rpc::RpcTransaction, Address, Block, BlockIdentifier, Bytes, EIP1186ProofResponse, Header, Log,
TransactionReceipt, TxHash, H256, U256, U64,
};

Expand Down Expand Up @@ -254,10 +254,10 @@ where
}

/// Returns information about a block.
async fn block_with_transactions(
async fn block_full(
&self,
at: AtBlock,
) -> Result<Option<Block<RpcTransaction>>, Self::Error> {
) -> Result<Option<Block<RpcTransaction, Header>>, Self::Error> {
let block = if let AtBlock::At(BlockIdentifier::Hash(block_hash)) = at {
<T as ClientT>::request::<Block<RpcTransaction>, _>(
&self.0,
Expand All @@ -273,6 +273,27 @@ where
)
.await?
};

let at = BlockIdentifier::Hash(block.hash);
let mut ommers = Vec::with_capacity(block.uncles.len());
for index in 0..block.uncles.len() {
let uncle = <T as ClientT>::request::<Header, _>(
&self.0,
"eth_getUncleByBlockHashAndIndex",
rpc_params![at, U64::from(index)],
)
.await?;
ommers.push(uncle);
}
let block = Block {
hash: block.hash,
header: block.header,
total_difficulty: block.total_difficulty,
seal_fields: block.seal_fields,
transactions: block.transactions,
uncles: ommers,
size: block.size,
};
Ok(Some(block))
}

Expand Down
8 changes: 4 additions & 4 deletions chains/ethereum/backend/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,8 @@ use alloc::{borrow::Cow, boxed::Box, string::String, vec::Vec};
use futures_core::{future::BoxFuture, Future};
use rosetta_ethereum_primitives::{
rpc::{CallRequest, RpcTransaction},
Address, Block, BlockIdentifier, Bytes, EIP1186ProofResponse, Log, TransactionReceipt, TxHash,
H256, U256, U64,
Address, Block, BlockIdentifier, Bytes, EIP1186ProofResponse, Header, Log, TransactionReceipt,
TxHash, H256, U256, U64,
};

/// Re-exports for proc-macro library to not require any additional
Expand Down Expand Up @@ -238,10 +238,10 @@ pub trait EthereumRpc {
async fn block(&self, at: AtBlock) -> Result<Option<Block<H256>>, Self::Error>;

/// Returns information about a block.
async fn block_with_transactions(
async fn block_full(
&self,
at: AtBlock,
) -> Result<Option<Block<RpcTransaction>>, Self::Error>;
) -> Result<Option<Block<RpcTransaction, Header>>, Self::Error>;

/// Returns the currently configured chain ID, a value used in replay-protected
/// transaction signing as introduced by EIP-155.
Expand Down
7 changes: 6 additions & 1 deletion chains/ethereum/executor/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ thiserror = { version = "1.0", optional = true }
revm = { version = "3.5", default-features = false, features = ["std", "c-kzg", "secp256k1", "optional_no_base_fee", "optional_block_gas_limit", "optional_eip3607"], optional = true }

# Sputnik EVM dependencies
hex-literal = { version = "0.4" }
libsecp256k1 = { version = "0.7", default-features = false, features = ["static-context"], optional = true }
num = { version = "0.4", default-features = false, features = ["alloc"], optional = true }
ripemd = { version = "0.1", default-features = false, optional = true }
Expand All @@ -32,7 +33,6 @@ tracing = { version = "0.1", default-features = false, features = ["attributes"]

[dev-dependencies]
hex = { version = "0.4" }
hex-literal = { version = "0.4" }
serde = { version = "1.0", features = ["derive"] }
serde_json = { version = "1.0" }

Expand All @@ -50,6 +50,9 @@ with-serde = [
"sputnik-evm/with-serde",
"rosetta-ethereum-primitives/with-serde",
]
with-rlp = [
"rosetta-ethereum-primitives/with-rlp",
]
rust-evm = ["dep:revm", "dep:tracing"]
sputnik-evm = [
"dep:libsecp256k1",
Expand All @@ -60,6 +63,8 @@ sputnik-evm = [
"dep:sputnik-evm",
"dep:substrate-bn",
"dep:tracing",
"sputnik-evm/tracing",
"sputnik-evm/force-debug",
]
std = [
"dep:thiserror",
Expand Down
69 changes: 69 additions & 0 deletions chains/ethereum/executor/src/chain_spec.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,69 @@
mod chain_config;
mod chain_id;
mod genesis;
mod hard_fork;

use alloc::collections::BTreeMap;
pub use chain_config::ChainConfig;
pub use chain_id::ChainId;
pub use genesis::{Genesis, MAINNET_GENESIS};
pub use hard_fork::{ForkCondition, Hardfork};
use rosetta_ethereum_primitives::H256;

/// An Ethereum chain specification.
///
/// A chain specification describes:
///
/// - Meta-information about the chain (the chain ID)
/// - The genesis block of the chain ([`Genesis`])
/// - What hardforks are activated, and under which conditions
#[derive(Debug, Clone)]
pub struct ChainSpec {
/// The chain ID
pub chain_id: ChainId,

/// The hash of the genesis block.
///
/// This acts as a small cache for known chains. If the chain is known, then the genesis hash
/// is also known ahead of time, and this will be `Some`.
// #[serde(skip, default)]
pub genesis_hash: Option<H256>,

/// The genesis block
pub genesis: Genesis,

// /// The block at which [Hardfork::Paris] was activated and the final difficulty at this
// block. // #[serde(skip, default)]
// pub paris_block_and_final_difficulty: Option<(u64, U256)>,

// // #[serde(skip, default)]
// /// Timestamps of various hardforks
// ///
// /// This caches entries in `hardforks` map
// pub fork_timestamps: ForkTimestamps,
/// The active hard forks and their activation conditions
pub hardforks: BTreeMap<Hardfork, ForkCondition>,

// #[serde(skip, default)]
/// The deposit contract deployed for PoS
// pub deposit_contract: Option<DepositContract>,

// /// The parameters that configure how a block's base fee is computed
// pub base_fee_params: BaseFeeParams,

// #[serde(default)]
/// The delete limit for pruner, per block. In the actual pruner run it will be multiplied by
/// the amount of blocks between pruner runs to account for the difference in amount of new
/// data coming in.
pub prune_delete_limit: usize,

/// The block interval for creating snapshots. Each snapshot will have that much blocks in it.
pub snapshot_block_interval: u64,
}

impl ChainSpec {
/// Get the fork condition for the given fork.
pub fn fork(&self, fork: Hardfork) -> ForkCondition {
self.hardforks.get(&fork).copied().unwrap_or(ForkCondition::Never)
}
}
177 changes: 177 additions & 0 deletions chains/ethereum/executor/src/chain_spec/chain_config.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,177 @@
#[cfg(feature = "with-serde")]
use rosetta_ethereum_primitives::serde_utils::uint_hex_or_decimal;
use rosetta_ethereum_primitives::{H256, U256};

use super::chain_id::ChainId;

/// Represents a node's chain configuration.
///
/// See [geth's `ChainConfig`
/// struct](https://github.com/ethereum/go-ethereum/blob/64dccf7aa411c5c7cd36090c3d9b9892945ae813/params/config.go#L349)
/// for the source of each field.
#[derive(Clone, Debug, Default, PartialEq, Eq)]
#[cfg_attr(
feature = "with-codec",
derive(parity_scale_codec::Encode, parity_scale_codec::Decode, scale_info::TypeInfo)
)]
#[cfg_attr(
feature = "with-serde",
derive(serde::Serialize, serde::Deserialize),
serde(default, rename_all = "camelCase")
)]
pub struct ChainConfig {
/// The network's chain ID.
#[cfg_attr(feature = "with-serde", serde(default = "mainnet_id"))]
pub chain_id: ChainId,

/// The homestead switch block (None = no fork, 0 = already homestead).
#[cfg_attr(
feature = "with-serde",
serde(skip_serializing_if = "Option::is_none", with = "uint_hex_or_decimal")
)]
pub homestead_block: Option<u64>,

/// The DAO fork switch block (None = no fork).
#[cfg_attr(
feature = "with-serde",
serde(skip_serializing_if = "Option::is_none", with = "uint_hex_or_decimal")
)]
pub dao_fork_block: Option<u64>,

/// Whether or not the node supports the DAO hard-fork.
pub dao_fork_support: bool,

/// The EIP-150 hard fork block (None = no fork).
#[cfg_attr(
feature = "with-serde",
serde(skip_serializing_if = "Option::is_none", with = "uint_hex_or_decimal")
)]
pub eip150_block: Option<u64>,

/// The EIP-150 hard fork hash.
#[cfg_attr(feature = "with-serde", serde(skip_serializing_if = "Option::is_none"))]
pub eip150_hash: Option<H256>,

/// The EIP-155 hard fork block.
#[cfg_attr(
feature = "with-serde",
serde(skip_serializing_if = "Option::is_none", with = "uint_hex_or_decimal")
)]
pub eip155_block: Option<u64>,

/// The EIP-158 hard fork block.
#[cfg_attr(
feature = "with-serde",
serde(skip_serializing_if = "Option::is_none", with = "uint_hex_or_decimal")
)]
pub eip158_block: Option<u64>,

/// The Byzantium hard fork block.
#[cfg_attr(
feature = "with-serde",
serde(skip_serializing_if = "Option::is_none", with = "uint_hex_or_decimal")
)]
pub byzantium_block: Option<u64>,

/// The Constantinople hard fork block.
#[cfg_attr(
feature = "with-serde",
serde(skip_serializing_if = "Option::is_none", with = "uint_hex_or_decimal")
)]
pub constantinople_block: Option<u64>,

/// The Petersburg hard fork block.
#[cfg_attr(
feature = "with-serde",
serde(skip_serializing_if = "Option::is_none", with = "uint_hex_or_decimal")
)]
pub petersburg_block: Option<u64>,

/// The Istanbul hard fork block.
#[cfg_attr(
feature = "with-serde",
serde(skip_serializing_if = "Option::is_none", with = "uint_hex_or_decimal")
)]
pub istanbul_block: Option<u64>,

/// The Muir Glacier hard fork block.
#[cfg_attr(
feature = "with-serde",
serde(skip_serializing_if = "Option::is_none", with = "uint_hex_or_decimal")
)]
pub muir_glacier_block: Option<u64>,

/// The Berlin hard fork block.
#[cfg_attr(
feature = "with-serde",
serde(skip_serializing_if = "Option::is_none", with = "uint_hex_or_decimal")
)]
pub berlin_block: Option<u64>,

/// The London hard fork block.
#[cfg_attr(
feature = "with-serde",
serde(skip_serializing_if = "Option::is_none", with = "uint_hex_or_decimal")
)]
pub london_block: Option<u64>,

/// The Arrow Glacier hard fork block.
#[cfg_attr(
feature = "with-serde",
serde(skip_serializing_if = "Option::is_none", with = "uint_hex_or_decimal")
)]
pub arrow_glacier_block: Option<u64>,

/// The Gray Glacier hard fork block.
#[cfg_attr(
feature = "with-serde",
serde(skip_serializing_if = "Option::is_none", with = "uint_hex_or_decimal")
)]
pub gray_glacier_block: Option<u64>,

/// Virtual fork after the merge to use as a network splitter.
#[cfg_attr(
feature = "with-serde",
serde(skip_serializing_if = "Option::is_none", with = "uint_hex_or_decimal")
)]
pub merge_netsplit_block: Option<u64>,

/// Shanghai switch time.
#[cfg_attr(
feature = "with-serde",
serde(skip_serializing_if = "Option::is_none", with = "uint_hex_or_decimal")
)]
pub shanghai_time: Option<u64>,

/// Cancun switch time.
#[cfg_attr(
feature = "with-serde",
serde(skip_serializing_if = "Option::is_none", with = "uint_hex_or_decimal")
)]
pub cancun_time: Option<u64>,

/// Total difficulty reached that triggers the merge consensus upgrade.
#[cfg_attr(feature = "with-serde", serde(
skip_serializing_if = "Option::is_none",
// deserialize_with = "deserialize_json_ttd_opt"
))]
pub terminal_total_difficulty: Option<U256>,

/// A flag specifying that the network already passed the terminal total difficulty. Its
/// purpose is to disable legacy sync without having seen the TTD locally.
pub terminal_total_difficulty_passed: bool,
// /// Ethash parameters.
// #[cfg_attr(feature = "with-serde", serde(skip_serializing_if = "Option::is_none"))]
// pub ethash: Option<EthashConfig>,

// /// Clique parameters.
// #[cfg_attr(feature = "with-serde", serde(skip_serializing_if = "Option::is_none"))]
// pub clique: Option<CliqueConfig>,
}

// used only for serde
#[cfg(feature = "with-serde")]
#[inline]
const fn mainnet_id() -> ChainId {
ChainId::MAINNET
}
Loading

0 comments on commit d5de484

Please sign in to comment.