Skip to content

Commit

Permalink
un-stub some ncli_db code so that it uses
Browse files Browse the repository at this point in the history
  • Loading branch information
tersec committed Mar 4, 2021
1 parent 6633ae0 commit ae28a4c
Show file tree
Hide file tree
Showing 4 changed files with 12 additions and 17 deletions.
4 changes: 4 additions & 0 deletions beacon_chain/beacon_chain_db.nim
Original file line number Diff line number Diff line change
Expand Up @@ -617,3 +617,7 @@ iterator getAncestorSummaries*(db: BeaconChainDB, root: Eth2Digest):
break

root = res.summary.parent_root

proc loadImmutableValidators*(db: BeaconChainDB): seq[ImmutableValidatorData] =
for i in 0'u64 ..< db.immutableValidators.len:
result.add db.immutableValidators.get(i)
4 changes: 0 additions & 4 deletions beacon_chain/block_pools/chain_dag.nim
Original file line number Diff line number Diff line change
Expand Up @@ -304,10 +304,6 @@ proc loadStateCache*(cache: var StateCache, blck: BlockRef, epoch: Epoch) =
if epoch > 0:
load(epoch - 1)

proc loadImmutableValidators(db: BeaconChainDB): seq[ImmutableValidatorData] =
for i in 0'u64 ..< db.immutableValidators.len:
result.add db.immutableValidators.get(i)

func init(T: type BlockRef, root: Eth2Digest, slot: Slot): BlockRef =
BlockRef(
root: root,
Expand Down
18 changes: 8 additions & 10 deletions ncli/ncli_db.nim
Original file line number Diff line number Diff line change
Expand Up @@ -130,10 +130,9 @@ proc cmdBench(conf: DbConf, runtimePreset: RuntimePreset) =
root: db.getBlock(blockRefs[^1].root).get().message.state_root
)

var foo: seq[ImmutableValidatorData]
withTimer(timers[tLoadState]):
discard db.getState(state[].root, state[].data, noRollback, foo)
#discard db.getState(state[].root, state[].data, noRollback, pool.iv)
discard db.getState(
state[].root, state[].data, noRollback, pool.immutableValidators)

var cache = StateCache()

Expand Down Expand Up @@ -168,17 +167,16 @@ proc cmdBench(conf: DbConf, runtimePreset: RuntimePreset) =
printTimers(false, timers)

proc cmdDumpState(conf: DbConf, preset: RuntimePreset) =
let db = BeaconChainDB.init(preset, conf.databaseDir.string)
let
db = BeaconChainDB.init(preset, conf.databaseDir.string)
immutableValidators = db.loadImmutableValidators()
defer: db.close()

var foo: seq[ImmutableValidatorData]
# TODO move the load-immutable-validators thing out of chain dag maybe, since
# want it here too. then use that instead of `foo`
for stateRoot in conf.stateRoot:
try:
let root = Eth2Digest(data: hexToByteArray[32](stateRoot))
var state = (ref HashedBeaconState)(root: root)
if not db.getState(root, state.data, noRollback, foo):
if not db.getState(root, state.data, noRollback, immutableValidators):
echo "Couldn't load ", root
else:
dump("./", state[])
Expand Down Expand Up @@ -221,9 +219,9 @@ proc copyPrunedDatabase(
let headEpoch = db.getBlock(headBlock.get).get.message.slot.epoch

# Tail states are specially addressed; no stateroot intermediary
# TODO here, want to copy raw blocks, not the processed forms,
# and also the immutable validators; might need to adjust APIs
var foo: seq[ImmutableValidatorData]
# TODO move the load-immutable-validators thing out of chain dag maybe, since
# want it here too. then use that instead of `foo`
if not db.getState(
db.getBlock(tailBlock.get).get.message.state_root, beaconState[],
noRollback, foo):
Expand Down
3 changes: 0 additions & 3 deletions tests/test_beacon_chain_db.nim
Original file line number Diff line number Diff line change
Expand Up @@ -189,9 +189,6 @@ suiteReport "Beacon chain DB" & preset():
immutableValidators: seq[ImmutableValidatorData] = @[]

# TODO make sure there's a validator

# TODO it's fine, but maybe for testing purposes should be able to force a
# non-split-validators store. the interface isn't yet different
db.putState(state[])

check:
Expand Down

0 comments on commit ae28a4c

Please sign in to comment.