Skip to content

Followup pre populate chain validity window #2012

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

Open
wants to merge 15 commits into
base: main
Choose a base branch
from

Conversation

Elvis339
Copy link
Contributor

@Elvis339 Elvis339 commented Mar 28, 2025

This PR addresses several issues related to the validity window initialization flow.

  1. Improved Validity Window API:

    • Added NewPopulatedTimeValidityWindow as a factory method to create and populate a validity window in one step
    • Made populateValidityWindow private (formerly PopulateValidityWindow) to reduce API surface area
    • Simplified timestamp comparison logic within populateValidityWindow
  2. Cleaner VM Initialization Flow:

    • Removed the circular dependency between chain store and validity window
  3. Validity Window Initialization

    • Enforce populated validity window before starting normal operation

Elvis S added 2 commits March 27, 2025 22:53
* Add NewPopulatedTimeValidityWindow for direct initialization
* Simplify validity window population with consistent timestamp comparison
* Improve VM initialization flow to handle validity window during restart
* Unify calculateOldestAllowed function implementation
* Update component initialization order to break circular dependencies
@Elvis339 Elvis339 self-assigned this Mar 28, 2025
@Elvis339 Elvis339 requested a review from aaronbuchwald as a code owner March 28, 2025 10:52
@Elvis339
Copy link
Contributor Author

#2005 (comment) ->

// backfillFromExisting attempts to build a validity window from existing blocks

#2005 (comment) ->

oldestAllowed = v.calculateOldestAllowed(block.GetTimestamp())

#2005 (comment) ->

if vm.consensusIndex != nil {

#2005 (comment) ->

if err == database.ErrNotFound || !normalOp {

#2005 (comment) ->

func (vm *VM) initValidityWindow(ctx context.Context) error {

#2005 (comment) ->

slices.Reverse(parents)

RodrigoVillar
RodrigoVillar previously approved these changes Mar 28, 2025
Copy link
Contributor

@RodrigoVillar RodrigoVillar left a comment

Choose a reason for hiding this comment

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

LGTM

Copy link
Collaborator

@aaronbuchwald aaronbuchwald left a comment

Choose a reason for hiding this comment

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

Can we define a function within startNormalOp (always called before transitioning to normal operation) that will return an error if the validity window does not report as fully populated yet?

Comment on lines +530 to +531
// AddNormalOpStarter registers a callback that will be executed when the engine invokes SetState(snow.NormalOp)
// i.e., transitioning from state sync / bootstrapping to normal operation.
Copy link
Collaborator

Choose a reason for hiding this comment

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

Note: these will also be called on SetState(snow.NormalOp) when still performing dynamic state sync.

We could try and make that explicitly handled here so that the snow package can support callbacks for actually entering normal operation (ie. exclude dynamic state sync).

Elvis S added 4 commits April 11, 2025 17:10
…p safety checks enhance VW implementation with a populated flag that tracks whether a complete validity window has been observed. Reducing API surface area
…uring consistent view of state across the network
log: log,
tracer: tracer,
chainIndex: chainIndex,
seen: emap.NewEMap[T](),
getTimeValidityWindow: getTimeValidityWindowF,
populated: false,
}
if lastAcceptedBlock != nil {
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Allowing nil lastAcceptedBlock for testing purposes. While not ideal for production use, passing nil signals the creation of an empty validity window. The constructor handles this case gracefully. I'm open to improvements.

vw := NewTimeValidityWindow(ctx, log, tracer, chainIndex, nil, ...)

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.

3 participants