don't check legacy tables for pruning (#5116)
These tables can't be deleted from (read-only) and would be too slow to delete from anyway due to the inefficient storage format in use. * slow down startup clearing too * remove unused del function
This commit is contained in:
parent
1bc9f3a67a
commit
17e74c0c8b
|
@ -885,18 +885,11 @@ proc delBlock*(db: BeaconChainDB, fork: ConsensusFork, key: Eth2Digest): bool =
|
|||
proc delState*(db: BeaconChainDB, fork: ConsensusFork, key: Eth2Digest) =
|
||||
discard db.statesNoVal[fork].del(key.data).expectDb()
|
||||
|
||||
proc clearBlocks*(db: BeaconChainDB, fork: ConsensusFork) =
|
||||
discard db.blocks[fork].clear().expectDb()
|
||||
proc clearBlocks*(db: BeaconChainDB, fork: ConsensusFork): bool =
|
||||
db.blocks[fork].clear().expectDb()
|
||||
|
||||
proc clearStates*(db: BeaconChainDB, fork: ConsensusFork) =
|
||||
discard db.statesNoVal[fork].clear().expectDb()
|
||||
|
||||
proc delKeyValue*(db: BeaconChainDB, key: array[1, byte]) =
|
||||
discard db.keyValues.del(key).expectDb()
|
||||
discard db.v0.backend.del(key).expectDb()
|
||||
|
||||
proc delKeyValue*(db: BeaconChainDB, key: DbKeyKind) =
|
||||
db.delKeyValue(subkey(key))
|
||||
proc clearStates*(db: BeaconChainDB, fork: ConsensusFork): bool =
|
||||
db.statesNoVal[fork].clear().expectDb()
|
||||
|
||||
proc delStateRoot*(db: BeaconChainDB, root: Eth2Digest, slot: Slot) =
|
||||
discard db.stateRoots.del(stateRootKey(root, slot)).expectDb()
|
||||
|
|
|
@ -683,13 +683,13 @@ proc getState(
|
|||
|
||||
proc containsState*(
|
||||
db: BeaconChainDB, cfg: RuntimeConfig, block_root: Eth2Digest,
|
||||
slots: Slice[Slot]): bool =
|
||||
slots: Slice[Slot], legacy = true): bool =
|
||||
var slot = slots.b
|
||||
while slot >= slots.a:
|
||||
let state_root = db.getStateRoot(block_root, slot)
|
||||
if state_root.isSome() and
|
||||
db.containsState(
|
||||
cfg.consensusForkAtEpoch(slot.epoch), state_root.get()):
|
||||
cfg.consensusForkAtEpoch(slot.epoch), state_root.get(), legacy):
|
||||
return true
|
||||
|
||||
if slot == slots.a: # avoid underflow at genesis
|
||||
|
@ -2192,7 +2192,10 @@ proc pruneHistory*(dag: ChainDAGRef, startup = false) =
|
|||
var first = true
|
||||
while cur.isSome():
|
||||
let bs = cur.get()
|
||||
if dag.db.containsState(dag.cfg, bs.bid.root, bs.slot..bs.slot):
|
||||
# We don't delete legacy states because the legacy database is openend
|
||||
# in read-only and slow to delete from due to its sub-optimal structure
|
||||
if dag.db.containsState(
|
||||
dag.cfg, bs.bid.root, bs.slot..bs.slot, legacy = first):
|
||||
if first:
|
||||
# We leave the state on the prune horizon intact and update the tail
|
||||
# to point to this state, indicating the new point in time from
|
||||
|
@ -2252,17 +2255,21 @@ proc pruneHistory*(dag: ChainDAGRef, startup = false) =
|
|||
# Once during start, we'll clear all "old fork" data - this ensures we get
|
||||
# rid of any leftover junk in the tables - we do so after linear pruning
|
||||
# so as to "mostly" clean up the phase0 tables as well (which cannot be
|
||||
# pruned easily by fork)
|
||||
# pruned easily by fork) - one fork at a time, so as not to take too long
|
||||
|
||||
let stateFork = dag.cfg.consensusForkAtEpoch(dag.tail.slot.epoch)
|
||||
var clearedStates = false
|
||||
if stateFork > ConsensusFork.Phase0:
|
||||
for fork in ConsensusFork.Phase0..<stateFork:
|
||||
dag.db.clearStates(fork)
|
||||
if dag.db.clearStates(fork):
|
||||
clearedStates = true
|
||||
break
|
||||
|
||||
let blockFork = dag.cfg.consensusForkAtEpoch(blockHorizon.epoch)
|
||||
if blockFork > ConsensusFork.Phase0:
|
||||
if not clearedStates and blockFork > ConsensusFork.Phase0:
|
||||
for fork in ConsensusFork.Phase0..<blockFork:
|
||||
dag.db.clearBlocks(fork)
|
||||
if dag.db.clearBlocks(fork):
|
||||
break
|
||||
|
||||
proc loadExecutionBlockHash*(dag: ChainDAGRef, bid: BlockId): Eth2Digest =
|
||||
if dag.cfg.consensusForkAtEpoch(bid.slot.epoch) < ConsensusFork.Bellatrix:
|
||||
|
|
Loading…
Reference in New Issue