7311: Handle headers with no receipts as a special case in DownloadReceiptsStep

Signed-off-by: Matilda Clerke <matilda.clerke@consensys.net>
pull/7638/head
Matilda Clerke 1 month ago
parent af93824210
commit e664a51c00
  1. 5
      ethereum/eth/src/main/java/org/hyperledger/besu/ethereum/eth/sync/fastsync/DownloadReceiptsStep.java
  2. 1
      ethereum/eth/src/main/java/org/hyperledger/besu/ethereum/eth/sync/tasks/GetReceiptsForHeadersTask.java
  3. 2
      ethereum/eth/src/test/java/org/hyperledger/besu/ethereum/eth/sync/fastsync/DownloadReceiptsStepTest.java

@ -17,6 +17,7 @@ package org.hyperledger.besu.ethereum.eth.sync.fastsync;
import static java.util.Collections.emptyList;
import static java.util.stream.Collectors.toList;
import org.hyperledger.besu.datatypes.Hash;
import org.hyperledger.besu.ethereum.core.Block;
import org.hyperledger.besu.ethereum.core.BlockHeader;
import org.hyperledger.besu.ethereum.core.BlockWithReceipts;
@ -80,6 +81,10 @@ public class DownloadReceiptsStep
private CompletableFuture<Map<BlockHeader, List<TransactionReceipt>>>
getReceiptsWithPeerTaskSystem(final List<BlockHeader> headers) {
Map<BlockHeader, List<TransactionReceipt>> getReceipts = new HashMap<>();
headers.stream()
.filter(header -> header.getReceiptsRoot().equals(Hash.EMPTY_TRIE_HASH))
.forEach(header -> getReceipts.put(header, emptyList()));
headers.removeAll(getReceipts.keySet());
do {
GetReceiptsFromPeerTask task =
new GetReceiptsFromPeerTask(headers, new BodyValidator(), currentProtocolSpecSupplier);

@ -65,6 +65,7 @@ public class GetReceiptsForHeadersTask
completeEmptyReceipts(headers);
}
// TODO: This is only used in test code and should be removed
public static GetReceiptsForHeadersTask forHeaders(
final EthContext ethContext,
final List<BlockHeader> headers,

@ -18,6 +18,7 @@ import static java.util.Arrays.asList;
import static org.assertj.core.api.Assertions.assertThat;
import static org.mockito.Mockito.mock;
import org.hyperledger.besu.datatypes.Hash;
import org.hyperledger.besu.ethereum.ProtocolContext;
import org.hyperledger.besu.ethereum.chain.MutableBlockchain;
import org.hyperledger.besu.ethereum.core.Block;
@ -156,6 +157,7 @@ public class DownloadReceiptsStepTest {
final Block block = Mockito.mock(Block.class);
final BlockHeader blockHeader = Mockito.mock(BlockHeader.class);
Mockito.when(block.getHeader()).thenAnswer((invocationOnMock) -> blockHeader);
Mockito.when(blockHeader.getReceiptsRoot()).thenReturn(Hash.fromHexStringLenient("DEADBEEF"));
final BlockBody blockBody = Mockito.mock(BlockBody.class);
Mockito.when(block.getBody()).thenAnswer((invocationOnMock) -> blockBody);
Mockito.when(blockBody.getTransactions())

Loading…
Cancel
Save