Skip to content

Commit

Permalink
Add requests root to empty block check (#7785)
Browse files Browse the repository at this point in the history
* add requests root to empty block check and move it to BlockHeader

Signed-off-by: stefan.pingel@consensys.net <stefan.pingel@consensys.net>
  • Loading branch information
pinges authored Oct 21, 2024
1 parent 9a77447 commit 7e61f74
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 11 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -92,6 +92,19 @@ public BlockHeader(
this.parsedExtraData = Suppliers.memoize(() -> blockHeaderFunctions.parseExtraData(this));
}

public static boolean hasEmptyBlock(final BlockHeader blockHeader) {
return blockHeader.getOmmersHash().equals(Hash.EMPTY_LIST_HASH)
&& blockHeader.getTransactionsRoot().equals(Hash.EMPTY_TRIE_HASH)
&& blockHeader
.getWithdrawalsRoot()
.map(wsRoot -> wsRoot.equals(Hash.EMPTY_TRIE_HASH))
.orElse(true)
&& blockHeader
.getRequestsRoot()
.map(reqRoot -> reqRoot.equals(Hash.EMPTY_TRIE_HASH))
.orElse(true);
}

/**
* Returns the block mixed hash.
*
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@
import static java.util.concurrent.CompletableFuture.completedFuture;
import static java.util.stream.Collectors.toMap;

import org.hyperledger.besu.datatypes.Hash;
import org.hyperledger.besu.ethereum.core.Block;
import org.hyperledger.besu.ethereum.core.BlockBody;
import org.hyperledger.besu.ethereum.core.BlockHeader;
Expand Down Expand Up @@ -75,7 +74,7 @@ private CompleteBlocksTask(
this.headers = headers;
this.blocks =
headers.stream()
.filter(this::hasEmptyBody)
.filter(BlockHeader::hasEmptyBlock)
.collect(
toMap(
BlockHeader::getNumber,
Expand All @@ -102,15 +101,6 @@ private boolean isWithdrawalsEnabled(
return protocolSchedule.getByBlockHeader(header).getWithdrawalsProcessor().isPresent();
}

private boolean hasEmptyBody(final BlockHeader header) {
return header.getOmmersHash().equals(Hash.EMPTY_LIST_HASH)
&& header.getTransactionsRoot().equals(Hash.EMPTY_TRIE_HASH)
&& header
.getWithdrawalsRoot()
.map(wsRoot -> wsRoot.equals(Hash.EMPTY_TRIE_HASH))
.orElse(true);
}

public static CompleteBlocksTask forHeaders(
final ProtocolSchedule protocolSchedule,
final EthContext ethContext,
Expand Down

0 comments on commit 7e61f74

Please sign in to comment.