Skip to content

Commit

Permalink
Merge pull request #22 from weaveVM/precompile-infrastructure
Browse files Browse the repository at this point in the history
feat: Add precompile infrastructure
  • Loading branch information
andreespirela authored Aug 1, 2024
2 parents 3ddba6e + 92cd4d1 commit 8175e78
Show file tree
Hide file tree
Showing 127 changed files with 1,376 additions and 898 deletions.
28 changes: 28 additions & 0 deletions Cargo.lock

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

1 change: 1 addition & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -146,6 +146,7 @@ members = [
"wvm-apps/wvm-exexed/crates/repository/",
"wvm-apps/wvm-exexed/crates/exex-etl/",
"wvm-apps/wvm-exexed/crates/lambda/",
"wvm-apps/wvm-exexed/crates/precompiles/",
"wvm-apps/wvm-exexed/crates/bigquery/",
"wvm-apps/wvm-exexed/crates/wevm-borsh/",
"wvm-apps/wvm-exexed/crates/types/",
Expand Down
4 changes: 2 additions & 2 deletions bin/reth/src/commands/debug_cmd/in_memory_merkle.rs
Original file line number Diff line number Diff line change
Expand Up @@ -196,8 +196,8 @@ impl Command {
match (in_mem_updates_iter.next(), incremental_updates_iter.next()) {
(Some(in_mem), Some(incr)) => {
similar_asserts::assert_eq!(in_mem.0, incr.0, "Nibbles don't match");
if in_mem.1 != incr.1 &&
in_mem.0.len() > self.skip_node_depth.unwrap_or_default()
if in_mem.1 != incr.1
&& in_mem.0.len() > self.skip_node_depth.unwrap_or_default()
{
in_mem_mismatched.push(in_mem);
incremental_mismatched.push(incr);
Expand Down
16 changes: 8 additions & 8 deletions bin/reth/src/commands/debug_cmd/merkle.rs
Original file line number Diff line number Diff line change
Expand Up @@ -221,14 +221,14 @@ impl Command {
let mut clean_account_mismatched = Vec::new();
let mut incremental_account_trie_iter = incremental_account_trie.into_iter().peekable();
let mut clean_account_trie_iter = clean_account_trie.into_iter().peekable();
while incremental_account_trie_iter.peek().is_some() ||
clean_account_trie_iter.peek().is_some()
while incremental_account_trie_iter.peek().is_some()
|| clean_account_trie_iter.peek().is_some()
{
match (incremental_account_trie_iter.next(), clean_account_trie_iter.next()) {
(Some(incremental), Some(clean)) => {
similar_asserts::assert_eq!(incremental.0, clean.0, "Nibbles don't match");
if incremental.1 != clean.1 &&
clean.0 .0.len() > self.skip_node_depth.unwrap_or_default()
if incremental.1 != clean.1
&& clean.0 .0.len() > self.skip_node_depth.unwrap_or_default()
{
incremental_account_mismatched.push(incremental);
clean_account_mismatched.push(clean);
Expand All @@ -250,13 +250,13 @@ impl Command {
let mut first_mismatched_storage = None;
let mut incremental_storage_trie_iter = incremental_storage_trie.into_iter().peekable();
let mut clean_storage_trie_iter = clean_storage_trie.into_iter().peekable();
while incremental_storage_trie_iter.peek().is_some() ||
clean_storage_trie_iter.peek().is_some()
while incremental_storage_trie_iter.peek().is_some()
|| clean_storage_trie_iter.peek().is_some()
{
match (incremental_storage_trie_iter.next(), clean_storage_trie_iter.next()) {
(Some(incremental), Some(clean)) => {
if incremental != clean &&
clean.1.nibbles.len() > self.skip_node_depth.unwrap_or_default()
if incremental != clean
&& clean.1.nibbles.len() > self.skip_node_depth.unwrap_or_default()
{
first_mismatched_storage = Some((incremental, clean));
break;
Expand Down
4 changes: 2 additions & 2 deletions bin/reth/src/commands/import.rs
Original file line number Diff line number Diff line change
Expand Up @@ -126,8 +126,8 @@ impl ImportCommand {
let total_imported_blocks = provider.tx_ref().entries::<tables::HeaderNumbers>()?;
let total_imported_txns = provider.tx_ref().entries::<tables::TransactionHashNumbers>()?;

if total_decoded_blocks != total_imported_blocks ||
total_decoded_txns != total_imported_txns
if total_decoded_blocks != total_imported_blocks
|| total_decoded_txns != total_imported_txns
{
error!(target: "reth::cli",
total_decoded_blocks,
Expand Down
42 changes: 21 additions & 21 deletions crates/blockchain-tree-api/src/error.rs
Original file line number Diff line number Diff line change
Expand Up @@ -260,10 +260,10 @@ impl InsertBlockErrorKind {
Self::Canonical(err) => {
matches!(
err,
CanonicalError::Validation(BlockValidationError::StateRoot { .. }) |
CanonicalError::Provider(
ProviderError::StateRootMismatch(_) |
ProviderError::UnwindStateRootMismatch(_)
CanonicalError::Validation(BlockValidationError::StateRoot { .. })
| CanonicalError::Provider(
ProviderError::StateRootMismatch(_)
| ProviderError::UnwindStateRootMismatch(_)
)
)
}
Expand Down Expand Up @@ -292,12 +292,12 @@ impl InsertBlockErrorKind {
true
}
// these are internal errors, not caused by an invalid block
BlockExecutionError::LatestBlock(_) |
BlockExecutionError::Pruning(_) |
BlockExecutionError::CanonicalRevert { .. } |
BlockExecutionError::CanonicalCommit { .. } |
BlockExecutionError::AppendChainDoesntConnect { .. } |
BlockExecutionError::Other(_) => false,
BlockExecutionError::LatestBlock(_)
| BlockExecutionError::Pruning(_)
| BlockExecutionError::CanonicalRevert { .. }
| BlockExecutionError::CanonicalCommit { .. }
| BlockExecutionError::AppendChainDoesntConnect { .. }
| BlockExecutionError::Other(_) => false,
}
}
Self::Tree(err) => {
Expand All @@ -306,24 +306,24 @@ impl InsertBlockErrorKind {
// the block's number is lower than the finalized block's number
true
}
BlockchainTreeError::BlockSideChainIdConsistency { .. } |
BlockchainTreeError::CanonicalChain { .. } |
BlockchainTreeError::BlockNumberNotFoundInChain { .. } |
BlockchainTreeError::BlockHashNotFoundInChain { .. } |
BlockchainTreeError::BlockBufferingFailed { .. } |
BlockchainTreeError::GenesisBlockHasNoParent => false,
BlockchainTreeError::BlockSideChainIdConsistency { .. }
| BlockchainTreeError::CanonicalChain { .. }
| BlockchainTreeError::BlockNumberNotFoundInChain { .. }
| BlockchainTreeError::BlockHashNotFoundInChain { .. }
| BlockchainTreeError::BlockBufferingFailed { .. }
| BlockchainTreeError::GenesisBlockHasNoParent => false,
}
}
Self::Provider(_) | Self::Internal(_) => {
// any other error, such as database errors, are considered internal errors
false
}
Self::Canonical(err) => match err {
CanonicalError::BlockchainTree(_) |
CanonicalError::CanonicalCommit(_) |
CanonicalError::CanonicalRevert(_) |
CanonicalError::OptimisticTargetRevert(_) |
CanonicalError::Provider(_) => false,
CanonicalError::BlockchainTree(_)
| CanonicalError::CanonicalCommit(_)
| CanonicalError::CanonicalRevert(_)
| CanonicalError::OptimisticTargetRevert(_)
| CanonicalError::Provider(_) => false,
CanonicalError::Validation(_) => true,
},
Self::BlockchainTree(_) => false,
Expand Down
8 changes: 4 additions & 4 deletions crates/blockchain-tree/src/blockchain_tree.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1305,8 +1305,8 @@ where
.provider_factory
.static_file_provider()
.get_highest_static_file_block(StaticFileSegment::Headers)
.unwrap_or_default() >
revert_until
.unwrap_or_default()
> revert_until
{
trace!(
target: "blockchain_tree",
Expand Down Expand Up @@ -1608,8 +1608,8 @@ mod tests {
signer,
(
AccountInfo {
balance: initial_signer_balance -
(single_tx_cost * U256::from(num_of_signer_txs)),
balance: initial_signer_balance
- (single_tx_cost * U256::from(num_of_signer_txs)),
nonce: num_of_signer_txs,
..Default::default()
},
Expand Down
24 changes: 12 additions & 12 deletions crates/chainspec/src/spec.rs
Original file line number Diff line number Diff line change
Expand Up @@ -333,14 +333,14 @@ impl ChainSpec {
matches!(
self.chain.kind(),
ChainKind::Named(
NamedChain::Mainnet |
NamedChain::Morden |
NamedChain::Ropsten |
NamedChain::Rinkeby |
NamedChain::Goerli |
NamedChain::Kovan |
NamedChain::Holesky |
NamedChain::Sepolia
NamedChain::Mainnet
| NamedChain::Morden
| NamedChain::Ropsten
| NamedChain::Rinkeby
| NamedChain::Goerli
| NamedChain::Kovan
| NamedChain::Holesky
| NamedChain::Sepolia
)
)
}
Expand Down Expand Up @@ -555,8 +555,8 @@ impl ChainSpec {
// We filter out TTD-based forks w/o a pre-known block since those do not show up in the
// fork filter.
Some(match condition {
ForkCondition::Block(block) |
ForkCondition::TTD { fork_block: Some(block), .. } => ForkFilterKey::Block(block),
ForkCondition::Block(block)
| ForkCondition::TTD { fork_block: Some(block), .. } => ForkFilterKey::Block(block),
ForkCondition::Timestamp(time) => ForkFilterKey::Time(time),
_ => return None,
})
Expand All @@ -574,8 +574,8 @@ impl ChainSpec {
for (_, cond) in self.hardforks.forks_iter() {
// handle block based forks and the sepolia merge netsplit block edge case (TTD
// ForkCondition with Some(block))
if let ForkCondition::Block(block) |
ForkCondition::TTD { fork_block: Some(block), .. } = cond
if let ForkCondition::Block(block)
| ForkCondition::TTD { fork_block: Some(block), .. } = cond
{
if cond.active_at_head(head) {
if block != current_applied {
Expand Down
8 changes: 4 additions & 4 deletions crates/cli/commands/src/db/stats.rs
Original file line number Diff line number Diff line change
Expand Up @@ -271,10 +271,10 @@ impl Command {
.add_cell(Cell::new(human_bytes(segment_config_size as f64)));
}
row.add_cell(Cell::new(human_bytes(
(segment_data_size +
segment_index_size +
segment_offsets_size +
segment_config_size) as f64,
(segment_data_size
+ segment_index_size
+ segment_offsets_size
+ segment_config_size) as f64,
)));
table.add_row(row);
}
Expand Down
4 changes: 2 additions & 2 deletions crates/cli/commands/src/stage/run.rs
Original file line number Diff line number Diff line change
Expand Up @@ -155,8 +155,8 @@ impl Command {
config.stages.bodies.downloader_max_buffered_blocks_size_bytes,
)
.with_concurrent_requests_range(
config.stages.bodies.downloader_min_concurrent_requests..=
config.stages.bodies.downloader_max_concurrent_requests,
config.stages.bodies.downloader_min_concurrent_requests
..=config.stages.bodies.downloader_max_concurrent_requests,
)
.build(fetch_client, consensus.clone(), provider_factory.clone()),
);
Expand Down
26 changes: 13 additions & 13 deletions crates/consensus/beacon/src/engine/hooks/controller.rs
Original file line number Diff line number Diff line change
Expand Up @@ -136,10 +136,10 @@ impl EngineHooksController {
// - Active DB write according to passed argument
// - Missing a finalized block number. We might be on an optimistic sync scenario where we
// cannot skip the FCU with the finalized hash, otherwise CL might misbehave.
if hook.db_access_level().is_read_write() &&
(self.active_db_write_hook.is_some() ||
db_write_active ||
args.finalized_block_number.is_none())
if hook.db_access_level().is_read_write()
&& (self.active_db_write_hook.is_some()
|| db_write_active
|| args.finalized_block_number.is_none())
{
return Poll::Pending;
}
Expand Down Expand Up @@ -307,9 +307,9 @@ mod tests {
assert_eq!(
result.map(|result| {
let polled_hook = result.unwrap();
polled_hook.name == hook_ro_name &&
polled_hook.event.is_started() &&
polled_hook.db_access_level.is_read_only()
polled_hook.name == hook_ro_name
&& polled_hook.event.is_started()
&& polled_hook.db_access_level.is_read_only()
}),
Poll::Ready(true)
);
Expand Down Expand Up @@ -346,9 +346,9 @@ mod tests {
assert_eq!(
result.map(|result| {
let polled_hook = result.unwrap();
polled_hook.name == hook_rw_1_name &&
polled_hook.event.is_started() &&
polled_hook.db_access_level.is_read_write()
polled_hook.name == hook_rw_1_name
&& polled_hook.event.is_started()
&& polled_hook.db_access_level.is_read_write()
}),
Poll::Ready(true)
);
Expand All @@ -368,9 +368,9 @@ mod tests {
assert_eq!(
result.map(|result| {
let polled_hook = result.unwrap();
polled_hook.name == hook_ro_name &&
polled_hook.event.is_started() &&
polled_hook.db_access_level.is_read_only()
polled_hook.name == hook_ro_name
&& polled_hook.event.is_started()
&& polled_hook.db_access_level.is_read_only()
}),
Poll::Ready(true)
);
Expand Down
16 changes: 8 additions & 8 deletions crates/consensus/beacon/src/engine/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -757,8 +757,8 @@ where

// If current_header is None, then the current_hash does not have an invalid
// ancestor in the cache, check its presence in blockchain tree
if current_header.is_none() &&
self.blockchain.find_block_by_hash(current_hash, BlockSource::Any)?.is_some()
if current_header.is_none()
&& self.blockchain.find_block_by_hash(current_hash, BlockSource::Any)?.is_some()
{
return Ok(Some(current_hash));
}
Expand Down Expand Up @@ -857,8 +857,8 @@ where
//
// This ensures that the finalized block is consistent with the head block, i.e. the
// finalized block is an ancestor of the head block.
if !state.finalized_block_hash.is_zero() &&
!self.blockchain.is_canonical(state.finalized_block_hash)?
if !state.finalized_block_hash.is_zero()
&& !self.blockchain.is_canonical(state.finalized_block_hash)?
{
return Ok(Some(OnForkChoiceUpdated::invalid_state()));
}
Expand All @@ -871,8 +871,8 @@ where
//
// This ensures that the safe block is consistent with the head block, i.e. the safe
// block is an ancestor of the head block.
if !state.safe_block_hash.is_zero() &&
!self.blockchain.is_canonical(state.safe_block_hash)?
if !state.safe_block_hash.is_zero()
&& !self.blockchain.is_canonical(state.safe_block_hash)?
{
return Ok(Some(OnForkChoiceUpdated::invalid_state()));
}
Expand Down Expand Up @@ -1255,8 +1255,8 @@ where
latest_valid_hash = Some(block_hash);
PayloadStatusEnum::Valid
}
InsertPayloadOk::Inserted(BlockStatus::Disconnected { .. }) |
InsertPayloadOk::AlreadySeen(BlockStatus::Disconnected { .. }) => {
InsertPayloadOk::Inserted(BlockStatus::Disconnected { .. })
| InsertPayloadOk::AlreadySeen(BlockStatus::Disconnected { .. }) => {
// check if the block's parent is already marked as invalid
if let Some(status) =
self.check_invalid_ancestor_with_head(block.parent_hash, block.hash()).map_err(
Expand Down
4 changes: 2 additions & 2 deletions crates/consensus/common/src/validation.rs
Original file line number Diff line number Diff line change
Expand Up @@ -29,8 +29,8 @@ pub fn validate_header_base_fee(
header: &SealedHeader,
chain_spec: &ChainSpec,
) -> Result<(), ConsensusError> {
if chain_spec.is_fork_active_at_block(EthereumHardfork::London, header.number) &&
header.base_fee_per_gas.is_none()
if chain_spec.is_fork_active_at_block(EthereumHardfork::London, header.number)
&& header.base_fee_per_gas.is_none()
{
return Err(ConsensusError::BaseFeeMissing);
}
Expand Down
Loading

0 comments on commit 8175e78

Please sign in to comment.