aboutsummaryrefslogtreecommitdiffstats
path: root/blockpool
diff options
context:
space:
mode:
authorzelig <viktor.tron@gmail.com>2015-04-09 04:14:49 +0800
committerzelig <viktor.tron@gmail.com>2015-04-09 20:58:35 +0800
commit0e2bc23148731a2e9fbb22885aced057e308335a (patch)
treeb792b86e58bd051aa4465feb28400d1dd84c0f42 /blockpool
parente55747a074c7f280029b94c94418d60dff5d6773 (diff)
downloadgo-tangerine-0e2bc23148731a2e9fbb22885aced057e308335a.tar
go-tangerine-0e2bc23148731a2e9fbb22885aced057e308335a.tar.gz
go-tangerine-0e2bc23148731a2e9fbb22885aced057e308335a.tar.bz2
go-tangerine-0e2bc23148731a2e9fbb22885aced057e308335a.tar.lz
go-tangerine-0e2bc23148731a2e9fbb22885aced057e308335a.tar.xz
go-tangerine-0e2bc23148731a2e9fbb22885aced057e308335a.tar.zst
go-tangerine-0e2bc23148731a2e9fbb22885aced057e308335a.zip
uncomment future block TD check, add test for skipping TD check on future block
Diffstat (limited to 'blockpool')
-rw-r--r--blockpool/blockpool.go8
-rw-r--r--blockpool/blockpool_util_test.go2
-rw-r--r--blockpool/errors_test.go41
-rw-r--r--blockpool/peers.go4
4 files changed, 46 insertions, 9 deletions
diff --git a/blockpool/blockpool.go b/blockpool/blockpool.go
index 0a130773d..2340eadae 100644
--- a/blockpool/blockpool.go
+++ b/blockpool/blockpool.go
@@ -790,10 +790,10 @@ func (self *BlockPool) checkTD(nodes ...*node) {
if n.td != nil && !n.block.Queued() {
plog.DebugDetailf("peer td %v =?= block td %v", n.td, n.block.Td)
if n.td.Cmp(n.block.Td) != 0 {
- // self.peers.peerError(n.blockBy, ErrIncorrectTD, "on block %x", n.hash)
- // self.status.lock.Lock()
- // self.status.badPeers[n.blockBy]++
- // self.status.lock.Unlock()
+ self.peers.peerError(n.blockBy, ErrIncorrectTD, "on block %x", n.hash)
+ self.status.lock.Lock()
+ self.status.badPeers[n.blockBy]++
+ self.status.lock.Unlock()
}
}
}
diff --git a/blockpool/blockpool_util_test.go b/blockpool/blockpool_util_test.go
index be14fbae8..e52c0f753 100644
--- a/blockpool/blockpool_util_test.go
+++ b/blockpool/blockpool_util_test.go
@@ -87,7 +87,7 @@ func (self *blockPoolTester) insertChain(blocks types.Blocks) error {
var ok bool
for _, block := range blocks {
child = self.hashPool.HashesToIndexes([]common.Hash{block.Hash()})[0]
- var td int
+ td := child
if self.tds != nil {
td, ok = self.tds[child]
}
diff --git a/blockpool/errors_test.go b/blockpool/errors_test.go
index e9aef4c87..b0b831270 100644
--- a/blockpool/errors_test.go
+++ b/blockpool/errors_test.go
@@ -128,8 +128,6 @@ func TestErrInsufficientChainInfo(t *testing.T) {
}
func TestIncorrectTD(t *testing.T) {
- t.Skip() // @zelig this one requires fixing for the TD
-
test.LogInit()
_, blockPool, blockPoolTester := newTestBlockPool(t)
blockPoolTester.blockChain[0] = nil
@@ -156,6 +154,45 @@ func TestIncorrectTD(t *testing.T) {
}
}
+func TestSkipIncorrectTDonFutureBlocks(t *testing.T) {
+ // t.Skip() // @zelig this one requires fixing for the TD
+
+ test.LogInit()
+ _, blockPool, blockPoolTester := newTestBlockPool(t)
+ blockPoolTester.blockChain[0] = nil
+ blockPoolTester.initRefBlockChain(3)
+
+ blockPool.insertChain = func(blocks types.Blocks) error {
+ err := blockPoolTester.insertChain(blocks)
+ if err == nil {
+ for _, block := range blocks {
+ if block.Td.Cmp(common.Big3) == 0 {
+ block.Td = common.Big3
+ block.SetQueued(true)
+ break
+ }
+ }
+ }
+ return err
+ }
+
+ blockPool.Start()
+
+ peer1 := blockPoolTester.newPeer("peer1", 3, 3)
+ peer1.AddPeer()
+ go peer1.serveBlocks(2, 3)
+ go peer1.serveBlockHashes(3, 2, 1, 0)
+ peer1.serveBlocks(0, 1, 2)
+
+ blockPool.Wait(waitTimeout)
+ blockPool.Stop()
+ blockPoolTester.refBlockChain[3] = []int{}
+ blockPoolTester.checkBlockChain(blockPoolTester.refBlockChain)
+ if len(peer1.peerErrors) > 0 {
+ t.Errorf("expected no error, got %v (1 of %v)", peer1.peerErrors[0], len(peer1.peerErrors))
+ }
+}
+
func TestPeerSuspension(t *testing.T) {
test.LogInit()
_, blockPool, blockPoolTester := newTestBlockPool(t)
diff --git a/blockpool/peers.go b/blockpool/peers.go
index 7e6d281bb..8a52545df 100644
--- a/blockpool/peers.go
+++ b/blockpool/peers.go
@@ -473,8 +473,8 @@ func (self *peer) getBlockHashes() bool {
// XXX added currentBlock check (?)
if self.currentBlock != nil && self.currentBlock.Td != nil && !self.currentBlock.Queued() {
if self.td.Cmp(self.currentBlock.Td) != 0 {
- // self.addError(ErrIncorrectTD, "on block %x", self.currentBlockHash)
- // self.bp.status.badPeers[self.id]++
+ self.addError(ErrIncorrectTD, "on block %x", self.currentBlockHash)
+ self.bp.status.badPeers[self.id]++
}
}
headKey := self.parentHash