Skip to content

Commit

Permalink
Replace PeerListAck with GetPeerList (#2580)
Browse files Browse the repository at this point in the history
  • Loading branch information
StephenButtolph committed Jan 14, 2024
1 parent a6ee978 commit 864dbec
Show file tree
Hide file tree
Showing 30 changed files with 2,142 additions and 2,211 deletions.
6 changes: 6 additions & 0 deletions config/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -427,6 +427,8 @@ func getNetworkConfig(
PeerListNonValidatorGossipSize: v.GetUint32(NetworkPeerListNonValidatorGossipSizeKey),
PeerListPeersGossipSize: v.GetUint32(NetworkPeerListPeersGossipSizeKey),
PeerListGossipFreq: v.GetDuration(NetworkPeerListGossipFreqKey),
PeerListPullGossipFreq: v.GetDuration(NetworkPeerListPullGossipFreqKey),
PeerListBloomResetFreq: v.GetDuration(NetworkPeerListBloomResetFreqKey),
},

DelayConfig: network.DelayConfig{
Expand Down Expand Up @@ -462,6 +464,10 @@ func getNetworkConfig(
return network.Config{}, fmt.Errorf("%q must be >= 0", NetworkOutboundConnectionTimeoutKey)
case config.PeerListGossipFreq < 0:
return network.Config{}, fmt.Errorf("%s must be >= 0", NetworkPeerListGossipFreqKey)
case config.PeerListPullGossipFreq < 0:
return network.Config{}, fmt.Errorf("%s must be >= 0", NetworkPeerListPullGossipFreqKey)
case config.PeerListBloomResetFreq < 0:
return network.Config{}, fmt.Errorf("%s must be >= 0", NetworkPeerListBloomResetFreqKey)
case config.ThrottlerConfig.InboundMsgThrottlerConfig.CPUThrottlerConfig.MaxRecheckDelay < constants.MinInboundThrottlerMaxRecheckDelay:
return network.Config{}, fmt.Errorf("%s must be >= %d", InboundThrottlerCPUMaxRecheckDelayKey, constants.MinInboundThrottlerMaxRecheckDelay)
case config.ThrottlerConfig.InboundMsgThrottlerConfig.DiskThrottlerConfig.MaxRecheckDelay < constants.MinInboundThrottlerMaxRecheckDelay:
Expand Down
2 changes: 2 additions & 0 deletions config/flags.go
Original file line number Diff line number Diff line change
Expand Up @@ -132,6 +132,8 @@ func addNodeFlags(fs *pflag.FlagSet) {
fs.Uint(NetworkPeerListNonValidatorGossipSizeKey, constants.DefaultNetworkPeerListNonValidatorGossipSize, "Number of non-validators that the node will gossip peer list to")
fs.Uint(NetworkPeerListPeersGossipSizeKey, constants.DefaultNetworkPeerListPeersGossipSize, "Number of total peers (including non-validators and validators) that the node will gossip peer list to")
fs.Duration(NetworkPeerListGossipFreqKey, constants.DefaultNetworkPeerListGossipFreq, "Frequency to gossip peers to other nodes")
fs.Duration(NetworkPeerListPullGossipFreqKey, constants.DefaultNetworkPeerListPullGossipFreq, "Frequency to request peers from other nodes")
fs.Duration(NetworkPeerListBloomResetFreqKey, constants.DefaultNetworkPeerListBloomResetFreq, "Frequency to recalculate the bloom filter used to request new peers from other nodes")

// Public IP Resolution
fs.String(PublicIPKey, "", "Public IP of this node for P2P communication")
Expand Down
2 changes: 2 additions & 0 deletions config/keys.go
Original file line number Diff line number Diff line change
Expand Up @@ -94,6 +94,8 @@ const (
NetworkPeerListNonValidatorGossipSizeKey = "network-peer-list-non-validator-gossip-size"
NetworkPeerListPeersGossipSizeKey = "network-peer-list-peers-gossip-size"
NetworkPeerListGossipFreqKey = "network-peer-list-gossip-frequency"
NetworkPeerListPullGossipFreqKey = "network-peer-list-pull-gossip-frequency"
NetworkPeerListBloomResetFreqKey = "network-peer-list-bloom-reset-frequency"
NetworkInitialReconnectDelayKey = "network-initial-reconnect-delay"
NetworkReadHandshakeTimeoutKey = "network-read-handshake-timeout"
NetworkPingTimeoutKey = "network-ping-timeout"
Expand Down
9 changes: 7 additions & 2 deletions genesis/bootstrappers.go
Original file line number Diff line number Diff line change
Expand Up @@ -36,10 +36,15 @@ type Bootstrapper struct {
IP ips.IPDesc `json:"ip"`
}

// GetBootstrappers returns all default bootstrappers for the provided network.
func GetBootstrappers(networkID uint32) []Bootstrapper {
networkName := constants.NetworkIDToNetworkName[networkID]
return bootstrappersPerNetwork[networkName]
}

// SampleBootstrappers returns the some beacons this node should connect to
func SampleBootstrappers(networkID uint32, count int) []Bootstrapper {
networkName := constants.NetworkIDToNetworkName[networkID]
bootstrappers := bootstrappersPerNetwork[networkName]
bootstrappers := GetBootstrappers(networkID)
count = math.Min(count, len(bootstrappers))

s := sampler.NewUniform()
Expand Down
87 changes: 60 additions & 27 deletions message/messages_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -142,12 +142,63 @@ func TestMessage(t *testing.T) {
bypassThrottling: true,
bytesSaved: false,
},
{
desc: "get_peer_list message with no compression",
op: GetPeerListOp,
msg: &p2p.Message{
Message: &p2p.Message_GetPeerList{
GetPeerList: &p2p.GetPeerList{
KnownPeers: &p2p.BloomFilter{
Filter: make([]byte, 2048),
Salt: make([]byte, 32),
},
},
},
},
compressionType: compression.TypeNone,
bypassThrottling: false,
bytesSaved: false,
},
{
desc: "get_peer_list message with gzip compression",
op: GetPeerListOp,
msg: &p2p.Message{
Message: &p2p.Message_GetPeerList{
GetPeerList: &p2p.GetPeerList{
KnownPeers: &p2p.BloomFilter{
Filter: make([]byte, 2048),
Salt: make([]byte, 32),
},
},
},
},
compressionType: compression.TypeGzip,
bypassThrottling: false,
bytesSaved: true,
},
{
desc: "get_peer_list message with zstd compression",
op: GetPeerListOp,
msg: &p2p.Message{
Message: &p2p.Message_GetPeerList{
GetPeerList: &p2p.GetPeerList{
KnownPeers: &p2p.BloomFilter{
Filter: make([]byte, 2048),
Salt: make([]byte, 32),
},
},
},
},
compressionType: compression.TypeZstd,
bypassThrottling: false,
bytesSaved: true,
},
{
desc: "peer_list message with no compression",
op: PeerListOp,
msg: &p2p.Message{
Message: &p2p.Message_PeerList{
PeerList: &p2p.PeerList{
Message: &p2p.Message_PeerList_{
PeerList_: &p2p.PeerList{
ClaimedIpPorts: []*p2p.ClaimedIpPort{
{
X509Certificate: testTLSCert.Certificate[0],
Expand All @@ -168,8 +219,8 @@ func TestMessage(t *testing.T) {
desc: "peer_list message with gzip compression",
op: PeerListOp,
msg: &p2p.Message{
Message: &p2p.Message_PeerList{
PeerList: &p2p.PeerList{
Message: &p2p.Message_PeerList_{
PeerList_: &p2p.PeerList{
ClaimedIpPorts: []*p2p.ClaimedIpPort{
{
X509Certificate: testTLSCert.Certificate[0],
Expand All @@ -190,8 +241,8 @@ func TestMessage(t *testing.T) {
desc: "peer_list message with zstd compression",
op: PeerListOp,
msg: &p2p.Message{
Message: &p2p.Message_PeerList{
PeerList: &p2p.PeerList{
Message: &p2p.Message_PeerList_{
PeerList_: &p2p.PeerList{
ClaimedIpPorts: []*p2p.ClaimedIpPort{
{
X509Certificate: testTLSCert.Certificate[0],
Expand All @@ -208,25 +259,6 @@ func TestMessage(t *testing.T) {
bypassThrottling: true,
bytesSaved: true,
},
{
desc: "peer_list_ack message with no compression",
op: PeerListAckOp,
msg: &p2p.Message{
Message: &p2p.Message_PeerListAck{
PeerListAck: &p2p.PeerListAck{
PeerAcks: []*p2p.PeerAck{
{
TxId: testID[:],
Timestamp: 1,
},
},
},
},
},
compressionType: compression.TypeNone,
bypassThrottling: false,
bytesSaved: false,
},
{
desc: "get_state_summary_frontier message with no compression",
op: GetStateSummaryFrontierOp,
Expand Down Expand Up @@ -836,8 +868,9 @@ func TestMessage(t *testing.T) {
require.Equal(tv.bypassThrottling, encodedMsg.BypassThrottling())
require.Equal(tv.op, encodedMsg.Op())

bytesSaved := encodedMsg.BytesSavedCompression()
require.Equal(tv.bytesSaved, bytesSaved > 0)
if bytesSaved := encodedMsg.BytesSavedCompression(); tv.bytesSaved {
require.Greater(bytesSaved, 0)
}

parsedMsg, err := mb.parseInbound(encodedMsg.Bytes(), ids.EmptyNodeID, func() {})
require.NoError(err)
Expand Down
40 changes: 20 additions & 20 deletions message/mock_outbound_message_builder.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

22 changes: 11 additions & 11 deletions message/ops.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,8 @@ const (
PingOp Op = iota
PongOp
HandshakeOp
GetPeerListOp
PeerListOp
PeerListAckOp
// State sync:
GetStateSummaryFrontierOp
GetStateSummaryFrontierFailedOp
Expand Down Expand Up @@ -72,8 +72,8 @@ var (
PingOp,
PongOp,
HandshakeOp,
GetPeerListOp,
PeerListOp,
PeerListAckOp,
}

// List of all consensus request message types
Expand Down Expand Up @@ -211,10 +211,10 @@ func (op Op) String() string {
return "pong"
case HandshakeOp:
return "handshake"
case GetPeerListOp:
return "get_peerlist"
case PeerListOp:
return "peerlist"
case PeerListAckOp:
return "peerlist_ack"
// State sync
case GetStateSummaryFrontierOp:
return "get_state_summary_frontier"
Expand Down Expand Up @@ -305,10 +305,10 @@ func Unwrap(m *p2p.Message) (fmt.Stringer, error) {
return msg.Pong, nil
case *p2p.Message_Handshake:
return msg.Handshake, nil
case *p2p.Message_PeerList:
return msg.PeerList, nil
case *p2p.Message_PeerListAck:
return msg.PeerListAck, nil
case *p2p.Message_GetPeerList:
return msg.GetPeerList, nil
case *p2p.Message_PeerList_:
return msg.PeerList_, nil
// State sync:
case *p2p.Message_GetStateSummaryFrontier:
return msg.GetStateSummaryFrontier, nil
Expand Down Expand Up @@ -364,10 +364,10 @@ func ToOp(m *p2p.Message) (Op, error) {
return PongOp, nil
case *p2p.Message_Handshake:
return HandshakeOp, nil
case *p2p.Message_PeerList:
case *p2p.Message_GetPeerList:
return GetPeerListOp, nil
case *p2p.Message_PeerList_:
return PeerListOp, nil
case *p2p.Message_PeerListAck:
return PeerListAckOp, nil
case *p2p.Message_GetStateSummaryFrontier:
return GetStateSummaryFrontierOp, nil
case *p2p.Message_StateSummaryFrontier_:
Expand Down

0 comments on commit 864dbec

Please sign in to comment.