mirror of
https://github.com/tendermint/tendermint.git
synced 2026-08-20 06:06:15 +00:00
node: move handshake out of constructor (#8264)
This commit is contained in:
@@ -124,6 +124,7 @@ type State struct {
|
||||
|
||||
stateStore sm.Store
|
||||
initialStatePopulated bool
|
||||
skipBootstrapping bool
|
||||
|
||||
// create and execute blocks
|
||||
blockExec *sm.BlockExecutor
|
||||
@@ -185,6 +186,12 @@ type State struct {
|
||||
// StateOption sets an optional parameter on the State.
|
||||
type StateOption func(*State)
|
||||
|
||||
// SkipStateStoreBootstrap is a state option forces the constructor to
|
||||
// skip state bootstrapping during construction.
|
||||
func SkipStateStoreBootstrap(sm *State) {
|
||||
sm.skipBootstrapping = true
|
||||
}
|
||||
|
||||
// NewState returns a new State.
|
||||
func NewState(
|
||||
ctx context.Context,
|
||||
@@ -223,16 +230,21 @@ func NewState(
|
||||
cs.doPrevote = cs.defaultDoPrevote
|
||||
cs.setProposal = cs.defaultSetProposal
|
||||
|
||||
if err := cs.updateStateFromStore(ctx); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
// NOTE: we do not call scheduleRound0 yet, we do that upon Start()
|
||||
cs.BaseService = *service.NewBaseService(logger, "State", cs)
|
||||
for _, option := range options {
|
||||
option(cs)
|
||||
}
|
||||
|
||||
// this is not ideal, but it lets the consensus tests start
|
||||
// node-fragments gracefully while letting the nodes
|
||||
// themselves avoid this.
|
||||
if !cs.skipBootstrapping {
|
||||
if err := cs.updateStateFromStore(ctx); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
}
|
||||
|
||||
return cs, nil
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user