From eb777a6c8bc7b7329f1fcad91b700aec2b546744 Mon Sep 17 00:00:00 2001 From: Etan Kissling Date: Mon, 29 Nov 2021 11:25:47 +0100 Subject: [PATCH] allow `withState` to be called multiple times This allows `blockchain_dag`'s `withState` template to be called more than once in a single function. This led to a compilation error before because the injected variables and functions shared the same scope. --- beacon_chain/consensus_object_pools/blockchain_dag.nim | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/beacon_chain/consensus_object_pools/blockchain_dag.nim b/beacon_chain/consensus_object_pools/blockchain_dag.nim index 47aeb8e46..9a6a5ed9f 100644 --- a/beacon_chain/consensus_object_pools/blockchain_dag.nim +++ b/beacon_chain/consensus_object_pools/blockchain_dag.nim @@ -74,11 +74,12 @@ template withState*( ## TODO async transformations will lead to a race where stateData gets updated ## while waiting for future to complete - catch this here somehow? - var cache {.inject.} = StateCache() - updateStateData(dag, stateData, blockSlot, false, cache) + block: + var cache {.inject.} = StateCache() + updateStateData(dag, stateData, blockSlot, false, cache) - withStateVars(stateData): - body + withStateVars(stateData): + body func parent*(bs: BlockSlot): BlockSlot = ## Return a blockslot representing the previous slot, using the parent block