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.
This commit is contained in:
Erik Grinaker
2020-08-28 12:32:37 +02:00
committed by GitHub
parent f2f60181a9
commit 49efd44faa
2 changed files with 6 additions and 3 deletions

View File

@@ -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)

View File

@@ -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)
}