-
Notifications
You must be signed in to change notification settings - Fork 251
chore: minor deduplication #3139
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
base: main
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -55,6 +55,7 @@ linters: | |
| gosec: | ||
| excludes: | ||
| - G115 | ||
| - G118 | ||
| revive: | ||
| rules: | ||
| - name: package-comments | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -354,9 +354,7 @@ func (s *Submitter) processDAInclusionLoop() { | |
| currentDAIncluded = nextHeight | ||
|
|
||
| // Persist DA included height | ||
| bz := make([]byte, 8) | ||
| binary.LittleEndian.PutUint64(bz, nextHeight) | ||
| if err := s.store.SetMetadata(s.ctx, store.DAIncludedHeightKey, bz); err != nil { | ||
| if err := putUint64Metadata(s.ctx, s.store, store.DAIncludedHeightKey, nextHeight); err != nil { | ||
| s.logger.Error().Err(err).Uint64("height", nextHeight).Msg("failed to persist DA included height") | ||
| } | ||
|
Comment on lines
+357
to
359
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Don't advance past this height unless Line 363 still deletes the per-height cache even when this write fails, but Suggested fix- // Update DA included height
- s.SetDAIncludedHeight(nextHeight)
- currentDAIncluded = nextHeight
-
- // Persist DA included height
- if err := putUint64Metadata(s.ctx, s.store, store.DAIncludedHeightKey, nextHeight); err != nil {
+ // Persist DA included height before advancing in-memory state
+ if err := putUint64Metadata(s.ctx, s.store, store.DAIncludedHeightKey, nextHeight); err != nil {
s.logger.Error().Err(err).Uint64("height", nextHeight).Msg("failed to persist DA included height")
+ break
}
+ // Update DA included height
+ s.SetDAIncludedHeight(nextHeight)
+ currentDAIncluded = nextHeight
+
// Delete height cache for that height
// This can only be performed after the height has been persisted to store
s.cache.DeleteHeight(nextHeight)🤖 Prompt for AI Agents |
||
|
|
||
|
|
@@ -415,6 +413,13 @@ func (s *Submitter) initializeDAIncludedHeight(ctx context.Context) error { | |
| return nil | ||
| } | ||
|
|
||
| // putUint64Metadata encodes val as 8-byte little-endian and writes it to the store. | ||
| func putUint64Metadata(ctx context.Context, st store.Store, key string, val uint64) error { | ||
| bz := make([]byte, 8) | ||
| binary.LittleEndian.PutUint64(bz, val) | ||
| return st.SetMetadata(ctx, key, bz) | ||
| } | ||
|
|
||
| // sendCriticalError sends a critical error to the error channel without blocking | ||
| func (s *Submitter) sendCriticalError(err error) { | ||
| if s.errorCh != nil { | ||
|
|
@@ -431,41 +436,33 @@ func (s *Submitter) sendCriticalError(err error) { | |
| func (s *Submitter) setNodeHeightToDAHeight(ctx context.Context, height uint64, data *types.Data, genesisInclusion bool) error { | ||
| dataHash := data.DACommitment() | ||
|
|
||
| headerDaHeightBytes := make([]byte, 8) | ||
| daHeightForHeader, ok := s.cache.GetHeaderDAIncludedByHeight(height) | ||
| if !ok { | ||
| return fmt.Errorf("header for height %d not found in cache", height) | ||
| } | ||
| binary.LittleEndian.PutUint64(headerDaHeightBytes, daHeightForHeader) | ||
|
|
||
| if err := s.store.SetMetadata(ctx, store.GetHeightToDAHeightHeaderKey(height), headerDaHeightBytes); err != nil { | ||
| if err := putUint64Metadata(ctx, s.store, store.GetHeightToDAHeightHeaderKey(height), daHeightForHeader); err != nil { | ||
| return err | ||
| } | ||
|
|
||
| genesisDAIncludedHeight := daHeightForHeader | ||
| dataDaHeightBytes := make([]byte, 8) | ||
| // For empty transactions, use the same DA height as the header | ||
| if bytes.Equal(dataHash, common.DataHashForEmptyTxs) { | ||
| binary.LittleEndian.PutUint64(dataDaHeightBytes, daHeightForHeader) | ||
| } else { | ||
| // For empty transactions, use the same DA height as the header. | ||
| dataDAHeight := daHeightForHeader | ||
| if !bytes.Equal(dataHash, common.DataHashForEmptyTxs) { | ||
| daHeightForData, ok := s.cache.GetDataDAIncludedByHeight(height) | ||
| if !ok { | ||
| return fmt.Errorf("data for height %d not found in cache", height) | ||
| } | ||
| binary.LittleEndian.PutUint64(dataDaHeightBytes, daHeightForData) | ||
|
|
||
| dataDAHeight = daHeightForData | ||
| // if data posted before header, use data da included height for genesis da height | ||
| genesisDAIncludedHeight = min(daHeightForData, genesisDAIncludedHeight) | ||
| } | ||
| if err := s.store.SetMetadata(ctx, store.GetHeightToDAHeightDataKey(height), dataDaHeightBytes); err != nil { | ||
| if err := putUint64Metadata(ctx, s.store, store.GetHeightToDAHeightDataKey(height), dataDAHeight); err != nil { | ||
| return err | ||
| } | ||
|
|
||
| if genesisInclusion { | ||
| genesisDAIncludedHeightBytes := make([]byte, 8) | ||
| binary.LittleEndian.PutUint64(genesisDAIncludedHeightBytes, genesisDAIncludedHeight) | ||
|
|
||
| if err := s.store.SetMetadata(ctx, store.GenesisDAHeightKey, genesisDAIncludedHeightBytes); err != nil { | ||
| if err := putUint64Metadata(ctx, s.store, store.GenesisDAHeightKey, genesisDAIncludedHeight); err != nil { | ||
| return err | ||
| } | ||
|
|
||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Preserve metadata read failures here instead of treating them as “missing”.
getMetadataUint64now maps not-found, backend read errors, and malformed values to the samefalseresult.initDAHeightFromStorethen silently skips seedingDaHeight(), so a transient store failure can look like “no metadata” and reset startup state with no diagnostic.Suggested fix
Then have
initDAHeightFromStorelog/handle the error separately and only ignore the real not-found case.🤖 Prompt for AI Agents