consensus: persist AppQC and blocks to disk#2896
Open
wen-coding wants to merge 4 commits intomainfrom
Open
Conversation
|
The latest Buf updates on your PR. Results from workflow Buf / buf (pull_request).
|
Codecov Report❌ Patch coverage is Additional details and impacted files@@ Coverage Diff @@
## main #2896 +/- ##
==========================================
+ Coverage 57.22% 57.27% +0.05%
==========================================
Files 2093 2100 +7
Lines 171771 172599 +828
==========================================
+ Hits 98294 98855 +561
- Misses 64701 64868 +167
- Partials 8776 8876 +100
Flags with carried forward coverage won't be shown. Click here to find out more.
🚀 New features to boost your workflow:
|
Extract generic A/B file persistence into a reusable consensus/persist/ sub-package and add block-file persistence for crash-safe availability state recovery. Changes: - Move persist.go and persist_test.go into consensus/persist/ (git mv to preserve history), exporting Persister, NewPersister, WriteAndSync, SuffixA, SuffixB. - Add persist/blocks.go: per-block file persistence using <lane_hex>_<blocknum>.pb files in a blocks/ subdirectory, with load, delete-before, and header-mismatch validation. - Wire avail.NewState to accept stateDir, create A/B persister for AppQC and BlockPersister for signed lane proposals, and restore both on restart (contiguous block runs, queue alignment). - Update avail/state.go to persist AppQC on prune and delete obsolete block files after each AppQC advance. - Thread PersistentStateDir from consensus.Config through to avail.NewState. - Expand consensus/inner.go doc comment with full persistence design (what, why, recovery, write behavior, rebroadcasting). - Move TestRunOutputsPersistErrorPropagates to consensus/inner_test.go for proper package alignment. - Add comprehensive tests for blocks persistence (empty dir, multi-lane, corrupt/mismatched skip, DeleteBefore, filename roundtrip). Ref: sei-protocol/sei-v3#512 Co-authored-by: Cursor <cursoragent@cursor.com>
ebf93df to
f4a9c1e
Compare
Move persisted data loading (AppQC deserialization and block loading) into a dedicated function for readability. Co-authored-by: Cursor <cursoragent@cursor.com>
Move block sorting, contiguous-prefix extraction, and gap truncation from avail/inner.go into persist/blocks.go so all disk-recovery logic lives in one place. This isolates storage concerns in the persistence layer, simplifying newInner and preparing for a future storage backend swap. Co-authored-by: Cursor <cursoragent@cursor.com>
Comment on lines
+61
to
+78
| for lane, bs := range loaded.blocks { | ||
| q, ok := i.blocks[lane] | ||
| if !ok || len(bs) == 0 { | ||
| continue | ||
| } | ||
| first := bs[0].Number | ||
| q.first = first | ||
| q.next = first | ||
| for _, b := range bs { | ||
| q.q[q.next] = b.Proposal | ||
| q.next++ | ||
| } | ||
| // Advance the votes queue to match so headers() returns ErrPruned | ||
| // for already-committed blocks instead of blocking forever. | ||
| vq := i.votes[lane] | ||
| vq.first = first | ||
| vq.next = first | ||
| } |
Check warning
Code scanning / CodeQL
Iteration over map Warning
Comment on lines
+166
to
+181
| for lane, bs := range raw { | ||
| sorted := slices.Sorted(maps.Keys(bs)) | ||
| var contiguous []LoadedBlock | ||
| for i, n := range sorted { | ||
| if i > 0 && n != sorted[i-1]+1 { | ||
| log.Warn(). | ||
| Str("lane", lane.String()). | ||
| Uint64("gapAt", uint64(sorted[i-1]+1)). | ||
| Int("skipped", len(sorted)-i). | ||
| Msg("truncating loaded blocks at gap; remaining will be re-fetched") | ||
| break | ||
| } | ||
| contiguous = append(contiguous, LoadedBlock{Number: n, Proposal: bs[n]}) | ||
| } | ||
| result[lane] = contiguous | ||
| } |
Check warning
Code scanning / CodeQL
Iteration over map Warning
Co-authored-by: Cursor <cursoragent@cursor.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Adding crash-safe persistence for availability state (AppQC and signed lane proposals).
consensus/persist/sub-package: Moves the generic A/B file persistence logic (persist.go,persist_test.go) into its own package viagit mv(preserving history), exportingPersister,NewPersister,WriteAndSync,SuffixA/SuffixB.persist/blocks.go): Each signed lane proposal is stored as an individual<lane_hex>_<blocknum>.pbfile in ablocks/subdirectory; includes load-all, delete-before, and header-mismatch validation. On load, blocks are sorted and truncated at the first gap (with a warning log), so higher layers receive clean contiguous slices. (This is a temp remedy before we move to a real storage solution.)avail/state.go):NewStatenow acceptsstateDir, initialises both the A/B persister (for AppQC) andBlockPersister, loads persisted data on restart, and passes it tonewInnerfor queue restoration. Persistence loading is factored into a dedicatedloadPersistedStatehelper.avail/inner.go): On load, advancescommitQCs,appVotes, and per-lane block queues past already-persisted indices. Block restoration simply iterates the pre-sorted contiguous slices from the persistence layer.PersistentStateDirfromconsensus.Configthroughconsensus/state.gointoavail.NewState.consensus/inner.go): Documents what is persisted, why, recovery semantics, write behavior, and rebroadcasting strategy.TestRunOutputsPersistErrorPropagatestoconsensus/inner_test.gofor proper package alignment.persist/blocks.go, keepingnewInnerfocused on queue initialization. This prepares for a future storage backend swap.Test plan
consensus/persist/tests pass (A/B alternation, sequence picking, corruption, error propagation)persist/blocks_test.gotests pass (empty dir, single/multi-lane, corrupt/mismatched skip,DeleteBefore, filename roundtrip, gap truncation, corrupt-mid-sequence truncation)avail/inner_test.goandavail/state_test.goupdated and passing with newNewStatesignatureconsensus/inner_test.goupdated with relocated persist-error-propagation testgo build ./...succeedsgofmt -s -lcleanRef: sei-protocol/sei-v3#512
Made with Cursor