Skip to content

Commit

Permalink
fix prune logic
Browse files Browse the repository at this point in the history
  • Loading branch information
kaladinlight committed Apr 24, 2024
1 parent 28ec03a commit 0975b18
Showing 1 changed file with 3 additions and 4 deletions.
7 changes: 3 additions & 4 deletions db/rocksdb.go
Original file line number Diff line number Diff line change
Expand Up @@ -349,18 +349,17 @@ const (
)

func (d *RocksDB) pruneAddressContracts(attempt float64) {
pruned := 0
desiredSize := d.maxAddrContracts / 2
threshold := math.Pow(10, attempt)
for k, v := range d.addressContracts {
if pruned >= (d.maxAddrContracts / 10) {
if len(d.addressContracts) == desiredSize {
break
}
if len(v.Contracts) < int(threshold) {
delete(d.addressContracts, k)
pruned++
}
}
if pruned == 0 {
if len(d.addressContracts) > desiredSize {
d.pruneAddressContracts(attempt + 1)
}
}
Expand Down

0 comments on commit 0975b18

Please sign in to comment.