Port sei-v3 PR #510: crash-safe consensus state persistence#2893
Merged
wen-coding merged 4 commits intomainfrom Feb 16, 2026
Merged
Port sei-v3 PR #510: crash-safe consensus state persistence#2893wen-coding merged 4 commits intomainfrom
wen-coding merged 4 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.17% 57.24% +0.06%
==========================================
Files 2091 2093 +2
Lines 171543 171771 +228
==========================================
+ Hits 98081 98322 +241
+ Misses 64713 64689 -24
- Partials 8749 8760 +11
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>
pompon0
approved these changes
Feb 16, 2026
pompon0
reviewed
Feb 16, 2026
| } | ||
|
|
||
| // innerProtoConv is a protobuf converter for persistedInner. | ||
| var innerProtoConv = utils.ProtoConv[*persistedInner, *pb.PersistedInner]{ |
Contributor
There was a problem hiding this comment.
use internal/protoutils.Conv instead, which is dedicated for the new proto generator. Also, it does implement the Test(), so you can utilize it in tests.
stevenlanders
approved these changes
Feb 16, 2026
…toConv protoutils.Conv uses google.golang.org/protobuf (matching the generated pb types), while utils.ProtoConv uses gogo/protobuf. Also simplifies callers via Conv.Marshal/Unmarshal helpers and Conv.Test() in tests. 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