Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Set initial canonical block root #9203

Merged
merged 9 commits into from
Mar 6, 2025

Conversation

tbenr
Copy link
Contributor

@tbenr tbenr commented Mar 4, 2025

  • add a new hot variable to store latest canonical block root
  • add an hidden CLI param to override it so that we can revive nodes which do not have the latest canonical root set
  • the canonical root is set via dedicated StoredLatestCanonicalBlockUpdater on every slot%32 == 1
  • At startup, reads the valuer from db (or CLI) and via protoArray.setInitialCanonicalBlockRoot it "breaks the tie" by adding 1 to weight on all the nodes on the canonical chain identified by that block root

fixes #9198

Documentation

  • I thought about documentation and added the doc-change-required label to this PR if updates are required.

Changelog

  • I thought about adding a changelog entry, and added one if I deemed necessary.

@tbenr tbenr force-pushed the initial-canonical-block-root branch from 2684ed2 to fca73a8 Compare March 5, 2025 17:06
@tbenr tbenr marked this pull request as ready for review March 5, 2025 17:39
Copy link
Member

@lucassaldanha lucassaldanha left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM. Added a few questions and some NITs. But overall looks good to go.


@Override
public void onSlot(final UInt64 slot) {
if (!slot.mod(UInt64.valueOf(32)).equals(ONE)) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Wouldn't be better to use spec.getSlotsPerEpoch(slot) instead of hardcoded 32?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

we could store slotsPerEpoch at initialisation, it wont change with current spec

Comment on lines +39 to +43
final StoreTransaction transaction = recentChainData.startStoreTransaction();
recentChainData.getBestBlockRoot().ifPresent(transaction::setLatestCanonicalBlockRoot);
transaction
.commit()
.finish(error -> LOG.error("Failed to store latest canonical block root", error));
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

One thought: should we compare our current canonical block root value before starting a tx? Just thinking that if it hasn't changed there is no benefit in updating it.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

if it hasn't changed we may as well just update the variable regardless, its simpler imo...


applyToNodes(this::updateBestDescendantOfParent);

// let's peak the best descendant of the initial canonical block root
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

NIT: did you mean pick?

.map(this::getNodeByIndex)
.orElse(initialCanonicalProtoNode.get());

// add a single weight to from the best descendant up to the root
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

NIT: add a single weight to ??? Maybe missing "it" or "the node"?

private static Optional<Bytes32> getInitialCanonicalBlockRoot(
final StoreConfig config, final Optional<Bytes32> initialCanonicalBlockRoot) {
if (config.getInitialCanonicalBlockRoot().isPresent()) {
LOG.warn(
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why are we using WARN? Isn't this something we want to happen? It does not require intervention and is expected. I'd move it to INFO.

@lucassaldanha lucassaldanha enabled auto-merge (squash) March 6, 2025 01:13
@lucassaldanha lucassaldanha merged commit 9fd1641 into Consensys:master Mar 6, 2025
16 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

[HOLESKY PECTRA] Our head slot is not maintained upon restart
3 participants