aboutsummaryrefslogtreecommitdiffstats
path: root/blockpool/section.go
diff options
context:
space:
mode:
authorzelig <viktor.tron@gmail.com>2015-03-20 07:00:19 +0800
committerzelig <viktor.tron@gmail.com>2015-03-20 18:41:41 +0800
commit137a9c9365dd9ec76d4a4aab7475d716457d00ae (patch)
treebbd282f06b0559c53f9fe3ae7c7beb74e0cfe592 /blockpool/section.go
parenta9926a289dd21bcfd8e2def8f4005b43b728cb3d (diff)
downloaddexon-137a9c9365dd9ec76d4a4aab7475d716457d00ae.tar
dexon-137a9c9365dd9ec76d4a4aab7475d716457d00ae.tar.gz
dexon-137a9c9365dd9ec76d4a4aab7475d716457d00ae.tar.bz2
dexon-137a9c9365dd9ec76d4a4aab7475d716457d00ae.tar.lz
dexon-137a9c9365dd9ec76d4a4aab7475d716457d00ae.tar.xz
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/section.go')
-rw-r--r--blockpool/section.go33
1 files changed, 21 insertions, 12 deletions
diff --git a/blockpool/section.go b/blockpool/section.go
index c73aaa6df..0304c9a04 100644
--- a/blockpool/section.go
+++ b/blockpool/section.go
@@ -83,9 +83,9 @@ func (self *BlockPool) newSection(nodes []*node) *section {
offC: make(chan bool),
}
- for i, node := range nodes {
- entry := &entry{node: node, section: sec, index: &index{i}}
- self.set(node.hash, entry)
+ for i, n := range nodes {
+ entry := &entry{node: n, section: sec, index: &index{i}}
+ self.set(n.hash, entry)
}
plog.DebugDetailf("[%s] setup section process", sectionhex(sec))
@@ -104,20 +104,22 @@ func (self *section) addSectionToBlockChain(p *peer) {
self.bp.wg.Done()
}()
- var node *node
+ var nodes []*node
+ var n *node
var keys []string
var blocks []*types.Block
for self.poolRootIndex > 0 {
- node = self.nodes[self.poolRootIndex-1]
- node.lock.RLock()
- block := node.block
- node.lock.RUnlock()
+ n = self.nodes[self.poolRootIndex-1]
+ n.lock.RLock()
+ block := n.block
+ n.lock.RUnlock()
if block == nil {
break
}
self.poolRootIndex--
keys = append(keys, node.hash.Str())
blocks = append(blocks, block)
+ nodes = append(nodes, n)
}
if len(blocks) == 0 {
@@ -134,13 +136,20 @@ func (self *section) addSectionToBlockChain(p *peer) {
err := self.bp.insertChain(blocks)
if err != nil {
self.invalid = true
- self.bp.peers.peerError(node.blockBy, ErrInvalidBlock, "%v", err)
- plog.Warnf("invalid block %x", node.hash)
- plog.Warnf("penalise peers %v (hash), %v (block)", node.hashBy, node.blockBy)
+ self.bp.peers.peerError(n.blockBy, ErrInvalidBlock, "%v", err)
+ plog.Warnf("invalid block %x", n.hash)
+ plog.Warnf("penalise peers %v (hash), %v (block)", n.hashBy, n.blockBy)
// or invalid block and the entire chain needs to be removed
self.removeChain()
} else {
+ // check tds
+ self.bp.wg.Add(1)
+ go func() {
+ plog.DebugDetailf("checking td")
+ self.bp.checkTD(nodes...)
+ self.bp.wg.Done()
+ }()
// if all blocks inserted in this section
// then need to try to insert blocks in child section
if self.poolRootIndex == 0 {
@@ -178,7 +187,7 @@ func (self *section) addSectionToBlockChain(p *peer) {
self.bp.status.values.BlocksInChain += len(blocks)
self.bp.status.values.BlocksInPool -= len(blocks)
if err != nil {
- self.bp.status.badPeers[node.blockBy]++
+ self.bp.status.badPeers[n.blockBy]++
}
self.bp.status.lock.Unlock()