Don't disconnect on unrequested blocks for regtest.
The "official" regression test tool intentionally sends some unrequested duplicate blocks to ensure the chain handling code does not fail when trying to insert them. This commit adds an exception to the block manager which typically disconnects peers that send unrequested blocks (they are misbehaving if they do this) for regression test mode.
This commit is contained in:
parent
bd3a39ad4a
commit
0c6b79afb0
1 changed files with 12 additions and 5 deletions
|
@ -216,12 +216,19 @@ func (b *blockManager) handleBlockMsg(bmsg *blockMsg) {
|
|||
// handler can request the parent blocks from the appropriate peer.
|
||||
blockSha, _ := bmsg.block.Sha()
|
||||
|
||||
// If we didnt' ask for this block then the peer is misbehaving.
|
||||
// If we didn't ask for this block then the peer is misbehaving.
|
||||
if _, ok := bmsg.peer.requestedBlocks[*blockSha]; !ok {
|
||||
log.Warnf("[BMGR] Got unreqeusted block from %s, disconnecting",
|
||||
bmsg.peer.addr)
|
||||
bmsg.peer.Disconnect()
|
||||
return
|
||||
// The regression test intentionally sends some blocks twice
|
||||
// to test duplicate block insertion fails. Don't disconnect
|
||||
// the peer or ignore the block when we're in regression test
|
||||
// mode in this case so the chain code is actually fed the
|
||||
// duplicate blocks.
|
||||
if !cfg.RegressionTest {
|
||||
log.Warnf("[BMGR] Got unrequested block %v from %s -- "+
|
||||
"disconnecting", blockSha, bmsg.peer.addr)
|
||||
bmsg.peer.Disconnect()
|
||||
return
|
||||
}
|
||||
}
|
||||
b.blockPeer[*blockSha] = bmsg.peer
|
||||
|
||||
|
|
Loading…
Reference in a new issue