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 slot
  • Loading branch information
StefanBratanov committed Feb 19, 2024
1 parent 9e14631 commit e338f25
Show file tree
Hide file tree
Showing 5 changed files with 20 additions and 21 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -33,11 +33,15 @@ public class StateAndBlockSummary implements BeaconBlockSummary {
protected StateAndBlockSummary(final BeaconBlockSummary blockSummary, final BeaconState state) {
checkNotNull(blockSummary);
checkNotNull(state);
verifyStateAndBlockConsistency();
this.blockSummary = blockSummary;
this.state = state;
}

protected void verifyStateAndBlockConsistency() {
checkArgument(
blockSummary.getStateRoot().equals(state.hashTreeRoot()),
"Block state root must match the supplied state");
this.blockSummary = blockSummary;
this.state = state;
}

public static StateAndBlockSummary create(final BeaconState state) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,15 @@ private AnchorPoint(
this.isGenesis = checkpoint.getEpoch().equals(SpecConfig.GENESIS_EPOCH);
}

@Override
protected void verifyStateAndBlockConsistency() {
if (state.getSlot().isGreaterThan(blockSummary.getSlot())) {
// skip verification when state is transitioned with empty slot(s)
return;
}
super.verifyStateAndBlockConsistency();
}

public static AnchorPoint create(
final Spec spec,
Checkpoint checkpoint,
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 @@ -1385,14 +1385,14 @@ private Optional<AnchorPoint> tryLoadingAnchorPointFromInitialState(
initialAnchor =
attemptToLoadAnchorPoint(
networkConfiguration.getNetworkBoostrapConfig().getInitialState());
} catch (final InvalidConfigurationException e) {
} catch (final InvalidConfigurationException ex) {
final StateBoostrapConfig stateBoostrapConfig =
networkConfiguration.getNetworkBoostrapConfig();
if (stateBoostrapConfig.isUsingCustomInitialState()
&& !stateBoostrapConfig.isUsingCheckpointSync()) {
throw e;
throw ex;
}
STATUS_LOG.warnFailedToLoadInitialState(e.getMessage());
STATUS_LOG.warnFailedToLoadInitialState(ex);
}

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 e338f25

Please sign in to comment.