From 49efd44faa21c00c324825c3a0734020032b6552 Mon Sep 17 00:00:00 2001 From: Erik Grinaker Date: Fri, 28 Aug 2020 12:32:37 +0200 Subject: [PATCH] node: fix genesis state propagation to state sync (#5302) State sync broke in #5231 since the genesis state is not propagated explicitly from `NewNode()` to `Node.OnStart()` and further into the state sync initialization. This is a hack until we can clean up the node startup process. --- CHANGELOG_PENDING.md | 2 ++ node/node.go | 7 ++++--- 2 files changed, 6 insertions(+), 3 deletions(-) diff --git a/CHANGELOG_PENDING.md b/CHANGELOG_PENDING.md index 056c1b064..c46b481c4 100644 --- a/CHANGELOG_PENDING.md +++ b/CHANGELOG_PENDING.md @@ -20,3 +20,5 @@ Friendly reminder, we have a [bug bounty program](https://hackerone.com/tendermi ## BUG FIXES - [blockchain] \#5249 Fix fast sync halt with initial height > 1 (@erikgrinaker) + +- [statesync] \#5302 Fix genesis state propagation to state sync routine (@erikgrinaker) diff --git a/node/node.go b/node/node.go index 8827696a6..3e063fb8e 100644 --- a/node/node.go +++ b/node/node.go @@ -193,6 +193,7 @@ type Node struct { stateSync bool // whether the node should state sync on startup stateSyncReactor *statesync.Reactor // for hosting and restoring state sync snapshots stateSyncProvider statesync.StateProvider // provides state data for bootstrapping a node + stateSyncGenesis sm.State // provides the genesis state for state sync consensusState *cs.State // latest consensus state consensusReactor *cs.Reactor // for participating in the consensus pexReactor *pex.Reactor // for exchanging peer addresses @@ -558,10 +559,9 @@ func createPEXReactorAndAddToSwitch(addrBook pex.AddrBook, config *cfg.Config, // startStateSync starts an asynchronous state sync process, then switches to fast sync mode. func startStateSync(ssR *statesync.Reactor, bcR fastSyncReactor, conR *cs.Reactor, stateProvider statesync.StateProvider, config *cfg.StateSyncConfig, fastSync bool, - stateDB dbm.DB, blockStore *store.BlockStore) error { + stateDB dbm.DB, blockStore *store.BlockStore, state sm.State) error { ssR.Logger.Info("Starting state sync") - state := sm.LoadState(stateDB) if stateProvider == nil { var err error stateProvider, err = statesync.NewLightClientStateProvider( @@ -813,6 +813,7 @@ func NewNode(config *cfg.Config, consensusReactor: consensusReactor, stateSyncReactor: stateSyncReactor, stateSync: stateSync, + stateSyncGenesis: state, // Shouldn't be necessary, but need a way to pass the genesis state pexReactor: pexReactor, evidencePool: evidencePool, proxyApp: proxyApp, @@ -893,7 +894,7 @@ func (n *Node) OnStart() error { return fmt.Errorf("this blockchain reactor does not support switching from state sync") } err := startStateSync(n.stateSyncReactor, bcR, n.consensusReactor, n.stateSyncProvider, - n.config.StateSync, n.config.FastSyncMode, n.stateDB, n.blockStore) + n.config.StateSync, n.config.FastSyncMode, n.stateDB, n.blockStore, n.stateSyncGenesis) if err != nil { return fmt.Errorf("failed to start state sync: %w", err) }