Skip to content

Serve verified uncommitted blocks to seq-only lookups in CachedStorage - #497

Open
samliok wants to merge 2 commits into
mainfrom
fix/cachedstorage-seq-only-lookup
Open

Serve verified uncommitted blocks to seq-only lookups in CachedStorage#497
samliok wants to merge 2 commits into
mainfrom
fix/cachedstorage-seq-only-lookup

Conversation

@samliok

@samliok samliok commented Aug 6, 2026

Copy link
Copy Markdown
Collaborator

CachedStorage keeps verified-but-not-yet-finalized blocks in a cache keyed by digest. The msm sealing-block checks (buildBlockOrTransitionEpoch, areWeReadyToTransitionEpoch) look blocks up by sequence only and pass a zero digest, so they can never hit the cache. The lookup falls through to committed storage, and while the sealing block is notarized but not yet indexed, block building fails with failed to retrieve sealing block for previous epoch. The failed build is not retried, so the leader misses its round and the round empty-notarizes.

Comment thread adapters.go Outdated
Comment thread adapters.go Outdated
Comment thread adapters.go Outdated
Comment thread adapters.go

item, exists := cs.cache[digest]
if exists {
cs.lock.RUnlock()

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

why the locking change?

Comment thread adapters.go Outdated

// If we are requesting an empty digest, and the sequence is not found in storage,
// check if we have verified but not indexed this sequence
if err == common.ErrBlockNotFound && digest == (common.Digest{}) {

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

shouldn't this be: f err == common.ErrBlockNotFound || digest == (common.Digest{}) ?

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

no in this case it should be &&.

because || would mean we grab and return from the cache even if we returned a block & finalization above. this shouldn't happen because if we finalize a block, it shouldn't be in the cache but still ranging through the cache seems unnecessary.

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

After reading the code again - I just noticed that we do the check after we check the storage with cs.GetBlock(seq) in line 126.

Why do we do that? Shouldn't we iterate the cache before we ask the storage?

What's the point of asking the storage first?

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can't we do this?

func (cs *CachedStorage) Retrieve(seq uint64, digest common.Digest) (common.VerifiedBlock, *common.Finalization, error) {
	cs.lock.RLock()
	defer cs.lock.RUnlock()

	// A cached block is not finalized yet, since indexing removes it from the cache.
	if item, exists := cs.cache[digest]; exists {
		return item.ParsedBlock, nil, nil
	}

	for _, cb := range cs.cache {
		if cb.BlockHeader().Seq == seq && digest == (common.Digest{}) {
			return cb.ParsedBlock, nil, nil
		}
	}

	// We don't populate the cache here because we populate it externally.
	block, finalization, err := cs.GetBlock(seq)
	if err == nil {
		return &ParsedBlock{
			StateMachineBlock: block,
			msm:               cs.msm,
		}, finalization, nil
	}

	return nil, nil, err
}

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

yep, i updated the logic + re-added the locking stuff from before

@samliok
samliok marked this pull request as draft August 17, 2026 18:25
@samliok
samliok force-pushed the fix/cachedstorage-seq-only-lookup branch from 25d253c to 04bca80 Compare August 17, 2026 19:43
@samliok
samliok force-pushed the fix/cachedstorage-seq-only-lookup branch from 8268292 to 3cebdc0 Compare August 17, 2026 19:44
@samliok
samliok marked this pull request as ready for review August 17, 2026 19:45
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants