ChainSafe / ChainSafe/gossamer
fix(dot/sync): Use correct block origin data
- Dominant language
- Go
- Stars
- 454
- Forks
- 144
- PR merge metrics
- No merged PRs in 30d
Description
## Issue summary
- Gossamer has 2 block origin values:
- `networkInitialSync`: blocks acquired through initial sync where the node is request blocks from other peers in order to reach the most up to date state (tip of the chain)
- `networkBroadcast`: blocks acquired through block announces
- The current problem is that Gossamer is using `networkInitialSync` for every acquired block, this is a problem because initial sync acquired blocks skip BABE verifications, but blocks acquired through block announcements should pass through the BABE verification since we should ensure the producer rights to build that block!
### Suggestion
- One approach to fix this problem is to add the block origin data to the `SyncTask` and `SyncTaskResult`. So when processing the acquired block it already have appended as a metadata its origin.
```go
type SyncTask struct {
requestMaker network.RequestMaker
request messages.P2PMessage
response messages.P2PMessage
origin blockOrigin
}
type SyncTaskResult struct {
who peer.ID
completed bool
request messages.P2PMessage
response messages.P2PMessage
origin blockOrigin
}
```
and then the strategy that is going to `Process` the results, will have the block origin of that fragment of blocks:
```go
type nextBlocksToImport struct {
blocks []*types.BlockData
origin blockOrigin
}
func (f *FullSyncStrategy) Process(results []*SyncTaskResult) ... {
blocksToImport := nextBlocksToImport{}
...
for _, block := range blocksToImport.blocks {
imported, err := f.blockImporter.importBlock(block, blocksToImport.origin)
if err != nil {
return false, nil, nil, fmt.Errorf("while handling ready block: %w", err)
}
...
}
...
}
```
## Other information and links
-
Contributor guide
Assessment
This issue has not been assessed yet.