ChainSafe / ChainSafe/gossamer

feat(dot/sync): Implement Gap Sync Strategy - WIP more discussion needed

Open
#4,218 1 comment 0 reactions 1 assignee Claimed by @dimartiro View on GitHub
Dominant language
Go
Stars
454
Forks
144
PR merge metrics
No merged PRs in 30d

Description

### Description

When starting the sync service engine we should check if there is a ongoing gap sync work to resume (see https://github.com/ChainSafe/gossamer/issues/4217):

```go
func (s *SyncService) runSyncEngine() {
...
latestGap, err := s.gapSyncState.Retrieve()
if err != nil {}
if latestGap != nil {
s.spawnGapSyncFrom(latestGap)
}
...
}
```

- If there is no gap sync work to resume, then we have all the gaps filled or Warp Sync still working and we didn't started the gap sync process.

### Starting after Warp Sync process

Here is where we will startup gap sync for the first time, the flow is:

```
1. We start the node for the first time
2. Warp sync is the current strategy and is running...
3. Warp sync reached the tip of the chain, but left a gap behind
4. Warp sync is finished, it will stop and switch to the default strategy which is FullSync
5. FullSync started and is running from the block where warp sync stopped and keep progressing...
6. We should start gap sync and place the target as the block warp sync stopped and full sync started...
```

The step 6 is the crucial point, when moving from `warp sync -> full sync` we should start the gap sync background process and place it the target it should achieve starting from genesis (or the `latestGap` see `First way`), once Gap Sync reaches the target it can just stop.

This can be placed in `func (s *SyncService) runStrategy()`, like:

```go
if done {
// get the block where warp sync stopped
latestKownBlock, err := s. blockState.BestBlockHeader()
info := GapSyncInfo{
latestBlockImported: s. blockState.GenesisHash()
target: latestKownBlock.Hash()
}
s.spawnGapSync(info)
s.currentStrategy = s.defaultStrategy
}
```

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.