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: Revert non functional modifications #57

Closed
wants to merge 4 commits into from
Closed
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
6 changes: 3 additions & 3 deletions crates/blockchain-tree/src/block_indices.rs
Original file line number Diff line number Diff line change
Expand Up @@ -154,7 +154,7 @@ impl BlockIndices {
added.push(new.into());
new_hash = new_hashes.next();
}
break;
break
};
let Some(new_block_value) = new_hash else {
// Old canonical chain had more block than new chain.
Expand All @@ -164,7 +164,7 @@ impl BlockIndices {
removed.push(rem);
old_hash = old_hashes.next();
}
break;
break
};
// compare old and new canonical block number
match new_block_value.0.cmp(&old_block_value.0) {
Expand Down Expand Up @@ -251,7 +251,7 @@ impl BlockIndices {
/// It is assumed that blocks are interconnected and that they connect to canonical chain
pub fn canonicalize_blocks(&mut self, blocks: &BTreeMap<BlockNumber, SealedBlockWithSenders>) {
if blocks.is_empty() {
return;
return
}

// Remove all blocks from canonical chain
Expand Down
62 changes: 31 additions & 31 deletions crates/blockchain-tree/src/blockchain_tree.rs
Original file line number Diff line number Diff line change
Expand Up @@ -182,15 +182,15 @@ where
) -> Result<Option<BlockStatus>, InsertBlockErrorKind> {
// check if block is canonical
if self.is_block_hash_canonical(&block.hash)? {
return Ok(Some(BlockStatus::Valid(BlockAttachment::Canonical)));
return Ok(Some(BlockStatus::Valid(BlockAttachment::Canonical)))
}

let last_finalized_block = self.block_indices().last_finalized_block();
// check db if block is finalized.
if block.number <= last_finalized_block {
// check if block is inside database
if self.externals.provider_factory.provider()?.block_number(block.hash)?.is_some() {
return Ok(Some(BlockStatus::Valid(BlockAttachment::Canonical)));
return Ok(Some(BlockStatus::Valid(BlockAttachment::Canonical)))
}

#[cfg(not(feature = "taiko"))]
Expand All @@ -204,15 +204,15 @@ where

// is block inside chain
if let Some(attachment) = self.is_block_inside_sidechain(&block) {
return Ok(Some(BlockStatus::Valid(attachment)));
return Ok(Some(BlockStatus::Valid(attachment)))
}

// check if block is disconnected
if let Some(block) = self.state.buffered_blocks.block(&block.hash) {
return Ok(Some(BlockStatus::Disconnected {
head: self.state.block_indices.canonical_tip(),
missing_ancestor: block.parent_num_hash(),
}));
}))
}

Ok(None)
Expand Down Expand Up @@ -288,7 +288,7 @@ where
let Some((first_pending_block_number, _)) = parent_block_hashes.first_key_value()
else {
debug!(target: "blockchain_tree", ?chain_id, "No block hashes stored");
return None;
return None
};
let canonical_chain = canonical_chain
.iter()
Expand All @@ -298,7 +298,7 @@ where

// get canonical fork.
let canonical_fork = self.canonical_fork(chain_id)?;
return Some(ExecutionData { execution_outcome, parent_block_hashes, canonical_fork });
return Some(ExecutionData { execution_outcome, parent_block_hashes, canonical_fork })
}

// check if there is canonical block
Expand All @@ -308,7 +308,7 @@ where
canonical_fork: ForkBlock { number: canonical_number, hash: block_hash },
execution_outcome: ExecutionOutcome::default(),
parent_block_hashes: canonical_chain.inner().clone(),
});
})
}

None
Expand All @@ -331,12 +331,12 @@ where
// check if block parent can be found in any side chain.
if let Some(chain_id) = self.block_indices().get_block_chain_id(&parent.hash) {
// found parent in side tree, try to insert there
return self.try_insert_block_into_side_chain(block, chain_id, block_validation_kind);
return self.try_insert_block_into_side_chain(block, chain_id, block_validation_kind)
}

// if not found, check if the parent can be found inside canonical chain.
if self.is_block_hash_canonical(&parent.hash)? {
return self.try_append_canonical_chain(block.clone(), block_validation_kind);
return self.try_append_canonical_chain(block.clone(), block_validation_kind)
}

// this is another check to ensure that if the block points to a canonical block its block
Expand All @@ -350,7 +350,7 @@ where
parent_block_number: canonical_parent_number,
block_number: block.number,
}
.into());
.into())
}
}

Expand Down Expand Up @@ -411,7 +411,7 @@ where
return Err(BlockExecutionError::Validation(BlockValidationError::BlockPreMerge {
hash: block.hash(),
})
.into());
.into())
}

let parent_header = provider
Expand Down Expand Up @@ -549,7 +549,7 @@ where
} else {
// if there is no fork block that point to other chains, break the loop.
// it means that this fork joins to canonical block.
break;
break
}
}
hashes
Expand All @@ -570,9 +570,9 @@ where
// get fork block chain
if let Some(fork_chain_id) = self.block_indices().get_block_chain_id(&fork.hash) {
chain_id = fork_chain_id;
continue;
continue
}
break;
break
}
(self.block_indices().canonical_hash(&fork.number) == Some(fork.hash)).then_some(fork)
}
Expand Down Expand Up @@ -687,7 +687,7 @@ where
pub fn buffer_block(&mut self, block: SealedBlockWithSenders) -> Result<(), InsertBlockError> {
// validate block consensus rules
if let Err(err) = self.validate_block(&block) {
return Err(InsertBlockError::consensus_error(err, block.block));
return Err(InsertBlockError::consensus_error(err, block.block))
}

self.state.buffered_blocks.insert_block(block);
Expand All @@ -705,17 +705,17 @@ where
"Failed to validate total difficulty for block {}: {e}",
block.header.hash()
);
return Err(e);
return Err(e)
}

if let Err(e) = self.externals.consensus.validate_header(block) {
error!(?block, "Failed to validate header {}: {e}", block.header.hash());
return Err(e);
return Err(e)
}

if let Err(e) = self.externals.consensus.validate_block_pre_execution(block) {
error!(?block, "Failed to validate block {}: {e}", block.header.hash());
return Err(e);
return Err(e)
}

Ok(())
Expand All @@ -740,7 +740,7 @@ where
Some(BlockAttachment::Canonical)
} else {
Some(BlockAttachment::HistoricalFork)
};
}
}
None
}
Expand Down Expand Up @@ -781,7 +781,7 @@ where

// validate block consensus rules
if let Err(err) = self.validate_block(&block) {
return Err(InsertBlockError::consensus_error(err, block.block));
return Err(InsertBlockError::consensus_error(err, block.block))
}

let status = self
Expand Down Expand Up @@ -988,7 +988,7 @@ where
}

if header.is_none() && self.sidechain_block_by_hash(*hash).is_some() {
return Ok(None);
return Ok(None)
}

if header.is_none() {
Expand Down Expand Up @@ -1051,18 +1051,18 @@ where
{
return Err(CanonicalError::from(BlockValidationError::BlockPreMerge {
hash: block_hash,
}));
}))
}

let head = self.state.block_indices.canonical_tip();
return Ok(CanonicalOutcome::AlreadyCanonical { header, head });
return Ok(CanonicalOutcome::AlreadyCanonical { header, head })
}

let Some(chain_id) = self.block_indices().get_block_chain_id(&block_hash) else {
debug!(target: "blockchain_tree", ?block_hash, "Block hash not found in block indices");
return Err(CanonicalError::from(BlockchainTreeError::BlockHashNotFoundInChain {
block_hash,
}));
}))
};

// we are splitting chain at the block hash that we want to make canonical
Expand Down Expand Up @@ -1246,7 +1246,7 @@ where
block_number: tip.number,
block_hash: tip.hash(),
}))
.into());
.into())
}
self.metrics.trie_updates_insert_recomputed.increment(1);
trie_updates
Expand Down Expand Up @@ -1275,7 +1275,7 @@ where
pub fn unwind(&mut self, unwind_to: BlockNumber) -> Result<(), CanonicalError> {
// nothing to be done if unwind_to is higher then the tip
if self.block_indices().canonical_tip().number <= unwind_to {
return Ok(());
return Ok(())
}
// revert `N` blocks from current canonical chain and put them inside BlockchainTree
let old_canon_chain = self.revert_canonical_from_database(unwind_to)?;
Expand Down Expand Up @@ -1309,15 +1309,15 @@ 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",
"Reverting optimistic canonical chain to block {}",
revert_until
);
return Err(CanonicalError::OptimisticTargetRevert(revert_until));
return Err(CanonicalError::OptimisticTargetRevert(revert_until))
}

// read data that is needed for new sidechain
Expand Down Expand Up @@ -1614,8 +1614,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
4 changes: 2 additions & 2 deletions crates/blockchain-tree/src/state.rs
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ impl TreeState {
/// Caution: This will not return blocks from the canonical chain.
pub(crate) fn receipts_by_block_hash(&self, block_hash: BlockHash) -> Option<Vec<&Receipt>> {
let id = self.block_indices.get_block_chain_id(&block_hash)?;
let chain: &AppendableChain = self.chains.get(&id)?;
let chain = self.chains.get(&id)?;
chain.receipts_by_block_hash(block_hash)
}

Expand All @@ -87,7 +87,7 @@ impl TreeState {
/// Inserts a chain into the tree and builds the block indices.
pub(crate) fn insert_chain(&mut self, chain: AppendableChain) -> Option<BlockchainId> {
if chain.is_empty() {
return None;
return None
}
let chain_id = self.next_id();

Expand Down
10 changes: 5 additions & 5 deletions crates/consensus/auto-seal/src/task.rs
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,7 @@ where
if this.insert_task.is_none() {
if this.queued.is_empty() {
// nothing to insert
break;
break
}

// ready to queue in new insert task
Expand Down Expand Up @@ -172,18 +172,18 @@ where
ForkchoiceStatus::Valid => break,
ForkchoiceStatus::Invalid => {
error!(target: "consensus::auto", ?fcu_response, "Forkchoice update returned invalid response");
return None;
return None
}
ForkchoiceStatus::Syncing => {
debug!(target: "consensus::auto", ?fcu_response, "Forkchoice update returned SYNCING, waiting for VALID");
// wait for the next fork choice update
continue;
continue
}
}
}
Err(err) => {
error!(target: "consensus::auto", %err, "Autoseal fork choice update failed");
return None;
return None
}
}
}
Expand All @@ -209,7 +209,7 @@ where
}
Poll::Pending => {
this.insert_task = Some(fut);
break;
break
}
}
}
Expand Down
Loading
Loading