From 0f704f67b88c058b3b13fc3f862b69cbe97e0848 Mon Sep 17 00:00:00 2001 From: Jacek Sieka Date: Fri, 18 Mar 2022 08:02:07 +0100 Subject: [PATCH] tns: checkpoint wal periodically while backfilling Witout this, we end up with a massive .wal file that needs to be checkpointed on first startup (which takes a few minutes) - it's much more efficient to do smaller checkpoints, it turns out. --- beacon_chain/consensus_object_pools/blockchain_dag.nim | 1 + beacon_chain/trusted_node_sync.nim | 5 +++++ 2 files changed, 6 insertions(+) diff --git a/beacon_chain/consensus_object_pools/blockchain_dag.nim b/beacon_chain/consensus_object_pools/blockchain_dag.nim index 8b282bc77a..6dbafc6d67 100644 --- a/beacon_chain/consensus_object_pools/blockchain_dag.nim +++ b/beacon_chain/consensus_object_pools/blockchain_dag.nim @@ -1836,6 +1836,7 @@ proc rebuildIndex*(dag: ChainDAGRef) = withState(state[]): dag.db.putState(state) + dag.db.checkpoint() state_root = state.root diff --git a/beacon_chain/trusted_node_sync.nim b/beacon_chain/trusted_node_sync.nim index 4949d82d5e..659da79b70 100644 --- a/beacon_chain/trusted_node_sync.nim +++ b/beacon_chain/trusted_node_sync.nim @@ -73,6 +73,8 @@ proc doTrustedNodeSync*( let db = BeaconChainDB.new(databaseDir, inMemory = false) + defer: + db.close() var dbCache = DbCache(summaries: db.loadSummaries()) @@ -391,6 +393,9 @@ proc doTrustedNodeSync*( continue gets[int(i mod gets.lenu64)] = downloadBlock(slot) + + if i mod 1024 == 0: + db.checkpoint() # Transfer stuff from wal periodically true else: notice "Database initialized, historical blocks will be backfilled when starting the node",