Skip to content

Commit

Permalink
fetch: requests got lost when there are no peers (spacemeshos#4849)
Browse files Browse the repository at this point in the history
requests are not restored back to the queue when there were no peers to dispatch to.

- restore requests when there are no peers
- push mesh to still make progress even when there are missing blocks
- increase frequency of state sync

i manually test against mainnet, artificially causing GetPeers() to return zero peers.
mesh was making very slow progress because it aborts as soon as it finds a missing block, not executing the next block even when it's available.
  • Loading branch information
countvonzero authored and brunovale91 committed Aug 21, 2023
1 parent 52cffb8 commit 8922013
Showing 1 changed file with 6 additions and 4 deletions.
10 changes: 6 additions & 4 deletions mesh/mesh.go
Original file line number Diff line number Diff line change
Expand Up @@ -319,12 +319,15 @@ func (msh *Mesh) ProcessLayer(ctx context.Context, lid types.LayerID) error {
})),
)
}
if missing := missingBlocks(results); len(missing) > 0 {
applicable, missing := filterMissing(results, next)
if len(missing) > 0 {
select {
case <-ctx.Done():
case msh.missingBlocks <- missing:
}
return fmt.Errorf("request missing blocks %v", missing)
if len(applicable) == 0 {
return fmt.Errorf("request missing blocks %v", missing)
}
}

if err := msh.ensureStateConsistent(ctx, applicable); err != nil {
Expand All @@ -334,8 +337,7 @@ func (msh *Mesh) ProcessLayer(ctx context.Context, lid types.LayerID) error {
return err
}
if len(missing) > 0 {
msh.pendingUpdates.min = applicable[len(applicable)-1].Layer
msh.pendingUpdates.max = types.MaxLayer(msh.pendingUpdates.min, msh.pendingUpdates.max)
msh.pendingUpdates.min = msh.LatestLayerInState()
} else {
msh.pendingUpdates.min = 0
msh.pendingUpdates.max = 0
Expand Down

0 comments on commit 8922013

Please sign in to comment.