@@ -112,6 +112,53 @@ func (ss *stateSyncer) Context() *snow.ConsensusContext {
112
112
return ss .Ctx
113
113
}
114
114
115
+ func (ss * stateSyncer ) Start (ctx context.Context , startReqID uint32 ) error {
116
+ ss .Ctx .Log .Info ("starting state sync" )
117
+
118
+ ss .Ctx .State .Set (snow.EngineState {
119
+ Type : p2p .EngineType_ENGINE_TYPE_SNOWMAN ,
120
+ State : snow .StateSyncing ,
121
+ })
122
+ if err := ss .VM .SetState (ctx , snow .StateSyncing ); err != nil {
123
+ return fmt .Errorf ("failed to notify VM that state syncing has started: %w" , err )
124
+ }
125
+
126
+ ss .requestID = startReqID
127
+
128
+ return ss .tryStartSyncing (ctx )
129
+ }
130
+
131
+ func (ss * stateSyncer ) Connected (ctx context.Context , nodeID ids.NodeID , nodeVersion * version.Application ) error {
132
+ if err := ss .VM .Connected (ctx , nodeID , nodeVersion ); err != nil {
133
+ return err
134
+ }
135
+
136
+ if err := ss .StartupTracker .Connected (ctx , nodeID , nodeVersion ); err != nil {
137
+ return err
138
+ }
139
+
140
+ return ss .tryStartSyncing (ctx )
141
+ }
142
+
143
+ func (ss * stateSyncer ) Disconnected (ctx context.Context , nodeID ids.NodeID ) error {
144
+ if err := ss .VM .Disconnected (ctx , nodeID ); err != nil {
145
+ return err
146
+ }
147
+
148
+ return ss .StartupTracker .Disconnected (ctx , nodeID )
149
+ }
150
+
151
+ // tryStartSyncing will start syncing the first time it is called while the
152
+ // startupTracker is reporting that the protocol should start.
153
+ func (ss * stateSyncer ) tryStartSyncing (ctx context.Context ) error {
154
+ if ss .started || ! ss .StartupTracker .ShouldStart () {
155
+ return nil
156
+ }
157
+
158
+ ss .started = true
159
+ return ss .startup (ctx )
160
+ }
161
+
115
162
func (ss * stateSyncer ) StateSummaryFrontier (ctx context.Context , nodeID ids.NodeID , requestID uint32 , summaryBytes []byte ) error {
116
163
// ignores any late responses
117
164
if requestID != ss .requestID {
@@ -426,27 +473,6 @@ func (ss *stateSyncer) GetAcceptedStateSummaryFailed(ctx context.Context, nodeID
426
473
return ss .AcceptedStateSummary (ctx , nodeID , requestID , nil )
427
474
}
428
475
429
- func (ss * stateSyncer ) Start (ctx context.Context , startReqID uint32 ) error {
430
- ss .Ctx .Log .Info ("starting state sync" )
431
-
432
- ss .Ctx .State .Set (snow.EngineState {
433
- Type : p2p .EngineType_ENGINE_TYPE_SNOWMAN ,
434
- State : snow .StateSyncing ,
435
- })
436
- if err := ss .VM .SetState (ctx , snow .StateSyncing ); err != nil {
437
- return fmt .Errorf ("failed to notify VM that state syncing has started: %w" , err )
438
- }
439
-
440
- ss .requestID = startReqID
441
-
442
- if ! ss .StartupTracker .ShouldStart () {
443
- return nil
444
- }
445
-
446
- ss .started = true
447
- return ss .startup (ctx )
448
- }
449
-
450
476
// startup do start the whole state sync process by
451
477
// sampling frontier seeders, listing state syncers to request votes to
452
478
// and reaching out frontier seeders if any. Otherwise, it moves immediately
@@ -580,31 +606,6 @@ func (ss *stateSyncer) Notify(ctx context.Context, msg common.Message) error {
580
606
return ss .onDoneStateSyncing (ctx , ss .requestID )
581
607
}
582
608
583
- func (ss * stateSyncer ) Connected (ctx context.Context , nodeID ids.NodeID , nodeVersion * version.Application ) error {
584
- if err := ss .VM .Connected (ctx , nodeID , nodeVersion ); err != nil {
585
- return err
586
- }
587
-
588
- if err := ss .StartupTracker .Connected (ctx , nodeID , nodeVersion ); err != nil {
589
- return err
590
- }
591
-
592
- if ss .started || ! ss .StartupTracker .ShouldStart () {
593
- return nil
594
- }
595
-
596
- ss .started = true
597
- return ss .startup (ctx )
598
- }
599
-
600
- func (ss * stateSyncer ) Disconnected (ctx context.Context , nodeID ids.NodeID ) error {
601
- if err := ss .VM .Disconnected (ctx , nodeID ); err != nil {
602
- return err
603
- }
604
-
605
- return ss .StartupTracker .Disconnected (ctx , nodeID )
606
- }
607
-
608
609
func (* stateSyncer ) Gossip (context.Context ) error {
609
610
return nil
610
611
}
0 commit comments