From 137a9c9365dd9ec76d4a4aab7475d716457d00ae Mon Sep 17 00:00:00 2001 From: zelig Date: Thu, 19 Mar 2015 23:00:19 +0000 Subject: check and penalise td misreporting - add ErrIncorrectTD - checkTD called after insertChain successful - fix tests, use blockPoolTester.tds to map block index to TD --- blockpool/peers.go | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) (limited to 'blockpool/peers.go') diff --git a/blockpool/peers.go b/blockpool/peers.go index b463137e3..5cc483a3b 100644 --- a/blockpool/peers.go +++ b/blockpool/peers.go @@ -452,8 +452,12 @@ func (self *peer) getBlockHashes() { self.addError(ErrInvalidBlock, "%v", err) self.bp.status.badPeers[self.id]++ } else { + if self.currentBlock.Td != nil { + if self.td.Cmp(self.currentBlock.Td) != 0 { + self.addError(ErrIncorrectTD, "on block %x", self.currentBlockHash) + } + } headKey := self.parentHash.Str() - height := self.bp.status.chain[headKey] + 1 self.bp.status.chain[self.currentBlockHash.Str()] = height if height > self.bp.status.values.LongestChain { self.bp.status.values.LongestChain = height @@ -471,6 +475,7 @@ func (self *peer) getBlockHashes() { block: self.currentBlock, hashBy: self.id, blockBy: self.id, + td: self.td, } self.bp.newSection([]*node{n}).activate(self) } else { -- cgit