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
Show file tree
Hide file tree
Changes from 19 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
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
52 changes: 37 additions & 15 deletions network/peer/peer.go
Original file line number Diff line number Diff line change
Expand Up @@ -497,11 +497,22 @@ func (p *peer) writeMessages() {
return
}

legacyApplication := &version.Application{
Name: version.LegacyAppName,
Major: p.VersionCompatibility.Version().Major,
Minor: p.VersionCompatibility.Version().Minor,
Patch: p.VersionCompatibility.Version().Patch,
}

msg, err := p.MessageCreator.Version(
p.NetworkID,
p.Clock.Unix(),
mySignedIP.IPPort,
p.VersionCompatibility.Version().String(),
legacyApplication.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 +881,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 _, ok := p.Beacons.GetValidator(constants.PrimaryNetworkID, p.id); ok {
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 @@ -115,6 +115,17 @@ message Version {
bytes sig = 7;
// Subnets the peer is tracking
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;
}

// ClaimedIpPort contains metadata needed to connect to a peer
Expand Down
Loading
Loading