Skip to content

Commit badc3e6

Browse files
Make checkpoint sync work when finalized state is transitioned with empty slots
1 parent 34e4fa8 commit badc3e6

File tree

4 files changed

+16
-18
lines changed

4 files changed

+16
-18
lines changed

ethereum/spec/src/main/java/tech/pegasys/teku/spec/datastructures/state/AnchorPoint.java

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -94,7 +94,19 @@ public static AnchorPoint fromInitialState(final Spec spec, final BeaconState st
9494
if (isGenesisState(state)) {
9595
return fromGenesisState(spec, state);
9696
} else {
97-
final BeaconBlockHeader header = BeaconBlockHeader.fromState(state);
97+
BeaconBlockHeader header = BeaconBlockHeader.fromState(state);
98+
99+
if (state.getSlot().isGreaterThan(header.getSlot())) {
100+
// there have been empty slot(s) since the latest block header so replace the state root
101+
// with the current state root
102+
header =
103+
new BeaconBlockHeader(
104+
header.getSlot(),
105+
header.getProposerIndex(),
106+
header.getParentRoot(),
107+
state.hashTreeRoot(),
108+
header.getBodyRoot());
109+
}
98110

99111
// Calculate closest epoch boundary to use for the checkpoint
100112
final UInt64 epoch = spec.computeNextEpochBoundary(state.getSlot());

infrastructure/logging/src/main/java/tech/pegasys/teku/infrastructure/logging/StatusLogger.java

Lines changed: 2 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -322,21 +322,12 @@ public void loadedInitialStateResource(
322322
}
323323
}
324324

325-
public void errorIncompatibleInitialState(final UInt64 epoch) {
326-
log.error(
327-
"Cannot start with provided initial state for the epoch {}, "
328-
+ "checkpoint occurred on the empty slot, which is not yet supported.\n"
329-
+ "If you are using remote checkpoint source, "
330-
+ "please wait for the next epoch to finalize and retry.",
331-
epoch);
332-
}
333-
334325
public void warnInitialStateIgnored() {
335326
log.warn("Not loading specified initial state as chain data already exists.");
336327
}
337328

338-
public void warnFailedToLoadInitialState(final String message) {
339-
log.warn(message);
329+
public void warnFailedToLoadInitialState(final Throwable throwable) {
330+
log.warn("Failed to load initial state", throwable);
340331
}
341332

342333
public void warnOnInitialStateWithSkippedSlots(

services/beaconchain/src/main/java/tech/pegasys/teku/services/beaconchain/BeaconChainController.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1392,7 +1392,7 @@ private Optional<AnchorPoint> tryLoadingAnchorPointFromInitialState(
13921392
&& !stateBoostrapConfig.isUsingCheckpointSync()) {
13931393
throw e;
13941394
}
1395-
STATUS_LOG.warnFailedToLoadInitialState(e.getMessage());
1395+
STATUS_LOG.warnFailedToLoadInitialState(e);
13961396
}
13971397

13981398
return initialAnchor;

services/beaconchain/src/main/java/tech/pegasys/teku/services/beaconchain/WeakSubjectivityInitializer.java

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,6 @@
1313

1414
package tech.pegasys.teku.services.beaconchain;
1515

16-
import static tech.pegasys.teku.infrastructure.exceptions.ExitConstants.ERROR_EXIT_CODE;
1716
import static tech.pegasys.teku.infrastructure.logging.StatusLogger.STATUS_LOG;
1817
import static tech.pegasys.teku.networks.Eth2NetworkConfiguration.FINALIZED_STATE_URL_PATH;
1918

@@ -86,10 +85,6 @@ private AnchorPoint getAnchorPoint(Spec spec, String stateResource, String sanit
8685
throws IOException {
8786
STATUS_LOG.loadingInitialStateResource(sanitizedResource);
8887
final BeaconState state = ChainDataLoader.loadState(spec, stateResource);
89-
if (state.getSlot().isGreaterThan(state.getLatestBlockHeader().getSlot())) {
90-
STATUS_LOG.errorIncompatibleInitialState(spec.computeEpochAtSlot(state.getSlot()));
91-
System.exit(ERROR_EXIT_CODE);
92-
}
9388
final AnchorPoint anchor = AnchorPoint.fromInitialState(spec, state);
9489
STATUS_LOG.loadedInitialStateResource(
9590
state.hashTreeRoot(),

0 commit comments

Comments
 (0)