Skip to content

Commit

Permalink
Switch client version to a proto type from a string (#2188)
Browse files Browse the repository at this point in the history
Signed-off-by: Joshua Kim <[email protected]>
Co-authored-by: Stephen Buttolph <[email protected]>
  • Loading branch information
joshua-kim and StephenButtolph authored Dec 12, 2023
1 parent dd3759a commit de89d1e
Show file tree
Hide file tree
Showing 16 changed files with 905 additions and 665 deletions.
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,23 @@ func (p *peer) writeMessages() {
return
}

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

msg, err := p.MessageCreator.Version(
p.NetworkID,
p.Clock.Unix(),
mySignedIP.IPPort,
p.VersionCompatibility.Version().String(),
legacyApplication.String(),
myVersion.Name,
uint32(myVersion.Major),
uint32(myVersion.Minor),
uint32(myVersion.Patch),
mySignedIP.Timestamp,
mySignedIP.Signature,
p.MySubnets.List(),
Expand Down Expand Up @@ -870,35 +882,45 @@ 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
peerVersion, err := version.ParseLegacyApplication(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

0 comments on commit de89d1e

Please sign in to comment.