diff --git a/libs/service/group.go b/libs/service/group.go index f50dcfcfe..de8f08992 100644 --- a/libs/service/group.go +++ b/libs/service/group.go @@ -46,3 +46,27 @@ func (gs *groupImpl) OnReset() error { } return nil } + +type FunctionalService struct { + Starter func() error + Stopper func() + Reseter func() error +} + +func MakeFunctionalService(logger log.Logger, name string, opts FunctionalService) Service { + srv := &funImpl{ + opts: FunctionalService, + } + + srv.BaseService = NewBaseService(logger, name, srv) + return srv +} + +type funImpl struct { + *BaseService + ops FunctionalService +} + +func (fs *funImpl) OnStart() error { return fs.ops.Starter() } +func (fs *funImpl) OnStop() { fs.ops.Stoper() } +func (fs *funImpl) OnReset() error { return fs.ops.Reseter() } diff --git a/node/node.go b/node/node.go index 9845fd5ec..caa3a47a2 100644 --- a/node/node.go +++ b/node/node.go @@ -191,7 +191,7 @@ func makeNode(config *cfg.Config, } // Determine whether we should attempt state sync. - stateSync := config.StateSync.Enable && !onlyValidatorIsUs(state, pubKey) + stateSync := config.StateSync.Enable && !onlyValidatorIsUs(genDoc, pubKey) if stateSync && state.LastBlockHeight > 0 { logger.Info("Found local state with non-zero height, skipping state sync") stateSync = false diff --git a/node/setup.go b/node/setup.go index bb1c32fc9..5e42de8a0 100644 --- a/node/setup.go +++ b/node/setup.go @@ -182,12 +182,12 @@ func logNodeStartupInfo(state sm.State, pubKey crypto.PubKey, logger, consensusL } } -func onlyValidatorIsUs(state sm.State, pubKey crypto.PubKey) bool { - if state.Validators.Size() > 1 { +func onlyValidatorIsUs(genDoc *types.GenesisDoc, pubKey crypto.PubKey) bool { + if len(genDoc.Validators) > 1 || pubKey == nil { return false } - addr, _ := state.Validators.GetByIndex(0) - return pubKey != nil && bytes.Equal(pubKey.Address(), addr) + + return bytes.Equal(pubKey.Address(), genDoc.Validators[0].Address) } func createMempoolReactor(