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

[KVStore] Support changing protocol state ID in sealing segment #5656

Merged

Conversation

jordanschalm
Copy link
Member

@jordanschalm jordanschalm commented Apr 10, 2024

This PR modifies the SealingSegment to support block segments containing different protocol state commitments (distinct Payload.ProtocolStateID fields).

  • Adds a field SealingSegment.ProtocolStateEntries to store all distinct protocol state entries
    • Since epoch data is still stored outside the KV store, each entry is represented as a wrapper around both the KVStore entry for that block and the epoch state entry for that block
    • Modifies bootstrapping to bootstrap the protocol state and epoch info for each element in ProtocolStateEntries
  • Re-enables all tests from [Dynamic Protocol State] Querying of KV Store using Snapshot API #5650
  • Consolidates the error types defined for SealingSegment:
    • We had 6 different sentinels, but didn't use any of them outside of tests. The error documentation also did not reflect when each sentinel could be returned. This PR replaces the 6 sentinels with 1 and updates error documentation where applicable.
  • Removes cases where we treat snapshots spanning epoch transitions differently (code)

@jordanschalm jordanschalm changed the title DRAFT: Support changing protocol state ID in sealing segment [DRAFT] [KVStore] Support changing protocol state ID in sealing segment Apr 12, 2024
Base automatically changed from yurii/5136-querying-kvstore to feature/protocol-state-kvstore April 12, 2024 15:15
@codecov-commenter
Copy link

codecov-commenter commented Apr 12, 2024

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 63.48%. Comparing base (01fcf31) to head (2d0cb94).
Report is 22 commits behind head on feature/protocol-state-kvstore.

Additional details and impacted files
@@                        Coverage Diff                         @@
##           feature/protocol-state-kvstore    #5656      +/-   ##
==================================================================
- Coverage                           64.03%   63.48%   -0.55%     
==================================================================
  Files                                   8       91      +83     
  Lines                                 798     8153    +7355     
==================================================================
+ Hits                                  511     5176    +4665     
- Misses                                252     2690    +2438     
- Partials                               35      287     +252     
Flag Coverage Δ
unittests 63.48% <ø> (-0.55%) ⬇️

Flags with carried forward coverage won't be shown. Click here to find out more.

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

we had many error types, but none were actually used.
if err != nil {
return nil, fmt.Errorf("could not get current epoch commit event: %w", err)
head := s.enc.SealingSegment.Highest()
entry, ok := s.enc.SealingSegment.ProtocolStateEntries[head.Payload.ProtocolStateID]
Copy link
Member

Choose a reason for hiding this comment

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

LatestProtocolStateEntry()?

}

func (s Snapshot) ProtocolState() (protocol.KVStoreReader, error) {
return kvstore.VersionedDecode(s.enc.KVStore.Version, s.enc.KVStore.Data)
head := s.enc.SealingSegment.Highest()
entry, ok := s.enc.SealingSegment.ProtocolStateEntries[head.Payload.ProtocolStateID]
Copy link
Member

Choose a reason for hiding this comment

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

LatestProtocolStateEntry()?


segment, err := state.Final().SealingSegment()
require.NoError(t, err)
assert.GreaterOrEqual(t, len(segment.ProtocolStateEntries), 2, "should have >2 distinct protocol state entries")
Copy link
Member

Choose a reason for hiding this comment

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

nice!

@@ -588,6 +572,12 @@ func bootstrapEpoch(
}
}

// insert epoch protocol state entry, which references above service events
err := epochProtocolStateSnapshots.StoreTx(richEntry.ID(), richEntry.ProtocolStateEntry)(tx)
Copy link
Member

Choose a reason for hiding this comment

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

You can also use SkipDuplicatesTx to avoid handling specific sentinel

seal into epoch 2 before stopping the epoch 1 VN
// wait until we have sealed all blocks in epoch 1 before stopping the replaced container
// in particular, this avoids an edge case where sealing halts if we stop the single VN
// assigned in epoch 1 between finalizing and sealing the transition into epoch 2
s.AwaitSealedView(s.Ctx, epoch1FinalView+1, time.Minute, 500*time.Millisecond)
Copy link
Member

Choose a reason for hiding this comment

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

nice

// to a previously unseen protocol state entry. If it does, retrieves the state entry
// and persists it for inclusion in the resulting SealingSegment.
// Errors expected during normal operation:
// - InvalidSealingSegmentError if the added block would cause an invalid resulting segment
Copy link
Member

Choose a reason for hiding this comment

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

Not sure where this comes from? protocolStateLookup doesn't return expected errors.
Additionally confused how it can construct an invalid resulting segment

Copy link
Member

@durkmurder durkmurder left a comment

Choose a reason for hiding this comment

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

Very solid update functionally and structurally, nicely done !
My only concern is about storing EpochSetup/Commit events, aside that haven't found anything critical.

@jordanschalm
Copy link
Member Author

Created this WIP follow-up PR to address the outstanding feedback to remove EncodableEpoch: #5682.

Copy link
Member

@AlexHentschel AlexHentschel left a comment

Choose a reason for hiding this comment

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

👍 on the extension of sealing segment to support multiple Protocol States
👏 very nice consolidation and cleanup.

Copy link
Member

Choose a reason for hiding this comment

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

minor nitpick: maybe we should rename the function GenerateProtocolSnapshotForCheckpointWithHeights to GenerateProtocolSnapshotForCheckpointWithHeight (remove "s" at the end), because we are only providing one height value.

model/flow/sealing_segment.go Outdated Show resolved Hide resolved
model/flow/sealing_segment.go Outdated Show resolved Hide resolved
state/protocol/badger/state.go Outdated Show resolved Hide resolved
state/protocol/badger/state.go Outdated Show resolved Hide resolved
@jordanschalm jordanschalm merged commit 48297e8 into feature/protocol-state-kvstore Apr 26, 2024
55 checks passed
@jordanschalm jordanschalm deleted the jordan/5120-sealing-segment branch April 26, 2024 15:25
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.

4 participants