Skip to content

Commit

Permalink
graph sync should always start with the node heads
Browse files Browse the repository at this point in the history
  • Loading branch information
cedricfung committed May 3, 2024
1 parent 06f8e04 commit a404979
Showing 1 changed file with 14 additions and 12 deletions.
26 changes: 14 additions & 12 deletions p2p/sync.go
Original file line number Diff line number Diff line change
Expand Up @@ -110,6 +110,20 @@ func (me *Peer) syncToNeighborLoop(p *Peer) {
for !me.closing && !p.closing {
graph, offset := me.getSyncPointOffset(p)
logger.Verbosef("network.sync syncToNeighborLoop getSyncPointOffset %s %d %v\n", p.IdForNetwork, offset, graph != nil)
if graph == nil {
time.Sleep(time.Duration(config.SnapshotRoundGap))
continue
}

points := me.handle.BuildGraph()
nodes := me.handle.ReadAllNodesWithoutState()
local := make(map[crypto.Hash]*SyncPoint)
for _, n := range points {
local[n.NodeId] = n
}
for _, n := range nodes {
me.syncHeadRoundToRemote(local, graph, p, n)
}

for !me.closing && !p.closing && offset > 0 {
off, err := me.syncToNeighborSince(graph, p, offset)
Expand All @@ -119,18 +133,6 @@ func (me *Peer) syncToNeighborLoop(p *Peer) {
}
offset = off
}

if graph != nil {
points := me.handle.BuildGraph()
nodes := me.handle.ReadAllNodesWithoutState()
local := make(map[crypto.Hash]*SyncPoint)
for _, n := range points {
local[n.NodeId] = n
}
for _, n := range nodes {
me.syncHeadRoundToRemote(local, graph, p, n)
}
}
}
}

Expand Down

0 comments on commit a404979

Please sign in to comment.