Skip to content

Commit

Permalink
Make checkpoint sync work when finalized state is transitioned with e…
Browse files Browse the repository at this point in the history
…mpty slots
  • Loading branch information
StefanBratanov committed Feb 14, 2024
1 parent 34e4fa8 commit badc3e6
Show file tree
Hide file tree
Showing 4 changed files with 16 additions and 18 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,19 @@ public static AnchorPoint fromInitialState(final Spec spec, final BeaconState st
if (isGenesisState(state)) {
return fromGenesisState(spec, state);
} else {
final BeaconBlockHeader header = BeaconBlockHeader.fromState(state);
BeaconBlockHeader header = BeaconBlockHeader.fromState(state);

if (state.getSlot().isGreaterThan(header.getSlot())) {
// there have been empty slot(s) since the latest block header so replace the state root
// with the current state root
header =
new BeaconBlockHeader(
header.getSlot(),
header.getProposerIndex(),
header.getParentRoot(),
state.hashTreeRoot(),
header.getBodyRoot());
}

// Calculate closest epoch boundary to use for the checkpoint
final UInt64 epoch = spec.computeNextEpochBoundary(state.getSlot());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -322,21 +322,12 @@ public void loadedInitialStateResource(
}
}

public void errorIncompatibleInitialState(final UInt64 epoch) {
log.error(
"Cannot start with provided initial state for the epoch {}, "
+ "checkpoint occurred on the empty slot, which is not yet supported.\n"
+ "If you are using remote checkpoint source, "
+ "please wait for the next epoch to finalize and retry.",
epoch);
}

public void warnInitialStateIgnored() {
log.warn("Not loading specified initial state as chain data already exists.");
}

public void warnFailedToLoadInitialState(final String message) {
log.warn(message);
public void warnFailedToLoadInitialState(final Throwable throwable) {
log.warn("Failed to load initial state", throwable);
}

public void warnOnInitialStateWithSkippedSlots(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1392,7 +1392,7 @@ private Optional<AnchorPoint> tryLoadingAnchorPointFromInitialState(
&& !stateBoostrapConfig.isUsingCheckpointSync()) {
throw e;
}
STATUS_LOG.warnFailedToLoadInitialState(e.getMessage());
STATUS_LOG.warnFailedToLoadInitialState(e);
}

return initialAnchor;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@

package tech.pegasys.teku.services.beaconchain;

import static tech.pegasys.teku.infrastructure.exceptions.ExitConstants.ERROR_EXIT_CODE;
import static tech.pegasys.teku.infrastructure.logging.StatusLogger.STATUS_LOG;
import static tech.pegasys.teku.networks.Eth2NetworkConfiguration.FINALIZED_STATE_URL_PATH;

Expand Down Expand Up @@ -86,10 +85,6 @@ private AnchorPoint getAnchorPoint(Spec spec, String stateResource, String sanit
throws IOException {
STATUS_LOG.loadingInitialStateResource(sanitizedResource);
final BeaconState state = ChainDataLoader.loadState(spec, stateResource);
if (state.getSlot().isGreaterThan(state.getLatestBlockHeader().getSlot())) {
STATUS_LOG.errorIncompatibleInitialState(spec.computeEpochAtSlot(state.getSlot()));
System.exit(ERROR_EXIT_CODE);
}
final AnchorPoint anchor = AnchorPoint.fromInitialState(spec, state);
STATUS_LOG.loadedInitialStateResource(
state.hashTreeRoot(),
Expand Down

0 comments on commit badc3e6

Please sign in to comment.