[NOD-301] Don't sync with peer if the rendezvous point is below finality (#387)

* [NOD-301] Don't sync with peer if the rendezvous point is below finality

* [NOD-301] Add block hash and peer address for the warn message

* [NOD-301] Fix perrLog.Warnf arguments order
This commit is contained in:
Ori Newman 2019-08-29 10:47:05 +03:00 committed by Svarog
parent f0c80905eb
commit 1b00e01030
2 changed files with 15 additions and 0 deletions

View File

@ -780,6 +780,15 @@ func (dag *BlockDAG) finalizeNodesBelowFinalityPoint(deleteDiffData bool) {
}
}
// IsKnownFinalizedBlock returns whether the block is below the finality point.
// IsKnownFinalizedBlock might be false-negative because node finality status is
// updated in a separate goroutine. To get a definite answer if a block
// is finalized or not, use dag.checkFinalityRules.
func (dag *BlockDAG) IsKnownFinalizedBlock(blockHash *daghash.Hash) bool {
node := dag.index.LookupNode(blockHash)
return node != nil && node.isFinalized
}
// NextBlockCoinbaseTransaction prepares the coinbase transaction for the next mined block
//
// This function CAN'T be called with the DAG lock held.

View File

@ -718,6 +718,12 @@ func (sp *Peer) OnBlockLocator(_ *peer.Peer, msg *wire.MsgBlockLocator) {
// the highest shared block.
firstHash := msg.BlockLocatorHashes[0]
if dag.BlockExists(firstHash) {
if dag.IsKnownFinalizedBlock(firstHash) {
peerLog.Warnf("Cannot sync with peer %s because the highest"+
" shared chain block (%s) is below the finality point", sp, firstHash)
sp.Disconnect()
return
}
err := sp.server.SyncManager.PushGetBlockInvsOrHeaders(sp.Peer, firstHash)
if err != nil {
peerLog.Errorf("Failed pushing get blocks message for peer %s: %s",