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:
Dave Collins 2013-10-03 11:21:41 -05:00
parent bd3a39ad4a
commit 0c6b79afb0

View file

@ -216,13 +216,20 @@ 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)
// 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
// Process the block to include validation, best chain selection, orphan