Skip to content

Commit

Permalink
Remove getByBlockNumber for CheckpointSync (#5173)
Browse files Browse the repository at this point in the history
Pull up and simplify data passed to CheckpointSource, which then allows checkpointBlockHeader to be used by protocolSchedule.getByBlockHeader.
Signed-off-by: Simon Dudley <[email protected]>
  • Loading branch information
siladu authored Mar 9, 2023
1 parent bee8699 commit 192c0bb
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 17 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,7 @@

import org.hyperledger.besu.datatypes.Hash;
import org.hyperledger.besu.ethereum.core.BlockHeader;
import org.hyperledger.besu.ethereum.core.BlockHeaderFunctions;
import org.hyperledger.besu.ethereum.core.ProcessableBlockHeader;
import org.hyperledger.besu.ethereum.eth.manager.EthPeer;
import org.hyperledger.besu.ethereum.eth.sync.state.SyncState;

import java.util.Iterator;
Expand All @@ -35,12 +33,10 @@ public class CheckpointSource implements Iterator<Hash> {
private final AtomicBoolean isDownloading = new AtomicBoolean(false);

public CheckpointSource(
final SyncState syncState,
final EthPeer ethPeer,
final BlockHeaderFunctions blockHeaderFunctions) {
final SyncState syncState, final BlockHeader blockHeader, final int nbBlocks) {
this.syncState = syncState;
this.checkpoint = ethPeer.getCheckpointHeader().orElseThrow();
this.nbBlocks = blockHeaderFunctions.getCheckPointWindowSize(checkpoint);
this.checkpoint = blockHeader;
this.nbBlocks = nbBlocks;
this.lastHeaderDownloaded = Optional.empty();
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -61,11 +61,15 @@ protected Pipeline<Hash> createDownloadCheckPointPipeline(

final Checkpoint checkpoint = syncState.getCheckpoint().orElseThrow();

final BlockHeader checkpointBlockHeader = target.peer().getCheckpointHeader().orElseThrow();
final CheckpointSource checkPointSource =
new CheckpointSource(
syncState,
target.peer(),
protocolSchedule.getByBlockNumber(checkpoint.blockNumber()).getBlockHeaderFunctions());
checkpointBlockHeader,
protocolSchedule
.getByBlockHeader(checkpointBlockHeader)
.getBlockHeaderFunctions()
.getCheckPointWindowSize(checkpointBlockHeader));

final CheckpointBlockImportStep checkPointBlockImportStep =
new CheckpointBlockImportStep(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,14 +15,11 @@
package org.hyperledger.besu.ethereum.eth.sync.checkpointsync;

import static org.assertj.core.api.Assertions.assertThat;
import static org.mockito.ArgumentMatchers.any;
import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.when;

import org.hyperledger.besu.ethereum.core.BlockHeader;
import org.hyperledger.besu.ethereum.core.BlockHeaderFunctions;
import org.hyperledger.besu.ethereum.core.BlockHeaderTestFixture;
import org.hyperledger.besu.ethereum.eth.manager.EthPeer;
import org.hyperledger.besu.ethereum.eth.sync.state.SyncState;

import java.util.Optional;
Expand All @@ -33,15 +30,11 @@
public class CheckPointSourceTest {

private final SyncState syncState = mock(SyncState.class);
private final EthPeer peer = mock(EthPeer.class);
private final BlockHeaderFunctions blockHeaderFunctions = mock(BlockHeaderFunctions.class);
private CheckpointSource checkPointSource;

@Before
public void setup() {
when(peer.getCheckpointHeader()).thenReturn(Optional.of(header(12)));
when(blockHeaderFunctions.getCheckPointWindowSize(any(BlockHeader.class))).thenReturn(1);
checkPointSource = new CheckpointSource(syncState, peer, blockHeaderFunctions);
checkPointSource = new CheckpointSource(syncState, header(12), 1);
}

@Test
Expand Down

0 comments on commit 192c0bb

Please sign in to comment.