Skip to content

Commit

Permalink
Move AppGossip configs from SubnetConfig into ChainConfig (#2785)
Browse files Browse the repository at this point in the history
  • Loading branch information
StephenButtolph authored Feb 29, 2024
1 parent c5da946 commit e9ca612
Show file tree
Hide file tree
Showing 33 changed files with 336 additions and 173 deletions.
3 changes: 0 additions & 3 deletions config/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -271,9 +271,6 @@ func getGossipConfig(v *viper.Viper) subnets.GossipConfig {
OnAcceptValidatorSize: uint(v.GetUint32(ConsensusGossipOnAcceptValidatorSizeKey)),
OnAcceptNonValidatorSize: uint(v.GetUint32(ConsensusGossipOnAcceptNonValidatorSizeKey)),
OnAcceptPeerSize: uint(v.GetUint32(ConsensusGossipOnAcceptPeerSizeKey)),
AppGossipValidatorSize: uint(v.GetUint32(AppGossipValidatorSizeKey)),
AppGossipNonValidatorSize: uint(v.GetUint32(AppGossipNonValidatorSizeKey)),
AppGossipPeerSize: uint(v.GetUint32(AppGossipPeerSizeKey)),
}
}

Expand Down
9 changes: 5 additions & 4 deletions config/config_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ import (
"github.com/ava-labs/avalanchego/ids"
"github.com/ava-labs/avalanchego/snow/consensus/snowball"
"github.com/ava-labs/avalanchego/subnets"
"github.com/ava-labs/avalanchego/utils/constants"
)

func TestGetChainConfigsFromFiles(t *testing.T) {
Expand Down Expand Up @@ -421,15 +422,15 @@ func TestGetSubnetConfigsFromFile(t *testing.T) {
},
"gossip config": {
fileName: "2Ctt6eGAeo4MLqTmGa7AdRecuVMPGWEX9wSsCLBYrLhX4a394i.json",
givenJSON: `{"appGossipNonValidatorSize": 100 }`,
givenJSON: `{"gossipOnAcceptValidatorSize": 100 }`,
testF: func(require *require.Assertions, given map[ids.ID]subnets.Config) {
id, _ := ids.FromString("2Ctt6eGAeo4MLqTmGa7AdRecuVMPGWEX9wSsCLBYrLhX4a394i")
config, ok := given[id]
require.True(ok)
require.Equal(uint(100), config.GossipConfig.AppGossipNonValidatorSize)
require.Equal(uint(100), config.GossipConfig.OnAcceptValidatorSize)
// must still respect defaults
require.Equal(20, config.ConsensusParameters.K)
require.Equal(uint(10), config.GossipConfig.AppGossipValidatorSize)
require.Equal(uint(constants.DefaultConsensusGossipOnAcceptPeerSize), config.GossipConfig.OnAcceptPeerSize)
},
expectedErr: nil,
},
Expand Down Expand Up @@ -527,7 +528,7 @@ func TestGetSubnetConfigsFromFlags(t *testing.T) {
require.Equal(20, config.ConsensusParameters.AlphaConfidence)
require.Equal(30, config.ConsensusParameters.K)
// must still respect defaults
require.Equal(uint(10), config.GossipConfig.AppGossipValidatorSize)
require.Equal(uint(constants.DefaultConsensusGossipAcceptedFrontierPeerSize), config.GossipConfig.AcceptedFrontierPeerSize)
require.Equal(256, config.ConsensusParameters.MaxOutstandingItems)
},
expectedErr: nil,
Expand Down
3 changes: 0 additions & 3 deletions config/flags.go
Original file line number Diff line number Diff line change
Expand Up @@ -193,9 +193,6 @@ func addNodeFlags(fs *pflag.FlagSet) {
fs.Uint(ConsensusGossipOnAcceptValidatorSizeKey, constants.DefaultConsensusGossipOnAcceptValidatorSize, "Number of validators to gossip to each accepted container to")
fs.Uint(ConsensusGossipOnAcceptNonValidatorSizeKey, constants.DefaultConsensusGossipOnAcceptNonValidatorSize, "Number of non-validators to gossip to each accepted container to")
fs.Uint(ConsensusGossipOnAcceptPeerSizeKey, constants.DefaultConsensusGossipOnAcceptPeerSize, "Number of peers to gossip to each accepted container to")
fs.Uint(AppGossipValidatorSizeKey, constants.DefaultAppGossipValidatorSize, "Number of validators to gossip an AppGossip message to")
fs.Uint(AppGossipNonValidatorSizeKey, constants.DefaultAppGossipNonValidatorSize, "Number of non-validators to gossip an AppGossip message to")
fs.Uint(AppGossipPeerSizeKey, constants.DefaultAppGossipPeerSize, "Number of peers (which may be validators or non-validators) to gossip an AppGossip message to")

// Inbound Throttling
fs.Uint64(InboundThrottlerAtLargeAllocSizeKey, constants.DefaultInboundThrottlerAtLargeAllocSize, "Size, in bytes, of at-large byte allocation in inbound message throttler")
Expand Down
3 changes: 0 additions & 3 deletions config/keys.go
Original file line number Diff line number Diff line change
Expand Up @@ -151,9 +151,6 @@ const (
ConsensusGossipOnAcceptValidatorSizeKey = "consensus-on-accept-gossip-validator-size"
ConsensusGossipOnAcceptNonValidatorSizeKey = "consensus-on-accept-gossip-non-validator-size"
ConsensusGossipOnAcceptPeerSizeKey = "consensus-on-accept-gossip-peer-size"
AppGossipValidatorSizeKey = "consensus-app-gossip-validator-size"
AppGossipNonValidatorSizeKey = "consensus-app-gossip-non-validator-size"
AppGossipPeerSizeKey = "consensus-app-gossip-peer-size"
ProposerVMUseCurrentHeightKey = "proposervm-use-current-height"
FdLimitKey = "fd-limit"
IndexEnabledKey = "index-enabled"
Expand Down
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ go 1.21
require (
github.com/DataDog/zstd v1.5.2
github.com/NYTimes/gziphandler v1.1.1
github.com/ava-labs/coreth v0.13.1-rc.1
github.com/ava-labs/coreth v0.13.1-rc.3
github.com/ava-labs/ledger-avalanche/go v0.0.0-20231102202641-ae2ebdaeac34
github.com/btcsuite/btcd/btcutil v1.1.3
github.com/cockroachdb/pebble v0.0.0-20230209160836-829675f94811
Expand Down
4 changes: 2 additions & 2 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -63,8 +63,8 @@ github.com/alecthomas/units v0.0.0-20151022065526-2efee857e7cf/go.mod h1:ybxpYRF
github.com/allegro/bigcache v1.2.1-0.20190218064605-e24eb225f156 h1:eMwmnE/GDgah4HI848JfFxHt+iPb26b4zyfspmqY0/8=
github.com/allegro/bigcache v1.2.1-0.20190218064605-e24eb225f156/go.mod h1:Cb/ax3seSYIx7SuZdm2G2xzfwmv3TPSk2ucNfQESPXM=
github.com/armon/consul-api v0.0.0-20180202201655-eb2c6b5be1b6/go.mod h1:grANhF5doyWs3UAsr3K4I6qtAmlQcZDesFNEHPZAzj8=
github.com/ava-labs/coreth v0.13.1-rc.1 h1:T838dWZicYXrajXBeLbJTat5rtSXkZisOZ0qcHTEVjM=
github.com/ava-labs/coreth v0.13.1-rc.1/go.mod h1:LzD4pI5AjkPS3r86e36Xpt6PZB2pZ/wUS4Vn8kJwWmY=
github.com/ava-labs/coreth v0.13.1-rc.3 h1:d32AzRI5HLwfFEevhR/RU4QPRjdl7LIMvPxTwlMlsmM=
github.com/ava-labs/coreth v0.13.1-rc.3/go.mod h1:J1boUw9u7S3JrisnJ81PvrhhyZUBnS4WuxSeMtTuVU0=
github.com/ava-labs/ledger-avalanche/go v0.0.0-20231102202641-ae2ebdaeac34 h1:mg9Uw6oZFJKytJxgxnl3uxZOs/SB8CVHg6Io4Tf99Zc=
github.com/ava-labs/ledger-avalanche/go v0.0.0-20231102202641-ae2ebdaeac34/go.mod h1:pJxaT9bUgeRNVmNRgtCHb7sFDIRKy7CzTQVi8gGNT6g=
github.com/aymerick/raymond v2.0.3-0.20180322193309-b565731e1464+incompatible/go.mod h1:osfaiScAUVup+UC9Nfq76eWqDhXlp+4UYaA8uhTBO6g=
Expand Down
6 changes: 6 additions & 0 deletions network/p2p/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -109,10 +109,16 @@ func (c *Client) AppRequest(
func (c *Client) AppGossip(
ctx context.Context,
appGossipBytes []byte,
numValidators int,
numNonValidators int,
numPeers int,
) error {
return c.sender.SendAppGossip(
ctx,
PrefixMessage(c.handlerPrefix, appGossipBytes),
numValidators,
numNonValidators,
numPeers,
)
}

Expand Down
33 changes: 29 additions & 4 deletions network/p2p/gossip/gossip.go
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,10 @@ var (
typeLabel: sentType,
}

ErrInvalidNumValidators = errors.New("num validators cannot be negative")
ErrInvalidNumNonValidators = errors.New("num non-validators cannot be negative")
ErrInvalidNumPeers = errors.New("num peers cannot be negative")
ErrInvalidNumToGossip = errors.New("must gossip to at least one peer")
ErrInvalidDiscardedSize = errors.New("discarded size cannot be negative")
ErrInvalidTargetGossipSize = errors.New("target gossip size cannot be negative")
ErrInvalidRegossipFrequency = errors.New("re-gossip frequency cannot be negative")
Expand Down Expand Up @@ -259,11 +263,22 @@ func NewPushGossiper[T Gossipable](
mempool Set[T],
client *p2p.Client,
metrics Metrics,
numValidators int,
numNonValidators int,
numPeers int,
discardedSize int,
targetGossipSize int,
maxRegossipFrequency time.Duration,
) (*PushGossiper[T], error) {
switch {
case numValidators < 0:
return nil, ErrInvalidNumValidators
case numNonValidators < 0:
return nil, ErrInvalidNumNonValidators
case numPeers < 0:
return nil, ErrInvalidNumPeers
case max(numValidators, numNonValidators, numPeers) == 0:
return nil, ErrInvalidNumToGossip
case discardedSize < 0:
return nil, ErrInvalidDiscardedSize
case targetGossipSize < 0:
Expand All @@ -277,6 +292,9 @@ func NewPushGossiper[T Gossipable](
set: mempool,
client: client,
metrics: metrics,
numValidators: numValidators,
numNonValidators: numNonValidators,
numPeers: numPeers,
targetGossipSize: targetGossipSize,
maxRegossipFrequency: maxRegossipFrequency,

Expand All @@ -294,6 +312,9 @@ type PushGossiper[T Gossipable] struct {
client *p2p.Client
metrics Metrics

numValidators int
numNonValidators int
numPeers int
targetGossipSize int
maxRegossipFrequency time.Duration

Expand Down Expand Up @@ -423,10 +444,14 @@ func (p *PushGossiper[T]) Gossip(ctx context.Context) error {
}
sentCountMetric.Add(float64(len(gossip)))
sentBytesMetric.Add(float64(sentBytes))
if err := p.client.AppGossip(ctx, msgBytes); err != nil {
return fmt.Errorf("failed to gossip: %w", err)
}
return nil

return p.client.AppGossip(
ctx,
msgBytes,
p.numValidators,
p.numNonValidators,
p.numPeers,
)
}

// Add enqueues new gossipables to be pushed. If a gossiable is already tracked,
Expand Down
53 changes: 43 additions & 10 deletions network/p2p/gossip/gossip_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -235,39 +235,69 @@ func TestValidatorGossiper(t *testing.T) {
func TestPushGossiperNew(t *testing.T) {
tests := []struct {
name string
numValidators int
numNonValidators int
numPeers int
discardedSize int
targetGossipSize int
maxRegossipFrequency time.Duration
expected error
}{
{
name: "invalid num validators",
numValidators: -1,
expected: ErrInvalidNumValidators,
},
{
name: "invalid num non-validators",
numNonValidators: -1,
expected: ErrInvalidNumNonValidators,
},
{
name: "invalid num peers",
numPeers: -1,
expected: ErrInvalidNumPeers,
},
{
name: "invalid num to gossip",
expected: ErrInvalidNumToGossip,
},
{
name: "invalid discarded size",
numValidators: 1,
discardedSize: -1,
expected: ErrInvalidDiscardedSize,
},
{
name: "invalid target gossip size",
numValidators: 1,
targetGossipSize: -1,
expected: ErrInvalidTargetGossipSize,
},
{
name: "invalid max re-gossip frequency",
numValidators: 1,
maxRegossipFrequency: -1,
expected: ErrInvalidRegossipFrequency,
},
}

for _, tt := range tests {
_, err := NewPushGossiper[*testTx](
nil,
nil,
nil,
Metrics{},
tt.discardedSize,
tt.targetGossipSize,
tt.maxRegossipFrequency,
)
require.ErrorIs(t, err, tt.expected)
t.Run(tt.name, func(t *testing.T) {
_, err := NewPushGossiper[*testTx](
nil,
nil,
nil,
Metrics{},
tt.numValidators,
tt.numNonValidators,
tt.numPeers,
tt.discardedSize,
tt.targetGossipSize,
tt.maxRegossipFrequency,
)
require.ErrorIs(t, err, tt.expected)
})
}
}

Expand Down Expand Up @@ -417,6 +447,9 @@ func TestPushGossiper(t *testing.T) {
FullSet[*testTx]{},
client,
metrics,
1,
0,
0,
0, // the discarded cache size doesn't matter for this test
units.MiB,
regossipTime,
Expand Down
4 changes: 2 additions & 2 deletions network/p2p/network_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ func TestMessageRouting(t *testing.T) {
require.NoError(network.AddHandler(1, testHandler))
client := network.NewClient(1)

require.NoError(client.AppGossip(ctx, wantMsg))
require.NoError(client.AppGossip(ctx, wantMsg, 0, 0, 1))
require.NoError(network.AppGossip(ctx, wantNodeID, <-sender.SentAppGossip))
require.True(appGossipCalled)

Expand Down Expand Up @@ -129,7 +129,7 @@ func TestClientPrefixesMessages(t *testing.T) {
require.Equal(handlerPrefix, gotCrossChainAppRequest[0])
require.Equal(want, gotCrossChainAppRequest[1:])

require.NoError(client.AppGossip(ctx, want))
require.NoError(client.AppGossip(ctx, want, 0, 0, 1))
gotAppGossip := <-sender.SentAppGossip
require.Equal(handlerPrefix, gotAppGossip[0])
require.Equal(want, gotAppGossip[1:])
Expand Down
3 changes: 3 additions & 0 deletions proto/appsender/appsender.proto
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,9 @@ message SendAppErrorMsg {
message SendAppGossipMsg {
// The message body
bytes msg = 1;
uint64 num_validators = 2;
uint64 num_non_validators = 3;
uint64 num_peers = 4;
}

message SendAppGossipSpecificMsg {
Expand Down
Loading

0 comments on commit e9ca612

Please sign in to comment.