Port sei-v3 PR #510: crash-safe consensus state persistence#2893
Open
wen-coding wants to merge 2 commits intomainfrom
Open
Port sei-v3 PR #510: crash-safe consensus state persistence#2893wen-coding wants to merge 2 commits intomainfrom
wen-coding wants to merge 2 commits intomainfrom
Conversation
Port of sei-protocol/sei-v3#510 to sei-chain. Adds crash-safe A/B file persistence for the autobahn consensus inner state (votes and QCs), preventing double-voting on restart and enabling fast view synchronization after cluster-wide outages. New files: - persisted_inner.go: persistedInner struct, validation, protobuf conversion - persist.go: crash-safe A/B file persistence with seq numbering - inner_test.go: tests for newInner and persisted state loading - persist_test.go: tests for A/B file persistence logic - persisted_inner_test.go: protobuf roundtrip tests Modified files: - autobahn.proto: added PersistedInner and PersistedWrapper messages - autobahn.pb.go: regenerated via buf generate - inner.go: refactored to embed persistedInner, added newInner constructor - state.go: NewState returns error, added PersistentStateDir config, integrated persistence into runOutputs - types/testonly.go: added GenProposalAt helper - giga/avail_test.go, data_test.go: adapted for NewState error return Co-authored-by: Cursor <cursoragent@cursor.com>
|
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 #2893 +/- ##
==========================================
+ Coverage 57.15% 57.21% +0.06%
==========================================
Files 2091 2093 +2
Lines 171524 171755 +231
==========================================
+ Hits 98033 98271 +238
+ Misses 64751 64727 -24
- Partials 8740 8757 +17
Flags with carried forward coverage won't be shown. Click here to find out more.
🚀 New features to boost your workflow:
|
- Add nolint:gosec for os.ReadFile, os.OpenFile, and os.Open where paths are built from operator-configured stateDir + hardcoded filename suffixes (G304 false positives — no user-controlled input). - Explicitly ignore return values of probe.Close(), os.Remove(), f.Close(), and d.Close() with _ = to satisfy errcheck. All are safe to ignore: probe and dir handles have no data to flush. 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
This is a port of sei-protocol/sei-v3#510 to sei-chain.
Adds crash-safe A/B file persistence for the autobahn consensus inner state (votes and QCs). This prevents double-voting on restart (a slashable offense) and enables fast view synchronization after cluster-wide outages by persisting QC justifications.
Key changes
persist.go): Alternates writes between two files (_a.pb/_b.pb) with sequence numbering. On load, picks the file with the higher seq; tolerates one corrupt file (crash mid-write recovery). Only needs one fsync per write (no directory sync after initial setup).persisted_inner.go): Defines thepersistedInnerstruct holding CommitQC, PrepareQC, TimeoutQC, and current-view votes. Includes validation logic that checks internal consistency and cryptographic signatures on load.inner.go):innernow embedspersistedInnerso persisted fields are promoted. AddednewInnerconstructor that loads and validates persisted state.state.go):NewStatenow returns(*State, error). AddedPersistentStateDirconfig option. Persistence is called inrunOutputsbefore broadcasting votes.autobahn.proto,autobahn.pb.go): AddedPersistedInnerandPersistedWrappermessage definitions. Regenerated viabuf generate.types/testonly.go): AddedGenProposalAtfor generating proposals at a specific view.giga/avail_test.go,giga/data_test.go): Adapted forNewStatereturning an error.Adaptation notes (sei-v3 → sei-chain)
sei-stream/stream/consensus→sei-tendermint/internal/autobahn/consensusprotocol→pb(protobuf package)utils.AtomicWatch[inner].Update()→utils.Mutex[*utils.AtomicSend[inner]].Lock()/Store()*rand.Rand→utils.Rngin test helpersinnerProtoConv.Test()replaced with manual roundtrip usinggoogle.golang.org/protobuf/proto(gogo/protobuf incompatibility with protoc-gen-go generated types)New files (5)
sei-tendermint/internal/autobahn/consensus/persisted_inner.gosei-tendermint/internal/autobahn/consensus/persist.gosei-tendermint/internal/autobahn/consensus/inner_test.gosei-tendermint/internal/autobahn/consensus/persist_test.gosei-tendermint/internal/autobahn/consensus/persisted_inner_test.goModified files (7)
sei-tendermint/internal/autobahn/autobahn.protosei-tendermint/internal/autobahn/pb/autobahn.pb.gosei-tendermint/internal/autobahn/consensus/inner.gosei-tendermint/internal/autobahn/consensus/state.gosei-tendermint/internal/autobahn/types/testonly.gosei-tendermint/internal/p2p/giga/avail_test.gosei-tendermint/internal/p2p/giga/data_test.goTest plan
go test ./sei-tendermint/internal/autobahn/...)go test ./sei-tendermint/internal/p2p/giga/...)gofmt -sclean on all modified filesbuf generate(matchingprotoc-gen-go v1.36.10,protoc (unknown))Made with Cursor