core/txpool/blobpool: fall back on cache version mismatch

This commit is contained in:
0xoasis 2026-07-01 17:06:30 +08:00
parent 769c8c52c5
commit e34f2a2d5d
2 changed files with 24 additions and 3 deletions

View file

@ -201,9 +201,7 @@ func (c *Cache) GetBlobs(ctx context.Context, vhashes []common.Hash, version byt
cached := c.entries[vhash]
if cached == nil || cached.version != version {
cacheMiss += n
if cached == nil {
misses = append(misses, vhash)
}
misses = append(misses, vhash)
continue
}
cacheHits += n

View file

@ -280,6 +280,29 @@ func TestCacheGetBlobs(t *testing.T) {
tc.expectEntries(t, tc.vhashes[1]...)
}
func TestCacheGetBlobsFallsBackOnVersionMismatch(t *testing.T) {
tc := newTestCache(t, []txSpec{
{blobs: 1, tip: 100},
})
vhash := tc.vhashes[0][0]
tc.expectEntries(t, vhash)
tc.mu.Lock()
tc.entries[vhash].version = types.BlobSidecarVersion0
tc.mu.Unlock()
blobs, _, proofs, err := tc.GetBlobs(context.Background(), []common.Hash{vhash}, types.BlobSidecarVersion1)
if err != nil {
t.Fatalf("GetBlobs: %v", err)
}
if blobs[0] == nil {
t.Fatal("blob missing in GetBlobs response")
}
if len(proofs[0]) == 0 {
t.Fatal("proofs missing in GetBlobs response")
}
}
// TestCacheTopKRefresh verifies that when a more profitable tx appears in the
// pool, the next topK tick replaces the cached entry with the better one.
func TestCacheTopKRefresh(t *testing.T) {