Files
node/mesh/peer/ip_signer_test.go
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

62 lines
1.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/signer/localsigner"
"github.com/luxfi/node/staking"
"github.com/luxfi/util"
)
func TestIPSigner(t *testing.T) {
require := require.New(t)
dynIP := utils.NewAtomic(netip.AddrPortFrom(
netip.IPv6Loopback(),
0,
))
tlsCert, err := staking.NewTLSCert()
require.NoError(err)
tlsKey := tlsCert.PrivateKey.(crypto.Signer)
blsSigner, err := localsigner.New()
require.NoError(err)
s := NewIPSigner(dynIP, tlsKey, blsSigner)
s.clock.Set(time.Unix(10, 0))
signedIP1, err := s.GetSignedIP()
require.NoError(err)
require.Equal(dynIP.Get(), signedIP1.AddrPort)
require.Equal(uint64(10), signedIP1.Timestamp)
s.clock.Set(time.Unix(11, 0))
signedIP2, err := s.GetSignedIP()
require.NoError(err)
require.Equal(dynIP.Get(), signedIP2.AddrPort)
require.Equal(uint64(10), signedIP2.Timestamp)
require.Equal(signedIP1.TLSSignature, signedIP2.TLSSignature)
dynIP.Set(netip.AddrPortFrom(
netip.AddrFrom4([4]byte{1, 2, 3, 4}),
dynIP.Get().Port(),
))
signedIP3, err := s.GetSignedIP()
require.NoError(err)
require.Equal(dynIP.Get(), signedIP3.AddrPort)
require.Equal(uint64(11), signedIP3.Timestamp)
require.NotEqual(signedIP2.TLSSignature, signedIP3.TLSSignature)
}