Skip to content

Commit

Permalink
tmp
Browse files Browse the repository at this point in the history
  • Loading branch information
tbenr committed Mar 5, 2025
1 parent a3be18d commit d42bc27
Show file tree
Hide file tree
Showing 7 changed files with 25 additions and 16 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -461,7 +461,7 @@ protected SafeFuture<?> initialize() {
// Setup chain storage
this.recentChainData = client;
if (recentChainData.isPreGenesis()) {
return setupInitialState(client).thenApply(__ -> client);
setupInitialState(client);
} else {
if (isUsingCustomInitialState()) {
STATUS_LOG.warnInitialStateIgnored();
Expand Down Expand Up @@ -1396,7 +1396,7 @@ private Optional<Eth1Address> getProposerDefaultFeeRecipient() {
return defaultFeeRecipient;
}

protected SafeFuture<Void> setupInitialState(final RecentChainData client) {
protected void setupInitialState(final RecentChainData client) {
final Eth2NetworkConfiguration networkConfiguration = beaconConfig.eth2NetworkConfig();

final Optional<AnchorPoint> initialAnchor =
Expand Down Expand Up @@ -1427,25 +1427,20 @@ protected SafeFuture<Void> setupInitialState(final RecentChainData client) {

if (initialAnchor.isPresent()) {
final AnchorPoint anchor = initialAnchor.get();
client.initializeFromAnchorPoint(anchor, timeProvider.getTimeInSeconds());
if (anchor.isGenesis()) {
EVENT_LOG.genesisEvent(
anchor.getStateRoot(),
recentChainData.getBestBlockRoot().orElseThrow(),
anchor.getState().getGenesisTime());
}
return storageQueryChannel.getLatestCanonicalBlockRoot().thenApply(block -> {
client.initializeFromAnchorPoint(anchor, block, timeProvider.getTimeInSeconds());
return SafeFuture.COMPLETE;
}
).toVoid();
} else if (beaconConfig.interopConfig().isInteropEnabled()) {
setupInteropState();
} else if (!beaconConfig.powchainConfig().isEnabled()) {
throw new InvalidConfigurationException(
"ETH1 is disabled but initial state is unknown. Enable ETH1 or specify an initial state"
+ ".");
}
return SafeFuture.COMPLETE;
}

private Optional<AnchorPoint> tryLoadingAnchorPointFromInitialState(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -158,10 +158,10 @@ public void subscribeBestBlockInitialized(final Runnable runnable) {

public void initializeFromGenesis(final BeaconState genesisState, final UInt64 currentTime) {
final AnchorPoint genesis = AnchorPoint.fromGenesisState(spec, genesisState);
initializeFromAnchorPoint(genesis, Optional.empty(), currentTime);
initializeFromAnchorPoint(genesis, currentTime);
}

public void initializeFromAnchorPoint(final AnchorPoint anchorPoint, final Optional<Bytes32> latestCanonicalBlockRoot, final UInt64 currentTime) {
public void initializeFromAnchorPoint(final AnchorPoint anchorPoint, final UInt64 currentTime) {
final UpdatableStore store =
StoreBuilder.create()
.onDiskStoreData(StoreBuilder.forkChoiceStoreBuilder(spec, anchorPoint, currentTime))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -275,7 +275,7 @@ public SafeFuture<Optional<UInt64>> getFinalizedSlotByStateRoot(final Bytes32 st

@Override
public SafeFuture<Optional<Bytes32>> getLatestCanonicalBlockRoot() {
return SafeFuture.of(database::getLatestFinalizedBlockRoot);
return SafeFuture.of(database::getLatestCanonicalBlockRoot);
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -187,6 +187,11 @@ public SafeFuture<Optional<BeaconState>> getFinalizedStateByBlockRoot(final Byte
return asyncRunner.runAsync(() -> queryDelegate.getFinalizedStateByBlockRoot(blockRoot));
}

@Override
public SafeFuture<Optional<Bytes32>> getLatestCanonicalBlockRoot() {
return asyncRunner.runAsync(() -> queryDelegate.getLatestCanonicalBlockRoot());
}

@Override
public SafeFuture<Optional<UInt64>> getFinalizedSlotByStateRoot(final Bytes32 stateRoot) {
return asyncRunner.runAsync(() -> queryDelegate.getFinalizedSlotByStateRoot(stateRoot));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -755,6 +755,7 @@ Optional<OnDiskStoreData> createMemoryStore(final Supplier<Long> timeSupplier) {
final Checkpoint finalizedCheckpoint = dao.getFinalizedCheckpoint().orElseThrow();
final Checkpoint bestJustifiedCheckpoint = dao.getBestJustifiedCheckpoint().orElseThrow();
final BeaconState finalizedState = dao.getLatestFinalizedState().orElseThrow();
final Optional<Bytes32> latestCanonicalBlockRoot = dao.getLatestCanonicalBlockRoot();

final Map<UInt64, VoteTracker> votes = dao.getVotes();

Expand Down Expand Up @@ -801,7 +802,8 @@ Optional<OnDiskStoreData> createMemoryStore(final Supplier<Long> timeSupplier) {
justifiedCheckpoint,
bestJustifiedCheckpoint,
blockInformation,
votes));
votes,
latestCanonicalBlockRoot));
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ public static StoreBuilder create() {
}

public static OnDiskStoreData forkChoiceStoreBuilder(
final Spec spec, final AnchorPoint anchor, final UInt64 currentTime) {
final Spec spec, final AnchorPoint anchor, final UInt64 currentTime) {
final UInt64 genesisTime = anchor.getState().getGenesisTime();
final UInt64 slot = anchor.getState().getSlot();
final UInt64 time = genesisTime.plus(slot.times(spec.getSecondsPerSlot(slot))).max(currentTime);
Expand All @@ -92,7 +92,8 @@ public static OnDiskStoreData forkChoiceStoreBuilder(
anchor.getCheckpoint(),
anchor.getCheckpoint(),
blockInfo,
new HashMap<>());
new HashMap<>(),
Optional.empty());
}

public StoreBuilder onDiskStoreData(final OnDiskStoreData data) {
Expand All @@ -104,7 +105,8 @@ public StoreBuilder onDiskStoreData(final OnDiskStoreData data) {
.justifiedCheckpoint(data.justifiedCheckpoint())
.bestJustifiedCheckpoint(data.bestJustifiedCheckpoint())
.blockInformation(data.blockInformation())
.votes(data.votes());
.votes(data.votes())
.latestCanonicalBlockRoot(data.latestCanonicalBlockRoot());
}

public UpdatableStore build() {
Expand Down Expand Up @@ -145,7 +147,7 @@ public UpdatableStore build() {
justifiedCheckpoint,
bestJustifiedCheckpoint,
blockInfoByRoot,
Optional.empty(),
latestCanonicalBlockRoot,
votes,
storeConfig);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -118,6 +118,11 @@ public SafeFuture<Optional<UInt64>> getFinalizedSlotByStateRoot(final Bytes32 st
return SafeFuture.completedFuture(Optional.empty());
}

@Override
public SafeFuture<Optional<Bytes32>> getLatestCanonicalBlockRoot() {
return SafeFuture.completedFuture(Optional.empty());
}

@Override
public SafeFuture<List<SignedBeaconBlock>> getNonCanonicalBlocksBySlot(final UInt64 slot) {
return SafeFuture.completedFuture(new ArrayList<>());
Expand Down

0 comments on commit d42bc27

Please sign in to comment.