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

Use old method of peer selection for non-POS networks #6279

Merged
merged 3 commits into from
Dec 11, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
30 changes: 30 additions & 0 deletions cmd/sentry/sentry/sentry_grpc_server.go
Original file line number Diff line number Diff line change
Expand Up @@ -773,6 +773,28 @@ func (ss *GrpcServer) findBestPeersWithPermit(peerCount int) []*PeerInfo {
return foundPeers
}

func (ss *GrpcServer) findPeerByMinBlock(minBlock uint64) (*PeerInfo, bool) {
// Choose a peer that we can send this request to, with maximum number of permits
var foundPeerInfo *PeerInfo
var maxPermits int
now := time.Now()
ss.rangePeers(func(peerInfo *PeerInfo) bool {
if peerInfo.Height() >= minBlock {
deadlines := peerInfo.ClearDeadlines(now, false /* givePermit */)
//fmt.Printf("%d deadlines for peer %s\n", deadlines, peerID)
if deadlines < maxPermitsPerPeer {
permits := maxPermitsPerPeer - deadlines
if permits > maxPermits {
maxPermits = permits
foundPeerInfo = peerInfo
}
}
}
return true
})
return foundPeerInfo, maxPermits > 0
}

func (ss *GrpcServer) SendMessageByMinBlock(_ context.Context, inreq *proto_sentry.SendMessageByMinBlockRequest) (*proto_sentry.SentPeers, error) {
reply := &proto_sentry.SentPeers{}
msgcode := eth.FromProto[ss.Protocol.Version][inreq.Data.Id]
Expand All @@ -781,6 +803,14 @@ func (ss *GrpcServer) SendMessageByMinBlock(_ context.Context, inreq *proto_sent
msgcode != eth.GetPooledTransactionsMsg {
return reply, fmt.Errorf("sendMessageByMinBlock not implemented for message Id: %s", inreq.Data.Id)
}
if !ss.GetStatus().PassivePeers {
peerInfo, found := ss.findPeerByMinBlock(inreq.MinBlock)
if found {
ss.writePeer("sendMessageByMinBlock", peerInfo, msgcode, inreq.Data.Data, 30*time.Second)
reply.Peers = []*proto_types.H512{gointerfaces.ConvertHashToH512(peerInfo.ID())}
return reply, nil
}
}
peerInfos := ss.findBestPeersWithPermit(int(inreq.MaxPeers))
reply.Peers = make([]*proto_types.H512, len(peerInfos))
for i, peerInfo := range peerInfos {
Expand Down
3 changes: 3 additions & 0 deletions cmd/sentry/sentry/sentry_multi_client.go
Original file line number Diff line number Diff line change
Expand Up @@ -262,6 +262,7 @@ type MultiClient struct {
Engine consensus.Engine
blockReader services.HeaderAndCanonicalReader
logPeerInfo bool
passivePeers bool

historyV3 bool
}
Expand Down Expand Up @@ -307,6 +308,7 @@ func NewMultiClient(
logPeerInfo: logPeerInfo,
forkValidator: forkValidator,
historyV3: historyV3,
passivePeers: chainConfig.TerminalTotalDifficultyPassed,
}
cs.ChainConfig = chainConfig
cs.forks = forkid.GatherForks(cs.ChainConfig)
Expand Down Expand Up @@ -758,6 +760,7 @@ func (cs *MultiClient) makeStatusData() *proto_sentry.StatusData {
Genesis: gointerfaces.ConvertHashToH256(s.genesisHash),
Forks: s.forks,
},
PassivePeers: cs.passivePeers,
}
}

Expand Down
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ module github.com/ledgerwatch/erigon
go 1.18

require (
github.com/ledgerwatch/erigon-lib v0.0.0-20221210085350-2f641bdeb4fe
github.com/ledgerwatch/erigon-lib v0.0.0-20221211145319-874c497dda90
github.com/ledgerwatch/erigon-snapshot v1.1.1-0.20221117232719-cf68648bf146
github.com/ledgerwatch/log/v3 v3.6.0
github.com/ledgerwatch/secp256k1 v1.0.0
Expand Down
4 changes: 2 additions & 2 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -561,8 +561,8 @@ github.com/kr/text v0.2.0/go.mod h1:eLer722TekiGuMkidMxC/pM04lWEeraHUUmBw8l2grE=
github.com/kylelemons/godebug v0.0.0-20170224010052-a616ab194758 h1:0D5M2HQSGD3PYPwICLl+/9oulQauOuETfgFvhBDffs0=
github.com/leanovate/gopter v0.2.9 h1:fQjYxZaynp97ozCzfOyOuAGOU4aU/z37zf/tOujFk7c=
github.com/leanovate/gopter v0.2.9/go.mod h1:U2L/78B+KVFIx2VmW6onHJQzXtFb+p5y3y2Sh+Jxxv8=
github.com/ledgerwatch/erigon-lib v0.0.0-20221210085350-2f641bdeb4fe h1:bCQEQpM07ludipLTi/CTdQVGFqIrWvgQ1//Ndpx0TIY=
github.com/ledgerwatch/erigon-lib v0.0.0-20221210085350-2f641bdeb4fe/go.mod h1:cckLLWh0v0OHNSjeq6bpzdvEjZ1HMLKavLBF19tpqeg=
github.com/ledgerwatch/erigon-lib v0.0.0-20221211145319-874c497dda90 h1:ZsCnxEiUWDgp9ed/TeAnF15nVha4TRiL/1RGRecgs/c=
github.com/ledgerwatch/erigon-lib v0.0.0-20221211145319-874c497dda90/go.mod h1:Cy/yMqN6ufAXayVYLEIKnRoYz25PK9Uxmp1yil+wA/A=
github.com/ledgerwatch/erigon-snapshot v1.1.1-0.20221117232719-cf68648bf146 h1:BBoJuTSC1Z41wvz26l+HBJCXEBrPh3LXjkJd4CT6n1E=
github.com/ledgerwatch/erigon-snapshot v1.1.1-0.20221117232719-cf68648bf146/go.mod h1:3AuPxZc85jkehh/HA9h8gabv5MSi3kb/ddtzBsTVJFo=
github.com/ledgerwatch/log/v3 v3.6.0 h1:JBUSK1epPyutUrz7KYDTcJtQLEHnehECRpKbM1ugy5M=
Expand Down