les, les/lespay/server: refactor client pool (#21236)
* les, les/lespay/server: refactor client pool * les: use ns.Operation and sub calls where needed * les: fixed tests * les: removed active/inactive logic from peerSet * les: removed active/inactive peer logic * les: fixed linter warnings * les: fixed more linter errors and added missing metrics * les: addressed comments * cmd/geth: fixed TestPriorityClient * les: simplified clientPool state machine * les/lespay/server: do not use goroutine for balance callbacks * internal/web3ext: fix addBalance required parameters * les: removed freeCapacity, always connect at minCapacity initially * les: only allow capacity change with priority status Co-authored-by: rjl493456442 <garyrong0905@gmail.com>
This commit is contained in:
26
les/peer.go
26
les/peer.go
@ -33,6 +33,7 @@ import (
|
||||
"github.com/ethereum/go-ethereum/eth"
|
||||
"github.com/ethereum/go-ethereum/les/flowcontrol"
|
||||
lpc "github.com/ethereum/go-ethereum/les/lespay/client"
|
||||
lps "github.com/ethereum/go-ethereum/les/lespay/server"
|
||||
"github.com/ethereum/go-ethereum/les/utils"
|
||||
"github.com/ethereum/go-ethereum/light"
|
||||
"github.com/ethereum/go-ethereum/p2p"
|
||||
@ -463,7 +464,7 @@ func (p *serverPeer) requestTxStatus(reqID uint64, txHashes []common.Hash) error
|
||||
return p.sendRequest(GetTxStatusMsg, reqID, txHashes, len(txHashes))
|
||||
}
|
||||
|
||||
// SendTxStatus creates a reply with a batch of transactions to be added to the remote transaction pool.
|
||||
// sendTxs creates a reply with a batch of transactions to be added to the remote transaction pool.
|
||||
func (p *serverPeer) sendTxs(reqID uint64, amount int, txs rlp.RawValue) error {
|
||||
p.Log().Debug("Sending batch of transactions", "amount", amount, "size", len(txs))
|
||||
sizeFactor := (len(txs) + txSizeCostLimit/2) / txSizeCostLimit
|
||||
@ -719,6 +720,8 @@ type clientPeer struct {
|
||||
responseLock sync.Mutex
|
||||
responseCount uint64 // Counter to generate an unique id for request processing.
|
||||
|
||||
balance *lps.NodeBalance
|
||||
|
||||
// invalidLock is used for protecting invalidCount.
|
||||
invalidLock sync.RWMutex
|
||||
invalidCount utils.LinearExpiredValue // Counter the invalid request the client peer has made.
|
||||
@ -876,18 +879,25 @@ func (p *clientPeer) sendAnnounce(request announceData) error {
|
||||
return p2p.Send(p.rw, AnnounceMsg, request)
|
||||
}
|
||||
|
||||
// allowInactive implements clientPoolPeer
|
||||
func (p *clientPeer) allowInactive() bool {
|
||||
return false
|
||||
}
|
||||
|
||||
// updateCapacity updates the request serving capacity assigned to a given client
|
||||
// and also sends an announcement about the updated flow control parameters
|
||||
func (p *clientPeer) updateCapacity(cap uint64) {
|
||||
p.lock.Lock()
|
||||
defer p.lock.Unlock()
|
||||
|
||||
p.fcParams = flowcontrol.ServerParams{MinRecharge: cap, BufLimit: cap * bufLimitRatio}
|
||||
p.fcClient.UpdateParams(p.fcParams)
|
||||
var kvList keyValueList
|
||||
kvList = kvList.add("flowControl/MRR", cap)
|
||||
kvList = kvList.add("flowControl/BL", cap*bufLimitRatio)
|
||||
p.queueSend(func() { p.sendAnnounce(announceData{Update: kvList}) })
|
||||
if cap != p.fcParams.MinRecharge {
|
||||
p.fcParams = flowcontrol.ServerParams{MinRecharge: cap, BufLimit: cap * bufLimitRatio}
|
||||
p.fcClient.UpdateParams(p.fcParams)
|
||||
var kvList keyValueList
|
||||
kvList = kvList.add("flowControl/MRR", cap)
|
||||
kvList = kvList.add("flowControl/BL", cap*bufLimitRatio)
|
||||
p.queueSend(func() { p.sendAnnounce(announceData{Update: kvList}) })
|
||||
}
|
||||
}
|
||||
|
||||
// freezeClient temporarily puts the client in a frozen state which means all
|
||||
@ -974,7 +984,7 @@ func (p *clientPeer) Handshake(td *big.Int, head common.Hash, headNum uint64, ge
|
||||
// set default announceType on server side
|
||||
p.announceType = announceTypeSimple
|
||||
}
|
||||
p.fcClient = flowcontrol.NewClientNode(server.fcManager, server.defParams)
|
||||
p.fcClient = flowcontrol.NewClientNode(server.fcManager, p.fcParams)
|
||||
}
|
||||
return nil
|
||||
})
|
||||
|
Reference in New Issue
Block a user