mirror of
https://github.com/ethereum/go-ethereum.git
synced 2026-07-27 07:06:42 +00:00
core/rawdb: add PruneTransactionIndex
This commit is contained in:
parent
55a4a392cb
commit
2e470f1865
1 changed files with 27 additions and 0 deletions
|
|
@ -17,6 +17,8 @@
|
||||||
package rawdb
|
package rawdb
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"encoding/binary"
|
||||||
|
"fmt"
|
||||||
"runtime"
|
"runtime"
|
||||||
"sync/atomic"
|
"sync/atomic"
|
||||||
"time"
|
"time"
|
||||||
|
|
@ -361,3 +363,28 @@ func UnindexTransactions(db ethdb.Database, from uint64, to uint64, interrupt ch
|
||||||
func unindexTransactionsForTesting(db ethdb.Database, from uint64, to uint64, interrupt chan struct{}, hook func(uint64) bool) {
|
func unindexTransactionsForTesting(db ethdb.Database, from uint64, to uint64, interrupt chan struct{}, hook func(uint64) bool) {
|
||||||
unindexTransactions(db, from, to, interrupt, hook, false)
|
unindexTransactions(db, from, to, interrupt, hook, false)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// PruneTransactionIndex removes all tx index entries below a certain block number.
|
||||||
|
func PruneTransactionIndex(db ethdb.Database, pruneBlock uint64) {
|
||||||
|
index := NewTable(db, string(txLookupPrefix))
|
||||||
|
iter := index.NewIterator(nil, nil)
|
||||||
|
defer iter.Release()
|
||||||
|
|
||||||
|
for iter.Next() {
|
||||||
|
v := iter.Value()
|
||||||
|
if len(v) > 8 {
|
||||||
|
continue // legacy entry
|
||||||
|
}
|
||||||
|
bn := decodeNumber(v)
|
||||||
|
if bn < pruneBlock {
|
||||||
|
fmt.Println("found entry", iter.Key())
|
||||||
|
// db.Delete(iter.Key())
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
func decodeNumber(b []byte) uint64 {
|
||||||
|
var numBuffer [8]byte
|
||||||
|
copy(numBuffer[8-len(b):], b)
|
||||||
|
return binary.BigEndian.Uint64(numBuffer[:])
|
||||||
|
}
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue