-
Notifications
You must be signed in to change notification settings - Fork 250
fix: persist last queried DA Height across full node restarts #2552
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
Changes from all commits
c13c613
7e7a1af
f9e0333
73c6e4b
3258471
470ffc2
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 |
|---|---|---|
|
|
@@ -317,7 +317,28 @@ func NewManager( | |
| return nil, err | ||
| } | ||
|
|
||
| if s.DAHeight < config.DA.StartHeight { | ||
| // Determine the DA height to start from based on the last applied block's DA inclusion | ||
| if s.LastBlockHeight > 0 { | ||
| // Try to find where the last applied block was included in DA | ||
| headerKey := fmt.Sprintf("%s/%d/h", storepkg.HeightToDAHeightKey, s.LastBlockHeight) | ||
| if daHeightBytes, err := store.GetMetadata(ctx, headerKey); err == nil && len(daHeightBytes) == 8 { | ||
| lastBlockDAHeight := binary.LittleEndian.Uint64(daHeightBytes) | ||
| // Start scanning from the next DA height after the last included block | ||
| s.DAHeight = lastBlockDAHeight + 1 | ||
| logger.Info(). | ||
| Uint64("lastBlockHeight", s.LastBlockHeight). | ||
| Uint64("lastBlockDAHeight", lastBlockDAHeight). | ||
| Uint64("startingDAHeight", s.DAHeight). | ||
| Msg("resuming DA scan from last applied block's DA inclusion height") | ||
| } else { | ||
| // Fallback: if we can't find DA inclusion info, use the persisted DA height | ||
| logger.Info(). | ||
| Uint64("lastBlockHeight", s.LastBlockHeight). | ||
| Uint64("daHeight", s.DAHeight). | ||
| Msg("no DA inclusion metadata found for last block, using persisted DA height") | ||
| } | ||
|
Comment on lines
+324
to
+339
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. The logic to determine the starting DA height could be more explicit about handling different failure cases. Currently, a database error and a 'not found' error are treated the same way, which can hide underlying storage problems. Refactoring this block to check for the error from daHeightBytes, err := store.GetMetadata(ctx, headerKey)
if err == nil && len(daHeightBytes) == 8 {
lastBlockDAHeight := binary.LittleEndian.Uint64(daHeightBytes)
// Start scanning from the next DA height after the last included block
s.DAHeight = lastBlockDAHeight + 1
logger.Info().
Uint64("lastBlockHeight", s.LastBlockHeight).
Uint64("lastBlockDAHeight", lastBlockDAHeight).
Uint64("startingDAHeight", s.DAHeight).
Msg("resuming DA scan from last applied block's DA inclusion height")
} else {
if err != nil {
if !errors.Is(err, ds.ErrNotFound) {
logger.Warn().Err(err).Msg("Error retrieving DA inclusion metadata for last block")
}
} else { // err == nil, so len is wrong
logger.Warn().Int("len", len(daHeightBytes)).Msg("malformed DA inclusion metadata for last block")
}
// Fallback: if we can't find DA inclusion info, use the persisted DA height
logger.Info().
Uint64("lastBlockHeight", s.LastBlockHeight).
Uint64("daHeight", s.DAHeight).
Msg("no DA inclusion metadata found for last block, using persisted DA height")
} |
||
| } else if s.DAHeight < config.DA.StartHeight { | ||
| // For fresh chains, use the configured start height | ||
| s.DAHeight = config.DA.StartHeight | ||
| } | ||
|
|
||
|
|
@@ -519,6 +540,27 @@ func (m *Manager) IsDAIncluded(ctx context.Context, height uint64) (bool, error) | |
| return isIncluded, nil | ||
| } | ||
|
|
||
| // storeDAInclusionMetadata stores the DA height where a block was included. | ||
| // This is used by both aggregators (via SetSequencerHeightToDAHeight) and | ||
| // non-aggregator nodes during sync to track where blocks came from in DA. | ||
| func (m *Manager) storeDAInclusionMetadata(ctx context.Context, blockHeight uint64, daHeight uint64) error { | ||
| // Store header DA height | ||
| headerHeightBytes := make([]byte, 8) | ||
| binary.LittleEndian.PutUint64(headerHeightBytes, daHeight) | ||
| headerKey := fmt.Sprintf("%s/%d/h", storepkg.HeightToDAHeightKey, blockHeight) | ||
| if err := m.store.SetMetadata(ctx, headerKey, headerHeightBytes); err != nil { | ||
| return fmt.Errorf("failed to store header DA height: %w", err) | ||
| } | ||
|
|
||
| // Store data DA height (same as header for synced blocks) | ||
| dataKey := fmt.Sprintf("%s/%d/d", storepkg.HeightToDAHeightKey, blockHeight) | ||
| if err := m.store.SetMetadata(ctx, dataKey, headerHeightBytes); err != nil { | ||
| return fmt.Errorf("failed to store data DA height: %w", err) | ||
| } | ||
|
|
||
| return nil | ||
| } | ||
|
|
||
| // SetSequencerHeightToDAHeight stores the mapping from a Evolve block height to the corresponding | ||
| // DA (Data Availability) layer heights where the block's header and data were included. | ||
| // This mapping is persisted in the store metadata and is used to track which DA heights | ||
|
|
||
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.
Is the DA height actually persisted? If it was then why would it always start from 0?
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.
i think there is another bug, that is hidden here. ive been going through the code slowly. there is a startup discrepancy