From 09671fdc0f61c5773eb3de42f893761a450e43d2 Mon Sep 17 00:00:00 2001 From: Jacek Sieka Date: Mon, 27 Apr 2020 12:18:00 +0200 Subject: [PATCH] avoid memory allocations and copies when loading states * rolls back some of the ref changes * adds utility to calculate stack sizes --- Makefile | 3 +- beacon_chain/attestation_pool.nim | 8 +- beacon_chain/beacon_chain_db.nim | 43 ++++++++-- beacon_chain/beacon_node.nim | 50 ++++++------ beacon_chain/beacon_node_types.nim | 14 ---- beacon_chain/block_pool.nim | 127 +++++++++++++++++------------ beacon_chain/spec/datatypes.nim | 7 +- beacon_chain/state_transition.nim | 16 ++-- ncli/ncli_hash_tree_root.nim | 21 ++--- ncli/ncli_pretty.nim | 21 ++--- ncli/ncli_transition.nim | 9 +- nfuzz/libnfuzz.nim | 32 ++++---- research/stackSizes.nim | 24 ++++++ tests/test_attestation_pool.nim | 58 ++++++------- tests/test_beacon_chain_db.nim | 23 +++--- tests/test_block_pool.nim | 22 ++--- tests/testutil.nim | 4 +- 17 files changed, 274 insertions(+), 208 deletions(-) create mode 100644 research/stackSizes.nim diff --git a/Makefile b/Makefile index 50f3132feb..7f20d0e216 100644 --- a/Makefile +++ b/Makefile @@ -22,7 +22,8 @@ TOOLS := \ ncli_hash_tree_root \ ncli_pretty \ ncli_transition \ - process_dashboard + process_dashboard \ + stackSizes # bench_bls_sig_agggregation TODO reenable after bls v0.10.1 changes TOOLS_DIRS := \ beacon_chain \ diff --git a/beacon_chain/attestation_pool.nim b/beacon_chain/attestation_pool.nim index 858e9a0a5c..38ab31457e 100644 --- a/beacon_chain/attestation_pool.nim +++ b/beacon_chain/attestation_pool.nim @@ -180,7 +180,7 @@ proc addResolved(pool: var AttestationPool, blck: BlockRef, attestation: Attesta pool.blockPool, pool.blockPool.tmpState, BlockSlot(blck: blck, slot: attestation.data.slot)) - template state(): BeaconState = pool.blockPool.tmpState.data.data[] + template state(): BeaconState = pool.blockPool.tmpState.data.data if not validate(state, attestation): notice "Invalid attestation", @@ -456,7 +456,7 @@ proc selectHead*(pool: AttestationPool): BlockRef = justifiedHead = pool.blockPool.latestJustifiedBlock() let newHead = - lmdGhost(pool, pool.blockPool.justifiedState.data.data[], justifiedHead.blck) + lmdGhost(pool, pool.blockPool.justifiedState.data.data, justifiedHead.blck) newHead @@ -529,9 +529,9 @@ proc isValidAttestation*( # as it supports aggregated attestations (which this can't be) var cache = get_empty_per_epoch_cache() if not is_valid_indexed_attestation( - pool.blockPool.headState.data.data[], + pool.blockPool.headState.data.data, get_indexed_attestation( - pool.blockPool.headState.data.data[], attestation, cache), {}): + pool.blockPool.headState.data.data, attestation, cache), {}): debug "isValidAttestation: signature verification failed" return false diff --git a/beacon_chain/beacon_chain_db.nim b/beacon_chain/beacon_chain_db.nim index 0e300e5146..c9ad13c90d 100644 --- a/beacon_chain/beacon_chain_db.nim +++ b/beacon_chain/beacon_chain_db.nim @@ -1,10 +1,12 @@ {.push raises: [Defect].} import - options, typetraits, stew/[results, endians2], + typetraits, stew/[results, endians2], serialization, chronicles, spec/[datatypes, digest, crypto], - kvstore, ssz + kvstore, ssz, state_transition + +export results type BeaconChainDB* = ref object @@ -45,7 +47,7 @@ func subkey[N: static int](kind: DbKeyKind, key: array[N, byte]): result[0] = byte ord(kind) result[1 .. ^1] = key -func subkey(kind: type BeaconStateRef, key: Eth2Digest): auto = +func subkey(kind: type BeaconState, key: Eth2Digest): auto = subkey(kHashToState, key.data) func subkey(kind: type SignedBeaconBlock, key: Eth2Digest): auto = @@ -86,13 +88,13 @@ proc get(db: BeaconChainDB, key: openArray[byte], T: typedesc): Opt[T] = proc putBlock*(db: BeaconChainDB, key: Eth2Digest, value: SignedBeaconBlock) = db.put(subkey(type value, key), value) -proc putState*(db: BeaconChainDB, key: Eth2Digest, value: BeaconStateRef) = +proc putState*(db: BeaconChainDB, key: Eth2Digest, value: BeaconState) = # TODO prune old states - this is less easy than it seems as we never know # when or if a particular state will become finalized. db.put(subkey(type value, key), value) -proc putState*(db: BeaconChainDB, value: BeaconStateRef) = +proc putState*(db: BeaconChainDB, value: BeaconState) = db.putState(hash_tree_root(value), value) proc putStateRoot*(db: BeaconChainDB, root: Eth2Digest, slot: Slot, @@ -108,7 +110,7 @@ proc delBlock*(db: BeaconChainDB, key: Eth2Digest) = "working database") proc delState*(db: BeaconChainDB, key: Eth2Digest) = - db.backend.del(subkey(BeaconStateRef, key)).expect("working database") + db.backend.del(subkey(BeaconState, key)).expect("working database") proc delStateRoot*(db: BeaconChainDB, root: Eth2Digest, slot: Slot) = db.backend.del(subkey(root, slot)).expect("working database") @@ -122,8 +124,31 @@ proc putTailBlock*(db: BeaconChainDB, key: Eth2Digest) = proc getBlock*(db: BeaconChainDB, key: Eth2Digest): Opt[SignedBeaconBlock] = db.get(subkey(SignedBeaconBlock, key), SignedBeaconBlock) -proc getState*(db: BeaconChainDB, key: Eth2Digest): Opt[BeaconStateRef] = - db.get(subkey(BeaconStateRef, key), BeaconStateRef) +proc getState*( + db: BeaconChainDB, key: Eth2Digest, output: var BeaconState, + rollback: RollbackProc): bool = + ## Load state into `output` - BeaconState is large so we want to avoid + ## re-allocating it if possible + ## Return `true` iff the entry was found in the database and `output` was + ## overwritten. + # TODO rollback is needed to deal with bug - use `noRollback` to ignore: + # https://github.com/nim-lang/Nim/issues/14126 + # TODO RVO is inefficient for large objects: + # https://github.com/nim-lang/Nim/issues/13879 + # TODO address is needed because there's no way to express lifetimes in nim + # we'll use unsafeAddr to find the code later + let outputAddr = unsafeAddr output # callback is local + proc decode(data: openArray[byte]) = + try: + # TODO can't write to output directly.. + outputAddr[] = SSZ.decode(data, BeaconState) + except SerializationError as e: + # If the data can't be deserialized, it could be because it's from a + # version of the software that uses a different SSZ encoding + warn "Unable to deserialize data, old database?", err = e.msg + rollback(outputAddr[]) + + db.backend.get(subkey(BeaconState, key), decode).expect("working database") proc getStateRoot*(db: BeaconChainDB, root: Eth2Digest, @@ -140,7 +165,7 @@ proc containsBlock*(db: BeaconChainDB, key: Eth2Digest): bool = db.backend.contains(subkey(SignedBeaconBlock, key)).expect("working database") proc containsState*(db: BeaconChainDB, key: Eth2Digest): bool = - db.backend.contains(subkey(BeaconStateRef, key)).expect("working database") + db.backend.contains(subkey(BeaconState, key)).expect("working database") iterator getAncestors*(db: BeaconChainDB, root: Eth2Digest): tuple[root: Eth2Digest, blck: SignedBeaconBlock] = diff --git a/beacon_chain/beacon_node.nim b/beacon_chain/beacon_node.nim index 3fdb0d15c6..aa27c6efab 100644 --- a/beacon_chain/beacon_node.nim +++ b/beacon_chain/beacon_node.nim @@ -23,7 +23,7 @@ import attestation_pool, block_pool, eth2_network, eth2_discovery, beacon_node_types, mainchain_monitor, version, ssz, ssz/dynamic_navigator, sync_protocol, request_manager, validator_keygen, interop, statusbar, - attestation_aggregation, sync_manager + attestation_aggregation, sync_manager, state_transition const genesisFile = "genesis.ssz" @@ -122,11 +122,15 @@ proc getStateFromSnapshot(conf: BeaconNodeConf): NilableBeaconStateRef = quit 1 try: - result = SSZ.decode(snapshotContents, BeaconStateRef) + let res = BeaconStateRef() + res[] = SSZ.decode(snapshotContents, BeaconState) + result = res except SerializationError: error "Failed to import genesis file", path = genesisPath quit 1 + echo sizeof(result[]) + info "Loaded genesis state", path = genesisPath if writeGenesisFile: @@ -192,7 +196,7 @@ proc init*(T: type BeaconNode, conf: BeaconNodeConf): Future[BeaconNode] {.async let tailBlock = get_initial_beacon_block(genesisState[]) try: - BlockPool.preInit(db, genesisState, tailBlock) + BlockPool.preInit(db, genesisState[], tailBlock) doAssert BlockPool.isInitialized(db), "preInit should have initialized db" except CatchableError as e: error "Failed to initialize database", err = e.msg @@ -219,7 +223,7 @@ proc init*(T: type BeaconNode, conf: BeaconNodeConf): Future[BeaconNode] {.async nil let - enrForkId = enrForkIdFromState(blockPool.headState.data.data[]) + enrForkId = enrForkIdFromState(blockPool.headState.data.data) topicBeaconBlocks = getBeaconBlocksTopic(enrForkId.forkDigest) topicAggregateAndProofs = getAggregateAndProofsTopic(enrForkId.forkDigest) network = await createEth2Node(conf, enrForkId) @@ -235,7 +239,7 @@ proc init*(T: type BeaconNode, conf: BeaconNodeConf): Future[BeaconNode] {.async blockPool: blockPool, attestationPool: AttestationPool.init(blockPool), mainchainMonitor: mainchainMonitor, - beaconClock: BeaconClock.init(blockPool.headState.data.data[]), + beaconClock: BeaconClock.init(blockPool.headState.data.data), rpcServer: rpcServer, forkDigest: enrForkId.forkDigest, topicBeaconBlocks: topicBeaconBlocks, @@ -410,15 +414,15 @@ proc proposeBlock(node: BeaconNode, (get_eth1data_stub(state.eth1_deposit_index, slot.compute_epoch_at_slot()), newSeq[Deposit]()) else: - node.mainchainMonitor.getBlockProposalData(state[]) + node.mainchainMonitor.getBlockProposalData(state) let message = makeBeaconBlock( - state[], + state, head.root, validator.genRandaoReveal(state.fork, state.genesis_validators_root, slot), eth1data, Eth2Digest(), - node.attestationPool.getAttestationsForBlock(state[]), + node.attestationPool.getAttestationsForBlock(state), deposits) if not message.isSome(): @@ -576,16 +580,16 @@ proc handleAttestations(node: BeaconNode, head: BlockRef, slot: Slot) = # version here that calculates the committee for a single slot only node.blockPool.withState(node.blockPool.tmpState, attestationHead): var cache = get_empty_per_epoch_cache() - let committees_per_slot = get_committee_count_at_slot(state[], slot) + let committees_per_slot = get_committee_count_at_slot(state, slot) for committee_index in 0'u64..8} {spaces(indent)}{n}: {typeof(t).name}" + + when t is object|tuple: + for n, p in t.fieldPairs: + print(p, n, indent + 1) + +print(BeaconState(), "state", 0) + +echo "" + +print(SignedBeaconBlock(), "block", 0) + +echo "" + +print(Validator(), "validator", 0) + +echo "" + +print(Attestation(), "attestation", 0) diff --git a/tests/test_attestation_pool.nim b/tests/test_attestation_pool.nim index aa891f49aa..71e0e80afe 100644 --- a/tests/test_attestation_pool.nim +++ b/tests/test_attestation_pool.nim @@ -29,7 +29,7 @@ when const_preset == "minimal": # Too much stack space used on mainnet var blockPool = BlockPool.init(makeTestDB(SLOTS_PER_EPOCH * 3)) pool = AttestationPool.init(blockPool) - state = loadTailState(blockPool) + state = newClone(loadTailState(blockPool)) # Slot 0 is a finalized slot - won't be making attestations for it.. process_slots(state.data, state.data.data.slot + 1) @@ -38,15 +38,15 @@ when const_preset == "minimal": # Too much stack space used on mainnet let # Create an attestation for slot 1! beacon_committee = get_beacon_committee( - state.data.data[], state.data.data.slot, 0.CommitteeIndex, cache) + state.data.data, state.data.data.slot, 0.CommitteeIndex, cache) attestation = makeAttestation( - state.data.data[], state.blck.root, beacon_committee[0], cache) + state.data.data, state.blck.root, beacon_committee[0], cache) pool.add(attestation) process_slots(state.data, MIN_ATTESTATION_INCLUSION_DELAY.Slot + 1) - let attestations = pool.getAttestationsForBlock(state.data.data[]) + let attestations = pool.getAttestationsForBlock(state.data.data) check: attestations.len == 1 @@ -56,17 +56,17 @@ when const_preset == "minimal": # Too much stack space used on mainnet let # Create an attestation for slot 1! bc0 = get_beacon_committee( - state.data.data[], state.data.data.slot, 0.CommitteeIndex, cache) + state.data.data, state.data.data.slot, 0.CommitteeIndex, cache) attestation0 = makeAttestation( - state.data.data[], state.blck.root, bc0[0], cache) + state.data.data, state.blck.root, bc0[0], cache) process_slots(state.data, state.data.data.slot + 1) let - bc1 = get_beacon_committee(state.data.data[], + bc1 = get_beacon_committee(state.data.data, state.data.data.slot, 0.CommitteeIndex, cache) attestation1 = makeAttestation( - state.data.data[], state.blck.root, bc1[0], cache) + state.data.data, state.blck.root, bc1[0], cache) # test reverse order pool.add(attestation1) @@ -74,7 +74,7 @@ when const_preset == "minimal": # Too much stack space used on mainnet process_slots(state.data, MIN_ATTESTATION_INCLUSION_DELAY.Slot + 1) - let attestations = pool.getAttestationsForBlock(state.data.data[]) + let attestations = pool.getAttestationsForBlock(state.data.data) check: attestations.len == 1 @@ -84,18 +84,18 @@ when const_preset == "minimal": # Too much stack space used on mainnet let # Create an attestation for slot 1! bc0 = get_beacon_committee( - state.data.data[], state.data.data.slot, 0.CommitteeIndex, cache) + state.data.data, state.data.data.slot, 0.CommitteeIndex, cache) attestation0 = makeAttestation( - state.data.data[], state.blck.root, bc0[0], cache) + state.data.data, state.blck.root, bc0[0], cache) attestation1 = makeAttestation( - state.data.data[], state.blck.root, bc0[1], cache) + state.data.data, state.blck.root, bc0[1], cache) pool.add(attestation0) pool.add(attestation1) process_slots(state.data, MIN_ATTESTATION_INCLUSION_DELAY.Slot + 1) - let attestations = pool.getAttestationsForBlock(state.data.data[]) + let attestations = pool.getAttestationsForBlock(state.data.data) check: attestations.len == 1 @@ -106,11 +106,11 @@ when const_preset == "minimal": # Too much stack space used on mainnet var # Create an attestation for slot 1! bc0 = get_beacon_committee( - state.data.data[], state.data.data.slot, 0.CommitteeIndex, cache) + state.data.data, state.data.data.slot, 0.CommitteeIndex, cache) attestation0 = makeAttestation( - state.data.data[], state.blck.root, bc0[0], cache) + state.data.data, state.blck.root, bc0[0], cache) attestation1 = makeAttestation( - state.data.data[], state.blck.root, bc0[1], cache) + state.data.data, state.blck.root, bc0[1], cache) attestation0.combine(attestation1, {}) @@ -119,7 +119,7 @@ when const_preset == "minimal": # Too much stack space used on mainnet process_slots(state.data, MIN_ATTESTATION_INCLUSION_DELAY.Slot + 1) - let attestations = pool.getAttestationsForBlock(state.data.data[]) + let attestations = pool.getAttestationsForBlock(state.data.data) check: attestations.len == 1 @@ -128,12 +128,12 @@ when const_preset == "minimal": # Too much stack space used on mainnet var cache = get_empty_per_epoch_cache() var # Create an attestation for slot 1! - bc0 = get_beacon_committee(state.data.data[], + bc0 = get_beacon_committee(state.data.data, state.data.data.slot, 0.CommitteeIndex, cache) attestation0 = makeAttestation( - state.data.data[], state.blck.root, bc0[0], cache) + state.data.data, state.blck.root, bc0[0], cache) attestation1 = makeAttestation( - state.data.data[], state.blck.root, bc0[1], cache) + state.data.data, state.blck.root, bc0[1], cache) attestation0.combine(attestation1, {}) @@ -142,14 +142,14 @@ when const_preset == "minimal": # Too much stack space used on mainnet process_slots(state.data, MIN_ATTESTATION_INCLUSION_DELAY.Slot + 1) - let attestations = pool.getAttestationsForBlock(state.data.data[]) + let attestations = pool.getAttestationsForBlock(state.data.data) check: attestations.len == 1 timedTest "Fork choice returns latest block with no attestations": let - b1 = addTestBlock(state.data.data[], blockPool.tail.root) + b1 = addTestBlock(state.data.data, blockPool.tail.root) b1Root = hash_tree_root(b1.message) b1Add = blockPool.add(b1Root, b1) head = pool.selectHead() @@ -158,7 +158,7 @@ when const_preset == "minimal": # Too much stack space used on mainnet head == b1Add let - b2 = addTestBlock(state.data.data[], b1Root) + b2 = addTestBlock(state.data.data, b1Root) b2Root = hash_tree_root(b2.message) b2Add = blockPool.add(b2Root, b2) head2 = pool.selectHead() @@ -169,7 +169,7 @@ when const_preset == "minimal": # Too much stack space used on mainnet timedTest "Fork choice returns block with attestation": var cache = get_empty_per_epoch_cache() let - b10 = makeTestBlock(state.data.data[], blockPool.tail.root) + b10 = makeTestBlock(state.data.data, blockPool.tail.root) b10Root = hash_tree_root(b10.message) b10Add = blockPool.add(b10Root, b10) head = pool.selectHead() @@ -178,15 +178,15 @@ when const_preset == "minimal": # Too much stack space used on mainnet head == b10Add let - b11 = makeTestBlock(state.data.data[], blockPool.tail.root, + b11 = makeTestBlock(state.data.data, blockPool.tail.root, graffiti = Eth2Digest(data: [1'u8, 0, 0, 0 ,0 ,0 ,0 ,0 ,0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0]) ) b11Root = hash_tree_root(b11.message) b11Add = blockPool.add(b11Root, b11) bc1 = get_beacon_committee( - state.data.data[], state.data.data.slot, 1.CommitteeIndex, cache) - attestation0 = makeAttestation(state.data.data[], b10Root, bc1[0], cache) + state.data.data, state.data.data.slot, 1.CommitteeIndex, cache) + attestation0 = makeAttestation(state.data.data, b10Root, bc1[0], cache) pool.add(attestation0) @@ -197,8 +197,8 @@ when const_preset == "minimal": # Too much stack space used on mainnet head2 == b10Add let - attestation1 = makeAttestation(state.data.data[], b11Root, bc1[1], cache) - attestation2 = makeAttestation(state.data.data[], b11Root, bc1[2], cache) + attestation1 = makeAttestation(state.data.data, b11Root, bc1[1], cache) + attestation2 = makeAttestation(state.data.data, b11Root, bc1[2], cache) pool.add(attestation1) let head3 = pool.selectHead() diff --git a/tests/test_beacon_chain_db.nim b/tests/test_beacon_chain_db.nim index c9c715944c..7e02a4a4e4 100644 --- a/tests/test_beacon_chain_db.nim +++ b/tests/test_beacon_chain_db.nim @@ -8,7 +8,7 @@ {.used.} import options, unittest, sequtils, - ../beacon_chain/[beacon_chain_db, extras, interop, ssz, kvstore], + ../beacon_chain/[beacon_chain_db, extras, interop, ssz, kvstore, state_transition], ../beacon_chain/spec/[beaconstate, datatypes, digest, crypto], # test utilies ./testutil, ./testblockutil @@ -17,13 +17,10 @@ suiteReport "Beacon chain DB" & preset(): timedTest "empty database" & preset(): var db = init(BeaconChainDB, kvStore MemStoreRef.init()) - + tmpState = BeaconStateRef() check: - when const_preset=="minimal": - db.getState(Eth2Digest()).isNone and db.getBlock(Eth2Digest()).isNone - else: - # TODO re-check crash here in mainnet - true + not db.getState(Eth2Digest(), tmpState[], noRollback) + db.getBlock(Eth2Digest()).isNone timedTest "sanity check blocks" & preset(): var @@ -49,13 +46,15 @@ suiteReport "Beacon chain DB" & preset(): let state = BeaconStateRef() + state2 = BeaconStateRef() root = hash_tree_root(state) - db.putState(state) + db.putState(state[]) check: db.containsState(root) - db.getState(root).get[] == state[] + db.getState(root, state2[], noRollback) + state2[] == state[] timedTest "find ancestors" & preset(): var @@ -102,8 +101,10 @@ suiteReport "Beacon chain DB" & preset(): eth1BlockHash, 0, makeInitialDeposits(SLOTS_PER_EPOCH), {skipBlsValidation}) root = hash_tree_root(state) - db.putState(state) + db.putState(state[]) + var tmpState = BeaconStateRef() check: db.containsState(root) - db.getState(root).get[] == state[] + db.getState(root, tmpState[], noRollback) + tmpState[] == state[] diff --git a/tests/test_block_pool.nim b/tests/test_block_pool.nim index 9423d2748e..bbb8e7cfbb 100644 --- a/tests/test_block_pool.nim +++ b/tests/test_block_pool.nim @@ -94,7 +94,7 @@ when const_preset == "minimal": # Too much stack space used on mainnet var db = makeTestDB(SLOTS_PER_EPOCH) pool = BlockPool.init(db) - state = pool.loadTailState().data.data + state = newClone(pool.loadTailState().data.data) b1 = addTestBlock(state[], pool.tail.root) b1Root = hash_tree_root(b1.message) b2 = addTestBlock(state[], b1Root) @@ -242,42 +242,42 @@ when const_preset == "minimal": # Too much stack space used on mainnet bs1_3 = b1Add.atSlot(3.Slot) bs2_3 = b2Add.atSlot(3.Slot) - var tmpState = clone(pool.headState) + var tmpState = newClone(pool.headState) # move to specific block - pool.updateStateData(tmpState, bs1) + pool.updateStateData(tmpState[], bs1) check: tmpState.blck == b1Add tmpState.data.data.slot == bs1.slot # Skip slots - pool.updateStateData(tmpState, bs1_3) # skip slots + pool.updateStateData(tmpState[], bs1_3) # skip slots check: tmpState.blck == b1Add tmpState.data.data.slot == bs1_3.slot # Move back slots, but not blocks - pool.updateStateData(tmpState, bs1_3.parent()) + pool.updateStateData(tmpState[], bs1_3.parent()) check: tmpState.blck == b1Add tmpState.data.data.slot == bs1_3.parent().slot # Move to different block and slot - pool.updateStateData(tmpState, bs2_3) + pool.updateStateData(tmpState[], bs2_3) check: tmpState.blck == b2Add tmpState.data.data.slot == bs2_3.slot # Move back slot and block - pool.updateStateData(tmpState, bs1) + pool.updateStateData(tmpState[], bs1) check: tmpState.blck == b1Add tmpState.data.data.slot == bs1.slot # Move back to genesis - pool.updateStateData(tmpState, bs1.parent()) + pool.updateStateData(tmpState[], bs1.parent()) check: tmpState.blck == b1Add.parent tmpState.data.data.slot == bs1.parent.slot @@ -292,7 +292,7 @@ when const_preset == "minimal": # Too much stack space used on mainnet block: # Create a fork that will not be taken var - blck = makeTestBlock(pool.headState.data.data[], pool.head.blck.root) + blck = makeTestBlock(pool.headState.data.data, pool.head.blck.root) discard pool.add(hash_tree_root(blck.message), blck) for i in 0 ..< (SLOTS_PER_EPOCH * 6): @@ -304,9 +304,9 @@ when const_preset == "minimal": # Too much stack space used on mainnet var cache = get_empty_per_epoch_cache() blck = makeTestBlock( - pool.headState.data.data[], pool.head.blck.root, + pool.headState.data.data, pool.head.blck.root, attestations = makeFullAttestations( - pool.headState.data.data[], pool.head.blck.root, + pool.headState.data.data, pool.head.blck.root, pool.headState.data.data.slot, cache, {})) let added = pool.add(hash_tree_root(blck.message), blck) pool.updateHead(added) diff --git a/tests/testutil.nim b/tests/testutil.nim index ded38888e7..b4e77adb8b 100644 --- a/tests/testutil.nim +++ b/tests/testutil.nim @@ -92,7 +92,7 @@ template timedTest*(name, body) = # TODO noto thread-safe as-is testTimes.add (f, name) -proc makeTestDB*(tailState: BeaconStateRef, tailBlock: SignedBeaconBlock): BeaconChainDB = +proc makeTestDB*(tailState: BeaconState, tailBlock: SignedBeaconBlock): BeaconChainDB = result = init(BeaconChainDB, kvStore MemStoreRef.init()) BlockPool.preInit(result, tailState, tailBlock) @@ -103,6 +103,6 @@ proc makeTestDB*(validators: int): BeaconChainDB = makeInitialDeposits(validators, flags = {skipBlsValidation}), {skipBlsValidation}) genBlock = get_initial_beacon_block(genState[]) - makeTestDB(genState, genBlock) + makeTestDB(genState[], genBlock) export inMicroseconds