Skip to content

Commit

Permalink
fix: global symbols per period and interval
Browse files Browse the repository at this point in the history
  • Loading branch information
hopeyen committed Dec 19, 2024
1 parent 1345e77 commit 8351d8e
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 11 deletions.
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)
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

0 comments on commit 8351d8e

Please sign in to comment.