mirror of
https://github.com/OffchainLabs/prysm.git
synced 2026-02-02 00:55:16 -05:00
Compare commits
26 Commits
e2e-debugg
...
quicStream
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
501ad49f58 | ||
|
|
875c654f55 | ||
|
|
c3ccf8d536 | ||
|
|
649e2ea9fa | ||
|
|
f3b54dbdd3 | ||
|
|
5cd86812c7 | ||
|
|
6b7a7a1c10 | ||
|
|
4efb331924 | ||
|
|
46497793b9 | ||
|
|
1a0bd725fa | ||
|
|
ebbdc78b2b | ||
|
|
a1bb70e50a | ||
|
|
b95bdf87fd | ||
|
|
3102a79a5d | ||
|
|
37332e2e49 | ||
|
|
123b034d0b | ||
|
|
7f449660f0 | ||
|
|
a2d0702aa5 | ||
|
|
c9ccc1cb2c | ||
|
|
a9687a5f35 | ||
|
|
3996a5b5be | ||
|
|
e01decfc4f | ||
|
|
8ea340026b | ||
|
|
9e382c4ff4 | ||
|
|
54b2ee8435 | ||
|
|
da51fae94c |
@@ -707,6 +707,7 @@ func (b *BeaconNode) registerP2P(cliCtx *cli.Context) error {
|
|||||||
PrivateKey: cliCtx.String(cmd.P2PPrivKey.Name),
|
PrivateKey: cliCtx.String(cmd.P2PPrivKey.Name),
|
||||||
StaticPeerID: cliCtx.Bool(cmd.P2PStaticID.Name),
|
StaticPeerID: cliCtx.Bool(cmd.P2PStaticID.Name),
|
||||||
MetaDataDir: cliCtx.String(cmd.P2PMetadata.Name),
|
MetaDataDir: cliCtx.String(cmd.P2PMetadata.Name),
|
||||||
|
QUICPort: cliCtx.Uint(cmd.P2PQUICPort.Name),
|
||||||
TCPPort: cliCtx.Uint(cmd.P2PTCPPort.Name),
|
TCPPort: cliCtx.Uint(cmd.P2PTCPPort.Name),
|
||||||
UDPPort: cliCtx.Uint(cmd.P2PUDPPort.Name),
|
UDPPort: cliCtx.Uint(cmd.P2PUDPPort.Name),
|
||||||
MaxPeers: cliCtx.Uint(cmd.P2PMaxPeers.Name),
|
MaxPeers: cliCtx.Uint(cmd.P2PMaxPeers.Name),
|
||||||
|
|||||||
@@ -90,6 +90,7 @@ go_library(
|
|||||||
"@com_github_libp2p_go_libp2p//core/peerstore:go_default_library",
|
"@com_github_libp2p_go_libp2p//core/peerstore:go_default_library",
|
||||||
"@com_github_libp2p_go_libp2p//core/protocol:go_default_library",
|
"@com_github_libp2p_go_libp2p//core/protocol:go_default_library",
|
||||||
"@com_github_libp2p_go_libp2p//p2p/security/noise:go_default_library",
|
"@com_github_libp2p_go_libp2p//p2p/security/noise:go_default_library",
|
||||||
|
"@com_github_libp2p_go_libp2p//p2p/transport/quic:go_default_library",
|
||||||
"@com_github_libp2p_go_libp2p//p2p/transport/tcp:go_default_library",
|
"@com_github_libp2p_go_libp2p//p2p/transport/tcp:go_default_library",
|
||||||
"@com_github_libp2p_go_libp2p_mplex//:go_default_library",
|
"@com_github_libp2p_go_libp2p_mplex//:go_default_library",
|
||||||
"@com_github_libp2p_go_libp2p_pubsub//:go_default_library",
|
"@com_github_libp2p_go_libp2p_pubsub//:go_default_library",
|
||||||
|
|||||||
@@ -24,6 +24,7 @@ type Config struct {
|
|||||||
PrivateKey string
|
PrivateKey string
|
||||||
DataDir string
|
DataDir string
|
||||||
MetaDataDir string
|
MetaDataDir string
|
||||||
|
QUICPort uint
|
||||||
TCPPort uint
|
TCPPort uint
|
||||||
UDPPort uint
|
UDPPort uint
|
||||||
MaxPeers uint
|
MaxPeers uint
|
||||||
|
|||||||
@@ -39,6 +39,11 @@ const (
|
|||||||
udp6
|
udp6
|
||||||
)
|
)
|
||||||
|
|
||||||
|
type quicProtocol uint16
|
||||||
|
|
||||||
|
// quicProtocol is the "quic" key, which holds the QUIC port of the node.
|
||||||
|
func (quicProtocol) ENRKey() string { return "quic" }
|
||||||
|
|
||||||
// RefreshENR uses an epoch to refresh the enr entry for our node
|
// RefreshENR uses an epoch to refresh the enr entry for our node
|
||||||
// with the tracked committee ids for the epoch, allowing our node
|
// with the tracked committee ids for the epoch, allowing our node
|
||||||
// to be dynamically discoverable by others given our tracked committee ids.
|
// to be dynamically discoverable by others given our tracked committee ids.
|
||||||
@@ -100,14 +105,15 @@ func (s *Service) RefreshENR() {
|
|||||||
|
|
||||||
// listen for new nodes watches for new nodes in the network and adds them to the peerstore.
|
// listen for new nodes watches for new nodes in the network and adds them to the peerstore.
|
||||||
func (s *Service) listenForNewNodes() {
|
func (s *Service) listenForNewNodes() {
|
||||||
iterator := s.dv5Listener.RandomNodes()
|
iterator := enode.Filter(s.dv5Listener.RandomNodes(), s.filterPeer)
|
||||||
iterator = enode.Filter(iterator, s.filterPeer)
|
|
||||||
defer iterator.Close()
|
defer iterator.Close()
|
||||||
|
|
||||||
for {
|
for {
|
||||||
// Exit if service's context is canceled
|
// Exit if service's context is canceled.
|
||||||
if s.ctx.Err() != nil {
|
if s.ctx.Err() != nil {
|
||||||
break
|
break
|
||||||
}
|
}
|
||||||
|
|
||||||
if s.isPeerAtLimit(false /* inbound */) {
|
if s.isPeerAtLimit(false /* inbound */) {
|
||||||
// Pause the main loop for a period to stop looking
|
// Pause the main loop for a period to stop looking
|
||||||
// for new peers.
|
// for new peers.
|
||||||
@@ -115,16 +121,22 @@ func (s *Service) listenForNewNodes() {
|
|||||||
time.Sleep(pollingPeriod)
|
time.Sleep(pollingPeriod)
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
exists := iterator.Next()
|
|
||||||
if !exists {
|
if exists := iterator.Next(); !exists {
|
||||||
break
|
break
|
||||||
}
|
}
|
||||||
|
|
||||||
node := iterator.Node()
|
node := iterator.Node()
|
||||||
peerInfo, _, err := convertToAddrInfo(node)
|
peerInfo, _, err := convertToAddrInfo(node)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.WithError(err).Error("Could not convert to peer info")
|
log.WithError(err).Error("Could not convert to peer info")
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if peerInfo == nil {
|
||||||
|
continue
|
||||||
|
}
|
||||||
|
|
||||||
// Make sure that peer is not dialed too often, for each connection attempt there's a backoff period.
|
// Make sure that peer is not dialed too often, for each connection attempt there's a backoff period.
|
||||||
s.Peers().RandomizeBackOff(peerInfo.ID)
|
s.Peers().RandomizeBackOff(peerInfo.ID)
|
||||||
go func(info *peer.AddrInfo) {
|
go func(info *peer.AddrInfo) {
|
||||||
@@ -167,8 +179,7 @@ func (s *Service) createListener(
|
|||||||
|
|
||||||
// Listen to all network interfaces
|
// Listen to all network interfaces
|
||||||
// for both ip protocols.
|
// for both ip protocols.
|
||||||
networkVersion := "udp"
|
conn, err := net.ListenUDP("udp", udpAddr)
|
||||||
conn, err := net.ListenUDP(networkVersion, udpAddr)
|
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, errors.Wrap(err, "could not listen to UDP")
|
return nil, errors.Wrap(err, "could not listen to UDP")
|
||||||
}
|
}
|
||||||
@@ -178,6 +189,7 @@ func (s *Service) createListener(
|
|||||||
ipAddr,
|
ipAddr,
|
||||||
int(s.cfg.UDPPort),
|
int(s.cfg.UDPPort),
|
||||||
int(s.cfg.TCPPort),
|
int(s.cfg.TCPPort),
|
||||||
|
int(s.cfg.QUICPort),
|
||||||
)
|
)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, errors.Wrap(err, "could not create local node")
|
return nil, errors.Wrap(err, "could not create local node")
|
||||||
@@ -209,7 +221,7 @@ func (s *Service) createListener(
|
|||||||
func (s *Service) createLocalNode(
|
func (s *Service) createLocalNode(
|
||||||
privKey *ecdsa.PrivateKey,
|
privKey *ecdsa.PrivateKey,
|
||||||
ipAddr net.IP,
|
ipAddr net.IP,
|
||||||
udpPort, tcpPort int,
|
udpPort, tcpPort, quicPort int,
|
||||||
) (*enode.LocalNode, error) {
|
) (*enode.LocalNode, error) {
|
||||||
db, err := enode.OpenDB("")
|
db, err := enode.OpenDB("")
|
||||||
if err != nil {
|
if err != nil {
|
||||||
@@ -220,9 +232,13 @@ func (s *Service) createLocalNode(
|
|||||||
ipEntry := enr.IP(ipAddr)
|
ipEntry := enr.IP(ipAddr)
|
||||||
udpEntry := enr.UDP(udpPort)
|
udpEntry := enr.UDP(udpPort)
|
||||||
tcpEntry := enr.TCP(tcpPort)
|
tcpEntry := enr.TCP(tcpPort)
|
||||||
|
quicEntry := quicProtocol(quicPort)
|
||||||
|
|
||||||
localNode.Set(ipEntry)
|
localNode.Set(ipEntry)
|
||||||
localNode.Set(udpEntry)
|
localNode.Set(udpEntry)
|
||||||
localNode.Set(tcpEntry)
|
localNode.Set(tcpEntry)
|
||||||
|
localNode.Set(quicEntry)
|
||||||
|
|
||||||
localNode.SetFallbackIP(ipAddr)
|
localNode.SetFallbackIP(ipAddr)
|
||||||
localNode.SetFallbackUDP(udpPort)
|
localNode.SetFallbackUDP(udpPort)
|
||||||
|
|
||||||
@@ -277,7 +293,7 @@ func (s *Service) startDiscoveryV5(
|
|||||||
// filterPeer validates each node that we retrieve from our dht. We
|
// filterPeer validates each node that we retrieve from our dht. We
|
||||||
// try to ascertain that the peer can be a valid protocol peer.
|
// try to ascertain that the peer can be a valid protocol peer.
|
||||||
// Validity Conditions:
|
// Validity Conditions:
|
||||||
// 1. Peer has a valid IP and TCP port set in their enr.
|
// 1. Peer has a valid IP and a (QUIC and/or TCP) port set in their enr.
|
||||||
// 2. Peer hasn't been marked as 'bad'.
|
// 2. Peer hasn't been marked as 'bad'.
|
||||||
// 3. Peer is not currently active or connected.
|
// 3. Peer is not currently active or connected.
|
||||||
// 4. Peer is ready to receive incoming connections.
|
// 4. Peer is ready to receive incoming connections.
|
||||||
@@ -294,17 +310,13 @@ func (s *Service) filterPeer(node *enode.Node) bool {
|
|||||||
return false
|
return false
|
||||||
}
|
}
|
||||||
|
|
||||||
// Ignore nodes with their TCP ports not set.
|
peerData, multiAddrs, err := convertToAddrInfo(node)
|
||||||
if err := node.Record().Load(enr.WithEntry("tcp", new(enr.TCP))); err != nil {
|
if err != nil {
|
||||||
if !enr.IsNotFound(err) {
|
log.WithError(err).Debug("Could not convert to peer data")
|
||||||
log.WithError(err).Debug("Could not retrieve tcp port")
|
|
||||||
}
|
|
||||||
return false
|
return false
|
||||||
}
|
}
|
||||||
|
|
||||||
peerData, multiAddr, err := convertToAddrInfo(node)
|
if len(multiAddrs) == 0 {
|
||||||
if err != nil {
|
|
||||||
log.WithError(err).Debug("Could not convert to peer data")
|
|
||||||
return false
|
return false
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -337,6 +349,9 @@ func (s *Service) filterPeer(node *enode.Node) bool {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// If the peer has 2 multiaddrs, favor the QUIC address, which is in first position.
|
||||||
|
multiAddr := multiAddrs[0]
|
||||||
|
|
||||||
// Add peer to peer handler.
|
// Add peer to peer handler.
|
||||||
s.peers.Add(nodeENR, peerData.ID, multiAddr, network.DirUnknown)
|
s.peers.Add(nodeENR, peerData.ID, multiAddr, network.DirUnknown)
|
||||||
|
|
||||||
@@ -380,11 +395,11 @@ func PeersFromStringAddrs(addrs []string) ([]ma.Multiaddr, error) {
|
|||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, errors.Wrapf(err, "Could not get enode from string")
|
return nil, errors.Wrapf(err, "Could not get enode from string")
|
||||||
}
|
}
|
||||||
addr, err := convertToSingleMultiAddr(enodeAddr)
|
nodeAddrs, err := convertToMultiAddrs(enodeAddr)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, errors.Wrapf(err, "Could not get multiaddr")
|
return nil, errors.Wrapf(err, "Could not get multiaddr")
|
||||||
}
|
}
|
||||||
allAddrs = append(allAddrs, addr)
|
allAddrs = append(allAddrs, nodeAddrs...)
|
||||||
}
|
}
|
||||||
return allAddrs, nil
|
return allAddrs, nil
|
||||||
}
|
}
|
||||||
@@ -419,45 +434,141 @@ func parseGenericAddrs(addrs []string) (enodeString, multiAddrString []string) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func convertToMultiAddr(nodes []*enode.Node) []ma.Multiaddr {
|
func convertToMultiAddr(nodes []*enode.Node) []ma.Multiaddr {
|
||||||
var multiAddrs []ma.Multiaddr
|
// Expect each node to have a TCP and a QUIC address.
|
||||||
|
multiAddrs := make([]ma.Multiaddr, 0, 2*len(nodes))
|
||||||
|
|
||||||
for _, node := range nodes {
|
for _, node := range nodes {
|
||||||
// ignore nodes with no ip address stored
|
// Skip nodes with no ip address stored.
|
||||||
if node.IP() == nil {
|
if node.IP() == nil {
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
multiAddr, err := convertToSingleMultiAddr(node)
|
|
||||||
|
// Get up to two multiaddrs (TCP and QUIC) for each node.
|
||||||
|
nodeMultiAddrs, err := convertToMultiAddrs(node)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.WithError(err).Error("Could not convert to multiAddr")
|
log.WithError(err).Errorf("Could not convert to multiAddr node %s", node)
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
multiAddrs = append(multiAddrs, multiAddr)
|
|
||||||
|
multiAddrs = append(multiAddrs, nodeMultiAddrs...)
|
||||||
}
|
}
|
||||||
|
|
||||||
return multiAddrs
|
return multiAddrs
|
||||||
}
|
}
|
||||||
|
|
||||||
func convertToAddrInfo(node *enode.Node) (*peer.AddrInfo, ma.Multiaddr, error) {
|
func convertToAddrInfo(node *enode.Node) (*peer.AddrInfo, []ma.Multiaddr, error) {
|
||||||
multiAddr, err := convertToSingleMultiAddr(node)
|
multiAddrs, err := convertToMultiAddrs(node)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, nil, err
|
return nil, nil, err
|
||||||
}
|
}
|
||||||
info, err := peer.AddrInfoFromP2pAddr(multiAddr)
|
|
||||||
if err != nil {
|
if len(multiAddrs) == 0 {
|
||||||
return nil, nil, err
|
return nil, nil, nil
|
||||||
}
|
}
|
||||||
return info, multiAddr, nil
|
|
||||||
|
infos, err := peer.AddrInfosFromP2pAddrs(multiAddrs...)
|
||||||
|
if err != nil {
|
||||||
|
return nil, nil, errors.Wrapf(err, "could not convert to peer info: %v", multiAddrs)
|
||||||
|
}
|
||||||
|
|
||||||
|
if len(infos) > 1 {
|
||||||
|
return nil, nil, errors.Errorf("infos contains %v elements, expected not more than 1", len(infos))
|
||||||
|
}
|
||||||
|
|
||||||
|
if len(infos) == 0 {
|
||||||
|
return nil, multiAddrs, nil
|
||||||
|
}
|
||||||
|
|
||||||
|
return &infos[0], multiAddrs, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func convertToSingleMultiAddr(node *enode.Node) (ma.Multiaddr, error) {
|
// convertToMultiAddrs converts an enode.Node to a list of multiaddrs.
|
||||||
|
// If the node has a both a QUIC and a TCP port set in their ENR, then
|
||||||
|
// the multiaddr corresponding to the QUIC port is added first, followed
|
||||||
|
// by the multiaddr corresponding to the TCP port.
|
||||||
|
func convertToMultiAddrs(node *enode.Node) ([]ma.Multiaddr, error) {
|
||||||
|
multiaddrs := make([]ma.Multiaddr, 0, 2)
|
||||||
|
|
||||||
|
// Retrieve the node public key.
|
||||||
pubkey := node.Pubkey()
|
pubkey := node.Pubkey()
|
||||||
assertedKey, err := ecdsaprysm.ConvertToInterfacePubkey(pubkey)
|
assertedKey, err := ecdsaprysm.ConvertToInterfacePubkey(pubkey)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, errors.Wrap(err, "could not get pubkey")
|
return nil, errors.Wrap(err, "could not get pubkey")
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Compute the node ID from the public key.
|
||||||
id, err := peer.IDFromPublicKey(assertedKey)
|
id, err := peer.IDFromPublicKey(assertedKey)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, errors.Wrap(err, "could not get peer id")
|
return nil, errors.Wrap(err, "could not get peer id")
|
||||||
}
|
}
|
||||||
return multiAddressBuilderWithID(node.IP().String(), "tcp", uint(node.TCP()), id)
|
|
||||||
|
// If the QUIC entry is present in the ENR, build the corresponding multiaddress.
|
||||||
|
port, ok, err := getPort(node, quic)
|
||||||
|
if err != nil {
|
||||||
|
return nil, errors.Wrap(err, "could not get QUIC port")
|
||||||
|
}
|
||||||
|
|
||||||
|
if ok {
|
||||||
|
addr, err := multiAddressBuilderWithID(node.IP(), quic, port, id)
|
||||||
|
if err != nil {
|
||||||
|
return nil, errors.Wrap(err, "could not build QUIC address")
|
||||||
|
}
|
||||||
|
|
||||||
|
multiaddrs = append(multiaddrs, addr)
|
||||||
|
}
|
||||||
|
|
||||||
|
// If the TCP entry is present in the ENR, build the corresponding multiaddress.
|
||||||
|
port, ok, err = getPort(node, tcp)
|
||||||
|
if err != nil {
|
||||||
|
return nil, errors.Wrap(err, "could not get TCP port")
|
||||||
|
}
|
||||||
|
|
||||||
|
if ok {
|
||||||
|
addr, err := multiAddressBuilderWithID(node.IP(), tcp, port, id)
|
||||||
|
if err != nil {
|
||||||
|
return nil, errors.Wrap(err, "could not build TCP address")
|
||||||
|
}
|
||||||
|
|
||||||
|
multiaddrs = append(multiaddrs, addr)
|
||||||
|
}
|
||||||
|
|
||||||
|
return multiaddrs, nil
|
||||||
|
}
|
||||||
|
|
||||||
|
// getPort retrieves the port for a given node and protocol, as well as a boolean
|
||||||
|
// indicating whether the port was found, and an error
|
||||||
|
func getPort(node *enode.Node, protocol internetProtocol) (uint, bool, error) {
|
||||||
|
var (
|
||||||
|
port uint
|
||||||
|
err error
|
||||||
|
)
|
||||||
|
|
||||||
|
switch protocol {
|
||||||
|
case tcp:
|
||||||
|
var entry enr.TCP
|
||||||
|
err = node.Load(&entry)
|
||||||
|
port = uint(entry)
|
||||||
|
case udp:
|
||||||
|
var entry enr.UDP
|
||||||
|
err = node.Load(&entry)
|
||||||
|
port = uint(entry)
|
||||||
|
case quic:
|
||||||
|
var entry quicProtocol
|
||||||
|
err = node.Load(&entry)
|
||||||
|
port = uint(entry)
|
||||||
|
default:
|
||||||
|
return 0, false, errors.Errorf("invalid protocol: %v", protocol)
|
||||||
|
}
|
||||||
|
|
||||||
|
if enr.IsNotFound(err) {
|
||||||
|
return port, false, nil
|
||||||
|
}
|
||||||
|
|
||||||
|
if err != nil {
|
||||||
|
return 0, false, errors.Wrap(err, "could not get port")
|
||||||
|
}
|
||||||
|
|
||||||
|
return port, true, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func convertToUdpMultiAddr(node *enode.Node) ([]ma.Multiaddr, error) {
|
func convertToUdpMultiAddr(node *enode.Node) ([]ma.Multiaddr, error) {
|
||||||
@@ -475,14 +586,14 @@ func convertToUdpMultiAddr(node *enode.Node) ([]ma.Multiaddr, error) {
|
|||||||
var ip4 enr.IPv4
|
var ip4 enr.IPv4
|
||||||
var ip6 enr.IPv6
|
var ip6 enr.IPv6
|
||||||
if node.Load(&ip4) == nil {
|
if node.Load(&ip4) == nil {
|
||||||
address, ipErr := multiAddressBuilderWithID(net.IP(ip4).String(), "udp", uint(node.UDP()), id)
|
address, ipErr := multiAddressBuilderWithID(net.IP(ip4), udp, uint(node.UDP()), id)
|
||||||
if ipErr != nil {
|
if ipErr != nil {
|
||||||
return nil, errors.Wrap(ipErr, "could not build IPv4 address")
|
return nil, errors.Wrap(ipErr, "could not build IPv4 address")
|
||||||
}
|
}
|
||||||
addresses = append(addresses, address)
|
addresses = append(addresses, address)
|
||||||
}
|
}
|
||||||
if node.Load(&ip6) == nil {
|
if node.Load(&ip6) == nil {
|
||||||
address, ipErr := multiAddressBuilderWithID(net.IP(ip6).String(), "udp", uint(node.UDP()), id)
|
address, ipErr := multiAddressBuilderWithID(net.IP(ip6), udp, uint(node.UDP()), id)
|
||||||
if ipErr != nil {
|
if ipErr != nil {
|
||||||
return nil, errors.Wrap(ipErr, "could not build IPv6 address")
|
return nil, errors.Wrap(ipErr, "could not build IPv6 address")
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -166,8 +166,9 @@ func TestCreateLocalNode(t *testing.T) {
|
|||||||
t.Run(tt.name, func(t *testing.T) {
|
t.Run(tt.name, func(t *testing.T) {
|
||||||
// Define ports.
|
// Define ports.
|
||||||
const (
|
const (
|
||||||
udpPort = 2000
|
udpPort = 2000
|
||||||
tcpPort = 3000
|
tcpPort = 3000
|
||||||
|
quicPort = 3000
|
||||||
)
|
)
|
||||||
|
|
||||||
// Create a private key.
|
// Create a private key.
|
||||||
@@ -180,7 +181,7 @@ func TestCreateLocalNode(t *testing.T) {
|
|||||||
cfg: tt.cfg,
|
cfg: tt.cfg,
|
||||||
}
|
}
|
||||||
|
|
||||||
localNode, err := service.createLocalNode(privKey, address, udpPort, tcpPort)
|
localNode, err := service.createLocalNode(privKey, address, udpPort, tcpPort, quicPort)
|
||||||
if tt.expectedError {
|
if tt.expectedError {
|
||||||
require.NotNil(t, err)
|
require.NotNil(t, err)
|
||||||
return
|
return
|
||||||
@@ -237,7 +238,7 @@ func TestMultiAddrsConversion_InvalidIPAddr(t *testing.T) {
|
|||||||
genesisTime: time.Now(),
|
genesisTime: time.Now(),
|
||||||
genesisValidatorsRoot: bytesutil.PadTo([]byte{'A'}, 32),
|
genesisValidatorsRoot: bytesutil.PadTo([]byte{'A'}, 32),
|
||||||
}
|
}
|
||||||
node, err := s.createLocalNode(pkey, addr, 0, 0)
|
node, err := s.createLocalNode(pkey, addr, 0, 0, 0)
|
||||||
require.NoError(t, err)
|
require.NoError(t, err)
|
||||||
multiAddr := convertToMultiAddr([]*enode.Node{node.Node()})
|
multiAddr := convertToMultiAddr([]*enode.Node{node.Node()})
|
||||||
assert.Equal(t, 0, len(multiAddr), "Invalid ip address converted successfully")
|
assert.Equal(t, 0, len(multiAddr), "Invalid ip address converted successfully")
|
||||||
@@ -248,8 +249,9 @@ func TestMultiAddrConversion_OK(t *testing.T) {
|
|||||||
ipAddr, pkey := createAddrAndPrivKey(t)
|
ipAddr, pkey := createAddrAndPrivKey(t)
|
||||||
s := &Service{
|
s := &Service{
|
||||||
cfg: &Config{
|
cfg: &Config{
|
||||||
TCPPort: 0,
|
UDPPort: 2000,
|
||||||
UDPPort: 0,
|
TCPPort: 3000,
|
||||||
|
QUICPort: 3000,
|
||||||
},
|
},
|
||||||
genesisTime: time.Now(),
|
genesisTime: time.Now(),
|
||||||
genesisValidatorsRoot: bytesutil.PadTo([]byte{'A'}, 32),
|
genesisValidatorsRoot: bytesutil.PadTo([]byte{'A'}, 32),
|
||||||
|
|||||||
@@ -28,7 +28,8 @@ import (
|
|||||||
)
|
)
|
||||||
|
|
||||||
func TestStartDiscv5_DifferentForkDigests(t *testing.T) {
|
func TestStartDiscv5_DifferentForkDigests(t *testing.T) {
|
||||||
port := 2000
|
const port = 2000
|
||||||
|
|
||||||
ipAddr, pkey := createAddrAndPrivKey(t)
|
ipAddr, pkey := createAddrAndPrivKey(t)
|
||||||
genesisTime := time.Now()
|
genesisTime := time.Now()
|
||||||
genesisValidatorsRoot := make([]byte, fieldparams.RootLength)
|
genesisValidatorsRoot := make([]byte, fieldparams.RootLength)
|
||||||
@@ -53,7 +54,7 @@ func TestStartDiscv5_DifferentForkDigests(t *testing.T) {
|
|||||||
|
|
||||||
var listeners []*discover.UDPv5
|
var listeners []*discover.UDPv5
|
||||||
for i := 1; i <= 5; i++ {
|
for i := 1; i <= 5; i++ {
|
||||||
port = 3000 + i
|
port := 3000 + i
|
||||||
cfg.UDPPort = uint(port)
|
cfg.UDPPort = uint(port)
|
||||||
ipAddr, pkey := createAddrAndPrivKey(t)
|
ipAddr, pkey := createAddrAndPrivKey(t)
|
||||||
|
|
||||||
@@ -98,13 +99,14 @@ func TestStartDiscv5_DifferentForkDigests(t *testing.T) {
|
|||||||
s.genesisTime = genesisTime
|
s.genesisTime = genesisTime
|
||||||
s.genesisValidatorsRoot = make([]byte, 32)
|
s.genesisValidatorsRoot = make([]byte, 32)
|
||||||
s.dv5Listener = lastListener
|
s.dv5Listener = lastListener
|
||||||
var addrs []ma.Multiaddr
|
|
||||||
|
|
||||||
for _, n := range nodes {
|
addrs := make([]ma.Multiaddr, 0)
|
||||||
if s.filterPeer(n) {
|
|
||||||
addr, err := convertToSingleMultiAddr(n)
|
for _, node := range nodes {
|
||||||
|
if s.filterPeer(node) {
|
||||||
|
nodeAddrs, err := convertToMultiAddrs(node)
|
||||||
require.NoError(t, err)
|
require.NoError(t, err)
|
||||||
addrs = append(addrs, addr)
|
addrs = append(addrs, nodeAddrs...)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -114,10 +116,11 @@ func TestStartDiscv5_DifferentForkDigests(t *testing.T) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func TestStartDiscv5_SameForkDigests_DifferentNextForkData(t *testing.T) {
|
func TestStartDiscv5_SameForkDigests_DifferentNextForkData(t *testing.T) {
|
||||||
|
const port = 2000
|
||||||
|
|
||||||
params.SetupTestConfigCleanup(t)
|
params.SetupTestConfigCleanup(t)
|
||||||
hook := logTest.NewGlobal()
|
hook := logTest.NewGlobal()
|
||||||
logrus.SetLevel(logrus.TraceLevel)
|
logrus.SetLevel(logrus.TraceLevel)
|
||||||
port := 2000
|
|
||||||
ipAddr, pkey := createAddrAndPrivKey(t)
|
ipAddr, pkey := createAddrAndPrivKey(t)
|
||||||
genesisTime := time.Now()
|
genesisTime := time.Now()
|
||||||
genesisValidatorsRoot := make([]byte, 32)
|
genesisValidatorsRoot := make([]byte, 32)
|
||||||
@@ -138,7 +141,7 @@ func TestStartDiscv5_SameForkDigests_DifferentNextForkData(t *testing.T) {
|
|||||||
|
|
||||||
var listeners []*discover.UDPv5
|
var listeners []*discover.UDPv5
|
||||||
for i := 1; i <= 5; i++ {
|
for i := 1; i <= 5; i++ {
|
||||||
port = 3000 + i
|
port := 3000 + i
|
||||||
cfg.UDPPort = uint(port)
|
cfg.UDPPort = uint(port)
|
||||||
ipAddr, pkey := createAddrAndPrivKey(t)
|
ipAddr, pkey := createAddrAndPrivKey(t)
|
||||||
|
|
||||||
@@ -188,13 +191,13 @@ func TestStartDiscv5_SameForkDigests_DifferentNextForkData(t *testing.T) {
|
|||||||
s.genesisTime = genesisTime
|
s.genesisTime = genesisTime
|
||||||
s.genesisValidatorsRoot = make([]byte, 32)
|
s.genesisValidatorsRoot = make([]byte, 32)
|
||||||
s.dv5Listener = lastListener
|
s.dv5Listener = lastListener
|
||||||
var addrs []ma.Multiaddr
|
addrs := make([]ma.Multiaddr, 0, len(nodes))
|
||||||
|
|
||||||
for _, n := range nodes {
|
for _, node := range nodes {
|
||||||
if s.filterPeer(n) {
|
if s.filterPeer(node) {
|
||||||
addr, err := convertToSingleMultiAddr(n)
|
nodeAddrs, err := convertToMultiAddrs(node)
|
||||||
require.NoError(t, err)
|
require.NoError(t, err)
|
||||||
addrs = append(addrs, addr)
|
addrs = append(addrs, nodeAddrs...)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if len(addrs) == 0 {
|
if len(addrs) == 0 {
|
||||||
|
|||||||
@@ -1,6 +1,7 @@
|
|||||||
package p2p
|
package p2p
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"net"
|
||||||
"strconv"
|
"strconv"
|
||||||
"strings"
|
"strings"
|
||||||
|
|
||||||
@@ -12,32 +13,32 @@ import (
|
|||||||
var log = logrus.WithField("prefix", "p2p")
|
var log = logrus.WithField("prefix", "p2p")
|
||||||
|
|
||||||
func logIPAddr(id peer.ID, addrs ...ma.Multiaddr) {
|
func logIPAddr(id peer.ID, addrs ...ma.Multiaddr) {
|
||||||
var correctAddr ma.Multiaddr
|
|
||||||
for _, addr := range addrs {
|
for _, addr := range addrs {
|
||||||
if strings.Contains(addr.String(), "/ip4/") || strings.Contains(addr.String(), "/ip6/") {
|
if !(strings.Contains(addr.String(), "/ip4/") || strings.Contains(addr.String(), "/ip6/")) {
|
||||||
correctAddr = addr
|
continue
|
||||||
break
|
|
||||||
}
|
}
|
||||||
}
|
|
||||||
if correctAddr != nil {
|
|
||||||
log.WithField(
|
log.WithField(
|
||||||
"multiAddr",
|
"multiAddr",
|
||||||
correctAddr.String()+"/p2p/"+id.String(),
|
addr.String()+"/p2p/"+id.String(),
|
||||||
).Info("Node started p2p server")
|
).Info("Node started p2p server")
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func logExternalIPAddr(id peer.ID, addr string, port uint) {
|
func logExternalIPAddr(id peer.ID, addr string, tcpPort, quicPort uint) {
|
||||||
if addr != "" {
|
if addr != "" {
|
||||||
multiAddr, err := MultiAddressBuilder(addr, port)
|
multiAddrs, err := MultiAddressBuilder(net.ParseIP(addr), tcpPort, quicPort)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.WithError(err).Error("Could not create multiaddress")
|
log.WithError(err).Error("Could not create multiaddress")
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
log.WithField(
|
|
||||||
"multiAddr",
|
for _, multiAddr := range multiAddrs {
|
||||||
multiAddr.String()+"/p2p/"+id.String(),
|
log.WithField(
|
||||||
).Info("Node started external p2p server")
|
"multiAddr",
|
||||||
|
multiAddr.String()+"/p2p/"+id.String(),
|
||||||
|
).Info("Node started external p2p server")
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -11,40 +11,62 @@ import (
|
|||||||
"github.com/libp2p/go-libp2p/core/network"
|
"github.com/libp2p/go-libp2p/core/network"
|
||||||
"github.com/libp2p/go-libp2p/core/peer"
|
"github.com/libp2p/go-libp2p/core/peer"
|
||||||
"github.com/libp2p/go-libp2p/p2p/security/noise"
|
"github.com/libp2p/go-libp2p/p2p/security/noise"
|
||||||
"github.com/libp2p/go-libp2p/p2p/transport/tcp"
|
libp2pquic "github.com/libp2p/go-libp2p/p2p/transport/quic"
|
||||||
|
libp2ptcp "github.com/libp2p/go-libp2p/p2p/transport/tcp"
|
||||||
gomplex "github.com/libp2p/go-mplex"
|
gomplex "github.com/libp2p/go-mplex"
|
||||||
ma "github.com/multiformats/go-multiaddr"
|
ma "github.com/multiformats/go-multiaddr"
|
||||||
"github.com/pkg/errors"
|
"github.com/pkg/errors"
|
||||||
"github.com/prysmaticlabs/prysm/v5/config/features"
|
"github.com/prysmaticlabs/prysm/v5/config/features"
|
||||||
ecdsaprysm "github.com/prysmaticlabs/prysm/v5/crypto/ecdsa"
|
ecdsaprysm "github.com/prysmaticlabs/prysm/v5/crypto/ecdsa"
|
||||||
|
|
||||||
"github.com/prysmaticlabs/prysm/v5/runtime/version"
|
"github.com/prysmaticlabs/prysm/v5/runtime/version"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
type internetProtocol string
|
||||||
|
|
||||||
|
const (
|
||||||
|
udp = "udp"
|
||||||
|
tcp = "tcp"
|
||||||
|
quic = "quic"
|
||||||
|
)
|
||||||
|
|
||||||
// MultiAddressBuilder takes in an ip address string and port to produce a go multiaddr format.
|
// MultiAddressBuilder takes in an ip address string and port to produce a go multiaddr format.
|
||||||
func MultiAddressBuilder(ipAddr string, port uint) (ma.Multiaddr, error) {
|
func MultiAddressBuilder(ip net.IP, tcpPort, quicPort uint) ([]ma.Multiaddr, error) {
|
||||||
parsedIP := net.ParseIP(ipAddr)
|
ipType, err := extractIpType(ip)
|
||||||
if parsedIP.To4() == nil && parsedIP.To16() == nil {
|
if err != nil {
|
||||||
return nil, errors.Errorf("invalid ip address provided: %s", ipAddr)
|
return nil, errors.Wrap(err, "unable to determine IP type")
|
||||||
}
|
}
|
||||||
if parsedIP.To4() != nil {
|
|
||||||
return ma.NewMultiaddr(fmt.Sprintf("/ip4/%s/tcp/%d", ipAddr, port))
|
// Example: /ip4/1.2.3.4/udp/5678/quic-v1
|
||||||
|
multiAddrQUIC, err := ma.NewMultiaddr(fmt.Sprintf("/%s/%s/udp/%d/quic-v1", ipType, ip, quicPort))
|
||||||
|
if err != nil {
|
||||||
|
return nil, errors.Wrapf(err, "cannot produce QUIC multiaddr format from %s:%d", ip, tcpPort)
|
||||||
}
|
}
|
||||||
return ma.NewMultiaddr(fmt.Sprintf("/ip6/%s/tcp/%d", ipAddr, port))
|
|
||||||
|
// Example: /ip4/1.2.3.4./tcp/5678
|
||||||
|
multiaddrStr := fmt.Sprintf("/%s/%s/tcp/%d", ipType, ip, tcpPort)
|
||||||
|
multiAddrTCP, err := ma.NewMultiaddr(multiaddrStr)
|
||||||
|
if err != nil {
|
||||||
|
return nil, errors.Wrapf(err, "cannot produce TCP multiaddr format from %s:%d", ip, tcpPort)
|
||||||
|
}
|
||||||
|
|
||||||
|
return []ma.Multiaddr{multiAddrTCP, multiAddrQUIC}, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
// buildOptions for the libp2p host.
|
// buildOptions for the libp2p host.
|
||||||
func (s *Service) buildOptions(ip net.IP, priKey *ecdsa.PrivateKey) ([]libp2p.Option, error) {
|
func (s *Service) buildOptions(ip net.IP, priKey *ecdsa.PrivateKey) ([]libp2p.Option, error) {
|
||||||
cfg := s.cfg
|
cfg := s.cfg
|
||||||
listen, err := MultiAddressBuilder(ip.String(), cfg.TCPPort)
|
multiaddrs, err := MultiAddressBuilder(ip, cfg.TCPPort, cfg.QUICPort)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, errors.Wrapf(err, "cannot produce multiaddr format from %s:%d", ip.String(), cfg.TCPPort)
|
return nil, errors.Wrapf(err, "cannot produce multiaddr format from %s:%d", ip, cfg.TCPPort)
|
||||||
}
|
}
|
||||||
if cfg.LocalIP != "" {
|
if cfg.LocalIP != "" {
|
||||||
if net.ParseIP(cfg.LocalIP) == nil {
|
localIP := net.ParseIP(cfg.LocalIP)
|
||||||
|
if localIP == nil {
|
||||||
return nil, errors.Wrapf(err, "invalid local ip provided: %s:%d", cfg.LocalIP, cfg.TCPPort)
|
return nil, errors.Wrapf(err, "invalid local ip provided: %s:%d", cfg.LocalIP, cfg.TCPPort)
|
||||||
}
|
}
|
||||||
|
|
||||||
listen, err = MultiAddressBuilder(cfg.LocalIP, cfg.TCPPort)
|
multiaddrs, err = MultiAddressBuilder(localIP, cfg.TCPPort, cfg.QUICPort)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, errors.Wrapf(err, "cannot produce multiaddr format from %s:%d", cfg.LocalIP, cfg.TCPPort)
|
return nil, errors.Wrapf(err, "cannot produce multiaddr format from %s:%d", cfg.LocalIP, cfg.TCPPort)
|
||||||
}
|
}
|
||||||
@@ -58,14 +80,15 @@ func (s *Service) buildOptions(ip net.IP, priKey *ecdsa.PrivateKey) ([]libp2p.Op
|
|||||||
return nil, errors.Wrapf(err, "cannot get ID from public key: %s", ifaceKey.GetPublic().Type().String())
|
return nil, errors.Wrapf(err, "cannot get ID from public key: %s", ifaceKey.GetPublic().Type().String())
|
||||||
}
|
}
|
||||||
|
|
||||||
log.Infof("Running node with peer id of %s ", id.String())
|
log.WithField("peerId", id).Info("Running node with")
|
||||||
|
|
||||||
options := []libp2p.Option{
|
options := []libp2p.Option{
|
||||||
privKeyOption(priKey),
|
privKeyOption(priKey),
|
||||||
libp2p.ListenAddrs(listen),
|
libp2p.ListenAddrs(multiaddrs...),
|
||||||
libp2p.UserAgent(version.BuildData()),
|
libp2p.UserAgent(version.BuildData()),
|
||||||
libp2p.ConnectionGater(s),
|
libp2p.ConnectionGater(s),
|
||||||
libp2p.Transport(tcp.NewTCPTransport),
|
libp2p.Transport(libp2pquic.NewTransport),
|
||||||
|
libp2p.Transport(libp2ptcp.NewTCPTransport),
|
||||||
libp2p.DefaultMuxers,
|
libp2p.DefaultMuxers,
|
||||||
libp2p.Muxer("/mplex/6.7.0", mplex.DefaultTransport),
|
libp2p.Muxer("/mplex/6.7.0", mplex.DefaultTransport),
|
||||||
libp2p.Security(noise.ID, noise.New),
|
libp2p.Security(noise.ID, noise.New),
|
||||||
@@ -75,23 +98,26 @@ func (s *Service) buildOptions(ip net.IP, priKey *ecdsa.PrivateKey) ([]libp2p.Op
|
|||||||
if cfg.EnableUPnP {
|
if cfg.EnableUPnP {
|
||||||
options = append(options, libp2p.NATPortMap()) // Allow to use UPnP
|
options = append(options, libp2p.NATPortMap()) // Allow to use UPnP
|
||||||
}
|
}
|
||||||
|
|
||||||
if cfg.RelayNodeAddr != "" {
|
if cfg.RelayNodeAddr != "" {
|
||||||
options = append(options, libp2p.AddrsFactory(withRelayAddrs(cfg.RelayNodeAddr)))
|
options = append(options, libp2p.AddrsFactory(withRelayAddrs(cfg.RelayNodeAddr)))
|
||||||
} else {
|
} else {
|
||||||
// Disable relay if it has not been set.
|
// Disable relay if it has not been set.
|
||||||
options = append(options, libp2p.DisableRelay())
|
options = append(options, libp2p.DisableRelay())
|
||||||
}
|
}
|
||||||
|
|
||||||
if cfg.HostAddress != "" {
|
if cfg.HostAddress != "" {
|
||||||
options = append(options, libp2p.AddrsFactory(func(addrs []ma.Multiaddr) []ma.Multiaddr {
|
options = append(options, libp2p.AddrsFactory(func(addrs []ma.Multiaddr) []ma.Multiaddr {
|
||||||
external, err := MultiAddressBuilder(cfg.HostAddress, cfg.TCPPort)
|
externalMultiaddrs, err := MultiAddressBuilder(net.ParseIP(cfg.HostAddress), cfg.TCPPort, cfg.QUICPort)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.WithError(err).Error("Unable to create external multiaddress")
|
log.WithError(err).Error("Unable to create external multiaddress")
|
||||||
} else {
|
} else {
|
||||||
addrs = append(addrs, external)
|
addrs = append(addrs, externalMultiaddrs...)
|
||||||
}
|
}
|
||||||
return addrs
|
return addrs
|
||||||
}))
|
}))
|
||||||
}
|
}
|
||||||
|
|
||||||
if cfg.HostDNS != "" {
|
if cfg.HostDNS != "" {
|
||||||
options = append(options, libp2p.AddrsFactory(func(addrs []ma.Multiaddr) []ma.Multiaddr {
|
options = append(options, libp2p.AddrsFactory(func(addrs []ma.Multiaddr) []ma.Multiaddr {
|
||||||
external, err := ma.NewMultiaddr(fmt.Sprintf("/dns4/%s/tcp/%d", cfg.HostDNS, cfg.TCPPort))
|
external, err := ma.NewMultiaddr(fmt.Sprintf("/dns4/%s/tcp/%d", cfg.HostDNS, cfg.TCPPort))
|
||||||
@@ -107,21 +133,47 @@ func (s *Service) buildOptions(ip net.IP, priKey *ecdsa.PrivateKey) ([]libp2p.Op
|
|||||||
if features.Get().DisableResourceManager {
|
if features.Get().DisableResourceManager {
|
||||||
options = append(options, libp2p.ResourceManager(&network.NullResourceManager{}))
|
options = append(options, libp2p.ResourceManager(&network.NullResourceManager{}))
|
||||||
}
|
}
|
||||||
|
|
||||||
return options, nil
|
return options, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func multiAddressBuilderWithID(ipAddr, protocol string, port uint, id peer.ID) (ma.Multiaddr, error) {
|
func extractIpType(ip net.IP) (string, error) {
|
||||||
parsedIP := net.ParseIP(ipAddr)
|
if ip.To4() != nil {
|
||||||
if parsedIP.To4() == nil && parsedIP.To16() == nil {
|
return "ip4", nil
|
||||||
return nil, errors.Errorf("invalid ip address provided: %s", ipAddr)
|
|
||||||
}
|
}
|
||||||
if id.String() == "" {
|
|
||||||
return nil, errors.New("empty peer id given")
|
if ip.To16() != nil {
|
||||||
|
return "ip6", nil
|
||||||
}
|
}
|
||||||
if parsedIP.To4() != nil {
|
|
||||||
return ma.NewMultiaddr(fmt.Sprintf("/ip4/%s/%s/%d/p2p/%s", ipAddr, protocol, port, id.String()))
|
return "", errors.Errorf("provided IP address is neither IPv4 nor IPv6: %s", ip)
|
||||||
|
}
|
||||||
|
|
||||||
|
func multiAddressBuilderWithID(ip net.IP, protocol internetProtocol, port uint, id peer.ID) (ma.Multiaddr, error) {
|
||||||
|
var multiaddrStr string
|
||||||
|
|
||||||
|
if id == "" {
|
||||||
|
return nil, errors.Errorf("empty peer id given: %s", id)
|
||||||
}
|
}
|
||||||
return ma.NewMultiaddr(fmt.Sprintf("/ip6/%s/%s/%d/p2p/%s", ipAddr, protocol, port, id.String()))
|
|
||||||
|
ipType, err := extractIpType(ip)
|
||||||
|
if err != nil {
|
||||||
|
return nil, errors.Wrap(err, "unable to determine IP type")
|
||||||
|
}
|
||||||
|
|
||||||
|
switch protocol {
|
||||||
|
case udp, tcp:
|
||||||
|
// Example with UDP: /ip4/1.2.3.4/udp/5678/p2p/16Uiu2HAkum7hhuMpWqFj3yNLcmQBGmThmqw2ohaCRThXQuKU9ohs
|
||||||
|
// Example with TCP: /ip6/1.2.3.4/tcp/5678/p2p/16Uiu2HAkum7hhuMpWqFj3yNLcmQBGmThmqw2ohaCRThXQuKU9ohs
|
||||||
|
multiaddrStr = fmt.Sprintf("/%s/%s/%s/%d/p2p/%s", ipType, ip, protocol, port, id)
|
||||||
|
case quic:
|
||||||
|
// Example: /ip4/1.2.3.4/udp/5678/quic-v1/p2p/16Uiu2HAkum7hhuMpWqFj3yNLcmQBGmThmqw2ohaCRThXQuKU9ohs
|
||||||
|
multiaddrStr = fmt.Sprintf("/%s/%s/udp/%d/quic-v1/p2p/%s", ipType, ip, port, id)
|
||||||
|
default:
|
||||||
|
return nil, errors.Errorf("unsupported protocol: %s", protocol)
|
||||||
|
}
|
||||||
|
|
||||||
|
return ma.NewMultiaddr(multiaddrStr)
|
||||||
}
|
}
|
||||||
|
|
||||||
// Adds a private key to the libp2p option if the option was provided.
|
// Adds a private key to the libp2p option if the option was provided.
|
||||||
|
|||||||
@@ -13,6 +13,7 @@ import (
|
|||||||
"github.com/ethereum/go-ethereum/p2p/enr"
|
"github.com/ethereum/go-ethereum/p2p/enr"
|
||||||
"github.com/libp2p/go-libp2p"
|
"github.com/libp2p/go-libp2p"
|
||||||
"github.com/libp2p/go-libp2p/core/crypto"
|
"github.com/libp2p/go-libp2p/core/crypto"
|
||||||
|
"github.com/libp2p/go-libp2p/core/peer"
|
||||||
"github.com/libp2p/go-libp2p/core/protocol"
|
"github.com/libp2p/go-libp2p/core/protocol"
|
||||||
mock "github.com/prysmaticlabs/prysm/v5/beacon-chain/blockchain/testing"
|
mock "github.com/prysmaticlabs/prysm/v5/beacon-chain/blockchain/testing"
|
||||||
"github.com/prysmaticlabs/prysm/v5/config/params"
|
"github.com/prysmaticlabs/prysm/v5/config/params"
|
||||||
@@ -88,30 +89,34 @@ func TestIPV6Support(t *testing.T) {
|
|||||||
lNode := enode.NewLocalNode(db, key)
|
lNode := enode.NewLocalNode(db, key)
|
||||||
mockIPV6 := net.IP{0xff, 0x02, 0xAA, 0, 0x1F, 0, 0x2E, 0, 0, 0x36, 0x45, 0, 0, 0, 0, 0x02}
|
mockIPV6 := net.IP{0xff, 0x02, 0xAA, 0, 0x1F, 0, 0x2E, 0, 0, 0x36, 0x45, 0, 0, 0, 0, 0x02}
|
||||||
lNode.Set(enr.IP(mockIPV6))
|
lNode.Set(enr.IP(mockIPV6))
|
||||||
ma, err := convertToSingleMultiAddr(lNode.Node())
|
mas, err := convertToMultiAddrs(lNode.Node())
|
||||||
if err != nil {
|
if err != nil {
|
||||||
t.Fatal(err)
|
t.Fatal(err)
|
||||||
}
|
}
|
||||||
ipv6Exists := false
|
|
||||||
for _, p := range ma.Protocols() {
|
for _, ma := range mas {
|
||||||
if p.Name == "ip4" {
|
ipv6Exists := false
|
||||||
t.Error("Got ip4 address instead of ip6")
|
for _, p := range ma.Protocols() {
|
||||||
|
if p.Name == "ip4" {
|
||||||
|
t.Error("Got ip4 address instead of ip6")
|
||||||
|
}
|
||||||
|
if p.Name == "ip6" {
|
||||||
|
ipv6Exists = true
|
||||||
|
}
|
||||||
}
|
}
|
||||||
if p.Name == "ip6" {
|
if !ipv6Exists {
|
||||||
ipv6Exists = true
|
t.Error("Multiaddress did not have ipv6 protocol")
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if !ipv6Exists {
|
|
||||||
t.Error("Multiaddress did not have ipv6 protocol")
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestDefaultMultiplexers(t *testing.T) {
|
func TestDefaultMultiplexers(t *testing.T) {
|
||||||
var cfg libp2p.Config
|
var cfg libp2p.Config
|
||||||
_ = cfg
|
_ = cfg
|
||||||
p2pCfg := &Config{
|
p2pCfg := &Config{
|
||||||
TCPPort: 2000,
|
|
||||||
UDPPort: 2000,
|
UDPPort: 2000,
|
||||||
|
TCPPort: 3000,
|
||||||
|
QUICPort: 3000,
|
||||||
StateNotifier: &mock.MockStateNotifier{},
|
StateNotifier: &mock.MockStateNotifier{},
|
||||||
}
|
}
|
||||||
svc := &Service{cfg: p2pCfg}
|
svc := &Service{cfg: p2pCfg}
|
||||||
@@ -127,5 +132,57 @@ func TestDefaultMultiplexers(t *testing.T) {
|
|||||||
|
|
||||||
assert.Equal(t, protocol.ID("/yamux/1.0.0"), cfg.Muxers[0].ID)
|
assert.Equal(t, protocol.ID("/yamux/1.0.0"), cfg.Muxers[0].ID)
|
||||||
assert.Equal(t, protocol.ID("/mplex/6.7.0"), cfg.Muxers[1].ID)
|
assert.Equal(t, protocol.ID("/mplex/6.7.0"), cfg.Muxers[1].ID)
|
||||||
|
}
|
||||||
|
|
||||||
|
func TestMultiAddressBuilderWithID(t *testing.T) {
|
||||||
|
testCases := []struct {
|
||||||
|
name string
|
||||||
|
ip net.IP
|
||||||
|
protocol internetProtocol
|
||||||
|
port uint
|
||||||
|
id string
|
||||||
|
|
||||||
|
expectedMultiaddrStr string
|
||||||
|
}{
|
||||||
|
{
|
||||||
|
name: "UDP",
|
||||||
|
ip: net.IPv4(192, 168, 0, 1),
|
||||||
|
protocol: udp,
|
||||||
|
port: 5678,
|
||||||
|
id: "0025080212210204fb1ebb1aa467527d34306a4794a5171d6516405e720b909b7f816d63aef96a",
|
||||||
|
|
||||||
|
expectedMultiaddrStr: "/ip4/192.168.0.1/udp/5678/p2p/16Uiu2HAkum7hhuMpWqFj3yNLcmQBGmThmqw2ohaCRThXQuKU9ohs",
|
||||||
|
},
|
||||||
|
{
|
||||||
|
name: "TCP",
|
||||||
|
ip: net.IPv4(192, 168, 0, 1),
|
||||||
|
protocol: tcp,
|
||||||
|
port: 5678,
|
||||||
|
id: "0025080212210204fb1ebb1aa467527d34306a4794a5171d6516405e720b909b7f816d63aef96a",
|
||||||
|
|
||||||
|
expectedMultiaddrStr: "/ip4/192.168.0.1/tcp/5678/p2p/16Uiu2HAkum7hhuMpWqFj3yNLcmQBGmThmqw2ohaCRThXQuKU9ohs",
|
||||||
|
},
|
||||||
|
{
|
||||||
|
name: "QUIC",
|
||||||
|
ip: net.IPv4(192, 168, 0, 1),
|
||||||
|
protocol: quic,
|
||||||
|
port: 5678,
|
||||||
|
id: "0025080212210204fb1ebb1aa467527d34306a4794a5171d6516405e720b909b7f816d63aef96a",
|
||||||
|
|
||||||
|
expectedMultiaddrStr: "/ip4/192.168.0.1/udp/5678/quic-v1/p2p/16Uiu2HAkum7hhuMpWqFj3yNLcmQBGmThmqw2ohaCRThXQuKU9ohs",
|
||||||
|
},
|
||||||
|
}
|
||||||
|
|
||||||
|
for _, tt := range testCases {
|
||||||
|
t.Run(tt.name, func(t *testing.T) {
|
||||||
|
id, err := hex.DecodeString(tt.id)
|
||||||
|
require.NoError(t, err)
|
||||||
|
|
||||||
|
actualMultiaddr, err := multiAddressBuilderWithID(tt.ip, tt.protocol, tt.port, peer.ID(id))
|
||||||
|
require.NoError(t, err)
|
||||||
|
|
||||||
|
actualMultiaddrStr := actualMultiaddr.String()
|
||||||
|
require.Equal(t, tt.expectedMultiaddrStr, actualMultiaddrStr)
|
||||||
|
})
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -26,6 +26,7 @@ import (
|
|||||||
"context"
|
"context"
|
||||||
"math"
|
"math"
|
||||||
"sort"
|
"sort"
|
||||||
|
"strings"
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
"github.com/ethereum/go-ethereum/p2p/enr"
|
"github.com/ethereum/go-ethereum/p2p/enr"
|
||||||
@@ -449,6 +450,32 @@ func (p *Status) InboundConnected() []peer.ID {
|
|||||||
return peers
|
return peers
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// InboundConnectedTCP returns the current batch of inbound peers that are connected using TCP.
|
||||||
|
func (p *Status) InboundConnectedTCP() []peer.ID {
|
||||||
|
p.store.RLock()
|
||||||
|
defer p.store.RUnlock()
|
||||||
|
peers := make([]peer.ID, 0)
|
||||||
|
for pid, peerData := range p.store.Peers() {
|
||||||
|
if peerData.ConnState == PeerConnected && peerData.Direction == network.DirInbound && strings.Contains(peerData.Address.String(), "tcp") {
|
||||||
|
peers = append(peers, pid)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return peers
|
||||||
|
}
|
||||||
|
|
||||||
|
// InboundConnectedTCP returns the current batch of inbound peers that are connected using QUIC.
|
||||||
|
func (p *Status) InboundConnectedQUIC() []peer.ID {
|
||||||
|
p.store.RLock()
|
||||||
|
defer p.store.RUnlock()
|
||||||
|
peers := make([]peer.ID, 0)
|
||||||
|
for pid, peerData := range p.store.Peers() {
|
||||||
|
if peerData.ConnState == PeerConnected && peerData.Direction == network.DirInbound && strings.Contains(peerData.Address.String(), "quic") {
|
||||||
|
peers = append(peers, pid)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return peers
|
||||||
|
}
|
||||||
|
|
||||||
// Outbound returns the current batch of outbound peers.
|
// Outbound returns the current batch of outbound peers.
|
||||||
func (p *Status) Outbound() []peer.ID {
|
func (p *Status) Outbound() []peer.ID {
|
||||||
p.store.RLock()
|
p.store.RLock()
|
||||||
@@ -475,7 +502,33 @@ func (p *Status) OutboundConnected() []peer.ID {
|
|||||||
return peers
|
return peers
|
||||||
}
|
}
|
||||||
|
|
||||||
// Active returns the peers that are connecting or connected.
|
// OutboundConnected returns the current batch of outbound peers that are connected using TCP.
|
||||||
|
func (p *Status) OutboundConnectedTCP() []peer.ID {
|
||||||
|
p.store.RLock()
|
||||||
|
defer p.store.RUnlock()
|
||||||
|
peers := make([]peer.ID, 0)
|
||||||
|
for pid, peerData := range p.store.Peers() {
|
||||||
|
if peerData.ConnState == PeerConnected && peerData.Direction == network.DirOutbound && strings.Contains(peerData.Address.String(), "tcp") {
|
||||||
|
peers = append(peers, pid)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return peers
|
||||||
|
}
|
||||||
|
|
||||||
|
// OutboundConnected returns the current batch of outbound peers that are connected using QUIC.
|
||||||
|
func (p *Status) OutboundConnectedQUIC() []peer.ID {
|
||||||
|
p.store.RLock()
|
||||||
|
defer p.store.RUnlock()
|
||||||
|
peers := make([]peer.ID, 0)
|
||||||
|
for pid, peerData := range p.store.Peers() {
|
||||||
|
if peerData.ConnState == PeerConnected && peerData.Direction == network.DirOutbound && strings.Contains(peerData.Address.String(), "quic") {
|
||||||
|
peers = append(peers, pid)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return peers
|
||||||
|
}
|
||||||
|
|
||||||
|
// Active returns the peers that are active (connecting or connected).
|
||||||
func (p *Status) Active() []peer.ID {
|
func (p *Status) Active() []peer.ID {
|
||||||
p.store.RLock()
|
p.store.RLock()
|
||||||
defer p.store.RUnlock()
|
defer p.store.RUnlock()
|
||||||
@@ -514,7 +567,7 @@ func (p *Status) Disconnected() []peer.ID {
|
|||||||
return peers
|
return peers
|
||||||
}
|
}
|
||||||
|
|
||||||
// Inactive returns the peers that are disconnecting or disconnected.
|
// Inactive returns the peers that are inactive (disconnecting or disconnected).
|
||||||
func (p *Status) Inactive() []peer.ID {
|
func (p *Status) Inactive() []peer.ID {
|
||||||
p.store.RLock()
|
p.store.RLock()
|
||||||
defer p.store.RUnlock()
|
defer p.store.RUnlock()
|
||||||
|
|||||||
@@ -1111,6 +1111,74 @@ func TestInbound(t *testing.T) {
|
|||||||
assert.Equal(t, inbound.String(), result[0].String())
|
assert.Equal(t, inbound.String(), result[0].String())
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func TestInboundConnected(t *testing.T) {
|
||||||
|
p := peers.NewStatus(context.Background(), &peers.StatusConfig{
|
||||||
|
PeerLimit: 30,
|
||||||
|
ScorerParams: &scorers.Config{
|
||||||
|
BadResponsesScorerConfig: &scorers.BadResponsesScorerConfig{
|
||||||
|
Threshold: 0,
|
||||||
|
},
|
||||||
|
},
|
||||||
|
})
|
||||||
|
|
||||||
|
addr, err := ma.NewMultiaddr("/ip4/127.0.0.1/tcp/33333")
|
||||||
|
require.NoError(t, err)
|
||||||
|
inbound := createPeer(t, p, addr, network.DirInbound, peers.PeerConnected)
|
||||||
|
createPeer(t, p, addr, network.DirInbound, peers.PeerConnecting)
|
||||||
|
|
||||||
|
result := p.InboundConnected()
|
||||||
|
require.Equal(t, 1, len(result))
|
||||||
|
assert.Equal(t, inbound.String(), result[0].String())
|
||||||
|
}
|
||||||
|
|
||||||
|
func TestInboundConnectedTCP(t *testing.T) {
|
||||||
|
p := peers.NewStatus(context.Background(), &peers.StatusConfig{
|
||||||
|
PeerLimit: 30,
|
||||||
|
ScorerParams: &scorers.Config{
|
||||||
|
BadResponsesScorerConfig: &scorers.BadResponsesScorerConfig{
|
||||||
|
Threshold: 0,
|
||||||
|
},
|
||||||
|
},
|
||||||
|
})
|
||||||
|
|
||||||
|
addrTCP, err := ma.NewMultiaddr("/ip4/127.0.0.1/tcp/33333")
|
||||||
|
require.NoError(t, err)
|
||||||
|
|
||||||
|
addrQUIC, err := ma.NewMultiaddr("/ip4/192.168.1.3/udp/13000/quic-v1")
|
||||||
|
require.NoError(t, err)
|
||||||
|
|
||||||
|
inboundTCP := createPeer(t, p, addrTCP, network.DirInbound, peers.PeerConnected)
|
||||||
|
createPeer(t, p, addrQUIC, network.DirInbound, peers.PeerConnected)
|
||||||
|
|
||||||
|
result := p.InboundConnectedTCP()
|
||||||
|
require.Equal(t, 1, len(result))
|
||||||
|
assert.Equal(t, inboundTCP.String(), result[0].String())
|
||||||
|
}
|
||||||
|
|
||||||
|
func TestInboundConnectedQUIC(t *testing.T) {
|
||||||
|
p := peers.NewStatus(context.Background(), &peers.StatusConfig{
|
||||||
|
PeerLimit: 30,
|
||||||
|
ScorerParams: &scorers.Config{
|
||||||
|
BadResponsesScorerConfig: &scorers.BadResponsesScorerConfig{
|
||||||
|
Threshold: 0,
|
||||||
|
},
|
||||||
|
},
|
||||||
|
})
|
||||||
|
|
||||||
|
addrQUIC, err := ma.NewMultiaddr("/ip4/192.168.1.3/udp/13000/quic-v1")
|
||||||
|
require.NoError(t, err)
|
||||||
|
|
||||||
|
addrTCP, err := ma.NewMultiaddr("/ip4/127.0.0.1/tcp/33333")
|
||||||
|
require.NoError(t, err)
|
||||||
|
|
||||||
|
inboundQUIC := createPeer(t, p, addrQUIC, network.DirInbound, peers.PeerConnected)
|
||||||
|
createPeer(t, p, addrTCP, network.DirInbound, peers.PeerConnected)
|
||||||
|
|
||||||
|
result := p.InboundConnectedQUIC()
|
||||||
|
require.Equal(t, 1, len(result))
|
||||||
|
assert.Equal(t, inboundQUIC.String(), result[0].String())
|
||||||
|
}
|
||||||
|
|
||||||
func TestOutbound(t *testing.T) {
|
func TestOutbound(t *testing.T) {
|
||||||
p := peers.NewStatus(context.Background(), &peers.StatusConfig{
|
p := peers.NewStatus(context.Background(), &peers.StatusConfig{
|
||||||
PeerLimit: 30,
|
PeerLimit: 30,
|
||||||
@@ -1130,6 +1198,74 @@ func TestOutbound(t *testing.T) {
|
|||||||
assert.Equal(t, outbound.String(), result[0].String())
|
assert.Equal(t, outbound.String(), result[0].String())
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func TestOutboundConnected(t *testing.T) {
|
||||||
|
p := peers.NewStatus(context.Background(), &peers.StatusConfig{
|
||||||
|
PeerLimit: 30,
|
||||||
|
ScorerParams: &scorers.Config{
|
||||||
|
BadResponsesScorerConfig: &scorers.BadResponsesScorerConfig{
|
||||||
|
Threshold: 0,
|
||||||
|
},
|
||||||
|
},
|
||||||
|
})
|
||||||
|
|
||||||
|
addr, err := ma.NewMultiaddr("/ip4/127.0.0.1/tcp/33333")
|
||||||
|
require.NoError(t, err)
|
||||||
|
inbound := createPeer(t, p, addr, network.DirOutbound, peers.PeerConnected)
|
||||||
|
createPeer(t, p, addr, network.DirOutbound, peers.PeerConnecting)
|
||||||
|
|
||||||
|
result := p.OutboundConnected()
|
||||||
|
require.Equal(t, 1, len(result))
|
||||||
|
assert.Equal(t, inbound.String(), result[0].String())
|
||||||
|
}
|
||||||
|
|
||||||
|
func TestOutbondConnectedTCP(t *testing.T) {
|
||||||
|
p := peers.NewStatus(context.Background(), &peers.StatusConfig{
|
||||||
|
PeerLimit: 30,
|
||||||
|
ScorerParams: &scorers.Config{
|
||||||
|
BadResponsesScorerConfig: &scorers.BadResponsesScorerConfig{
|
||||||
|
Threshold: 0,
|
||||||
|
},
|
||||||
|
},
|
||||||
|
})
|
||||||
|
|
||||||
|
addrTCP, err := ma.NewMultiaddr("/ip4/127.0.0.1/tcp/33333")
|
||||||
|
require.NoError(t, err)
|
||||||
|
|
||||||
|
addrQUIC, err := ma.NewMultiaddr("/ip4/192.168.1.3/udp/13000/quic-v1")
|
||||||
|
require.NoError(t, err)
|
||||||
|
|
||||||
|
outboundTCP := createPeer(t, p, addrTCP, network.DirOutbound, peers.PeerConnected)
|
||||||
|
createPeer(t, p, addrQUIC, network.DirOutbound, peers.PeerConnected)
|
||||||
|
|
||||||
|
result := p.OutboundConnectedTCP()
|
||||||
|
require.Equal(t, 1, len(result))
|
||||||
|
assert.Equal(t, outboundTCP.String(), result[0].String())
|
||||||
|
}
|
||||||
|
|
||||||
|
func TestOutboundConnectedQUIC(t *testing.T) {
|
||||||
|
p := peers.NewStatus(context.Background(), &peers.StatusConfig{
|
||||||
|
PeerLimit: 30,
|
||||||
|
ScorerParams: &scorers.Config{
|
||||||
|
BadResponsesScorerConfig: &scorers.BadResponsesScorerConfig{
|
||||||
|
Threshold: 0,
|
||||||
|
},
|
||||||
|
},
|
||||||
|
})
|
||||||
|
|
||||||
|
addrQUIC, err := ma.NewMultiaddr("/ip4/192.168.1.3/udp/13000/quic-v1")
|
||||||
|
require.NoError(t, err)
|
||||||
|
|
||||||
|
addrTCP, err := ma.NewMultiaddr("/ip4/127.0.0.1/tcp/33333")
|
||||||
|
require.NoError(t, err)
|
||||||
|
|
||||||
|
outboundQUIC := createPeer(t, p, addrQUIC, network.DirOutbound, peers.PeerConnected)
|
||||||
|
createPeer(t, p, addrTCP, network.DirOutbound, peers.PeerConnected)
|
||||||
|
|
||||||
|
result := p.OutboundConnectedQUIC()
|
||||||
|
require.Equal(t, 1, len(result))
|
||||||
|
assert.Equal(t, outboundQUIC.String(), result[0].String())
|
||||||
|
}
|
||||||
|
|
||||||
// addPeer is a helper to add a peer with a given connection state)
|
// addPeer is a helper to add a peer with a given connection state)
|
||||||
func addPeer(t *testing.T, p *peers.Status, state peerdata.PeerConnectionState) peer.ID {
|
func addPeer(t *testing.T, p *peers.Status, state peerdata.PeerConnectionState) peer.ID {
|
||||||
// Set up some peers with different states
|
// Set up some peers with different states
|
||||||
|
|||||||
@@ -124,31 +124,34 @@ func NewService(ctx context.Context, cfg *Config) (*Service, error) {
|
|||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, errors.Wrapf(err, "failed to build p2p options")
|
return nil, errors.Wrapf(err, "failed to build p2p options")
|
||||||
}
|
}
|
||||||
|
|
||||||
// Sets mplex timeouts
|
// Sets mplex timeouts
|
||||||
configureMplex()
|
configureMplex()
|
||||||
h, err := libp2p.New(opts...)
|
h, err := libp2p.New(opts...)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.WithError(err).Error("Failed to create p2p host")
|
return nil, errors.Wrapf(err, "failed to create p2p host")
|
||||||
return nil, err
|
|
||||||
}
|
}
|
||||||
|
|
||||||
s.host = h
|
s.host = h
|
||||||
|
|
||||||
// Gossipsub registration is done before we add in any new peers
|
// Gossipsub registration is done before we add in any new peers
|
||||||
// due to libp2p's gossipsub implementation not taking into
|
// due to libp2p's gossipsub implementation not taking into
|
||||||
// account previously added peers when creating the gossipsub
|
// account previously added peers when creating the gossipsub
|
||||||
// object.
|
// object.
|
||||||
psOpts := s.pubsubOptions()
|
psOpts := s.pubsubOptions()
|
||||||
|
|
||||||
// Set the pubsub global parameters that we require.
|
// Set the pubsub global parameters that we require.
|
||||||
setPubSubParameters()
|
setPubSubParameters()
|
||||||
|
|
||||||
// Reinitialize them in the event we are running a custom config.
|
// Reinitialize them in the event we are running a custom config.
|
||||||
attestationSubnetCount = params.BeaconConfig().AttestationSubnetCount
|
attestationSubnetCount = params.BeaconConfig().AttestationSubnetCount
|
||||||
syncCommsSubnetCount = params.BeaconConfig().SyncCommitteeSubnetCount
|
syncCommsSubnetCount = params.BeaconConfig().SyncCommitteeSubnetCount
|
||||||
|
|
||||||
gs, err := pubsub.NewGossipSub(s.ctx, s.host, psOpts...)
|
gs, err := pubsub.NewGossipSub(s.ctx, s.host, psOpts...)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.WithError(err).Error("Failed to start pubsub")
|
return nil, errors.Wrapf(err, "failed to create p2p pubsub")
|
||||||
return nil, err
|
|
||||||
}
|
}
|
||||||
|
|
||||||
s.pubsub = gs
|
s.pubsub = gs
|
||||||
|
|
||||||
s.peers = peers.NewStatus(ctx, &peers.StatusConfig{
|
s.peers = peers.NewStatus(ctx, &peers.StatusConfig{
|
||||||
@@ -213,7 +216,7 @@ func (s *Service) Start() {
|
|||||||
if len(s.cfg.StaticPeers) > 0 {
|
if len(s.cfg.StaticPeers) > 0 {
|
||||||
addrs, err := PeersFromStringAddrs(s.cfg.StaticPeers)
|
addrs, err := PeersFromStringAddrs(s.cfg.StaticPeers)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.WithError(err).Error("Could not connect to static peer")
|
log.WithError(err).Error("could not convert ENR to multiaddr")
|
||||||
}
|
}
|
||||||
// Set trusted peers for those that are provided as static addresses.
|
// Set trusted peers for those that are provided as static addresses.
|
||||||
pids := peerIdsFromMultiAddrs(addrs)
|
pids := peerIdsFromMultiAddrs(addrs)
|
||||||
@@ -232,11 +235,19 @@ func (s *Service) Start() {
|
|||||||
async.RunEvery(s.ctx, time.Duration(params.BeaconConfig().RespTimeout)*time.Second, s.updateMetrics)
|
async.RunEvery(s.ctx, time.Duration(params.BeaconConfig().RespTimeout)*time.Second, s.updateMetrics)
|
||||||
async.RunEvery(s.ctx, refreshRate, s.RefreshENR)
|
async.RunEvery(s.ctx, refreshRate, s.RefreshENR)
|
||||||
async.RunEvery(s.ctx, 1*time.Minute, func() {
|
async.RunEvery(s.ctx, 1*time.Minute, func() {
|
||||||
|
inboundQUICCount := len(s.peers.InboundConnectedQUIC())
|
||||||
|
inboundTCPCount := len(s.peers.InboundConnectedTCP())
|
||||||
|
outboundQUICCount := len(s.peers.OutboundConnectedQUIC())
|
||||||
|
outboundTCPCount := len(s.peers.OutboundConnectedTCP())
|
||||||
|
total := inboundQUICCount + inboundTCPCount + outboundQUICCount + outboundTCPCount
|
||||||
|
|
||||||
log.WithFields(logrus.Fields{
|
log.WithFields(logrus.Fields{
|
||||||
"inbound": len(s.peers.InboundConnected()),
|
"inboundQUIC": inboundQUICCount,
|
||||||
"outbound": len(s.peers.OutboundConnected()),
|
"inboundTCP": inboundTCPCount,
|
||||||
"activePeers": len(s.peers.Active()),
|
"outboundQUIC": outboundQUICCount,
|
||||||
}).Info("Peer summary")
|
"outboundTCP": outboundTCPCount,
|
||||||
|
"total": total,
|
||||||
|
}).Info("Connected peers")
|
||||||
})
|
})
|
||||||
|
|
||||||
multiAddrs := s.host.Network().ListenAddresses()
|
multiAddrs := s.host.Network().ListenAddresses()
|
||||||
@@ -244,9 +255,10 @@ func (s *Service) Start() {
|
|||||||
|
|
||||||
p2pHostAddress := s.cfg.HostAddress
|
p2pHostAddress := s.cfg.HostAddress
|
||||||
p2pTCPPort := s.cfg.TCPPort
|
p2pTCPPort := s.cfg.TCPPort
|
||||||
|
p2pQUICPort := s.cfg.QUICPort
|
||||||
|
|
||||||
if p2pHostAddress != "" {
|
if p2pHostAddress != "" {
|
||||||
logExternalIPAddr(s.host.ID(), p2pHostAddress, p2pTCPPort)
|
logExternalIPAddr(s.host.ID(), p2pHostAddress, p2pTCPPort, p2pQUICPort)
|
||||||
verifyConnectivity(p2pHostAddress, p2pTCPPort, "tcp")
|
verifyConnectivity(p2pHostAddress, p2pTCPPort, "tcp")
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -102,8 +102,9 @@ func TestService_Start_OnlyStartsOnce(t *testing.T) {
|
|||||||
|
|
||||||
cs := startup.NewClockSynchronizer()
|
cs := startup.NewClockSynchronizer()
|
||||||
cfg := &Config{
|
cfg := &Config{
|
||||||
TCPPort: 2000,
|
|
||||||
UDPPort: 2000,
|
UDPPort: 2000,
|
||||||
|
TCPPort: 3000,
|
||||||
|
QUICPort: 3000,
|
||||||
ClockWaiter: cs,
|
ClockWaiter: cs,
|
||||||
}
|
}
|
||||||
s, err := NewService(context.Background(), cfg)
|
s, err := NewService(context.Background(), cfg)
|
||||||
@@ -147,8 +148,9 @@ func TestService_Start_NoDiscoverFlag(t *testing.T) {
|
|||||||
|
|
||||||
cs := startup.NewClockSynchronizer()
|
cs := startup.NewClockSynchronizer()
|
||||||
cfg := &Config{
|
cfg := &Config{
|
||||||
TCPPort: 2000,
|
|
||||||
UDPPort: 2000,
|
UDPPort: 2000,
|
||||||
|
TCPPort: 3000,
|
||||||
|
QUICPort: 3000,
|
||||||
StateNotifier: &mock.MockStateNotifier{},
|
StateNotifier: &mock.MockStateNotifier{},
|
||||||
NoDiscovery: true, // <-- no s.dv5Listener is created
|
NoDiscovery: true, // <-- no s.dv5Listener is created
|
||||||
ClockWaiter: cs,
|
ClockWaiter: cs,
|
||||||
|
|||||||
@@ -93,6 +93,11 @@ func (s *Service) FindPeersWithSubnet(ctx context.Context, topic string,
|
|||||||
if err != nil {
|
if err != nil {
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if info == nil {
|
||||||
|
continue
|
||||||
|
}
|
||||||
|
|
||||||
wg.Add(1)
|
wg.Add(1)
|
||||||
go func() {
|
go func() {
|
||||||
if err := s.connectWithPeer(ctx, *info); err != nil {
|
if err := s.connectWithPeer(ctx, *info); err != nil {
|
||||||
|
|||||||
@@ -66,7 +66,7 @@ func TestStartDiscV5_FindPeersWithSubnet(t *testing.T) {
|
|||||||
genesisTime := time.Now()
|
genesisTime := time.Now()
|
||||||
|
|
||||||
bootNodeService := &Service{
|
bootNodeService := &Service{
|
||||||
cfg: &Config{TCPPort: 2000, UDPPort: 3000},
|
cfg: &Config{UDPPort: 2000, TCPPort: 3000, QUICPort: 3000},
|
||||||
genesisTime: genesisTime,
|
genesisTime: genesisTime,
|
||||||
genesisValidatorsRoot: genesisValidatorsRoot,
|
genesisValidatorsRoot: genesisValidatorsRoot,
|
||||||
}
|
}
|
||||||
@@ -89,8 +89,9 @@ func TestStartDiscV5_FindPeersWithSubnet(t *testing.T) {
|
|||||||
service, err := NewService(ctx, &Config{
|
service, err := NewService(ctx, &Config{
|
||||||
Discv5BootStrapAddrs: []string{bootNodeENR},
|
Discv5BootStrapAddrs: []string{bootNodeENR},
|
||||||
MaxPeers: 30,
|
MaxPeers: 30,
|
||||||
TCPPort: uint(2000 + i),
|
UDPPort: uint(2000 + i),
|
||||||
UDPPort: uint(3000 + i),
|
TCPPort: uint(3000 + i),
|
||||||
|
QUICPort: uint(3000 + i),
|
||||||
})
|
})
|
||||||
|
|
||||||
require.NoError(t, err)
|
require.NoError(t, err)
|
||||||
@@ -133,8 +134,9 @@ func TestStartDiscV5_FindPeersWithSubnet(t *testing.T) {
|
|||||||
cfg := &Config{
|
cfg := &Config{
|
||||||
Discv5BootStrapAddrs: []string{bootNodeENR},
|
Discv5BootStrapAddrs: []string{bootNodeENR},
|
||||||
MaxPeers: 30,
|
MaxPeers: 30,
|
||||||
TCPPort: 2010,
|
UDPPort: 2010,
|
||||||
UDPPort: 3010,
|
TCPPort: 3010,
|
||||||
|
QUICPort: 3010,
|
||||||
}
|
}
|
||||||
|
|
||||||
service, err := NewService(ctx, cfg)
|
service, err := NewService(ctx, cfg)
|
||||||
|
|||||||
@@ -50,7 +50,7 @@ func ensurePeerConnections(ctx context.Context, h host.Host, peers *peers.Status
|
|||||||
c := h.Network().ConnsToPeer(p.ID)
|
c := h.Network().ConnsToPeer(p.ID)
|
||||||
if len(c) == 0 {
|
if len(c) == 0 {
|
||||||
if err := connectWithTimeout(ctx, h, p); err != nil {
|
if err := connectWithTimeout(ctx, h, p); err != nil {
|
||||||
log.WithField("peer", p.ID).WithField("addrs", p.Addrs).WithError(err).Errorf("Failed to reconnect to peer")
|
log.WithField("peer", p.ID).WithField("addrs", p.Addrs).WithError(err).Errorf("failed to reconnect to peer")
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -10,6 +10,7 @@ import (
|
|||||||
libp2pcore "github.com/libp2p/go-libp2p/core"
|
libp2pcore "github.com/libp2p/go-libp2p/core"
|
||||||
"github.com/libp2p/go-libp2p/core/network"
|
"github.com/libp2p/go-libp2p/core/network"
|
||||||
"github.com/libp2p/go-libp2p/core/protocol"
|
"github.com/libp2p/go-libp2p/core/protocol"
|
||||||
|
"github.com/multiformats/go-multiaddr"
|
||||||
ssz "github.com/prysmaticlabs/fastssz"
|
ssz "github.com/prysmaticlabs/fastssz"
|
||||||
"github.com/prysmaticlabs/prysm/v5/beacon-chain/p2p"
|
"github.com/prysmaticlabs/prysm/v5/beacon-chain/p2p"
|
||||||
p2ptypes "github.com/prysmaticlabs/prysm/v5/beacon-chain/p2p/types"
|
p2ptypes "github.com/prysmaticlabs/prysm/v5/beacon-chain/p2p/types"
|
||||||
@@ -142,7 +143,30 @@ func (s *Service) registerRPC(baseTopic string, handle rpcHandler) {
|
|||||||
// it successfully writes a response. We don't blindly call
|
// it successfully writes a response. We don't blindly call
|
||||||
// Close here because we may have only written a partial
|
// Close here because we may have only written a partial
|
||||||
// response.
|
// response.
|
||||||
|
// About the special case for quic-v1, please see:
|
||||||
|
// https://github.com/quic-go/quic-go/issues/3291
|
||||||
defer func() {
|
defer func() {
|
||||||
|
isQuic := false
|
||||||
|
multiaddr.ForEach(stream.Conn().RemoteMultiaddr(), func(c multiaddr.Component) bool {
|
||||||
|
pCode := c.Protocol().Code
|
||||||
|
if pCode == multiaddr.P_QUIC || pCode == multiaddr.P_QUIC_V1 {
|
||||||
|
isQuic = true
|
||||||
|
return false
|
||||||
|
}
|
||||||
|
return true
|
||||||
|
})
|
||||||
|
|
||||||
|
// We special case for QUIC connections as unlike yamux where a reset is a no-op for a successful close. An abrupt
|
||||||
|
// stream termination can lead to the remote peer dropping the inbound data. For that reason, we only reset streams
|
||||||
|
// in the event there is an error while closing them.
|
||||||
|
if isQuic {
|
||||||
|
if err := stream.Close(); err != nil {
|
||||||
|
_err := stream.Reset()
|
||||||
|
_ = _err
|
||||||
|
}
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
_err := stream.Reset()
|
_err := stream.Reset()
|
||||||
_ = _err
|
_ = _err
|
||||||
}()
|
}()
|
||||||
|
|||||||
@@ -90,6 +90,7 @@ var appFlags = []cli.Flag{
|
|||||||
cmd.StaticPeers,
|
cmd.StaticPeers,
|
||||||
cmd.RelayNode,
|
cmd.RelayNode,
|
||||||
cmd.P2PUDPPort,
|
cmd.P2PUDPPort,
|
||||||
|
cmd.P2PQUICPort,
|
||||||
cmd.P2PTCPPort,
|
cmd.P2PTCPPort,
|
||||||
cmd.P2PIP,
|
cmd.P2PIP,
|
||||||
cmd.P2PHost,
|
cmd.P2PHost,
|
||||||
|
|||||||
@@ -55,6 +55,7 @@ var appHelpFlagGroups = []flagGroup{
|
|||||||
cmd.BootstrapNode,
|
cmd.BootstrapNode,
|
||||||
cmd.RelayNode,
|
cmd.RelayNode,
|
||||||
cmd.P2PUDPPort,
|
cmd.P2PUDPPort,
|
||||||
|
cmd.P2PQUICPort,
|
||||||
cmd.P2PTCPPort,
|
cmd.P2PTCPPort,
|
||||||
cmd.DataDirFlag,
|
cmd.DataDirFlag,
|
||||||
cmd.VerbosityFlag,
|
cmd.VerbosityFlag,
|
||||||
|
|||||||
12
cmd/flags.go
12
cmd/flags.go
@@ -112,13 +112,19 @@ var (
|
|||||||
// P2PUDPPort defines the port to be used by discv5.
|
// P2PUDPPort defines the port to be used by discv5.
|
||||||
P2PUDPPort = &cli.IntFlag{
|
P2PUDPPort = &cli.IntFlag{
|
||||||
Name: "p2p-udp-port",
|
Name: "p2p-udp-port",
|
||||||
Usage: "The port used by discv5.",
|
Usage: "The UDP port used by the discovery service discv5.",
|
||||||
Value: 12000,
|
Value: 12000,
|
||||||
}
|
}
|
||||||
// P2PTCPPort defines the port to be used by libp2p.
|
// P2PQUICPort defines the QUIC port to be used by libp2p.
|
||||||
|
P2PQUICPort = &cli.IntFlag{
|
||||||
|
Name: "p2p-quic-port",
|
||||||
|
Usage: "The QUIC port used by libp2p.",
|
||||||
|
Value: 13000,
|
||||||
|
}
|
||||||
|
// P2PTCPPort defines the TCP port to be used by libp2p.
|
||||||
P2PTCPPort = &cli.IntFlag{
|
P2PTCPPort = &cli.IntFlag{
|
||||||
Name: "p2p-tcp-port",
|
Name: "p2p-tcp-port",
|
||||||
Usage: "The port used by libp2p.",
|
Usage: "The TCP port used by libp2p.",
|
||||||
Value: 13000,
|
Value: 13000,
|
||||||
}
|
}
|
||||||
// P2PIP defines the local IP to be used by libp2p.
|
// P2PIP defines the local IP to be used by libp2p.
|
||||||
|
|||||||
@@ -43,6 +43,7 @@ go_library(
|
|||||||
"@com_github_libp2p_go_libp2p//core/peer:go_default_library",
|
"@com_github_libp2p_go_libp2p//core/peer:go_default_library",
|
||||||
"@com_github_libp2p_go_libp2p//core/protocol:go_default_library",
|
"@com_github_libp2p_go_libp2p//core/protocol:go_default_library",
|
||||||
"@com_github_libp2p_go_libp2p//p2p/security/noise:go_default_library",
|
"@com_github_libp2p_go_libp2p//p2p/security/noise:go_default_library",
|
||||||
|
"@com_github_libp2p_go_libp2p//p2p/transport/quic:go_default_library",
|
||||||
"@com_github_libp2p_go_libp2p//p2p/transport/tcp:go_default_library",
|
"@com_github_libp2p_go_libp2p//p2p/transport/tcp:go_default_library",
|
||||||
"@com_github_pkg_errors//:go_default_library",
|
"@com_github_pkg_errors//:go_default_library",
|
||||||
"@com_github_prysmaticlabs_fastssz//:go_default_library",
|
"@com_github_prysmaticlabs_fastssz//:go_default_library",
|
||||||
|
|||||||
@@ -14,7 +14,8 @@ import (
|
|||||||
"github.com/libp2p/go-libp2p/core/peer"
|
"github.com/libp2p/go-libp2p/core/peer"
|
||||||
"github.com/libp2p/go-libp2p/core/protocol"
|
"github.com/libp2p/go-libp2p/core/protocol"
|
||||||
"github.com/libp2p/go-libp2p/p2p/security/noise"
|
"github.com/libp2p/go-libp2p/p2p/security/noise"
|
||||||
"github.com/libp2p/go-libp2p/p2p/transport/tcp"
|
libp2pquic "github.com/libp2p/go-libp2p/p2p/transport/quic"
|
||||||
|
libp2ptcp "github.com/libp2p/go-libp2p/p2p/transport/tcp"
|
||||||
"github.com/pkg/errors"
|
"github.com/pkg/errors"
|
||||||
ssz "github.com/prysmaticlabs/fastssz"
|
ssz "github.com/prysmaticlabs/fastssz"
|
||||||
"github.com/prysmaticlabs/go-bitfield"
|
"github.com/prysmaticlabs/go-bitfield"
|
||||||
@@ -43,7 +44,7 @@ type client struct {
|
|||||||
nodeClient pb.NodeClient
|
nodeClient pb.NodeClient
|
||||||
}
|
}
|
||||||
|
|
||||||
func newClient(beaconEndpoints []string, clientPort uint) (*client, error) {
|
func newClient(beaconEndpoints []string, tcpPort, quicPort uint) (*client, error) {
|
||||||
ipAdd := ipAddr()
|
ipAdd := ipAddr()
|
||||||
priv, err := privKey()
|
priv, err := privKey()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
@@ -53,15 +54,16 @@ func newClient(beaconEndpoints []string, clientPort uint) (*client, error) {
|
|||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, errors.Wrap(err, "could not set up p2p metadata")
|
return nil, errors.Wrap(err, "could not set up p2p metadata")
|
||||||
}
|
}
|
||||||
listen, err := p2p.MultiAddressBuilder(ipAdd.String(), clientPort)
|
multiaddrs, err := p2p.MultiAddressBuilder(ipAdd, tcpPort, quicPort)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, errors.Wrap(err, "could not set up listening multiaddr")
|
return nil, errors.Wrap(err, "could not set up listening multiaddr")
|
||||||
}
|
}
|
||||||
options := []libp2p.Option{
|
options := []libp2p.Option{
|
||||||
privKeyOption(priv),
|
privKeyOption(priv),
|
||||||
libp2p.ListenAddrs(listen),
|
libp2p.ListenAddrs(multiaddrs...),
|
||||||
libp2p.UserAgent(version.BuildData()),
|
libp2p.UserAgent(version.BuildData()),
|
||||||
libp2p.Transport(tcp.NewTCPTransport),
|
libp2p.Transport(libp2pquic.NewTransport),
|
||||||
|
libp2p.Transport(libp2ptcp.NewTCPTransport),
|
||||||
}
|
}
|
||||||
options = append(options, libp2p.Security(noise.ID, noise.New))
|
options = append(options, libp2p.Security(noise.ID, noise.New))
|
||||||
options = append(options, libp2p.Ping(false))
|
options = append(options, libp2p.Ping(false))
|
||||||
|
|||||||
@@ -22,11 +22,12 @@ import (
|
|||||||
)
|
)
|
||||||
|
|
||||||
var requestBlobsFlags = struct {
|
var requestBlobsFlags = struct {
|
||||||
Peers string
|
Peers string
|
||||||
ClientPort uint
|
ClientPortTCP uint
|
||||||
APIEndpoints string
|
ClientPortQUIC uint
|
||||||
StartSlot uint64
|
APIEndpoints string
|
||||||
Count uint64
|
StartSlot uint64
|
||||||
|
Count uint64
|
||||||
}{}
|
}{}
|
||||||
|
|
||||||
var requestBlobsCmd = &cli.Command{
|
var requestBlobsCmd = &cli.Command{
|
||||||
@@ -47,9 +48,16 @@ var requestBlobsCmd = &cli.Command{
|
|||||||
Value: "",
|
Value: "",
|
||||||
},
|
},
|
||||||
&cli.UintFlag{
|
&cli.UintFlag{
|
||||||
Name: "client-port",
|
Name: "client-port-tcp",
|
||||||
Usage: "port to use for the client as a libp2p host",
|
Aliases: []string{"client-port"},
|
||||||
Destination: &requestBlobsFlags.ClientPort,
|
Usage: "TCP port to use for the client as a libp2p host",
|
||||||
|
Destination: &requestBlobsFlags.ClientPortTCP,
|
||||||
|
Value: 13001,
|
||||||
|
},
|
||||||
|
&cli.UintFlag{
|
||||||
|
Name: "client-port-quic",
|
||||||
|
Usage: "QUIC port to use for the client as a libp2p host",
|
||||||
|
Destination: &requestBlobsFlags.ClientPortQUIC,
|
||||||
Value: 13001,
|
Value: 13001,
|
||||||
},
|
},
|
||||||
&cli.StringFlag{
|
&cli.StringFlag{
|
||||||
@@ -60,13 +68,13 @@ var requestBlobsCmd = &cli.Command{
|
|||||||
},
|
},
|
||||||
&cli.Uint64Flag{
|
&cli.Uint64Flag{
|
||||||
Name: "start-slot",
|
Name: "start-slot",
|
||||||
Usage: "start slot for blocks by range request. If unset, will use start_slot(current_epoch-1)",
|
Usage: "start slot for blobs by range request. If unset, will use start_slot(current_epoch-1)",
|
||||||
Destination: &requestBlobsFlags.StartSlot,
|
Destination: &requestBlobsFlags.StartSlot,
|
||||||
Value: 0,
|
Value: 0,
|
||||||
},
|
},
|
||||||
&cli.Uint64Flag{
|
&cli.Uint64Flag{
|
||||||
Name: "count",
|
Name: "count",
|
||||||
Usage: "number of blocks to request, (default 32)",
|
Usage: "number of blobs to request, (default 32)",
|
||||||
Destination: &requestBlobsFlags.Count,
|
Destination: &requestBlobsFlags.Count,
|
||||||
Value: 32,
|
Value: 32,
|
||||||
},
|
},
|
||||||
@@ -90,7 +98,7 @@ func cliActionRequestBlobs(cliCtx *cli.Context) error {
|
|||||||
allAPIEndpoints = strings.Split(requestBlobsFlags.APIEndpoints, ",")
|
allAPIEndpoints = strings.Split(requestBlobsFlags.APIEndpoints, ",")
|
||||||
}
|
}
|
||||||
var err error
|
var err error
|
||||||
c, err := newClient(allAPIEndpoints, requestBlobsFlags.ClientPort)
|
c, err := newClient(allAPIEndpoints, requestBlobsFlags.ClientPortTCP, requestBlobsFlags.ClientPortQUIC)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -23,12 +23,14 @@ import (
|
|||||||
)
|
)
|
||||||
|
|
||||||
var requestBlocksFlags = struct {
|
var requestBlocksFlags = struct {
|
||||||
Peers string
|
Network string
|
||||||
ClientPort uint
|
Peers string
|
||||||
APIEndpoints string
|
ClientPortTCP uint
|
||||||
StartSlot uint64
|
ClientPortQUIC uint
|
||||||
Count uint64
|
APIEndpoints string
|
||||||
Step uint64
|
StartSlot uint64
|
||||||
|
Count uint64
|
||||||
|
Step uint64
|
||||||
}{}
|
}{}
|
||||||
|
|
||||||
var requestBlocksCmd = &cli.Command{
|
var requestBlocksCmd = &cli.Command{
|
||||||
@@ -42,6 +44,12 @@ var requestBlocksCmd = &cli.Command{
|
|||||||
},
|
},
|
||||||
Flags: []cli.Flag{
|
Flags: []cli.Flag{
|
||||||
cmd.ChainConfigFileFlag,
|
cmd.ChainConfigFileFlag,
|
||||||
|
&cli.StringFlag{
|
||||||
|
Name: "network",
|
||||||
|
Usage: "network to run on (mainnet, sepolia, holesky)",
|
||||||
|
Destination: &requestBlocksFlags.Network,
|
||||||
|
Value: "mainnet",
|
||||||
|
},
|
||||||
&cli.StringFlag{
|
&cli.StringFlag{
|
||||||
Name: "peer-multiaddrs",
|
Name: "peer-multiaddrs",
|
||||||
Usage: "comma-separated, peer multiaddr(s) to connect to for p2p requests",
|
Usage: "comma-separated, peer multiaddr(s) to connect to for p2p requests",
|
||||||
@@ -49,9 +57,16 @@ var requestBlocksCmd = &cli.Command{
|
|||||||
Value: "",
|
Value: "",
|
||||||
},
|
},
|
||||||
&cli.UintFlag{
|
&cli.UintFlag{
|
||||||
Name: "client-port",
|
Name: "client-port-tcp",
|
||||||
Usage: "port to use for the client as a libp2p host",
|
Aliases: []string{"client-port"},
|
||||||
Destination: &requestBlocksFlags.ClientPort,
|
Usage: "TCP port to use for the client as a libp2p host",
|
||||||
|
Destination: &requestBlocksFlags.ClientPortTCP,
|
||||||
|
Value: 13001,
|
||||||
|
},
|
||||||
|
&cli.UintFlag{
|
||||||
|
Name: "client-port-quic",
|
||||||
|
Usage: "QUIC port to use for the client as a libp2p host",
|
||||||
|
Destination: &requestBlocksFlags.ClientPortQUIC,
|
||||||
Value: 13001,
|
Value: 13001,
|
||||||
},
|
},
|
||||||
&cli.StringFlag{
|
&cli.StringFlag{
|
||||||
@@ -82,6 +97,21 @@ var requestBlocksCmd = &cli.Command{
|
|||||||
}
|
}
|
||||||
|
|
||||||
func cliActionRequestBlocks(cliCtx *cli.Context) error {
|
func cliActionRequestBlocks(cliCtx *cli.Context) error {
|
||||||
|
switch requestBlocksFlags.Network {
|
||||||
|
case params.SepoliaName:
|
||||||
|
if err := params.SetActive(params.SepoliaConfig()); err != nil {
|
||||||
|
log.Fatal(err)
|
||||||
|
}
|
||||||
|
case params.HoleskyName:
|
||||||
|
if err := params.SetActive(params.HoleskyConfig()); err != nil {
|
||||||
|
log.Fatal(err)
|
||||||
|
}
|
||||||
|
case params.MainnetName:
|
||||||
|
// Do nothing
|
||||||
|
default:
|
||||||
|
log.Fatalf("Unknown network provided: %s", requestBlocksFlags.Network)
|
||||||
|
}
|
||||||
|
|
||||||
if cliCtx.IsSet(cmd.ChainConfigFileFlag.Name) {
|
if cliCtx.IsSet(cmd.ChainConfigFileFlag.Name) {
|
||||||
chainConfigFileName := cliCtx.String(cmd.ChainConfigFileFlag.Name)
|
chainConfigFileName := cliCtx.String(cmd.ChainConfigFileFlag.Name)
|
||||||
if err := params.LoadChainConfigFile(chainConfigFileName, nil); err != nil {
|
if err := params.LoadChainConfigFile(chainConfigFileName, nil); err != nil {
|
||||||
@@ -98,7 +128,7 @@ func cliActionRequestBlocks(cliCtx *cli.Context) error {
|
|||||||
allAPIEndpoints = strings.Split(requestBlocksFlags.APIEndpoints, ",")
|
allAPIEndpoints = strings.Split(requestBlocksFlags.APIEndpoints, ",")
|
||||||
}
|
}
|
||||||
var err error
|
var err error
|
||||||
c, err := newClient(allAPIEndpoints, requestBlocksFlags.ClientPort)
|
c, err := newClient(allAPIEndpoints, requestBlocksFlags.ClientPortTCP, requestBlocksFlags.ClientPortQUIC)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -109,8 +109,8 @@ var (
|
|||||||
}
|
}
|
||||||
enableDoppelGangerProtection = &cli.BoolFlag{
|
enableDoppelGangerProtection = &cli.BoolFlag{
|
||||||
Name: "enable-doppelganger",
|
Name: "enable-doppelganger",
|
||||||
Usage: `Enables the validator to perform a doppelganger check.
|
Usage: `Enables the validator to perform a doppelganger check.
|
||||||
This is not "a foolproof method to find duplicate instances in the network.
|
This is not a foolproof method to find duplicate instances in the network.
|
||||||
Your validator will still be vulnerable if it is being run in unsafe configurations.`,
|
Your validator will still be vulnerable if it is being run in unsafe configurations.`,
|
||||||
}
|
}
|
||||||
disableStakinContractCheck = &cli.BoolFlag{
|
disableStakinContractCheck = &cli.BoolFlag{
|
||||||
|
|||||||
@@ -257,6 +257,7 @@ func (node *BeaconNode) Start(ctx context.Context) error {
|
|||||||
fmt.Sprintf("--%s=%s", flags.ExecutionJWTSecretFlag.Name, jwtPath),
|
fmt.Sprintf("--%s=%s", flags.ExecutionJWTSecretFlag.Name, jwtPath),
|
||||||
fmt.Sprintf("--%s=%d", flags.MinSyncPeers.Name, 1),
|
fmt.Sprintf("--%s=%d", flags.MinSyncPeers.Name, 1),
|
||||||
fmt.Sprintf("--%s=%d", cmdshared.P2PUDPPort.Name, e2e.TestParams.Ports.PrysmBeaconNodeUDPPort+index),
|
fmt.Sprintf("--%s=%d", cmdshared.P2PUDPPort.Name, e2e.TestParams.Ports.PrysmBeaconNodeUDPPort+index),
|
||||||
|
fmt.Sprintf("--%s=%d", cmdshared.P2PQUICPort.Name, e2e.TestParams.Ports.PrysmBeaconNodeQUICPort+index),
|
||||||
fmt.Sprintf("--%s=%d", cmdshared.P2PTCPPort.Name, e2e.TestParams.Ports.PrysmBeaconNodeTCPPort+index),
|
fmt.Sprintf("--%s=%d", cmdshared.P2PTCPPort.Name, e2e.TestParams.Ports.PrysmBeaconNodeTCPPort+index),
|
||||||
fmt.Sprintf("--%s=%d", cmdshared.P2PMaxPeers.Name, expectedNumOfPeers),
|
fmt.Sprintf("--%s=%d", cmdshared.P2PMaxPeers.Name, expectedNumOfPeers),
|
||||||
fmt.Sprintf("--%s=%d", flags.MonitoringPortFlag.Name, e2e.TestParams.Ports.PrysmBeaconNodeMetricsPort+index),
|
fmt.Sprintf("--%s=%d", flags.MonitoringPortFlag.Name, e2e.TestParams.Ports.PrysmBeaconNodeMetricsPort+index),
|
||||||
@@ -313,7 +314,7 @@ func (node *BeaconNode) Start(ctx context.Context) error {
|
|||||||
}
|
}
|
||||||
|
|
||||||
if config.UseFixedPeerIDs {
|
if config.UseFixedPeerIDs {
|
||||||
peerId, err := helpers.FindFollowingTextInFile(stdOutFile, "Running node with peer id of ")
|
peerId, err := helpers.FindFollowingTextInFile(stdOutFile, "Running node with peerId=")
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return fmt.Errorf("could not find peer id: %w", err)
|
return fmt.Errorf("could not find peer id: %w", err)
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -46,6 +46,7 @@ type ports struct {
|
|||||||
Eth1ProxyPort int
|
Eth1ProxyPort int
|
||||||
PrysmBeaconNodeRPCPort int
|
PrysmBeaconNodeRPCPort int
|
||||||
PrysmBeaconNodeUDPPort int
|
PrysmBeaconNodeUDPPort int
|
||||||
|
PrysmBeaconNodeQUICPort int
|
||||||
PrysmBeaconNodeTCPPort int
|
PrysmBeaconNodeTCPPort int
|
||||||
PrysmBeaconNodeGatewayPort int
|
PrysmBeaconNodeGatewayPort int
|
||||||
PrysmBeaconNodeMetricsPort int
|
PrysmBeaconNodeMetricsPort int
|
||||||
@@ -144,10 +145,11 @@ const (
|
|||||||
|
|
||||||
PrysmBeaconNodeRPCPort = 4150
|
PrysmBeaconNodeRPCPort = 4150
|
||||||
PrysmBeaconNodeUDPPort = PrysmBeaconNodeRPCPort + portSpan
|
PrysmBeaconNodeUDPPort = PrysmBeaconNodeRPCPort + portSpan
|
||||||
PrysmBeaconNodeTCPPort = PrysmBeaconNodeRPCPort + 2*portSpan
|
PrysmBeaconNodeQUICPort = PrysmBeaconNodeRPCPort + 2*portSpan
|
||||||
PrysmBeaconNodeGatewayPort = PrysmBeaconNodeRPCPort + 3*portSpan
|
PrysmBeaconNodeTCPPort = PrysmBeaconNodeRPCPort + 3*portSpan
|
||||||
PrysmBeaconNodeMetricsPort = PrysmBeaconNodeRPCPort + 4*portSpan
|
PrysmBeaconNodeGatewayPort = PrysmBeaconNodeRPCPort + 4*portSpan
|
||||||
PrysmBeaconNodePprofPort = PrysmBeaconNodeRPCPort + 5*portSpan
|
PrysmBeaconNodeMetricsPort = PrysmBeaconNodeRPCPort + 5*portSpan
|
||||||
|
PrysmBeaconNodePprofPort = PrysmBeaconNodeRPCPort + 6*portSpan
|
||||||
|
|
||||||
LighthouseBeaconNodeP2PPort = 5150
|
LighthouseBeaconNodeP2PPort = 5150
|
||||||
LighthouseBeaconNodeHTTPPort = LighthouseBeaconNodeP2PPort + portSpan
|
LighthouseBeaconNodeHTTPPort = LighthouseBeaconNodeP2PPort + portSpan
|
||||||
@@ -330,6 +332,10 @@ func initializeStandardPorts(shardCount, shardIndex int, ports *ports, existingR
|
|||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
beaconNodeQUICPort, err := port(PrysmBeaconNodeQUICPort, shardCount, shardIndex, existingRegistrations)
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
beaconNodeTCPPort, err := port(PrysmBeaconNodeTCPPort, shardCount, shardIndex, existingRegistrations)
|
beaconNodeTCPPort, err := port(PrysmBeaconNodeTCPPort, shardCount, shardIndex, existingRegistrations)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
@@ -367,6 +373,7 @@ func initializeStandardPorts(shardCount, shardIndex int, ports *ports, existingR
|
|||||||
ports.Eth1ProxyPort = eth1ProxyPort
|
ports.Eth1ProxyPort = eth1ProxyPort
|
||||||
ports.PrysmBeaconNodeRPCPort = beaconNodeRPCPort
|
ports.PrysmBeaconNodeRPCPort = beaconNodeRPCPort
|
||||||
ports.PrysmBeaconNodeUDPPort = beaconNodeUDPPort
|
ports.PrysmBeaconNodeUDPPort = beaconNodeUDPPort
|
||||||
|
ports.PrysmBeaconNodeQUICPort = beaconNodeQUICPort
|
||||||
ports.PrysmBeaconNodeTCPPort = beaconNodeTCPPort
|
ports.PrysmBeaconNodeTCPPort = beaconNodeTCPPort
|
||||||
ports.PrysmBeaconNodeGatewayPort = beaconNodeGatewayPort
|
ports.PrysmBeaconNodeGatewayPort = beaconNodeGatewayPort
|
||||||
ports.PrysmBeaconNodeMetricsPort = beaconNodeMetricsPort
|
ports.PrysmBeaconNodeMetricsPort = beaconNodeMetricsPort
|
||||||
|
|||||||
@@ -30,7 +30,7 @@ func TestStandardPorts(t *testing.T) {
|
|||||||
var existingRegistrations []int
|
var existingRegistrations []int
|
||||||
testPorts := &ports{}
|
testPorts := &ports{}
|
||||||
assert.NoError(t, initializeStandardPorts(2, 0, testPorts, &existingRegistrations))
|
assert.NoError(t, initializeStandardPorts(2, 0, testPorts, &existingRegistrations))
|
||||||
assert.Equal(t, 16, len(existingRegistrations))
|
assert.Equal(t, 17, len(existingRegistrations))
|
||||||
assert.NotEqual(t, 0, testPorts.PrysmBeaconNodeGatewayPort)
|
assert.NotEqual(t, 0, testPorts.PrysmBeaconNodeGatewayPort)
|
||||||
assert.NotEqual(t, 0, testPorts.PrysmBeaconNodeTCPPort)
|
assert.NotEqual(t, 0, testPorts.PrysmBeaconNodeTCPPort)
|
||||||
assert.NotEqual(t, 0, testPorts.JaegerTracingPort)
|
assert.NotEqual(t, 0, testPorts.JaegerTracingPort)
|
||||||
|
|||||||
Reference in New Issue
Block a user