Skip to content

Commit

Permalink
[network/peer] Disconnect from peers who only send legacy version fie…
Browse files Browse the repository at this point in the history
…ld (#2830)

Co-authored-by: Stephen Buttolph <[email protected]>
  • Loading branch information
dhrubabasu and StephenButtolph authored Mar 8, 2024
1 parent 4be015b commit b8cd687
Show file tree
Hide file tree
Showing 13 changed files with 272 additions and 405 deletions.
2 changes: 0 additions & 2 deletions message/messages_benchmark_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,6 @@ func BenchmarkMarshalHandshake(b *testing.B) {
MyTime: uint64(time.Now().Unix()),
IpAddr: []byte(net.IPv4(1, 2, 3, 4).To16()),
IpPort: 0,
MyVersion: "v1.2.3",
IpSigningTime: uint64(time.Now().Unix()),
IpNodeIdSig: []byte{'y', 'e', 'e', 't'},
TrackedSubnets: [][]byte{id[:]},
Expand Down Expand Up @@ -108,7 +107,6 @@ func BenchmarkUnmarshalHandshake(b *testing.B) {
MyTime: uint64(time.Now().Unix()),
IpAddr: []byte(net.IPv4(1, 2, 3, 4).To16()),
IpPort: 0,
MyVersion: "v1.2.3",
IpSigningTime: uint64(time.Now().Unix()),
IpNodeIdSig: []byte{'y', 'e', 'e', 't'},
TrackedSubnets: [][]byte{id[:]},
Expand Down
1 change: 0 additions & 1 deletion message/messages_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -129,7 +129,6 @@ func TestMessage(t *testing.T) {
MyTime: uint64(nowUnix),
IpAddr: []byte(net.IPv6zero),
IpPort: 9651,
MyVersion: "v1.2.3",
IpSigningTime: uint64(nowUnix),
IpNodeIdSig: []byte{'y', 'e', 'e', 't'},
TrackedSubnets: [][]byte{testID[:]},
Expand Down
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.

3 changes: 0 additions & 3 deletions message/outbound_msg_builder.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,6 @@ type OutboundMsgBuilder interface {
networkID uint32,
myTime uint64,
ip ips.IPPort,
myVersion string,
client string,
major uint32,
minor uint32,
Expand Down Expand Up @@ -245,7 +244,6 @@ func (b *outMsgBuilder) Handshake(
networkID uint32,
myTime uint64,
ip ips.IPPort,
myVersion string,
client string,
major uint32,
minor uint32,
Expand All @@ -269,7 +267,6 @@ func (b *outMsgBuilder) Handshake(
MyTime: myTime,
IpAddr: ip.IP.To16(),
IpPort: uint32(ip.Port),
MyVersion: myVersion,
IpSigningTime: ipSigningTime,
IpNodeIdSig: ipNodeIDSig,
TrackedSubnets: subnetIDBytes,
Expand Down
32 changes: 5 additions & 27 deletions network/peer/peer.go
Original file line number Diff line number Diff line change
Expand Up @@ -523,20 +523,12 @@ func (p *peer) writeMessages() {
}

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

knownPeersFilter, knownPeersSalt := p.Network.KnownPeers()

msg, err := p.MessageCreator.Handshake(
p.NetworkID,
p.Clock.Unix(),
mySignedIP.IPPort,
legacyApplication.String(),
myVersion.Name,
uint32(myVersion.Major),
uint32(myVersion.Minor),
Expand Down Expand Up @@ -946,25 +938,11 @@ func (p *peer) handleHandshake(msg *p2p.Handshake) {
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 = &version.Application{
Name: msg.Client.GetName(),
Major: int(msg.Client.GetMajor()),
Minor: int(msg.Client.GetMinor()),
Patch: int(msg.Client.GetPatch()),
}

if p.VersionCompatibility.Version().Before(p.version) {
Expand Down
7 changes: 1 addition & 6 deletions proto/p2p/p2p.proto
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@ option go_package = "github.com/ava-labs/avalanchego/proto/pb/p2p";
// Represents peer-to-peer messages.
// Only one type can be non-null.
message Message {
reserved 33; // Until after durango activation.
reserved 36; // Next unused field number.
// NOTES
// Use "oneof" for each message type and set rest to null if not used.
Expand Down Expand Up @@ -100,6 +99,7 @@ message Pong {
//
// Peers should drop connections to peers with incompatible versions.
message Handshake {
reserved 5; // Until E upgrade is activated.
// Network the peer is running on (e.g local, testnet, mainnet)
uint32 network_id = 1;
// Unix timestamp when this Handshake message was created
Expand All @@ -108,8 +108,6 @@ message Handshake {
bytes ip_addr = 3;
// IP port of the peer
uint32 ip_port = 4;
// Avalanche client version
string my_version = 5;
// Timestamp of the IP
uint64 ip_signing_time = 6;
// Signature of the peer IP port pair at a provided timestamp with the TLS
Expand Down Expand Up @@ -251,7 +249,6 @@ message GetAcceptedFrontier {
//
// AcceptedFrontier is sent in response to GetAcceptedFrontier.
message AcceptedFrontier {
reserved 4; // Until Cortina upgrade is activated
// Chain being responded from
bytes chain_id = 1;
// Request id of the original GetAcceptedFrontier request
Expand Down Expand Up @@ -281,7 +278,6 @@ message GetAccepted {
// a subset of container ids from the GetAccepted request that the sending peer
// has accepted.
message Accepted {
reserved 4; // Until Cortina upgrade is activated
// Chain being responded from
bytes chain_id = 1;
// Request id of the original GetAccepted request
Expand Down Expand Up @@ -312,7 +308,6 @@ message GetAncestors {
// Ancestors contains a contiguous ancestry of containers for the requested
// container in order of increasing block height.
message Ancestors {
reserved 4; // Until Cortina upgrade is activated
// Chain being responded from
bytes chain_id = 1;
// Request id of the original GetAncestors request
Expand Down
Loading

0 comments on commit b8cd687

Please sign in to comment.