Skip to content
This repository was archived by the owner on Nov 6, 2020. It is now read-only.
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
28 changes: 18 additions & 10 deletions ethcore/src/block.rs
Original file line number Diff line number Diff line change
Expand Up @@ -491,6 +491,24 @@ impl ClosedBlock {
}

impl LockedBlock {

/// Removes outcomes from receipts and updates the receipt root.
///
/// This is done after the block is enacted for historical reasons.
/// We allow inconsistency in receipts for some chains if `validate_receipts_transition`
/// is set to non-zero value, so the check only happens if we detect
/// unmatching root first and then fall back to striped receipts.
pub fn strip_receipts_outcomes(&mut self) {
for receipt in &mut self.block.receipts {
receipt.outcome = TransactionOutcome::Unknown;
}
self.block.header.set_receipts_root(
ordered_trie_root(self.block.receipts.iter().map(|r| r.rlp_bytes()))
);
// compute hash and cache it.
self.block.header.compute_hash();
}

/// Get the hash of the header without seal arguments.
pub fn hash(&self) -> H256 { self.header().bare_hash() }

Expand Down Expand Up @@ -570,7 +588,6 @@ fn enact(
last_hashes: Arc<LastHashes>,
factories: Factories,
is_epoch_begin: bool,
strip_receipts: bool,
) -> Result<LockedBlock, Error> {
{
if ::log::max_log_level() >= ::log::LogLevel::Trace {
Expand Down Expand Up @@ -600,12 +617,6 @@ fn enact(
b.push_uncle(u)?;
}

if strip_receipts {
for receipt in &mut b.block.receipts {
receipt.outcome = TransactionOutcome::Unknown;
}
}

Ok(b.close_and_lock())
}

Expand All @@ -619,8 +630,6 @@ pub fn enact_verified(
last_hashes: Arc<LastHashes>,
factories: Factories,
is_epoch_begin: bool,
// Remove state root from transaction receipts to make them EIP-98 compatible.
strip_receipts: bool,
) -> Result<LockedBlock, Error> {
let view = view!(BlockView, &block.bytes);

Expand All @@ -635,7 +644,6 @@ pub fn enact_verified(
last_hashes,
factories,
is_epoch_begin,
strip_receipts,
)
}

Expand Down
13 changes: 10 additions & 3 deletions ethcore/src/client/client.rs
Original file line number Diff line number Diff line change
Expand Up @@ -415,7 +415,6 @@ impl Importer {
let db = client.state_db.read().boxed_clone_canon(header.parent_hash());

let is_epoch_begin = chain.epoch_transition(parent.number(), *header.parent_hash()).is_some();
let strip_receipts = header.number() < engine.params().validate_receipts_transition;
let enact_result = enact_verified(
block,
engine,
Expand All @@ -425,13 +424,21 @@ impl Importer {
last_hashes,
client.factories.clone(),
is_epoch_begin,
strip_receipts,
);

let locked_block = enact_result.map_err(|e| {
let mut locked_block = enact_result.map_err(|e| {
warn!(target: "client", "Block import failed for #{} ({})\nError: {:?}", header.number(), header.hash(), e);
})?;

// Strip receipts for blocks before validate_receipts_transition,
// if the expected receipts root header does not match.
// (i.e. allow inconsistency in receipts outcome before the transition block)
if header.number() < engine.params().validate_receipts_transition
&& header.receipts_root() != locked_block.block().header().receipts_root()
{
locked_block.strip_receipts_outcomes();
}

// Final Verification
if let Err(e) = self.verifier.verify_block_final(&header, locked_block.block().header()) {
warn!(target: "client", "Stage 5 block verification failed for #{} ({})\nError: {:?}", header.number(), header.hash(), e);
Expand Down