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

Switch client version to a proto type from a string #2188

Merged
merged 21 commits into from
Dec 12, 2023
Merged
8 changes: 4 additions & 4 deletions message/mock_outbound_message_builder.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

14 changes: 14 additions & 0 deletions message/outbound_msg_builder.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,10 @@ type OutboundMsgBuilder interface {
myTime uint64,
ip ips.IPPort,
myVersion string,
client string,
major uint32,
minor uint32,
patch uint32,
myVersionTime uint64,
sig []byte,
trackedSubnets []ids.ID,
Expand Down Expand Up @@ -229,6 +233,10 @@ func (b *outMsgBuilder) Version(
myTime uint64,
ip ips.IPPort,
myVersion string,
client string,
major uint32,
minor uint32,
patch uint32,
myVersionTime uint64,
sig []byte,
trackedSubnets []ids.ID,
Expand All @@ -247,6 +255,12 @@ func (b *outMsgBuilder) Version(
MyVersionTime: myVersionTime,
Sig: sig,
TrackedSubnets: subnetIDBytes,
Client: &p2p.Client{
Name: client,
Major: major,
Minor: minor,
Patch: patch,
},
},
},
},
Expand Down
43 changes: 29 additions & 14 deletions network/peer/peer.go
Original file line number Diff line number Diff line change
Expand Up @@ -502,6 +502,10 @@ func (p *peer) writeMessages() {
p.Clock.Unix(),
mySignedIP.IPPort,
p.VersionCompatibility.Version().String(),
p.VersionCompatibility.Version().Name,
uint32(p.VersionCompatibility.Version().Major),
uint32(p.VersionCompatibility.Version().Minor),
uint32(p.VersionCompatibility.Version().Patch),
mySignedIP.Timestamp,
mySignedIP.Signature,
p.MySubnets.List(),
Expand Down Expand Up @@ -870,35 +874,46 @@ func (p *peer) handleVersion(msg *p2p.Version) {
return
}

peerVersion, err := version.ParseApplication(msg.MyVersion)
if err != nil {
p.Log.Debug("failed to parse peer version",
zap.Stringer("nodeID", p.id),
zap.Error(err),
)
p.StartClose()
return
if msg.Client != nil {
p.version = &version.Application{
Name: msg.Client.Name,
Major: int(msg.Client.Major),
Minor: int(msg.Client.Minor),
Patch: int(msg.Client.Patch),
}
} else {
// Handle legacy version field
// TODO deprecate after D upgrade
peerVersion, err := version.ParseApplication(msg.MyVersion)
if err != nil {
p.Log.Debug("failed to parse peer version",
zap.Stringer("nodeID", p.id),
zap.Error(err),
)
p.StartClose()
return
}
p.version = peerVersion
}
p.version = peerVersion

if p.VersionCompatibility.Version().Before(peerVersion) {
if p.VersionCompatibility.Version().Before(p.version) {
if p.Beacons.Contains(p.id) {
p.Log.Info("beacon attempting to connect with newer version. You may want to update your client",
zap.Stringer("nodeID", p.id),
zap.Stringer("beaconVersion", peerVersion),
zap.Stringer("beaconVersion", p.version),
)
} else {
p.Log.Debug("peer attempting to connect with newer version. You may want to update your client",
zap.Stringer("nodeID", p.id),
zap.Stringer("peerVersion", peerVersion),
zap.Stringer("peerVersion", p.version),
)
}
}

if err := p.VersionCompatibility.Compatible(peerVersion); err != nil {
if err := p.VersionCompatibility.Compatible(p.version); err != nil {
p.Log.Verbo("peer version not compatible",
zap.Stringer("nodeID", p.id),
zap.Stringer("peerVersion", peerVersion),
zap.Stringer("peerVersion", p.version),
zap.Error(err),
)
p.StartClose()
Expand Down
11 changes: 11 additions & 0 deletions proto/p2p/p2p.proto
Original file line number Diff line number Diff line change
Expand Up @@ -106,6 +106,17 @@ message Version {
uint64 my_version_time = 6;
bytes sig = 7;
repeated bytes tracked_subnets = 8;
Client client = 9;
}

// Metadata about a peer's P2P client used to determine compatibility
message Client {
// Client name (e.g avalanchego)
string name = 1;
// Client semantic version
uint32 major = 2;
uint32 minor = 3;
uint32 patch = 4;
}

// ref. https://pkg.go.dev/github.com/ava-labs/avalanchego/utils/ips#ClaimedIPPort
Expand Down