From ef1729214d4d78c8fd0d69e1725227dfab6bbdeb Mon Sep 17 00:00:00 2001 From: ledgerwatch Date: Fri, 22 Sep 2023 11:08:22 +0100 Subject: [PATCH] Fixes for bor snapshots (#8270) --- turbo/snapshotsync/freezeblocks/block_reader.go | 6 ++++++ turbo/snapshotsync/freezeblocks/bor_snapshots.go | 6 ++++-- 2 files changed, 10 insertions(+), 2 deletions(-) diff --git a/turbo/snapshotsync/freezeblocks/block_reader.go b/turbo/snapshotsync/freezeblocks/block_reader.go index f55a53c0f..a837d6bf0 100644 --- a/turbo/snapshotsync/freezeblocks/block_reader.go +++ b/turbo/snapshotsync/freezeblocks/block_reader.go @@ -963,6 +963,9 @@ func (r *BlockReader) borBlockByEventHash(txnHash common.Hash, segments []*BorEv if sn.IdxBorTxnHash == nil { continue } + if sn.IdxBorTxnHash.KeyCount() == 0 { + continue + } reader := recsplit.NewIndexReader(sn.IdxBorTxnHash) blockEventId := reader.Lookup(txnHash[:]) offset := sn.IdxBorTxnHash.OrdinalLookup(blockEventId) @@ -1041,6 +1044,9 @@ func (r *BlockReader) EventsByBlock(ctx context.Context, tx kv.Tx, hash common.H if sn.IdxBorTxnHash == nil { continue } + if sn.IdxBorTxnHash.KeyCount() == 0 { + continue + } reader := recsplit.NewIndexReader(sn.IdxBorTxnHash) blockEventId := reader.Lookup(borTxHash[:]) offset := sn.IdxBorTxnHash.OrdinalLookup(blockEventId) diff --git a/turbo/snapshotsync/freezeblocks/bor_snapshots.go b/turbo/snapshotsync/freezeblocks/bor_snapshots.go index d8ea5b396..4abd61322 100644 --- a/turbo/snapshotsync/freezeblocks/bor_snapshots.go +++ b/turbo/snapshotsync/freezeblocks/bor_snapshots.go @@ -789,8 +789,8 @@ func (s *BorRoSnapshots) Files() (list []string) { func (s *BorRoSnapshots) ReopenList(fileNames []string, optimistic bool) error { s.Events.lock.Lock() defer s.Events.lock.Unlock() - s.Spans.lock.RLock() - defer s.Spans.lock.RUnlock() + s.Spans.lock.Lock() + defer s.Spans.lock.Unlock() s.closeWhatNotInList(fileNames) var segmentsMax uint64 @@ -948,6 +948,8 @@ func (s *BorRoSnapshots) ReopenWithDB(db kv.RoDB) error { func (s *BorRoSnapshots) Close() { s.Events.lock.Lock() defer s.Events.lock.Unlock() + s.Spans.lock.Lock() + defer s.Spans.lock.Unlock() s.closeWhatNotInList(nil) }