diff --git a/go.mod b/go.mod index efbeb89be378..ecb2d4c8abcd 100644 --- a/go.mod +++ b/go.mod @@ -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.3 + github.com/ava-labs/coreth v0.13.1-rc.4 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 diff --git a/go.sum b/go.sum index 0c0869a6581b..6c5578440404 100644 --- a/go.sum +++ b/go.sum @@ -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.3 h1:d32AzRI5HLwfFEevhR/RU4QPRjdl7LIMvPxTwlMlsmM= -github.com/ava-labs/coreth v0.13.1-rc.3/go.mod h1:J1boUw9u7S3JrisnJ81PvrhhyZUBnS4WuxSeMtTuVU0= +github.com/ava-labs/coreth v0.13.1-rc.4 h1:/3LsQi64oet6uCoUhEkgEXXcAAZFGPMUNJGdU03XH30= +github.com/ava-labs/coreth v0.13.1-rc.4/go.mod h1:4y1igTe/sFOIrpAtXoY+AdmfftNHrmrhBBRVfGCAPcw= 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= diff --git a/network/p2p/gossip/gossip.go b/network/p2p/gossip/gossip.go index 27f5d414b3f6..32d77a32babe 100644 --- a/network/p2p/gossip/gossip.go +++ b/network/p2p/gossip/gossip.go @@ -263,22 +263,19 @@ func NewPushGossiper[T Gossipable]( mempool Set[T], client *p2p.Client, metrics Metrics, - numValidators int, - numNonValidators int, - numPeers int, + gossipParams BranchingFactor, + regossipParams BranchingFactor, discardedSize int, targetGossipSize int, maxRegossipFrequency time.Duration, ) (*PushGossiper[T], error) { + if err := gossipParams.Verify(); err != nil { + return nil, fmt.Errorf("invalid gossip params: %w", err) + } + if err := regossipParams.Verify(); err != nil { + return nil, fmt.Errorf("invalid regossip params: %w", err) + } 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: @@ -292,9 +289,8 @@ func NewPushGossiper[T Gossipable]( set: mempool, client: client, metrics: metrics, - numValidators: numValidators, - numNonValidators: numNonValidators, - numPeers: numPeers, + gossipParams: gossipParams, + regossipParams: regossipParams, targetGossipSize: targetGossipSize, maxRegossipFrequency: maxRegossipFrequency, @@ -312,9 +308,8 @@ type PushGossiper[T Gossipable] struct { client *p2p.Client metrics Metrics - numValidators int - numNonValidators int - numPeers int + gossipParams BranchingFactor + regossipParams BranchingFactor targetGossipSize int maxRegossipFrequency time.Duration @@ -326,6 +321,27 @@ type PushGossiper[T Gossipable] struct { discarded *cache.LRU[ids.ID, struct{}] // discarded attempts to avoid overgossiping transactions that are frequently dropped } +type BranchingFactor struct { + Validators int + NonValidators int + Peers int +} + +func (b *BranchingFactor) Verify() error { + switch { + case b.Validators < 0: + return ErrInvalidNumValidators + case b.NonValidators < 0: + return ErrInvalidNumNonValidators + case b.Peers < 0: + return ErrInvalidNumPeers + case max(b.Validators, b.NonValidators, b.Peers) == 0: + return ErrInvalidNumToGossip + default: + return nil + } +} + type tracking struct { addedTime float64 // unix nanoseconds lastGossiped time.Time @@ -348,46 +364,46 @@ func (p *PushGossiper[T]) Gossip(ctx context.Context) error { return nil } - var ( - sentBytes = 0 - gossip = make([][]byte, 0, defaultGossipableCount) - ) - - // Iterate over all unsent gossipables. - for sentBytes < p.targetGossipSize { - gossipable, ok := p.toGossip.PopLeft() - if !ok { - break - } - - // Ensure item is still in the set before we gossip. - gossipID := gossipable.GossipID() - tracking := p.tracking[gossipID] - if !p.set.Has(gossipID) { - delete(p.tracking, gossipID) - p.addedTimeSum -= tracking.addedTime - continue - } - - bytes, err := p.marshaller.MarshalGossip(gossipable) - if err != nil { - delete(p.tracking, gossipID) - p.addedTimeSum -= tracking.addedTime - return err - } + if err := p.gossip( + ctx, + now, + p.gossipParams, + p.toGossip, + p.toRegossip, + &cache.Empty[ids.ID, struct{}]{}, // Don't mark dropped unsent transactions as discarded + ); err != nil { + return fmt.Errorf("unexpected error during gossip: %w", err) + } - gossip = append(gossip, bytes) - sentBytes += len(bytes) - p.toRegossip.PushRight(gossipable) - tracking.lastGossiped = now + if err := p.gossip( + ctx, + now, + p.regossipParams, + p.toRegossip, + p.toRegossip, + p.discarded, // Mark dropped sent transactions as discarded + ); err != nil { + return fmt.Errorf("unexpected error during regossip: %w", err) } + return nil +} - maxLastGossipTimeToRegossip := now.Add(-p.maxRegossipFrequency) +func (p *PushGossiper[T]) gossip( + ctx context.Context, + now time.Time, + gossipParams BranchingFactor, + toGossip buffer.Deque[T], + toRegossip buffer.Deque[T], + discarded cache.Cacher[ids.ID, struct{}], +) error { + var ( + sentBytes = 0 + gossip = make([][]byte, 0, defaultGossipableCount) + maxLastGossipTimeToRegossip = now.Add(-p.maxRegossipFrequency) + ) - // Iterate over all previously sent gossipables to fill any remaining space - // in the gossip batch. for sentBytes < p.targetGossipSize { - gossipable, ok := p.toRegossip.PopLeft() + gossipable, ok := toGossip.PopLeft() if !ok { break } @@ -398,7 +414,7 @@ func (p *PushGossiper[T]) Gossip(ctx context.Context) error { if !p.set.Has(gossipID) { delete(p.tracking, gossipID) p.addedTimeSum -= tracking.addedTime - p.discarded.Put(gossipID, struct{}{}) // only add to discarded if previously sent + discarded.Put(gossipID, struct{}{}) // Cache that the item was dropped continue } @@ -406,13 +422,12 @@ func (p *PushGossiper[T]) Gossip(ctx context.Context) error { if maxLastGossipTimeToRegossip.Before(tracking.lastGossiped) { // Put the gossipable on the front of the queue to keep items sorted // by last issuance time. - p.toRegossip.PushLeft(gossipable) + toGossip.PushLeft(gossipable) break } bytes, err := p.marshaller.MarshalGossip(gossipable) if err != nil { - // Should never happen because we've already sent this once. delete(p.tracking, gossipID) p.addedTimeSum -= tracking.addedTime return err @@ -420,7 +435,7 @@ func (p *PushGossiper[T]) Gossip(ctx context.Context) error { gossip = append(gossip, bytes) sentBytes += len(bytes) - p.toRegossip.PushRight(gossipable) + toRegossip.PushRight(gossipable) tracking.lastGossiped = now } @@ -448,9 +463,9 @@ func (p *PushGossiper[T]) Gossip(ctx context.Context) error { return p.client.AppGossip( ctx, msgBytes, - p.numValidators, - p.numNonValidators, - p.numPeers, + gossipParams.Validators, + gossipParams.NonValidators, + gossipParams.Peers, ) } diff --git a/network/p2p/gossip/gossip_test.go b/network/p2p/gossip/gossip_test.go index 8b70506cdece..47a05ceb5330 100644 --- a/network/p2p/gossip/gossip_test.go +++ b/network/p2p/gossip/gossip_test.go @@ -235,48 +235,119 @@ func TestValidatorGossiper(t *testing.T) { func TestPushGossiperNew(t *testing.T) { tests := []struct { name string - numValidators int - numNonValidators int - numPeers int + gossipParams BranchingFactor + regossipParams BranchingFactor discardedSize int targetGossipSize int maxRegossipFrequency time.Duration expected error }{ { - name: "invalid num validators", - numValidators: -1, - expected: ErrInvalidNumValidators, + name: "invalid gossip num validators", + gossipParams: BranchingFactor{ + Validators: -1, + }, + regossipParams: BranchingFactor{ + Peers: 1, + }, + expected: ErrInvalidNumValidators, }, { - name: "invalid num non-validators", - numNonValidators: -1, - expected: ErrInvalidNumNonValidators, + name: "invalid gossip num non-validators", + gossipParams: BranchingFactor{ + NonValidators: -1, + }, + regossipParams: BranchingFactor{ + Peers: 1, + }, + expected: ErrInvalidNumNonValidators, }, { - name: "invalid num peers", - numPeers: -1, + name: "invalid gossip num peers", + gossipParams: BranchingFactor{ + Peers: -1, + }, + regossipParams: BranchingFactor{ + Peers: 1, + }, expected: ErrInvalidNumPeers, }, { - name: "invalid num to gossip", + name: "invalid gossip num to gossip", + gossipParams: BranchingFactor{}, + regossipParams: BranchingFactor{ + Peers: 1, + }, expected: ErrInvalidNumToGossip, }, { - name: "invalid discarded size", - numValidators: 1, + name: "invalid regossip num validators", + gossipParams: BranchingFactor{ + Validators: 1, + }, + regossipParams: BranchingFactor{ + Validators: -1, + }, + expected: ErrInvalidNumValidators, + }, + { + name: "invalid regossip num non-validators", + gossipParams: BranchingFactor{ + Validators: 1, + }, + regossipParams: BranchingFactor{ + NonValidators: -1, + }, + expected: ErrInvalidNumNonValidators, + }, + { + name: "invalid regossip num peers", + gossipParams: BranchingFactor{ + Validators: 1, + }, + regossipParams: BranchingFactor{ + Peers: -1, + }, + expected: ErrInvalidNumPeers, + }, + { + name: "invalid regossip num to gossip", + gossipParams: BranchingFactor{ + Validators: 1, + }, + regossipParams: BranchingFactor{}, + expected: ErrInvalidNumToGossip, + }, + { + name: "invalid discarded size", + gossipParams: BranchingFactor{ + Validators: 1, + }, + regossipParams: BranchingFactor{ + Validators: 1, + }, discardedSize: -1, expected: ErrInvalidDiscardedSize, }, { - name: "invalid target gossip size", - numValidators: 1, + name: "invalid target gossip size", + gossipParams: BranchingFactor{ + Validators: 1, + }, + regossipParams: BranchingFactor{ + Validators: 1, + }, targetGossipSize: -1, expected: ErrInvalidTargetGossipSize, }, { - name: "invalid max re-gossip frequency", - numValidators: 1, + name: "invalid max re-gossip frequency", + gossipParams: BranchingFactor{ + Validators: 1, + }, + regossipParams: BranchingFactor{ + Validators: 1, + }, maxRegossipFrequency: -1, expected: ErrInvalidRegossipFrequency, }, @@ -289,9 +360,8 @@ func TestPushGossiperNew(t *testing.T) { nil, nil, Metrics{}, - tt.numValidators, - tt.numNonValidators, - tt.numPeers, + tt.gossipParams, + tt.regossipParams, tt.discardedSize, tt.targetGossipSize, tt.maxRegossipFrequency, @@ -305,7 +375,7 @@ func TestPushGossiperNew(t *testing.T) { func TestPushGossiper(t *testing.T) { type cycle struct { toAdd []*testTx - expected []*testTx + expected [][]*testTx } tests := []struct { name string @@ -327,15 +397,17 @@ func TestPushGossiper(t *testing.T) { id: ids.ID{2}, }, }, - expected: []*testTx{ + expected: [][]*testTx{ { - id: ids.ID{0}, - }, - { - id: ids.ID{1}, - }, - { - id: ids.ID{2}, + { + id: ids.ID{0}, + }, + { + id: ids.ID{1}, + }, + { + id: ids.ID{2}, + }, }, }, }, @@ -351,9 +423,11 @@ func TestPushGossiper(t *testing.T) { id: ids.ID{0}, }, }, - expected: []*testTx{ + expected: [][]*testTx{ { - id: ids.ID{0}, + { + id: ids.ID{0}, + }, }, }, }, @@ -363,12 +437,16 @@ func TestPushGossiper(t *testing.T) { id: ids.ID{1}, }, }, - expected: []*testTx{ + expected: [][]*testTx{ { - id: ids.ID{1}, + { + id: ids.ID{1}, + }, }, { - id: ids.ID{0}, + { + id: ids.ID{0}, + }, }, }, }, @@ -378,15 +456,19 @@ func TestPushGossiper(t *testing.T) { id: ids.ID{2}, }, }, - expected: []*testTx{ + expected: [][]*testTx{ { - id: ids.ID{2}, + { + id: ids.ID{2}, + }, }, { - id: ids.ID{1}, - }, - { - id: ids.ID{0}, + { + id: ids.ID{1}, + }, + { + id: ids.ID{0}, + }, }, }, }, @@ -402,15 +484,17 @@ func TestPushGossiper(t *testing.T) { id: ids.ID{0}, }, }, - expected: []*testTx{ + expected: [][]*testTx{ { - id: ids.ID{0}, + { + id: ids.ID{0}, + }, }, }, }, { toAdd: []*testTx{}, - expected: []*testTx{}, + expected: [][]*testTx{}, }, }, shouldRegossip: false, @@ -423,7 +507,7 @@ func TestPushGossiper(t *testing.T) { ctx := context.Background() sender := &common.FakeSender{ - SentAppGossip: make(chan []byte, 1), + SentAppGossip: make(chan []byte, 2), } network, err := p2p.NewNetwork( logging.NoLog{}, @@ -447,9 +531,12 @@ func TestPushGossiper(t *testing.T) { FullSet[*testTx]{}, client, metrics, - 1, - 0, - 0, + BranchingFactor{ + Validators: 1, + }, + BranchingFactor{ + Validators: 1, + }, 0, // the discarded cache size doesn't matter for this test units.MiB, regossipTime, @@ -460,29 +547,31 @@ func TestPushGossiper(t *testing.T) { gossiper.Add(cycle.toAdd...) require.NoError(gossiper.Gossip(ctx)) - want := &sdk.PushGossip{ - Gossip: make([][]byte, 0, len(cycle.expected)), - } + for _, expected := range cycle.expected { + want := &sdk.PushGossip{ + Gossip: make([][]byte, 0, len(expected)), + } - for _, gossipable := range cycle.expected { - bytes, err := marshaller.MarshalGossip(gossipable) - require.NoError(err) + for _, gossipable := range expected { + bytes, err := marshaller.MarshalGossip(gossipable) + require.NoError(err) - want.Gossip = append(want.Gossip, bytes) - } + want.Gossip = append(want.Gossip, bytes) + } - if len(want.Gossip) > 0 { - // remove the handler prefix - sentMsg := <-sender.SentAppGossip - got := &sdk.PushGossip{} - require.NoError(proto.Unmarshal(sentMsg[1:], got)) - - require.Equal(want.Gossip, got.Gossip) - } else { - select { - case <-sender.SentAppGossip: - require.FailNow("unexpectedly sent gossip message") - default: + if len(want.Gossip) > 0 { + // remove the handler prefix + sentMsg := <-sender.SentAppGossip + got := &sdk.PushGossip{} + require.NoError(proto.Unmarshal(sentMsg[1:], got)) + + require.Equal(want.Gossip, got.Gossip) + } else { + select { + case <-sender.SentAppGossip: + require.FailNow("unexpectedly sent gossip message") + default: + } } } diff --git a/vms/avm/config_test.go b/vms/avm/config_test.go index 5d4f6d476c44..f372335b80d8 100644 --- a/vms/avm/config_test.go +++ b/vms/avm/config_test.go @@ -42,6 +42,8 @@ func TestParseConfig(t *testing.T) { TargetGossipSize: network.DefaultConfig.TargetGossipSize, PushGossipNumValidators: network.DefaultConfig.PushGossipNumValidators, PushGossipNumPeers: network.DefaultConfig.PushGossipNumPeers, + PushRegossipNumValidators: network.DefaultConfig.PushRegossipNumValidators, + PushRegossipNumPeers: network.DefaultConfig.PushRegossipNumPeers, PushGossipDiscardedCacheSize: network.DefaultConfig.PushGossipDiscardedCacheSize, PushGossipMaxRegossipFrequency: network.DefaultConfig.PushGossipMaxRegossipFrequency, PushGossipFrequency: network.DefaultConfig.PushGossipFrequency, diff --git a/vms/avm/network/config.go b/vms/avm/network/config.go index d545d1ee8e8d..8c3975653dfa 100644 --- a/vms/avm/network/config.go +++ b/vms/avm/network/config.go @@ -12,10 +12,12 @@ import ( var DefaultConfig = Config{ MaxValidatorSetStaleness: time.Minute, TargetGossipSize: 20 * units.KiB, - PushGossipNumValidators: 10, + PushGossipNumValidators: 100, PushGossipNumPeers: 0, - PushGossipDiscardedCacheSize: 1024, - PushGossipMaxRegossipFrequency: 10 * time.Second, + PushRegossipNumValidators: 10, + PushRegossipNumPeers: 0, + PushGossipDiscardedCacheSize: 16384, + PushGossipMaxRegossipFrequency: 30 * time.Second, PushGossipFrequency: 500 * time.Millisecond, PullGossipPollSize: 1, PullGossipFrequency: 1500 * time.Millisecond, @@ -35,11 +37,17 @@ type Config struct { // requests. TargetGossipSize int `json:"target-gossip-size"` // PushGossipNumValidators is the number of validators to push transactions - // to per round of gossip. + // to in the first round of gossip. PushGossipNumValidators int `json:"push-gossip-num-validators"` - // PushGossipNumPeers is the number of peers to push transactions to per - // round of gossip. + // PushGossipNumPeers is the number of peers to push transactions to in the + // first round of gossip. PushGossipNumPeers int `json:"push-gossip-num-peers"` + // PushRegossipNumValidators is the number of validators to push + // transactions to after the first round of gossip. + PushRegossipNumValidators int `json:"push-regossip-num-validators"` + // PushRegossipNumPeers is the number of peers to push transactions to after + // the first round of gossip. + PushRegossipNumPeers int `json:"push-regossip-num-peers"` // PushGossipDiscardedCacheSize is the number of txIDs to cache to avoid // pushing transactions that were recently dropped from the mempool. PushGossipDiscardedCacheSize int `json:"push-gossip-discarded-cache-size"` diff --git a/vms/avm/network/network.go b/vms/avm/network/network.go index ae594d9a6b42..5cc17b03cec0 100644 --- a/vms/avm/network/network.go +++ b/vms/avm/network/network.go @@ -21,10 +21,7 @@ import ( "github.com/ava-labs/avalanchego/vms/components/message" ) -const ( - txGossipHandlerID = 0 - pushGossipNumNonValidators = 0 -) +const txGossipHandlerID = 0 var ( _ common.AppHandler = (*Network)(nil) @@ -97,9 +94,14 @@ func New( gossipMempool, txGossipClient, txGossipMetrics, - config.PushGossipNumValidators, - pushGossipNumNonValidators, - config.PushGossipNumPeers, + gossip.BranchingFactor{ + Validators: config.PushGossipNumValidators, + Peers: config.PushGossipNumPeers, + }, + gossip.BranchingFactor{ + Validators: config.PushRegossipNumValidators, + Peers: config.PushRegossipNumPeers, + }, config.PushGossipDiscardedCacheSize, config.TargetGossipSize, config.PushGossipMaxRegossipFrequency, diff --git a/vms/avm/network/network_test.go b/vms/avm/network/network_test.go index 39e580392290..4fdd09b9230f 100644 --- a/vms/avm/network/network_test.go +++ b/vms/avm/network/network_test.go @@ -34,6 +34,8 @@ var ( TargetGossipSize: 1, PushGossipNumValidators: 1, PushGossipNumPeers: 0, + PushRegossipNumValidators: 1, + PushRegossipNumPeers: 0, PushGossipDiscardedCacheSize: 1, PushGossipMaxRegossipFrequency: time.Second, PushGossipFrequency: time.Second, diff --git a/vms/platformvm/config/execution_config_test.go b/vms/platformvm/config/execution_config_test.go index e096fd7ac744..66b43e800198 100644 --- a/vms/platformvm/config/execution_config_test.go +++ b/vms/platformvm/config/execution_config_test.go @@ -47,16 +47,18 @@ func TestExecutionConfigUnmarshal(t *testing.T) { "target-gossip-size": 2, "push-gossip-num-validators": 3, "push-gossip-num-peers": 4, - "push-gossip-discarded-cache-size": 5, - "push-gossip-max-regossip-frequency": 6, - "push-gossip-frequency": 7, - "pull-gossip-poll-size": 8, - "pull-gossip-frequency": 9, - "pull-gossip-throttling-period": 10, - "pull-gossip-throttling-limit": 11, - "expected-bloom-filter-elements": 12, - "expected-bloom-filter-false-positive-probability": 13, - "max-bloom-filter-false-positive-probability": 14 + "push-regossip-num-validators": 5, + "push-regossip-num-peers": 6, + "push-gossip-discarded-cache-size": 7, + "push-gossip-max-regossip-frequency": 8, + "push-gossip-frequency": 9, + "pull-gossip-poll-size": 10, + "pull-gossip-frequency": 11, + "pull-gossip-throttling-period": 12, + "pull-gossip-throttling-limit": 13, + "expected-bloom-filter-elements": 14, + "expected-bloom-filter-false-positive-probability": 15, + "max-bloom-filter-false-positive-probability": 16 }, "block-cache-size": 1, "tx-cache-size": 2, @@ -77,16 +79,18 @@ func TestExecutionConfigUnmarshal(t *testing.T) { TargetGossipSize: 2, PushGossipNumValidators: 3, PushGossipNumPeers: 4, - PushGossipDiscardedCacheSize: 5, - PushGossipMaxRegossipFrequency: 6, - PushGossipFrequency: 7, - PullGossipPollSize: 8, - PullGossipFrequency: 9, - PullGossipThrottlingPeriod: 10, - PullGossipThrottlingLimit: 11, - ExpectedBloomFilterElements: 12, - ExpectedBloomFilterFalsePositiveProbability: 13, - MaxBloomFilterFalsePositiveProbability: 14, + PushRegossipNumValidators: 5, + PushRegossipNumPeers: 6, + PushGossipDiscardedCacheSize: 7, + PushGossipMaxRegossipFrequency: 8, + PushGossipFrequency: 9, + PullGossipPollSize: 10, + PullGossipFrequency: 11, + PullGossipThrottlingPeriod: 12, + PullGossipThrottlingLimit: 13, + ExpectedBloomFilterElements: 14, + ExpectedBloomFilterFalsePositiveProbability: 15, + MaxBloomFilterFalsePositiveProbability: 16, }, BlockCacheSize: 1, TxCacheSize: 2, @@ -132,8 +136,10 @@ func TestExecutionConfigUnmarshal(t *testing.T) { TargetGossipSize: 2, PushGossipNumValidators: DefaultExecutionConfig.Network.PushGossipNumValidators, PushGossipNumPeers: DefaultExecutionConfig.Network.PushGossipNumPeers, - PushGossipDiscardedCacheSize: DefaultExecutionConfig.Network.PushGossipDiscardedCacheSize, - PushGossipMaxRegossipFrequency: DefaultExecutionConfig.Network.PushGossipMaxRegossipFrequency, + PushRegossipNumValidators: DefaultExecutionConfig.Network.PushRegossipNumValidators, + PushRegossipNumPeers: DefaultExecutionConfig.Network.PushRegossipNumPeers, + PushGossipDiscardedCacheSize: 1024, + PushGossipMaxRegossipFrequency: 10 * time.Second, PushGossipFrequency: DefaultExecutionConfig.Network.PushGossipFrequency, PullGossipPollSize: 3, PullGossipFrequency: 4, diff --git a/vms/platformvm/network/config.go b/vms/platformvm/network/config.go index d545d1ee8e8d..8c3975653dfa 100644 --- a/vms/platformvm/network/config.go +++ b/vms/platformvm/network/config.go @@ -12,10 +12,12 @@ import ( var DefaultConfig = Config{ MaxValidatorSetStaleness: time.Minute, TargetGossipSize: 20 * units.KiB, - PushGossipNumValidators: 10, + PushGossipNumValidators: 100, PushGossipNumPeers: 0, - PushGossipDiscardedCacheSize: 1024, - PushGossipMaxRegossipFrequency: 10 * time.Second, + PushRegossipNumValidators: 10, + PushRegossipNumPeers: 0, + PushGossipDiscardedCacheSize: 16384, + PushGossipMaxRegossipFrequency: 30 * time.Second, PushGossipFrequency: 500 * time.Millisecond, PullGossipPollSize: 1, PullGossipFrequency: 1500 * time.Millisecond, @@ -35,11 +37,17 @@ type Config struct { // requests. TargetGossipSize int `json:"target-gossip-size"` // PushGossipNumValidators is the number of validators to push transactions - // to per round of gossip. + // to in the first round of gossip. PushGossipNumValidators int `json:"push-gossip-num-validators"` - // PushGossipNumPeers is the number of peers to push transactions to per - // round of gossip. + // PushGossipNumPeers is the number of peers to push transactions to in the + // first round of gossip. PushGossipNumPeers int `json:"push-gossip-num-peers"` + // PushRegossipNumValidators is the number of validators to push + // transactions to after the first round of gossip. + PushRegossipNumValidators int `json:"push-regossip-num-validators"` + // PushRegossipNumPeers is the number of peers to push transactions to after + // the first round of gossip. + PushRegossipNumPeers int `json:"push-regossip-num-peers"` // PushGossipDiscardedCacheSize is the number of txIDs to cache to avoid // pushing transactions that were recently dropped from the mempool. PushGossipDiscardedCacheSize int `json:"push-gossip-discarded-cache-size"` diff --git a/vms/platformvm/network/network.go b/vms/platformvm/network/network.go index 24a09e48b0ea..0c78f9a84081 100644 --- a/vms/platformvm/network/network.go +++ b/vms/platformvm/network/network.go @@ -22,10 +22,7 @@ import ( "github.com/ava-labs/avalanchego/vms/platformvm/txs/mempool" ) -const ( - TxGossipHandlerID = 0 - pushGossipNumNonValidators = 0 -) +const TxGossipHandlerID = 0 var errMempoolDisabledWithPartialSync = errors.New("mempool is disabled partial syncing") @@ -96,9 +93,14 @@ func New( gossipMempool, txGossipClient, txGossipMetrics, - config.PushGossipNumValidators, - pushGossipNumNonValidators, - config.PushGossipNumPeers, + gossip.BranchingFactor{ + Validators: config.PushGossipNumValidators, + Peers: config.PushGossipNumPeers, + }, + gossip.BranchingFactor{ + Validators: config.PushRegossipNumValidators, + Peers: config.PushRegossipNumPeers, + }, config.PushGossipDiscardedCacheSize, config.TargetGossipSize, config.PushGossipMaxRegossipFrequency, diff --git a/vms/platformvm/network/network_test.go b/vms/platformvm/network/network_test.go index 8572c97100d9..98b92801c840 100644 --- a/vms/platformvm/network/network_test.go +++ b/vms/platformvm/network/network_test.go @@ -31,6 +31,8 @@ var ( TargetGossipSize: 1, PushGossipNumValidators: 1, PushGossipNumPeers: 0, + PushRegossipNumValidators: 1, + PushRegossipNumPeers: 0, PushGossipDiscardedCacheSize: 1, PushGossipMaxRegossipFrequency: time.Second, PushGossipFrequency: time.Second,