From a60a18b080197cad836f18f9d093bba3bcb6cef8 Mon Sep 17 00:00:00 2001 From: zelig Date: Tue, 3 Mar 2015 00:43:12 +0700 Subject: - fix peer disconnect by adding severity function to errs - improve logging - suicide -> removeChain - improved status BlocksInPool calculation --- blockpool/peers.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'blockpool/peers.go') diff --git a/blockpool/peers.go b/blockpool/peers.go index 5f1b2017c..576d6e41d 100644 --- a/blockpool/peers.go +++ b/blockpool/peers.go @@ -503,7 +503,7 @@ LOOP: // quitting on timeout case <-self.suicide: - self.peerError(self.bp.peers.errors.New(ErrInsufficientChainInfo, "timed out without providing block hashes or head block", currentBlockHash)) + self.peerError(self.bp.peers.errors.New(ErrInsufficientChainInfo, "timed out without providing block hashes or head block %x", currentBlockHash)) self.bp.status.lock.Lock() self.bp.status.badPeers[self.id]++ -- cgit v1.2.3 From 47278a6e4eb4b8dc02ff322ba24c9c225267ffe5 Mon Sep 17 00:00:00 2001 From: zelig Date: Tue, 3 Mar 2015 03:39:21 +0700 Subject: log when added peer is behind (hash found in blockchain) --- blockpool/peers.go | 1 + 1 file changed, 1 insertion(+) (limited to 'blockpool/peers.go') diff --git a/blockpool/peers.go b/blockpool/peers.go index 576d6e41d..9c4ffc5c6 100644 --- a/blockpool/peers.go +++ b/blockpool/peers.go @@ -214,6 +214,7 @@ func (self *peers) addPeer( // check peer current head if self.bp.hasBlock(currentBlockHash) { // peer not ahead + plog.Debugf("addPeer: peer <%v> with td %v and current block %s is behind", id, td, hex(currentBlockHash)) return false } -- cgit v1.2.3 From 2c616bd2795974877b0d3e23e99f6eff9e775218 Mon Sep 17 00:00:00 2001 From: zelig Date: Wed, 4 Mar 2015 02:06:15 +0700 Subject: partial fix to idle best peer issue - best peer cannot be idle for more than idleBestPeerTimeout - introduce ErrIdleTooLong fatal error - modify default values --- blockpool/peers.go | 28 +++++++++++++++++++--------- 1 file changed, 19 insertions(+), 9 deletions(-) (limited to 'blockpool/peers.go') diff --git a/blockpool/peers.go b/blockpool/peers.go index 9c4ffc5c6..b4aa48f49 100644 --- a/blockpool/peers.go +++ b/blockpool/peers.go @@ -37,7 +37,7 @@ type peer struct { currentBlockC chan *types.Block headSectionC chan *section - // channels to signal peers witch and peer quit + // channels to signal peer switch and peer quit to section processes idleC chan bool switchC chan bool @@ -47,7 +47,7 @@ type peer struct { // timers for head section process blockHashesRequestTimer <-chan time.Time blocksRequestTimer <-chan time.Time - suicide <-chan time.Time + suicideC <-chan time.Time idle bool } @@ -286,8 +286,7 @@ func (self *peers) removePeer(id string) { } } -// switchPeer launches section processes based on information about -// shared interest and legacy of peers +// switchPeer launches section processes func (self *BlockPool) switchPeer(oldp, newp *peer) { // first quit AddBlockHashes, requestHeadSection and activateChain @@ -372,16 +371,16 @@ func (self *peer) handleSection(sec *section) { self.bp.syncing() } - self.suicide = time.After(self.bp.Config.BlockHashesTimeout) + self.suicideC = time.After(self.bp.Config.BlockHashesTimeout) plog.DebugDetailf("HeadSection: <%s> head block hash changed (mined block received). New head %s", self.id, hex(self.currentBlockHash)) } else { if !self.idle { self.idle = true - self.suicide = nil self.bp.wg.Done() } plog.DebugDetailf("HeadSection: <%s> head section [%s] created", self.id, sectionhex(sec)) + self.suicideC = time.After(self.bp.Config.IdleBestPeerTimeout) } } @@ -451,7 +450,7 @@ func (self *peer) getBlockHashes() { self.blockHashesRequestTimer = nil if !self.idle { self.idle = true - self.suicide = nil + self.suicideC = time.After(self.bp.Config.IdleBestPeerTimeout) self.bp.wg.Done() } } @@ -467,7 +466,7 @@ func (self *peer) run() { self.blockHashesRequestTimer = nil self.blocksRequestTimer = time.After(0) - self.suicide = time.After(self.bp.Config.BlockHashesTimeout) + self.suicideC = time.After(self.bp.Config.BlockHashesTimeout) var quit chan bool @@ -476,9 +475,20 @@ func (self *peer) run() { LOOP: for { select { + // to minitor section process behaviou case <-ping.C: plog.Debugf("HeadSection: <%s> section with head %s, idle: %v", self.id, hex(self.currentBlockHash), self.idle) + // idle timer started when process goes idle + case <-self.idleC: + if self.idle { + self.peerError(self.bp.peers.errors.New(ErrIdleTooLong, "timed out without providing new blocks...quitting", currentBlockHash)) + + self.bp.status.lock.Lock() + self.bp.status.badPeers[self.id]++ + self.bp.status.lock.Unlock() + } + // signal from AddBlockHashes that head section for current best peer is created // if sec == nil, it signals that chain info has updated (new block message) case sec := <-self.headSectionC: @@ -503,7 +513,7 @@ LOOP: self.getCurrentBlock(nil) // quitting on timeout - case <-self.suicide: + case <-self.suicideC: self.peerError(self.bp.peers.errors.New(ErrInsufficientChainInfo, "timed out without providing block hashes or head block %x", currentBlockHash)) self.bp.status.lock.Lock() -- cgit v1.2.3