Skip to content

Commit

Permalink
Merge branch 'paradigmxyz:main' into main
Browse files Browse the repository at this point in the history
  • Loading branch information
Arindam2407 authored Nov 28, 2023
2 parents 0f951e4 + 9fe3b02 commit a733fc1
Show file tree
Hide file tree
Showing 24 changed files with 348 additions and 171 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/sanity.yml
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ jobs:
- uses: dtolnay/rust-toolchain@nightly
- uses: taiki-e/install-action@cargo-udeps
- name: Check for unused dependencies
run: cargo udeps --features "jemalloc,${{ matrix.network }}"
run: cargo udeps --lib --features "jemalloc,${{ matrix.network }}"
- uses: JasonEtco/create-an-issue@v2
if: ${{ failure() }}
env:
Expand Down
108 changes: 3 additions & 105 deletions Cargo.lock

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

17 changes: 16 additions & 1 deletion bin/reth/src/debug_cmd/build_block.rs
Original file line number Diff line number Diff line change
Expand Up @@ -277,11 +277,26 @@ impl Command {
let state = executor.take_output_state();
debug!(target: "reth::cli", ?state, "Executed block");

let hashed_state = state.hash_state_slow();
let (state_root, trie_updates) = state
.state_root_calculator(provider_factory.provider()?.tx_ref(), &hashed_state)
.root_with_updates()?;

if state_root != block_with_senders.state_root {
eyre::bail!(
"state root mismatch. expected: {}. got: {}",
block_with_senders.state_root,
state_root
);
}

// Attempt to insert new block without committing
let provider_rw = provider_factory.provider_rw()?;
provider_rw.append_blocks_with_bundle_state(
provider_rw.append_blocks_with_state(
Vec::from([block_with_senders]),
state,
hashed_state,
trie_updates,
None,
)?;
info!(target: "reth::cli", "Successfully appended built block");
Expand Down
38 changes: 30 additions & 8 deletions crates/blockchain-tree/src/blockchain_tree.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,25 +6,26 @@ use crate::{
state::{BlockChainId, TreeState},
AppendableChain, BlockIndices, BlockchainTreeConfig, BundleStateData, TreeExternals,
};
use reth_db::database::Database;
use reth_db::{database::Database, DatabaseError};
use reth_interfaces::{
blockchain_tree::{
error::{BlockchainTreeError, CanonicalError, InsertBlockError, InsertBlockErrorKind},
BlockStatus, BlockValidationKind, CanonicalOutcome, InsertPayloadOk,
},
consensus::{Consensus, ConsensusError},
executor::{BlockExecutionError, BlockValidationError},
RethResult,
provider::RootMismatch,
RethError, RethResult,
};
use reth_primitives::{
BlockHash, BlockNumHash, BlockNumber, ForkBlock, Hardfork, PruneModes, Receipt, SealedBlock,
SealedBlockWithSenders, SealedHeader, U256,
BlockHash, BlockNumHash, BlockNumber, ForkBlock, GotExpected, Hardfork, PruneModes, Receipt,
SealedBlock, SealedBlockWithSenders, SealedHeader, U256,
};
use reth_provider::{
chain::{ChainSplit, ChainSplitTarget},
BlockExecutionWriter, BlockNumReader, BlockWriter, BundleStateWithReceipts,
CanonStateNotification, CanonStateNotificationSender, CanonStateNotifications, Chain,
ChainSpecProvider, DisplayBlocksChain, ExecutorFactory, HeaderProvider,
ChainSpecProvider, DisplayBlocksChain, ExecutorFactory, HeaderProvider, ProviderError,
};
use reth_stages::{MetricEvent, MetricEventsSender};
use std::{collections::BTreeMap, sync::Arc};
Expand Down Expand Up @@ -1104,14 +1105,35 @@ impl<DB: Database, EF: ExecutorFactory> BlockchainTree<DB, EF> {

/// Write the given chain to the database as canonical.
fn commit_canonical_to_database(&self, chain: Chain) -> RethResult<()> {
let provider_rw = self.externals.provider_factory.provider_rw()?;
// Compute state root before opening write transaction.
let hashed_state = chain.state().hash_state_slow();
let (state_root, trie_updates) = chain
.state()
.state_root_calculator(
self.externals.provider_factory.provider()?.tx_ref(),
&hashed_state,
)
.root_with_updates()
.map_err(Into::<DatabaseError>::into)?;
let tip = chain.tip();
if state_root != tip.state_root {
return Err(RethError::Provider(ProviderError::StateRootMismatch(Box::new(
RootMismatch {
root: GotExpected { got: state_root, expected: tip.state_root },
block_number: tip.number,
block_hash: tip.hash,
},
))))
}

let (blocks, state) = chain.into_inner();

let provider_rw = self.externals.provider_factory.provider_rw()?;
provider_rw
.append_blocks_with_bundle_state(
.append_blocks_with_state(
blocks.into_blocks().collect(),
state,
hashed_state,
trie_updates,
self.prune_modes.as_ref(),
)
.map_err(|e| BlockExecutionError::CanonicalCommit { inner: e.to_string() })?;
Expand Down
2 changes: 1 addition & 1 deletion crates/primitives/src/account.rs
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ impl Account {
Some(hash) => hash == KECCAK_EMPTY,
};

self.nonce == 0 && self.balance == U256::ZERO && is_bytecode_empty
self.nonce == 0 && self.balance.is_zero() && is_bytecode_empty
}

/// Returns an account bytecode's hash.
Expand Down
26 changes: 22 additions & 4 deletions crates/primitives/src/revm/env.rs
Original file line number Diff line number Diff line change
Expand Up @@ -92,26 +92,44 @@ pub fn fill_block_env_with_coinbase(
/// Return the coinbase address for the given header and chain spec.
pub fn block_coinbase(chain_spec: &ChainSpec, header: &Header, after_merge: bool) -> Address {
if chain_spec.chain == Chain::goerli() && !after_merge {
recover_header_signer(header).expect("failed to recover signer")
recover_header_signer(header).unwrap_or_else(|err| {
panic!(
"Failed to recover goerli Clique Consensus signer from header ({}, {}) using extradata {}: {:?}",
header.number, header.hash_slow(), header.extra_data, err
)
})
} else {
header.beneficiary
}
}

/// Error type for recovering Clique signer from a header.
#[derive(Debug, thiserror::Error)]
pub enum CliqueSignerRecoveryError {
/// Header extradata is too short.
#[error("Invalid extra data length")]
InvalidExtraData,
/// Recovery failed.
#[error("Invalid signature: {0}")]
InvalidSignature(#[from] secp256k1::Error),
}

/// Recover the account from signed header per clique consensus rules.
pub fn recover_header_signer(header: &Header) -> Option<Address> {
pub fn recover_header_signer(header: &Header) -> Result<Address, CliqueSignerRecoveryError> {
let extra_data_len = header.extra_data.len();
// Fixed number of extra-data suffix bytes reserved for signer signature.
// 65 bytes fixed as signatures are based on the standard secp256k1 curve.
// Filled with zeros on genesis block.
let signature_start_byte = extra_data_len - 65;
let signature: [u8; 65] = header.extra_data[signature_start_byte..].try_into().ok()?;
let signature: [u8; 65] = header.extra_data[signature_start_byte..]
.try_into()
.map_err(|_| CliqueSignerRecoveryError::InvalidExtraData)?;
let seal_hash = {
let mut header_to_seal = header.clone();
header_to_seal.extra_data = Bytes::from(header.extra_data[..signature_start_byte].to_vec());
header_to_seal.hash_slow()
};
recover_signer(&signature, &seal_hash.0).ok()
recover_signer(&signature, &seal_hash.0).map_err(CliqueSignerRecoveryError::InvalidSignature)
}

/// Returns a new [TxEnv] filled with the transaction's data.
Expand Down
2 changes: 1 addition & 1 deletion crates/primitives/src/transaction/signature.rs
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ impl Signature {
#[inline]
pub fn v(&self, chain_id: Option<u64>) -> u64 {
#[cfg(feature = "optimism")]
if self.r == U256::ZERO && self.s == U256::ZERO {
if self.r.is_zero() && self.s.is_zero() {
return 0
}

Expand Down
2 changes: 1 addition & 1 deletion crates/revm/revm-inspectors/src/tracing/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -144,7 +144,7 @@ impl TracingInspector {
) -> bool {
if data.precompiles.contains(to) {
// only if this is _not_ the root call
return self.is_deep() && value == U256::ZERO
return self.is_deep() && value.is_zero()
}
false
}
Expand Down
2 changes: 1 addition & 1 deletion crates/rpc/rpc-engine-api/tests/it/payload.rs
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,7 @@ fn payload_validation() {
assert_matches!(

try_into_sealed_block(block_with_zero_base_fee,None),
Err(PayloadError::BaseFee(val)) if val == U256::ZERO
Err(PayloadError::BaseFee(val)) if val.is_zero()
);

// Invalid encoded transactions
Expand Down
4 changes: 3 additions & 1 deletion crates/rpc/rpc/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -40,9 +40,11 @@ jsonrpsee.workspace = true
http = "0.2.8"
http-body = "0.4.5"
hyper = "0.14.24"
reqwest = { version = "0.11.20", optional = true }
jsonwebtoken = "8"

## required for optimism sequencer delegation
reqwest = { version = "0.11", default-features = false, features = ["rustls"], optional = true }

# async
async-trait.workspace = true
tokio = { workspace = true, features = ["sync"] }
Expand Down
Loading

0 comments on commit a733fc1

Please sign in to comment.