From f6ee5ca7446f73f454bf745c8f0a9120d207fb6f Mon Sep 17 00:00:00 2001 From: hopeyen <60078528+hopeyen@users.noreply.github.com> Date: Wed, 8 Jan 2025 12:55:55 -0600 Subject: [PATCH] start on-chain refresh (#1083) --- core/meterer/meterer.go | 3 ++- disperser/cmd/apiserver/config.go | 6 ++---- disperser/cmd/apiserver/flags/flags.go | 11 ++--------- disperser/cmd/apiserver/main.go | 5 +++-- 4 files changed, 9 insertions(+), 16 deletions(-) diff --git a/core/meterer/meterer.go b/core/meterer/meterer.go index 55c2712119..c4673bb991 100644 --- a/core/meterer/meterer.go +++ b/core/meterer/meterer.go @@ -54,7 +54,7 @@ func NewMeterer( // Start starts to periodically refreshing the on-chain state func (m *Meterer) Start(ctx context.Context) { go func() { - ticker := time.NewTicker(m.UpdateInterval) + ticker := time.NewTicker(m.Config.UpdateInterval) defer ticker.Stop() for { @@ -63,6 +63,7 @@ func (m *Meterer) Start(ctx context.Context) { if err := m.ChainPaymentState.RefreshOnchainPaymentState(ctx); err != nil { m.logger.Error("Failed to refresh on-chain state", "error", err) } + m.logger.Debug("Refreshed on-chain state") case <-ctx.Done(): return } diff --git a/disperser/cmd/apiserver/config.go b/disperser/cmd/apiserver/config.go index a27bd0b793..fedb597dec 100644 --- a/disperser/cmd/apiserver/config.go +++ b/disperser/cmd/apiserver/config.go @@ -35,8 +35,7 @@ type Config struct { EncodingConfig kzg.KzgConfig EnableRatelimiter bool EnablePaymentMeterer bool - UpdateInterval int - ChainReadTimeout int + ChainReadTimeout time.Duration ReservationsTableName string OnDemandTableName string GlobalRateTableName string @@ -119,8 +118,7 @@ func NewConfig(ctx *cli.Context) (Config, error) { GlobalRateTableName: ctx.GlobalString(flags.GlobalRateTableName.Name), BucketTableName: ctx.GlobalString(flags.BucketTableName.Name), BucketStoreSize: ctx.GlobalInt(flags.BucketStoreSize.Name), - UpdateInterval: ctx.GlobalInt(flags.UpdateInterval.Name), - ChainReadTimeout: ctx.GlobalInt(flags.ChainReadTimeout.Name), + ChainReadTimeout: ctx.GlobalDuration(flags.ChainReadTimeout.Name), EthClientConfig: geth.ReadEthClientConfigRPCOnly(ctx), MaxBlobSize: ctx.GlobalInt(flags.MaxBlobSize.Name), MaxNumSymbolsPerBlob: ctx.GlobalUint(flags.MaxNumSymbolsPerBlob.Name), diff --git a/disperser/cmd/apiserver/flags/flags.go b/disperser/cmd/apiserver/flags/flags.go index af31d87ff9..99b3e828ca 100644 --- a/disperser/cmd/apiserver/flags/flags.go +++ b/disperser/cmd/apiserver/flags/flags.go @@ -107,14 +107,7 @@ var ( Value: "global_rate", EnvVar: common.PrefixEnvVar(envVarPrefix, "GLOBAL_RATE_TABLE_NAME"), } - UpdateInterval = cli.DurationFlag{ - Name: common.PrefixFlag(FlagPrefix, "update-interval"), - Usage: "update interval for refreshing the on-chain state", - Value: 1 * time.Second, - EnvVar: common.PrefixEnvVar(envVarPrefix, "UPDATE_INTERVAL"), - Required: false, - } - ChainReadTimeout = cli.UintFlag{ + ChainReadTimeout = cli.DurationFlag{ Name: common.PrefixFlag(FlagPrefix, "chain-read-timeout"), Usage: "timeout for reading from the chain", Value: 10, @@ -146,7 +139,7 @@ var ( Usage: "The interval at which to refresh the onchain state. This flag is only relevant in v2", Required: false, EnvVar: common.PrefixEnvVar(envVarPrefix, "ONCHAIN_STATE_REFRESH_INTERVAL"), - Value: 1 * time.Hour, + Value: 1 * time.Minute, } MaxNumSymbolsPerBlob = cli.UintFlag{ Name: common.PrefixFlag(FlagPrefix, "max-num-symbols-per-blob"), diff --git a/disperser/cmd/apiserver/main.go b/disperser/cmd/apiserver/main.go index 2659f0c87b..31fb2d094e 100644 --- a/disperser/cmd/apiserver/main.go +++ b/disperser/cmd/apiserver/main.go @@ -99,8 +99,8 @@ func RunDisperserServer(ctx *cli.Context) error { var meterer *mt.Meterer if config.EnablePaymentMeterer { mtConfig := mt.Config{ - ChainReadTimeout: time.Duration(config.ChainReadTimeout) * time.Second, - UpdateInterval: time.Duration(config.UpdateInterval) * time.Second, + ChainReadTimeout: config.ChainReadTimeout, + UpdateInterval: config.OnchainStateRefreshInterval, } paymentChainState, err := mt.NewOnchainPaymentState(context.Background(), transactor) @@ -129,6 +129,7 @@ func RunDisperserServer(ctx *cli.Context) error { logger, // metrics.NewNoopMetrics(), ) + meterer.Start(context.Background()) } var ratelimiter common.RateLimiter