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

[v2] integrate with new payments contract #995

Merged
merged 4 commits into from
Dec 16, 2024
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
39 changes: 35 additions & 4 deletions contracts/bindings/EigenDAServiceManager/binding.go

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion contracts/bindings/MockRollup/binding.go

Large diffs are not rendered by default.

524 changes: 262 additions & 262 deletions contracts/bindings/PaymentVault/binding.go

Large diffs are not rendered by default.

51 changes: 31 additions & 20 deletions core/eth/reader.go
Original file line number Diff line number Diff line change
Expand Up @@ -210,6 +210,21 @@ func (t *Reader) updateContractBindings(blsOperatorStateRetrieverAddr, eigenDASe
}
}

var contractPaymentVault *paymentvault.ContractPaymentVault
paymentVaultAddr, err := contractEigenDAServiceManager.PaymentVault(&bind.CallOpts{})
if err != nil {
Copy link
Contributor

Choose a reason for hiding this comment

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

let's not fail and account for the case contract isn't deployed like threshold registry above

Copy link
Contributor Author

Choose a reason for hiding this comment

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

okay, edited to just log

t.logger.Error("Failed to fetch PaymentVault address", "err", err)
//TODO(hopeyen): return err when the contract is deployed
// return err
} else {
contractPaymentVault, err = paymentvault.NewContractPaymentVault(paymentVaultAddr, t.ethClient)
if err != nil {
t.logger.Error("Failed to fetch PaymentVault contract", "err", err)
return err
}

}

t.bindings = &ContractBindings{
ServiceManagerAddr: eigenDAServiceManagerAddr,
RegCoordinatorAddr: registryCoordinatorAddr,
Expand All @@ -224,8 +239,8 @@ func (t *Reader) updateContractBindings(blsOperatorStateRetrieverAddr, eigenDASe
EigenDAServiceManager: contractEigenDAServiceManager,
DelegationManager: contractDelegationManager,
RelayRegistry: contractRelayRegistry,
// PaymentVault: contractPaymentVault,
ThresholdRegistry: contractThresholdRegistry,
PaymentVault: contractPaymentVault,
ThresholdRegistry: contractThresholdRegistry,
}
return nil
}
Expand Down Expand Up @@ -734,9 +749,8 @@ func (t *Reader) GetOnDemandPayments(ctx context.Context, accountIDs []gethcommo
return nil, errors.New("payment vault not deployed")
}
paymentsMap := make(map[gethcommon.Address]*core.OnDemandPayment)
payments, err := t.bindings.PaymentVault.GetOnDemandAmounts(&bind.CallOpts{
Context: ctx,
}, accountIDs)
payments, err := t.bindings.PaymentVault.GetOnDemandTotalDeposits(&bind.CallOpts{
Context: ctx}, accountIDs)
if err != nil {
return nil, err
}
Expand All @@ -759,7 +773,7 @@ func (t *Reader) GetOnDemandPaymentByAccount(ctx context.Context, accountID geth
if t.bindings.PaymentVault == nil {
return nil, errors.New("payment vault not deployed")
}
onDemandPayment, err := t.bindings.PaymentVault.GetOnDemandAmount(&bind.CallOpts{
onDemandPayment, err := t.bindings.PaymentVault.GetOnDemandTotalDeposit(&bind.CallOpts{
Context: ctx,
}, accountID)
if err != nil {
Expand All @@ -777,28 +791,27 @@ 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.GlobalRateBinInterval(&bind.CallOpts{
globalSymbolsPerSecond, err := t.bindings.PaymentVault.GlobalRatePeriodInterval(&bind.CallOpts{
Context: ctx,
})
if err != nil {
return 0, err
}
return globalSymbolsPerSecond.Uint64(), nil
return globalSymbolsPerSecond, nil
}

func (t *Reader) GetGlobalRateBinInterval(ctx context.Context) (uint32, error) {
func (t *Reader) GetGlobalRatePeriodInterval(ctx context.Context) (uint32, error) {
if t.bindings.PaymentVault == nil {
return 0, errors.New("payment vault not deployed")
}
globalRateBinInterval, err := t.bindings.PaymentVault.GlobalRateBinInterval(&bind.CallOpts{
globalRateBinInterval, err := t.bindings.PaymentVault.GlobalRatePeriodInterval(&bind.CallOpts{
Context: ctx,
})
if err != nil {
return 0, err
}
return uint32(globalRateBinInterval.Uint64()), nil
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 All @@ -809,7 +822,7 @@ func (t *Reader) GetMinNumSymbols(ctx context.Context) (uint32, error) {
if err != nil {
return 0, err
}
return uint32(minNumSymbols.Uint64()), nil
return uint32(minNumSymbols), nil
}

func (t *Reader) GetPricePerSymbol(ctx context.Context) (uint32, error) {
Expand All @@ -822,29 +835,27 @@ func (t *Reader) GetPricePerSymbol(ctx context.Context) (uint32, error) {
if err != nil {
return 0, err
}
return uint32(pricePerSymbol.Uint64()), nil
return uint32(pricePerSymbol), nil
}

func (t *Reader) GetReservationWindow(ctx context.Context) (uint32, error) {
if t.bindings.PaymentVault == nil {
return 0, errors.New("payment vault not deployed")
}
reservationWindow, err := t.bindings.PaymentVault.ReservationBinInterval(&bind.CallOpts{
Context: ctx,
})
reservationWindow, err := t.bindings.PaymentVault.ReservationPeriodInterval(&bind.CallOpts{
Context: ctx})
if err != nil {
return 0, err
}
return uint32(reservationWindow.Uint64()), nil
return uint32(reservationWindow), nil
}

func (t *Reader) GetOperatorSocket(ctx context.Context, operatorId core.OperatorID) (string, error) {
if t.bindings.SocketRegistry == nil {
return "", errors.New("socket registry not enabled")
}
socket, err := t.bindings.SocketRegistry.GetOperatorSocket(&bind.CallOpts{
Context: ctx,
}, [32]byte(operatorId))
Context: ctx}, [32]byte(operatorId))
if err != nil {
return "", err
}
Expand Down
4 changes: 2 additions & 2 deletions core/meterer/meterer.go
Original file line number Diff line number Diff line change
Expand Up @@ -264,13 +264,13 @@ func (m *Meterer) SymbolsCharged(numSymbols uint) uint32 {

// IncrementBinUsage increments the bin usage atomically and checks for overflow
func (m *Meterer) IncrementGlobalBinUsage(ctx context.Context, symbolsCharged uint64) error {
globalPeriod := GetReservationPeriod(uint64(time.Now().Unix()), m.ChainPaymentState.GetGlobalRateBinInterval())
globalPeriod := GetReservationPeriod(uint64(time.Now().Unix()), m.ChainPaymentState.GetGlobalRatePeriodInterval())

newUsage, err := m.OffchainStore.UpdateGlobalBin(ctx, globalPeriod, symbolsCharged)
if err != nil {
return fmt.Errorf("failed to increment global bin usage: %w", err)
}
if newUsage > m.ChainPaymentState.GetGlobalSymbolsPerSecond() {
if newUsage > m.ChainPaymentState.GetGlobalSymbolsPerSecond()*uint64(m.ChainPaymentState.GetGlobalRatePeriodInterval()) {
return fmt.Errorf("global bin usage overflows")
}
return nil
Expand Down
2 changes: 1 addition & 1 deletion core/meterer/meterer_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -180,7 +180,7 @@ func TestMetererReservations(t *testing.T) {
ctx := context.Background()
paymentChainState.On("GetReservationWindow", testifymock.Anything).Return(uint32(1), nil)
paymentChainState.On("GetGlobalSymbolsPerSecond", testifymock.Anything).Return(uint64(1009), nil)
paymentChainState.On("GetGlobalRateBinInterval", testifymock.Anything).Return(uint32(1), nil)
paymentChainState.On("GetGlobalRatePeriodInterval", testifymock.Anything).Return(uint32(1), nil)
paymentChainState.On("GetMinNumSymbols", testifymock.Anything).Return(uint32(3), nil)

reservationPeriod := meterer.GetReservationPeriod(uint64(time.Now().Unix()), mt.ChainPaymentState.GetReservationWindow())
Expand Down
18 changes: 9 additions & 9 deletions core/meterer/onchain_state.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ type OnchainPayment interface {
GetOnDemandPaymentByAccount(ctx context.Context, accountID gethcommon.Address) (*core.OnDemandPayment, error)
GetOnDemandQuorumNumbers(ctx context.Context) ([]uint8, error)
GetGlobalSymbolsPerSecond() uint64
GetGlobalRateBinInterval() uint32
GetGlobalRatePeriodInterval() uint32
GetMinNumSymbols() uint32
GetPricePerSymbol() uint32
GetReservationWindow() uint32
Expand All @@ -40,12 +40,12 @@ type OnchainPaymentState struct {
}

type PaymentVaultParams struct {
GlobalSymbolsPerSecond uint64
GlobalRateBinInterval uint32
MinNumSymbols uint32
PricePerSymbol uint32
ReservationWindow uint32
OnDemandQuorumNumbers []uint8
GlobalSymbolsPerSecond uint64
GlobalRatePeriodInterval uint32
MinNumSymbols uint32
PricePerSymbol uint32
ReservationWindow uint32
OnDemandQuorumNumbers []uint8
}

func NewOnchainPaymentState(ctx context.Context, tx *eth.Reader) (*OnchainPaymentState, error) {
Expand Down Expand Up @@ -194,8 +194,8 @@ func (pcs *OnchainPaymentState) GetGlobalSymbolsPerSecond() uint64 {
return pcs.PaymentVaultParams.Load().GlobalSymbolsPerSecond
}

func (pcs *OnchainPaymentState) GetGlobalRateBinInterval() uint32 {
return pcs.PaymentVaultParams.Load().GlobalRateBinInterval
func (pcs *OnchainPaymentState) GetGlobalRatePeriodInterval() uint32 {
return pcs.PaymentVaultParams.Load().GlobalRatePeriodInterval
}

func (pcs *OnchainPaymentState) GetMinNumSymbols() uint32 {
Expand Down
2 changes: 1 addition & 1 deletion core/mock/payment_state.go
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ func (m *MockOnchainPaymentState) GetGlobalSymbolsPerSecond() uint64 {
return args.Get(0).(uint64)
}

func (m *MockOnchainPaymentState) GetGlobalRateBinInterval() uint32 {
func (m *MockOnchainPaymentState) GetGlobalRatePeriodInterval() uint32 {
args := m.Called()
return args.Get(0).(uint32)
}
Expand Down
2 changes: 1 addition & 1 deletion disperser/apiserver/server_v2_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -443,7 +443,7 @@ func newTestServerV2(t *testing.T) *testComponents {
mockState.On("GetReservationWindow", tmock.Anything).Return(uint32(1), nil)
mockState.On("GetPricePerSymbol", tmock.Anything).Return(uint32(2), nil)
mockState.On("GetGlobalSymbolsPerSecond", tmock.Anything).Return(uint64(1009), nil)
mockState.On("GetGlobalRateBinInterval", tmock.Anything).Return(uint32(1), nil)
mockState.On("GetGlobalRatePeriodInterval", tmock.Anything).Return(uint32(1), nil)
mockState.On("GetMinNumSymbols", tmock.Anything).Return(uint32(3), nil)

now := uint64(time.Now().Unix())
Expand Down
Loading