Skip to content

Commit

Permalink
chore: fix missing nodeInfo.Channels initialization
Browse files Browse the repository at this point in the history
  • Loading branch information
lklimek committed Feb 7, 2024
1 parent 0e1e267 commit 64038d3
Show file tree
Hide file tree
Showing 5 changed files with 18 additions and 6 deletions.
6 changes: 3 additions & 3 deletions internal/libs/sync/concurrent_slice_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,12 +22,12 @@ func TestConcurrentSlice(t *testing.T) {
}

// Test Set
s.Set(3, 5)
s.Set(1, 5)

// Test ToSlice
slice := s.ToSlice()
if len(slice) != 4 || slice[3] != 4 {
t.Errorf("Expected ToSlice to return [1 2 3 4], got %v", slice)
if len(slice) != 4 || slice[3] != 4 || slice[1] != 5 {
t.Errorf("Expected ToSlice to return [1 5 3 4], got %v", slice)
}

// Test Reset
Expand Down
2 changes: 2 additions & 0 deletions internal/p2p/p2ptest/network.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ import (
"github.com/dashpay/tenderdash/config"
"github.com/dashpay/tenderdash/crypto"
"github.com/dashpay/tenderdash/crypto/ed25519"
tmsync "github.com/dashpay/tenderdash/internal/libs/sync"
"github.com/dashpay/tenderdash/internal/p2p"
p2pclient "github.com/dashpay/tenderdash/internal/p2p/client"
"github.com/dashpay/tenderdash/libs/log"
Expand Down Expand Up @@ -272,6 +273,7 @@ func (n *Network) MakeNode(ctx context.Context, t *testing.T, proTxHash crypto.P
ListenAddr: "0.0.0.0:0", // FIXME: We have to fake this for now.
Moniker: string(nodeID),
ProTxHash: proTxHash.Copy(),
Channels: tmsync.NewConcurrentSlice[uint16](),
}

transport := n.memoryNetwork.CreateTransport(nodeID)
Expand Down
2 changes: 2 additions & 0 deletions internal/p2p/router_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -304,6 +304,7 @@ func TestRouter_AcceptPeers(t *testing.T) {
ListenAddr: "0.0.0.0:0",
Network: "other-network",
Moniker: string(peerID),
Channels: tmsync.NewConcurrentSlice[uint16](),
},
peerKey.PubKey(),
false,
Expand Down Expand Up @@ -505,6 +506,7 @@ func TestRouter_DialPeers(t *testing.T) {
ListenAddr: "0.0.0.0:0",
Network: "other-network",
Moniker: string(peerID),
Channels: tmsync.NewConcurrentSlice[uint16](),
},
peerKey.PubKey(),
nil,
Expand Down
9 changes: 6 additions & 3 deletions internal/p2p/transport_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -291,7 +291,10 @@ func TestConnection_Handshake(t *testing.T) {
},
}
bKey := ed25519.GenPrivKey()
bInfo := types.NodeInfo{NodeID: types.NodeIDFromPubKey(bKey.PubKey())}
bInfo := types.NodeInfo{
NodeID: types.NodeIDFromPubKey(bKey.PubKey()),
Channels: tmsync.NewConcurrentSlice[uint16](),
}

errCh := make(chan error, 1)
go func() {
Expand Down Expand Up @@ -641,13 +644,13 @@ func dialAcceptHandshake(ctx context.Context, t *testing.T, a, b p2p.Transport)
errCh := make(chan error, 1)
go func() {
privKey := ed25519.GenPrivKey()
nodeInfo := types.NodeInfo{NodeID: types.NodeIDFromPubKey(privKey.PubKey())}
nodeInfo := types.NodeInfo{NodeID: types.NodeIDFromPubKey(privKey.PubKey()), Channels: tmsync.NewConcurrentSlice[uint16]()}
_, _, err := ba.Handshake(ctx, 0, nodeInfo, privKey)
errCh <- err
}()

privKey := ed25519.GenPrivKey()
nodeInfo := types.NodeInfo{NodeID: types.NodeIDFromPubKey(privKey.PubKey())}
nodeInfo := types.NodeInfo{NodeID: types.NodeIDFromPubKey(privKey.PubKey()), Channels: tmsync.NewConcurrentSlice[uint16]()}
_, _, err := ab.Handshake(ctx, 0, nodeInfo, privKey)
require.NoError(t, err)

Expand Down
5 changes: 5 additions & 0 deletions types/node_info.go
Original file line number Diff line number Diff line change
Expand Up @@ -97,6 +97,10 @@ func (info NodeInfo) Validate() error {
}

// Validate Channels - ensure max and check for duplicates.
if info.Channels == nil {
return fmt.Errorf("info.Channels is nil")
}

if info.Channels.Len() > maxNumChannels {
return fmt.Errorf("info.Channels is too long (%v). Max is %v", info.Channels.Len(), maxNumChannels)
}
Expand Down Expand Up @@ -235,6 +239,7 @@ func NodeInfoFromProto(pb *tmp2p.NodeInfo) (NodeInfo, error) {
ListenAddr: pb.ListenAddr,
Network: pb.Network,
Version: pb.Version,
Channels: tmsync.NewConcurrentSlice[uint16](),
Moniker: pb.Moniker,
Other: NodeInfoOther{
TxIndex: pb.Other.TxIndex,
Expand Down

0 comments on commit 64038d3

Please sign in to comment.