[erigon2] Fix history bug, optimise history search (#326)

* Another fix for DeleteAccount

* Optimise bitmap search

* Optimise bitmap search

Co-authored-by: Alexey Sharp <alexeysharp@Alexeys-iMac.local>
This commit is contained in:
ledgerwatch 2022-02-13 18:56:36 +00:00 committed by GitHub
parent 79aa17d297
commit 1363859958
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 12 additions and 3 deletions

View File

@ -2436,6 +2436,9 @@ func (w *Writer) DeleteAccount(addr []byte, trace bool) {
key, _ := g.Next(nil) key, _ := g.Next(nil)
if bytes.HasPrefix(key, addr) { if bytes.HasPrefix(key, addr) {
val, _ := g.Next(nil) val, _ := g.Next(nil)
if len(val) > 0 {
val = val[1:]
}
heap.Push(&cp, &CursorItem{t: FILE_CURSOR, key: key, val: val, dg: g, endBlock: item.endBlock}) heap.Push(&cp, &CursorItem{t: FILE_CURSOR, key: key, val: val, dg: g, endBlock: item.endBlock})
} }
} }

View File

@ -224,11 +224,17 @@ func (hr *HistoryReader) searchInHistory(bitmapType, historyType FileType, key [
if _, err = bm.ReadFrom(bytes.NewReader(bitmapVal)); err != nil { if _, err = bm.ReadFrom(bytes.NewReader(bitmapVal)); err != nil {
return false return false
} }
bm.RemoveRange(0, searchTx) if searchTx == 0 {
if bm.IsEmpty() { foundTxNum = bm.Minimum()
foundEndBlock = item.endBlock
found = true
return false
}
searchRank := bm.Rank(searchTx - 1)
if searchRank >= bm.GetCardinality() {
continue continue
} }
foundTxNum = bm.Minimum() foundTxNum, _ = bm.Select(searchRank)
foundEndBlock = item.endBlock foundEndBlock = item.endBlock
found = true found = true
return false return false