[NOD-1012] Fix erroneous partial node check (#739)

* [NOD-1012] Fix bad partial node check.

* [NOD-1012] Fix unit tests.
This commit is contained in:
stasatdaglabs 2020-05-31 14:13:30 +03:00 committed by GitHub
parent a4c1898624
commit 3a22249be9
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 13 additions and 16 deletions

View File

@ -6,7 +6,6 @@ package peer_test
import (
"fmt"
"github.com/kaspanet/kaspad/util/subnetworkid"
"net"
"time"
@ -32,7 +31,7 @@ func mockRemotePeer() error {
UserAgentVersion: "1.0.0", // User agent version to advertise.
DAGParams: &dagconfig.SimnetParams,
SelectedTipHash: fakeSelectedTipFn,
SubnetworkID: subnetworkid.SubnetworkIDNative,
SubnetworkID: nil,
}
// Accept connections on the simnet port.
@ -92,7 +91,7 @@ func Example_newOutboundPeer() {
},
},
SelectedTipHash: fakeSelectedTipFn,
SubnetworkID: subnetworkid.SubnetworkIDNative,
SubnetworkID: nil,
}
p, err := peer.NewOutboundPeer(peerCfg, "127.0.0.1:18555")
if err != nil {

View File

@ -897,10 +897,9 @@ func (p *Peer) handleRemoteVersionMsg(msg *wire.MsgVersion) error {
return errors.New(reason)
}
// Disconnect from non-native/coinbase subnetworks in networks that don't allow them
if !p.cfg.DAGParams.EnableNonNativeSubnetworks &&
!msg.SubnetworkID.IsEqual(subnetworkid.SubnetworkIDNative) {
return errors.New("non-native subnetworks are not allowed")
// Disconnect from partial nodes in networks that don't allow them
if !p.cfg.DAGParams.EnableNonNativeSubnetworks && msg.SubnetworkID != nil {
return errors.New("partial nodes are not allowed")
}
// Disconnect if:

View File

@ -5,7 +5,6 @@
package peer
import (
"github.com/kaspanet/kaspad/util/subnetworkid"
"io"
"net"
"strconv"
@ -224,7 +223,7 @@ func TestPeerConnection(t *testing.T) {
ProtocolVersion: wire.ProtocolVersion, // Configure with older version
Services: 0,
SelectedTipHash: fakeSelectedTipFn,
SubnetworkID: subnetworkid.SubnetworkIDNative,
SubnetworkID: nil,
}
outPeerCfg := &Config{
Listeners: MessageListeners{
@ -245,7 +244,7 @@ func TestPeerConnection(t *testing.T) {
ProtocolVersion: wire.ProtocolVersion + 1,
Services: wire.SFNodeNetwork,
SelectedTipHash: fakeSelectedTipFn,
SubnetworkID: subnetworkid.SubnetworkIDNative,
SubnetworkID: nil,
}
wantStats1 := peerStats{
@ -259,8 +258,8 @@ func TestPeerConnection(t *testing.T) {
wantLastPingNonce: uint64(0),
wantLastPingMicros: int64(0),
wantTimeOffset: int64(0),
wantBytesSent: 215, // 191 version + 24 verack
wantBytesReceived: 215,
wantBytesSent: 195, // 171 version + 24 verack
wantBytesReceived: 195,
}
wantStats2 := peerStats{
wantUserAgent: wire.DefaultUserAgent + "peer:1.0(comment)/",
@ -273,8 +272,8 @@ func TestPeerConnection(t *testing.T) {
wantLastPingNonce: uint64(0),
wantLastPingMicros: int64(0),
wantTimeOffset: int64(0),
wantBytesSent: 215, // 191 version + 24 verack
wantBytesReceived: 215,
wantBytesSent: 195, // 171 version + 24 verack
wantBytesReceived: 195,
}
tests := []struct {
@ -404,7 +403,7 @@ func TestPeerListeners(t *testing.T) {
DAGParams: &dagconfig.MainnetParams,
Services: wire.SFNodeBloom,
SelectedTipHash: fakeSelectedTipFn,
SubnetworkID: subnetworkid.SubnetworkIDNative,
SubnetworkID: nil,
}
outPeerCfg := &Config{}
@ -521,7 +520,7 @@ func TestOutboundPeer(t *testing.T) {
UserAgentComments: []string{"comment"},
DAGParams: &dagconfig.MainnetParams,
Services: 0,
SubnetworkID: subnetworkid.SubnetworkIDNative,
SubnetworkID: nil,
}
_, p, err := setupPeers(peerCfg, peerCfg)