From afd077e317a419b438615e0a8f40e2dad7003d5b Mon Sep 17 00:00:00 2001 From: hopeyen Date: Fri, 22 Nov 2024 11:31:50 -0800 Subject: [PATCH 01/18] feat: fill in transactor payment contract call --- core/chainio.go | 10 ++-- core/data.go | 11 +---- core/eth/reader.go | 73 +++++++++++++++++++++++++----- core/meterer/meterer.go | 2 +- core/meterer/meterer_test.go | 4 +- core/meterer/onchain_state.go | 45 +++++++++++++----- core/meterer/onchain_state_test.go | 8 ++-- 7 files changed, 108 insertions(+), 45 deletions(-) diff --git a/core/chainio.go b/core/chainio.go index b5b587c8d2..4c1e464234 100644 --- a/core/chainio.go +++ b/core/chainio.go @@ -110,16 +110,16 @@ type Reader interface { GetAllVersionedBlobParams(ctx context.Context) (map[uint8]*BlobVersionParameters, error) // GetActiveReservations returns active reservations (end timestamp > current timestamp) - GetActiveReservations(ctx context.Context, blockNumber uint32, accountIDs []string) (map[string]ActiveReservation, error) + GetActiveReservations(ctx context.Context, accountIDs []string) (map[string]ActiveReservation, error) - // GetActiveReservationByAccount returns active reservation by account ID - GetActiveReservationByAccount(ctx context.Context, blockNumber uint32, accountID string) (ActiveReservation, error) + // GetActiveReservations returns active reservations (end timestamp > current timestamp) + GetActiveReservationByAccount(ctx context.Context, accountID string) (ActiveReservation, error) // GetOnDemandPayments returns all on-demand payments - GetOnDemandPayments(ctx context.Context, blockNumber uint32, accountIDs []string) (map[string]OnDemandPayment, error) + GetOnDemandPayments(ctx context.Context, accountIDs []string) (map[string]OnDemandPayment, error) // GetOnDemandPaymentByAccount returns on-demand payment of an account - GetOnDemandPaymentByAccount(ctx context.Context, blockNumber uint32, accountID string) (OnDemandPayment, error) + GetOnDemandPaymentByAccount(ctx context.Context, accountID string) (OnDemandPayment, error) // GetRelayURL returns the relay URL address for the given key. GetRelayURL(ctx context.Context, key uint32) (string, error) diff --git a/core/data.go b/core/data.go index 1a3b5218a8..6b09685526 100644 --- a/core/data.go +++ b/core/data.go @@ -9,6 +9,7 @@ import ( commonpb "github.com/Layr-Labs/eigenda/api/grpc/common" "github.com/Layr-Labs/eigenda/common" + paymentvault "github.com/Layr-Labs/eigenda/contracts/bindings/PaymentVault" "github.com/Layr-Labs/eigenda/encoding" "github.com/aws/aws-sdk-go-v2/service/dynamodb/types" "github.com/consensys/gnark-crypto/ecc/bn254" @@ -600,15 +601,7 @@ func ConvertToPaymentMetadata(ph *commonpb.PaymentHeader) *PaymentMetadata { // OperatorInfo contains information about an operator which is stored on the blockchain state, // corresponding to a particular quorum -type ActiveReservation struct { - SymbolsPerSec uint64 // reserve number of symbols per second - //TODO: we are not using start and end timestamp, add check or remove - StartTimestamp uint64 // Unix timestamp that's valid for basically eternity - EndTimestamp uint64 - - QuorumNumbers []uint8 // allowed quorums - QuorumSplit []byte // ordered mapping of quorum number to payment split; on-chain validation should ensure split <= 100 -} +type ActiveReservation = paymentvault.IPaymentVaultReservation type OnDemandPayment struct { CumulativePayment *big.Int // Total amount deposited by the user diff --git a/core/eth/reader.go b/core/eth/reader.go index 8e231f8675..2942965941 100644 --- a/core/eth/reader.go +++ b/core/eth/reader.go @@ -15,6 +15,7 @@ import ( relayreg "github.com/Layr-Labs/eigenda/contracts/bindings/IEigenDARelayRegistry" indexreg "github.com/Layr-Labs/eigenda/contracts/bindings/IIndexRegistry" opstateretriever "github.com/Layr-Labs/eigenda/contracts/bindings/OperatorStateRetriever" + paymentvault "github.com/Layr-Labs/eigenda/contracts/bindings/PaymentVault" regcoordinator "github.com/Layr-Labs/eigenda/contracts/bindings/RegistryCoordinator" socketreg "github.com/Layr-Labs/eigenda/contracts/bindings/SocketRegistry" stakereg "github.com/Layr-Labs/eigenda/contracts/bindings/StakeRegistry" @@ -41,6 +42,7 @@ type ContractBindings struct { AVSDirectory *avsdir.ContractAVSDirectory SocketRegistry *socketreg.ContractSocketRegistry RelayRegistry *relayreg.ContractIEigenDARelayRegistry + PaymentVault *paymentvault.ContractPaymentVault } type Reader struct { @@ -654,24 +656,71 @@ func (t *Reader) GetAllVersionedBlobParams(ctx context.Context) (map[uint8]*core return res, nil } -func (t *Reader) GetActiveReservations(ctx context.Context, blockNumber uint32, accountIDs []string) (map[string]core.ActiveReservation, error) { - // contract is not implemented yet - return map[string]core.ActiveReservation{}, nil +func (t *Reader) GetActiveReservations(ctx context.Context, accountIDs []string) (map[string]core.ActiveReservation, error) { + // map accountIDs to addresses + accountAddresses := make([]gethcommon.Address, len(accountIDs)) + for i, accountID := range accountIDs { + accountAddresses[i] = gethcommon.HexToAddress(accountID) + } + + reservations_map := make(map[string]core.ActiveReservation) + reservations, err := t.bindings.PaymentVault.GetReservations(&bind.CallOpts{ + Context: ctx, + }, accountAddresses) + if err != nil { + return nil, err + } + + // since reservations are returned in the same order as the accountIDs, we can directly map them + for i, reservation := range reservations { + reservations_map[accountIDs[i]] = reservation + } + return reservations_map, nil } -func (t *Reader) GetActiveReservationByAccount(ctx context.Context, blockNumber uint32, accountID string) (core.ActiveReservation, error) { - // contract is not implemented yet - return core.ActiveReservation{}, nil +func (t *Reader) GetActiveReservationByAccount(ctx context.Context, accountID string) (core.ActiveReservation, error) { + reservation, err := t.bindings.PaymentVault.GetReservation(&bind.CallOpts{ + Context: ctx, + }, gethcommon.HexToAddress(accountID)) + if err != nil { + return core.ActiveReservation{}, err + } + return reservation, nil } -func (t *Reader) GetOnDemandPayments(ctx context.Context, blockNumber uint32, accountIDs []string) (map[string]core.OnDemandPayment, error) { - // contract is not implemented yet - return map[string]core.OnDemandPayment{}, nil +func (t *Reader) GetOnDemandPayments(ctx context.Context, accountIDs []string) (map[string]core.OnDemandPayment, error) { + // map accountIDs to addresses + accountAddresses := make([]gethcommon.Address, len(accountIDs)) + for i, accountID := range accountIDs { + accountAddresses[i] = gethcommon.HexToAddress(accountID) + } + payments_map := make(map[string]core.OnDemandPayment) + payments, err := t.bindings.PaymentVault.GetOnDemandAmounts(&bind.CallOpts{ + Context: ctx, + }, accountAddresses) + if err != nil { + return nil, err + } + + // since payments are returned in the same order as the accountIDs, we can directly map them + for i, payment := range payments { + payments_map[accountIDs[i]] = core.OnDemandPayment{ + CumulativePayment: payment, + } + } + return payments_map, nil } -func (t *Reader) GetOnDemandPaymentByAccount(ctx context.Context, blockNumber uint32, accountID string) (core.OnDemandPayment, error) { - // contract is not implemented yet - return core.OnDemandPayment{}, nil +func (t *Reader) GetOnDemandPaymentByAccount(ctx context.Context, accountID string) (core.OnDemandPayment, error) { + onDemandPayment, err := t.bindings.PaymentVault.GetOnDemandAmount(&bind.CallOpts{ + Context: ctx, + }, gethcommon.HexToAddress(accountID)) + if err != nil { + return core.OnDemandPayment{}, err + } + return core.OnDemandPayment{ + CumulativePayment: onDemandPayment, + }, nil } func (t *Reader) GetGlobalSymbolsPerSecond(ctx context.Context) (uint64, error) { diff --git a/core/meterer/meterer.go b/core/meterer/meterer.go index ba1f2cfc65..2c93626c34 100644 --- a/core/meterer/meterer.go +++ b/core/meterer/meterer.go @@ -281,5 +281,5 @@ func (m *Meterer) IncrementGlobalBinUsage(ctx context.Context, symbolsCharged ui // GetReservationBinLimit returns the bin limit for a given reservation func (m *Meterer) GetReservationBinLimit(reservation *core.ActiveReservation) uint64 { - return reservation.SymbolsPerSec * uint64(m.ChainPaymentState.GetReservationWindow()) + return reservation.SymbolsPerSecond * uint64(m.ChainPaymentState.GetReservationWindow()) } diff --git a/core/meterer/meterer_test.go b/core/meterer/meterer_test.go index d4298d6017..99ece955e5 100644 --- a/core/meterer/meterer_test.go +++ b/core/meterer/meterer_test.go @@ -125,8 +125,8 @@ func setup(_ *testing.M) { now := uint64(time.Now().Unix()) accountID1 = crypto.PubkeyToAddress(privateKey1.PublicKey).Hex() accountID2 = crypto.PubkeyToAddress(privateKey2.PublicKey).Hex() - account1Reservations = core.ActiveReservation{SymbolsPerSec: 100, StartTimestamp: now + 1200, EndTimestamp: now + 1800, QuorumSplit: []byte{50, 50}, QuorumNumbers: []uint8{0, 1}} - account2Reservations = core.ActiveReservation{SymbolsPerSec: 200, StartTimestamp: now - 120, EndTimestamp: now + 180, QuorumSplit: []byte{30, 70}, QuorumNumbers: []uint8{0, 1}} + account1Reservations = core.ActiveReservation{SymbolsPerSecond: 100, StartTimestamp: now + 1200, EndTimestamp: now + 1800, QuorumSplits: []byte{50, 50}, QuorumNumbers: []uint8{0, 1}} + account2Reservations = core.ActiveReservation{SymbolsPerSecond: 200, StartTimestamp: now - 120, EndTimestamp: now + 180, QuorumSplits: []byte{30, 70}, QuorumNumbers: []uint8{0, 1}} account1OnDemandPayments = core.OnDemandPayment{CumulativePayment: big.NewInt(3864)} account2OnDemandPayments = core.OnDemandPayment{CumulativePayment: big.NewInt(2000)} diff --git a/core/meterer/onchain_state.go b/core/meterer/onchain_state.go index 2725ef765e..4e2ace64ee 100644 --- a/core/meterer/onchain_state.go +++ b/core/meterer/onchain_state.go @@ -107,6 +107,33 @@ func (pcs *OnchainPaymentState) RefreshOnchainPaymentState(ctx context.Context, } // These parameters should be rarely updated, but we refresh them anyway pcs.PaymentVaultParams = paymentVaultParams + + pcs.ReservationsLock.Lock() + accountIDs := make([]string, 0, len(pcs.ActiveReservations)) + for accountID := range pcs.ActiveReservations { + accountIDs = append(accountIDs, accountID) + } + + activeReservations, err := tx.GetActiveReservations(ctx, accountIDs) + if err != nil { + return err + } + pcs.ActiveReservations = activeReservations + pcs.ReservationsLock.Unlock() + + pcs.OnDemandLocks.Lock() + accountIDs = make([]string, 0, len(pcs.OnDemandPayments)) + for accountID := range pcs.OnDemandPayments { + accountIDs = append(accountIDs, accountID) + } + + onDemandPayments, err := tx.GetOnDemandPayments(ctx, accountIDs) + if err != nil { + return err + } + pcs.OnDemandPayments = onDemandPayments + pcs.OnDemandLocks.Unlock() + return nil } @@ -115,7 +142,8 @@ func (pcs *OnchainPaymentState) GetActiveReservationByAccount(ctx context.Contex if reservation, ok := pcs.ActiveReservations[accountID]; ok { return reservation, nil } - res, err := pcs.GetActiveReservationByAccountOnChain(ctx, accountID) + // pulls the chain state + res, err := pcs.tx.GetActiveReservationByAccount(ctx, accountID) if err != nil { return core.ActiveReservation{}, err } @@ -128,11 +156,7 @@ func (pcs *OnchainPaymentState) GetActiveReservationByAccount(ctx context.Contex // GetActiveReservationByAccountOnChain returns on-chain reservation for the given account ID func (pcs *OnchainPaymentState) GetActiveReservationByAccountOnChain(ctx context.Context, accountID string) (core.ActiveReservation, error) { - blockNumber, err := pcs.tx.GetCurrentBlockNumber(ctx) - if err != nil { - return core.ActiveReservation{}, err - } - res, err := pcs.tx.GetActiveReservationByAccount(ctx, blockNumber, accountID) + res, err := pcs.tx.GetActiveReservationByAccount(ctx, accountID) if err != nil { return core.ActiveReservation{}, fmt.Errorf("reservation account not found on-chain: %w", err) } @@ -144,7 +168,8 @@ func (pcs *OnchainPaymentState) GetOnDemandPaymentByAccount(ctx context.Context, if payment, ok := pcs.OnDemandPayments[accountID]; ok { return payment, nil } - res, err := pcs.GetOnDemandPaymentByAccountOnChain(ctx, accountID) + // pulls the chain state + res, err := pcs.tx.GetOnDemandPaymentByAccount(ctx, accountID) if err != nil { return core.OnDemandPayment{}, err } @@ -156,11 +181,7 @@ func (pcs *OnchainPaymentState) GetOnDemandPaymentByAccount(ctx context.Context, } func (pcs *OnchainPaymentState) GetOnDemandPaymentByAccountOnChain(ctx context.Context, accountID string) (core.OnDemandPayment, error) { - blockNumber, err := pcs.tx.GetCurrentBlockNumber(ctx) - if err != nil { - return core.OnDemandPayment{}, err - } - res, err := pcs.tx.GetOnDemandPaymentByAccount(ctx, blockNumber, accountID) + res, err := pcs.tx.GetOnDemandPaymentByAccount(ctx, accountID) if err != nil { return core.OnDemandPayment{}, fmt.Errorf("on-demand not found on-chain: %w", err) } diff --git a/core/meterer/onchain_state_test.go b/core/meterer/onchain_state_test.go index efd7149a63..ae14dc55eb 100644 --- a/core/meterer/onchain_state_test.go +++ b/core/meterer/onchain_state_test.go @@ -14,10 +14,10 @@ import ( var ( dummyActiveReservation = core.ActiveReservation{ - SymbolsPerSec: 100, - StartTimestamp: 1000, - EndTimestamp: 2000, - QuorumSplit: []byte{50, 50}, + SymbolsPerSecond: 100, + StartTimestamp: 1000, + EndTimestamp: 2000, + QuorumSplits: []byte{50, 50}, } dummyOnDemandPayment = core.OnDemandPayment{ CumulativePayment: big.NewInt(1000), From a1f9d6aa53b5a87248e5511ff11690e5e0e9c5f3 Mon Sep 17 00:00:00 2001 From: hopeyen Date: Fri, 22 Nov 2024 11:36:14 -0800 Subject: [PATCH 02/18] fix: use on-chain field names --- api/clients/accountant.go | 2 +- api/clients/accountant_test.go | 80 +++++++++++++++--------------- core/mock/writer.go | 8 +-- disperser/apiserver/server_test.go | 10 ++-- test/integration_test.go | 2 +- 5 files changed, 51 insertions(+), 51 deletions(-) diff --git a/api/clients/accountant.go b/api/clients/accountant.go index bd8192b31e..02cf11ac26 100644 --- a/api/clients/accountant.go +++ b/api/clients/accountant.go @@ -77,7 +77,7 @@ func (a *Accountant) BlobPaymentInfo(ctx context.Context, numSymbols uint64, quo relativeBinRecord.Usage += numSymbols // first attempt to use the active reservation - binLimit := a.reservation.SymbolsPerSec * uint64(a.reservationWindow) + binLimit := a.reservation.SymbolsPerSecond * uint64(a.reservationWindow) if relativeBinRecord.Usage <= binLimit { if err := QuorumCheck(quorumNumbers, a.reservation.QuorumNumbers); err != nil { return 0, big.NewInt(0), err diff --git a/api/clients/accountant_test.go b/api/clients/accountant_test.go index 09b880664c..5c19e15926 100644 --- a/api/clients/accountant_test.go +++ b/api/clients/accountant_test.go @@ -18,11 +18,11 @@ const numBins = uint32(3) func TestNewAccountant(t *testing.T) { reservation := &core.ActiveReservation{ - SymbolsPerSec: 100, - StartTimestamp: 100, - EndTimestamp: 200, - QuorumSplit: []byte{50, 50}, - QuorumNumbers: []uint8{0, 1}, + SymbolsPerSecond: 100, + StartTimestamp: 100, + EndTimestamp: 200, + QuorumSplits: []byte{50, 50}, + QuorumNumbers: []uint8{0, 1}, } onDemand := &core.OnDemandPayment{ CumulativePayment: big.NewInt(500), @@ -48,11 +48,11 @@ func TestNewAccountant(t *testing.T) { func TestAccountBlob_Reservation(t *testing.T) { reservation := &core.ActiveReservation{ - SymbolsPerSec: 200, - StartTimestamp: 100, - EndTimestamp: 200, - QuorumSplit: []byte{50, 50}, - QuorumNumbers: []uint8{0, 1}, + SymbolsPerSecond: 200, + StartTimestamp: 100, + EndTimestamp: 200, + QuorumSplits: []byte{50, 50}, + QuorumNumbers: []uint8{0, 1}, } onDemand := &core.OnDemandPayment{ CumulativePayment: big.NewInt(500), @@ -96,11 +96,11 @@ func TestAccountBlob_Reservation(t *testing.T) { func TestAccountBlob_OnDemand(t *testing.T) { reservation := &core.ActiveReservation{ - SymbolsPerSec: 200, - StartTimestamp: 100, - EndTimestamp: 200, - QuorumSplit: []byte{50, 50}, - QuorumNumbers: []uint8{0, 1}, + SymbolsPerSecond: 200, + StartTimestamp: 100, + EndTimestamp: 200, + QuorumSplits: []byte{50, 50}, + QuorumNumbers: []uint8{0, 1}, } onDemand := &core.OnDemandPayment{ CumulativePayment: big.NewInt(1500), @@ -152,11 +152,11 @@ func TestAccountBlob_InsufficientOnDemand(t *testing.T) { func TestAccountBlobCallSeries(t *testing.T) { reservation := &core.ActiveReservation{ - SymbolsPerSec: 200, - StartTimestamp: 100, - EndTimestamp: 200, - QuorumSplit: []byte{50, 50}, - QuorumNumbers: []uint8{0, 1}, + SymbolsPerSecond: 200, + StartTimestamp: 100, + EndTimestamp: 200, + QuorumSplits: []byte{50, 50}, + QuorumNumbers: []uint8{0, 1}, } onDemand := &core.OnDemandPayment{ CumulativePayment: big.NewInt(1000), @@ -200,11 +200,11 @@ func TestAccountBlobCallSeries(t *testing.T) { func TestAccountBlob_BinRotation(t *testing.T) { reservation := &core.ActiveReservation{ - SymbolsPerSec: 1000, - StartTimestamp: 100, - EndTimestamp: 200, - QuorumSplit: []byte{50, 50}, - QuorumNumbers: []uint8{0, 1}, + SymbolsPerSecond: 1000, + StartTimestamp: 100, + EndTimestamp: 200, + QuorumSplits: []byte{50, 50}, + QuorumNumbers: []uint8{0, 1}, } onDemand := &core.OnDemandPayment{ CumulativePayment: big.NewInt(1000), @@ -242,11 +242,11 @@ func TestAccountBlob_BinRotation(t *testing.T) { func TestConcurrentBinRotationAndAccountBlob(t *testing.T) { reservation := &core.ActiveReservation{ - SymbolsPerSec: 1000, - StartTimestamp: 100, - EndTimestamp: 200, - QuorumSplit: []byte{50, 50}, - QuorumNumbers: []uint8{0, 1}, + SymbolsPerSecond: 1000, + StartTimestamp: 100, + EndTimestamp: 200, + QuorumSplits: []byte{50, 50}, + QuorumNumbers: []uint8{0, 1}, } onDemand := &core.OnDemandPayment{ CumulativePayment: big.NewInt(1000), @@ -288,11 +288,11 @@ func TestConcurrentBinRotationAndAccountBlob(t *testing.T) { func TestAccountBlob_ReservationWithOneOverflow(t *testing.T) { reservation := &core.ActiveReservation{ - SymbolsPerSec: 200, - StartTimestamp: 100, - EndTimestamp: 200, - QuorumSplit: []byte{50, 50}, - QuorumNumbers: []uint8{0, 1}, + SymbolsPerSecond: 200, + StartTimestamp: 100, + EndTimestamp: 200, + QuorumSplits: []byte{50, 50}, + QuorumNumbers: []uint8{0, 1}, } onDemand := &core.OnDemandPayment{ CumulativePayment: big.NewInt(1000), @@ -333,11 +333,11 @@ func TestAccountBlob_ReservationWithOneOverflow(t *testing.T) { func TestAccountBlob_ReservationOverflowReset(t *testing.T) { reservation := &core.ActiveReservation{ - SymbolsPerSec: 1000, - StartTimestamp: 100, - EndTimestamp: 200, - QuorumSplit: []byte{50, 50}, - QuorumNumbers: []uint8{0, 1}, + SymbolsPerSecond: 1000, + StartTimestamp: 100, + EndTimestamp: 200, + QuorumSplits: []byte{50, 50}, + QuorumNumbers: []uint8{0, 1}, } onDemand := &core.OnDemandPayment{ CumulativePayment: big.NewInt(1000), diff --git a/core/mock/writer.go b/core/mock/writer.go index 7e56e64cc3..d8dd4f406e 100644 --- a/core/mock/writer.go +++ b/core/mock/writer.go @@ -221,25 +221,25 @@ func (t *MockWriter) PubkeyHashToOperator(ctx context.Context, operatorId core.O return result.(gethcommon.Address), args.Error(1) } -func (t *MockWriter) GetActiveReservations(ctx context.Context, blockNumber uint32, accountIDs []string) (map[string]core.ActiveReservation, error) { +func (t *MockWriter) GetActiveReservations(ctx context.Context, accountIDs []string) (map[string]core.ActiveReservation, error) { args := t.Called() result := args.Get(0) return result.(map[string]core.ActiveReservation), args.Error(1) } -func (t *MockWriter) GetActiveReservationByAccount(ctx context.Context, blockNumber uint32, accountID string) (core.ActiveReservation, error) { +func (t *MockWriter) GetActiveReservationByAccount(ctx context.Context, accountID string) (core.ActiveReservation, error) { args := t.Called() result := args.Get(0) return result.(core.ActiveReservation), args.Error(1) } -func (t *MockWriter) GetOnDemandPayments(ctx context.Context, blockNumber uint32, accountIDs []string) (map[string]core.OnDemandPayment, error) { +func (t *MockWriter) GetOnDemandPayments(ctx context.Context, accountIDs []string) (map[string]core.OnDemandPayment, error) { args := t.Called() result := args.Get(0) return result.(map[string]core.OnDemandPayment), args.Error(1) } -func (t *MockWriter) GetOnDemandPaymentByAccount(ctx context.Context, blockNumber uint32, accountID string) (core.OnDemandPayment, error) { +func (t *MockWriter) GetOnDemandPaymentByAccount(ctx context.Context, accountID string) (core.OnDemandPayment, error) { args := t.Called() result := args.Get(0) return result.(core.OnDemandPayment), args.Error(1) diff --git a/disperser/apiserver/server_test.go b/disperser/apiserver/server_test.go index 43a5b0333b..b426455550 100644 --- a/disperser/apiserver/server_test.go +++ b/disperser/apiserver/server_test.go @@ -762,11 +762,11 @@ func newTestServer(transactor core.Writer, testName string) *apiserver.Dispersal CumulativePayment: big.NewInt(3000), }, nil) mockState.On("GetActiveReservationByAccount", tmock.Anything, tmock.Anything).Return(core.ActiveReservation{ - SymbolsPerSec: 2048, - StartTimestamp: 0, - EndTimestamp: math.MaxUint32, - QuorumNumbers: []uint8{0, 1}, - QuorumSplit: []byte{50, 50}, + SymbolsPerSecond: 2048, + StartTimestamp: 0, + EndTimestamp: math.MaxUint32, + QuorumNumbers: []uint8{0, 1}, + QuorumSplits: []byte{50, 50}, }, nil) // append test name to each table name for an unique store table_names := []string{"reservations_server_" + testName, "ondemand_server_" + testName, "global_server_" + testName} diff --git a/test/integration_test.go b/test/integration_test.go index b3efdc25f1..4f36b5065d 100644 --- a/test/integration_test.go +++ b/test/integration_test.go @@ -223,7 +223,7 @@ func mustMakeDisperser(t *testing.T, cst core.IndexedChainState, store disperser paymentLimit := big.NewInt(512) mockState.On("GetActiveReservationByAccount", mock.Anything, mock.MatchedBy(func(account string) bool { return account == publicKey - })).Return(core.ActiveReservation{SymbolsPerSec: reservationLimit, StartTimestamp: 0, EndTimestamp: math.MaxUint32, QuorumSplit: []byte{50, 50}, QuorumNumbers: []uint8{0, 1}}, nil) + })).Return(core.ActiveReservation{SymbolsPerSecond: reservationLimit, StartTimestamp: 0, EndTimestamp: math.MaxUint32, QuorumSplits: []byte{50, 50}, QuorumNumbers: []uint8{0, 1}}, nil) mockState.On("GetActiveReservationByAccount", mock.Anything, mock.Anything).Return(core.ActiveReservation{}, errors.New("reservation not found")) mockState.On("GetOnDemandPaymentByAccount", mock.Anything, mock.MatchedBy(func(account string) bool { From 75320b19fc3048e5dc3212738311cc492bc6c237 Mon Sep 17 00:00:00 2001 From: hopeyen Date: Fri, 22 Nov 2024 12:02:10 -0800 Subject: [PATCH 03/18] fix: fill in global param contract calls --- core/eth/reader.go | 46 ++++++++++++++++++++++++++++++++++++++-------- 1 file changed, 38 insertions(+), 8 deletions(-) diff --git a/core/eth/reader.go b/core/eth/reader.go index 2942965941..31cf1f6ce6 100644 --- a/core/eth/reader.go +++ b/core/eth/reader.go @@ -724,23 +724,53 @@ func (t *Reader) GetOnDemandPaymentByAccount(ctx context.Context, accountID stri } func (t *Reader) GetGlobalSymbolsPerSecond(ctx context.Context) (uint64, error) { - // contract is not implemented yet - return 0, nil + globalSymbolsPerSecond, err := t.bindings.PaymentVault.GlobalRateBinInterval(&bind.CallOpts{ + Context: ctx, + }) + if err != nil { + return 0, err + } + return globalSymbolsPerSecond.Uint64(), nil +} + +func (t *Reader) GetGlobalRateBinInterval(ctx context.Context) (uint64, error) { + globalRateBinInterval, err := t.bindings.PaymentVault.GlobalRateBinInterval(&bind.CallOpts{ + Context: ctx, + }) + if err != nil { + return 0, err + } + return globalRateBinInterval.Uint64(), nil } func (t *Reader) GetMinNumSymbols(ctx context.Context) (uint32, error) { - // contract is not implemented yet - return 0, nil + minNumSymbols, err := t.bindings.PaymentVault.MinNumSymbols(&bind.CallOpts{ + Context: ctx, + }) + if err != nil { + return 0, err + } + return uint32(minNumSymbols.Uint64()), nil } func (t *Reader) GetPricePerSymbol(ctx context.Context) (uint32, error) { - // contract is not implemented yet - return 0, nil + pricePerSymbol, err := t.bindings.PaymentVault.PricePerSymbol(&bind.CallOpts{ + Context: ctx, + }) + if err != nil { + return 0, err + } + return uint32(pricePerSymbol.Uint64()), nil } func (t *Reader) GetReservationWindow(ctx context.Context) (uint32, error) { - // contract is not implemented yet - return 0, nil + reservationWindow, err := t.bindings.PaymentVault.ReservationBinInterval(&bind.CallOpts{ + Context: ctx, + }) + if err != nil { + return 0, err + } + return uint32(reservationWindow.Uint64()), nil } func (t *Reader) GetOperatorSocket(ctx context.Context, operatorId core.OperatorID) (string, error) { From eee8f4e2fe8e7e0a6445d3ea23fd7e5b5fbcf89d Mon Sep 17 00:00:00 2001 From: hopeyen Date: Mon, 25 Nov 2024 10:18:05 -0800 Subject: [PATCH 04/18] feat: global bin interval calls --- core/meterer/meterer.go | 1 + core/meterer/meterer_test.go | 1 + core/meterer/onchain_state.go | 6 ++++++ core/mock/payment_state.go | 5 +++++ 4 files changed, 13 insertions(+) diff --git a/core/meterer/meterer.go b/core/meterer/meterer.go index 2c93626c34..d1bed19bcb 100644 --- a/core/meterer/meterer.go +++ b/core/meterer/meterer.go @@ -268,6 +268,7 @@ func (m *Meterer) ValidateGlobalBinIndex(header core.PaymentMetadata) (uint32, e // IncrementBinUsage increments the bin usage atomically and checks for overflow func (m *Meterer) IncrementGlobalBinUsage(ctx context.Context, symbolsCharged uint64) error { + //TODO: edit globalIndex based on bin interval in a subsequent PR globalIndex := uint64(time.Now().Unix()) newUsage, err := m.OffchainStore.UpdateGlobalBin(ctx, globalIndex, symbolsCharged) if err != nil { diff --git a/core/meterer/meterer_test.go b/core/meterer/meterer_test.go index 99ece955e5..fe32051fce 100644 --- a/core/meterer/meterer_test.go +++ b/core/meterer/meterer_test.go @@ -170,6 +170,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(uint64(1), nil) paymentChainState.On("GetMinNumSymbols", testifymock.Anything).Return(uint32(3), nil) binIndex := meterer.GetBinIndex(uint64(time.Now().Unix()), mt.ChainPaymentState.GetReservationWindow()) diff --git a/core/meterer/onchain_state.go b/core/meterer/onchain_state.go index 4e2ace64ee..85487ebba4 100644 --- a/core/meterer/onchain_state.go +++ b/core/meterer/onchain_state.go @@ -18,6 +18,7 @@ type OnchainPayment interface { GetOnDemandPaymentByAccount(ctx context.Context, accountID string) (core.OnDemandPayment, error) GetOnDemandQuorumNumbers(ctx context.Context) ([]uint8, error) GetGlobalSymbolsPerSecond() uint64 + GetGlobalRateBinInterval() uint64 GetMinNumSymbols() uint32 GetPricePerSymbol() uint32 GetReservationWindow() uint32 @@ -39,6 +40,7 @@ type OnchainPaymentState struct { type PaymentVaultParams struct { GlobalSymbolsPerSecond uint64 + GlobalRateBinInterval uint64 MinNumSymbols uint32 PricePerSymbol uint32 ReservationWindow uint32 @@ -200,6 +202,10 @@ func (pcs *OnchainPaymentState) GetGlobalSymbolsPerSecond() uint64 { return pcs.PaymentVaultParams.GlobalSymbolsPerSecond } +func (pcs *OnchainPaymentState) GetGlobalRateBinInterval() uint64 { + return pcs.PaymentVaultParams.GlobalRateBinInterval +} + func (pcs *OnchainPaymentState) GetMinNumSymbols() uint32 { return pcs.PaymentVaultParams.MinNumSymbols } diff --git a/core/mock/payment_state.go b/core/mock/payment_state.go index c5e7885107..80725189a1 100644 --- a/core/mock/payment_state.go +++ b/core/mock/payment_state.go @@ -61,6 +61,11 @@ func (m *MockOnchainPaymentState) GetGlobalSymbolsPerSecond() uint64 { return args.Get(0).(uint64) } +func (m *MockOnchainPaymentState) GetGlobalRateBinInterval() uint64 { + args := m.Called() + return args.Get(0).(uint64) +} + func (m *MockOnchainPaymentState) GetMinNumSymbols() uint32 { args := m.Called() return args.Get(0).(uint32) From 56c85e16369a0b972423002e141d52b492995e9a Mon Sep 17 00:00:00 2001 From: hopeyen Date: Wed, 4 Dec 2024 12:57:46 -0800 Subject: [PATCH 05/18] refactor: ptrs, addrs, zero-value mapping check --- core/chainio.go | 10 ++--- core/eth/reader.go | 70 +++++++++++++++++------------- core/eth/utils.go | 8 ++++ core/meterer/meterer.go | 10 +++-- core/meterer/onchain_state.go | 69 ++++++++++++++--------------- core/meterer/onchain_state_test.go | 6 +-- core/mock/payment_state.go | 13 +++--- core/mock/writer.go | 16 +++---- 8 files changed, 113 insertions(+), 89 deletions(-) diff --git a/core/chainio.go b/core/chainio.go index 4c1e464234..f75a753c30 100644 --- a/core/chainio.go +++ b/core/chainio.go @@ -110,16 +110,16 @@ type Reader interface { GetAllVersionedBlobParams(ctx context.Context) (map[uint8]*BlobVersionParameters, error) // GetActiveReservations returns active reservations (end timestamp > current timestamp) - GetActiveReservations(ctx context.Context, accountIDs []string) (map[string]ActiveReservation, error) + GetActiveReservations(ctx context.Context, accountIDs []gethcommon.Address) (*map[gethcommon.Address]ActiveReservation, error) - // GetActiveReservations returns active reservations (end timestamp > current timestamp) - GetActiveReservationByAccount(ctx context.Context, accountID string) (ActiveReservation, error) + // GetActiveReservationByAccount returns active reservation by account ID + GetActiveReservationByAccount(ctx context.Context, accountID gethcommon.Address) (*ActiveReservation, error) // GetOnDemandPayments returns all on-demand payments - GetOnDemandPayments(ctx context.Context, accountIDs []string) (map[string]OnDemandPayment, error) + GetOnDemandPayments(ctx context.Context, accountIDs []gethcommon.Address) (*map[gethcommon.Address]OnDemandPayment, error) // GetOnDemandPaymentByAccount returns on-demand payment of an account - GetOnDemandPaymentByAccount(ctx context.Context, accountID string) (OnDemandPayment, error) + GetOnDemandPaymentByAccount(ctx context.Context, accountID gethcommon.Address) (*OnDemandPayment, error) // GetRelayURL returns the relay URL address for the given key. GetRelayURL(ctx context.Context, key uint32) (string, error) diff --git a/core/eth/reader.go b/core/eth/reader.go index 31cf1f6ce6..7db421d102 100644 --- a/core/eth/reader.go +++ b/core/eth/reader.go @@ -210,6 +210,7 @@ func (t *Reader) updateContractBindings(blsOperatorStateRetrieverAddr, eigenDASe EigenDAServiceManager: contractEigenDAServiceManager, DelegationManager: contractDelegationManager, RelayRegistry: contractRelayRegistry, + // PaymentVault: contractPaymentVault, } return nil } @@ -656,69 +657,80 @@ func (t *Reader) GetAllVersionedBlobParams(ctx context.Context) (map[uint8]*core return res, nil } -func (t *Reader) GetActiveReservations(ctx context.Context, accountIDs []string) (map[string]core.ActiveReservation, error) { - // map accountIDs to addresses - accountAddresses := make([]gethcommon.Address, len(accountIDs)) - for i, accountID := range accountIDs { - accountAddresses[i] = gethcommon.HexToAddress(accountID) - } - - reservations_map := make(map[string]core.ActiveReservation) +func (t *Reader) GetActiveReservations(ctx context.Context, accountIDs []gethcommon.Address) (*map[gethcommon.Address]core.ActiveReservation, error) { + reservationsMap := make(map[gethcommon.Address]core.ActiveReservation) reservations, err := t.bindings.PaymentVault.GetReservations(&bind.CallOpts{ Context: ctx, - }, accountAddresses) + }, accountIDs) if err != nil { return nil, err } // since reservations are returned in the same order as the accountIDs, we can directly map them for i, reservation := range reservations { - reservations_map[accountIDs[i]] = reservation + reservationsMap[accountIDs[i]] = reservation + } + + // filter out all zero-valued reservations + for accountID, reservation := range reservationsMap { + if isZeroValuedReservation(reservation) { + delete(reservationsMap, accountID) + } } - return reservations_map, nil + + return &reservationsMap, nil } -func (t *Reader) GetActiveReservationByAccount(ctx context.Context, accountID string) (core.ActiveReservation, error) { +func (t *Reader) GetActiveReservationByAccount(ctx context.Context, accountID gethcommon.Address) (*core.ActiveReservation, error) { reservation, err := t.bindings.PaymentVault.GetReservation(&bind.CallOpts{ Context: ctx, - }, gethcommon.HexToAddress(accountID)) + }, accountID) if err != nil { - return core.ActiveReservation{}, err + return nil, err + } + if isZeroValuedReservation(reservation) { + return nil, errors.New("reservation is zero-valued") } - return reservation, nil + return &reservation, nil } -func (t *Reader) GetOnDemandPayments(ctx context.Context, accountIDs []string) (map[string]core.OnDemandPayment, error) { - // map accountIDs to addresses - accountAddresses := make([]gethcommon.Address, len(accountIDs)) - for i, accountID := range accountIDs { - accountAddresses[i] = gethcommon.HexToAddress(accountID) - } - payments_map := make(map[string]core.OnDemandPayment) +func (t *Reader) GetOnDemandPayments(ctx context.Context, accountIDs []gethcommon.Address) (*map[gethcommon.Address]core.OnDemandPayment, error) { + paymentsMap := make(map[gethcommon.Address]core.OnDemandPayment) payments, err := t.bindings.PaymentVault.GetOnDemandAmounts(&bind.CallOpts{ Context: ctx, - }, accountAddresses) + }, accountIDs) if err != nil { return nil, err } // since payments are returned in the same order as the accountIDs, we can directly map them for i, payment := range payments { - payments_map[accountIDs[i]] = core.OnDemandPayment{ + paymentsMap[accountIDs[i]] = core.OnDemandPayment{ CumulativePayment: payment, } } - return payments_map, nil + + // filter out all zero-valued payments + for accountID, payment := range paymentsMap { + if payment.CumulativePayment.Cmp(big.NewInt(0)) == 0 { + delete(paymentsMap, accountID) + } + } + + return &paymentsMap, nil } -func (t *Reader) GetOnDemandPaymentByAccount(ctx context.Context, accountID string) (core.OnDemandPayment, error) { +func (t *Reader) GetOnDemandPaymentByAccount(ctx context.Context, accountID gethcommon.Address) (*core.OnDemandPayment, error) { onDemandPayment, err := t.bindings.PaymentVault.GetOnDemandAmount(&bind.CallOpts{ Context: ctx, - }, gethcommon.HexToAddress(accountID)) + }, accountID) if err != nil { - return core.OnDemandPayment{}, err + return nil, err + } + if onDemandPayment == big.NewInt(0) { + return nil, errors.New("on-demand payment is zero-valued") } - return core.OnDemandPayment{ + return &core.OnDemandPayment{ CumulativePayment: onDemandPayment, }, nil } diff --git a/core/eth/utils.go b/core/eth/utils.go index 8556fa82d4..973db46e2d 100644 --- a/core/eth/utils.go +++ b/core/eth/utils.go @@ -2,11 +2,13 @@ package eth import ( "math/big" + "reflect" "slices" "github.com/Layr-Labs/eigenda/core" eigendasrvmg "github.com/Layr-Labs/eigenda/contracts/bindings/EigenDAServiceManager" + paymentvault "github.com/Layr-Labs/eigenda/contracts/bindings/PaymentVault" "github.com/ethereum/go-ethereum/crypto" ) @@ -126,3 +128,9 @@ func bitmapToBytesArray(bitmap *big.Int) []byte { } return bytesArray } + +func isZeroValuedReservation(reservation paymentvault.IPaymentVaultReservation) bool { + zeroReservation := paymentvault.IPaymentVaultReservation{} + + return reflect.DeepEqual(reservation, zeroReservation) +} diff --git a/core/meterer/meterer.go b/core/meterer/meterer.go index d1bed19bcb..f8d46d0b72 100644 --- a/core/meterer/meterer.go +++ b/core/meterer/meterer.go @@ -8,6 +8,7 @@ import ( "github.com/Layr-Labs/eigenda/core" "github.com/Layr-Labs/eigensdk-go/logging" + gethcommon "github.com/ethereum/go-ethereum/common" ) // Config contains network parameters that should be published on-chain. We currently configure these params through disperser env vars. @@ -71,21 +72,22 @@ func (m *Meterer) Start(ctx context.Context) { // MeterRequest validates a blob header and adds it to the meterer's state // TODO: return error if there's a rejection (with reasoning) or internal error (should be very rare) func (m *Meterer) MeterRequest(ctx context.Context, header core.PaymentMetadata, numSymbols uint, quorumNumbers []uint8) error { + accountID := gethcommon.HexToAddress(header.AccountID) // Validate against the payment method if header.CumulativePayment.Sign() == 0 { - reservation, err := m.ChainPaymentState.GetActiveReservationByAccount(ctx, header.AccountID) + reservation, err := m.ChainPaymentState.GetActiveReservationByAccount(ctx, accountID) if err != nil { return fmt.Errorf("failed to get active reservation by account: %w", err) } - if err := m.ServeReservationRequest(ctx, header, &reservation, numSymbols, quorumNumbers); err != nil { + if err := m.ServeReservationRequest(ctx, header, reservation, numSymbols, quorumNumbers); err != nil { return fmt.Errorf("invalid reservation: %w", err) } } else { - onDemandPayment, err := m.ChainPaymentState.GetOnDemandPaymentByAccount(ctx, header.AccountID) + onDemandPayment, err := m.ChainPaymentState.GetOnDemandPaymentByAccount(ctx, accountID) if err != nil { return fmt.Errorf("failed to get on-demand payment by account: %w", err) } - if err := m.ServeOnDemandRequest(ctx, header, &onDemandPayment, numSymbols, quorumNumbers); err != nil { + if err := m.ServeOnDemandRequest(ctx, header, onDemandPayment, numSymbols, quorumNumbers); err != nil { return fmt.Errorf("invalid on-demand request: %w", err) } } diff --git a/core/meterer/onchain_state.go b/core/meterer/onchain_state.go index 85487ebba4..610adcf76c 100644 --- a/core/meterer/onchain_state.go +++ b/core/meterer/onchain_state.go @@ -7,6 +7,7 @@ import ( "github.com/Layr-Labs/eigenda/core" "github.com/Layr-Labs/eigenda/core/eth" + gethcommon "github.com/ethereum/go-ethereum/common" ) // PaymentAccounts (For reservations and on-demand payments) @@ -14,8 +15,8 @@ import ( // OnchainPaymentState is an interface for getting information about the current chain state for payments. type OnchainPayment interface { RefreshOnchainPaymentState(ctx context.Context, tx *eth.Reader) error - GetActiveReservationByAccount(ctx context.Context, accountID string) (core.ActiveReservation, error) - GetOnDemandPaymentByAccount(ctx context.Context, accountID string) (core.OnDemandPayment, error) + GetActiveReservationByAccount(ctx context.Context, accountID gethcommon.Address) (*core.ActiveReservation, error) + GetOnDemandPaymentByAccount(ctx context.Context, accountID gethcommon.Address) (*core.OnDemandPayment, error) GetOnDemandQuorumNumbers(ctx context.Context) ([]uint8, error) GetGlobalSymbolsPerSecond() uint64 GetGlobalRateBinInterval() uint64 @@ -29,13 +30,13 @@ var _ OnchainPayment = (*OnchainPaymentState)(nil) type OnchainPaymentState struct { tx *eth.Reader - ActiveReservations map[string]core.ActiveReservation - OnDemandPayments map[string]core.OnDemandPayment + ActiveReservations *map[gethcommon.Address]core.ActiveReservation + OnDemandPayments *map[gethcommon.Address]core.OnDemandPayment ReservationsLock sync.RWMutex OnDemandLocks sync.RWMutex - PaymentVaultParams PaymentVaultParams + PaymentVaultParams *PaymentVaultParams } type PaymentVaultParams struct { @@ -55,44 +56,44 @@ func NewOnchainPaymentState(ctx context.Context, tx *eth.Reader) (OnchainPayment return OnchainPaymentState{ tx: tx, - ActiveReservations: make(map[string]core.ActiveReservation), - OnDemandPayments: make(map[string]core.OnDemandPayment), + ActiveReservations: &map[gethcommon.Address]core.ActiveReservation{}, + OnDemandPayments: &map[gethcommon.Address]core.OnDemandPayment{}, PaymentVaultParams: paymentVaultParams, }, nil } -func GetPaymentVaultParams(ctx context.Context, tx *eth.Reader) (PaymentVaultParams, error) { +func GetPaymentVaultParams(ctx context.Context, tx *eth.Reader) (*PaymentVaultParams, error) { blockNumber, err := tx.GetCurrentBlockNumber(ctx) if err != nil { - return PaymentVaultParams{}, err + return nil, err } quorumNumbers, err := tx.GetRequiredQuorumNumbers(ctx, blockNumber) if err != nil { - return PaymentVaultParams{}, err + return nil, err } globalSymbolsPerSecond, err := tx.GetGlobalSymbolsPerSecond(ctx) if err != nil { - return PaymentVaultParams{}, err + return nil, err } minNumSymbols, err := tx.GetMinNumSymbols(ctx) if err != nil { - return PaymentVaultParams{}, err + return nil, err } pricePerSymbol, err := tx.GetPricePerSymbol(ctx) if err != nil { - return PaymentVaultParams{}, err + return nil, err } reservationWindow, err := tx.GetReservationWindow(ctx) if err != nil { - return PaymentVaultParams{}, err + return nil, err } - return PaymentVaultParams{ + return &PaymentVaultParams{ OnDemandQuorumNumbers: quorumNumbers, GlobalSymbolsPerSecond: globalSymbolsPerSecond, MinNumSymbols: minNumSymbols, @@ -111,8 +112,8 @@ func (pcs *OnchainPaymentState) RefreshOnchainPaymentState(ctx context.Context, pcs.PaymentVaultParams = paymentVaultParams pcs.ReservationsLock.Lock() - accountIDs := make([]string, 0, len(pcs.ActiveReservations)) - for accountID := range pcs.ActiveReservations { + accountIDs := make([]gethcommon.Address, 0, len(*pcs.ActiveReservations)) + for accountID := range *pcs.ActiveReservations { accountIDs = append(accountIDs, accountID) } @@ -124,8 +125,8 @@ func (pcs *OnchainPaymentState) RefreshOnchainPaymentState(ctx context.Context, pcs.ReservationsLock.Unlock() pcs.OnDemandLocks.Lock() - accountIDs = make([]string, 0, len(pcs.OnDemandPayments)) - for accountID := range pcs.OnDemandPayments { + accountIDs = make([]gethcommon.Address, 0, len(*pcs.OnDemandPayments)) + for accountID := range *pcs.OnDemandPayments { accountIDs = append(accountIDs, accountID) } @@ -140,52 +141,52 @@ func (pcs *OnchainPaymentState) RefreshOnchainPaymentState(ctx context.Context, } // GetActiveReservationByAccount returns a pointer to the active reservation for the given account ID; no writes will be made to the reservation -func (pcs *OnchainPaymentState) GetActiveReservationByAccount(ctx context.Context, accountID string) (core.ActiveReservation, error) { - if reservation, ok := pcs.ActiveReservations[accountID]; ok { - return reservation, nil +func (pcs *OnchainPaymentState) GetActiveReservationByAccount(ctx context.Context, accountID gethcommon.Address) (*core.ActiveReservation, error) { + if reservation, ok := (*pcs.ActiveReservations)[accountID]; ok { + return &reservation, nil } + // pulls the chain state res, err := pcs.tx.GetActiveReservationByAccount(ctx, accountID) if err != nil { - return core.ActiveReservation{}, err + return nil, err } - pcs.ReservationsLock.Lock() - pcs.ActiveReservations[accountID] = res + (*pcs.ActiveReservations)[accountID] = *res pcs.ReservationsLock.Unlock() return res, nil } // GetActiveReservationByAccountOnChain returns on-chain reservation for the given account ID -func (pcs *OnchainPaymentState) GetActiveReservationByAccountOnChain(ctx context.Context, accountID string) (core.ActiveReservation, error) { +func (pcs *OnchainPaymentState) GetActiveReservationByAccountOnChain(ctx context.Context, accountID gethcommon.Address) (*core.ActiveReservation, error) { res, err := pcs.tx.GetActiveReservationByAccount(ctx, accountID) if err != nil { - return core.ActiveReservation{}, fmt.Errorf("reservation account not found on-chain: %w", err) + return nil, fmt.Errorf("reservation account not found on-chain: %w", err) } return res, nil } // GetOnDemandPaymentByAccount returns a pointer to the on-demand payment for the given account ID; no writes will be made to the payment -func (pcs *OnchainPaymentState) GetOnDemandPaymentByAccount(ctx context.Context, accountID string) (core.OnDemandPayment, error) { - if payment, ok := pcs.OnDemandPayments[accountID]; ok { - return payment, nil +func (pcs *OnchainPaymentState) GetOnDemandPaymentByAccount(ctx context.Context, accountID gethcommon.Address) (*core.OnDemandPayment, error) { + if payment, ok := (*pcs.OnDemandPayments)[accountID]; ok { + return &payment, nil } // pulls the chain state res, err := pcs.tx.GetOnDemandPaymentByAccount(ctx, accountID) if err != nil { - return core.OnDemandPayment{}, err + return nil, err } pcs.OnDemandLocks.Lock() - pcs.OnDemandPayments[accountID] = res + (*pcs.OnDemandPayments)[accountID] = *res pcs.OnDemandLocks.Unlock() return res, nil } -func (pcs *OnchainPaymentState) GetOnDemandPaymentByAccountOnChain(ctx context.Context, accountID string) (core.OnDemandPayment, error) { +func (pcs *OnchainPaymentState) GetOnDemandPaymentByAccountOnChain(ctx context.Context, accountID gethcommon.Address) (*core.OnDemandPayment, error) { res, err := pcs.tx.GetOnDemandPaymentByAccount(ctx, accountID) if err != nil { - return core.OnDemandPayment{}, fmt.Errorf("on-demand not found on-chain: %w", err) + return nil, fmt.Errorf("on-demand not found on-chain: %w", err) } return res, nil } diff --git a/core/meterer/onchain_state_test.go b/core/meterer/onchain_state_test.go index ae14dc55eb..c9a2b4c6f0 100644 --- a/core/meterer/onchain_state_test.go +++ b/core/meterer/onchain_state_test.go @@ -8,6 +8,7 @@ import ( "github.com/Layr-Labs/eigenda/core" "github.com/Layr-Labs/eigenda/core/eth" "github.com/Layr-Labs/eigenda/core/mock" + gethcommon "github.com/ethereum/go-ethereum/common" "github.com/stretchr/testify/assert" testifymock "github.com/stretchr/testify/mock" ) @@ -47,7 +48,7 @@ func TestGetActiveReservationByAccount(t *testing.T) { ctx := context.Background() mockState.On("GetActiveReservationByAccount", testifymock.Anything, testifymock.Anything).Return(dummyActiveReservation, nil) - reservation, err := mockState.GetActiveReservationByAccount(ctx, "account1") + reservation, err := mockState.GetActiveReservationByAccount(ctx, gethcommon.Address{}) assert.NoError(t, err) assert.Equal(t, dummyActiveReservation, reservation) } @@ -55,10 +56,9 @@ func TestGetActiveReservationByAccount(t *testing.T) { func TestGetOnDemandPaymentByAccount(t *testing.T) { mockState := &mock.MockOnchainPaymentState{} ctx := context.Background() - accountID := "account1" mockState.On("GetOnDemandPaymentByAccount", testifymock.Anything, testifymock.Anything, testifymock.Anything).Return(dummyOnDemandPayment, nil) - payment, err := mockState.GetOnDemandPaymentByAccount(ctx, accountID) + payment, err := mockState.GetOnDemandPaymentByAccount(ctx, gethcommon.Address{}) assert.NoError(t, err) assert.Equal(t, dummyOnDemandPayment, payment) } diff --git a/core/mock/payment_state.go b/core/mock/payment_state.go index 80725189a1..e4c89784d3 100644 --- a/core/mock/payment_state.go +++ b/core/mock/payment_state.go @@ -6,6 +6,7 @@ import ( "github.com/Layr-Labs/eigenda/core" "github.com/Layr-Labs/eigenda/core/eth" "github.com/Layr-Labs/eigenda/core/meterer" + gethcommon "github.com/ethereum/go-ethereum/common" "github.com/stretchr/testify/mock" ) @@ -29,20 +30,20 @@ func (m *MockOnchainPaymentState) RefreshOnchainPaymentState(ctx context.Context return args.Error(0) } -func (m *MockOnchainPaymentState) GetActiveReservationByAccount(ctx context.Context, accountID string) (core.ActiveReservation, error) { +func (m *MockOnchainPaymentState) GetActiveReservationByAccount(ctx context.Context, accountID gethcommon.Address) (*core.ActiveReservation, error) { args := m.Called(ctx, accountID) - var value core.ActiveReservation + var value *core.ActiveReservation if args.Get(0) != nil { - value = args.Get(0).(core.ActiveReservation) + value = args.Get(0).(*core.ActiveReservation) } return value, args.Error(1) } -func (m *MockOnchainPaymentState) GetOnDemandPaymentByAccount(ctx context.Context, accountID string) (core.OnDemandPayment, error) { +func (m *MockOnchainPaymentState) GetOnDemandPaymentByAccount(ctx context.Context, accountID gethcommon.Address) (*core.OnDemandPayment, error) { args := m.Called(ctx, accountID) - var value core.OnDemandPayment + var value *core.OnDemandPayment if args.Get(0) != nil { - value = args.Get(0).(core.OnDemandPayment) + value = args.Get(0).(*core.OnDemandPayment) } return value, args.Error(1) } diff --git a/core/mock/writer.go b/core/mock/writer.go index d8dd4f406e..b667c5197a 100644 --- a/core/mock/writer.go +++ b/core/mock/writer.go @@ -221,28 +221,28 @@ func (t *MockWriter) PubkeyHashToOperator(ctx context.Context, operatorId core.O return result.(gethcommon.Address), args.Error(1) } -func (t *MockWriter) GetActiveReservations(ctx context.Context, accountIDs []string) (map[string]core.ActiveReservation, error) { +func (t *MockWriter) GetActiveReservations(ctx context.Context, accountIDs []gethcommon.Address) (*map[gethcommon.Address]core.ActiveReservation, error) { args := t.Called() result := args.Get(0) - return result.(map[string]core.ActiveReservation), args.Error(1) + return result.(*map[gethcommon.Address]core.ActiveReservation), args.Error(1) } -func (t *MockWriter) GetActiveReservationByAccount(ctx context.Context, accountID string) (core.ActiveReservation, error) { +func (t *MockWriter) GetActiveReservationByAccount(ctx context.Context, accountID gethcommon.Address) (*core.ActiveReservation, error) { args := t.Called() result := args.Get(0) - return result.(core.ActiveReservation), args.Error(1) + return result.(*core.ActiveReservation), args.Error(1) } -func (t *MockWriter) GetOnDemandPayments(ctx context.Context, accountIDs []string) (map[string]core.OnDemandPayment, error) { +func (t *MockWriter) GetOnDemandPayments(ctx context.Context, accountIDs []gethcommon.Address) (*map[gethcommon.Address]core.OnDemandPayment, error) { args := t.Called() result := args.Get(0) - return result.(map[string]core.OnDemandPayment), args.Error(1) + return result.(*map[gethcommon.Address]core.OnDemandPayment), args.Error(1) } -func (t *MockWriter) GetOnDemandPaymentByAccount(ctx context.Context, accountID string) (core.OnDemandPayment, error) { +func (t *MockWriter) GetOnDemandPaymentByAccount(ctx context.Context, accountID gethcommon.Address) (*core.OnDemandPayment, error) { args := t.Called() result := args.Get(0) - return result.(core.OnDemandPayment), args.Error(1) + return result.(*core.OnDemandPayment), args.Error(1) } func (t *MockWriter) GetOperatorSocket(ctx context.Context, operatorID core.OperatorID) (string, error) { From 7fd1c610f67e42678d28ab85a36416342c06d9d5 Mon Sep 17 00:00:00 2001 From: hopeyen Date: Thu, 5 Dec 2024 09:04:26 -0800 Subject: [PATCH 06/18] fix: atomic and map pointers --- core/chainio.go | 4 ++-- core/eth/reader.go | 20 ++++++++++---------- core/meterer/onchain_state.go | 32 +++++++++++++++++--------------- core/mock/writer.go | 8 ++++---- 4 files changed, 33 insertions(+), 31 deletions(-) diff --git a/core/chainio.go b/core/chainio.go index f75a753c30..f9bf660819 100644 --- a/core/chainio.go +++ b/core/chainio.go @@ -110,13 +110,13 @@ type Reader interface { GetAllVersionedBlobParams(ctx context.Context) (map[uint8]*BlobVersionParameters, error) // GetActiveReservations returns active reservations (end timestamp > current timestamp) - GetActiveReservations(ctx context.Context, accountIDs []gethcommon.Address) (*map[gethcommon.Address]ActiveReservation, error) + GetActiveReservations(ctx context.Context, accountIDs []gethcommon.Address) (map[gethcommon.Address]*ActiveReservation, error) // GetActiveReservationByAccount returns active reservation by account ID GetActiveReservationByAccount(ctx context.Context, accountID gethcommon.Address) (*ActiveReservation, error) // GetOnDemandPayments returns all on-demand payments - GetOnDemandPayments(ctx context.Context, accountIDs []gethcommon.Address) (*map[gethcommon.Address]OnDemandPayment, error) + GetOnDemandPayments(ctx context.Context, accountIDs []gethcommon.Address) (map[gethcommon.Address]*OnDemandPayment, error) // GetOnDemandPaymentByAccount returns on-demand payment of an account GetOnDemandPaymentByAccount(ctx context.Context, accountID gethcommon.Address) (*OnDemandPayment, error) diff --git a/core/eth/reader.go b/core/eth/reader.go index 7db421d102..6712137f75 100644 --- a/core/eth/reader.go +++ b/core/eth/reader.go @@ -657,8 +657,8 @@ func (t *Reader) GetAllVersionedBlobParams(ctx context.Context) (map[uint8]*core return res, nil } -func (t *Reader) GetActiveReservations(ctx context.Context, accountIDs []gethcommon.Address) (*map[gethcommon.Address]core.ActiveReservation, error) { - reservationsMap := make(map[gethcommon.Address]core.ActiveReservation) +func (t *Reader) GetActiveReservations(ctx context.Context, accountIDs []gethcommon.Address) (map[gethcommon.Address]*core.ActiveReservation, error) { + reservationsMap := make(map[gethcommon.Address]*core.ActiveReservation) reservations, err := t.bindings.PaymentVault.GetReservations(&bind.CallOpts{ Context: ctx, }, accountIDs) @@ -668,17 +668,17 @@ func (t *Reader) GetActiveReservations(ctx context.Context, accountIDs []gethcom // since reservations are returned in the same order as the accountIDs, we can directly map them for i, reservation := range reservations { - reservationsMap[accountIDs[i]] = reservation + reservationsMap[accountIDs[i]] = &reservation } // filter out all zero-valued reservations for accountID, reservation := range reservationsMap { - if isZeroValuedReservation(reservation) { + if isZeroValuedReservation(*reservation) { delete(reservationsMap, accountID) } } - return &reservationsMap, nil + return reservationsMap, nil } func (t *Reader) GetActiveReservationByAccount(ctx context.Context, accountID gethcommon.Address) (*core.ActiveReservation, error) { @@ -689,13 +689,13 @@ func (t *Reader) GetActiveReservationByAccount(ctx context.Context, accountID ge return nil, err } if isZeroValuedReservation(reservation) { - return nil, errors.New("reservation is zero-valued") + return nil, errors.New("reservation does not exist for given account") } return &reservation, nil } -func (t *Reader) GetOnDemandPayments(ctx context.Context, accountIDs []gethcommon.Address) (*map[gethcommon.Address]core.OnDemandPayment, error) { - paymentsMap := make(map[gethcommon.Address]core.OnDemandPayment) +func (t *Reader) GetOnDemandPayments(ctx context.Context, accountIDs []gethcommon.Address) (map[gethcommon.Address]*core.OnDemandPayment, error) { + paymentsMap := make(map[gethcommon.Address]*core.OnDemandPayment) payments, err := t.bindings.PaymentVault.GetOnDemandAmounts(&bind.CallOpts{ Context: ctx, }, accountIDs) @@ -705,7 +705,7 @@ func (t *Reader) GetOnDemandPayments(ctx context.Context, accountIDs []gethcommo // since payments are returned in the same order as the accountIDs, we can directly map them for i, payment := range payments { - paymentsMap[accountIDs[i]] = core.OnDemandPayment{ + paymentsMap[accountIDs[i]] = &core.OnDemandPayment{ CumulativePayment: payment, } } @@ -717,7 +717,7 @@ func (t *Reader) GetOnDemandPayments(ctx context.Context, accountIDs []gethcommo } } - return &paymentsMap, nil + return paymentsMap, nil } func (t *Reader) GetOnDemandPaymentByAccount(ctx context.Context, accountID gethcommon.Address) (*core.OnDemandPayment, error) { diff --git a/core/meterer/onchain_state.go b/core/meterer/onchain_state.go index 610adcf76c..a01d1b1bae 100644 --- a/core/meterer/onchain_state.go +++ b/core/meterer/onchain_state.go @@ -4,6 +4,8 @@ import ( "context" "fmt" "sync" + "sync/atomic" + "unsafe" "github.com/Layr-Labs/eigenda/core" "github.com/Layr-Labs/eigenda/core/eth" @@ -30,8 +32,8 @@ var _ OnchainPayment = (*OnchainPaymentState)(nil) type OnchainPaymentState struct { tx *eth.Reader - ActiveReservations *map[gethcommon.Address]core.ActiveReservation - OnDemandPayments *map[gethcommon.Address]core.OnDemandPayment + ActiveReservations map[gethcommon.Address]*core.ActiveReservation + OnDemandPayments map[gethcommon.Address]*core.OnDemandPayment ReservationsLock sync.RWMutex OnDemandLocks sync.RWMutex @@ -56,8 +58,8 @@ func NewOnchainPaymentState(ctx context.Context, tx *eth.Reader) (OnchainPayment return OnchainPaymentState{ tx: tx, - ActiveReservations: &map[gethcommon.Address]core.ActiveReservation{}, - OnDemandPayments: &map[gethcommon.Address]core.OnDemandPayment{}, + ActiveReservations: make(map[gethcommon.Address]*core.ActiveReservation), + OnDemandPayments: make(map[gethcommon.Address]*core.OnDemandPayment), PaymentVaultParams: paymentVaultParams, }, nil } @@ -109,11 +111,11 @@ func (pcs *OnchainPaymentState) RefreshOnchainPaymentState(ctx context.Context, return err } // These parameters should be rarely updated, but we refresh them anyway - pcs.PaymentVaultParams = paymentVaultParams + atomic.StorePointer((*unsafe.Pointer)(unsafe.Pointer(&pcs.PaymentVaultParams)), unsafe.Pointer(paymentVaultParams)) pcs.ReservationsLock.Lock() - accountIDs := make([]gethcommon.Address, 0, len(*pcs.ActiveReservations)) - for accountID := range *pcs.ActiveReservations { + accountIDs := make([]gethcommon.Address, 0, len(pcs.ActiveReservations)) + for accountID := range pcs.ActiveReservations { accountIDs = append(accountIDs, accountID) } @@ -125,8 +127,8 @@ func (pcs *OnchainPaymentState) RefreshOnchainPaymentState(ctx context.Context, pcs.ReservationsLock.Unlock() pcs.OnDemandLocks.Lock() - accountIDs = make([]gethcommon.Address, 0, len(*pcs.OnDemandPayments)) - for accountID := range *pcs.OnDemandPayments { + accountIDs = make([]gethcommon.Address, 0, len(pcs.OnDemandPayments)) + for accountID := range pcs.OnDemandPayments { accountIDs = append(accountIDs, accountID) } @@ -142,8 +144,8 @@ func (pcs *OnchainPaymentState) RefreshOnchainPaymentState(ctx context.Context, // GetActiveReservationByAccount returns a pointer to the active reservation for the given account ID; no writes will be made to the reservation func (pcs *OnchainPaymentState) GetActiveReservationByAccount(ctx context.Context, accountID gethcommon.Address) (*core.ActiveReservation, error) { - if reservation, ok := (*pcs.ActiveReservations)[accountID]; ok { - return &reservation, nil + if reservation, ok := (pcs.ActiveReservations)[accountID]; ok { + return reservation, nil } // pulls the chain state @@ -152,7 +154,7 @@ func (pcs *OnchainPaymentState) GetActiveReservationByAccount(ctx context.Contex return nil, err } pcs.ReservationsLock.Lock() - (*pcs.ActiveReservations)[accountID] = *res + (pcs.ActiveReservations)[accountID] = res pcs.ReservationsLock.Unlock() return res, nil } @@ -168,8 +170,8 @@ func (pcs *OnchainPaymentState) GetActiveReservationByAccountOnChain(ctx context // GetOnDemandPaymentByAccount returns a pointer to the on-demand payment for the given account ID; no writes will be made to the payment func (pcs *OnchainPaymentState) GetOnDemandPaymentByAccount(ctx context.Context, accountID gethcommon.Address) (*core.OnDemandPayment, error) { - if payment, ok := (*pcs.OnDemandPayments)[accountID]; ok { - return &payment, nil + if payment, ok := (pcs.OnDemandPayments)[accountID]; ok { + return payment, nil } // pulls the chain state res, err := pcs.tx.GetOnDemandPaymentByAccount(ctx, accountID) @@ -178,7 +180,7 @@ func (pcs *OnchainPaymentState) GetOnDemandPaymentByAccount(ctx context.Context, } pcs.OnDemandLocks.Lock() - (*pcs.OnDemandPayments)[accountID] = *res + (pcs.OnDemandPayments)[accountID] = res pcs.OnDemandLocks.Unlock() return res, nil } diff --git a/core/mock/writer.go b/core/mock/writer.go index b667c5197a..0f1dcee9ed 100644 --- a/core/mock/writer.go +++ b/core/mock/writer.go @@ -221,10 +221,10 @@ func (t *MockWriter) PubkeyHashToOperator(ctx context.Context, operatorId core.O return result.(gethcommon.Address), args.Error(1) } -func (t *MockWriter) GetActiveReservations(ctx context.Context, accountIDs []gethcommon.Address) (*map[gethcommon.Address]core.ActiveReservation, error) { +func (t *MockWriter) GetActiveReservations(ctx context.Context, accountIDs []gethcommon.Address) (map[gethcommon.Address]*core.ActiveReservation, error) { args := t.Called() result := args.Get(0) - return result.(*map[gethcommon.Address]core.ActiveReservation), args.Error(1) + return result.(map[gethcommon.Address]*core.ActiveReservation), args.Error(1) } func (t *MockWriter) GetActiveReservationByAccount(ctx context.Context, accountID gethcommon.Address) (*core.ActiveReservation, error) { @@ -233,10 +233,10 @@ func (t *MockWriter) GetActiveReservationByAccount(ctx context.Context, accountI return result.(*core.ActiveReservation), args.Error(1) } -func (t *MockWriter) GetOnDemandPayments(ctx context.Context, accountIDs []gethcommon.Address) (*map[gethcommon.Address]core.OnDemandPayment, error) { +func (t *MockWriter) GetOnDemandPayments(ctx context.Context, accountIDs []gethcommon.Address) (map[gethcommon.Address]*core.OnDemandPayment, error) { args := t.Called() result := args.Get(0) - return result.(*map[gethcommon.Address]core.OnDemandPayment), args.Error(1) + return result.(map[gethcommon.Address]*core.OnDemandPayment), args.Error(1) } func (t *MockWriter) GetOnDemandPaymentByAccount(ctx context.Context, accountID gethcommon.Address) (*core.OnDemandPayment, error) { From 28bed7762a4bacda76ec6b910aa63a7d8e4e994d Mon Sep 17 00:00:00 2001 From: hopeyen Date: Thu, 5 Dec 2024 09:40:27 -0800 Subject: [PATCH 07/18] fix: lint --- disperser/apiserver/server_v2.go | 8 +++++--- disperser/apiserver/server_v2_test.go | 2 +- 2 files changed, 6 insertions(+), 4 deletions(-) diff --git a/disperser/apiserver/server_v2.go b/disperser/apiserver/server_v2.go index e8dece0b36..435b99d318 100644 --- a/disperser/apiserver/server_v2.go +++ b/disperser/apiserver/server_v2.go @@ -22,6 +22,7 @@ import ( "github.com/Layr-Labs/eigenda/disperser/common/v2/blobstore" "github.com/Layr-Labs/eigenda/encoding" "github.com/Layr-Labs/eigensdk-go/logging" + gethcommon "github.com/ethereum/go-ethereum/common" "google.golang.org/grpc" "google.golang.org/grpc/reflection" ) @@ -222,6 +223,7 @@ func (s *DispersalServerV2) RefreshOnchainState(ctx context.Context) error { } func (s *DispersalServerV2) GetPaymentState(ctx context.Context, req *pb.GetPaymentStateRequest) (*pb.GetPaymentStateReply, error) { + accountID := gethcommon.HexToAddress(req.AccountId) // validate the signature if err := s.authenticator.AuthenticatePaymentStateRequest(req.GetSignature(), req.GetAccountId()); err != nil { return nil, api.NewErrorInvalidArg(fmt.Sprintf("authentication failed: %s", err.Error())) @@ -244,11 +246,11 @@ func (s *DispersalServerV2) GetPaymentState(ctx context.Context, req *pb.GetPaym return nil, api.NewErrorNotFound("failed to get largest cumulative payment") } // on-Chain account state - reservation, err := s.meterer.ChainPaymentState.GetActiveReservationByAccount(ctx, req.AccountId) + reservation, err := s.meterer.ChainPaymentState.GetActiveReservationByAccount(ctx, accountID) if err != nil { return nil, api.NewErrorNotFound("failed to get active reservation") } - onDemandPayment, err := s.meterer.ChainPaymentState.GetOnDemandPaymentByAccount(ctx, req.AccountId) + onDemandPayment, err := s.meterer.ChainPaymentState.GetOnDemandPaymentByAccount(ctx, accountID) if err != nil { return nil, api.NewErrorNotFound("failed to get on-demand payment") } @@ -273,7 +275,7 @@ func (s *DispersalServerV2) GetPaymentState(ctx context.Context, req *pb.GetPaym PaymentGlobalParams: &paymentGlobalParams, BinRecords: binRecords[:], Reservation: &pb.Reservation{ - SymbolsPerSecond: reservation.SymbolsPerSec, + SymbolsPerSecond: reservation.SymbolsPerSecond, StartTimestamp: uint32(reservation.StartTimestamp), EndTimestamp: uint32(reservation.EndTimestamp), QuorumNumbers: quorumNumbers, diff --git a/disperser/apiserver/server_v2_test.go b/disperser/apiserver/server_v2_test.go index 17f84f510f..3d463ae38b 100644 --- a/disperser/apiserver/server_v2_test.go +++ b/disperser/apiserver/server_v2_test.go @@ -441,7 +441,7 @@ func newTestServerV2(t *testing.T) *testComponents { mockState.On("GetMinNumSymbols", tmock.Anything).Return(uint32(3), nil) now := uint64(time.Now().Unix()) - mockState.On("GetActiveReservationByAccount", tmock.Anything, tmock.Anything).Return(core.ActiveReservation{SymbolsPerSec: 100, StartTimestamp: now + 1200, EndTimestamp: now + 1800, QuorumSplit: []byte{50, 50}, QuorumNumbers: []uint8{0, 1}}, nil) + mockState.On("GetActiveReservationByAccount", tmock.Anything, tmock.Anything).Return(core.ActiveReservation{SymbolsPerSecond: 100, StartTimestamp: now + 1200, EndTimestamp: now + 1800, QuorumSplits: []byte{50, 50}, QuorumNumbers: []uint8{0, 1}}, nil) mockState.On("GetOnDemandPaymentByAccount", tmock.Anything, tmock.Anything).Return(core.OnDemandPayment{CumulativePayment: big.NewInt(3864)}, nil) mockState.On("GetOnDemandQuorumNumbers", tmock.Anything).Return([]uint8{0, 1}, nil) From 572ef6796ad40441e6cad1912ce24ef93489c330 Mon Sep 17 00:00:00 2001 From: hopeyen Date: Thu, 5 Dec 2024 09:53:40 -0800 Subject: [PATCH 08/18] fix: tests --- core/meterer/meterer_test.go | 59 ++++++++++++++------------- core/meterer/onchain_state_test.go | 4 +- disperser/apiserver/server_test.go | 4 +- disperser/apiserver/server_v2_test.go | 4 +- test/integration_test.go | 14 +++---- 5 files changed, 43 insertions(+), 42 deletions(-) diff --git a/core/meterer/meterer_test.go b/core/meterer/meterer_test.go index fe32051fce..dfc4b5f6b5 100644 --- a/core/meterer/meterer_test.go +++ b/core/meterer/meterer_test.go @@ -17,6 +17,7 @@ import ( "github.com/Layr-Labs/eigenda/core/mock" "github.com/Layr-Labs/eigenda/inabox/deploy" "github.com/aws/aws-sdk-go-v2/service/dynamodb/types" + gethcommon "github.com/ethereum/go-ethereum/common" "github.com/ethereum/go-ethereum/crypto" "github.com/ory/dockertest/v3" "github.com/stretchr/testify/assert" @@ -30,12 +31,12 @@ var ( dockertestResource *dockertest.Resource dynamoClient commondynamodb.Client clientConfig commonaws.ClientConfig - accountID1 string - account1Reservations core.ActiveReservation - account1OnDemandPayments core.OnDemandPayment - accountID2 string - account2Reservations core.ActiveReservation - account2OnDemandPayments core.OnDemandPayment + accountID1 gethcommon.Address + account1Reservations *core.ActiveReservation + account1OnDemandPayments *core.OnDemandPayment + accountID2 gethcommon.Address + account2Reservations *core.ActiveReservation + account2OnDemandPayments *core.OnDemandPayment mt *meterer.Meterer deployLocalStack bool @@ -123,12 +124,12 @@ func setup(_ *testing.M) { } now := uint64(time.Now().Unix()) - accountID1 = crypto.PubkeyToAddress(privateKey1.PublicKey).Hex() - accountID2 = crypto.PubkeyToAddress(privateKey2.PublicKey).Hex() - account1Reservations = core.ActiveReservation{SymbolsPerSecond: 100, StartTimestamp: now + 1200, EndTimestamp: now + 1800, QuorumSplits: []byte{50, 50}, QuorumNumbers: []uint8{0, 1}} - account2Reservations = core.ActiveReservation{SymbolsPerSecond: 200, StartTimestamp: now - 120, EndTimestamp: now + 180, QuorumSplits: []byte{30, 70}, QuorumNumbers: []uint8{0, 1}} - account1OnDemandPayments = core.OnDemandPayment{CumulativePayment: big.NewInt(3864)} - account2OnDemandPayments = core.OnDemandPayment{CumulativePayment: big.NewInt(2000)} + accountID1 = crypto.PubkeyToAddress(privateKey1.PublicKey) + accountID2 = crypto.PubkeyToAddress(privateKey2.PublicKey) + account1Reservations = &core.ActiveReservation{SymbolsPerSecond: 100, StartTimestamp: now + 1200, EndTimestamp: now + 1800, QuorumSplits: []byte{50, 50}, QuorumNumbers: []uint8{0, 1}} + account2Reservations = &core.ActiveReservation{SymbolsPerSecond: 200, StartTimestamp: now - 120, EndTimestamp: now + 180, QuorumSplits: []byte{30, 70}, QuorumNumbers: []uint8{0, 1}} + account1OnDemandPayments = &core.OnDemandPayment{CumulativePayment: big.NewInt(3864)} + account2OnDemandPayments = &core.OnDemandPayment{CumulativePayment: big.NewInt(2000)} store, err := meterer.NewOffchainStore( clientConfig, @@ -176,13 +177,13 @@ func TestMetererReservations(t *testing.T) { binIndex := meterer.GetBinIndex(uint64(time.Now().Unix()), mt.ChainPaymentState.GetReservationWindow()) quoromNumbers := []uint8{0, 1} - paymentChainState.On("GetActiveReservationByAccount", testifymock.Anything, testifymock.MatchedBy(func(account string) bool { + paymentChainState.On("GetActiveReservationByAccount", testifymock.Anything, testifymock.MatchedBy(func(account gethcommon.Address) bool { return account == accountID1 })).Return(account1Reservations, nil) - paymentChainState.On("GetActiveReservationByAccount", testifymock.Anything, testifymock.MatchedBy(func(account string) bool { + paymentChainState.On("GetActiveReservationByAccount", testifymock.Anything, testifymock.MatchedBy(func(account gethcommon.Address) bool { return account == accountID2 })).Return(account2Reservations, nil) - paymentChainState.On("GetActiveReservationByAccount", testifymock.Anything, testifymock.Anything).Return(core.ActiveReservation{}, fmt.Errorf("reservation not found")) + paymentChainState.On("GetActiveReservationByAccount", testifymock.Anything, testifymock.Anything).Return(&core.ActiveReservation{}, fmt.Errorf("reservation not found")) // test invalid quorom ID header := createPaymentHeader(1, 0, accountID1) @@ -203,7 +204,7 @@ func TestMetererReservations(t *testing.T) { if err != nil { t.Fatalf("Failed to generate key: %v", err) } - header = createPaymentHeader(1, 0, crypto.PubkeyToAddress(unregisteredUser.PublicKey).Hex()) + header = createPaymentHeader(1, 0, crypto.PubkeyToAddress(unregisteredUser.PublicKey)) assert.NoError(t, err) err = mt.MeterRequest(ctx, *header, 1000, []uint8{0, 1, 2}) assert.ErrorContains(t, err, "failed to get active reservation by account: reservation not found") @@ -221,11 +222,11 @@ func TestMetererReservations(t *testing.T) { err = mt.MeterRequest(ctx, *header, symbolLength, quoromNumbers) assert.NoError(t, err) item, err := dynamoClient.GetItem(ctx, reservationTableName, commondynamodb.Key{ - "AccountID": &types.AttributeValueMemberS{Value: accountID2}, + "AccountID": &types.AttributeValueMemberS{Value: accountID2.Hex()}, "BinIndex": &types.AttributeValueMemberN{Value: strconv.Itoa(int(binIndex))}, }) assert.NoError(t, err) - assert.Equal(t, accountID2, item["AccountID"].(*types.AttributeValueMemberS).Value) + assert.Equal(t, accountID2.Hex(), item["AccountID"].(*types.AttributeValueMemberS).Value) assert.Equal(t, strconv.Itoa(int(binIndex)), item["BinIndex"].(*types.AttributeValueMemberN).Value) assert.Equal(t, strconv.Itoa((i+1)*int(requiredLength)), item["BinUsage"].(*types.AttributeValueMemberN).Value) @@ -237,11 +238,11 @@ func TestMetererReservations(t *testing.T) { assert.NoError(t, err) overflowedBinIndex := binIndex + 2 item, err := dynamoClient.GetItem(ctx, reservationTableName, commondynamodb.Key{ - "AccountID": &types.AttributeValueMemberS{Value: accountID2}, + "AccountID": &types.AttributeValueMemberS{Value: accountID2.Hex()}, "BinIndex": &types.AttributeValueMemberN{Value: strconv.Itoa(int(overflowedBinIndex))}, }) assert.NoError(t, err) - assert.Equal(t, accountID2, item["AccountID"].(*types.AttributeValueMemberS).Value) + assert.Equal(t, accountID2.Hex(), item["AccountID"].(*types.AttributeValueMemberS).Value) assert.Equal(t, strconv.Itoa(int(overflowedBinIndex)), item["BinIndex"].(*types.AttributeValueMemberN).Value) // 25 rounded up to the nearest multiple of minNumSymbols - (200-21*9) = 16 assert.Equal(t, strconv.Itoa(int(16)), item["BinUsage"].(*types.AttributeValueMemberN).Value) @@ -260,13 +261,13 @@ func TestMetererOnDemand(t *testing.T) { paymentChainState.On("GetMinNumSymbols", testifymock.Anything).Return(uint32(3), nil) binIndex := uint32(0) // this field doesn't matter for on-demand payments wrt global rate limit - paymentChainState.On("GetOnDemandPaymentByAccount", testifymock.Anything, testifymock.MatchedBy(func(account string) bool { + paymentChainState.On("GetOnDemandPaymentByAccount", testifymock.Anything, testifymock.MatchedBy(func(account gethcommon.Address) bool { return account == accountID1 })).Return(account1OnDemandPayments, nil) - paymentChainState.On("GetOnDemandPaymentByAccount", testifymock.Anything, testifymock.MatchedBy(func(account string) bool { + paymentChainState.On("GetOnDemandPaymentByAccount", testifymock.Anything, testifymock.MatchedBy(func(account gethcommon.Address) bool { return account == accountID2 })).Return(account2OnDemandPayments, nil) - paymentChainState.On("GetOnDemandPaymentByAccount", testifymock.Anything, testifymock.Anything).Return(core.OnDemandPayment{}, fmt.Errorf("payment not found")) + paymentChainState.On("GetOnDemandPaymentByAccount", testifymock.Anything, testifymock.Anything).Return(&core.OnDemandPayment{}, fmt.Errorf("payment not found")) paymentChainState.On("GetOnDemandQuorumNumbers", testifymock.Anything).Return(quorumNumbers, nil) // test unregistered account @@ -274,7 +275,7 @@ func TestMetererOnDemand(t *testing.T) { if err != nil { t.Fatalf("Failed to generate key: %v", err) } - header := createPaymentHeader(binIndex, 2, crypto.PubkeyToAddress(unregisteredUser.PublicKey).Hex()) + header := createPaymentHeader(binIndex, 2, crypto.PubkeyToAddress(unregisteredUser.PublicKey)) assert.NoError(t, err) err = mt.MeterRequest(ctx, *header, 1000, quorumNumbers) assert.ErrorContains(t, err, "failed to get on-demand payment by account: payment not found") @@ -291,7 +292,7 @@ func TestMetererOnDemand(t *testing.T) { // No rollback after meter request result, err := dynamoClient.Query(ctx, ondemandTableName, "AccountID = :account", commondynamodb.ExpressionValues{ ":account": &types.AttributeValueMemberS{ - Value: accountID1, + Value: accountID1.Hex(), }}) assert.NoError(t, err) assert.Equal(t, 1, len(result)) @@ -336,7 +337,7 @@ func TestMetererOnDemand(t *testing.T) { numPrevRecords := 12 result, err = dynamoClient.Query(ctx, ondemandTableName, "AccountID = :account", commondynamodb.ExpressionValues{ ":account": &types.AttributeValueMemberS{ - Value: accountID2, + Value: accountID2.Hex(), }}) assert.NoError(t, err) assert.Equal(t, numPrevRecords, len(result)) @@ -347,7 +348,7 @@ func TestMetererOnDemand(t *testing.T) { // Correct rollback result, err = dynamoClient.Query(ctx, ondemandTableName, "AccountID = :account", commondynamodb.ExpressionValues{ ":account": &types.AttributeValueMemberS{ - Value: accountID2, + Value: accountID2.Hex(), }}) assert.NoError(t, err) assert.Equal(t, numPrevRecords, len(result)) @@ -464,9 +465,9 @@ func TestMeterer_symbolsCharged(t *testing.T) { } } -func createPaymentHeader(binIndex uint32, cumulativePayment uint64, accountID string) *core.PaymentMetadata { +func createPaymentHeader(binIndex uint32, cumulativePayment uint64, accountID gethcommon.Address) *core.PaymentMetadata { return &core.PaymentMetadata{ - AccountID: accountID, + AccountID: accountID.Hex(), BinIndex: binIndex, CumulativePayment: big.NewInt(int64(cumulativePayment)), } diff --git a/core/meterer/onchain_state_test.go b/core/meterer/onchain_state_test.go index c9a2b4c6f0..d7fca84845 100644 --- a/core/meterer/onchain_state_test.go +++ b/core/meterer/onchain_state_test.go @@ -14,13 +14,13 @@ import ( ) var ( - dummyActiveReservation = core.ActiveReservation{ + dummyActiveReservation = &core.ActiveReservation{ SymbolsPerSecond: 100, StartTimestamp: 1000, EndTimestamp: 2000, QuorumSplits: []byte{50, 50}, } - dummyOnDemandPayment = core.OnDemandPayment{ + dummyOnDemandPayment = &core.OnDemandPayment{ CumulativePayment: big.NewInt(1000), } ) diff --git a/disperser/apiserver/server_test.go b/disperser/apiserver/server_test.go index b426455550..29f4f74a94 100644 --- a/disperser/apiserver/server_test.go +++ b/disperser/apiserver/server_test.go @@ -758,10 +758,10 @@ func newTestServer(transactor core.Writer, testName string) *apiserver.Dispersal mockState.On("GetRequiredQuorumNumbers").Return([]uint8{0, 1}, nil) mockState.On("GetOnDemandQuorumNumbers").Return([]uint8{0, 1}, nil) mockState.On("GetReservationWindow").Return(uint32(1), nil) - mockState.On("GetOnDemandPaymentByAccount", tmock.Anything, tmock.Anything).Return(core.OnDemandPayment{ + mockState.On("GetOnDemandPaymentByAccount", tmock.Anything, tmock.Anything).Return(&core.OnDemandPayment{ CumulativePayment: big.NewInt(3000), }, nil) - mockState.On("GetActiveReservationByAccount", tmock.Anything, tmock.Anything).Return(core.ActiveReservation{ + mockState.On("GetActiveReservationByAccount", tmock.Anything, tmock.Anything).Return(&core.ActiveReservation{ SymbolsPerSecond: 2048, StartTimestamp: 0, EndTimestamp: math.MaxUint32, diff --git a/disperser/apiserver/server_v2_test.go b/disperser/apiserver/server_v2_test.go index 3d463ae38b..d5f8262872 100644 --- a/disperser/apiserver/server_v2_test.go +++ b/disperser/apiserver/server_v2_test.go @@ -441,8 +441,8 @@ func newTestServerV2(t *testing.T) *testComponents { mockState.On("GetMinNumSymbols", tmock.Anything).Return(uint32(3), nil) now := uint64(time.Now().Unix()) - mockState.On("GetActiveReservationByAccount", tmock.Anything, tmock.Anything).Return(core.ActiveReservation{SymbolsPerSecond: 100, StartTimestamp: now + 1200, EndTimestamp: now + 1800, QuorumSplits: []byte{50, 50}, QuorumNumbers: []uint8{0, 1}}, nil) - mockState.On("GetOnDemandPaymentByAccount", tmock.Anything, tmock.Anything).Return(core.OnDemandPayment{CumulativePayment: big.NewInt(3864)}, nil) + mockState.On("GetActiveReservationByAccount", tmock.Anything, tmock.Anything).Return(&core.ActiveReservation{SymbolsPerSecond: 100, StartTimestamp: now + 1200, EndTimestamp: now + 1800, QuorumSplits: []byte{50, 50}, QuorumNumbers: []uint8{0, 1}}, nil) + mockState.On("GetOnDemandPaymentByAccount", tmock.Anything, tmock.Anything).Return(&core.OnDemandPayment{CumulativePayment: big.NewInt(3864)}, nil) mockState.On("GetOnDemandQuorumNumbers", tmock.Anything).Return([]uint8{0, 1}, nil) if err := mockState.RefreshOnchainPaymentState(context.Background(), nil); err != nil { diff --git a/test/integration_test.go b/test/integration_test.go index 4f36b5065d..5016f3598f 100644 --- a/test/integration_test.go +++ b/test/integration_test.go @@ -216,20 +216,20 @@ func mustMakeDisperser(t *testing.T, cst core.IndexedChainState, store disperser if err != nil { panic("failed to convert hex to ECDSA") } - publicKey := crypto.PubkeyToAddress(privateKey.PublicKey).Hex() + publicKey := crypto.PubkeyToAddress(privateKey.PublicKey) mockState := &coremock.MockOnchainPaymentState{} reservationLimit := uint64(1024) paymentLimit := big.NewInt(512) - mockState.On("GetActiveReservationByAccount", mock.Anything, mock.MatchedBy(func(account string) bool { + mockState.On("GetActiveReservationByAccount", mock.Anything, mock.MatchedBy(func(account gethcommon.Address) bool { return account == publicKey - })).Return(core.ActiveReservation{SymbolsPerSecond: reservationLimit, StartTimestamp: 0, EndTimestamp: math.MaxUint32, QuorumSplits: []byte{50, 50}, QuorumNumbers: []uint8{0, 1}}, nil) - mockState.On("GetActiveReservationByAccount", mock.Anything, mock.Anything).Return(core.ActiveReservation{}, errors.New("reservation not found")) + })).Return(&core.ActiveReservation{SymbolsPerSecond: reservationLimit, StartTimestamp: 0, EndTimestamp: math.MaxUint32, QuorumSplits: []byte{50, 50}, QuorumNumbers: []uint8{0, 1}}, nil) + mockState.On("GetActiveReservationByAccount", mock.Anything, mock.Anything).Return(&core.ActiveReservation{}, errors.New("reservation not found")) - mockState.On("GetOnDemandPaymentByAccount", mock.Anything, mock.MatchedBy(func(account string) bool { + mockState.On("GetOnDemandPaymentByAccount", mock.Anything, mock.MatchedBy(func(account gethcommon.Address) bool { return account == publicKey - })).Return(core.OnDemandPayment{CumulativePayment: paymentLimit}, nil) - mockState.On("GetOnDemandPaymentByAccount", mock.Anything, mock.Anything).Return(core.OnDemandPayment{}, errors.New("payment not found")) + })).Return(&core.OnDemandPayment{CumulativePayment: paymentLimit}, nil) + mockState.On("GetOnDemandPaymentByAccount", mock.Anything, mock.Anything).Return(&core.OnDemandPayment{}, errors.New("payment not found")) mockState.On("GetOnDemandQuorumNumbers", mock.Anything).Return([]uint8{0, 1}, nil) mockState.On("GetGlobalSymbolsPerSecond", mock.Anything).Return(uint64(1024), nil) mockState.On("GetPricePerSymbol", mock.Anything).Return(uint32(1), nil) From b0d8d51ff12caa24fd0456f60a3c2e61546f216b Mon Sep 17 00:00:00 2001 From: hopeyen Date: Fri, 6 Dec 2024 08:28:20 -0800 Subject: [PATCH 09/18] refactor: atomicPointer type --- core/eth/reader.go | 2 +- core/meterer/onchain_state.go | 28 +++++++++++++++------------- 2 files changed, 16 insertions(+), 14 deletions(-) diff --git a/core/eth/reader.go b/core/eth/reader.go index 6712137f75..80ebc6d4d9 100644 --- a/core/eth/reader.go +++ b/core/eth/reader.go @@ -728,7 +728,7 @@ func (t *Reader) GetOnDemandPaymentByAccount(ctx context.Context, accountID geth return nil, err } if onDemandPayment == big.NewInt(0) { - return nil, errors.New("on-demand payment is zero-valued") + return nil, errors.New("ondemand payment does not exist for given account") } return &core.OnDemandPayment{ CumulativePayment: onDemandPayment, diff --git a/core/meterer/onchain_state.go b/core/meterer/onchain_state.go index a01d1b1bae..45a8a24fc4 100644 --- a/core/meterer/onchain_state.go +++ b/core/meterer/onchain_state.go @@ -5,7 +5,6 @@ import ( "fmt" "sync" "sync/atomic" - "unsafe" "github.com/Layr-Labs/eigenda/core" "github.com/Layr-Labs/eigenda/core/eth" @@ -38,7 +37,7 @@ type OnchainPaymentState struct { ReservationsLock sync.RWMutex OnDemandLocks sync.RWMutex - PaymentVaultParams *PaymentVaultParams + PaymentVaultParams atomic.Pointer[PaymentVaultParams] } type PaymentVaultParams struct { @@ -50,18 +49,21 @@ type PaymentVaultParams struct { OnDemandQuorumNumbers []uint8 } -func NewOnchainPaymentState(ctx context.Context, tx *eth.Reader) (OnchainPaymentState, error) { +func NewOnchainPaymentState(ctx context.Context, tx *eth.Reader) (*OnchainPaymentState, error) { paymentVaultParams, err := GetPaymentVaultParams(ctx, tx) if err != nil { - return OnchainPaymentState{}, err + return nil, err } - return OnchainPaymentState{ + state := OnchainPaymentState{ tx: tx, ActiveReservations: make(map[gethcommon.Address]*core.ActiveReservation), OnDemandPayments: make(map[gethcommon.Address]*core.OnDemandPayment), - PaymentVaultParams: paymentVaultParams, - }, nil + PaymentVaultParams: atomic.Pointer[PaymentVaultParams]{}, + } + state.PaymentVaultParams.Store(paymentVaultParams) + + return &state, nil } func GetPaymentVaultParams(ctx context.Context, tx *eth.Reader) (*PaymentVaultParams, error) { @@ -111,7 +113,7 @@ func (pcs *OnchainPaymentState) RefreshOnchainPaymentState(ctx context.Context, return err } // These parameters should be rarely updated, but we refresh them anyway - atomic.StorePointer((*unsafe.Pointer)(unsafe.Pointer(&pcs.PaymentVaultParams)), unsafe.Pointer(paymentVaultParams)) + pcs.PaymentVaultParams.Store(paymentVaultParams) pcs.ReservationsLock.Lock() accountIDs := make([]gethcommon.Address, 0, len(pcs.ActiveReservations)) @@ -202,21 +204,21 @@ func (pcs *OnchainPaymentState) GetOnDemandQuorumNumbers(ctx context.Context) ([ } func (pcs *OnchainPaymentState) GetGlobalSymbolsPerSecond() uint64 { - return pcs.PaymentVaultParams.GlobalSymbolsPerSecond + return pcs.PaymentVaultParams.Load().GlobalSymbolsPerSecond } func (pcs *OnchainPaymentState) GetGlobalRateBinInterval() uint64 { - return pcs.PaymentVaultParams.GlobalRateBinInterval + return pcs.PaymentVaultParams.Load().GlobalRateBinInterval } func (pcs *OnchainPaymentState) GetMinNumSymbols() uint32 { - return pcs.PaymentVaultParams.MinNumSymbols + return pcs.PaymentVaultParams.Load().MinNumSymbols } func (pcs *OnchainPaymentState) GetPricePerSymbol() uint32 { - return pcs.PaymentVaultParams.PricePerSymbol + return pcs.PaymentVaultParams.Load().PricePerSymbol } func (pcs *OnchainPaymentState) GetReservationWindow() uint32 { - return pcs.PaymentVaultParams.ReservationWindow + return pcs.PaymentVaultParams.Load().ReservationWindow } From 49b6559e765a406226e7da52acb37a5dec6f2d46 Mon Sep 17 00:00:00 2001 From: hopeyen Date: Fri, 6 Dec 2024 08:31:11 -0800 Subject: [PATCH 10/18] fix: temporary nil checks for paymentVault contract --- core/eth/reader.go | 27 +++++++++++++++++++++++++++ 1 file changed, 27 insertions(+) diff --git a/core/eth/reader.go b/core/eth/reader.go index 80ebc6d4d9..1120c6d5ca 100644 --- a/core/eth/reader.go +++ b/core/eth/reader.go @@ -658,6 +658,9 @@ func (t *Reader) GetAllVersionedBlobParams(ctx context.Context) (map[uint8]*core } func (t *Reader) GetActiveReservations(ctx context.Context, accountIDs []gethcommon.Address) (map[gethcommon.Address]*core.ActiveReservation, error) { + if t.bindings.PaymentVault == nil { + return nil, errors.New("payment vault not deployed") + } reservationsMap := make(map[gethcommon.Address]*core.ActiveReservation) reservations, err := t.bindings.PaymentVault.GetReservations(&bind.CallOpts{ Context: ctx, @@ -682,6 +685,9 @@ func (t *Reader) GetActiveReservations(ctx context.Context, accountIDs []gethcom } func (t *Reader) GetActiveReservationByAccount(ctx context.Context, accountID gethcommon.Address) (*core.ActiveReservation, error) { + if t.bindings.PaymentVault == nil { + return nil, errors.New("payment vault not deployed") + } reservation, err := t.bindings.PaymentVault.GetReservation(&bind.CallOpts{ Context: ctx, }, accountID) @@ -695,6 +701,9 @@ func (t *Reader) GetActiveReservationByAccount(ctx context.Context, accountID ge } func (t *Reader) GetOnDemandPayments(ctx context.Context, accountIDs []gethcommon.Address) (map[gethcommon.Address]*core.OnDemandPayment, error) { + if t.bindings.PaymentVault == nil { + 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, @@ -721,6 +730,9 @@ func (t *Reader) GetOnDemandPayments(ctx context.Context, accountIDs []gethcommo } func (t *Reader) GetOnDemandPaymentByAccount(ctx context.Context, accountID gethcommon.Address) (*core.OnDemandPayment, error) { + if t.bindings.PaymentVault == nil { + return nil, errors.New("payment vault not deployed") + } onDemandPayment, err := t.bindings.PaymentVault.GetOnDemandAmount(&bind.CallOpts{ Context: ctx, }, accountID) @@ -736,6 +748,9 @@ func (t *Reader) GetOnDemandPaymentByAccount(ctx context.Context, accountID geth } 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{ Context: ctx, }) @@ -746,6 +761,9 @@ func (t *Reader) GetGlobalSymbolsPerSecond(ctx context.Context) (uint64, error) } func (t *Reader) GetGlobalRateBinInterval(ctx context.Context) (uint64, error) { + if t.bindings.PaymentVault == nil { + return 0, errors.New("payment vault not deployed") + } globalRateBinInterval, err := t.bindings.PaymentVault.GlobalRateBinInterval(&bind.CallOpts{ Context: ctx, }) @@ -756,6 +774,9 @@ func (t *Reader) GetGlobalRateBinInterval(ctx context.Context) (uint64, error) { } func (t *Reader) GetMinNumSymbols(ctx context.Context) (uint32, error) { + if t.bindings.PaymentVault == nil { + return 0, errors.New("payment vault not deployed") + } minNumSymbols, err := t.bindings.PaymentVault.MinNumSymbols(&bind.CallOpts{ Context: ctx, }) @@ -766,6 +787,9 @@ func (t *Reader) GetMinNumSymbols(ctx context.Context) (uint32, error) { } func (t *Reader) GetPricePerSymbol(ctx context.Context) (uint32, error) { + if t.bindings.PaymentVault == nil { + return 0, errors.New("payment vault not deployed") + } pricePerSymbol, err := t.bindings.PaymentVault.PricePerSymbol(&bind.CallOpts{ Context: ctx, }) @@ -776,6 +800,9 @@ func (t *Reader) GetPricePerSymbol(ctx context.Context) (uint32, error) { } 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, }) From 9b683309d827325560b946cf81eb11cf80b18167 Mon Sep 17 00:00:00 2001 From: hopeyen Date: Fri, 6 Dec 2024 09:01:53 -0800 Subject: [PATCH 11/18] fix: onchain state type --- disperser/cmd/apiserver/main.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/disperser/cmd/apiserver/main.go b/disperser/cmd/apiserver/main.go index bebdc18128..9a5752b6a7 100644 --- a/disperser/cmd/apiserver/main.go +++ b/disperser/cmd/apiserver/main.go @@ -124,7 +124,7 @@ func RunDisperserServer(ctx *cli.Context) error { // add some default sensible configs meterer = mt.NewMeterer( mtConfig, - &paymentChainState, + paymentChainState, offchainStore, logger, // metrics.NewNoopMetrics(), From 573c0310f1092454664b9cf5f05bc51f4fc26aac Mon Sep 17 00:00:00 2001 From: hopeyen Date: Fri, 6 Dec 2024 12:28:04 -0800 Subject: [PATCH 12/18] refactor: adding locks and moving checks --- core/data.go | 2 -- core/eth/reader.go | 22 +++++++--------------- core/meterer/onchain_state.go | 4 ++++ 3 files changed, 11 insertions(+), 17 deletions(-) diff --git a/core/data.go b/core/data.go index 6b09685526..c0dfec23cb 100644 --- a/core/data.go +++ b/core/data.go @@ -599,8 +599,6 @@ func ConvertToPaymentMetadata(ph *commonpb.PaymentHeader) *PaymentMetadata { } } -// OperatorInfo contains information about an operator which is stored on the blockchain state, -// corresponding to a particular quorum type ActiveReservation = paymentvault.IPaymentVaultReservation type OnDemandPayment struct { diff --git a/core/eth/reader.go b/core/eth/reader.go index 1120c6d5ca..edb64ee6e6 100644 --- a/core/eth/reader.go +++ b/core/eth/reader.go @@ -671,14 +671,10 @@ func (t *Reader) GetActiveReservations(ctx context.Context, accountIDs []gethcom // since reservations are returned in the same order as the accountIDs, we can directly map them for i, reservation := range reservations { - reservationsMap[accountIDs[i]] = &reservation - } - - // filter out all zero-valued reservations - for accountID, reservation := range reservationsMap { - if isZeroValuedReservation(*reservation) { - delete(reservationsMap, accountID) + if isZeroValuedReservation(reservation) { + delete(reservationsMap, accountIDs[i]) } + reservationsMap[accountIDs[i]] = &reservation } return reservationsMap, nil @@ -714,18 +710,14 @@ func (t *Reader) GetOnDemandPayments(ctx context.Context, accountIDs []gethcommo // since payments are returned in the same order as the accountIDs, we can directly map them for i, payment := range payments { + if payment.Cmp(big.NewInt(0)) == 0 { + delete(paymentsMap, accountIDs[i]) + } paymentsMap[accountIDs[i]] = &core.OnDemandPayment{ CumulativePayment: payment, } } - // filter out all zero-valued payments - for accountID, payment := range paymentsMap { - if payment.CumulativePayment.Cmp(big.NewInt(0)) == 0 { - delete(paymentsMap, accountID) - } - } - return paymentsMap, nil } @@ -739,7 +731,7 @@ func (t *Reader) GetOnDemandPaymentByAccount(ctx context.Context, accountID geth if err != nil { return nil, err } - if onDemandPayment == big.NewInt(0) { + if onDemandPayment.Cmp(big.NewInt(0)) == 0 { return nil, errors.New("ondemand payment does not exist for given account") } return &core.OnDemandPayment{ diff --git a/core/meterer/onchain_state.go b/core/meterer/onchain_state.go index 45a8a24fc4..cdfaef457b 100644 --- a/core/meterer/onchain_state.go +++ b/core/meterer/onchain_state.go @@ -146,6 +146,8 @@ func (pcs *OnchainPaymentState) RefreshOnchainPaymentState(ctx context.Context, // GetActiveReservationByAccount returns a pointer to the active reservation for the given account ID; no writes will be made to the reservation func (pcs *OnchainPaymentState) GetActiveReservationByAccount(ctx context.Context, accountID gethcommon.Address) (*core.ActiveReservation, error) { + pcs.ReservationsLock.RLock() + defer pcs.ReservationsLock.RUnlock() if reservation, ok := (pcs.ActiveReservations)[accountID]; ok { return reservation, nil } @@ -172,6 +174,8 @@ func (pcs *OnchainPaymentState) GetActiveReservationByAccountOnChain(ctx context // GetOnDemandPaymentByAccount returns a pointer to the on-demand payment for the given account ID; no writes will be made to the payment func (pcs *OnchainPaymentState) GetOnDemandPaymentByAccount(ctx context.Context, accountID gethcommon.Address) (*core.OnDemandPayment, error) { + pcs.OnDemandLocks.RLock() + defer pcs.OnDemandLocks.RUnlock() if payment, ok := (pcs.OnDemandPayments)[accountID]; ok { return payment, nil } From 34ffa52098cc340cceffd85dbd958e0bfd40e9b3 Mon Sep 17 00:00:00 2001 From: hopeyen Date: Fri, 6 Dec 2024 12:32:47 -0800 Subject: [PATCH 13/18] fix: QuorumSplits typo --- api/clients/accountant.go | 12 +- api/grpc/disperser/v2/disperser_v2.pb.go | 90 ++-- api/proto/disperser/v2/disperser_v2.proto | 2 +- disperser/api/grpc/encoder/encoder.pb.go | 484 ------------------ disperser/api/grpc/encoder/encoder_grpc.pb.go | 109 ---- disperser/api/grpc/encoder/v2/encoder.pb.go | 386 -------------- .../api/grpc/encoder/v2/encoder_grpc.pb.go | 115 ----- disperser/apiserver/server_v2.go | 9 +- 8 files changed, 57 insertions(+), 1150 deletions(-) delete mode 100644 disperser/api/grpc/encoder/encoder.pb.go delete mode 100644 disperser/api/grpc/encoder/encoder_grpc.pb.go delete mode 100644 disperser/api/grpc/encoder/v2/encoder.pb.go delete mode 100644 disperser/api/grpc/encoder/v2/encoder_grpc.pb.go diff --git a/api/clients/accountant.go b/api/clients/accountant.go index 02cf11ac26..ef76eef1d9 100644 --- a/api/clients/accountant.go +++ b/api/clients/accountant.go @@ -166,7 +166,7 @@ func (a *Accountant) SetPaymentState(paymentState *disperser_rpc.GetPaymentState return fmt.Errorf("reservation cannot be nil") } else if paymentState.GetReservation().GetQuorumNumbers() == nil { return fmt.Errorf("reservation quorum numbers cannot be nil") - } else if paymentState.GetReservation().GetQuorumSplit() == nil { + } else if paymentState.GetReservation().GetQuorumSplits() == nil { return fmt.Errorf("reservation quorum split cannot be nil") } else if paymentState.GetBinRecords() == nil { return fmt.Errorf("bin records cannot be nil") @@ -177,7 +177,7 @@ func (a *Accountant) SetPaymentState(paymentState *disperser_rpc.GetPaymentState a.cumulativePayment = new(big.Int).SetBytes(paymentState.CumulativePayment) a.pricePerSymbol = uint32(paymentState.PaymentGlobalParams.PricePerSymbol) - a.reservation.SymbolsPerSec = uint64(paymentState.PaymentGlobalParams.GlobalSymbolsPerSecond) + a.reservation.SymbolsPerSecond = uint64(paymentState.PaymentGlobalParams.GlobalSymbolsPerSecond) a.reservation.StartTimestamp = uint64(paymentState.Reservation.StartTimestamp) a.reservation.EndTimestamp = uint64(paymentState.Reservation.EndTimestamp) a.reservationWindow = uint32(paymentState.PaymentGlobalParams.ReservationWindow) @@ -188,11 +188,11 @@ func (a *Accountant) SetPaymentState(paymentState *disperser_rpc.GetPaymentState } a.reservation.QuorumNumbers = quorumNumbers - quorumSplit := make([]uint8, len(paymentState.Reservation.QuorumSplit)) - for i, quorum := range paymentState.Reservation.QuorumSplit { - quorumSplit[i] = uint8(quorum) + quorumSplits := make([]uint8, len(paymentState.Reservation.QuorumSplits)) + for i, quorum := range paymentState.Reservation.QuorumSplits { + quorumSplits[i] = uint8(quorum) } - a.reservation.QuorumSplit = quorumSplit + a.reservation.QuorumSplits = quorumSplits binRecords := make([]BinRecord, len(paymentState.BinRecords)) for i, record := range paymentState.BinRecords { diff --git a/api/grpc/disperser/v2/disperser_v2.pb.go b/api/grpc/disperser/v2/disperser_v2.pb.go index 6e1db037b2..cca3e75dea 100644 --- a/api/grpc/disperser/v2/disperser_v2.pb.go +++ b/api/grpc/disperser/v2/disperser_v2.pb.go @@ -862,7 +862,7 @@ type Reservation struct { StartTimestamp uint32 `protobuf:"varint,2,opt,name=start_timestamp,json=startTimestamp,proto3" json:"start_timestamp,omitempty"` EndTimestamp uint32 `protobuf:"varint,3,opt,name=end_timestamp,json=endTimestamp,proto3" json:"end_timestamp,omitempty"` QuorumNumbers []uint32 `protobuf:"varint,4,rep,packed,name=quorum_numbers,json=quorumNumbers,proto3" json:"quorum_numbers,omitempty"` - QuorumSplit []uint32 `protobuf:"varint,5,rep,packed,name=quorum_split,json=quorumSplit,proto3" json:"quorum_split,omitempty"` + QuorumSplits []uint32 `protobuf:"varint,5,rep,packed,name=quorum_splits,json=quorumSplits,proto3" json:"quorum_splits,omitempty"` } func (x *Reservation) Reset() { @@ -925,9 +925,9 @@ func (x *Reservation) GetQuorumNumbers() []uint32 { return nil } -func (x *Reservation) GetQuorumSplit() []uint32 { +func (x *Reservation) GetQuorumSplits() []uint32 { if x != nil { - return x.QuorumSplit + return x.QuorumSplits } return nil } @@ -1108,7 +1108,7 @@ var file_disperser_v2_disperser_v2_proto_rawDesc = []byte{ 0x5f, 0x64, 0x65, 0x6d, 0x61, 0x6e, 0x64, 0x5f, 0x71, 0x75, 0x6f, 0x72, 0x75, 0x6d, 0x5f, 0x6e, 0x75, 0x6d, 0x62, 0x65, 0x72, 0x73, 0x18, 0x05, 0x20, 0x03, 0x28, 0x0d, 0x52, 0x15, 0x6f, 0x6e, 0x44, 0x65, 0x6d, 0x61, 0x6e, 0x64, 0x51, 0x75, 0x6f, 0x72, 0x75, 0x6d, 0x4e, 0x75, 0x6d, 0x62, - 0x65, 0x72, 0x73, 0x22, 0xd3, 0x01, 0x0a, 0x0b, 0x52, 0x65, 0x73, 0x65, 0x72, 0x76, 0x61, 0x74, + 0x65, 0x72, 0x73, 0x22, 0xd5, 0x01, 0x0a, 0x0b, 0x52, 0x65, 0x73, 0x65, 0x72, 0x76, 0x61, 0x74, 0x69, 0x6f, 0x6e, 0x12, 0x2c, 0x0a, 0x12, 0x73, 0x79, 0x6d, 0x62, 0x6f, 0x6c, 0x73, 0x5f, 0x70, 0x65, 0x72, 0x5f, 0x73, 0x65, 0x63, 0x6f, 0x6e, 0x64, 0x18, 0x01, 0x20, 0x01, 0x28, 0x04, 0x52, 0x10, 0x73, 0x79, 0x6d, 0x62, 0x6f, 0x6c, 0x73, 0x50, 0x65, 0x72, 0x53, 0x65, 0x63, 0x6f, 0x6e, @@ -1119,47 +1119,47 @@ var file_disperser_v2_disperser_v2_proto_rawDesc = []byte{ 0x0d, 0x52, 0x0c, 0x65, 0x6e, 0x64, 0x54, 0x69, 0x6d, 0x65, 0x73, 0x74, 0x61, 0x6d, 0x70, 0x12, 0x25, 0x0a, 0x0e, 0x71, 0x75, 0x6f, 0x72, 0x75, 0x6d, 0x5f, 0x6e, 0x75, 0x6d, 0x62, 0x65, 0x72, 0x73, 0x18, 0x04, 0x20, 0x03, 0x28, 0x0d, 0x52, 0x0d, 0x71, 0x75, 0x6f, 0x72, 0x75, 0x6d, 0x4e, - 0x75, 0x6d, 0x62, 0x65, 0x72, 0x73, 0x12, 0x21, 0x0a, 0x0c, 0x71, 0x75, 0x6f, 0x72, 0x75, 0x6d, - 0x5f, 0x73, 0x70, 0x6c, 0x69, 0x74, 0x18, 0x05, 0x20, 0x03, 0x28, 0x0d, 0x52, 0x0b, 0x71, 0x75, - 0x6f, 0x72, 0x75, 0x6d, 0x53, 0x70, 0x6c, 0x69, 0x74, 0x22, 0x37, 0x0a, 0x09, 0x42, 0x69, 0x6e, - 0x52, 0x65, 0x63, 0x6f, 0x72, 0x64, 0x12, 0x14, 0x0a, 0x05, 0x69, 0x6e, 0x64, 0x65, 0x78, 0x18, - 0x01, 0x20, 0x01, 0x28, 0x0d, 0x52, 0x05, 0x69, 0x6e, 0x64, 0x65, 0x78, 0x12, 0x14, 0x0a, 0x05, - 0x75, 0x73, 0x61, 0x67, 0x65, 0x18, 0x02, 0x20, 0x01, 0x28, 0x04, 0x52, 0x05, 0x75, 0x73, 0x61, - 0x67, 0x65, 0x2a, 0x6a, 0x0a, 0x0a, 0x42, 0x6c, 0x6f, 0x62, 0x53, 0x74, 0x61, 0x74, 0x75, 0x73, - 0x12, 0x0b, 0x0a, 0x07, 0x55, 0x4e, 0x4b, 0x4e, 0x4f, 0x57, 0x4e, 0x10, 0x00, 0x12, 0x0a, 0x0a, - 0x06, 0x51, 0x55, 0x45, 0x55, 0x45, 0x44, 0x10, 0x01, 0x12, 0x0b, 0x0a, 0x07, 0x45, 0x4e, 0x43, - 0x4f, 0x44, 0x45, 0x44, 0x10, 0x02, 0x12, 0x0d, 0x0a, 0x09, 0x43, 0x45, 0x52, 0x54, 0x49, 0x46, - 0x49, 0x45, 0x44, 0x10, 0x03, 0x12, 0x0a, 0x0a, 0x06, 0x46, 0x41, 0x49, 0x4c, 0x45, 0x44, 0x10, - 0x04, 0x12, 0x1b, 0x0a, 0x17, 0x49, 0x4e, 0x53, 0x55, 0x46, 0x46, 0x49, 0x43, 0x49, 0x45, 0x4e, - 0x54, 0x5f, 0x53, 0x49, 0x47, 0x4e, 0x41, 0x54, 0x55, 0x52, 0x45, 0x53, 0x10, 0x05, 0x32, 0xf2, - 0x02, 0x0a, 0x09, 0x44, 0x69, 0x73, 0x70, 0x65, 0x72, 0x73, 0x65, 0x72, 0x12, 0x54, 0x0a, 0x0c, - 0x44, 0x69, 0x73, 0x70, 0x65, 0x72, 0x73, 0x65, 0x42, 0x6c, 0x6f, 0x62, 0x12, 0x21, 0x2e, 0x64, - 0x69, 0x73, 0x70, 0x65, 0x72, 0x73, 0x65, 0x72, 0x2e, 0x76, 0x32, 0x2e, 0x44, 0x69, 0x73, 0x70, - 0x65, 0x72, 0x73, 0x65, 0x42, 0x6c, 0x6f, 0x62, 0x52, 0x65, 0x71, 0x75, 0x65, 0x73, 0x74, 0x1a, - 0x1f, 0x2e, 0x64, 0x69, 0x73, 0x70, 0x65, 0x72, 0x73, 0x65, 0x72, 0x2e, 0x76, 0x32, 0x2e, 0x44, - 0x69, 0x73, 0x70, 0x65, 0x72, 0x73, 0x65, 0x42, 0x6c, 0x6f, 0x62, 0x52, 0x65, 0x70, 0x6c, 0x79, - 0x22, 0x00, 0x12, 0x51, 0x0a, 0x0d, 0x47, 0x65, 0x74, 0x42, 0x6c, 0x6f, 0x62, 0x53, 0x74, 0x61, - 0x74, 0x75, 0x73, 0x12, 0x1f, 0x2e, 0x64, 0x69, 0x73, 0x70, 0x65, 0x72, 0x73, 0x65, 0x72, 0x2e, - 0x76, 0x32, 0x2e, 0x42, 0x6c, 0x6f, 0x62, 0x53, 0x74, 0x61, 0x74, 0x75, 0x73, 0x52, 0x65, 0x71, - 0x75, 0x65, 0x73, 0x74, 0x1a, 0x1d, 0x2e, 0x64, 0x69, 0x73, 0x70, 0x65, 0x72, 0x73, 0x65, 0x72, - 0x2e, 0x76, 0x32, 0x2e, 0x42, 0x6c, 0x6f, 0x62, 0x53, 0x74, 0x61, 0x74, 0x75, 0x73, 0x52, 0x65, - 0x70, 0x6c, 0x79, 0x22, 0x00, 0x12, 0x5d, 0x0a, 0x11, 0x47, 0x65, 0x74, 0x42, 0x6c, 0x6f, 0x62, - 0x43, 0x6f, 0x6d, 0x6d, 0x69, 0x74, 0x6d, 0x65, 0x6e, 0x74, 0x12, 0x23, 0x2e, 0x64, 0x69, 0x73, - 0x70, 0x65, 0x72, 0x73, 0x65, 0x72, 0x2e, 0x76, 0x32, 0x2e, 0x42, 0x6c, 0x6f, 0x62, 0x43, 0x6f, - 0x6d, 0x6d, 0x69, 0x74, 0x6d, 0x65, 0x6e, 0x74, 0x52, 0x65, 0x71, 0x75, 0x65, 0x73, 0x74, 0x1a, - 0x21, 0x2e, 0x64, 0x69, 0x73, 0x70, 0x65, 0x72, 0x73, 0x65, 0x72, 0x2e, 0x76, 0x32, 0x2e, 0x42, - 0x6c, 0x6f, 0x62, 0x43, 0x6f, 0x6d, 0x6d, 0x69, 0x74, 0x6d, 0x65, 0x6e, 0x74, 0x52, 0x65, 0x70, - 0x6c, 0x79, 0x22, 0x00, 0x12, 0x5d, 0x0a, 0x0f, 0x47, 0x65, 0x74, 0x50, 0x61, 0x79, 0x6d, 0x65, - 0x6e, 0x74, 0x53, 0x74, 0x61, 0x74, 0x65, 0x12, 0x24, 0x2e, 0x64, 0x69, 0x73, 0x70, 0x65, 0x72, - 0x73, 0x65, 0x72, 0x2e, 0x76, 0x32, 0x2e, 0x47, 0x65, 0x74, 0x50, 0x61, 0x79, 0x6d, 0x65, 0x6e, - 0x74, 0x53, 0x74, 0x61, 0x74, 0x65, 0x52, 0x65, 0x71, 0x75, 0x65, 0x73, 0x74, 0x1a, 0x22, 0x2e, - 0x64, 0x69, 0x73, 0x70, 0x65, 0x72, 0x73, 0x65, 0x72, 0x2e, 0x76, 0x32, 0x2e, 0x47, 0x65, 0x74, - 0x50, 0x61, 0x79, 0x6d, 0x65, 0x6e, 0x74, 0x53, 0x74, 0x61, 0x74, 0x65, 0x52, 0x65, 0x70, 0x6c, - 0x79, 0x22, 0x00, 0x42, 0x34, 0x5a, 0x32, 0x67, 0x69, 0x74, 0x68, 0x75, 0x62, 0x2e, 0x63, 0x6f, - 0x6d, 0x2f, 0x4c, 0x61, 0x79, 0x72, 0x2d, 0x4c, 0x61, 0x62, 0x73, 0x2f, 0x65, 0x69, 0x67, 0x65, - 0x6e, 0x64, 0x61, 0x2f, 0x61, 0x70, 0x69, 0x2f, 0x67, 0x72, 0x70, 0x63, 0x2f, 0x64, 0x69, 0x73, - 0x70, 0x65, 0x72, 0x73, 0x65, 0x72, 0x2f, 0x76, 0x32, 0x62, 0x06, 0x70, 0x72, 0x6f, 0x74, 0x6f, - 0x33, + 0x75, 0x6d, 0x62, 0x65, 0x72, 0x73, 0x12, 0x23, 0x0a, 0x0d, 0x71, 0x75, 0x6f, 0x72, 0x75, 0x6d, + 0x5f, 0x73, 0x70, 0x6c, 0x69, 0x74, 0x73, 0x18, 0x05, 0x20, 0x03, 0x28, 0x0d, 0x52, 0x0c, 0x71, + 0x75, 0x6f, 0x72, 0x75, 0x6d, 0x53, 0x70, 0x6c, 0x69, 0x74, 0x73, 0x22, 0x37, 0x0a, 0x09, 0x42, + 0x69, 0x6e, 0x52, 0x65, 0x63, 0x6f, 0x72, 0x64, 0x12, 0x14, 0x0a, 0x05, 0x69, 0x6e, 0x64, 0x65, + 0x78, 0x18, 0x01, 0x20, 0x01, 0x28, 0x0d, 0x52, 0x05, 0x69, 0x6e, 0x64, 0x65, 0x78, 0x12, 0x14, + 0x0a, 0x05, 0x75, 0x73, 0x61, 0x67, 0x65, 0x18, 0x02, 0x20, 0x01, 0x28, 0x04, 0x52, 0x05, 0x75, + 0x73, 0x61, 0x67, 0x65, 0x2a, 0x6a, 0x0a, 0x0a, 0x42, 0x6c, 0x6f, 0x62, 0x53, 0x74, 0x61, 0x74, + 0x75, 0x73, 0x12, 0x0b, 0x0a, 0x07, 0x55, 0x4e, 0x4b, 0x4e, 0x4f, 0x57, 0x4e, 0x10, 0x00, 0x12, + 0x0a, 0x0a, 0x06, 0x51, 0x55, 0x45, 0x55, 0x45, 0x44, 0x10, 0x01, 0x12, 0x0b, 0x0a, 0x07, 0x45, + 0x4e, 0x43, 0x4f, 0x44, 0x45, 0x44, 0x10, 0x02, 0x12, 0x0d, 0x0a, 0x09, 0x43, 0x45, 0x52, 0x54, + 0x49, 0x46, 0x49, 0x45, 0x44, 0x10, 0x03, 0x12, 0x0a, 0x0a, 0x06, 0x46, 0x41, 0x49, 0x4c, 0x45, + 0x44, 0x10, 0x04, 0x12, 0x1b, 0x0a, 0x17, 0x49, 0x4e, 0x53, 0x55, 0x46, 0x46, 0x49, 0x43, 0x49, + 0x45, 0x4e, 0x54, 0x5f, 0x53, 0x49, 0x47, 0x4e, 0x41, 0x54, 0x55, 0x52, 0x45, 0x53, 0x10, 0x05, + 0x32, 0xf2, 0x02, 0x0a, 0x09, 0x44, 0x69, 0x73, 0x70, 0x65, 0x72, 0x73, 0x65, 0x72, 0x12, 0x54, + 0x0a, 0x0c, 0x44, 0x69, 0x73, 0x70, 0x65, 0x72, 0x73, 0x65, 0x42, 0x6c, 0x6f, 0x62, 0x12, 0x21, + 0x2e, 0x64, 0x69, 0x73, 0x70, 0x65, 0x72, 0x73, 0x65, 0x72, 0x2e, 0x76, 0x32, 0x2e, 0x44, 0x69, + 0x73, 0x70, 0x65, 0x72, 0x73, 0x65, 0x42, 0x6c, 0x6f, 0x62, 0x52, 0x65, 0x71, 0x75, 0x65, 0x73, + 0x74, 0x1a, 0x1f, 0x2e, 0x64, 0x69, 0x73, 0x70, 0x65, 0x72, 0x73, 0x65, 0x72, 0x2e, 0x76, 0x32, + 0x2e, 0x44, 0x69, 0x73, 0x70, 0x65, 0x72, 0x73, 0x65, 0x42, 0x6c, 0x6f, 0x62, 0x52, 0x65, 0x70, + 0x6c, 0x79, 0x22, 0x00, 0x12, 0x51, 0x0a, 0x0d, 0x47, 0x65, 0x74, 0x42, 0x6c, 0x6f, 0x62, 0x53, + 0x74, 0x61, 0x74, 0x75, 0x73, 0x12, 0x1f, 0x2e, 0x64, 0x69, 0x73, 0x70, 0x65, 0x72, 0x73, 0x65, + 0x72, 0x2e, 0x76, 0x32, 0x2e, 0x42, 0x6c, 0x6f, 0x62, 0x53, 0x74, 0x61, 0x74, 0x75, 0x73, 0x52, + 0x65, 0x71, 0x75, 0x65, 0x73, 0x74, 0x1a, 0x1d, 0x2e, 0x64, 0x69, 0x73, 0x70, 0x65, 0x72, 0x73, + 0x65, 0x72, 0x2e, 0x76, 0x32, 0x2e, 0x42, 0x6c, 0x6f, 0x62, 0x53, 0x74, 0x61, 0x74, 0x75, 0x73, + 0x52, 0x65, 0x70, 0x6c, 0x79, 0x22, 0x00, 0x12, 0x5d, 0x0a, 0x11, 0x47, 0x65, 0x74, 0x42, 0x6c, + 0x6f, 0x62, 0x43, 0x6f, 0x6d, 0x6d, 0x69, 0x74, 0x6d, 0x65, 0x6e, 0x74, 0x12, 0x23, 0x2e, 0x64, + 0x69, 0x73, 0x70, 0x65, 0x72, 0x73, 0x65, 0x72, 0x2e, 0x76, 0x32, 0x2e, 0x42, 0x6c, 0x6f, 0x62, + 0x43, 0x6f, 0x6d, 0x6d, 0x69, 0x74, 0x6d, 0x65, 0x6e, 0x74, 0x52, 0x65, 0x71, 0x75, 0x65, 0x73, + 0x74, 0x1a, 0x21, 0x2e, 0x64, 0x69, 0x73, 0x70, 0x65, 0x72, 0x73, 0x65, 0x72, 0x2e, 0x76, 0x32, + 0x2e, 0x42, 0x6c, 0x6f, 0x62, 0x43, 0x6f, 0x6d, 0x6d, 0x69, 0x74, 0x6d, 0x65, 0x6e, 0x74, 0x52, + 0x65, 0x70, 0x6c, 0x79, 0x22, 0x00, 0x12, 0x5d, 0x0a, 0x0f, 0x47, 0x65, 0x74, 0x50, 0x61, 0x79, + 0x6d, 0x65, 0x6e, 0x74, 0x53, 0x74, 0x61, 0x74, 0x65, 0x12, 0x24, 0x2e, 0x64, 0x69, 0x73, 0x70, + 0x65, 0x72, 0x73, 0x65, 0x72, 0x2e, 0x76, 0x32, 0x2e, 0x47, 0x65, 0x74, 0x50, 0x61, 0x79, 0x6d, + 0x65, 0x6e, 0x74, 0x53, 0x74, 0x61, 0x74, 0x65, 0x52, 0x65, 0x71, 0x75, 0x65, 0x73, 0x74, 0x1a, + 0x22, 0x2e, 0x64, 0x69, 0x73, 0x70, 0x65, 0x72, 0x73, 0x65, 0x72, 0x2e, 0x76, 0x32, 0x2e, 0x47, + 0x65, 0x74, 0x50, 0x61, 0x79, 0x6d, 0x65, 0x6e, 0x74, 0x53, 0x74, 0x61, 0x74, 0x65, 0x52, 0x65, + 0x70, 0x6c, 0x79, 0x22, 0x00, 0x42, 0x34, 0x5a, 0x32, 0x67, 0x69, 0x74, 0x68, 0x75, 0x62, 0x2e, + 0x63, 0x6f, 0x6d, 0x2f, 0x4c, 0x61, 0x79, 0x72, 0x2d, 0x4c, 0x61, 0x62, 0x73, 0x2f, 0x65, 0x69, + 0x67, 0x65, 0x6e, 0x64, 0x61, 0x2f, 0x61, 0x70, 0x69, 0x2f, 0x67, 0x72, 0x70, 0x63, 0x2f, 0x64, + 0x69, 0x73, 0x70, 0x65, 0x72, 0x73, 0x65, 0x72, 0x2f, 0x76, 0x32, 0x62, 0x06, 0x70, 0x72, 0x6f, + 0x74, 0x6f, 0x33, } var ( diff --git a/api/proto/disperser/v2/disperser_v2.proto b/api/proto/disperser/v2/disperser_v2.proto index 4107023bc3..a9425249de 100644 --- a/api/proto/disperser/v2/disperser_v2.proto +++ b/api/proto/disperser/v2/disperser_v2.proto @@ -164,7 +164,7 @@ message Reservation { uint32 start_timestamp = 2; uint32 end_timestamp = 3; repeated uint32 quorum_numbers = 4; - repeated uint32 quorum_split = 5; + repeated uint32 quorum_splits = 5; } // BinRecord is the usage record of an account in a bin. The API should return the active bin diff --git a/disperser/api/grpc/encoder/encoder.pb.go b/disperser/api/grpc/encoder/encoder.pb.go deleted file mode 100644 index 63acf6b36c..0000000000 --- a/disperser/api/grpc/encoder/encoder.pb.go +++ /dev/null @@ -1,484 +0,0 @@ -// Code generated by protoc-gen-go. DO NOT EDIT. -// versions: -// protoc-gen-go v1.28.1 -// protoc v4.23.4 -// source: encoder/encoder.proto - -package encoder - -import ( - protoreflect "google.golang.org/protobuf/reflect/protoreflect" - protoimpl "google.golang.org/protobuf/runtime/protoimpl" - reflect "reflect" - sync "sync" -) - -const ( - // Verify that this generated code is sufficiently up-to-date. - _ = protoimpl.EnforceVersion(20 - protoimpl.MinVersion) - // Verify that runtime/protoimpl is sufficiently up-to-date. - _ = protoimpl.EnforceVersion(protoimpl.MaxVersion - 20) -) - -type ChunkEncodingFormat int32 - -const ( - ChunkEncodingFormat_UNKNOWN ChunkEncodingFormat = 0 - ChunkEncodingFormat_GNARK ChunkEncodingFormat = 1 - ChunkEncodingFormat_GOB ChunkEncodingFormat = 2 -) - -// Enum value maps for ChunkEncodingFormat. -var ( - ChunkEncodingFormat_name = map[int32]string{ - 0: "UNKNOWN", - 1: "GNARK", - 2: "GOB", - } - ChunkEncodingFormat_value = map[string]int32{ - "UNKNOWN": 0, - "GNARK": 1, - "GOB": 2, - } -) - -func (x ChunkEncodingFormat) Enum() *ChunkEncodingFormat { - p := new(ChunkEncodingFormat) - *p = x - return p -} - -func (x ChunkEncodingFormat) String() string { - return protoimpl.X.EnumStringOf(x.Descriptor(), protoreflect.EnumNumber(x)) -} - -func (ChunkEncodingFormat) Descriptor() protoreflect.EnumDescriptor { - return file_encoder_encoder_proto_enumTypes[0].Descriptor() -} - -func (ChunkEncodingFormat) Type() protoreflect.EnumType { - return &file_encoder_encoder_proto_enumTypes[0] -} - -func (x ChunkEncodingFormat) Number() protoreflect.EnumNumber { - return protoreflect.EnumNumber(x) -} - -// Deprecated: Use ChunkEncodingFormat.Descriptor instead. -func (ChunkEncodingFormat) EnumDescriptor() ([]byte, []int) { - return file_encoder_encoder_proto_rawDescGZIP(), []int{0} -} - -// BlobCommitments contains the blob's commitment, degree proof, and the actual degree -// DEPRECATED: use common.BlobCommitment instead -type BlobCommitment struct { - state protoimpl.MessageState - sizeCache protoimpl.SizeCache - unknownFields protoimpl.UnknownFields - - Commitment []byte `protobuf:"bytes,1,opt,name=commitment,proto3" json:"commitment,omitempty"` - LengthCommitment []byte `protobuf:"bytes,2,opt,name=length_commitment,json=lengthCommitment,proto3" json:"length_commitment,omitempty"` - LengthProof []byte `protobuf:"bytes,3,opt,name=length_proof,json=lengthProof,proto3" json:"length_proof,omitempty"` - Length uint32 `protobuf:"varint,4,opt,name=length,proto3" json:"length,omitempty"` -} - -func (x *BlobCommitment) Reset() { - *x = BlobCommitment{} - if protoimpl.UnsafeEnabled { - mi := &file_encoder_encoder_proto_msgTypes[0] - ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) - ms.StoreMessageInfo(mi) - } -} - -func (x *BlobCommitment) String() string { - return protoimpl.X.MessageStringOf(x) -} - -func (*BlobCommitment) ProtoMessage() {} - -func (x *BlobCommitment) ProtoReflect() protoreflect.Message { - mi := &file_encoder_encoder_proto_msgTypes[0] - if protoimpl.UnsafeEnabled && x != nil { - ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) - if ms.LoadMessageInfo() == nil { - ms.StoreMessageInfo(mi) - } - return ms - } - return mi.MessageOf(x) -} - -// Deprecated: Use BlobCommitment.ProtoReflect.Descriptor instead. -func (*BlobCommitment) Descriptor() ([]byte, []int) { - return file_encoder_encoder_proto_rawDescGZIP(), []int{0} -} - -func (x *BlobCommitment) GetCommitment() []byte { - if x != nil { - return x.Commitment - } - return nil -} - -func (x *BlobCommitment) GetLengthCommitment() []byte { - if x != nil { - return x.LengthCommitment - } - return nil -} - -func (x *BlobCommitment) GetLengthProof() []byte { - if x != nil { - return x.LengthProof - } - return nil -} - -func (x *BlobCommitment) GetLength() uint32 { - if x != nil { - return x.Length - } - return 0 -} - -// Parameters needed by Encoder for encoding -type EncodingParams struct { - state protoimpl.MessageState - sizeCache protoimpl.SizeCache - unknownFields protoimpl.UnknownFields - - ChunkLength uint32 `protobuf:"varint,1,opt,name=chunk_length,json=chunkLength,proto3" json:"chunk_length,omitempty"` - NumChunks uint32 `protobuf:"varint,2,opt,name=num_chunks,json=numChunks,proto3" json:"num_chunks,omitempty"` -} - -func (x *EncodingParams) Reset() { - *x = EncodingParams{} - if protoimpl.UnsafeEnabled { - mi := &file_encoder_encoder_proto_msgTypes[1] - ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) - ms.StoreMessageInfo(mi) - } -} - -func (x *EncodingParams) String() string { - return protoimpl.X.MessageStringOf(x) -} - -func (*EncodingParams) ProtoMessage() {} - -func (x *EncodingParams) ProtoReflect() protoreflect.Message { - mi := &file_encoder_encoder_proto_msgTypes[1] - if protoimpl.UnsafeEnabled && x != nil { - ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) - if ms.LoadMessageInfo() == nil { - ms.StoreMessageInfo(mi) - } - return ms - } - return mi.MessageOf(x) -} - -// Deprecated: Use EncodingParams.ProtoReflect.Descriptor instead. -func (*EncodingParams) Descriptor() ([]byte, []int) { - return file_encoder_encoder_proto_rawDescGZIP(), []int{1} -} - -func (x *EncodingParams) GetChunkLength() uint32 { - if x != nil { - return x.ChunkLength - } - return 0 -} - -func (x *EncodingParams) GetNumChunks() uint32 { - if x != nil { - return x.NumChunks - } - return 0 -} - -// EncodeBlobRequest contains data and pre-computed encoding params provided to Encoder -type EncodeBlobRequest struct { - state protoimpl.MessageState - sizeCache protoimpl.SizeCache - unknownFields protoimpl.UnknownFields - - Data []byte `protobuf:"bytes,1,opt,name=data,proto3" json:"data,omitempty"` - EncodingParams *EncodingParams `protobuf:"bytes,2,opt,name=encoding_params,json=encodingParams,proto3" json:"encoding_params,omitempty"` -} - -func (x *EncodeBlobRequest) Reset() { - *x = EncodeBlobRequest{} - if protoimpl.UnsafeEnabled { - mi := &file_encoder_encoder_proto_msgTypes[2] - ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) - ms.StoreMessageInfo(mi) - } -} - -func (x *EncodeBlobRequest) String() string { - return protoimpl.X.MessageStringOf(x) -} - -func (*EncodeBlobRequest) ProtoMessage() {} - -func (x *EncodeBlobRequest) ProtoReflect() protoreflect.Message { - mi := &file_encoder_encoder_proto_msgTypes[2] - if protoimpl.UnsafeEnabled && x != nil { - ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) - if ms.LoadMessageInfo() == nil { - ms.StoreMessageInfo(mi) - } - return ms - } - return mi.MessageOf(x) -} - -// Deprecated: Use EncodeBlobRequest.ProtoReflect.Descriptor instead. -func (*EncodeBlobRequest) Descriptor() ([]byte, []int) { - return file_encoder_encoder_proto_rawDescGZIP(), []int{2} -} - -func (x *EncodeBlobRequest) GetData() []byte { - if x != nil { - return x.Data - } - return nil -} - -func (x *EncodeBlobRequest) GetEncodingParams() *EncodingParams { - if x != nil { - return x.EncodingParams - } - return nil -} - -// EncodeBlobReply returns all encoded chunks along with BlobCommitment for the same, -// where Chunk is the smallest unit that is distributed to DA nodes -type EncodeBlobReply struct { - state protoimpl.MessageState - sizeCache protoimpl.SizeCache - unknownFields protoimpl.UnknownFields - - Commitment *BlobCommitment `protobuf:"bytes,1,opt,name=commitment,proto3" json:"commitment,omitempty"` - Chunks [][]byte `protobuf:"bytes,2,rep,name=chunks,proto3" json:"chunks,omitempty"` - // How the above chunks are encoded. - ChunkEncodingFormat ChunkEncodingFormat `protobuf:"varint,3,opt,name=chunk_encoding_format,json=chunkEncodingFormat,proto3,enum=encoder.ChunkEncodingFormat" json:"chunk_encoding_format,omitempty"` -} - -func (x *EncodeBlobReply) Reset() { - *x = EncodeBlobReply{} - if protoimpl.UnsafeEnabled { - mi := &file_encoder_encoder_proto_msgTypes[3] - ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) - ms.StoreMessageInfo(mi) - } -} - -func (x *EncodeBlobReply) String() string { - return protoimpl.X.MessageStringOf(x) -} - -func (*EncodeBlobReply) ProtoMessage() {} - -func (x *EncodeBlobReply) ProtoReflect() protoreflect.Message { - mi := &file_encoder_encoder_proto_msgTypes[3] - if protoimpl.UnsafeEnabled && x != nil { - ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) - if ms.LoadMessageInfo() == nil { - ms.StoreMessageInfo(mi) - } - return ms - } - return mi.MessageOf(x) -} - -// Deprecated: Use EncodeBlobReply.ProtoReflect.Descriptor instead. -func (*EncodeBlobReply) Descriptor() ([]byte, []int) { - return file_encoder_encoder_proto_rawDescGZIP(), []int{3} -} - -func (x *EncodeBlobReply) GetCommitment() *BlobCommitment { - if x != nil { - return x.Commitment - } - return nil -} - -func (x *EncodeBlobReply) GetChunks() [][]byte { - if x != nil { - return x.Chunks - } - return nil -} - -func (x *EncodeBlobReply) GetChunkEncodingFormat() ChunkEncodingFormat { - if x != nil { - return x.ChunkEncodingFormat - } - return ChunkEncodingFormat_UNKNOWN -} - -var File_encoder_encoder_proto protoreflect.FileDescriptor - -var file_encoder_encoder_proto_rawDesc = []byte{ - 0x0a, 0x15, 0x65, 0x6e, 0x63, 0x6f, 0x64, 0x65, 0x72, 0x2f, 0x65, 0x6e, 0x63, 0x6f, 0x64, 0x65, - 0x72, 0x2e, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x12, 0x07, 0x65, 0x6e, 0x63, 0x6f, 0x64, 0x65, 0x72, - 0x22, 0x98, 0x01, 0x0a, 0x0e, 0x42, 0x6c, 0x6f, 0x62, 0x43, 0x6f, 0x6d, 0x6d, 0x69, 0x74, 0x6d, - 0x65, 0x6e, 0x74, 0x12, 0x1e, 0x0a, 0x0a, 0x63, 0x6f, 0x6d, 0x6d, 0x69, 0x74, 0x6d, 0x65, 0x6e, - 0x74, 0x18, 0x01, 0x20, 0x01, 0x28, 0x0c, 0x52, 0x0a, 0x63, 0x6f, 0x6d, 0x6d, 0x69, 0x74, 0x6d, - 0x65, 0x6e, 0x74, 0x12, 0x2b, 0x0a, 0x11, 0x6c, 0x65, 0x6e, 0x67, 0x74, 0x68, 0x5f, 0x63, 0x6f, - 0x6d, 0x6d, 0x69, 0x74, 0x6d, 0x65, 0x6e, 0x74, 0x18, 0x02, 0x20, 0x01, 0x28, 0x0c, 0x52, 0x10, - 0x6c, 0x65, 0x6e, 0x67, 0x74, 0x68, 0x43, 0x6f, 0x6d, 0x6d, 0x69, 0x74, 0x6d, 0x65, 0x6e, 0x74, - 0x12, 0x21, 0x0a, 0x0c, 0x6c, 0x65, 0x6e, 0x67, 0x74, 0x68, 0x5f, 0x70, 0x72, 0x6f, 0x6f, 0x66, - 0x18, 0x03, 0x20, 0x01, 0x28, 0x0c, 0x52, 0x0b, 0x6c, 0x65, 0x6e, 0x67, 0x74, 0x68, 0x50, 0x72, - 0x6f, 0x6f, 0x66, 0x12, 0x16, 0x0a, 0x06, 0x6c, 0x65, 0x6e, 0x67, 0x74, 0x68, 0x18, 0x04, 0x20, - 0x01, 0x28, 0x0d, 0x52, 0x06, 0x6c, 0x65, 0x6e, 0x67, 0x74, 0x68, 0x22, 0x52, 0x0a, 0x0e, 0x45, - 0x6e, 0x63, 0x6f, 0x64, 0x69, 0x6e, 0x67, 0x50, 0x61, 0x72, 0x61, 0x6d, 0x73, 0x12, 0x21, 0x0a, - 0x0c, 0x63, 0x68, 0x75, 0x6e, 0x6b, 0x5f, 0x6c, 0x65, 0x6e, 0x67, 0x74, 0x68, 0x18, 0x01, 0x20, - 0x01, 0x28, 0x0d, 0x52, 0x0b, 0x63, 0x68, 0x75, 0x6e, 0x6b, 0x4c, 0x65, 0x6e, 0x67, 0x74, 0x68, - 0x12, 0x1d, 0x0a, 0x0a, 0x6e, 0x75, 0x6d, 0x5f, 0x63, 0x68, 0x75, 0x6e, 0x6b, 0x73, 0x18, 0x02, - 0x20, 0x01, 0x28, 0x0d, 0x52, 0x09, 0x6e, 0x75, 0x6d, 0x43, 0x68, 0x75, 0x6e, 0x6b, 0x73, 0x22, - 0x69, 0x0a, 0x11, 0x45, 0x6e, 0x63, 0x6f, 0x64, 0x65, 0x42, 0x6c, 0x6f, 0x62, 0x52, 0x65, 0x71, - 0x75, 0x65, 0x73, 0x74, 0x12, 0x12, 0x0a, 0x04, 0x64, 0x61, 0x74, 0x61, 0x18, 0x01, 0x20, 0x01, - 0x28, 0x0c, 0x52, 0x04, 0x64, 0x61, 0x74, 0x61, 0x12, 0x40, 0x0a, 0x0f, 0x65, 0x6e, 0x63, 0x6f, - 0x64, 0x69, 0x6e, 0x67, 0x5f, 0x70, 0x61, 0x72, 0x61, 0x6d, 0x73, 0x18, 0x02, 0x20, 0x01, 0x28, - 0x0b, 0x32, 0x17, 0x2e, 0x65, 0x6e, 0x63, 0x6f, 0x64, 0x65, 0x72, 0x2e, 0x45, 0x6e, 0x63, 0x6f, - 0x64, 0x69, 0x6e, 0x67, 0x50, 0x61, 0x72, 0x61, 0x6d, 0x73, 0x52, 0x0e, 0x65, 0x6e, 0x63, 0x6f, - 0x64, 0x69, 0x6e, 0x67, 0x50, 0x61, 0x72, 0x61, 0x6d, 0x73, 0x22, 0xb4, 0x01, 0x0a, 0x0f, 0x45, - 0x6e, 0x63, 0x6f, 0x64, 0x65, 0x42, 0x6c, 0x6f, 0x62, 0x52, 0x65, 0x70, 0x6c, 0x79, 0x12, 0x37, - 0x0a, 0x0a, 0x63, 0x6f, 0x6d, 0x6d, 0x69, 0x74, 0x6d, 0x65, 0x6e, 0x74, 0x18, 0x01, 0x20, 0x01, - 0x28, 0x0b, 0x32, 0x17, 0x2e, 0x65, 0x6e, 0x63, 0x6f, 0x64, 0x65, 0x72, 0x2e, 0x42, 0x6c, 0x6f, - 0x62, 0x43, 0x6f, 0x6d, 0x6d, 0x69, 0x74, 0x6d, 0x65, 0x6e, 0x74, 0x52, 0x0a, 0x63, 0x6f, 0x6d, - 0x6d, 0x69, 0x74, 0x6d, 0x65, 0x6e, 0x74, 0x12, 0x16, 0x0a, 0x06, 0x63, 0x68, 0x75, 0x6e, 0x6b, - 0x73, 0x18, 0x02, 0x20, 0x03, 0x28, 0x0c, 0x52, 0x06, 0x63, 0x68, 0x75, 0x6e, 0x6b, 0x73, 0x12, - 0x50, 0x0a, 0x15, 0x63, 0x68, 0x75, 0x6e, 0x6b, 0x5f, 0x65, 0x6e, 0x63, 0x6f, 0x64, 0x69, 0x6e, - 0x67, 0x5f, 0x66, 0x6f, 0x72, 0x6d, 0x61, 0x74, 0x18, 0x03, 0x20, 0x01, 0x28, 0x0e, 0x32, 0x1c, - 0x2e, 0x65, 0x6e, 0x63, 0x6f, 0x64, 0x65, 0x72, 0x2e, 0x43, 0x68, 0x75, 0x6e, 0x6b, 0x45, 0x6e, - 0x63, 0x6f, 0x64, 0x69, 0x6e, 0x67, 0x46, 0x6f, 0x72, 0x6d, 0x61, 0x74, 0x52, 0x13, 0x63, 0x68, - 0x75, 0x6e, 0x6b, 0x45, 0x6e, 0x63, 0x6f, 0x64, 0x69, 0x6e, 0x67, 0x46, 0x6f, 0x72, 0x6d, 0x61, - 0x74, 0x2a, 0x36, 0x0a, 0x13, 0x43, 0x68, 0x75, 0x6e, 0x6b, 0x45, 0x6e, 0x63, 0x6f, 0x64, 0x69, - 0x6e, 0x67, 0x46, 0x6f, 0x72, 0x6d, 0x61, 0x74, 0x12, 0x0b, 0x0a, 0x07, 0x55, 0x4e, 0x4b, 0x4e, - 0x4f, 0x57, 0x4e, 0x10, 0x00, 0x12, 0x09, 0x0a, 0x05, 0x47, 0x4e, 0x41, 0x52, 0x4b, 0x10, 0x01, - 0x12, 0x07, 0x0a, 0x03, 0x47, 0x4f, 0x42, 0x10, 0x02, 0x32, 0x4f, 0x0a, 0x07, 0x45, 0x6e, 0x63, - 0x6f, 0x64, 0x65, 0x72, 0x12, 0x44, 0x0a, 0x0a, 0x45, 0x6e, 0x63, 0x6f, 0x64, 0x65, 0x42, 0x6c, - 0x6f, 0x62, 0x12, 0x1a, 0x2e, 0x65, 0x6e, 0x63, 0x6f, 0x64, 0x65, 0x72, 0x2e, 0x45, 0x6e, 0x63, - 0x6f, 0x64, 0x65, 0x42, 0x6c, 0x6f, 0x62, 0x52, 0x65, 0x71, 0x75, 0x65, 0x73, 0x74, 0x1a, 0x18, - 0x2e, 0x65, 0x6e, 0x63, 0x6f, 0x64, 0x65, 0x72, 0x2e, 0x45, 0x6e, 0x63, 0x6f, 0x64, 0x65, 0x42, - 0x6c, 0x6f, 0x62, 0x52, 0x65, 0x70, 0x6c, 0x79, 0x22, 0x00, 0x42, 0x2f, 0x5a, 0x2d, 0x67, 0x69, - 0x74, 0x68, 0x75, 0x62, 0x2e, 0x63, 0x6f, 0x6d, 0x2f, 0x4c, 0x61, 0x79, 0x72, 0x2d, 0x4c, 0x61, - 0x62, 0x73, 0x2f, 0x65, 0x69, 0x67, 0x65, 0x6e, 0x64, 0x61, 0x2f, 0x61, 0x70, 0x69, 0x2f, 0x67, - 0x72, 0x70, 0x63, 0x2f, 0x65, 0x6e, 0x63, 0x6f, 0x64, 0x65, 0x72, 0x62, 0x06, 0x70, 0x72, 0x6f, - 0x74, 0x6f, 0x33, -} - -var ( - file_encoder_encoder_proto_rawDescOnce sync.Once - file_encoder_encoder_proto_rawDescData = file_encoder_encoder_proto_rawDesc -) - -func file_encoder_encoder_proto_rawDescGZIP() []byte { - file_encoder_encoder_proto_rawDescOnce.Do(func() { - file_encoder_encoder_proto_rawDescData = protoimpl.X.CompressGZIP(file_encoder_encoder_proto_rawDescData) - }) - return file_encoder_encoder_proto_rawDescData -} - -var file_encoder_encoder_proto_enumTypes = make([]protoimpl.EnumInfo, 1) -var file_encoder_encoder_proto_msgTypes = make([]protoimpl.MessageInfo, 4) -var file_encoder_encoder_proto_goTypes = []interface{}{ - (ChunkEncodingFormat)(0), // 0: encoder.ChunkEncodingFormat - (*BlobCommitment)(nil), // 1: encoder.BlobCommitment - (*EncodingParams)(nil), // 2: encoder.EncodingParams - (*EncodeBlobRequest)(nil), // 3: encoder.EncodeBlobRequest - (*EncodeBlobReply)(nil), // 4: encoder.EncodeBlobReply -} -var file_encoder_encoder_proto_depIdxs = []int32{ - 2, // 0: encoder.EncodeBlobRequest.encoding_params:type_name -> encoder.EncodingParams - 1, // 1: encoder.EncodeBlobReply.commitment:type_name -> encoder.BlobCommitment - 0, // 2: encoder.EncodeBlobReply.chunk_encoding_format:type_name -> encoder.ChunkEncodingFormat - 3, // 3: encoder.Encoder.EncodeBlob:input_type -> encoder.EncodeBlobRequest - 4, // 4: encoder.Encoder.EncodeBlob:output_type -> encoder.EncodeBlobReply - 4, // [4:5] is the sub-list for method output_type - 3, // [3:4] is the sub-list for method input_type - 3, // [3:3] is the sub-list for extension type_name - 3, // [3:3] is the sub-list for extension extendee - 0, // [0:3] is the sub-list for field type_name -} - -func init() { file_encoder_encoder_proto_init() } -func file_encoder_encoder_proto_init() { - if File_encoder_encoder_proto != nil { - return - } - if !protoimpl.UnsafeEnabled { - file_encoder_encoder_proto_msgTypes[0].Exporter = func(v interface{}, i int) interface{} { - switch v := v.(*BlobCommitment); i { - case 0: - return &v.state - case 1: - return &v.sizeCache - case 2: - return &v.unknownFields - default: - return nil - } - } - file_encoder_encoder_proto_msgTypes[1].Exporter = func(v interface{}, i int) interface{} { - switch v := v.(*EncodingParams); i { - case 0: - return &v.state - case 1: - return &v.sizeCache - case 2: - return &v.unknownFields - default: - return nil - } - } - file_encoder_encoder_proto_msgTypes[2].Exporter = func(v interface{}, i int) interface{} { - switch v := v.(*EncodeBlobRequest); i { - case 0: - return &v.state - case 1: - return &v.sizeCache - case 2: - return &v.unknownFields - default: - return nil - } - } - file_encoder_encoder_proto_msgTypes[3].Exporter = func(v interface{}, i int) interface{} { - switch v := v.(*EncodeBlobReply); i { - case 0: - return &v.state - case 1: - return &v.sizeCache - case 2: - return &v.unknownFields - default: - return nil - } - } - } - type x struct{} - out := protoimpl.TypeBuilder{ - File: protoimpl.DescBuilder{ - GoPackagePath: reflect.TypeOf(x{}).PkgPath(), - RawDescriptor: file_encoder_encoder_proto_rawDesc, - NumEnums: 1, - NumMessages: 4, - NumExtensions: 0, - NumServices: 1, - }, - GoTypes: file_encoder_encoder_proto_goTypes, - DependencyIndexes: file_encoder_encoder_proto_depIdxs, - EnumInfos: file_encoder_encoder_proto_enumTypes, - MessageInfos: file_encoder_encoder_proto_msgTypes, - }.Build() - File_encoder_encoder_proto = out.File - file_encoder_encoder_proto_rawDesc = nil - file_encoder_encoder_proto_goTypes = nil - file_encoder_encoder_proto_depIdxs = nil -} diff --git a/disperser/api/grpc/encoder/encoder_grpc.pb.go b/disperser/api/grpc/encoder/encoder_grpc.pb.go deleted file mode 100644 index 76285b6a2c..0000000000 --- a/disperser/api/grpc/encoder/encoder_grpc.pb.go +++ /dev/null @@ -1,109 +0,0 @@ -// Code generated by protoc-gen-go-grpc. DO NOT EDIT. -// versions: -// - protoc-gen-go-grpc v1.3.0 -// - protoc v4.23.4 -// source: encoder/encoder.proto - -package encoder - -import ( - context "context" - grpc "google.golang.org/grpc" - codes "google.golang.org/grpc/codes" - status "google.golang.org/grpc/status" -) - -// This is a compile-time assertion to ensure that this generated file -// is compatible with the grpc package it is being compiled against. -// Requires gRPC-Go v1.32.0 or later. -const _ = grpc.SupportPackageIsVersion7 - -const ( - Encoder_EncodeBlob_FullMethodName = "/encoder.Encoder/EncodeBlob" -) - -// EncoderClient is the client API for Encoder service. -// -// For semantics around ctx use and closing/ending streaming RPCs, please refer to https://pkg.go.dev/google.golang.org/grpc/?tab=doc#ClientConn.NewStream. -type EncoderClient interface { - EncodeBlob(ctx context.Context, in *EncodeBlobRequest, opts ...grpc.CallOption) (*EncodeBlobReply, error) -} - -type encoderClient struct { - cc grpc.ClientConnInterface -} - -func NewEncoderClient(cc grpc.ClientConnInterface) EncoderClient { - return &encoderClient{cc} -} - -func (c *encoderClient) EncodeBlob(ctx context.Context, in *EncodeBlobRequest, opts ...grpc.CallOption) (*EncodeBlobReply, error) { - out := new(EncodeBlobReply) - err := c.cc.Invoke(ctx, Encoder_EncodeBlob_FullMethodName, in, out, opts...) - if err != nil { - return nil, err - } - return out, nil -} - -// EncoderServer is the server API for Encoder service. -// All implementations must embed UnimplementedEncoderServer -// for forward compatibility -type EncoderServer interface { - EncodeBlob(context.Context, *EncodeBlobRequest) (*EncodeBlobReply, error) - mustEmbedUnimplementedEncoderServer() -} - -// UnimplementedEncoderServer must be embedded to have forward compatible implementations. -type UnimplementedEncoderServer struct { -} - -func (UnimplementedEncoderServer) EncodeBlob(context.Context, *EncodeBlobRequest) (*EncodeBlobReply, error) { - return nil, status.Errorf(codes.Unimplemented, "method EncodeBlob not implemented") -} -func (UnimplementedEncoderServer) mustEmbedUnimplementedEncoderServer() {} - -// UnsafeEncoderServer may be embedded to opt out of forward compatibility for this service. -// Use of this interface is not recommended, as added methods to EncoderServer will -// result in compilation errors. -type UnsafeEncoderServer interface { - mustEmbedUnimplementedEncoderServer() -} - -func RegisterEncoderServer(s grpc.ServiceRegistrar, srv EncoderServer) { - s.RegisterService(&Encoder_ServiceDesc, srv) -} - -func _Encoder_EncodeBlob_Handler(srv interface{}, ctx context.Context, dec func(interface{}) error, interceptor grpc.UnaryServerInterceptor) (interface{}, error) { - in := new(EncodeBlobRequest) - if err := dec(in); err != nil { - return nil, err - } - if interceptor == nil { - return srv.(EncoderServer).EncodeBlob(ctx, in) - } - info := &grpc.UnaryServerInfo{ - Server: srv, - FullMethod: Encoder_EncodeBlob_FullMethodName, - } - handler := func(ctx context.Context, req interface{}) (interface{}, error) { - return srv.(EncoderServer).EncodeBlob(ctx, req.(*EncodeBlobRequest)) - } - return interceptor(ctx, in, info, handler) -} - -// Encoder_ServiceDesc is the grpc.ServiceDesc for Encoder service. -// It's only intended for direct use with grpc.RegisterService, -// and not to be introspected or modified (even as a copy) -var Encoder_ServiceDesc = grpc.ServiceDesc{ - ServiceName: "encoder.Encoder", - HandlerType: (*EncoderServer)(nil), - Methods: []grpc.MethodDesc{ - { - MethodName: "EncodeBlob", - Handler: _Encoder_EncodeBlob_Handler, - }, - }, - Streams: []grpc.StreamDesc{}, - Metadata: "encoder/encoder.proto", -} diff --git a/disperser/api/grpc/encoder/v2/encoder.pb.go b/disperser/api/grpc/encoder/v2/encoder.pb.go deleted file mode 100644 index 182c97bfc9..0000000000 --- a/disperser/api/grpc/encoder/v2/encoder.pb.go +++ /dev/null @@ -1,386 +0,0 @@ -// Code generated by protoc-gen-go. DO NOT EDIT. -// versions: -// protoc-gen-go v1.28.1 -// protoc v4.23.4 -// source: encoder/v2/encoder.proto - -package v2 - -import ( - protoreflect "google.golang.org/protobuf/reflect/protoreflect" - protoimpl "google.golang.org/protobuf/runtime/protoimpl" - reflect "reflect" - sync "sync" -) - -const ( - // Verify that this generated code is sufficiently up-to-date. - _ = protoimpl.EnforceVersion(20 - protoimpl.MinVersion) - // Verify that runtime/protoimpl is sufficiently up-to-date. - _ = protoimpl.EnforceVersion(protoimpl.MaxVersion - 20) -) - -// EncodeBlobRequest contains the reference to the blob to be encoded and the encoding parameters -// determined by the control plane. -type EncodeBlobRequest struct { - state protoimpl.MessageState - sizeCache protoimpl.SizeCache - unknownFields protoimpl.UnknownFields - - BlobKey []byte `protobuf:"bytes,1,opt,name=blob_key,json=blobKey,proto3" json:"blob_key,omitempty"` - EncodingParams *EncodingParams `protobuf:"bytes,2,opt,name=encoding_params,json=encodingParams,proto3" json:"encoding_params,omitempty"` -} - -func (x *EncodeBlobRequest) Reset() { - *x = EncodeBlobRequest{} - if protoimpl.UnsafeEnabled { - mi := &file_encoder_v2_encoder_proto_msgTypes[0] - ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) - ms.StoreMessageInfo(mi) - } -} - -func (x *EncodeBlobRequest) String() string { - return protoimpl.X.MessageStringOf(x) -} - -func (*EncodeBlobRequest) ProtoMessage() {} - -func (x *EncodeBlobRequest) ProtoReflect() protoreflect.Message { - mi := &file_encoder_v2_encoder_proto_msgTypes[0] - if protoimpl.UnsafeEnabled && x != nil { - ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) - if ms.LoadMessageInfo() == nil { - ms.StoreMessageInfo(mi) - } - return ms - } - return mi.MessageOf(x) -} - -// Deprecated: Use EncodeBlobRequest.ProtoReflect.Descriptor instead. -func (*EncodeBlobRequest) Descriptor() ([]byte, []int) { - return file_encoder_v2_encoder_proto_rawDescGZIP(), []int{0} -} - -func (x *EncodeBlobRequest) GetBlobKey() []byte { - if x != nil { - return x.BlobKey - } - return nil -} - -func (x *EncodeBlobRequest) GetEncodingParams() *EncodingParams { - if x != nil { - return x.EncodingParams - } - return nil -} - -// EncodingParams specifies how the blob should be encoded into chunks -type EncodingParams struct { - state protoimpl.MessageState - sizeCache protoimpl.SizeCache - unknownFields protoimpl.UnknownFields - - ChunkLength uint64 `protobuf:"varint,1,opt,name=chunk_length,json=chunkLength,proto3" json:"chunk_length,omitempty"` - NumChunks uint64 `protobuf:"varint,2,opt,name=num_chunks,json=numChunks,proto3" json:"num_chunks,omitempty"` -} - -func (x *EncodingParams) Reset() { - *x = EncodingParams{} - if protoimpl.UnsafeEnabled { - mi := &file_encoder_v2_encoder_proto_msgTypes[1] - ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) - ms.StoreMessageInfo(mi) - } -} - -func (x *EncodingParams) String() string { - return protoimpl.X.MessageStringOf(x) -} - -func (*EncodingParams) ProtoMessage() {} - -func (x *EncodingParams) ProtoReflect() protoreflect.Message { - mi := &file_encoder_v2_encoder_proto_msgTypes[1] - if protoimpl.UnsafeEnabled && x != nil { - ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) - if ms.LoadMessageInfo() == nil { - ms.StoreMessageInfo(mi) - } - return ms - } - return mi.MessageOf(x) -} - -// Deprecated: Use EncodingParams.ProtoReflect.Descriptor instead. -func (*EncodingParams) Descriptor() ([]byte, []int) { - return file_encoder_v2_encoder_proto_rawDescGZIP(), []int{1} -} - -func (x *EncodingParams) GetChunkLength() uint64 { - if x != nil { - return x.ChunkLength - } - return 0 -} - -func (x *EncodingParams) GetNumChunks() uint64 { - if x != nil { - return x.NumChunks - } - return 0 -} - -// FragmentInfo contains metadata about the encoded fragments -type FragmentInfo struct { - state protoimpl.MessageState - sizeCache protoimpl.SizeCache - unknownFields protoimpl.UnknownFields - - TotalChunkSizeBytes uint32 `protobuf:"varint,1,opt,name=total_chunk_size_bytes,json=totalChunkSizeBytes,proto3" json:"total_chunk_size_bytes,omitempty"` - FragmentSizeBytes uint32 `protobuf:"varint,2,opt,name=fragment_size_bytes,json=fragmentSizeBytes,proto3" json:"fragment_size_bytes,omitempty"` -} - -func (x *FragmentInfo) Reset() { - *x = FragmentInfo{} - if protoimpl.UnsafeEnabled { - mi := &file_encoder_v2_encoder_proto_msgTypes[2] - ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) - ms.StoreMessageInfo(mi) - } -} - -func (x *FragmentInfo) String() string { - return protoimpl.X.MessageStringOf(x) -} - -func (*FragmentInfo) ProtoMessage() {} - -func (x *FragmentInfo) ProtoReflect() protoreflect.Message { - mi := &file_encoder_v2_encoder_proto_msgTypes[2] - if protoimpl.UnsafeEnabled && x != nil { - ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) - if ms.LoadMessageInfo() == nil { - ms.StoreMessageInfo(mi) - } - return ms - } - return mi.MessageOf(x) -} - -// Deprecated: Use FragmentInfo.ProtoReflect.Descriptor instead. -func (*FragmentInfo) Descriptor() ([]byte, []int) { - return file_encoder_v2_encoder_proto_rawDescGZIP(), []int{2} -} - -func (x *FragmentInfo) GetTotalChunkSizeBytes() uint32 { - if x != nil { - return x.TotalChunkSizeBytes - } - return 0 -} - -func (x *FragmentInfo) GetFragmentSizeBytes() uint32 { - if x != nil { - return x.FragmentSizeBytes - } - return 0 -} - -// EncodeBlobReply contains metadata about the encoded chunks -type EncodeBlobReply struct { - state protoimpl.MessageState - sizeCache protoimpl.SizeCache - unknownFields protoimpl.UnknownFields - - FragmentInfo *FragmentInfo `protobuf:"bytes,1,opt,name=fragment_info,json=fragmentInfo,proto3" json:"fragment_info,omitempty"` -} - -func (x *EncodeBlobReply) Reset() { - *x = EncodeBlobReply{} - if protoimpl.UnsafeEnabled { - mi := &file_encoder_v2_encoder_proto_msgTypes[3] - ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) - ms.StoreMessageInfo(mi) - } -} - -func (x *EncodeBlobReply) String() string { - return protoimpl.X.MessageStringOf(x) -} - -func (*EncodeBlobReply) ProtoMessage() {} - -func (x *EncodeBlobReply) ProtoReflect() protoreflect.Message { - mi := &file_encoder_v2_encoder_proto_msgTypes[3] - if protoimpl.UnsafeEnabled && x != nil { - ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) - if ms.LoadMessageInfo() == nil { - ms.StoreMessageInfo(mi) - } - return ms - } - return mi.MessageOf(x) -} - -// Deprecated: Use EncodeBlobReply.ProtoReflect.Descriptor instead. -func (*EncodeBlobReply) Descriptor() ([]byte, []int) { - return file_encoder_v2_encoder_proto_rawDescGZIP(), []int{3} -} - -func (x *EncodeBlobReply) GetFragmentInfo() *FragmentInfo { - if x != nil { - return x.FragmentInfo - } - return nil -} - -var File_encoder_v2_encoder_proto protoreflect.FileDescriptor - -var file_encoder_v2_encoder_proto_rawDesc = []byte{ - 0x0a, 0x18, 0x65, 0x6e, 0x63, 0x6f, 0x64, 0x65, 0x72, 0x2f, 0x76, 0x32, 0x2f, 0x65, 0x6e, 0x63, - 0x6f, 0x64, 0x65, 0x72, 0x2e, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x12, 0x0a, 0x65, 0x6e, 0x63, 0x6f, - 0x64, 0x65, 0x72, 0x2e, 0x76, 0x32, 0x22, 0x73, 0x0a, 0x11, 0x45, 0x6e, 0x63, 0x6f, 0x64, 0x65, - 0x42, 0x6c, 0x6f, 0x62, 0x52, 0x65, 0x71, 0x75, 0x65, 0x73, 0x74, 0x12, 0x19, 0x0a, 0x08, 0x62, - 0x6c, 0x6f, 0x62, 0x5f, 0x6b, 0x65, 0x79, 0x18, 0x01, 0x20, 0x01, 0x28, 0x0c, 0x52, 0x07, 0x62, - 0x6c, 0x6f, 0x62, 0x4b, 0x65, 0x79, 0x12, 0x43, 0x0a, 0x0f, 0x65, 0x6e, 0x63, 0x6f, 0x64, 0x69, - 0x6e, 0x67, 0x5f, 0x70, 0x61, 0x72, 0x61, 0x6d, 0x73, 0x18, 0x02, 0x20, 0x01, 0x28, 0x0b, 0x32, - 0x1a, 0x2e, 0x65, 0x6e, 0x63, 0x6f, 0x64, 0x65, 0x72, 0x2e, 0x76, 0x32, 0x2e, 0x45, 0x6e, 0x63, - 0x6f, 0x64, 0x69, 0x6e, 0x67, 0x50, 0x61, 0x72, 0x61, 0x6d, 0x73, 0x52, 0x0e, 0x65, 0x6e, 0x63, - 0x6f, 0x64, 0x69, 0x6e, 0x67, 0x50, 0x61, 0x72, 0x61, 0x6d, 0x73, 0x22, 0x52, 0x0a, 0x0e, 0x45, - 0x6e, 0x63, 0x6f, 0x64, 0x69, 0x6e, 0x67, 0x50, 0x61, 0x72, 0x61, 0x6d, 0x73, 0x12, 0x21, 0x0a, - 0x0c, 0x63, 0x68, 0x75, 0x6e, 0x6b, 0x5f, 0x6c, 0x65, 0x6e, 0x67, 0x74, 0x68, 0x18, 0x01, 0x20, - 0x01, 0x28, 0x04, 0x52, 0x0b, 0x63, 0x68, 0x75, 0x6e, 0x6b, 0x4c, 0x65, 0x6e, 0x67, 0x74, 0x68, - 0x12, 0x1d, 0x0a, 0x0a, 0x6e, 0x75, 0x6d, 0x5f, 0x63, 0x68, 0x75, 0x6e, 0x6b, 0x73, 0x18, 0x02, - 0x20, 0x01, 0x28, 0x04, 0x52, 0x09, 0x6e, 0x75, 0x6d, 0x43, 0x68, 0x75, 0x6e, 0x6b, 0x73, 0x22, - 0x73, 0x0a, 0x0c, 0x46, 0x72, 0x61, 0x67, 0x6d, 0x65, 0x6e, 0x74, 0x49, 0x6e, 0x66, 0x6f, 0x12, - 0x33, 0x0a, 0x16, 0x74, 0x6f, 0x74, 0x61, 0x6c, 0x5f, 0x63, 0x68, 0x75, 0x6e, 0x6b, 0x5f, 0x73, - 0x69, 0x7a, 0x65, 0x5f, 0x62, 0x79, 0x74, 0x65, 0x73, 0x18, 0x01, 0x20, 0x01, 0x28, 0x0d, 0x52, - 0x13, 0x74, 0x6f, 0x74, 0x61, 0x6c, 0x43, 0x68, 0x75, 0x6e, 0x6b, 0x53, 0x69, 0x7a, 0x65, 0x42, - 0x79, 0x74, 0x65, 0x73, 0x12, 0x2e, 0x0a, 0x13, 0x66, 0x72, 0x61, 0x67, 0x6d, 0x65, 0x6e, 0x74, - 0x5f, 0x73, 0x69, 0x7a, 0x65, 0x5f, 0x62, 0x79, 0x74, 0x65, 0x73, 0x18, 0x02, 0x20, 0x01, 0x28, - 0x0d, 0x52, 0x11, 0x66, 0x72, 0x61, 0x67, 0x6d, 0x65, 0x6e, 0x74, 0x53, 0x69, 0x7a, 0x65, 0x42, - 0x79, 0x74, 0x65, 0x73, 0x22, 0x50, 0x0a, 0x0f, 0x45, 0x6e, 0x63, 0x6f, 0x64, 0x65, 0x42, 0x6c, - 0x6f, 0x62, 0x52, 0x65, 0x70, 0x6c, 0x79, 0x12, 0x3d, 0x0a, 0x0d, 0x66, 0x72, 0x61, 0x67, 0x6d, - 0x65, 0x6e, 0x74, 0x5f, 0x69, 0x6e, 0x66, 0x6f, 0x18, 0x01, 0x20, 0x01, 0x28, 0x0b, 0x32, 0x18, - 0x2e, 0x65, 0x6e, 0x63, 0x6f, 0x64, 0x65, 0x72, 0x2e, 0x76, 0x32, 0x2e, 0x46, 0x72, 0x61, 0x67, - 0x6d, 0x65, 0x6e, 0x74, 0x49, 0x6e, 0x66, 0x6f, 0x52, 0x0c, 0x66, 0x72, 0x61, 0x67, 0x6d, 0x65, - 0x6e, 0x74, 0x49, 0x6e, 0x66, 0x6f, 0x32, 0x55, 0x0a, 0x07, 0x45, 0x6e, 0x63, 0x6f, 0x64, 0x65, - 0x72, 0x12, 0x4a, 0x0a, 0x0a, 0x45, 0x6e, 0x63, 0x6f, 0x64, 0x65, 0x42, 0x6c, 0x6f, 0x62, 0x12, - 0x1d, 0x2e, 0x65, 0x6e, 0x63, 0x6f, 0x64, 0x65, 0x72, 0x2e, 0x76, 0x32, 0x2e, 0x45, 0x6e, 0x63, - 0x6f, 0x64, 0x65, 0x42, 0x6c, 0x6f, 0x62, 0x52, 0x65, 0x71, 0x75, 0x65, 0x73, 0x74, 0x1a, 0x1b, - 0x2e, 0x65, 0x6e, 0x63, 0x6f, 0x64, 0x65, 0x72, 0x2e, 0x76, 0x32, 0x2e, 0x45, 0x6e, 0x63, 0x6f, - 0x64, 0x65, 0x42, 0x6c, 0x6f, 0x62, 0x52, 0x65, 0x70, 0x6c, 0x79, 0x22, 0x00, 0x42, 0x32, 0x5a, - 0x30, 0x67, 0x69, 0x74, 0x68, 0x75, 0x62, 0x2e, 0x63, 0x6f, 0x6d, 0x2f, 0x4c, 0x61, 0x79, 0x72, - 0x2d, 0x4c, 0x61, 0x62, 0x73, 0x2f, 0x65, 0x69, 0x67, 0x65, 0x6e, 0x64, 0x61, 0x2f, 0x61, 0x70, - 0x69, 0x2f, 0x67, 0x72, 0x70, 0x63, 0x2f, 0x65, 0x6e, 0x63, 0x6f, 0x64, 0x65, 0x72, 0x2f, 0x76, - 0x32, 0x62, 0x06, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x33, -} - -var ( - file_encoder_v2_encoder_proto_rawDescOnce sync.Once - file_encoder_v2_encoder_proto_rawDescData = file_encoder_v2_encoder_proto_rawDesc -) - -func file_encoder_v2_encoder_proto_rawDescGZIP() []byte { - file_encoder_v2_encoder_proto_rawDescOnce.Do(func() { - file_encoder_v2_encoder_proto_rawDescData = protoimpl.X.CompressGZIP(file_encoder_v2_encoder_proto_rawDescData) - }) - return file_encoder_v2_encoder_proto_rawDescData -} - -var file_encoder_v2_encoder_proto_msgTypes = make([]protoimpl.MessageInfo, 4) -var file_encoder_v2_encoder_proto_goTypes = []interface{}{ - (*EncodeBlobRequest)(nil), // 0: encoder.v2.EncodeBlobRequest - (*EncodingParams)(nil), // 1: encoder.v2.EncodingParams - (*FragmentInfo)(nil), // 2: encoder.v2.FragmentInfo - (*EncodeBlobReply)(nil), // 3: encoder.v2.EncodeBlobReply -} -var file_encoder_v2_encoder_proto_depIdxs = []int32{ - 1, // 0: encoder.v2.EncodeBlobRequest.encoding_params:type_name -> encoder.v2.EncodingParams - 2, // 1: encoder.v2.EncodeBlobReply.fragment_info:type_name -> encoder.v2.FragmentInfo - 0, // 2: encoder.v2.Encoder.EncodeBlob:input_type -> encoder.v2.EncodeBlobRequest - 3, // 3: encoder.v2.Encoder.EncodeBlob:output_type -> encoder.v2.EncodeBlobReply - 3, // [3:4] is the sub-list for method output_type - 2, // [2:3] is the sub-list for method input_type - 2, // [2:2] is the sub-list for extension type_name - 2, // [2:2] is the sub-list for extension extendee - 0, // [0:2] is the sub-list for field type_name -} - -func init() { file_encoder_v2_encoder_proto_init() } -func file_encoder_v2_encoder_proto_init() { - if File_encoder_v2_encoder_proto != nil { - return - } - if !protoimpl.UnsafeEnabled { - file_encoder_v2_encoder_proto_msgTypes[0].Exporter = func(v interface{}, i int) interface{} { - switch v := v.(*EncodeBlobRequest); i { - case 0: - return &v.state - case 1: - return &v.sizeCache - case 2: - return &v.unknownFields - default: - return nil - } - } - file_encoder_v2_encoder_proto_msgTypes[1].Exporter = func(v interface{}, i int) interface{} { - switch v := v.(*EncodingParams); i { - case 0: - return &v.state - case 1: - return &v.sizeCache - case 2: - return &v.unknownFields - default: - return nil - } - } - file_encoder_v2_encoder_proto_msgTypes[2].Exporter = func(v interface{}, i int) interface{} { - switch v := v.(*FragmentInfo); i { - case 0: - return &v.state - case 1: - return &v.sizeCache - case 2: - return &v.unknownFields - default: - return nil - } - } - file_encoder_v2_encoder_proto_msgTypes[3].Exporter = func(v interface{}, i int) interface{} { - switch v := v.(*EncodeBlobReply); i { - case 0: - return &v.state - case 1: - return &v.sizeCache - case 2: - return &v.unknownFields - default: - return nil - } - } - } - type x struct{} - out := protoimpl.TypeBuilder{ - File: protoimpl.DescBuilder{ - GoPackagePath: reflect.TypeOf(x{}).PkgPath(), - RawDescriptor: file_encoder_v2_encoder_proto_rawDesc, - NumEnums: 0, - NumMessages: 4, - NumExtensions: 0, - NumServices: 1, - }, - GoTypes: file_encoder_v2_encoder_proto_goTypes, - DependencyIndexes: file_encoder_v2_encoder_proto_depIdxs, - MessageInfos: file_encoder_v2_encoder_proto_msgTypes, - }.Build() - File_encoder_v2_encoder_proto = out.File - file_encoder_v2_encoder_proto_rawDesc = nil - file_encoder_v2_encoder_proto_goTypes = nil - file_encoder_v2_encoder_proto_depIdxs = nil -} diff --git a/disperser/api/grpc/encoder/v2/encoder_grpc.pb.go b/disperser/api/grpc/encoder/v2/encoder_grpc.pb.go deleted file mode 100644 index dae8a78bcf..0000000000 --- a/disperser/api/grpc/encoder/v2/encoder_grpc.pb.go +++ /dev/null @@ -1,115 +0,0 @@ -// Code generated by protoc-gen-go-grpc. DO NOT EDIT. -// versions: -// - protoc-gen-go-grpc v1.3.0 -// - protoc v4.23.4 -// source: encoder/v2/encoder.proto - -package v2 - -import ( - context "context" - grpc "google.golang.org/grpc" - codes "google.golang.org/grpc/codes" - status "google.golang.org/grpc/status" -) - -// This is a compile-time assertion to ensure that this generated file -// is compatible with the grpc package it is being compiled against. -// Requires gRPC-Go v1.32.0 or later. -const _ = grpc.SupportPackageIsVersion7 - -const ( - Encoder_EncodeBlob_FullMethodName = "/encoder.v2.Encoder/EncodeBlob" -) - -// EncoderClient is the client API for Encoder service. -// -// For semantics around ctx use and closing/ending streaming RPCs, please refer to https://pkg.go.dev/google.golang.org/grpc/?tab=doc#ClientConn.NewStream. -type EncoderClient interface { - // EncodeBlob encodes a blob into chunks using specified encoding parameters. - // The blob is retrieved using the provided blob key and the encoded chunks - // are persisted for later retrieval. - EncodeBlob(ctx context.Context, in *EncodeBlobRequest, opts ...grpc.CallOption) (*EncodeBlobReply, error) -} - -type encoderClient struct { - cc grpc.ClientConnInterface -} - -func NewEncoderClient(cc grpc.ClientConnInterface) EncoderClient { - return &encoderClient{cc} -} - -func (c *encoderClient) EncodeBlob(ctx context.Context, in *EncodeBlobRequest, opts ...grpc.CallOption) (*EncodeBlobReply, error) { - out := new(EncodeBlobReply) - err := c.cc.Invoke(ctx, Encoder_EncodeBlob_FullMethodName, in, out, opts...) - if err != nil { - return nil, err - } - return out, nil -} - -// EncoderServer is the server API for Encoder service. -// All implementations must embed UnimplementedEncoderServer -// for forward compatibility -type EncoderServer interface { - // EncodeBlob encodes a blob into chunks using specified encoding parameters. - // The blob is retrieved using the provided blob key and the encoded chunks - // are persisted for later retrieval. - EncodeBlob(context.Context, *EncodeBlobRequest) (*EncodeBlobReply, error) - mustEmbedUnimplementedEncoderServer() -} - -// UnimplementedEncoderServer must be embedded to have forward compatible implementations. -type UnimplementedEncoderServer struct { -} - -func (UnimplementedEncoderServer) EncodeBlob(context.Context, *EncodeBlobRequest) (*EncodeBlobReply, error) { - return nil, status.Errorf(codes.Unimplemented, "method EncodeBlob not implemented") -} -func (UnimplementedEncoderServer) mustEmbedUnimplementedEncoderServer() {} - -// UnsafeEncoderServer may be embedded to opt out of forward compatibility for this service. -// Use of this interface is not recommended, as added methods to EncoderServer will -// result in compilation errors. -type UnsafeEncoderServer interface { - mustEmbedUnimplementedEncoderServer() -} - -func RegisterEncoderServer(s grpc.ServiceRegistrar, srv EncoderServer) { - s.RegisterService(&Encoder_ServiceDesc, srv) -} - -func _Encoder_EncodeBlob_Handler(srv interface{}, ctx context.Context, dec func(interface{}) error, interceptor grpc.UnaryServerInterceptor) (interface{}, error) { - in := new(EncodeBlobRequest) - if err := dec(in); err != nil { - return nil, err - } - if interceptor == nil { - return srv.(EncoderServer).EncodeBlob(ctx, in) - } - info := &grpc.UnaryServerInfo{ - Server: srv, - FullMethod: Encoder_EncodeBlob_FullMethodName, - } - handler := func(ctx context.Context, req interface{}) (interface{}, error) { - return srv.(EncoderServer).EncodeBlob(ctx, req.(*EncodeBlobRequest)) - } - return interceptor(ctx, in, info, handler) -} - -// Encoder_ServiceDesc is the grpc.ServiceDesc for Encoder service. -// It's only intended for direct use with grpc.RegisterService, -// and not to be introspected or modified (even as a copy) -var Encoder_ServiceDesc = grpc.ServiceDesc{ - ServiceName: "encoder.v2.Encoder", - HandlerType: (*EncoderServer)(nil), - Methods: []grpc.MethodDesc{ - { - MethodName: "EncodeBlob", - Handler: _Encoder_EncodeBlob_Handler, - }, - }, - Streams: []grpc.StreamDesc{}, - Metadata: "encoder/v2/encoder.proto", -} diff --git a/disperser/apiserver/server_v2.go b/disperser/apiserver/server_v2.go index 435b99d318..cb96f8b40f 100644 --- a/disperser/apiserver/server_v2.go +++ b/disperser/apiserver/server_v2.go @@ -266,9 +266,10 @@ func (s *DispersalServerV2) GetPaymentState(ctx context.Context, req *pb.GetPaym for i, v := range reservation.QuorumNumbers { quorumNumbers[i] = uint32(v) } - quorumSplit := make([]uint32, len(reservation.QuorumSplit)) - for i, v := range reservation.QuorumSplit { - quorumSplit[i] = uint32(v) + + quorumSplits := make([]uint32, len(reservation.QuorumSplits)) + for i, v := range reservation.QuorumSplits { + quorumSplits[i] = uint32(v) } // build reply reply := &pb.GetPaymentStateReply{ @@ -279,7 +280,7 @@ func (s *DispersalServerV2) GetPaymentState(ctx context.Context, req *pb.GetPaym StartTimestamp: uint32(reservation.StartTimestamp), EndTimestamp: uint32(reservation.EndTimestamp), QuorumNumbers: quorumNumbers, - QuorumSplit: quorumSplit, + QuorumSplits: quorumSplits, }, CumulativePayment: largestCumulativePayment.Bytes(), OnchainCumulativePayment: onDemandPayment.CumulativePayment.Bytes(), From 7e9d37ee344105ccfbff5dfb092d43d32b6a8206 Mon Sep 17 00:00:00 2001 From: hopeyen Date: Fri, 6 Dec 2024 12:58:08 -0800 Subject: [PATCH 14/18] fix: proto gen --- api/docs/disperser_v2.html | 2 +- api/docs/disperser_v2.md | 2 +- api/docs/eigenda-protos.html | 2 +- api/docs/eigenda-protos.md | 2 +- disperser/api/grpc/encoder/encoder.pb.go | 484 ++++++++++++++++++ disperser/api/grpc/encoder/encoder_grpc.pb.go | 109 ++++ disperser/api/grpc/encoder/v2/encoder.pb.go | 386 ++++++++++++++ .../api/grpc/encoder/v2/encoder_grpc.pb.go | 115 +++++ 8 files changed, 1098 insertions(+), 4 deletions(-) create mode 100644 disperser/api/grpc/encoder/encoder.pb.go create mode 100644 disperser/api/grpc/encoder/encoder_grpc.pb.go create mode 100644 disperser/api/grpc/encoder/v2/encoder.pb.go create mode 100644 disperser/api/grpc/encoder/v2/encoder_grpc.pb.go diff --git a/api/docs/disperser_v2.html b/api/docs/disperser_v2.html index 02c6ea22c8..168ceeaf09 100644 --- a/api/docs/disperser_v2.html +++ b/api/docs/disperser_v2.html @@ -733,7 +733,7 @@

Reservation

- quorum_split + quorum_splits uint32 repeated

diff --git a/api/docs/disperser_v2.md b/api/docs/disperser_v2.md index 5b987d96f2..7c02307bc5 100644 --- a/api/docs/disperser_v2.md +++ b/api/docs/disperser_v2.md @@ -248,7 +248,7 @@ GetPaymentStateRequest contains parameters to query the payment state of an acco | start_timestamp | [uint32](#uint32) | | | | end_timestamp | [uint32](#uint32) | | | | quorum_numbers | [uint32](#uint32) | repeated | | -| quorum_split | [uint32](#uint32) | repeated | | +| quorum_splits | [uint32](#uint32) | repeated | | diff --git a/api/docs/eigenda-protos.html b/api/docs/eigenda-protos.html index 9f1c0c1c9a..7ffceec025 100644 --- a/api/docs/eigenda-protos.html +++ b/api/docs/eigenda-protos.html @@ -2396,7 +2396,7 @@

Reservation

- quorum_split + quorum_splits uint32 repeated

diff --git a/api/docs/eigenda-protos.md b/api/docs/eigenda-protos.md index 8b4992a428..fa357e9df0 100644 --- a/api/docs/eigenda-protos.md +++ b/api/docs/eigenda-protos.md @@ -949,7 +949,7 @@ GetPaymentStateRequest contains parameters to query the payment state of an acco | start_timestamp | [uint32](#uint32) | | | | end_timestamp | [uint32](#uint32) | | | | quorum_numbers | [uint32](#uint32) | repeated | | -| quorum_split | [uint32](#uint32) | repeated | | +| quorum_splits | [uint32](#uint32) | repeated | | diff --git a/disperser/api/grpc/encoder/encoder.pb.go b/disperser/api/grpc/encoder/encoder.pb.go new file mode 100644 index 0000000000..63acf6b36c --- /dev/null +++ b/disperser/api/grpc/encoder/encoder.pb.go @@ -0,0 +1,484 @@ +// Code generated by protoc-gen-go. DO NOT EDIT. +// versions: +// protoc-gen-go v1.28.1 +// protoc v4.23.4 +// source: encoder/encoder.proto + +package encoder + +import ( + protoreflect "google.golang.org/protobuf/reflect/protoreflect" + protoimpl "google.golang.org/protobuf/runtime/protoimpl" + reflect "reflect" + sync "sync" +) + +const ( + // Verify that this generated code is sufficiently up-to-date. + _ = protoimpl.EnforceVersion(20 - protoimpl.MinVersion) + // Verify that runtime/protoimpl is sufficiently up-to-date. + _ = protoimpl.EnforceVersion(protoimpl.MaxVersion - 20) +) + +type ChunkEncodingFormat int32 + +const ( + ChunkEncodingFormat_UNKNOWN ChunkEncodingFormat = 0 + ChunkEncodingFormat_GNARK ChunkEncodingFormat = 1 + ChunkEncodingFormat_GOB ChunkEncodingFormat = 2 +) + +// Enum value maps for ChunkEncodingFormat. +var ( + ChunkEncodingFormat_name = map[int32]string{ + 0: "UNKNOWN", + 1: "GNARK", + 2: "GOB", + } + ChunkEncodingFormat_value = map[string]int32{ + "UNKNOWN": 0, + "GNARK": 1, + "GOB": 2, + } +) + +func (x ChunkEncodingFormat) Enum() *ChunkEncodingFormat { + p := new(ChunkEncodingFormat) + *p = x + return p +} + +func (x ChunkEncodingFormat) String() string { + return protoimpl.X.EnumStringOf(x.Descriptor(), protoreflect.EnumNumber(x)) +} + +func (ChunkEncodingFormat) Descriptor() protoreflect.EnumDescriptor { + return file_encoder_encoder_proto_enumTypes[0].Descriptor() +} + +func (ChunkEncodingFormat) Type() protoreflect.EnumType { + return &file_encoder_encoder_proto_enumTypes[0] +} + +func (x ChunkEncodingFormat) Number() protoreflect.EnumNumber { + return protoreflect.EnumNumber(x) +} + +// Deprecated: Use ChunkEncodingFormat.Descriptor instead. +func (ChunkEncodingFormat) EnumDescriptor() ([]byte, []int) { + return file_encoder_encoder_proto_rawDescGZIP(), []int{0} +} + +// BlobCommitments contains the blob's commitment, degree proof, and the actual degree +// DEPRECATED: use common.BlobCommitment instead +type BlobCommitment struct { + state protoimpl.MessageState + sizeCache protoimpl.SizeCache + unknownFields protoimpl.UnknownFields + + Commitment []byte `protobuf:"bytes,1,opt,name=commitment,proto3" json:"commitment,omitempty"` + LengthCommitment []byte `protobuf:"bytes,2,opt,name=length_commitment,json=lengthCommitment,proto3" json:"length_commitment,omitempty"` + LengthProof []byte `protobuf:"bytes,3,opt,name=length_proof,json=lengthProof,proto3" json:"length_proof,omitempty"` + Length uint32 `protobuf:"varint,4,opt,name=length,proto3" json:"length,omitempty"` +} + +func (x *BlobCommitment) Reset() { + *x = BlobCommitment{} + if protoimpl.UnsafeEnabled { + mi := &file_encoder_encoder_proto_msgTypes[0] + ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) + ms.StoreMessageInfo(mi) + } +} + +func (x *BlobCommitment) String() string { + return protoimpl.X.MessageStringOf(x) +} + +func (*BlobCommitment) ProtoMessage() {} + +func (x *BlobCommitment) ProtoReflect() protoreflect.Message { + mi := &file_encoder_encoder_proto_msgTypes[0] + if protoimpl.UnsafeEnabled && x != nil { + ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) + if ms.LoadMessageInfo() == nil { + ms.StoreMessageInfo(mi) + } + return ms + } + return mi.MessageOf(x) +} + +// Deprecated: Use BlobCommitment.ProtoReflect.Descriptor instead. +func (*BlobCommitment) Descriptor() ([]byte, []int) { + return file_encoder_encoder_proto_rawDescGZIP(), []int{0} +} + +func (x *BlobCommitment) GetCommitment() []byte { + if x != nil { + return x.Commitment + } + return nil +} + +func (x *BlobCommitment) GetLengthCommitment() []byte { + if x != nil { + return x.LengthCommitment + } + return nil +} + +func (x *BlobCommitment) GetLengthProof() []byte { + if x != nil { + return x.LengthProof + } + return nil +} + +func (x *BlobCommitment) GetLength() uint32 { + if x != nil { + return x.Length + } + return 0 +} + +// Parameters needed by Encoder for encoding +type EncodingParams struct { + state protoimpl.MessageState + sizeCache protoimpl.SizeCache + unknownFields protoimpl.UnknownFields + + ChunkLength uint32 `protobuf:"varint,1,opt,name=chunk_length,json=chunkLength,proto3" json:"chunk_length,omitempty"` + NumChunks uint32 `protobuf:"varint,2,opt,name=num_chunks,json=numChunks,proto3" json:"num_chunks,omitempty"` +} + +func (x *EncodingParams) Reset() { + *x = EncodingParams{} + if protoimpl.UnsafeEnabled { + mi := &file_encoder_encoder_proto_msgTypes[1] + ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) + ms.StoreMessageInfo(mi) + } +} + +func (x *EncodingParams) String() string { + return protoimpl.X.MessageStringOf(x) +} + +func (*EncodingParams) ProtoMessage() {} + +func (x *EncodingParams) ProtoReflect() protoreflect.Message { + mi := &file_encoder_encoder_proto_msgTypes[1] + if protoimpl.UnsafeEnabled && x != nil { + ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) + if ms.LoadMessageInfo() == nil { + ms.StoreMessageInfo(mi) + } + return ms + } + return mi.MessageOf(x) +} + +// Deprecated: Use EncodingParams.ProtoReflect.Descriptor instead. +func (*EncodingParams) Descriptor() ([]byte, []int) { + return file_encoder_encoder_proto_rawDescGZIP(), []int{1} +} + +func (x *EncodingParams) GetChunkLength() uint32 { + if x != nil { + return x.ChunkLength + } + return 0 +} + +func (x *EncodingParams) GetNumChunks() uint32 { + if x != nil { + return x.NumChunks + } + return 0 +} + +// EncodeBlobRequest contains data and pre-computed encoding params provided to Encoder +type EncodeBlobRequest struct { + state protoimpl.MessageState + sizeCache protoimpl.SizeCache + unknownFields protoimpl.UnknownFields + + Data []byte `protobuf:"bytes,1,opt,name=data,proto3" json:"data,omitempty"` + EncodingParams *EncodingParams `protobuf:"bytes,2,opt,name=encoding_params,json=encodingParams,proto3" json:"encoding_params,omitempty"` +} + +func (x *EncodeBlobRequest) Reset() { + *x = EncodeBlobRequest{} + if protoimpl.UnsafeEnabled { + mi := &file_encoder_encoder_proto_msgTypes[2] + ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) + ms.StoreMessageInfo(mi) + } +} + +func (x *EncodeBlobRequest) String() string { + return protoimpl.X.MessageStringOf(x) +} + +func (*EncodeBlobRequest) ProtoMessage() {} + +func (x *EncodeBlobRequest) ProtoReflect() protoreflect.Message { + mi := &file_encoder_encoder_proto_msgTypes[2] + if protoimpl.UnsafeEnabled && x != nil { + ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) + if ms.LoadMessageInfo() == nil { + ms.StoreMessageInfo(mi) + } + return ms + } + return mi.MessageOf(x) +} + +// Deprecated: Use EncodeBlobRequest.ProtoReflect.Descriptor instead. +func (*EncodeBlobRequest) Descriptor() ([]byte, []int) { + return file_encoder_encoder_proto_rawDescGZIP(), []int{2} +} + +func (x *EncodeBlobRequest) GetData() []byte { + if x != nil { + return x.Data + } + return nil +} + +func (x *EncodeBlobRequest) GetEncodingParams() *EncodingParams { + if x != nil { + return x.EncodingParams + } + return nil +} + +// EncodeBlobReply returns all encoded chunks along with BlobCommitment for the same, +// where Chunk is the smallest unit that is distributed to DA nodes +type EncodeBlobReply struct { + state protoimpl.MessageState + sizeCache protoimpl.SizeCache + unknownFields protoimpl.UnknownFields + + Commitment *BlobCommitment `protobuf:"bytes,1,opt,name=commitment,proto3" json:"commitment,omitempty"` + Chunks [][]byte `protobuf:"bytes,2,rep,name=chunks,proto3" json:"chunks,omitempty"` + // How the above chunks are encoded. + ChunkEncodingFormat ChunkEncodingFormat `protobuf:"varint,3,opt,name=chunk_encoding_format,json=chunkEncodingFormat,proto3,enum=encoder.ChunkEncodingFormat" json:"chunk_encoding_format,omitempty"` +} + +func (x *EncodeBlobReply) Reset() { + *x = EncodeBlobReply{} + if protoimpl.UnsafeEnabled { + mi := &file_encoder_encoder_proto_msgTypes[3] + ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) + ms.StoreMessageInfo(mi) + } +} + +func (x *EncodeBlobReply) String() string { + return protoimpl.X.MessageStringOf(x) +} + +func (*EncodeBlobReply) ProtoMessage() {} + +func (x *EncodeBlobReply) ProtoReflect() protoreflect.Message { + mi := &file_encoder_encoder_proto_msgTypes[3] + if protoimpl.UnsafeEnabled && x != nil { + ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) + if ms.LoadMessageInfo() == nil { + ms.StoreMessageInfo(mi) + } + return ms + } + return mi.MessageOf(x) +} + +// Deprecated: Use EncodeBlobReply.ProtoReflect.Descriptor instead. +func (*EncodeBlobReply) Descriptor() ([]byte, []int) { + return file_encoder_encoder_proto_rawDescGZIP(), []int{3} +} + +func (x *EncodeBlobReply) GetCommitment() *BlobCommitment { + if x != nil { + return x.Commitment + } + return nil +} + +func (x *EncodeBlobReply) GetChunks() [][]byte { + if x != nil { + return x.Chunks + } + return nil +} + +func (x *EncodeBlobReply) GetChunkEncodingFormat() ChunkEncodingFormat { + if x != nil { + return x.ChunkEncodingFormat + } + return ChunkEncodingFormat_UNKNOWN +} + +var File_encoder_encoder_proto protoreflect.FileDescriptor + +var file_encoder_encoder_proto_rawDesc = []byte{ + 0x0a, 0x15, 0x65, 0x6e, 0x63, 0x6f, 0x64, 0x65, 0x72, 0x2f, 0x65, 0x6e, 0x63, 0x6f, 0x64, 0x65, + 0x72, 0x2e, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x12, 0x07, 0x65, 0x6e, 0x63, 0x6f, 0x64, 0x65, 0x72, + 0x22, 0x98, 0x01, 0x0a, 0x0e, 0x42, 0x6c, 0x6f, 0x62, 0x43, 0x6f, 0x6d, 0x6d, 0x69, 0x74, 0x6d, + 0x65, 0x6e, 0x74, 0x12, 0x1e, 0x0a, 0x0a, 0x63, 0x6f, 0x6d, 0x6d, 0x69, 0x74, 0x6d, 0x65, 0x6e, + 0x74, 0x18, 0x01, 0x20, 0x01, 0x28, 0x0c, 0x52, 0x0a, 0x63, 0x6f, 0x6d, 0x6d, 0x69, 0x74, 0x6d, + 0x65, 0x6e, 0x74, 0x12, 0x2b, 0x0a, 0x11, 0x6c, 0x65, 0x6e, 0x67, 0x74, 0x68, 0x5f, 0x63, 0x6f, + 0x6d, 0x6d, 0x69, 0x74, 0x6d, 0x65, 0x6e, 0x74, 0x18, 0x02, 0x20, 0x01, 0x28, 0x0c, 0x52, 0x10, + 0x6c, 0x65, 0x6e, 0x67, 0x74, 0x68, 0x43, 0x6f, 0x6d, 0x6d, 0x69, 0x74, 0x6d, 0x65, 0x6e, 0x74, + 0x12, 0x21, 0x0a, 0x0c, 0x6c, 0x65, 0x6e, 0x67, 0x74, 0x68, 0x5f, 0x70, 0x72, 0x6f, 0x6f, 0x66, + 0x18, 0x03, 0x20, 0x01, 0x28, 0x0c, 0x52, 0x0b, 0x6c, 0x65, 0x6e, 0x67, 0x74, 0x68, 0x50, 0x72, + 0x6f, 0x6f, 0x66, 0x12, 0x16, 0x0a, 0x06, 0x6c, 0x65, 0x6e, 0x67, 0x74, 0x68, 0x18, 0x04, 0x20, + 0x01, 0x28, 0x0d, 0x52, 0x06, 0x6c, 0x65, 0x6e, 0x67, 0x74, 0x68, 0x22, 0x52, 0x0a, 0x0e, 0x45, + 0x6e, 0x63, 0x6f, 0x64, 0x69, 0x6e, 0x67, 0x50, 0x61, 0x72, 0x61, 0x6d, 0x73, 0x12, 0x21, 0x0a, + 0x0c, 0x63, 0x68, 0x75, 0x6e, 0x6b, 0x5f, 0x6c, 0x65, 0x6e, 0x67, 0x74, 0x68, 0x18, 0x01, 0x20, + 0x01, 0x28, 0x0d, 0x52, 0x0b, 0x63, 0x68, 0x75, 0x6e, 0x6b, 0x4c, 0x65, 0x6e, 0x67, 0x74, 0x68, + 0x12, 0x1d, 0x0a, 0x0a, 0x6e, 0x75, 0x6d, 0x5f, 0x63, 0x68, 0x75, 0x6e, 0x6b, 0x73, 0x18, 0x02, + 0x20, 0x01, 0x28, 0x0d, 0x52, 0x09, 0x6e, 0x75, 0x6d, 0x43, 0x68, 0x75, 0x6e, 0x6b, 0x73, 0x22, + 0x69, 0x0a, 0x11, 0x45, 0x6e, 0x63, 0x6f, 0x64, 0x65, 0x42, 0x6c, 0x6f, 0x62, 0x52, 0x65, 0x71, + 0x75, 0x65, 0x73, 0x74, 0x12, 0x12, 0x0a, 0x04, 0x64, 0x61, 0x74, 0x61, 0x18, 0x01, 0x20, 0x01, + 0x28, 0x0c, 0x52, 0x04, 0x64, 0x61, 0x74, 0x61, 0x12, 0x40, 0x0a, 0x0f, 0x65, 0x6e, 0x63, 0x6f, + 0x64, 0x69, 0x6e, 0x67, 0x5f, 0x70, 0x61, 0x72, 0x61, 0x6d, 0x73, 0x18, 0x02, 0x20, 0x01, 0x28, + 0x0b, 0x32, 0x17, 0x2e, 0x65, 0x6e, 0x63, 0x6f, 0x64, 0x65, 0x72, 0x2e, 0x45, 0x6e, 0x63, 0x6f, + 0x64, 0x69, 0x6e, 0x67, 0x50, 0x61, 0x72, 0x61, 0x6d, 0x73, 0x52, 0x0e, 0x65, 0x6e, 0x63, 0x6f, + 0x64, 0x69, 0x6e, 0x67, 0x50, 0x61, 0x72, 0x61, 0x6d, 0x73, 0x22, 0xb4, 0x01, 0x0a, 0x0f, 0x45, + 0x6e, 0x63, 0x6f, 0x64, 0x65, 0x42, 0x6c, 0x6f, 0x62, 0x52, 0x65, 0x70, 0x6c, 0x79, 0x12, 0x37, + 0x0a, 0x0a, 0x63, 0x6f, 0x6d, 0x6d, 0x69, 0x74, 0x6d, 0x65, 0x6e, 0x74, 0x18, 0x01, 0x20, 0x01, + 0x28, 0x0b, 0x32, 0x17, 0x2e, 0x65, 0x6e, 0x63, 0x6f, 0x64, 0x65, 0x72, 0x2e, 0x42, 0x6c, 0x6f, + 0x62, 0x43, 0x6f, 0x6d, 0x6d, 0x69, 0x74, 0x6d, 0x65, 0x6e, 0x74, 0x52, 0x0a, 0x63, 0x6f, 0x6d, + 0x6d, 0x69, 0x74, 0x6d, 0x65, 0x6e, 0x74, 0x12, 0x16, 0x0a, 0x06, 0x63, 0x68, 0x75, 0x6e, 0x6b, + 0x73, 0x18, 0x02, 0x20, 0x03, 0x28, 0x0c, 0x52, 0x06, 0x63, 0x68, 0x75, 0x6e, 0x6b, 0x73, 0x12, + 0x50, 0x0a, 0x15, 0x63, 0x68, 0x75, 0x6e, 0x6b, 0x5f, 0x65, 0x6e, 0x63, 0x6f, 0x64, 0x69, 0x6e, + 0x67, 0x5f, 0x66, 0x6f, 0x72, 0x6d, 0x61, 0x74, 0x18, 0x03, 0x20, 0x01, 0x28, 0x0e, 0x32, 0x1c, + 0x2e, 0x65, 0x6e, 0x63, 0x6f, 0x64, 0x65, 0x72, 0x2e, 0x43, 0x68, 0x75, 0x6e, 0x6b, 0x45, 0x6e, + 0x63, 0x6f, 0x64, 0x69, 0x6e, 0x67, 0x46, 0x6f, 0x72, 0x6d, 0x61, 0x74, 0x52, 0x13, 0x63, 0x68, + 0x75, 0x6e, 0x6b, 0x45, 0x6e, 0x63, 0x6f, 0x64, 0x69, 0x6e, 0x67, 0x46, 0x6f, 0x72, 0x6d, 0x61, + 0x74, 0x2a, 0x36, 0x0a, 0x13, 0x43, 0x68, 0x75, 0x6e, 0x6b, 0x45, 0x6e, 0x63, 0x6f, 0x64, 0x69, + 0x6e, 0x67, 0x46, 0x6f, 0x72, 0x6d, 0x61, 0x74, 0x12, 0x0b, 0x0a, 0x07, 0x55, 0x4e, 0x4b, 0x4e, + 0x4f, 0x57, 0x4e, 0x10, 0x00, 0x12, 0x09, 0x0a, 0x05, 0x47, 0x4e, 0x41, 0x52, 0x4b, 0x10, 0x01, + 0x12, 0x07, 0x0a, 0x03, 0x47, 0x4f, 0x42, 0x10, 0x02, 0x32, 0x4f, 0x0a, 0x07, 0x45, 0x6e, 0x63, + 0x6f, 0x64, 0x65, 0x72, 0x12, 0x44, 0x0a, 0x0a, 0x45, 0x6e, 0x63, 0x6f, 0x64, 0x65, 0x42, 0x6c, + 0x6f, 0x62, 0x12, 0x1a, 0x2e, 0x65, 0x6e, 0x63, 0x6f, 0x64, 0x65, 0x72, 0x2e, 0x45, 0x6e, 0x63, + 0x6f, 0x64, 0x65, 0x42, 0x6c, 0x6f, 0x62, 0x52, 0x65, 0x71, 0x75, 0x65, 0x73, 0x74, 0x1a, 0x18, + 0x2e, 0x65, 0x6e, 0x63, 0x6f, 0x64, 0x65, 0x72, 0x2e, 0x45, 0x6e, 0x63, 0x6f, 0x64, 0x65, 0x42, + 0x6c, 0x6f, 0x62, 0x52, 0x65, 0x70, 0x6c, 0x79, 0x22, 0x00, 0x42, 0x2f, 0x5a, 0x2d, 0x67, 0x69, + 0x74, 0x68, 0x75, 0x62, 0x2e, 0x63, 0x6f, 0x6d, 0x2f, 0x4c, 0x61, 0x79, 0x72, 0x2d, 0x4c, 0x61, + 0x62, 0x73, 0x2f, 0x65, 0x69, 0x67, 0x65, 0x6e, 0x64, 0x61, 0x2f, 0x61, 0x70, 0x69, 0x2f, 0x67, + 0x72, 0x70, 0x63, 0x2f, 0x65, 0x6e, 0x63, 0x6f, 0x64, 0x65, 0x72, 0x62, 0x06, 0x70, 0x72, 0x6f, + 0x74, 0x6f, 0x33, +} + +var ( + file_encoder_encoder_proto_rawDescOnce sync.Once + file_encoder_encoder_proto_rawDescData = file_encoder_encoder_proto_rawDesc +) + +func file_encoder_encoder_proto_rawDescGZIP() []byte { + file_encoder_encoder_proto_rawDescOnce.Do(func() { + file_encoder_encoder_proto_rawDescData = protoimpl.X.CompressGZIP(file_encoder_encoder_proto_rawDescData) + }) + return file_encoder_encoder_proto_rawDescData +} + +var file_encoder_encoder_proto_enumTypes = make([]protoimpl.EnumInfo, 1) +var file_encoder_encoder_proto_msgTypes = make([]protoimpl.MessageInfo, 4) +var file_encoder_encoder_proto_goTypes = []interface{}{ + (ChunkEncodingFormat)(0), // 0: encoder.ChunkEncodingFormat + (*BlobCommitment)(nil), // 1: encoder.BlobCommitment + (*EncodingParams)(nil), // 2: encoder.EncodingParams + (*EncodeBlobRequest)(nil), // 3: encoder.EncodeBlobRequest + (*EncodeBlobReply)(nil), // 4: encoder.EncodeBlobReply +} +var file_encoder_encoder_proto_depIdxs = []int32{ + 2, // 0: encoder.EncodeBlobRequest.encoding_params:type_name -> encoder.EncodingParams + 1, // 1: encoder.EncodeBlobReply.commitment:type_name -> encoder.BlobCommitment + 0, // 2: encoder.EncodeBlobReply.chunk_encoding_format:type_name -> encoder.ChunkEncodingFormat + 3, // 3: encoder.Encoder.EncodeBlob:input_type -> encoder.EncodeBlobRequest + 4, // 4: encoder.Encoder.EncodeBlob:output_type -> encoder.EncodeBlobReply + 4, // [4:5] is the sub-list for method output_type + 3, // [3:4] is the sub-list for method input_type + 3, // [3:3] is the sub-list for extension type_name + 3, // [3:3] is the sub-list for extension extendee + 0, // [0:3] is the sub-list for field type_name +} + +func init() { file_encoder_encoder_proto_init() } +func file_encoder_encoder_proto_init() { + if File_encoder_encoder_proto != nil { + return + } + if !protoimpl.UnsafeEnabled { + file_encoder_encoder_proto_msgTypes[0].Exporter = func(v interface{}, i int) interface{} { + switch v := v.(*BlobCommitment); i { + case 0: + return &v.state + case 1: + return &v.sizeCache + case 2: + return &v.unknownFields + default: + return nil + } + } + file_encoder_encoder_proto_msgTypes[1].Exporter = func(v interface{}, i int) interface{} { + switch v := v.(*EncodingParams); i { + case 0: + return &v.state + case 1: + return &v.sizeCache + case 2: + return &v.unknownFields + default: + return nil + } + } + file_encoder_encoder_proto_msgTypes[2].Exporter = func(v interface{}, i int) interface{} { + switch v := v.(*EncodeBlobRequest); i { + case 0: + return &v.state + case 1: + return &v.sizeCache + case 2: + return &v.unknownFields + default: + return nil + } + } + file_encoder_encoder_proto_msgTypes[3].Exporter = func(v interface{}, i int) interface{} { + switch v := v.(*EncodeBlobReply); i { + case 0: + return &v.state + case 1: + return &v.sizeCache + case 2: + return &v.unknownFields + default: + return nil + } + } + } + type x struct{} + out := protoimpl.TypeBuilder{ + File: protoimpl.DescBuilder{ + GoPackagePath: reflect.TypeOf(x{}).PkgPath(), + RawDescriptor: file_encoder_encoder_proto_rawDesc, + NumEnums: 1, + NumMessages: 4, + NumExtensions: 0, + NumServices: 1, + }, + GoTypes: file_encoder_encoder_proto_goTypes, + DependencyIndexes: file_encoder_encoder_proto_depIdxs, + EnumInfos: file_encoder_encoder_proto_enumTypes, + MessageInfos: file_encoder_encoder_proto_msgTypes, + }.Build() + File_encoder_encoder_proto = out.File + file_encoder_encoder_proto_rawDesc = nil + file_encoder_encoder_proto_goTypes = nil + file_encoder_encoder_proto_depIdxs = nil +} diff --git a/disperser/api/grpc/encoder/encoder_grpc.pb.go b/disperser/api/grpc/encoder/encoder_grpc.pb.go new file mode 100644 index 0000000000..76285b6a2c --- /dev/null +++ b/disperser/api/grpc/encoder/encoder_grpc.pb.go @@ -0,0 +1,109 @@ +// Code generated by protoc-gen-go-grpc. DO NOT EDIT. +// versions: +// - protoc-gen-go-grpc v1.3.0 +// - protoc v4.23.4 +// source: encoder/encoder.proto + +package encoder + +import ( + context "context" + grpc "google.golang.org/grpc" + codes "google.golang.org/grpc/codes" + status "google.golang.org/grpc/status" +) + +// This is a compile-time assertion to ensure that this generated file +// is compatible with the grpc package it is being compiled against. +// Requires gRPC-Go v1.32.0 or later. +const _ = grpc.SupportPackageIsVersion7 + +const ( + Encoder_EncodeBlob_FullMethodName = "/encoder.Encoder/EncodeBlob" +) + +// EncoderClient is the client API for Encoder service. +// +// For semantics around ctx use and closing/ending streaming RPCs, please refer to https://pkg.go.dev/google.golang.org/grpc/?tab=doc#ClientConn.NewStream. +type EncoderClient interface { + EncodeBlob(ctx context.Context, in *EncodeBlobRequest, opts ...grpc.CallOption) (*EncodeBlobReply, error) +} + +type encoderClient struct { + cc grpc.ClientConnInterface +} + +func NewEncoderClient(cc grpc.ClientConnInterface) EncoderClient { + return &encoderClient{cc} +} + +func (c *encoderClient) EncodeBlob(ctx context.Context, in *EncodeBlobRequest, opts ...grpc.CallOption) (*EncodeBlobReply, error) { + out := new(EncodeBlobReply) + err := c.cc.Invoke(ctx, Encoder_EncodeBlob_FullMethodName, in, out, opts...) + if err != nil { + return nil, err + } + return out, nil +} + +// EncoderServer is the server API for Encoder service. +// All implementations must embed UnimplementedEncoderServer +// for forward compatibility +type EncoderServer interface { + EncodeBlob(context.Context, *EncodeBlobRequest) (*EncodeBlobReply, error) + mustEmbedUnimplementedEncoderServer() +} + +// UnimplementedEncoderServer must be embedded to have forward compatible implementations. +type UnimplementedEncoderServer struct { +} + +func (UnimplementedEncoderServer) EncodeBlob(context.Context, *EncodeBlobRequest) (*EncodeBlobReply, error) { + return nil, status.Errorf(codes.Unimplemented, "method EncodeBlob not implemented") +} +func (UnimplementedEncoderServer) mustEmbedUnimplementedEncoderServer() {} + +// UnsafeEncoderServer may be embedded to opt out of forward compatibility for this service. +// Use of this interface is not recommended, as added methods to EncoderServer will +// result in compilation errors. +type UnsafeEncoderServer interface { + mustEmbedUnimplementedEncoderServer() +} + +func RegisterEncoderServer(s grpc.ServiceRegistrar, srv EncoderServer) { + s.RegisterService(&Encoder_ServiceDesc, srv) +} + +func _Encoder_EncodeBlob_Handler(srv interface{}, ctx context.Context, dec func(interface{}) error, interceptor grpc.UnaryServerInterceptor) (interface{}, error) { + in := new(EncodeBlobRequest) + if err := dec(in); err != nil { + return nil, err + } + if interceptor == nil { + return srv.(EncoderServer).EncodeBlob(ctx, in) + } + info := &grpc.UnaryServerInfo{ + Server: srv, + FullMethod: Encoder_EncodeBlob_FullMethodName, + } + handler := func(ctx context.Context, req interface{}) (interface{}, error) { + return srv.(EncoderServer).EncodeBlob(ctx, req.(*EncodeBlobRequest)) + } + return interceptor(ctx, in, info, handler) +} + +// Encoder_ServiceDesc is the grpc.ServiceDesc for Encoder service. +// It's only intended for direct use with grpc.RegisterService, +// and not to be introspected or modified (even as a copy) +var Encoder_ServiceDesc = grpc.ServiceDesc{ + ServiceName: "encoder.Encoder", + HandlerType: (*EncoderServer)(nil), + Methods: []grpc.MethodDesc{ + { + MethodName: "EncodeBlob", + Handler: _Encoder_EncodeBlob_Handler, + }, + }, + Streams: []grpc.StreamDesc{}, + Metadata: "encoder/encoder.proto", +} diff --git a/disperser/api/grpc/encoder/v2/encoder.pb.go b/disperser/api/grpc/encoder/v2/encoder.pb.go new file mode 100644 index 0000000000..182c97bfc9 --- /dev/null +++ b/disperser/api/grpc/encoder/v2/encoder.pb.go @@ -0,0 +1,386 @@ +// Code generated by protoc-gen-go. DO NOT EDIT. +// versions: +// protoc-gen-go v1.28.1 +// protoc v4.23.4 +// source: encoder/v2/encoder.proto + +package v2 + +import ( + protoreflect "google.golang.org/protobuf/reflect/protoreflect" + protoimpl "google.golang.org/protobuf/runtime/protoimpl" + reflect "reflect" + sync "sync" +) + +const ( + // Verify that this generated code is sufficiently up-to-date. + _ = protoimpl.EnforceVersion(20 - protoimpl.MinVersion) + // Verify that runtime/protoimpl is sufficiently up-to-date. + _ = protoimpl.EnforceVersion(protoimpl.MaxVersion - 20) +) + +// EncodeBlobRequest contains the reference to the blob to be encoded and the encoding parameters +// determined by the control plane. +type EncodeBlobRequest struct { + state protoimpl.MessageState + sizeCache protoimpl.SizeCache + unknownFields protoimpl.UnknownFields + + BlobKey []byte `protobuf:"bytes,1,opt,name=blob_key,json=blobKey,proto3" json:"blob_key,omitempty"` + EncodingParams *EncodingParams `protobuf:"bytes,2,opt,name=encoding_params,json=encodingParams,proto3" json:"encoding_params,omitempty"` +} + +func (x *EncodeBlobRequest) Reset() { + *x = EncodeBlobRequest{} + if protoimpl.UnsafeEnabled { + mi := &file_encoder_v2_encoder_proto_msgTypes[0] + ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) + ms.StoreMessageInfo(mi) + } +} + +func (x *EncodeBlobRequest) String() string { + return protoimpl.X.MessageStringOf(x) +} + +func (*EncodeBlobRequest) ProtoMessage() {} + +func (x *EncodeBlobRequest) ProtoReflect() protoreflect.Message { + mi := &file_encoder_v2_encoder_proto_msgTypes[0] + if protoimpl.UnsafeEnabled && x != nil { + ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) + if ms.LoadMessageInfo() == nil { + ms.StoreMessageInfo(mi) + } + return ms + } + return mi.MessageOf(x) +} + +// Deprecated: Use EncodeBlobRequest.ProtoReflect.Descriptor instead. +func (*EncodeBlobRequest) Descriptor() ([]byte, []int) { + return file_encoder_v2_encoder_proto_rawDescGZIP(), []int{0} +} + +func (x *EncodeBlobRequest) GetBlobKey() []byte { + if x != nil { + return x.BlobKey + } + return nil +} + +func (x *EncodeBlobRequest) GetEncodingParams() *EncodingParams { + if x != nil { + return x.EncodingParams + } + return nil +} + +// EncodingParams specifies how the blob should be encoded into chunks +type EncodingParams struct { + state protoimpl.MessageState + sizeCache protoimpl.SizeCache + unknownFields protoimpl.UnknownFields + + ChunkLength uint64 `protobuf:"varint,1,opt,name=chunk_length,json=chunkLength,proto3" json:"chunk_length,omitempty"` + NumChunks uint64 `protobuf:"varint,2,opt,name=num_chunks,json=numChunks,proto3" json:"num_chunks,omitempty"` +} + +func (x *EncodingParams) Reset() { + *x = EncodingParams{} + if protoimpl.UnsafeEnabled { + mi := &file_encoder_v2_encoder_proto_msgTypes[1] + ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) + ms.StoreMessageInfo(mi) + } +} + +func (x *EncodingParams) String() string { + return protoimpl.X.MessageStringOf(x) +} + +func (*EncodingParams) ProtoMessage() {} + +func (x *EncodingParams) ProtoReflect() protoreflect.Message { + mi := &file_encoder_v2_encoder_proto_msgTypes[1] + if protoimpl.UnsafeEnabled && x != nil { + ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) + if ms.LoadMessageInfo() == nil { + ms.StoreMessageInfo(mi) + } + return ms + } + return mi.MessageOf(x) +} + +// Deprecated: Use EncodingParams.ProtoReflect.Descriptor instead. +func (*EncodingParams) Descriptor() ([]byte, []int) { + return file_encoder_v2_encoder_proto_rawDescGZIP(), []int{1} +} + +func (x *EncodingParams) GetChunkLength() uint64 { + if x != nil { + return x.ChunkLength + } + return 0 +} + +func (x *EncodingParams) GetNumChunks() uint64 { + if x != nil { + return x.NumChunks + } + return 0 +} + +// FragmentInfo contains metadata about the encoded fragments +type FragmentInfo struct { + state protoimpl.MessageState + sizeCache protoimpl.SizeCache + unknownFields protoimpl.UnknownFields + + TotalChunkSizeBytes uint32 `protobuf:"varint,1,opt,name=total_chunk_size_bytes,json=totalChunkSizeBytes,proto3" json:"total_chunk_size_bytes,omitempty"` + FragmentSizeBytes uint32 `protobuf:"varint,2,opt,name=fragment_size_bytes,json=fragmentSizeBytes,proto3" json:"fragment_size_bytes,omitempty"` +} + +func (x *FragmentInfo) Reset() { + *x = FragmentInfo{} + if protoimpl.UnsafeEnabled { + mi := &file_encoder_v2_encoder_proto_msgTypes[2] + ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) + ms.StoreMessageInfo(mi) + } +} + +func (x *FragmentInfo) String() string { + return protoimpl.X.MessageStringOf(x) +} + +func (*FragmentInfo) ProtoMessage() {} + +func (x *FragmentInfo) ProtoReflect() protoreflect.Message { + mi := &file_encoder_v2_encoder_proto_msgTypes[2] + if protoimpl.UnsafeEnabled && x != nil { + ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) + if ms.LoadMessageInfo() == nil { + ms.StoreMessageInfo(mi) + } + return ms + } + return mi.MessageOf(x) +} + +// Deprecated: Use FragmentInfo.ProtoReflect.Descriptor instead. +func (*FragmentInfo) Descriptor() ([]byte, []int) { + return file_encoder_v2_encoder_proto_rawDescGZIP(), []int{2} +} + +func (x *FragmentInfo) GetTotalChunkSizeBytes() uint32 { + if x != nil { + return x.TotalChunkSizeBytes + } + return 0 +} + +func (x *FragmentInfo) GetFragmentSizeBytes() uint32 { + if x != nil { + return x.FragmentSizeBytes + } + return 0 +} + +// EncodeBlobReply contains metadata about the encoded chunks +type EncodeBlobReply struct { + state protoimpl.MessageState + sizeCache protoimpl.SizeCache + unknownFields protoimpl.UnknownFields + + FragmentInfo *FragmentInfo `protobuf:"bytes,1,opt,name=fragment_info,json=fragmentInfo,proto3" json:"fragment_info,omitempty"` +} + +func (x *EncodeBlobReply) Reset() { + *x = EncodeBlobReply{} + if protoimpl.UnsafeEnabled { + mi := &file_encoder_v2_encoder_proto_msgTypes[3] + ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) + ms.StoreMessageInfo(mi) + } +} + +func (x *EncodeBlobReply) String() string { + return protoimpl.X.MessageStringOf(x) +} + +func (*EncodeBlobReply) ProtoMessage() {} + +func (x *EncodeBlobReply) ProtoReflect() protoreflect.Message { + mi := &file_encoder_v2_encoder_proto_msgTypes[3] + if protoimpl.UnsafeEnabled && x != nil { + ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) + if ms.LoadMessageInfo() == nil { + ms.StoreMessageInfo(mi) + } + return ms + } + return mi.MessageOf(x) +} + +// Deprecated: Use EncodeBlobReply.ProtoReflect.Descriptor instead. +func (*EncodeBlobReply) Descriptor() ([]byte, []int) { + return file_encoder_v2_encoder_proto_rawDescGZIP(), []int{3} +} + +func (x *EncodeBlobReply) GetFragmentInfo() *FragmentInfo { + if x != nil { + return x.FragmentInfo + } + return nil +} + +var File_encoder_v2_encoder_proto protoreflect.FileDescriptor + +var file_encoder_v2_encoder_proto_rawDesc = []byte{ + 0x0a, 0x18, 0x65, 0x6e, 0x63, 0x6f, 0x64, 0x65, 0x72, 0x2f, 0x76, 0x32, 0x2f, 0x65, 0x6e, 0x63, + 0x6f, 0x64, 0x65, 0x72, 0x2e, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x12, 0x0a, 0x65, 0x6e, 0x63, 0x6f, + 0x64, 0x65, 0x72, 0x2e, 0x76, 0x32, 0x22, 0x73, 0x0a, 0x11, 0x45, 0x6e, 0x63, 0x6f, 0x64, 0x65, + 0x42, 0x6c, 0x6f, 0x62, 0x52, 0x65, 0x71, 0x75, 0x65, 0x73, 0x74, 0x12, 0x19, 0x0a, 0x08, 0x62, + 0x6c, 0x6f, 0x62, 0x5f, 0x6b, 0x65, 0x79, 0x18, 0x01, 0x20, 0x01, 0x28, 0x0c, 0x52, 0x07, 0x62, + 0x6c, 0x6f, 0x62, 0x4b, 0x65, 0x79, 0x12, 0x43, 0x0a, 0x0f, 0x65, 0x6e, 0x63, 0x6f, 0x64, 0x69, + 0x6e, 0x67, 0x5f, 0x70, 0x61, 0x72, 0x61, 0x6d, 0x73, 0x18, 0x02, 0x20, 0x01, 0x28, 0x0b, 0x32, + 0x1a, 0x2e, 0x65, 0x6e, 0x63, 0x6f, 0x64, 0x65, 0x72, 0x2e, 0x76, 0x32, 0x2e, 0x45, 0x6e, 0x63, + 0x6f, 0x64, 0x69, 0x6e, 0x67, 0x50, 0x61, 0x72, 0x61, 0x6d, 0x73, 0x52, 0x0e, 0x65, 0x6e, 0x63, + 0x6f, 0x64, 0x69, 0x6e, 0x67, 0x50, 0x61, 0x72, 0x61, 0x6d, 0x73, 0x22, 0x52, 0x0a, 0x0e, 0x45, + 0x6e, 0x63, 0x6f, 0x64, 0x69, 0x6e, 0x67, 0x50, 0x61, 0x72, 0x61, 0x6d, 0x73, 0x12, 0x21, 0x0a, + 0x0c, 0x63, 0x68, 0x75, 0x6e, 0x6b, 0x5f, 0x6c, 0x65, 0x6e, 0x67, 0x74, 0x68, 0x18, 0x01, 0x20, + 0x01, 0x28, 0x04, 0x52, 0x0b, 0x63, 0x68, 0x75, 0x6e, 0x6b, 0x4c, 0x65, 0x6e, 0x67, 0x74, 0x68, + 0x12, 0x1d, 0x0a, 0x0a, 0x6e, 0x75, 0x6d, 0x5f, 0x63, 0x68, 0x75, 0x6e, 0x6b, 0x73, 0x18, 0x02, + 0x20, 0x01, 0x28, 0x04, 0x52, 0x09, 0x6e, 0x75, 0x6d, 0x43, 0x68, 0x75, 0x6e, 0x6b, 0x73, 0x22, + 0x73, 0x0a, 0x0c, 0x46, 0x72, 0x61, 0x67, 0x6d, 0x65, 0x6e, 0x74, 0x49, 0x6e, 0x66, 0x6f, 0x12, + 0x33, 0x0a, 0x16, 0x74, 0x6f, 0x74, 0x61, 0x6c, 0x5f, 0x63, 0x68, 0x75, 0x6e, 0x6b, 0x5f, 0x73, + 0x69, 0x7a, 0x65, 0x5f, 0x62, 0x79, 0x74, 0x65, 0x73, 0x18, 0x01, 0x20, 0x01, 0x28, 0x0d, 0x52, + 0x13, 0x74, 0x6f, 0x74, 0x61, 0x6c, 0x43, 0x68, 0x75, 0x6e, 0x6b, 0x53, 0x69, 0x7a, 0x65, 0x42, + 0x79, 0x74, 0x65, 0x73, 0x12, 0x2e, 0x0a, 0x13, 0x66, 0x72, 0x61, 0x67, 0x6d, 0x65, 0x6e, 0x74, + 0x5f, 0x73, 0x69, 0x7a, 0x65, 0x5f, 0x62, 0x79, 0x74, 0x65, 0x73, 0x18, 0x02, 0x20, 0x01, 0x28, + 0x0d, 0x52, 0x11, 0x66, 0x72, 0x61, 0x67, 0x6d, 0x65, 0x6e, 0x74, 0x53, 0x69, 0x7a, 0x65, 0x42, + 0x79, 0x74, 0x65, 0x73, 0x22, 0x50, 0x0a, 0x0f, 0x45, 0x6e, 0x63, 0x6f, 0x64, 0x65, 0x42, 0x6c, + 0x6f, 0x62, 0x52, 0x65, 0x70, 0x6c, 0x79, 0x12, 0x3d, 0x0a, 0x0d, 0x66, 0x72, 0x61, 0x67, 0x6d, + 0x65, 0x6e, 0x74, 0x5f, 0x69, 0x6e, 0x66, 0x6f, 0x18, 0x01, 0x20, 0x01, 0x28, 0x0b, 0x32, 0x18, + 0x2e, 0x65, 0x6e, 0x63, 0x6f, 0x64, 0x65, 0x72, 0x2e, 0x76, 0x32, 0x2e, 0x46, 0x72, 0x61, 0x67, + 0x6d, 0x65, 0x6e, 0x74, 0x49, 0x6e, 0x66, 0x6f, 0x52, 0x0c, 0x66, 0x72, 0x61, 0x67, 0x6d, 0x65, + 0x6e, 0x74, 0x49, 0x6e, 0x66, 0x6f, 0x32, 0x55, 0x0a, 0x07, 0x45, 0x6e, 0x63, 0x6f, 0x64, 0x65, + 0x72, 0x12, 0x4a, 0x0a, 0x0a, 0x45, 0x6e, 0x63, 0x6f, 0x64, 0x65, 0x42, 0x6c, 0x6f, 0x62, 0x12, + 0x1d, 0x2e, 0x65, 0x6e, 0x63, 0x6f, 0x64, 0x65, 0x72, 0x2e, 0x76, 0x32, 0x2e, 0x45, 0x6e, 0x63, + 0x6f, 0x64, 0x65, 0x42, 0x6c, 0x6f, 0x62, 0x52, 0x65, 0x71, 0x75, 0x65, 0x73, 0x74, 0x1a, 0x1b, + 0x2e, 0x65, 0x6e, 0x63, 0x6f, 0x64, 0x65, 0x72, 0x2e, 0x76, 0x32, 0x2e, 0x45, 0x6e, 0x63, 0x6f, + 0x64, 0x65, 0x42, 0x6c, 0x6f, 0x62, 0x52, 0x65, 0x70, 0x6c, 0x79, 0x22, 0x00, 0x42, 0x32, 0x5a, + 0x30, 0x67, 0x69, 0x74, 0x68, 0x75, 0x62, 0x2e, 0x63, 0x6f, 0x6d, 0x2f, 0x4c, 0x61, 0x79, 0x72, + 0x2d, 0x4c, 0x61, 0x62, 0x73, 0x2f, 0x65, 0x69, 0x67, 0x65, 0x6e, 0x64, 0x61, 0x2f, 0x61, 0x70, + 0x69, 0x2f, 0x67, 0x72, 0x70, 0x63, 0x2f, 0x65, 0x6e, 0x63, 0x6f, 0x64, 0x65, 0x72, 0x2f, 0x76, + 0x32, 0x62, 0x06, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x33, +} + +var ( + file_encoder_v2_encoder_proto_rawDescOnce sync.Once + file_encoder_v2_encoder_proto_rawDescData = file_encoder_v2_encoder_proto_rawDesc +) + +func file_encoder_v2_encoder_proto_rawDescGZIP() []byte { + file_encoder_v2_encoder_proto_rawDescOnce.Do(func() { + file_encoder_v2_encoder_proto_rawDescData = protoimpl.X.CompressGZIP(file_encoder_v2_encoder_proto_rawDescData) + }) + return file_encoder_v2_encoder_proto_rawDescData +} + +var file_encoder_v2_encoder_proto_msgTypes = make([]protoimpl.MessageInfo, 4) +var file_encoder_v2_encoder_proto_goTypes = []interface{}{ + (*EncodeBlobRequest)(nil), // 0: encoder.v2.EncodeBlobRequest + (*EncodingParams)(nil), // 1: encoder.v2.EncodingParams + (*FragmentInfo)(nil), // 2: encoder.v2.FragmentInfo + (*EncodeBlobReply)(nil), // 3: encoder.v2.EncodeBlobReply +} +var file_encoder_v2_encoder_proto_depIdxs = []int32{ + 1, // 0: encoder.v2.EncodeBlobRequest.encoding_params:type_name -> encoder.v2.EncodingParams + 2, // 1: encoder.v2.EncodeBlobReply.fragment_info:type_name -> encoder.v2.FragmentInfo + 0, // 2: encoder.v2.Encoder.EncodeBlob:input_type -> encoder.v2.EncodeBlobRequest + 3, // 3: encoder.v2.Encoder.EncodeBlob:output_type -> encoder.v2.EncodeBlobReply + 3, // [3:4] is the sub-list for method output_type + 2, // [2:3] is the sub-list for method input_type + 2, // [2:2] is the sub-list for extension type_name + 2, // [2:2] is the sub-list for extension extendee + 0, // [0:2] is the sub-list for field type_name +} + +func init() { file_encoder_v2_encoder_proto_init() } +func file_encoder_v2_encoder_proto_init() { + if File_encoder_v2_encoder_proto != nil { + return + } + if !protoimpl.UnsafeEnabled { + file_encoder_v2_encoder_proto_msgTypes[0].Exporter = func(v interface{}, i int) interface{} { + switch v := v.(*EncodeBlobRequest); i { + case 0: + return &v.state + case 1: + return &v.sizeCache + case 2: + return &v.unknownFields + default: + return nil + } + } + file_encoder_v2_encoder_proto_msgTypes[1].Exporter = func(v interface{}, i int) interface{} { + switch v := v.(*EncodingParams); i { + case 0: + return &v.state + case 1: + return &v.sizeCache + case 2: + return &v.unknownFields + default: + return nil + } + } + file_encoder_v2_encoder_proto_msgTypes[2].Exporter = func(v interface{}, i int) interface{} { + switch v := v.(*FragmentInfo); i { + case 0: + return &v.state + case 1: + return &v.sizeCache + case 2: + return &v.unknownFields + default: + return nil + } + } + file_encoder_v2_encoder_proto_msgTypes[3].Exporter = func(v interface{}, i int) interface{} { + switch v := v.(*EncodeBlobReply); i { + case 0: + return &v.state + case 1: + return &v.sizeCache + case 2: + return &v.unknownFields + default: + return nil + } + } + } + type x struct{} + out := protoimpl.TypeBuilder{ + File: protoimpl.DescBuilder{ + GoPackagePath: reflect.TypeOf(x{}).PkgPath(), + RawDescriptor: file_encoder_v2_encoder_proto_rawDesc, + NumEnums: 0, + NumMessages: 4, + NumExtensions: 0, + NumServices: 1, + }, + GoTypes: file_encoder_v2_encoder_proto_goTypes, + DependencyIndexes: file_encoder_v2_encoder_proto_depIdxs, + MessageInfos: file_encoder_v2_encoder_proto_msgTypes, + }.Build() + File_encoder_v2_encoder_proto = out.File + file_encoder_v2_encoder_proto_rawDesc = nil + file_encoder_v2_encoder_proto_goTypes = nil + file_encoder_v2_encoder_proto_depIdxs = nil +} diff --git a/disperser/api/grpc/encoder/v2/encoder_grpc.pb.go b/disperser/api/grpc/encoder/v2/encoder_grpc.pb.go new file mode 100644 index 0000000000..dae8a78bcf --- /dev/null +++ b/disperser/api/grpc/encoder/v2/encoder_grpc.pb.go @@ -0,0 +1,115 @@ +// Code generated by protoc-gen-go-grpc. DO NOT EDIT. +// versions: +// - protoc-gen-go-grpc v1.3.0 +// - protoc v4.23.4 +// source: encoder/v2/encoder.proto + +package v2 + +import ( + context "context" + grpc "google.golang.org/grpc" + codes "google.golang.org/grpc/codes" + status "google.golang.org/grpc/status" +) + +// This is a compile-time assertion to ensure that this generated file +// is compatible with the grpc package it is being compiled against. +// Requires gRPC-Go v1.32.0 or later. +const _ = grpc.SupportPackageIsVersion7 + +const ( + Encoder_EncodeBlob_FullMethodName = "/encoder.v2.Encoder/EncodeBlob" +) + +// EncoderClient is the client API for Encoder service. +// +// For semantics around ctx use and closing/ending streaming RPCs, please refer to https://pkg.go.dev/google.golang.org/grpc/?tab=doc#ClientConn.NewStream. +type EncoderClient interface { + // EncodeBlob encodes a blob into chunks using specified encoding parameters. + // The blob is retrieved using the provided blob key and the encoded chunks + // are persisted for later retrieval. + EncodeBlob(ctx context.Context, in *EncodeBlobRequest, opts ...grpc.CallOption) (*EncodeBlobReply, error) +} + +type encoderClient struct { + cc grpc.ClientConnInterface +} + +func NewEncoderClient(cc grpc.ClientConnInterface) EncoderClient { + return &encoderClient{cc} +} + +func (c *encoderClient) EncodeBlob(ctx context.Context, in *EncodeBlobRequest, opts ...grpc.CallOption) (*EncodeBlobReply, error) { + out := new(EncodeBlobReply) + err := c.cc.Invoke(ctx, Encoder_EncodeBlob_FullMethodName, in, out, opts...) + if err != nil { + return nil, err + } + return out, nil +} + +// EncoderServer is the server API for Encoder service. +// All implementations must embed UnimplementedEncoderServer +// for forward compatibility +type EncoderServer interface { + // EncodeBlob encodes a blob into chunks using specified encoding parameters. + // The blob is retrieved using the provided blob key and the encoded chunks + // are persisted for later retrieval. + EncodeBlob(context.Context, *EncodeBlobRequest) (*EncodeBlobReply, error) + mustEmbedUnimplementedEncoderServer() +} + +// UnimplementedEncoderServer must be embedded to have forward compatible implementations. +type UnimplementedEncoderServer struct { +} + +func (UnimplementedEncoderServer) EncodeBlob(context.Context, *EncodeBlobRequest) (*EncodeBlobReply, error) { + return nil, status.Errorf(codes.Unimplemented, "method EncodeBlob not implemented") +} +func (UnimplementedEncoderServer) mustEmbedUnimplementedEncoderServer() {} + +// UnsafeEncoderServer may be embedded to opt out of forward compatibility for this service. +// Use of this interface is not recommended, as added methods to EncoderServer will +// result in compilation errors. +type UnsafeEncoderServer interface { + mustEmbedUnimplementedEncoderServer() +} + +func RegisterEncoderServer(s grpc.ServiceRegistrar, srv EncoderServer) { + s.RegisterService(&Encoder_ServiceDesc, srv) +} + +func _Encoder_EncodeBlob_Handler(srv interface{}, ctx context.Context, dec func(interface{}) error, interceptor grpc.UnaryServerInterceptor) (interface{}, error) { + in := new(EncodeBlobRequest) + if err := dec(in); err != nil { + return nil, err + } + if interceptor == nil { + return srv.(EncoderServer).EncodeBlob(ctx, in) + } + info := &grpc.UnaryServerInfo{ + Server: srv, + FullMethod: Encoder_EncodeBlob_FullMethodName, + } + handler := func(ctx context.Context, req interface{}) (interface{}, error) { + return srv.(EncoderServer).EncodeBlob(ctx, req.(*EncodeBlobRequest)) + } + return interceptor(ctx, in, info, handler) +} + +// Encoder_ServiceDesc is the grpc.ServiceDesc for Encoder service. +// It's only intended for direct use with grpc.RegisterService, +// and not to be introspected or modified (even as a copy) +var Encoder_ServiceDesc = grpc.ServiceDesc{ + ServiceName: "encoder.v2.Encoder", + HandlerType: (*EncoderServer)(nil), + Methods: []grpc.MethodDesc{ + { + MethodName: "EncodeBlob", + Handler: _Encoder_EncodeBlob_Handler, + }, + }, + Streams: []grpc.StreamDesc{}, + Metadata: "encoder/v2/encoder.proto", +} From 2c2f8931bd40e7a937c7f7f7e26d516b6543a6d0 Mon Sep 17 00:00:00 2001 From: hopeyen Date: Tue, 10 Dec 2024 10:20:00 -0800 Subject: [PATCH 15/18] refactor: define and check ActiveReservation against onchain struct --- core/data.go | 13 +++++++++++-- core/eth/reader.go | 11 +++++------ core/eth/utils.go | 17 +++++++++++++++++ 3 files changed, 33 insertions(+), 8 deletions(-) diff --git a/core/data.go b/core/data.go index c0dfec23cb..256f6f70eb 100644 --- a/core/data.go +++ b/core/data.go @@ -9,7 +9,6 @@ import ( commonpb "github.com/Layr-Labs/eigenda/api/grpc/common" "github.com/Layr-Labs/eigenda/common" - paymentvault "github.com/Layr-Labs/eigenda/contracts/bindings/PaymentVault" "github.com/Layr-Labs/eigenda/encoding" "github.com/aws/aws-sdk-go-v2/service/dynamodb/types" "github.com/consensys/gnark-crypto/ecc/bn254" @@ -599,7 +598,17 @@ func ConvertToPaymentMetadata(ph *commonpb.PaymentHeader) *PaymentMetadata { } } -type ActiveReservation = paymentvault.IPaymentVaultReservation +// OperatorInfo contains information about an operator which is stored on the blockchain state, +// corresponding to a particular quorum +type ActiveReservation struct { + SymbolsPerSecond uint64 // reserve number of symbols per second + //TODO: we are not using start and end timestamp, add check or remove + StartTimestamp uint64 // Unix timestamp that's valid for basically eternity + EndTimestamp uint64 + + QuorumNumbers []uint8 // allowed quorums + QuorumSplits []byte // ordered mapping of quorum number to payment split; on-chain validation should ensure split <= 100 +} type OnDemandPayment struct { CumulativePayment *big.Int // Total amount deposited by the user diff --git a/core/eth/reader.go b/core/eth/reader.go index edb64ee6e6..83829320b0 100644 --- a/core/eth/reader.go +++ b/core/eth/reader.go @@ -671,10 +671,12 @@ func (t *Reader) GetActiveReservations(ctx context.Context, accountIDs []gethcom // since reservations are returned in the same order as the accountIDs, we can directly map them for i, reservation := range reservations { - if isZeroValuedReservation(reservation) { + res, err := ConvertToActiveReservation(reservation) + if err != nil { delete(reservationsMap, accountIDs[i]) + continue } - reservationsMap[accountIDs[i]] = &reservation + reservationsMap[accountIDs[i]] = res } return reservationsMap, nil @@ -690,10 +692,7 @@ func (t *Reader) GetActiveReservationByAccount(ctx context.Context, accountID ge if err != nil { return nil, err } - if isZeroValuedReservation(reservation) { - return nil, errors.New("reservation does not exist for given account") - } - return &reservation, nil + return ConvertToActiveReservation(reservation) } func (t *Reader) GetOnDemandPayments(ctx context.Context, accountIDs []gethcommon.Address) (map[gethcommon.Address]*core.OnDemandPayment, error) { diff --git a/core/eth/utils.go b/core/eth/utils.go index 973db46e2d..764c7f9b40 100644 --- a/core/eth/utils.go +++ b/core/eth/utils.go @@ -1,6 +1,7 @@ package eth import ( + "fmt" "math/big" "reflect" "slices" @@ -134,3 +135,19 @@ func isZeroValuedReservation(reservation paymentvault.IPaymentVaultReservation) return reflect.DeepEqual(reservation, zeroReservation) } + +// ConvertToActiveReservation converts a upstream binding data structure to local definition. +// Returns an error if the input reservation is zero-valued. +func ConvertToActiveReservation(reservation paymentvault.IPaymentVaultReservation) (*core.ActiveReservation, error) { + if isZeroValuedReservation(reservation) { + return nil, fmt.Errorf("reservation does not exist for given account") + } + + return &core.ActiveReservation{ + SymbolsPerSecond: reservation.SymbolsPerSecond, + StartTimestamp: reservation.StartTimestamp, + EndTimestamp: reservation.EndTimestamp, + QuorumNumbers: reservation.QuorumNumbers, + QuorumSplits: reservation.QuorumSplits, + }, nil +} From 91856ce71b3eb8b7f5a9033f89069e7b49106019 Mon Sep 17 00:00:00 2001 From: hopeyen Date: Tue, 10 Dec 2024 12:11:42 -0800 Subject: [PATCH 16/18] fix: properly check zero valued reservation --- core/eth/utils.go | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/core/eth/utils.go b/core/eth/utils.go index 764c7f9b40..544c9660e2 100644 --- a/core/eth/utils.go +++ b/core/eth/utils.go @@ -3,7 +3,6 @@ package eth import ( "fmt" "math/big" - "reflect" "slices" "github.com/Layr-Labs/eigenda/core" @@ -131,9 +130,11 @@ func bitmapToBytesArray(bitmap *big.Int) []byte { } func isZeroValuedReservation(reservation paymentvault.IPaymentVaultReservation) bool { - zeroReservation := paymentvault.IPaymentVaultReservation{} - - return reflect.DeepEqual(reservation, zeroReservation) + return reservation.SymbolsPerSecond == 0 && + reservation.StartTimestamp == 0 && + reservation.EndTimestamp == 0 && + len(reservation.QuorumNumbers) == 0 && + len(reservation.QuorumSplits) == 0 } // ConvertToActiveReservation converts a upstream binding data structure to local definition. From b585fca01466e0153b652c406fa0d55d0a81ef7b Mon Sep 17 00:00:00 2001 From: hopeyen Date: Tue, 10 Dec 2024 12:13:26 -0800 Subject: [PATCH 17/18] fix: adding on-chain payments to cached maps --- core/eth/reader.go | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/core/eth/reader.go b/core/eth/reader.go index 83829320b0..5533277072 100644 --- a/core/eth/reader.go +++ b/core/eth/reader.go @@ -673,9 +673,10 @@ func (t *Reader) GetActiveReservations(ctx context.Context, accountIDs []gethcom for i, reservation := range reservations { res, err := ConvertToActiveReservation(reservation) if err != nil { - delete(reservationsMap, accountIDs[i]) + t.logger.Warn("failed to get active reservation", "account", accountIDs[i], "err", err) continue } + reservationsMap[accountIDs[i]] = res } @@ -710,7 +711,8 @@ func (t *Reader) GetOnDemandPayments(ctx context.Context, accountIDs []gethcommo // since payments are returned in the same order as the accountIDs, we can directly map them for i, payment := range payments { if payment.Cmp(big.NewInt(0)) == 0 { - delete(paymentsMap, accountIDs[i]) + t.logger.Warn("failed to get on demand payment for account", "account", accountIDs[i], "err", err) + continue } paymentsMap[accountIDs[i]] = &core.OnDemandPayment{ CumulativePayment: payment, From 971edc2bfbb576dd97fc12ca614f3d7622ccb331 Mon Sep 17 00:00:00 2001 From: hopeyen Date: Tue, 10 Dec 2024 12:43:20 -0800 Subject: [PATCH 18/18] fix: logs --- core/eth/reader.go | 2 +- core/eth/utils.go | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/core/eth/reader.go b/core/eth/reader.go index 5533277072..b87724244a 100644 --- a/core/eth/reader.go +++ b/core/eth/reader.go @@ -711,7 +711,7 @@ func (t *Reader) GetOnDemandPayments(ctx context.Context, accountIDs []gethcommo // since payments are returned in the same order as the accountIDs, we can directly map them for i, payment := range payments { if payment.Cmp(big.NewInt(0)) == 0 { - t.logger.Warn("failed to get on demand payment for account", "account", accountIDs[i], "err", err) + t.logger.Warn("failed to get on demand payment for account", "account", accountIDs[i]) continue } paymentsMap[accountIDs[i]] = &core.OnDemandPayment{ diff --git a/core/eth/utils.go b/core/eth/utils.go index 544c9660e2..d98b6def2a 100644 --- a/core/eth/utils.go +++ b/core/eth/utils.go @@ -141,7 +141,7 @@ func isZeroValuedReservation(reservation paymentvault.IPaymentVaultReservation) // Returns an error if the input reservation is zero-valued. func ConvertToActiveReservation(reservation paymentvault.IPaymentVaultReservation) (*core.ActiveReservation, error) { if isZeroValuedReservation(reservation) { - return nil, fmt.Errorf("reservation does not exist for given account") + return nil, fmt.Errorf("reservation is not a valid active reservation") } return &core.ActiveReservation{