diff options
author | Zsolt Felfoldi <zsfelfoldi@gmail.com> | 2016-11-30 13:02:08 +0800 |
---|---|---|
committer | Zsolt Felfoldi <zsfelfoldi@gmail.com> | 2016-12-10 16:53:08 +0800 |
commit | af8a742d00f9d47b832f6f2d50a8e1c89bbf8441 (patch) | |
tree | 92fca6d9750797a9c5f1fc712e2de1181be60390 /les/peer.go | |
parent | e67500aa15a2f51a96f0ae91ab3af898b81d82f2 (diff) | |
download | go-tangerine-af8a742d00f9d47b832f6f2d50a8e1c89bbf8441.tar go-tangerine-af8a742d00f9d47b832f6f2d50a8e1c89bbf8441.tar.gz go-tangerine-af8a742d00f9d47b832f6f2d50a8e1c89bbf8441.tar.bz2 go-tangerine-af8a742d00f9d47b832f6f2d50a8e1c89bbf8441.tar.lz go-tangerine-af8a742d00f9d47b832f6f2d50a8e1c89bbf8441.tar.xz go-tangerine-af8a742d00f9d47b832f6f2d50a8e1c89bbf8441.tar.zst go-tangerine-af8a742d00f9d47b832f6f2d50a8e1c89bbf8441.zip |
les: improved header fetcher and server statistics
Diffstat (limited to 'les/peer.go')
-rw-r--r-- | les/peer.go | 70 |
1 files changed, 3 insertions, 67 deletions
diff --git a/les/peer.go b/les/peer.go index 8eced439d..8ebbe3511 100644 --- a/les/peer.go +++ b/les/peer.go @@ -51,9 +51,8 @@ type peer struct { id string - firstHeadInfo, headInfo *announceData - headInfoLen int - lock sync.RWMutex + headInfo *announceData + lock sync.RWMutex announceChn chan announceData @@ -111,67 +110,6 @@ func (p *peer) headBlockInfo() blockInfo { return blockInfo{Hash: p.headInfo.Hash, Number: p.headInfo.Number, Td: p.headInfo.Td} } -func (p *peer) addNotify(announce *announceData) bool { - p.lock.Lock() - defer p.lock.Unlock() - - if announce.Td.Cmp(p.headInfo.Td) < 1 { - return false - } - if p.headInfoLen >= maxHeadInfoLen { - //return false - p.firstHeadInfo = p.firstHeadInfo.next - p.headInfoLen-- - } - if announce.haveHeaders == 0 { - hh := p.headInfo.Number - announce.ReorgDepth - if p.headInfo.haveHeaders < hh { - hh = p.headInfo.haveHeaders - } - announce.haveHeaders = hh - } - p.headInfo.next = announce - p.headInfo = announce - p.headInfoLen++ - return true -} - -func (p *peer) gotHeader(hash common.Hash, number uint64, td *big.Int) bool { - h := p.firstHeadInfo - ptr := 0 - for h != nil { - if h.Hash == hash { - if h.Number != number || h.Td.Cmp(td) != 0 { - return false - } - h.headKnown = true - h.haveHeaders = h.Number - p.firstHeadInfo = h - p.headInfoLen -= ptr - last := h - h = h.next - // propagate haveHeaders through the chain - for h != nil { - hh := last.Number - h.ReorgDepth - if last.haveHeaders < hh { - hh = last.haveHeaders - } - if hh > h.haveHeaders { - h.haveHeaders = hh - } else { - return true - } - last = h - h = h.next - } - return true - } - h = h.next - ptr++ - } - return true -} - // Td retrieves the current total difficulty of a peer. func (p *peer) Td() *big.Int { p.lock.RLock() @@ -455,9 +393,7 @@ func (p *peer) Handshake(td *big.Int, head common.Hash, headNum uint64, genesis p.fcCosts = MRC.decode() } - p.firstHeadInfo = &announceData{Td: rTd, Hash: rHash, Number: rNum} - p.headInfo = p.firstHeadInfo - p.headInfoLen = 1 + p.headInfo = &announceData{Td: rTd, Hash: rHash, Number: rNum} return nil } |