-
Notifications
You must be signed in to change notification settings - Fork 20.6k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
les: move server pool to les/vflux/client #22377
Changes from all commits
eac82dd
4d48181
9eca750
b3609d9
0aaa63d
6dea908
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -114,11 +114,25 @@ func (h *clientHandler) handle(p *serverPeer) error { | |
p.Log().Debug("Light Ethereum handshake failed", "err", err) | ||
return err | ||
} | ||
// Register peer with the server pool | ||
if h.backend.serverPool != nil { | ||
if nvt, err := h.backend.serverPool.RegisterNode(p.Node()); err == nil { | ||
p.setValueTracker(nvt) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Will you consider that we can move the "valueTracker" notion into the IIUC, we just need to feed some statistics for the There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. So we can simplify the logic like // Register peer with the server pool
if err := h.backend.serverPool.RegisterNode(p.Node()); err != nil {
return err
}
defer h.backend.serverPool.UnregisterNode(p.Node()) |
||
p.updateVtParams() | ||
defer func() { | ||
p.setValueTracker(nil) | ||
h.backend.serverPool.UnregisterNode(p.Node()) | ||
}() | ||
} else { | ||
return err | ||
} | ||
} | ||
// Register the peer locally | ||
if err := h.backend.peers.register(p); err != nil { | ||
p.Log().Error("Light Ethereum peer registration failed", "err", err) | ||
return err | ||
} | ||
|
||
serverConnectionGauge.Update(int64(h.backend.peers.len())) | ||
|
||
connectedAt := mclock.Now() | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -349,7 +349,6 @@ type serverPeer struct { | |
|
||
fcServer *flowcontrol.ServerNode // Client side mirror token bucket. | ||
vtLock sync.Mutex | ||
valueTracker *vfc.ValueTracker | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. we can also remove this |
||
nodeValueTracker *vfc.NodeValueTracker | ||
sentReqs map[uint64]sentReqEntry | ||
|
||
|
@@ -676,9 +675,8 @@ func (p *serverPeer) Handshake(genesis common.Hash, forkid forkid.ID, forkFilter | |
|
||
// setValueTracker sets the value tracker references for connected servers. Note that the | ||
// references should be removed upon disconnection by setValueTracker(nil, nil). | ||
func (p *serverPeer) setValueTracker(vt *vfc.ValueTracker, nvt *vfc.NodeValueTracker) { | ||
func (p *serverPeer) setValueTracker(nvt *vfc.NodeValueTracker) { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. We can get rid of this function. |
||
p.vtLock.Lock() | ||
p.valueTracker = vt | ||
p.nodeValueTracker = nvt | ||
if nvt != nil { | ||
p.sentReqs = make(map[uint64]sentReqEntry) | ||
|
@@ -705,7 +703,7 @@ func (p *serverPeer) updateVtParams() { | |
} | ||
} | ||
} | ||
p.valueTracker.UpdateCosts(p.nodeValueTracker, reqCosts) | ||
p.nodeValueTracker.UpdateCosts(reqCosts) | ||
} | ||
|
||
// sentReqEntry remembers sent requests and their sending times | ||
|
@@ -732,7 +730,6 @@ func (p *serverPeer) answeredRequest(id uint64) { | |
} | ||
e, ok := p.sentReqs[id] | ||
delete(p.sentReqs, id) | ||
vt := p.valueTracker | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This function can be modified a bit, which only returns the serving time. All the value calculation work can be thrown to |
||
nvt := p.nodeValueTracker | ||
p.vtLock.Unlock() | ||
if !ok { | ||
|
@@ -752,7 +749,7 @@ func (p *serverPeer) answeredRequest(id uint64) { | |
vtReqs[1] = vfc.ServedRequest{ReqType: uint32(m.rest), Amount: e.amount - 1} | ||
} | ||
dt := time.Duration(mclock.Now() - e.at) | ||
vt.Served(nvt, vtReqs[:reqCount], dt) | ||
nvt.Served(vtReqs[:reqCount], dt) | ||
} | ||
|
||
// clientPeer represents each node to which the les server is connected. | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is there any possibility that the serverpool can be nil? Perhaps in the testing?