MCPcopy Create free account
hub / github.com/DeAI-Artist/Linkis / startStateSync

Function startStateSync

node/node.go:649–703  ·  view source on GitHub ↗

startStateSync starts an asynchronous state sync process, then switches to fast sync mode.

(ssR *statesync.Reactor, bcR fastSyncReactor, conR *cs.Reactor,
	stateProvider statesync.StateProvider, config *cfg.StateSyncConfig, fastSync bool,
	stateStore sm.Store, blockStore *store.BlockStore, state sm.State,
)

Source from the content-addressed store, hash-verified

647
648// startStateSync starts an asynchronous state sync process, then switches to fast sync mode.
649func startStateSync(ssR *statesync.Reactor, bcR fastSyncReactor, conR *cs.Reactor,
650 stateProvider statesync.StateProvider, config *cfg.StateSyncConfig, fastSync bool,
651 stateStore sm.Store, blockStore *store.BlockStore, state sm.State,
652) error {
653 ssR.Logger.Info("Starting state sync")
654
655 if stateProvider == nil {
656 var err error
657 ctx, cancel := context.WithTimeout(context.Background(), 10*time.Second)
658 defer cancel()
659 stateProvider, err = statesync.NewLightClientStateProvider(
660 ctx,
661 state.ChainID, state.Version, state.InitialHeight,
662 config.RPCServers, light.TrustOptions{
663 Period: config.TrustPeriod,
664 Height: config.TrustHeight,
665 Hash: config.TrustHashBytes(),
666 }, ssR.Logger.With("module", "light"))
667 if err != nil {
668 return fmt.Errorf("failed to set up light client state provider: %w", err)
669 }
670 }
671
672 go func() {
673 state, commit, err := ssR.Sync(stateProvider, config.DiscoveryTime)
674 if err != nil {
675 ssR.Logger.Error("State sync failed", "err", err)
676 return
677 }
678 err = stateStore.Bootstrap(state)
679 if err != nil {
680 ssR.Logger.Error("Failed to bootstrap node with new state", "err", err)
681 return
682 }
683 err = blockStore.SaveSeenCommit(state.LastBlockHeight, commit)
684 if err != nil {
685 ssR.Logger.Error("Failed to store last seen commit", "err", err)
686 return
687 }
688
689 if fastSync {
690 // FIXME Very ugly to have these metrics bleed through here.
691 conR.Metrics.StateSyncing.Set(0)
692 conR.Metrics.FastSyncing.Set(1)
693 err = bcR.SwitchToFastSync(state)
694 if err != nil {
695 ssR.Logger.Error("Failed to switch to fast sync", "err", err)
696 return
697 }
698 } else {
699 conR.SwitchToConsensus(state, true)
700 }
701 }()
702 return nil
703}
704
705// NewNode returns a new, ready to go, Tendermint Node.
706func NewNode(config *cfg.Config,

Callers 1

OnStartMethod · 0.70

Calls 11

TrustHashBytesMethod · 0.80
SaveSeenCommitMethod · 0.80
InfoMethod · 0.65
WithMethod · 0.65
ErrorMethod · 0.65
BootstrapMethod · 0.65
SetMethod · 0.65
SwitchToFastSyncMethod · 0.65
SwitchToConsensusMethod · 0.65
SyncMethod · 0.45

Tested by

no test coverage detected