Skip to content

Commit b8cd687

Browse files
[network/peer] Disconnect from peers who only send legacy version field (#2830)
Co-authored-by: Stephen Buttolph <stephen@avalabs.org>
1 parent 4be015b commit b8cd687

13 files changed

+272
-405
lines changed

message/messages_benchmark_test.go

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,6 @@ func BenchmarkMarshalHandshake(b *testing.B) {
5151
MyTime: uint64(time.Now().Unix()),
5252
IpAddr: []byte(net.IPv4(1, 2, 3, 4).To16()),
5353
IpPort: 0,
54-
MyVersion: "v1.2.3",
5554
IpSigningTime: uint64(time.Now().Unix()),
5655
IpNodeIdSig: []byte{'y', 'e', 'e', 't'},
5756
TrackedSubnets: [][]byte{id[:]},
@@ -108,7 +107,6 @@ func BenchmarkUnmarshalHandshake(b *testing.B) {
108107
MyTime: uint64(time.Now().Unix()),
109108
IpAddr: []byte(net.IPv4(1, 2, 3, 4).To16()),
110109
IpPort: 0,
111-
MyVersion: "v1.2.3",
112110
IpSigningTime: uint64(time.Now().Unix()),
113111
IpNodeIdSig: []byte{'y', 'e', 'e', 't'},
114112
TrackedSubnets: [][]byte{id[:]},

message/messages_test.go

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -129,7 +129,6 @@ func TestMessage(t *testing.T) {
129129
MyTime: uint64(nowUnix),
130130
IpAddr: []byte(net.IPv6zero),
131131
IpPort: 9651,
132-
MyVersion: "v1.2.3",
133132
IpSigningTime: uint64(nowUnix),
134133
IpNodeIdSig: []byte{'y', 'e', 'e', 't'},
135134
TrackedSubnets: [][]byte{testID[:]},

message/mock_outbound_message_builder.go

Lines changed: 4 additions & 4 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

message/outbound_msg_builder.go

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,6 @@ type OutboundMsgBuilder interface {
2222
networkID uint32,
2323
myTime uint64,
2424
ip ips.IPPort,
25-
myVersion string,
2625
client string,
2726
major uint32,
2827
minor uint32,
@@ -245,7 +244,6 @@ func (b *outMsgBuilder) Handshake(
245244
networkID uint32,
246245
myTime uint64,
247246
ip ips.IPPort,
248-
myVersion string,
249247
client string,
250248
major uint32,
251249
minor uint32,
@@ -269,7 +267,6 @@ func (b *outMsgBuilder) Handshake(
269267
MyTime: myTime,
270268
IpAddr: ip.IP.To16(),
271269
IpPort: uint32(ip.Port),
272-
MyVersion: myVersion,
273270
IpSigningTime: ipSigningTime,
274271
IpNodeIdSig: ipNodeIDSig,
275272
TrackedSubnets: subnetIDBytes,

network/peer/peer.go

Lines changed: 5 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -523,20 +523,12 @@ func (p *peer) writeMessages() {
523523
}
524524

525525
myVersion := p.VersionCompatibility.Version()
526-
legacyApplication := &version.Application{
527-
Name: version.LegacyAppName,
528-
Major: myVersion.Major,
529-
Minor: myVersion.Minor,
530-
Patch: myVersion.Patch,
531-
}
532-
533526
knownPeersFilter, knownPeersSalt := p.Network.KnownPeers()
534527

535528
msg, err := p.MessageCreator.Handshake(
536529
p.NetworkID,
537530
p.Clock.Unix(),
538531
mySignedIP.IPPort,
539-
legacyApplication.String(),
540532
myVersion.Name,
541533
uint32(myVersion.Major),
542534
uint32(myVersion.Minor),
@@ -946,25 +938,11 @@ func (p *peer) handleHandshake(msg *p2p.Handshake) {
946938
return
947939
}
948940

949-
if msg.Client != nil {
950-
p.version = &version.Application{
951-
Name: msg.Client.Name,
952-
Major: int(msg.Client.Major),
953-
Minor: int(msg.Client.Minor),
954-
Patch: int(msg.Client.Patch),
955-
}
956-
} else {
957-
// Handle legacy version field
958-
peerVersion, err := version.ParseLegacyApplication(msg.MyVersion)
959-
if err != nil {
960-
p.Log.Debug("failed to parse peer version",
961-
zap.Stringer("nodeID", p.id),
962-
zap.Error(err),
963-
)
964-
p.StartClose()
965-
return
966-
}
967-
p.version = peerVersion
941+
p.version = &version.Application{
942+
Name: msg.Client.GetName(),
943+
Major: int(msg.Client.GetMajor()),
944+
Minor: int(msg.Client.GetMinor()),
945+
Patch: int(msg.Client.GetPatch()),
968946
}
969947

970948
if p.VersionCompatibility.Version().Before(p.version) {

proto/p2p/p2p.proto

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,6 @@ option go_package = "github.com/ava-labs/avalanchego/proto/pb/p2p";
88
// Represents peer-to-peer messages.
99
// Only one type can be non-null.
1010
message Message {
11-
reserved 33; // Until after durango activation.
1211
reserved 36; // Next unused field number.
1312
// NOTES
1413
// Use "oneof" for each message type and set rest to null if not used.
@@ -100,6 +99,7 @@ message Pong {
10099
//
101100
// Peers should drop connections to peers with incompatible versions.
102101
message Handshake {
102+
reserved 5; // Until E upgrade is activated.
103103
// Network the peer is running on (e.g local, testnet, mainnet)
104104
uint32 network_id = 1;
105105
// Unix timestamp when this Handshake message was created
@@ -108,8 +108,6 @@ message Handshake {
108108
bytes ip_addr = 3;
109109
// IP port of the peer
110110
uint32 ip_port = 4;
111-
// Avalanche client version
112-
string my_version = 5;
113111
// Timestamp of the IP
114112
uint64 ip_signing_time = 6;
115113
// Signature of the peer IP port pair at a provided timestamp with the TLS
@@ -251,7 +249,6 @@ message GetAcceptedFrontier {
251249
//
252250
// AcceptedFrontier is sent in response to GetAcceptedFrontier.
253251
message AcceptedFrontier {
254-
reserved 4; // Until Cortina upgrade is activated
255252
// Chain being responded from
256253
bytes chain_id = 1;
257254
// Request id of the original GetAcceptedFrontier request
@@ -281,7 +278,6 @@ message GetAccepted {
281278
// a subset of container ids from the GetAccepted request that the sending peer
282279
// has accepted.
283280
message Accepted {
284-
reserved 4; // Until Cortina upgrade is activated
285281
// Chain being responded from
286282
bytes chain_id = 1;
287283
// Request id of the original GetAccepted request
@@ -312,7 +308,6 @@ message GetAncestors {
312308
// Ancestors contains a contiguous ancestry of containers for the requested
313309
// container in order of increasing block height.
314310
message Ancestors {
315-
reserved 4; // Until Cortina upgrade is activated
316311
// Chain being responded from
317312
bytes chain_id = 1;
318313
// Request id of the original GetAncestors request

0 commit comments

Comments
 (0)