aboutsummaryrefslogtreecommitdiffstats
path: root/blockpool/blockpool.go
diff options
context:
space:
mode:
authorzelig <viktor.tron@gmail.com>2015-03-03 01:43:12 +0800
committerzelig <viktor.tron@gmail.com>2015-03-03 01:43:12 +0800
commita60a18b080197cad836f18f9d093bba3bcb6cef8 (patch)
treebf5faaf44d1875a6c0cfe65107ad7329d70d2138 /blockpool/blockpool.go
parent16ecda951b767800b4e09ad8e86e0866b05136be (diff)
downloaddexon-a60a18b080197cad836f18f9d093bba3bcb6cef8.tar.gz
dexon-a60a18b080197cad836f18f9d093bba3bcb6cef8.tar.zst
dexon-a60a18b080197cad836f18f9d093bba3bcb6cef8.zip
- fix peer disconnect by adding severity function to errs
- improve logging - suicide -> removeChain - improved status BlocksInPool calculation
Diffstat (limited to 'blockpool/blockpool.go')
-rw-r--r--blockpool/blockpool.go45
1 files changed, 36 insertions, 9 deletions
diff --git a/blockpool/blockpool.go b/blockpool/blockpool.go
index 0126d734c..5da671ec2 100644
--- a/blockpool/blockpool.go
+++ b/blockpool/blockpool.go
@@ -149,6 +149,15 @@ func New(
}
}
+func severity(code int) ethlogger.LogLevel {
+ switch code {
+ case ErrUnrequestedBlock:
+ return ethlogger.WarnLevel
+ default:
+ return ethlogger.ErrorLevel
+ }
+}
+
// allows restart
func (self *BlockPool) Start() {
self.lock.Lock()
@@ -169,6 +178,7 @@ func (self *BlockPool) Start() {
errors: &errs.Errors{
Package: "Blockpool",
Errors: errorToString,
+ Level: severity,
},
peers: make(map[string]*peer),
status: self.status,
@@ -363,6 +373,8 @@ LOOP:
// check if known block connecting the downloaded chain to our blockchain
plog.DebugDetailf("AddBlockHashes: peer <%s> (head: %s) found block %s in the blockchain", peerId, hex(bestpeer.currentBlockHash), hex(hash))
if len(nodes) == 1 {
+ plog.DebugDetailf("AddBlockHashes: singleton section pushed to blockchain peer <%s> (head: %s) found block %s in the blockchain", peerId, hex(bestpeer.currentBlockHash), hex(hash))
+
// create new section if needed and push it to the blockchain
sec = self.newSection(nodes)
sec.addSectionToBlockChain(bestpeer)
@@ -379,6 +391,8 @@ LOOP:
and td together with blockBy are recorded on the node
*/
if len(nodes) == 0 && child != nil {
+ plog.DebugDetailf("AddBlockHashes: child section [%s] pushed to blockchain peer <%s> (head: %s) found block %s in the blockchain", sectionhex(child), peerId, hex(bestpeer.currentBlockHash), hex(hash))
+
child.addSectionToBlockChain(bestpeer)
}
}
@@ -446,10 +460,12 @@ LOOP:
*/
sec = self.linkSections(nodes, parent, child)
- self.status.lock.Lock()
- self.status.values.BlockHashes += len(nodes)
- self.status.lock.Unlock()
- plog.DebugDetailf("AddBlockHashes: peer <%s> (head: %s): section [%s] created", peerId, hex(bestpeer.currentBlockHash), sectionhex(sec))
+ if sec != nil {
+ self.status.lock.Lock()
+ self.status.values.BlockHashes += len(nodes)
+ self.status.lock.Unlock()
+ plog.DebugDetailf("AddBlockHashes: peer <%s> (head: %s): section [%s] created", peerId, hex(bestpeer.currentBlockHash), sectionhex(sec))
+ }
self.chainLock.Unlock()
@@ -549,6 +565,7 @@ func (self *BlockPool) AddBlock(block *types.Block, peerId string) {
self.status.lock.Unlock()
} else {
plog.DebugDetailf("AddBlock: head block %s for peer <%s> (head: %s) already known", hex(hash), peerId, hex(sender.currentBlockHash))
+ sender.currentBlockC <- block
}
} else {
@@ -644,11 +661,15 @@ LOOP:
we need to relink both complete and incomplete sections
the latter could have been blockHashesRequestsComplete before being delinked from its parent
*/
- if parent == nil && sec.bottom.block != nil {
- if entry := self.get(sec.bottom.block.ParentHash()); entry != nil {
- parent = entry.section
- plog.DebugDetailf("activateChain: [%s]-[%s] relink", sectionhex(parent), sectionhex(sec))
- link(parent, sec)
+ if parent == nil {
+ if sec.bottom.block != nil {
+ if entry := self.get(sec.bottom.block.ParentHash()); entry != nil {
+ parent = entry.section
+ plog.DebugDetailf("activateChain: [%s]-[%s] link", sectionhex(parent), sectionhex(sec))
+ link(parent, sec)
+ }
+ } else {
+ plog.DebugDetailf("activateChain: section [%s] activated by peer <%s> has missing root block", sectionhex(sec), p.id)
}
}
sec = parent
@@ -704,9 +725,15 @@ func (self *BlockPool) remove(sec *section) {
// delete node entries from pool index under pool lock
self.lock.Lock()
defer self.lock.Unlock()
+
for _, node := range sec.nodes {
delete(self.pool, string(node.hash))
}
+ if sec.initialised && sec.poolRootIndex != 0 {
+ self.status.lock.Lock()
+ self.status.values.BlocksInPool -= len(sec.nodes) - sec.missing
+ self.status.lock.Unlock()
+ }
}
func (self *BlockPool) getHashSlice() (s [][]byte) {