Skip to content

Commit ff62618

Browse files
authored
Check block height before populating BlockCache (#1388)
<!-- Please read and fill out this form before submitting your PR. Please make sure you have reviewed our contributors guide before submitting your first PR. --> ## Overview Duplicate of #1381 but merges to main. Also, closes: #1387 <!-- Please provide an explanation of the PR, including the appropriate context, background, goal, and rationale. If there is an issue with this information, please provide a tl;dr and link the issue. --> ## Checklist <!-- Please complete the checklist to ensure that the PR is ready to be reviewed. IMPORTANT: PRs should be left in Draft until the below checklist is completed. --> - [x] New and updated code has appropriate documentation - [x] New and updated code has new and/or updated testing - [ ] Required CI checks are passing - [ ] Visual proof for any user facing features like CLI or documentation updates - [x] Linked issues closed with keywords <!-- This is an auto-generated comment: release notes by coderabbit.ai --> ## Summary by CodeRabbit - **Refactor** - Improved the block processing logic to ensure blocks are only processed if they are new or unprocessed, enhancing the efficiency and reliability of the system. - **Bug Fixes** - Addressed an issue where previously processed blocks could be processed again, potentially leading to inconsistencies. <!-- end of auto-generated comment: release notes by coderabbit.ai -->
2 parents 8a524e5 + c12e2f1 commit ff62618

1 file changed

Lines changed: 2 additions & 1 deletion

File tree

block/manager.go

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -306,6 +306,7 @@ func (m *Manager) SyncLoop(ctx context.Context, cancel context.CancelFunc) {
306306
case <-blockTicker.C:
307307
m.sendNonBlockingSignalToBlockStoreCh()
308308
case blockEvent := <-m.blockInCh:
309+
// Only validated blocks are sent to blockInCh, so we can safely assume that blockEvent.block is valid
309310
block := blockEvent.block
310311
daHeight := blockEvent.daHeight
311312
blockHash := block.Hash().String()
@@ -315,7 +316,7 @@ func (m *Manager) SyncLoop(ctx context.Context, cancel context.CancelFunc) {
315316
"daHeight", daHeight,
316317
"hash", blockHash,
317318
)
318-
if m.blockCache.isSeen(blockHash) {
319+
if blockHeight <= m.store.Height() || m.blockCache.isSeen(blockHash) {
319320
m.logger.Debug("block already seen", "height", blockHeight, "block hash", blockHash)
320321
continue
321322
}

0 commit comments

Comments
 (0)