diff options
author | zelig <viktor.tron@gmail.com> | 2015-03-20 07:00:19 +0800 |
---|---|---|
committer | zelig <viktor.tron@gmail.com> | 2015-03-20 18:41:41 +0800 |
commit | 137a9c9365dd9ec76d4a4aab7475d716457d00ae (patch) | |
tree | bbd282f06b0559c53f9fe3ae7c7beb74e0cfe592 /blockpool/blockpool.go | |
parent | a9926a289dd21bcfd8e2def8f4005b43b728cb3d (diff) | |
download | dexon-137a9c9365dd9ec76d4a4aab7475d716457d00ae.tar.gz dexon-137a9c9365dd9ec76d4a4aab7475d716457d00ae.tar.zst dexon-137a9c9365dd9ec76d4a4aab7475d716457d00ae.zip |
check and penalise td misreporting
- add ErrIncorrectTD
- checkTD called after insertChain successful
- fix tests, use blockPoolTester.tds to map block index to TD
Diffstat (limited to 'blockpool/blockpool.go')
-rw-r--r-- | blockpool/blockpool.go | 14 |
1 files changed, 14 insertions, 0 deletions
diff --git a/blockpool/blockpool.go b/blockpool/blockpool.go index a552e1b72..df3d14542 100644 --- a/blockpool/blockpool.go +++ b/blockpool/blockpool.go @@ -62,6 +62,7 @@ const ( ErrUnrequestedBlock ErrInsufficientChainInfo ErrIdleTooLong + ErrIncorrectTD ) var errorToString = map[int]string{ @@ -70,6 +71,7 @@ var errorToString = map[int]string{ ErrUnrequestedBlock: "Unrequested block", ErrInsufficientChainInfo: "Insufficient chain info", ErrIdleTooLong: "Idle too long", + ErrIncorrectTD: "Incorrect Total Difficulty", } // init initialises all your laundry @@ -373,6 +375,7 @@ func (self *BlockPool) AddBlockHashes(next func() (common.Hash, bool), peerId st block: bestpeer.currentBlock, hashBy: peerId, blockBy: peerId, + td: bestpeer.td, } // nodes is a list of nodes in one section ordered top-bottom (old to young) nodes = append(nodes, node) @@ -729,6 +732,17 @@ LOOP: } } +func (self *BlockPool) checkTD(nodes ...*node) { + for _, n := range nodes { + if n.td != nil { + 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) + } + } + } +} + // must run in separate go routine, otherwise // switchpeer -> activateChain -> activate deadlocks on section process select and peers.lock func (self *BlockPool) requestBlocks(attempts int, hashes []common.Hash) { |