@@ -138,6 +138,8 @@ func (h *runtimeHistory) StorageSyncCheckpoint(round uint64) error {
138138 h .syncRoundLock .Lock ()
139139 defer h .syncRoundLock .Unlock ()
140140 switch {
141+ case h .lastStorageSyncedRound == roothash .RoundInvalid :
142+ // First sync, continue below.
141143 case round < h .lastStorageSyncedRound :
142144 return fmt .Errorf ("runtime/history: storage sync checkpoint at lower round (current: %d wanted: %d)" , h .lastStorageSyncedRound , round )
143145 case round == h .lastStorageSyncedRound :
@@ -163,10 +165,13 @@ func (h *runtimeHistory) StorageSyncCheckpoint(round uint64) error {
163165 return nil
164166}
165167
166- func (h * runtimeHistory ) LastStorageSyncedRound () (uint64 , error ) {
168+ func (h * runtimeHistory ) LastStorageSyncedRound () (uint64 , bool ) {
167169 h .syncRoundLock .RLock ()
168170 defer h .syncRoundLock .RUnlock ()
169- return h .lastStorageSyncedRound , nil
171+ if h .lastStorageSyncedRound == roothash .RoundInvalid {
172+ return 0 , false
173+ }
174+ return h .lastStorageSyncedRound , true
170175}
171176
172177func (h * runtimeHistory ) WatchBlocks () (<- chan * roothash.AnnotatedBlock , pubsub.ClosableSubscription , error ) {
@@ -227,16 +232,26 @@ func (h *runtimeHistory) resolveRound(round uint64, includeStorage bool) (uint64
227232 h .syncRoundLock .RLock ()
228233 defer h .syncRoundLock .RUnlock ()
229234 // Also take storage sync state into account.
230- if includeStorage && h .hasLocalStorage && h .lastStorageSyncedRound < meta .LastRound {
231- return h .lastStorageSyncedRound , nil
235+ if includeStorage && h .hasLocalStorage {
236+ if h .lastStorageSyncedRound == roothash .RoundInvalid {
237+ return 0 , roothash .ErrNotFound
238+ }
239+ if h .lastStorageSyncedRound < meta .LastRound {
240+ return h .lastStorageSyncedRound , nil
241+ }
232242 }
233243 return meta .LastRound , nil
234244 default :
235245 h .syncRoundLock .RLock ()
236246 defer h .syncRoundLock .RUnlock ()
237247 // Ensure round exists.
238- if includeStorage && h .hasLocalStorage && h .lastStorageSyncedRound < round {
239- return 0 , roothash .ErrNotFound
248+ if includeStorage && h .hasLocalStorage {
249+ if h .lastStorageSyncedRound == roothash .RoundInvalid {
250+ return 0 , roothash .ErrNotFound
251+ }
252+ if h .lastStorageSyncedRound < round {
253+ return 0 , roothash .ErrNotFound
254+ }
240255 }
241256 return round , nil
242257 }
@@ -368,6 +383,7 @@ func New(runtimeID common.Namespace, dataDir string, prunerFactory PrunerFactory
368383 ctx : ctx ,
369384 cancelCtx : cancelCtx ,
370385 db : db ,
386+ lastStorageSyncedRound : roothash .RoundInvalid ,
371387 hasLocalStorage : hasLocalStorage ,
372388 syncedBlocksNotifier : pubsub .NewBroker (true ),
373389 committedBlocksNotifier : pubsub .NewBroker (true ),
0 commit comments