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

Always penalize useless peers #6710

Merged
merged 4 commits into from
Jan 26, 2023
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
2 changes: 1 addition & 1 deletion cmd/sentry/sentry/sentry_api.go
Original file line number Diff line number Diff line change
Expand Up @@ -110,7 +110,7 @@ func (cs *MultiClient) SendHeaderRequest(ctx context.Context, req *headerdownloa
minBlock := req.Number

var maxPeers uint64
if cs.passivePeers {
if cs.sendHeaderRequestsToMultiplePeers {
maxPeers = 5
} else {
maxPeers = 1
Expand Down
2 changes: 1 addition & 1 deletion cmd/sentry/sentry/sentry_grpc_server.go
Original file line number Diff line number Diff line change
Expand Up @@ -739,7 +739,7 @@ func (ss *GrpcServer) PeerMinBlock(_ context.Context, req *proto_sentry.PeerMinB
func (ss *GrpcServer) PeerUseless(_ context.Context, req *proto_sentry.PeerUselessRequest) (*emptypb.Empty, error) {
peerID := ConvertH512ToPeerID(req.PeerId)
peerInfo := ss.getPeer(peerID)
if ss.statusData != nil && !ss.statusData.PassivePeers && peerInfo != nil && !peerInfo.peer.Info().Network.Static && !peerInfo.peer.Info().Network.Trusted {
if ss.statusData != nil && peerInfo != nil && !peerInfo.peer.Info().Network.Static && !peerInfo.peer.Info().Network.Trusted {
ss.removePeer(peerID)
log.Debug("Removed useless peer", "peerId", fmt.Sprintf("%x", peerID)[:8], "name", peerInfo.peer.Name())
}
Expand Down
65 changes: 32 additions & 33 deletions cmd/sentry/sentry/sentry_multi_client.go
Original file line number Diff line number Diff line change
Expand Up @@ -244,27 +244,27 @@ func pumpStreamLoop[TMessage interface{}](
// MultiClient - does handle request/response/subscriptions to multiple sentries
// each sentry may support same or different p2p protocol
type MultiClient struct {
lock sync.RWMutex
Hd *headerdownload.HeaderDownload
Bd *bodydownload.BodyDownload
IsMock bool
forkValidator *engineapi.ForkValidator
nodeName string
sentries []direct.SentryClient
headHeight uint64
headTime uint64
headHash libcommon.Hash
headTd *uint256.Int
ChainConfig *chain.Config
heightForks []uint64
timeForks []uint64
genesisHash libcommon.Hash
networkId uint64
db kv.RwDB
Engine consensus.Engine
blockReader services.HeaderAndCanonicalReader
logPeerInfo bool
passivePeers bool
lock sync.RWMutex
Hd *headerdownload.HeaderDownload
Bd *bodydownload.BodyDownload
IsMock bool
forkValidator *engineapi.ForkValidator
nodeName string
sentries []direct.SentryClient
headHeight uint64
headTime uint64
headHash libcommon.Hash
headTd *uint256.Int
ChainConfig *chain.Config
heightForks []uint64
timeForks []uint64
genesisHash libcommon.Hash
networkId uint64
db kv.RwDB
Engine consensus.Engine
blockReader services.HeaderAndCanonicalReader
logPeerInfo bool
sendHeaderRequestsToMultiplePeers bool

historyV3 bool
}
Expand Down Expand Up @@ -300,17 +300,17 @@ func NewMultiClient(
bd := bodydownload.NewBodyDownload(engine, int(syncCfg.BodyCacheLimit))

cs := &MultiClient{
nodeName: nodeName,
Hd: hd,
Bd: bd,
sentries: sentries,
db: db,
Engine: engine,
blockReader: blockReader,
logPeerInfo: logPeerInfo,
forkValidator: forkValidator,
historyV3: historyV3,
passivePeers: chainConfig.TerminalTotalDifficultyPassed,
nodeName: nodeName,
Hd: hd,
Bd: bd,
sentries: sentries,
db: db,
Engine: engine,
blockReader: blockReader,
logPeerInfo: logPeerInfo,
forkValidator: forkValidator,
historyV3: historyV3,
sendHeaderRequestsToMultiplePeers: chainConfig.TerminalTotalDifficultyPassed,
}
cs.ChainConfig = chainConfig
cs.heightForks, cs.timeForks = forkid.GatherForks(cs.ChainConfig)
Expand Down Expand Up @@ -792,7 +792,6 @@ func (cs *MultiClient) makeStatusData() *proto_sentry.StatusData {
HeightForks: s.heightForks,
TimeForks: s.timeForks,
},
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-20230126105350-8663a835adeb
github.com/ledgerwatch/erigon-lib v0.0.0-20230126112554-7c1f7af5cac5
github.com/ledgerwatch/erigon-snapshot v1.1.1-0.20230120022649-cd9409a200da
github.com/ledgerwatch/log/v3 v3.7.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 @@ -555,8 +555,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-20230126105350-8663a835adeb h1:OrxgQZrIEEa/hFD6nQpaO2FjnE63zuop4bzeqm7frFA=
github.com/ledgerwatch/erigon-lib v0.0.0-20230126105350-8663a835adeb/go.mod h1:dv/j9yNeEs4+HYq/x6/g2DVUGKBsRuB3yeVsWuuFH1U=
github.com/ledgerwatch/erigon-lib v0.0.0-20230126112554-7c1f7af5cac5 h1:gjHEHoudBZiI3XnN6dUqA1qinJs/nrXUCHqHtEYJ39o=
github.com/ledgerwatch/erigon-lib v0.0.0-20230126112554-7c1f7af5cac5/go.mod h1:NDe2LVxaewSK8PNTC9GshWNz03No8whA/W69cVTWCKM=
github.com/ledgerwatch/erigon-snapshot v1.1.1-0.20230120022649-cd9409a200da h1:lQQBOHzAUThkymfXJj/m07vAjyMx9XoMMy3OomaeOrA=
github.com/ledgerwatch/erigon-snapshot v1.1.1-0.20230120022649-cd9409a200da/go.mod h1:3AuPxZc85jkehh/HA9h8gabv5MSi3kb/ddtzBsTVJFo=
github.com/ledgerwatch/log/v3 v3.7.0 h1:aFPEZdwZx4jzA3+/Pf8wNDN5tCI0cIolq/kfvgcM+og=
Expand Down