Skip to content

Commit

Permalink
state sync: initialize snapshots in bootstrap set mode (#557)
Browse files Browse the repository at this point in the history
* state sync: initialize snapshots in bootstrap set mode

* move clear summary path

* undo rename
  • Loading branch information
darioush authored and ceyonur committed May 23, 2024
1 parent 065c880 commit afceef5
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 10 deletions.
12 changes: 3 additions & 9 deletions plugin/evm/syncervm_client.go
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,7 @@ type StateSyncClient interface {
ParseStateSummary(ctx context.Context, summaryBytes []byte) (block.StateSummary, error)

// additional methods required by the evm package
StateSyncClearOngoingSummary() error
ClearOngoingSummary() error
Shutdown() error
Error() error
}
Expand Down Expand Up @@ -125,8 +125,8 @@ func (client *stateSyncerClient) GetOngoingSyncStateSummary(context.Context) (bl
return summary, nil
}

// StateSyncClearOngoingSummary clears any marker of an ongoing state sync summary
func (client *stateSyncerClient) StateSyncClearOngoingSummary() error {
// ClearOngoingSummary clears any marker of an ongoing state sync summary
func (client *stateSyncerClient) ClearOngoingSummary() error {
if err := client.metadataDB.Delete(stateSyncSummaryKey); err != nil {
return fmt.Errorf("failed to clear ongoing summary: %w", err)
}
Expand Down Expand Up @@ -167,12 +167,6 @@ func (client *stateSyncerClient) acceptSyncSummary(proposedSummary message.SyncS
"lastAccepted", client.lastAcceptedHeight,
"syncableHeight", proposedSummary.Height(),
)
if err := client.StateSyncClearOngoingSummary(); err != nil {
return block.StateSyncSkipped, fmt.Errorf("failed to clear ongoing summary after skipping state sync: %w", err)
}
// Initialize snapshots if we're skipping state sync, since it will not have been initialized on
// startup.
client.chain.BlockChain().InitializeSnapshots()
return block.StateSyncSkipped, nil
}

Expand Down
9 changes: 8 additions & 1 deletion plugin/evm/vm.go
Original file line number Diff line number Diff line change
Expand Up @@ -610,7 +610,7 @@ func (vm *VM) initializeStateSyncClient(lastAcceptedHeight uint64) error {
// If StateSync is disabled, clear any ongoing summary so that we will not attempt to resume
// sync using a snapshot that has been modified by the node running normal operations.
if !vm.config.StateSyncEnabled {
return vm.StateSyncClient.StateSyncClearOngoingSummary()
return vm.StateSyncClient.ClearOngoingSummary()
}

return nil
Expand Down Expand Up @@ -665,6 +665,13 @@ func (vm *VM) SetState(_ context.Context, state snow.State) error {
if err := vm.StateSyncClient.Error(); err != nil {
return err
}
// After starting bootstrapping, do not attempt to resume a previous state sync.
if err := vm.StateSyncClient.ClearOngoingSummary(); err != nil {
return err
}
// Ensure snapshots are initialized before bootstrapping (i.e., if state sync is skipped).
// Note calling this function has no effect if snapshots are already initialized.
vm.blockChain.InitializeSnapshots()
return nil
case snow.NormalOp:
// Initialize goroutines related to block building once we enter normal operation as there is no need to handle mempool gossip before this point.
Expand Down

0 comments on commit afceef5

Please sign in to comment.