Files
zeekayandHanzo Dev 37e2940ead mesh is the peer layer, network is the validator set
Two packages were named for the same word and meant different things. network/
dialed peers, exchanged keys, throttled and tracked them; nets/ tracked which
chains share a validator set and when they have all bootstrapped. One letter
apart, and neither name said which was which.

The peer layer is mesh — the word this estate already uses for it, in
lux-rs/node's own mesh.rs. That frees network for the thing that is actually a
network: a set of chains sharing a validator set. A network holds chains; a
chain belongs to one network.

github.com/luxfi/p2p stays what it is, the gossip library the VMs use. Three
concerns, three names, none of them borrowed from another.

Co-authored-by: Hanzo Dev <[email protected]>
2026-09-07 21:17:09 -07:00

109 lines
2.4 KiB
Go

// Copyright (C) 2019-2025, Lux Industries Inc. All rights reserved.
// See the file LICENSE for licensing terms.
package peer
import (
"crypto"
"net/netip"
"testing"
"time"
"github.com/stretchr/testify/require"
"github.com/luxfi/crypto/bls"
"github.com/luxfi/crypto/bls/signer/localsigner"
"github.com/luxfi/node/staking"
)
func TestSignedIpVerify(t *testing.T) {
tlsCert1, err := staking.NewTLSCert()
require.NoError(t, err)
cert1, err := staking.ParseCertificate(tlsCert1.Leaf.Raw)
require.NoError(t, err)
tlsKey1 := tlsCert1.PrivateKey.(crypto.Signer)
blsKey1, err := localsigner.New()
require.NoError(t, err)
tlsCert2, err := staking.NewTLSCert()
require.NoError(t, err)
cert2, err := staking.ParseCertificate(tlsCert2.Leaf.Raw)
require.NoError(t, err)
now := time.Now()
addrPort := netip.AddrPortFrom(
netip.AddrFrom4([4]byte{1, 2, 3, 4}),
1,
)
type test struct {
name string
tlsSigner crypto.Signer
blsSigner bls.Signer
expectedCert *staking.Certificate
ip UnsignedIP
maxTimestamp time.Time
expectedErr error
}
tests := []test{
{
name: "valid (before max time)",
tlsSigner: tlsKey1,
blsSigner: blsKey1,
expectedCert: cert1,
ip: UnsignedIP{
AddrPort: addrPort,
Timestamp: uint64(now.Unix()) - 1,
},
maxTimestamp: now,
expectedErr: nil,
},
{
name: "valid (at max time)",
tlsSigner: tlsKey1,
blsSigner: blsKey1,
expectedCert: cert1,
ip: UnsignedIP{
AddrPort: addrPort,
Timestamp: uint64(now.Unix()),
},
maxTimestamp: now,
expectedErr: nil,
},
{
name: "timestamp too far ahead",
tlsSigner: tlsKey1,
blsSigner: blsKey1,
expectedCert: cert1,
ip: UnsignedIP{
AddrPort: addrPort,
Timestamp: uint64(now.Unix()) + 1,
},
maxTimestamp: now,
expectedErr: errTimestampTooFarInFuture,
},
{
name: "sig from wrong cert",
tlsSigner: tlsKey1,
blsSigner: blsKey1,
expectedCert: cert2, // note this isn't cert1
ip: UnsignedIP{
Timestamp: uint64(now.Unix()),
},
maxTimestamp: now,
expectedErr: errInvalidTLSSignature,
},
}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
signedIP, err := tt.ip.Sign(tt.tlsSigner, tt.blsSigner)
require.NoError(t, err)
err = signedIP.Verify(tt.expectedCert, tt.maxTimestamp)
require.ErrorIs(t, err, tt.expectedErr)
})
}
}