les: implement new client pool (#19745)

This commit is contained in:
Felföldi Zsolt
2019-08-03 14:36:10 +02:00
committed by GitHub
parent 947f5f2b15
commit a7de796840
15 changed files with 1653 additions and 588 deletions

View File

@@ -27,6 +27,7 @@ import (
"time"
"github.com/ethereum/go-ethereum/common"
"github.com/ethereum/go-ethereum/common/mclock"
"github.com/ethereum/go-ethereum/core"
"github.com/ethereum/go-ethereum/core/rawdb"
"github.com/ethereum/go-ethereum/core/state"
@@ -304,8 +305,14 @@ func (pm *ProtocolManager) handle(p *peer) error {
p.Log().Error("Light Ethereum peer registration failed", "err", err)
return err
}
if !pm.client && p.balanceTracker == nil {
// add dummy balance tracker for tests
p.balanceTracker = &balanceTracker{}
p.balanceTracker.init(&mclock.System{}, 1)
}
connectedAt := time.Now()
defer func() {
p.balanceTracker = nil
pm.removePeer(p.id)
connectionTimer.UpdateSince(connectedAt)
}()
@@ -400,6 +407,7 @@ func (pm *ProtocolManager) handleMsg(p *peer) error {
defer msg.Discard()
var deliverMsg *Msg
balanceTracker := p.balanceTracker
sendResponse := func(reqID, amount uint64, reply *reply, servingTime uint64) {
p.responseLock.Lock()
@@ -418,6 +426,7 @@ func (pm *ProtocolManager) handleMsg(p *peer) error {
realCost = pm.server.costTracker.realCost(servingTime, msg.Size, replySize)
if amount != 0 {
pm.server.costTracker.updateStats(msg.Code, amount, servingTime, realCost)
balanceTracker.requestCost(realCost)
}
} else {
realCost = maxCost