mirror of
https://github.com/fluencelabs/tendermint
synced 2025-04-26 07:12:16 +00:00
return error if peer sent us a block we didn't expect with a height too far ahead/behind
This commit is contained in:
parent
0c7e871ef0
commit
baf457e6d4
@ -40,6 +40,9 @@ const (
|
|||||||
// Assuming a DSL connection (not a good choice) 128 Kbps (upload) ~ 15 KB/s,
|
// Assuming a DSL connection (not a good choice) 128 Kbps (upload) ~ 15 KB/s,
|
||||||
// sending data across atlantic ~ 7.5 KB/s.
|
// sending data across atlantic ~ 7.5 KB/s.
|
||||||
minRecvRate = 7680
|
minRecvRate = 7680
|
||||||
|
|
||||||
|
// Maximum difference between current and new block's height.
|
||||||
|
maxDiffBetweenCurrentAndReceivedBlockHeight = 100
|
||||||
)
|
)
|
||||||
|
|
||||||
var peerTimeout = 15 * time.Second // not const so we can override with tests
|
var peerTimeout = 15 * time.Second // not const so we can override with tests
|
||||||
@ -230,8 +233,14 @@ func (pool *BlockPool) AddBlock(peerID p2p.ID, block *types.Block, blockSize int
|
|||||||
|
|
||||||
requester := pool.requesters[block.Height]
|
requester := pool.requesters[block.Height]
|
||||||
if requester == nil {
|
if requester == nil {
|
||||||
// a block we didn't expect.
|
pool.Logger.Info("peer sent us a block we didn't expect", "peer", peerID, "curHeight", pool.height, "blockHeight", block.Height)
|
||||||
// TODO:if height is too far ahead, punish peer
|
diff := pool.height - block.Height
|
||||||
|
if diff < 0 {
|
||||||
|
diff *= -1
|
||||||
|
}
|
||||||
|
if diff > maxDiffBetweenCurrentAndReceivedBlockHeight {
|
||||||
|
pool.sendError(errors.New("peer sent us a block we didn't expect with a height too far ahead/behind"), peerID)
|
||||||
|
}
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user