Skip to content
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

Merged
merged 6 commits into from
Feb 25, 2021

Conversation

zsfelfoldi
Copy link
Contributor

@zsfelfoldi zsfelfoldi commented Feb 24, 2021

This PR moves the server pool into the les/vflux/client package where the rest of the peer logic is, leaving package les for client functionality and protocol implementation. The value tracker is also created by the server pool. Only the NodeValueTracker of individual connected nodes is referenced by serverPeer in order to provide service quality feedback for the peer logic.

Replaces #22297
Fixes #22259

Note: a subsequent PR will move the clientPool into les/vflux/server, removing all peerset related complexity and all references to NodeStateMachine from package les.

@@ -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 {
Copy link
Member

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?

// 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)
Copy link
Member

@rjl493456442 rjl493456442 Feb 25, 2021

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Will you consider that we can move the "valueTracker" notion into the vflux/client totally?

IIUC, we just need to feed some statistics for the valueTracker and all the magics can be hidden in the vflux/client. The benefit is we can totally get rid of the nodeValueTracker *vfc.NodeValueTracker in the peer.

Copy link
Member

@rjl493456442 rjl493456442 Feb 25, 2021

Choose a reason for hiding this comment

The 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())

@@ -349,7 +349,6 @@ type serverPeer struct {

fcServer *flowcontrol.ServerNode // Client side mirror token bucket.
vtLock sync.Mutex
valueTracker *vfc.ValueTracker
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

we can also remove this nodeValueTracker out of the serverPeer.

@@ -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) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We can get rid of this function.

@@ -732,7 +730,6 @@ func (p *serverPeer) answeredRequest(id uint64) {
}
e, ok := p.sentReqs[id]
delete(p.sentReqs, id)
vt := p.valueTracker
Copy link
Member

Choose a reason for hiding this comment

The 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 vflux/client/serverpool.go

s.ns.SetField(p.Node(), sfiConnectedStats, nvt.RtStats())
p.setValueTracker(s.vt, nvt)
p.updateVtParams()
func (s *ServerPool) RegisterNode(node *enode.Node) (*NodeValueTracker, error) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We don't need to expose the NodeValueTracker to the outside. Serverpool expects other modules will feed it the necessary statistic for "value calculation". In this way, it's decoupled.

Copy link
Member

@rjl493456442 rjl493456442 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

lgtm

@zsfelfoldi zsfelfoldi merged commit dc109cc into ethereum:master Feb 25, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Light client crashes
2 participants