@@ -818,14 +818,14 @@ func (w *Worker) Serve(ctx context.Context) error { // nolint: gocyclo
818818 }
819819
820820 w .syncedLock .RLock ()
821- cachedLastRound := w .syncedState .Round
821+ lastFinalizedRound := w .syncedState .Round
822822 w .syncedLock .RUnlock ()
823- if cachedLastRound == defaultUndefinedRound || cachedLastRound < genesisBlock .Header .Round {
824- cachedLastRound = w .undefinedRound
823+ if lastFinalizedRound == defaultUndefinedRound || lastFinalizedRound < genesisBlock .Header .Round {
824+ lastFinalizedRound = w .undefinedRound
825825 }
826826
827827 // Initialize genesis from the runtime descriptor.
828- isInitialStartup := (cachedLastRound == w .undefinedRound )
828+ isInitialStartup := (lastFinalizedRound == w .undefinedRound )
829829 if isInitialStartup {
830830 w .statusLock .Lock ()
831831 w .status = api .StatusInitializingGenesis
@@ -850,7 +850,7 @@ func (w *Worker) Serve(ctx context.Context) error { // nolint: gocyclo
850850 w .statusLock .Unlock ()
851851
852852 // Determine what is the first round that we would need to sync.
853- iterativeSyncStart := cachedLastRound
853+ iterativeSyncStart := lastFinalizedRound
854854 if iterativeSyncStart == w .undefinedRound {
855855 iterativeSyncStart ++
856856 }
@@ -913,7 +913,7 @@ func (w *Worker) Serve(ctx context.Context) error { // nolint: gocyclo
913913 return fmt .Errorf ("failed to finalize filled in version %v: %w" , v , err )
914914 }
915915 }
916- cachedLastRound , err = w .flushSyncedState (summaryFromBlock (earlyBlk ))
916+ lastFinalizedRound , err = w .flushSyncedState (summaryFromBlock (earlyBlk ))
917917 if err != nil {
918918 return fmt .Errorf ("failed to flush synced state: %w" , err )
919919 }
@@ -939,7 +939,7 @@ func (w *Worker) Serve(ctx context.Context) error { // nolint: gocyclo
939939
940940 w .logger .Info ("worker initialized" ,
941941 "genesis_round" , genesisBlock .Header .Round ,
942- "last_synced " , cachedLastRound ,
942+ "last_finalized_round " , lastFinalizedRound ,
943943 )
944944
945945 // Try to perform initial sync from state and io checkpoints if either:
@@ -1000,7 +1000,7 @@ func (w *Worker) Serve(ctx context.Context) error { // nolint: gocyclo
10001000 if err != nil {
10011001 w .logger .Info ("checkpoint sync failed" , "err" , err )
10021002 } else {
1003- cachedLastRound , err = w .flushSyncedState (summary )
1003+ lastFinalizedRound , err = w .flushSyncedState (summary )
10041004 if err != nil {
10051005 return fmt .Errorf ("failed to flush synced state %w" , err )
10061006 }
@@ -1023,7 +1023,7 @@ func (w *Worker) Serve(ctx context.Context) error { // nolint: gocyclo
10231023 var wg sync.WaitGroup
10241024
10251025 latestBlockRound := w .undefinedRound // Don't register availability immediately, we want to know first how far behind consensus we are.
1026- lastFullyAppliedRound := cachedLastRound
1026+ lastFullyAppliedRound := lastFinalizedRound
10271027 syncingRounds := make (map [uint64 ]* inFlight )
10281028 summaryCache := make (map [uint64 ]* blockSummary )
10291029
@@ -1160,7 +1160,7 @@ mainLoop:
11601160 delete (summaryCache , lastDiff .round - 1 )
11611161 lastFullyAppliedRound = lastDiff .round
11621162
1163- storageWorkerLastSyncedRound .With (w .getMetricLabels ()).Set (float64 (lastDiff .round ))
1163+ storageWorkerLastFullyAppliedRound .With (w .getMetricLabels ()).Set (float64 (lastDiff .round ))
11641164 storageWorkerRoundSyncLatency .With (w .getMetricLabels ()).Observe (time .Since (syncing .startedAt ).Seconds ())
11651165
11661166 // Finalize storage for this round. This happens asynchronously
@@ -1173,7 +1173,7 @@ mainLoop:
11731173 // Check if any new rounds were fully applied and need to be finalized.
11741174 // Only finalize if it's the round after the one that was finalized last.
11751175 // As a consequence at most one finalization can be happening at the time.
1176- if len (* pendingFinalize ) > 0 && cachedLastRound + 1 == (* pendingFinalize )[0 ].GetRound () {
1176+ if len (* pendingFinalize ) > 0 && lastFinalizedRound + 1 == (* pendingFinalize )[0 ].GetRound () {
11771177 lastSummary := heap .Pop (pendingFinalize ).(* blockSummary )
11781178 wg .Add (1 )
11791179 go func () { // Don't block fetching and applying remaining rounds.
@@ -1188,13 +1188,13 @@ mainLoop:
11881188 blk := inBlk .(* block.Block )
11891189 w .logger .Debug ("incoming block" ,
11901190 "round" , blk .Header .Round ,
1191- "last_synced " , lastFullyAppliedRound ,
1192- "last_finalized" , cachedLastRound ,
1191+ "last_fully_applied " , lastFullyAppliedRound ,
1192+ "last_finalized" , lastFinalizedRound ,
11931193 )
11941194
11951195 // Check if we're far enough to reasonably register as available.
11961196 latestBlockRound = blk .Header .Round
1197- w .nudgeAvailability (cachedLastRound , latestBlockRound )
1197+ w .nudgeAvailability (lastFinalizedRound , latestBlockRound )
11981198
11991199 if _ , ok := summaryCache [lastFullyAppliedRound ]; ! ok && lastFullyAppliedRound == w .undefinedRound {
12001200 dummy := blockSummary {
@@ -1270,25 +1270,25 @@ mainLoop:
12701270 case finalized := <- w .finalizeCh :
12711271 // If finalization failed, things start falling apart.
12721272 // There's no point redoing it, since it's probably not a transient
1273- // error, and cachedLastRound also can't be updated legitimately.
1273+ // error, and lastFinalizedRound also can't be updated legitimately.
12741274 if finalized .err != nil {
12751275 w .logger .Error ("failed to finalize" , "err" , err , "summary" , finalized .summary )
12761276 err = fmt .Errorf ("failed to finalize (round: %d): %w" , finalized .summary .Round , finalized .err )
12771277 break mainLoop
12781278 }
12791279
12801280 // No further sync or out of order handling needed here, since
1281- // only one finalize at a time is triggered (for round cachedLastRound +1)
1282- cachedLastRound , err = w .flushSyncedState (finalized .summary )
1281+ // only one finalize at a time is triggered (for round lastFinalizedLastRound +1)
1282+ lastFinalizedRound , err = w .flushSyncedState (finalized .summary )
12831283 if err != nil {
12841284 w .logger .Error ("failed to flush synced state" ,
12851285 "err" , err ,
12861286 )
12871287 }
1288- storageWorkerLastFullRound .With (w .getMetricLabels ()).Set (float64 (finalized .summary .Round ))
1288+ storageWorkerLastFinalizedRound .With (w .getMetricLabels ()).Set (float64 (finalized .summary .Round ))
12891289
12901290 // Check if we're far enough to reasonably register as available.
1291- w .nudgeAvailability (cachedLastRound , latestBlockRound )
1291+ w .nudgeAvailability (lastFinalizedRound , latestBlockRound )
12921292
12931293 // Notify the checkpointer that there is a new finalized round.
12941294 if config .GlobalConfig .Storage .Checkpointer .Enabled {
0 commit comments