MCPcopy Create free account
hub / github.com/CPChain/chain / synchronize

Method synchronize

protocols/cpc/sync.go:188–219  ·  view source on GitHub ↗

Synchronise tries to sync up our local block chain with a remote peer. It fetches blocks a peer.

(peer *peer)

Source from the content-addressed store, hash-verified

186
187// Synchronise tries to sync up our local block chain with a remote peer. It fetches blocks a peer.
188func (pm *ProtocolManager) synchronize(peer *peer) {
189 if peer == nil {
190 return
191 }
192
193 // make sure the peer has more blocks
194 currentBlock := pm.blockchain.CurrentBlock()
195 height := currentBlock.Number()
196 pHead, pHt := peer.Head()
197 if pHt.Cmp(height) <= 0 {
198 return
199 }
200
201 // full sync with the downloader
202 if err := pm.syncer.Synchronise(peer, pHead, pHt, pm.syncMode); err != nil {
203 return
204 }
205
206 // because we have done the synchronization
207 atomic.StoreUint32(&pm.acceptTxs, 1) // Mark initial sync done
208
209 if head := pm.blockchain.CurrentBlock(); head.NumberU64() > 0 {
210 // We've completed a sync cycle, notify all peers of new state. This path is
211 // essential in star-topology networks where a gateway node needs to notify
212 // all its out-of-date peers of the availability of a new block. This failure
213 // scenario will most often crop up in private and hackathon networks with
214 // degenerate connectivity, but it should be healthy for the mainnet too to
215 // more reliably update peers or the local TD state.
216 go pm.BroadcastBlock(head, false)
217 go pm.BroadcastBlock(head, true)
218 }
219}

Callers 3

syncerLoopMethod · 0.95
SyncFromPeerMethod · 0.95
SyncFromBestPeerMethod · 0.95

Calls 7

BroadcastBlockMethod · 0.95
CmpMethod · 0.80
NumberU64Method · 0.80
CurrentBlockMethod · 0.65
HeadMethod · 0.65
SynchroniseMethod · 0.65
NumberMethod · 0.45

Tested by

no test coverage detected