Skip to content

Commit 6faabc0

Browse files
authored
Merge pull request #7683 from onflow/yurii/max-collection-size-rate-limitting
[Performance] Collection throttling
2 parents a10db7d + cd3bb04 commit 6faabc0

29 files changed

+2307
-116
lines changed

cmd/collection/main.go

Lines changed: 60 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,7 @@ import (
5151
"github.com/onflow/flow-go/module/mempool/herocache"
5252
"github.com/onflow/flow-go/module/mempool/queue"
5353
"github.com/onflow/flow-go/module/metrics"
54+
"github.com/onflow/flow-go/module/updatable_configs"
5455
"github.com/onflow/flow-go/network/channels"
5556
"github.com/onflow/flow-go/state/protocol"
5657
badgerState "github.com/onflow/flow-go/state/protocol/badger"
@@ -73,6 +74,7 @@ func main() {
7374
builderPayerRateLimitDryRun bool
7475
builderPayerRateLimit float64
7576
builderUnlimitedPayers []string
77+
builderPriorityPayers []string
7678
hotstuffMinTimeout time.Duration
7779
hotstuffTimeoutAdjustmentFactor float64
7880
hotstuffHappyPathMaxRoundFailures uint64
@@ -100,15 +102,16 @@ func main() {
100102
err error
101103

102104
// epoch qc contract client
103-
machineAccountInfo *bootstrap.NodeMachineAccountInfo
104-
flowClientConfigs []*grpcclient.FlowClientConfig
105-
insecureAccessAPI bool
106-
accessNodeIDS []string
107-
apiRatelimits map[string]int
108-
apiBurstlimits map[string]int
109-
txRatelimits float64
110-
txBurstlimits int
111-
txRatelimitPayers string
105+
machineAccountInfo *bootstrap.NodeMachineAccountInfo
106+
flowClientConfigs []*grpcclient.FlowClientConfig
107+
insecureAccessAPI bool
108+
accessNodeIDS []string
109+
apiRatelimits map[string]int
110+
apiBurstlimits map[string]int
111+
txRatelimits float64
112+
txBurstlimits int
113+
txRatelimitPayers string
114+
bySealingLagRateLimiterConfigGetter module.ReadonlySealingLagRateLimiterConfig
112115
)
113116
var deprecatedFlagBlockRateDelay time.Duration
114117

@@ -142,6 +145,8 @@ func main() {
142145
"rate limit for each payer (transactions/collection)")
143146
flags.StringSliceVar(&builderUnlimitedPayers, "builder-unlimited-payers", []string{}, // no unlimited payers
144147
"set of payer addresses which are omitted from rate limiting")
148+
flags.StringSliceVar(&builderPriorityPayers, "builder-priority-payers", []string{}, // no priority payers
149+
"set of payer addresses which are prioritized in tx selection algorithm")
145150
flags.UintVar(&maxCollectionSize, "builder-max-collection-size", flow.DefaultMaxCollectionSize,
146151
"maximum number of transactions in proposed collections")
147152
flags.Uint64Var(&maxCollectionByteSize, "builder-max-collection-byte-size", flow.DefaultMaxCollectionByteSize,
@@ -294,6 +299,43 @@ func main() {
294299

295300
return nil
296301
}).
302+
Module("updatable collection rate limiting config", func(node *cmd.NodeConfig) error {
303+
setter := updatable_configs.DefaultBySealingLagRateLimiterConfigs()
304+
305+
// update the getter with the setter, so other modules can only get, but not set
306+
bySealingLagRateLimiterConfigGetter = setter
307+
308+
// admin tool is the only instance that have access to the setter interface, therefore, is
309+
// the only module can change this config
310+
err = node.ConfigManager.RegisterUintConfig("collection-builder-rate-limiter-min-sealing-lag",
311+
setter.MinSealingLag,
312+
setter.SetMinSealingLag)
313+
if err != nil {
314+
return err
315+
}
316+
err = node.ConfigManager.RegisterUintConfig("collection-builder-rate-limiter-max-sealing-lag",
317+
setter.MaxSealingLag,
318+
setter.SetMaxSealingLag)
319+
if err != nil {
320+
return err
321+
}
322+
err = node.ConfigManager.RegisterUintConfig("collection-builder-rate-limiter-halving-interval",
323+
setter.HalvingInterval,
324+
setter.SetHalvingInterval)
325+
if err != nil {
326+
return err
327+
}
328+
err = node.ConfigManager.RegisterUintConfig("collection-builder-rate-limiter-min-collection-size",
329+
setter.MinCollectionSize,
330+
setter.SetMinCollectionSize)
331+
if err != nil {
332+
return err
333+
}
334+
335+
// report the initial config value
336+
colMetrics.CollectionMaxSize(maxCollectionSize)
337+
return nil
338+
}).
297339
Component("machine account config validator", func(node *cmd.NodeConfig) (module.ReadyDoneAware, error) {
298340
// @TODO use fallback logic for flowClient similar to DKG/QC contract clients
299341
flowClient, err := grpcclient.FlowClient(flowClientConfigs[0])
@@ -501,6 +543,13 @@ func main() {
501543
unlimitedPayers = append(unlimitedPayers, payerAddr)
502544
}
503545

546+
// convert hex string flag values to addresses
547+
priorityPayers := make([]flow.Address, 0, len(builderPriorityPayers))
548+
for _, payerStr := range builderPriorityPayers {
549+
payerAddr := flow.HexToAddress(payerStr)
550+
priorityPayers = append(priorityPayers, payerAddr)
551+
}
552+
504553
builderFactory, err := factories.NewBuilderFactory(
505554
node.DB,
506555
node.State,
@@ -509,13 +558,15 @@ func main() {
509558
colMetrics,
510559
push,
511560
node.Logger,
561+
bySealingLagRateLimiterConfigGetter,
512562
builder.WithMaxCollectionSize(maxCollectionSize),
513563
builder.WithMaxCollectionByteSize(maxCollectionByteSize),
514564
builder.WithMaxCollectionTotalGas(maxCollectionTotalGas),
515565
builder.WithExpiryBuffer(builderExpiryBuffer),
516566
builder.WithRateLimitDryRun(builderPayerRateLimitDryRun),
517567
builder.WithMaxPayerTransactionRate(builderPayerRateLimit),
518568
builder.WithUnlimitedPayers(unlimitedPayers...),
569+
builder.WithPriorityPayers(priorityPayers...),
519570
)
520571
if err != nil {
521572
return nil, err

cmd/observer/node_builder/observer_builder.go

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -528,7 +528,8 @@ func (builder *ObserverServiceBuilder) buildFollowerEngine() *ObserverServiceBui
528528
if err != nil {
529529
return nil, fmt.Errorf("could not create follower engine: %w", err)
530530
}
531-
builder.FollowerDistributor.AddOnBlockFinalizedConsumer(builder.FollowerEng.OnFinalizedBlock)
531+
builder.FollowerDistributor.
532+
AddOnBlockFinalizedConsumer(builder.FollowerEng.OnFinalizedBlock)
532533

533534
return builder.FollowerEng, nil
534535
})

engine/collection/epochmgr/factories/builder.go

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@ type BuilderFactory struct {
2424
opts []builder.Opt
2525
metrics module.CollectionMetrics
2626
pusher collection.GuaranteedCollectionPublisher // engine for pushing finalized collection to consensus committee
27+
configGetter module.ReadonlySealingLagRateLimiterConfig
2728
log zerolog.Logger
2829
}
2930

@@ -35,6 +36,7 @@ func NewBuilderFactory(
3536
metrics module.CollectionMetrics,
3637
pusher collection.GuaranteedCollectionPublisher,
3738
log zerolog.Logger,
39+
configGetter module.ReadonlySealingLagRateLimiterConfig,
3840
opts ...builder.Opt,
3941
) (*BuilderFactory, error) {
4042

@@ -46,6 +48,7 @@ func NewBuilderFactory(
4648
metrics: metrics,
4749
pusher: pusher,
4850
log: log,
51+
configGetter: configGetter,
4952
opts: opts,
5053
}
5154
return factory, nil
@@ -62,6 +65,7 @@ func (f *BuilderFactory) Create(
6265
build, err := builder.NewBuilder(
6366
f.db,
6467
f.trace,
68+
f.metrics,
6569
f.protoState,
6670
clusterState,
6771
f.mainChainHeaders,
@@ -70,6 +74,7 @@ func (f *BuilderFactory) Create(
7074
pool,
7175
f.log,
7276
epoch,
77+
f.configGetter,
7378
f.opts...,
7479
)
7580
if err != nil {

engine/collection/ingest/engine.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -70,6 +70,7 @@ func New(
7070
CheckScriptsParse: config.CheckScriptsParse,
7171
MaxTransactionByteSize: config.MaxTransactionByteSize,
7272
MaxCollectionByteSize: config.MaxCollectionByteSize,
73+
CheckPayerBalanceMode: validator.Disabled,
7374
},
7475
colMetrics,
7576
limiter,

engine/testutil/nodes.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -93,6 +93,7 @@ import (
9393
"github.com/onflow/flow-go/module/signature"
9494
requesterunit "github.com/onflow/flow-go/module/state_synchronization/requester/unittest"
9595
"github.com/onflow/flow-go/module/trace"
96+
"github.com/onflow/flow-go/module/updatable_configs"
9697
"github.com/onflow/flow-go/module/validation"
9798
"github.com/onflow/flow-go/network/channels"
9899
"github.com/onflow/flow-go/network/p2p/cache"
@@ -334,6 +335,7 @@ func CollectionNode(t *testing.T, hub *stub.Hub, identity bootstrap.NodeInfo, ro
334335
node.Metrics,
335336
pusherEngine,
336337
node.Log,
338+
updatable_configs.DefaultBySealingLagRateLimiterConfigs(),
337339
)
338340
require.NoError(t, err)
339341

0 commit comments

Comments
 (0)