Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

start on-chain refresh #1083

Merged
merged 3 commits into from
Jan 8, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion core/meterer/meterer.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand All @@ -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
}
Expand Down
6 changes: 2 additions & 4 deletions disperser/cmd/apiserver/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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),
Expand Down
11 changes: 2 additions & 9 deletions disperser/cmd/apiserver/flags/flags.go
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -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"),
Expand Down
5 changes: 3 additions & 2 deletions disperser/cmd/apiserver/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -129,6 +129,7 @@ func RunDisperserServer(ctx *cli.Context) error {
logger,
// metrics.NewNoopMetrics(),
)
meterer.Start(context.Background())
}

var ratelimiter common.RateLimiter
Expand Down
Loading