Skip to content

Commit

Permalink
Guard against multiple dup block inserts
Browse files Browse the repository at this point in the history
  • Loading branch information
marcopeereboom committed Oct 2, 2024
1 parent 79a6e93 commit 4aff545
Showing 1 changed file with 6 additions and 3 deletions.
9 changes: 6 additions & 3 deletions database/tbcd/level/level.go
Original file line number Diff line number Diff line change
Expand Up @@ -983,6 +983,8 @@ func (l *ldb) BlockTxUpdate(ctx context.Context, direction int, txs map[tbcd.TxK
block := make([]byte, 33)
block[0] = 'b'
var blk []byte
bm := make(map[string]struct{}, len(txs))
defer clear(bm)

txsBatch := new(leveldb.Batch)
for k, v := range txs {
Expand All @@ -994,9 +996,10 @@ func (l *ldb) BlockTxUpdate(ctx context.Context, direction int, txs map[tbcd.TxK
value = nil

// insert block hash to determine if it was indexed later
// XXX guard this operation behind a map lookup to no insert dups
copy(block[1:], k[33:65])
blk = block
if _, ok := bm[string(k[33:65])]; !ok {
copy(block[1:], k[33:65])
blk = block
}
case 's':
key = k[:]
value = v[:]
Expand Down

0 comments on commit 4aff545

Please sign in to comment.