Skip to content

Commit

Permalink
add ban score when receiving an invalid block form sync peer
Browse files Browse the repository at this point in the history
  • Loading branch information
whitefen committed Nov 30, 2018
1 parent 5fb5eaf commit 1ff5fe2
Show file tree
Hide file tree
Showing 4 changed files with 14 additions and 7 deletions.
2 changes: 1 addition & 1 deletion conf/bitcoincash.yml
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ P2PNet:
MaxPeers:
TargetOutbound:
ConnectPeersOnStart:
DisableBanning: true
DisableBanning: false
SimNet: false
DisableListen: false
BlocksOnly: false
Expand Down
2 changes: 1 addition & 1 deletion conf/conf.go
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,7 @@ type Configuration struct {
MaxPeers int `default:"128"`
TargetOutbound int `default:"64"`
ConnectPeersOnStart []string
DisableBanning bool `default:"true"`
DisableBanning bool `default:"false"`
BanThreshold uint32 `default:"100"`
TestNet bool
RegTest bool `default:"false"`
Expand Down
4 changes: 2 additions & 2 deletions conf/conf_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -231,7 +231,7 @@ func getDefaultConfiguration(args defaultArgs) *Configuration {
MaxPeers int `default:"128"`
TargetOutbound int `default:"64"`
ConnectPeersOnStart []string
DisableBanning bool `default:"true"`
DisableBanning bool `default:"false"`
BanThreshold uint32 `default:"100"`
TestNet bool
RegTest bool `default:"false"`
Expand All @@ -254,7 +254,7 @@ func getDefaultConfiguration(args defaultArgs) *Configuration {
ListenAddrs: []string{"1234"},
MaxPeers: 128,
TargetOutbound: 64,
DisableBanning: true,
DisableBanning: false,
BanThreshold: 100,
DisableListen: true,
BlocksOnly: false,
Expand Down
13 changes: 10 additions & 3 deletions net/syncmanager/syncmanager.go
Original file line number Diff line number Diff line change
Expand Up @@ -641,10 +641,17 @@ func (sm *SyncManager) handleBlockMsg(bmsg *blockMsg) {

if !sm.headersFirstMode {
log.Debug("len of Requested block:%d, sm.allowdGetBlocksTimes: %d", len(sm.requestedBlocks), sm.allowdGetBlocksTimes)
if peer == sm.syncPeer && sm.allowdGetBlocksTimes > 0 {
if len(state.requestedBlocks) == 0 {
if peer == sm.syncPeer {
activeChain := chain.GetInstance()
tipHash := activeChain.Tip().Header.GetHash()
// add ban score when receiving an invalid new block (next of the tip) from sync peer
if bmsg.block.Header.HashPrevBlock.IsEqual(&tipHash) {
log.Error("handleBlockMsg receive an invalid block[%s] from sync peer[%s]", blockHash.String(), peer.Addr())
sm.misbehaving(peer.Addr(), 100, err.Error())
return
}
if sm.allowdGetBlocksTimes > 0 && len(state.requestedBlocks) == 0 {
sm.allowdGetBlocksTimes--
activeChain := chain.GetInstance()
locator := activeChain.GetLocator(nil)
peer.PushGetBlocksMsg(*locator, &zeroHash)
}
Expand Down

0 comments on commit 1ff5fe2

Please sign in to comment.