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

fix: global symbols per period and interval #1033

Merged
merged 2 commits into from
Dec 19, 2024
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
4 changes: 2 additions & 2 deletions core/eth/reader.go
Original file line number Diff line number Diff line change
Expand Up @@ -222,7 +222,6 @@ func (t *Reader) updateContractBindings(blsOperatorStateRetrieverAddr, eigenDASe
t.logger.Error("Failed to fetch PaymentVault contract", "err", err)
return err
}

}

t.bindings = &ContractBindings{
Expand Down Expand Up @@ -791,7 +790,7 @@ func (t *Reader) GetGlobalSymbolsPerSecond(ctx context.Context) (uint64, error)
if t.bindings.PaymentVault == nil {
return 0, errors.New("payment vault not deployed")
}
globalSymbolsPerSecond, err := t.bindings.PaymentVault.GlobalRatePeriodInterval(&bind.CallOpts{
globalSymbolsPerSecond, err := t.bindings.PaymentVault.GlobalSymbolsPerPeriod(&bind.CallOpts{
Context: ctx,
})
if err != nil {
Expand All @@ -812,6 +811,7 @@ func (t *Reader) GetGlobalRatePeriodInterval(ctx context.Context) (uint32, error
}
return uint32(globalRateBinInterval), nil
}

func (t *Reader) GetMinNumSymbols(ctx context.Context) (uint32, error) {
if t.bindings.PaymentVault == nil {
return 0, errors.New("payment vault not deployed")
Expand Down
11 changes: 7 additions & 4 deletions core/meterer/meterer.go
Original file line number Diff line number Diff line change
Expand Up @@ -176,6 +176,9 @@ func (m *Meterer) IncrementBinUsage(ctx context.Context, header core.PaymentMeta
// GetReservationPeriod returns the current reservation period by chunking time by the bin interval;
// bin interval used by the disperser should be public information
func GetReservationPeriod(timestamp uint64, binInterval uint32) uint32 {
if binInterval == 0 {
return 0
}
return uint32(timestamp) / binInterval
}

Expand Down Expand Up @@ -207,11 +210,11 @@ func (m *Meterer) ServeOnDemandRequest(ctx context.Context, header core.PaymentM
// Update bin usage atomically and check against bin capacity
if err := m.IncrementGlobalBinUsage(ctx, uint64(symbolsCharged)); err != nil {
//TODO: conditionally remove the payment based on the error type (maybe if the error is store-op related)
err := m.OffchainStore.RemoveOnDemandPayment(ctx, header.AccountID, header.CumulativePayment)
if err != nil {
return err
db_err := m.OffchainStore.RemoveOnDemandPayment(ctx, header.AccountID, header.CumulativePayment)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

dbErr

if db_err != nil {
return db_err
}
return fmt.Errorf("failed global rate limiting")
return fmt.Errorf("failed global rate limiting: %w", err)
}

return nil
Expand Down
16 changes: 11 additions & 5 deletions core/meterer/onchain_state.go
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,11 @@ func (pcs *OnchainPaymentState) GetPaymentVaultParams(ctx context.Context) (*Pay
return nil, err
}

globalRatePeriodInterval, err := pcs.tx.GetGlobalRatePeriodInterval(ctx)
if err != nil {
return nil, err
}

minNumSymbols, err := pcs.tx.GetMinNumSymbols(ctx)
if err != nil {
return nil, err
Expand All @@ -93,11 +98,12 @@ func (pcs *OnchainPaymentState) GetPaymentVaultParams(ctx context.Context) (*Pay
}

return &PaymentVaultParams{
OnDemandQuorumNumbers: quorumNumbers,
GlobalSymbolsPerSecond: globalSymbolsPerSecond,
MinNumSymbols: minNumSymbols,
PricePerSymbol: pricePerSymbol,
ReservationWindow: reservationWindow,
OnDemandQuorumNumbers: quorumNumbers,
GlobalSymbolsPerSecond: globalSymbolsPerSecond,
GlobalRatePeriodInterval: globalRatePeriodInterval,
MinNumSymbols: minNumSymbols,
PricePerSymbol: pricePerSymbol,
ReservationWindow: reservationWindow,
}, nil
}

Expand Down
Loading