mirror of
https://github.com/kaspanet/kaspad.git
synced 2025-03-30 15:08:33 +00:00
[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:
parent
f0c80905eb
commit
1b00e01030
@ -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.
|
||||
|
@ -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",
|
||||
|
Loading…
x
Reference in New Issue
Block a user