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 2 months 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.Collections.emptyList;
import static java.util.stream.Collectors.toList; 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.Block;
import org.hyperledger.besu.ethereum.core.BlockHeader; import org.hyperledger.besu.ethereum.core.BlockHeader;
import org.hyperledger.besu.ethereum.core.BlockWithReceipts; import org.hyperledger.besu.ethereum.core.BlockWithReceipts;
@ -80,6 +81,10 @@ public class DownloadReceiptsStep
private CompletableFuture<Map<BlockHeader, List<TransactionReceipt>>> private CompletableFuture<Map<BlockHeader, List<TransactionReceipt>>>
getReceiptsWithPeerTaskSystem(final List<BlockHeader> headers) { getReceiptsWithPeerTaskSystem(final List<BlockHeader> headers) {
Map<BlockHeader, List<TransactionReceipt>> getReceipts = new HashMap<>(); 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 { do {
GetReceiptsFromPeerTask task = GetReceiptsFromPeerTask task =
new GetReceiptsFromPeerTask(headers, new BodyValidator(), currentProtocolSpecSupplier); new GetReceiptsFromPeerTask(headers, new BodyValidator(), currentProtocolSpecSupplier);

@ -65,6 +65,7 @@ public class GetReceiptsForHeadersTask
completeEmptyReceipts(headers); completeEmptyReceipts(headers);
} }
// TODO: This is only used in test code and should be removed
public static GetReceiptsForHeadersTask forHeaders( public static GetReceiptsForHeadersTask forHeaders(
final EthContext ethContext, final EthContext ethContext,
final List<BlockHeader> headers, 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.assertj.core.api.Assertions.assertThat;
import static org.mockito.Mockito.mock; import static org.mockito.Mockito.mock;
import org.hyperledger.besu.datatypes.Hash;
import org.hyperledger.besu.ethereum.ProtocolContext; import org.hyperledger.besu.ethereum.ProtocolContext;
import org.hyperledger.besu.ethereum.chain.MutableBlockchain; import org.hyperledger.besu.ethereum.chain.MutableBlockchain;
import org.hyperledger.besu.ethereum.core.Block; import org.hyperledger.besu.ethereum.core.Block;
@ -156,6 +157,7 @@ public class DownloadReceiptsStepTest {
final Block block = Mockito.mock(Block.class); final Block block = Mockito.mock(Block.class);
final BlockHeader blockHeader = Mockito.mock(BlockHeader.class); final BlockHeader blockHeader = Mockito.mock(BlockHeader.class);
Mockito.when(block.getHeader()).thenAnswer((invocationOnMock) -> blockHeader); Mockito.when(block.getHeader()).thenAnswer((invocationOnMock) -> blockHeader);
Mockito.when(blockHeader.getReceiptsRoot()).thenReturn(Hash.fromHexStringLenient("DEADBEEF"));
final BlockBody blockBody = Mockito.mock(BlockBody.class); final BlockBody blockBody = Mockito.mock(BlockBody.class);
Mockito.when(block.getBody()).thenAnswer((invocationOnMock) -> blockBody); Mockito.when(block.getBody()).thenAnswer((invocationOnMock) -> blockBody);
Mockito.when(blockBody.getTransactions()) Mockito.when(blockBody.getTransactions())

Loading…
Cancel
Save