From 1d3d7e8cc4db31ff1d3957ce9f9839b2eed711bd Mon Sep 17 00:00:00 2001 From: hopeyen Date: Wed, 8 Jan 2025 08:22:43 -0800 Subject: [PATCH] refactor: rename protobuf binRecords --- api/clients/v2/accountant.go | 44 +++++++++++------------ api/clients/v2/accountant_test.go | 30 ++++++++-------- api/docs/disperser_v2.html | 8 ++--- api/docs/disperser_v2.md | 10 +++--- api/docs/eigenda-protos.html | 8 ++--- api/docs/eigenda-protos.md | 10 +++--- api/grpc/disperser/v2/disperser_v2.pb.go | 34 +++++++++--------- api/proto/disperser/v2/disperser_v2.proto | 6 ++-- core/meterer/offchain_store.go | 16 ++++----- disperser/apiserver/server_v2.go | 4 +-- 10 files changed, 85 insertions(+), 85 deletions(-) diff --git a/api/clients/v2/accountant.go b/api/clients/v2/accountant.go index 02dd58d9f6..33dbecd7ac 100644 --- a/api/clients/v2/accountant.go +++ b/api/clients/v2/accountant.go @@ -26,7 +26,7 @@ type Accountant struct { // local accounting // contains 3 bins; circular wrapping of indices - binRecords []BinRecord + periodRecords []PeriodRecord usageLock sync.Mutex cumulativePayment *big.Int @@ -34,7 +34,7 @@ type Accountant struct { numBins uint32 } -type BinRecord struct { +type PeriodRecord struct { Index uint32 Usage uint64 } @@ -43,9 +43,9 @@ func NewAccountant(accountID string, reservation *core.ReservedPayment, onDemand //TODO: client storage; currently every instance starts fresh but on-chain or a small store makes more sense // Also client is currently responsible for supplying network params, we need to add RPC in order to be automatic // There's a subsequent PR that handles populating the accountant with on-chain state from the disperser - binRecords := make([]BinRecord, numBins) - for i := range binRecords { - binRecords[i] = BinRecord{Index: uint32(i), Usage: 0} + periodRecords := make([]PeriodRecord, numBins) + for i := range periodRecords { + periodRecords[i] = PeriodRecord{Index: uint32(i), Usage: 0} } a := Accountant{ accountID: accountID, @@ -54,7 +54,7 @@ func NewAccountant(accountID string, reservation *core.ReservedPayment, onDemand reservationWindow: reservationWindow, pricePerSymbol: pricePerSymbol, minNumSymbols: minNumSymbols, - binRecords: binRecords, + periodRecords: periodRecords, cumulativePayment: big.NewInt(0), numBins: max(numBins, uint32(meterer.MinNumBins)), } @@ -74,22 +74,22 @@ func (a *Accountant) BlobPaymentInfo(ctx context.Context, numSymbols uint32, quo a.usageLock.Lock() defer a.usageLock.Unlock() - relativeBinRecord := a.GetRelativeBinRecord(currentReservationPeriod) - relativeBinRecord.Usage += symbolUsage + relativePeriodRecord := a.GetRelativePeriodRecord(currentReservationPeriod) + relativePeriodRecord.Usage += symbolUsage // first attempt to use the active reservation binLimit := a.reservation.SymbolsPerSecond * uint64(a.reservationWindow) - if relativeBinRecord.Usage <= binLimit { + if relativePeriodRecord.Usage <= binLimit { if err := QuorumCheck(quorumNumbers, a.reservation.QuorumNumbers); err != nil { return 0, big.NewInt(0), err } return currentReservationPeriod, big.NewInt(0), nil } - overflowBinRecord := a.GetRelativeBinRecord(currentReservationPeriod + 2) + overflowPeriodRecord := a.GetRelativePeriodRecord(currentReservationPeriod + 2) // Allow one overflow when the overflow bin is empty, the current usage and new length are both less than the limit - if overflowBinRecord.Usage == 0 && relativeBinRecord.Usage-symbolUsage < binLimit && symbolUsage <= binLimit { - overflowBinRecord.Usage += relativeBinRecord.Usage - binLimit + if overflowPeriodRecord.Usage == 0 && relativePeriodRecord.Usage-symbolUsage < binLimit && symbolUsage <= binLimit { + overflowPeriodRecord.Usage += relativePeriodRecord.Usage - binLimit if err := QuorumCheck(quorumNumbers, a.reservation.QuorumNumbers); err != nil { return 0, big.NewInt(0), err } @@ -98,7 +98,7 @@ func (a *Accountant) BlobPaymentInfo(ctx context.Context, numSymbols uint32, quo // reservation not available, rollback reservation records, attempt on-demand //todo: rollback on-demand if disperser respond with some type of rejection? - relativeBinRecord.Usage -= symbolUsage + relativePeriodRecord.Usage -= symbolUsage incrementRequired := big.NewInt(int64(a.PaymentCharged(numSymbols))) a.cumulativePayment.Add(a.cumulativePayment, incrementRequired) if a.cumulativePayment.Cmp(a.onDemand.CumulativePayment) <= 0 { @@ -143,16 +143,16 @@ func (a *Accountant) SymbolsCharged(numSymbols uint32) uint32 { return uint32(core.RoundUpDivide(uint(numSymbols), uint(a.minNumSymbols))) * a.minNumSymbols } -func (a *Accountant) GetRelativeBinRecord(index uint32) *BinRecord { +func (a *Accountant) GetRelativePeriodRecord(index uint32) *PeriodRecord { relativeIndex := index % a.numBins - if a.binRecords[relativeIndex].Index != uint32(index) { - a.binRecords[relativeIndex] = BinRecord{ + if a.periodRecords[relativeIndex].Index != uint32(index) { + a.periodRecords[relativeIndex] = PeriodRecord{ Index: uint32(index), Usage: 0, } } - return &a.binRecords[relativeIndex] + return &a.periodRecords[relativeIndex] } // SetPaymentState sets the accountant's state from the disperser's response @@ -214,18 +214,18 @@ func (a *Accountant) SetPaymentState(paymentState *disperser_rpc.GetPaymentState } } - binRecords := make([]BinRecord, len(paymentState.GetBinRecords())) - for i, record := range paymentState.GetBinRecords() { + periodRecords := make([]PeriodRecord, len(paymentState.GetPeriodRecords())) + for i, record := range paymentState.GetPeriodRecords() { if record == nil { - binRecords[i] = BinRecord{Index: 0, Usage: 0} + periodRecords[i] = PeriodRecord{Index: 0, Usage: 0} } else { - binRecords[i] = BinRecord{ + periodRecords[i] = PeriodRecord{ Index: record.Index, Usage: record.Usage, } } } - a.binRecords = binRecords + a.periodRecords = periodRecords return nil } diff --git a/api/clients/v2/accountant_test.go b/api/clients/v2/accountant_test.go index ac8672ff5f..ba71c7a5b3 100644 --- a/api/clients/v2/accountant_test.go +++ b/api/clients/v2/accountant_test.go @@ -43,7 +43,7 @@ func TestNewAccountant(t *testing.T) { assert.Equal(t, reservationWindow, accountant.reservationWindow) assert.Equal(t, pricePerSymbol, accountant.pricePerSymbol) assert.Equal(t, minNumSymbols, accountant.minNumSymbols) - assert.Equal(t, []BinRecord{{Index: 0, Usage: 0}, {Index: 1, Usage: 0}, {Index: 2, Usage: 0}}, accountant.binRecords) + assert.Equal(t, []PeriodRecord{{Index: 0, Usage: 0}, {Index: 1, Usage: 0}, {Index: 2, Usage: 0}}, accountant.periodRecords) assert.Equal(t, big.NewInt(0), accountant.cumulativePayment) } @@ -76,7 +76,7 @@ func TestAccountBlob_Reservation(t *testing.T) { assert.NoError(t, err) assert.Equal(t, meterer.GetReservationPeriod(uint64(time.Now().Unix()), reservationWindow), header.ReservationPeriod) assert.Equal(t, big.NewInt(0), header.CumulativePayment) - assert.Equal(t, isRotation([]uint64{500, 0, 0}, mapRecordUsage(accountant.binRecords)), true) + assert.Equal(t, isRotation([]uint64{500, 0, 0}, mapRecordUsage(accountant.periodRecords)), true) symbolLength = uint32(700) @@ -85,7 +85,7 @@ func TestAccountBlob_Reservation(t *testing.T) { assert.NoError(t, err) assert.NotEqual(t, 0, header.ReservationPeriod) assert.Equal(t, big.NewInt(0), header.CumulativePayment) - assert.Equal(t, isRotation([]uint64{1200, 0, 200}, mapRecordUsage(accountant.binRecords)), true) + assert.Equal(t, isRotation([]uint64{1200, 0, 200}, mapRecordUsage(accountant.periodRecords)), true) // Second call should use on-demand payment header, err = accountant.AccountBlob(ctx, 300, quorums, salt) @@ -125,7 +125,7 @@ func TestAccountBlob_OnDemand(t *testing.T) { expectedPayment := big.NewInt(int64(numSymbols * pricePerSymbol)) assert.Equal(t, uint32(0), header.ReservationPeriod) assert.Equal(t, expectedPayment, header.CumulativePayment) - assert.Equal(t, isRotation([]uint64{0, 0, 0}, mapRecordUsage(accountant.binRecords)), true) + assert.Equal(t, isRotation([]uint64{0, 0, 0}, mapRecordUsage(accountant.periodRecords)), true) assert.Equal(t, expectedPayment, accountant.cumulativePayment) } @@ -225,7 +225,7 @@ func TestAccountBlob_BinRotation(t *testing.T) { // First call _, err = accountant.AccountBlob(ctx, 800, quorums, salt) assert.NoError(t, err) - assert.Equal(t, isRotation([]uint64{800, 0, 0}, mapRecordUsage(accountant.binRecords)), true) + assert.Equal(t, isRotation([]uint64{800, 0, 0}, mapRecordUsage(accountant.periodRecords)), true) // next reservation duration time.Sleep(1000 * time.Millisecond) @@ -233,12 +233,12 @@ func TestAccountBlob_BinRotation(t *testing.T) { // Second call _, err = accountant.AccountBlob(ctx, 300, quorums, salt) assert.NoError(t, err) - assert.Equal(t, isRotation([]uint64{800, 300, 0}, mapRecordUsage(accountant.binRecords)), true) + assert.Equal(t, isRotation([]uint64{800, 300, 0}, mapRecordUsage(accountant.periodRecords)), true) // Third call _, err = accountant.AccountBlob(ctx, 500, quorums, salt) assert.NoError(t, err) - assert.Equal(t, isRotation([]uint64{800, 800, 0}, mapRecordUsage(accountant.binRecords)), true) + assert.Equal(t, isRotation([]uint64{800, 800, 0}, mapRecordUsage(accountant.periodRecords)), true) } func TestConcurrentBinRotationAndAccountBlob(t *testing.T) { @@ -279,7 +279,7 @@ func TestConcurrentBinRotationAndAccountBlob(t *testing.T) { wg.Wait() // Check final state - usages := mapRecordUsage(accountant.binRecords) + usages := mapRecordUsage(accountant.periodRecords) assert.Equal(t, uint64(1000), usages[0]+usages[1]+usages[2]) } @@ -313,14 +313,14 @@ func TestAccountBlob_ReservationWithOneOverflow(t *testing.T) { assert.Equal(t, salt, header.Salt) assert.Equal(t, meterer.GetReservationPeriod(uint64(now), reservationWindow), header.ReservationPeriod) assert.Equal(t, big.NewInt(0), header.CumulativePayment) - assert.Equal(t, isRotation([]uint64{800, 0, 0}, mapRecordUsage(accountant.binRecords)), true) + assert.Equal(t, isRotation([]uint64{800, 0, 0}, mapRecordUsage(accountant.periodRecords)), true) // Second call: Allow one overflow header, err = accountant.AccountBlob(ctx, 500, quorums, salt+1) assert.NoError(t, err) assert.Equal(t, salt+1, header.Salt) assert.Equal(t, big.NewInt(0), header.CumulativePayment) - assert.Equal(t, isRotation([]uint64{1300, 0, 300}, mapRecordUsage(accountant.binRecords)), true) + assert.Equal(t, isRotation([]uint64{1300, 0, 300}, mapRecordUsage(accountant.periodRecords)), true) // Third call: Should use on-demand payment header, err = accountant.AccountBlob(ctx, 200, quorums, salt+2) @@ -328,7 +328,7 @@ func TestAccountBlob_ReservationWithOneOverflow(t *testing.T) { assert.Equal(t, salt+2, header.Salt) assert.Equal(t, uint32(0), header.ReservationPeriod) assert.Equal(t, big.NewInt(200), header.CumulativePayment) - assert.Equal(t, isRotation([]uint64{1300, 0, 300}, mapRecordUsage(accountant.binRecords)), true) + assert.Equal(t, isRotation([]uint64{1300, 0, 300}, mapRecordUsage(accountant.periodRecords)), true) } func TestAccountBlob_ReservationOverflowReset(t *testing.T) { @@ -357,12 +357,12 @@ func TestAccountBlob_ReservationOverflowReset(t *testing.T) { // full reservation _, err = accountant.AccountBlob(ctx, 1000, quorums, salt) assert.NoError(t, err) - assert.Equal(t, isRotation([]uint64{1000, 0, 0}, mapRecordUsage(accountant.binRecords)), true) + assert.Equal(t, isRotation([]uint64{1000, 0, 0}, mapRecordUsage(accountant.periodRecords)), true) // no overflow header, err := accountant.AccountBlob(ctx, 500, quorums, salt) assert.NoError(t, err) - assert.Equal(t, isRotation([]uint64{1000, 0, 0}, mapRecordUsage(accountant.binRecords)), true) + assert.Equal(t, isRotation([]uint64{1000, 0, 0}, mapRecordUsage(accountant.periodRecords)), true) assert.Equal(t, big.NewInt(500), header.CumulativePayment) // Wait for next reservation duration @@ -371,7 +371,7 @@ func TestAccountBlob_ReservationOverflowReset(t *testing.T) { // Third call: Should use new bin and allow overflow again _, err = accountant.AccountBlob(ctx, 500, quorums, salt) assert.NoError(t, err) - assert.Equal(t, isRotation([]uint64{1000, 500, 0}, mapRecordUsage(accountant.binRecords)), true) + assert.Equal(t, isRotation([]uint64{1000, 500, 0}, mapRecordUsage(accountant.periodRecords)), true) } func TestQuorumCheck(t *testing.T) { @@ -431,7 +431,7 @@ func TestQuorumCheck(t *testing.T) { } } -func mapRecordUsage(records []BinRecord) []uint64 { +func mapRecordUsage(records []PeriodRecord) []uint64 { return []uint64{records[0].Usage, records[1].Usage, records[2].Usage} } diff --git a/api/docs/disperser_v2.html b/api/docs/disperser_v2.html index 50b3685d72..3b1727ffb5 100644 --- a/api/docs/disperser_v2.html +++ b/api/docs/disperser_v2.html @@ -183,7 +183,7 @@

Table of Contents

  • - MBinRecord + MPeriodRecord
  • @@ -321,8 +321,8 @@

    Attestation

    -

    BinRecord

    -

    BinRecord is the usage record of an account in a bin. The API should return the active bin

    record and the subsequent two records that contains potential overflows.

    +

    PeriodRecord

    +

    PeriodRecord is the usage record of an account in a bin. The API should return the active bin

    record and the subsequent two records that contains potential overflows.

    @@ -586,7 +586,7 @@

    GetPaymentStateReply

    - + diff --git a/api/docs/disperser_v2.md b/api/docs/disperser_v2.md index 0ca84f3b0d..2650682abd 100644 --- a/api/docs/disperser_v2.md +++ b/api/docs/disperser_v2.md @@ -5,7 +5,7 @@ - [disperser/v2/disperser_v2.proto](#disperser_v2_disperser_v2-proto) - [Attestation](#disperser-v2-Attestation) - - [BinRecord](#disperser-v2-BinRecord) + - [PeriodRecord](#disperser-v2-PeriodRecord) - [BlobCommitmentReply](#disperser-v2-BlobCommitmentReply) - [BlobCommitmentRequest](#disperser-v2-BlobCommitmentRequest) - [BlobStatusReply](#disperser-v2-BlobStatusReply) @@ -54,10 +54,10 @@ - + -### BinRecord -BinRecord is the usage record of an account in a bin. The API should return the active bin +### PeriodRecord +PeriodRecord is the usage record of an account in a bin. The API should return the active bin record and the subsequent two records that contains potential overflows. @@ -192,7 +192,7 @@ GetPaymentStateReply contains the payment state of an account. | Field | Type | Label | Description | | ----- | ---- | ----- | ----------- | | payment_global_params | [PaymentGlobalParams](#disperser-v2-PaymentGlobalParams) | | global payment vault parameters | -| bin_records | [BinRecord](#disperser-v2-BinRecord) | repeated | off-chain account reservation usage records | +| bin_records | [PeriodRecord](#disperser-v2-PeriodRecord) | repeated | off-chain account reservation usage records | | reservation | [Reservation](#disperser-v2-Reservation) | | on-chain account reservation setting | | cumulative_payment | [bytes](#bytes) | | off-chain on-demand payment usage | | onchain_cumulative_payment | [bytes](#bytes) | | on-chain on-demand payment deposited | diff --git a/api/docs/eigenda-protos.html b/api/docs/eigenda-protos.html index 3981fbfb15..8bc6fd3fa1 100644 --- a/api/docs/eigenda-protos.html +++ b/api/docs/eigenda-protos.html @@ -351,7 +351,7 @@

    Table of Contents

  • - MBinRecord + MPeriodRecord
  • @@ -2015,8 +2015,8 @@

    Attestation

    -

    BinRecord

    -

    BinRecord is the usage record of an account in a bin. The API should return the active bin

    record and the subsequent two records that contains potential overflows.

    +

    PeriodRecord

    +

    PeriodRecord is the usage record of an account in a bin. The API should return the active bin

    record and the subsequent two records that contains potential overflows.

  • bin_recordsBinRecordPeriodRecord repeated

    off-chain account reservation usage records

    @@ -2280,7 +2280,7 @@

    GetPaymentStateReply

    - + diff --git a/api/docs/eigenda-protos.md b/api/docs/eigenda-protos.md index 69f4413969..0165aebe5f 100644 --- a/api/docs/eigenda-protos.md +++ b/api/docs/eigenda-protos.md @@ -47,7 +47,7 @@ - [disperser/v2/disperser_v2.proto](#disperser_v2_disperser_v2-proto) - [Attestation](#disperser-v2-Attestation) - - [BinRecord](#disperser-v2-BinRecord) + - [PeriodRecord](#disperser-v2-PeriodRecord) - [BlobCommitmentReply](#disperser-v2-BlobCommitmentReply) - [BlobCommitmentRequest](#disperser-v2-BlobCommitmentRequest) - [BlobStatusReply](#disperser-v2-BlobStatusReply) @@ -762,10 +762,10 @@ If DisperseBlob returns the following error codes: INVALID_ARGUMENT (400): reque - + -### BinRecord -BinRecord is the usage record of an account in a bin. The API should return the active bin +### PeriodRecord +PeriodRecord is the usage record of an account in a bin. The API should return the active bin record and the subsequent two records that contains potential overflows. @@ -900,7 +900,7 @@ GetPaymentStateReply contains the payment state of an account. | Field | Type | Label | Description | | ----- | ---- | ----- | ----------- | | payment_global_params | [PaymentGlobalParams](#disperser-v2-PaymentGlobalParams) | | global payment vault parameters | -| bin_records | [BinRecord](#disperser-v2-BinRecord) | repeated | off-chain account reservation usage records | +| bin_records | [PeriodRecord](#disperser-v2-PeriodRecord) | repeated | off-chain account reservation usage records | | reservation | [Reservation](#disperser-v2-Reservation) | | on-chain account reservation setting | | cumulative_payment | [bytes](#bytes) | | off-chain on-demand payment usage | | onchain_cumulative_payment | [bytes](#bytes) | | on-chain on-demand payment deposited | diff --git a/api/grpc/disperser/v2/disperser_v2.pb.go b/api/grpc/disperser/v2/disperser_v2.pb.go index 4fb9718f65..833b52bec8 100644 --- a/api/grpc/disperser/v2/disperser_v2.pb.go +++ b/api/grpc/disperser/v2/disperser_v2.pb.go @@ -488,7 +488,7 @@ type GetPaymentStateReply struct { // global payment vault parameters PaymentGlobalParams *PaymentGlobalParams `protobuf:"bytes,1,opt,name=payment_global_params,json=paymentGlobalParams,proto3" json:"payment_global_params,omitempty"` // off-chain account reservation usage records - BinRecords []*BinRecord `protobuf:"bytes,2,rep,name=bin_records,json=binRecords,proto3" json:"bin_records,omitempty"` + PeriodRecords []*PeriodRecord `protobuf:"bytes,2,rep,name=bin_records,json=periodRecords,proto3" json:"bin_records,omitempty"` // on-chain account reservation setting Reservation *Reservation `protobuf:"bytes,3,opt,name=reservation,proto3" json:"reservation,omitempty"` // off-chain on-demand payment usage @@ -536,9 +536,9 @@ func (x *GetPaymentStateReply) GetPaymentGlobalParams() *PaymentGlobalParams { return nil } -func (x *GetPaymentStateReply) GetBinRecords() []*BinRecord { +func (x *GetPaymentStateReply) GetPeriodRecords() []*PeriodRecord { if x != nil { - return x.BinRecords + return x.PeriodRecords } return nil } @@ -941,9 +941,9 @@ func (x *Reservation) GetQuorumSplits() []uint32 { return nil } -// BinRecord is the usage record of an account in a bin. The API should return the active bin +// PeriodRecord is the usage record of an account in a bin. The API should return the active bin // record and the subsequent two records that contains potential overflows. -type BinRecord struct { +type PeriodRecord struct { state protoimpl.MessageState sizeCache protoimpl.SizeCache unknownFields protoimpl.UnknownFields @@ -952,8 +952,8 @@ type BinRecord struct { Usage uint64 `protobuf:"varint,2,opt,name=usage,proto3" json:"usage,omitempty"` } -func (x *BinRecord) Reset() { - *x = BinRecord{} +func (x *PeriodRecord) Reset() { + *x = PeriodRecord{} if protoimpl.UnsafeEnabled { mi := &file_disperser_v2_disperser_v2_proto_msgTypes[13] ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) @@ -961,13 +961,13 @@ func (x *BinRecord) Reset() { } } -func (x *BinRecord) String() string { +func (x *PeriodRecord) String() string { return protoimpl.X.MessageStringOf(x) } -func (*BinRecord) ProtoMessage() {} +func (*PeriodRecord) ProtoMessage() {} -func (x *BinRecord) ProtoReflect() protoreflect.Message { +func (x *PeriodRecord) ProtoReflect() protoreflect.Message { mi := &file_disperser_v2_disperser_v2_proto_msgTypes[13] if protoimpl.UnsafeEnabled && x != nil { ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) @@ -979,19 +979,19 @@ func (x *BinRecord) ProtoReflect() protoreflect.Message { return mi.MessageOf(x) } -// Deprecated: Use BinRecord.ProtoReflect.Descriptor instead. -func (*BinRecord) Descriptor() ([]byte, []int) { +// Deprecated: Use PeriodRecord.ProtoReflect.Descriptor instead. +func (*PeriodRecord) Descriptor() ([]byte, []int) { return file_disperser_v2_disperser_v2_proto_rawDescGZIP(), []int{13} } -func (x *BinRecord) GetIndex() uint32 { +func (x *PeriodRecord) GetIndex() uint32 { if x != nil { return x.Index } return 0 } -func (x *BinRecord) GetUsage() uint64 { +func (x *PeriodRecord) GetUsage() uint64 { if x != nil { return x.Usage } @@ -1203,7 +1203,7 @@ var file_disperser_v2_disperser_v2_proto_goTypes = []interface{}{ (*Attestation)(nil), // 11: disperser.v2.Attestation (*PaymentGlobalParams)(nil), // 12: disperser.v2.PaymentGlobalParams (*Reservation)(nil), // 13: disperser.v2.Reservation - (*BinRecord)(nil), // 14: disperser.v2.BinRecord + (*PeriodRecord)(nil), // 14: disperser.v2.PeriodRecord (*v2.BlobHeader)(nil), // 15: common.v2.BlobHeader (*common.BlobCommitment)(nil), // 16: common.BlobCommitment (*v2.BatchHeader)(nil), // 17: common.v2.BatchHeader @@ -1217,7 +1217,7 @@ var file_disperser_v2_disperser_v2_proto_depIdxs = []int32{ 10, // 4: disperser.v2.BlobStatusReply.blob_verification_info:type_name -> disperser.v2.BlobVerificationInfo 16, // 5: disperser.v2.BlobCommitmentReply.blob_commitment:type_name -> common.BlobCommitment 12, // 6: disperser.v2.GetPaymentStateReply.payment_global_params:type_name -> disperser.v2.PaymentGlobalParams - 14, // 7: disperser.v2.GetPaymentStateReply.bin_records:type_name -> disperser.v2.BinRecord + 14, // 7: disperser.v2.GetPaymentStateReply.bin_records:type_name -> disperser.v2.PeriodRecord 13, // 8: disperser.v2.GetPaymentStateReply.reservation:type_name -> disperser.v2.Reservation 17, // 9: disperser.v2.SignedBatch.header:type_name -> common.v2.BatchHeader 11, // 10: disperser.v2.SignedBatch.attestation:type_name -> disperser.v2.Attestation @@ -1400,7 +1400,7 @@ func file_disperser_v2_disperser_v2_proto_init() { } } file_disperser_v2_disperser_v2_proto_msgTypes[13].Exporter = func(v interface{}, i int) interface{} { - switch v := v.(*BinRecord); i { + switch v := v.(*PeriodRecord); i { case 0: return &v.state case 1: diff --git a/api/proto/disperser/v2/disperser_v2.proto b/api/proto/disperser/v2/disperser_v2.proto index 0cae0f0d1b..8f1ddfe8f0 100644 --- a/api/proto/disperser/v2/disperser_v2.proto +++ b/api/proto/disperser/v2/disperser_v2.proto @@ -79,7 +79,7 @@ message GetPaymentStateReply { // global payment vault parameters PaymentGlobalParams payment_global_params = 1; // off-chain account reservation usage records - repeated BinRecord bin_records = 2; + repeated PeriodRecord bin_records = 2; // on-chain account reservation setting Reservation reservation = 3; // off-chain on-demand payment usage @@ -169,9 +169,9 @@ message Reservation { repeated uint32 quorum_splits = 5; } -// BinRecord is the usage record of an account in a bin. The API should return the active bin +// PeriodRecord is the usage record of an account in a bin. The API should return the active bin // record and the subsequent two records that contains potential overflows. -message BinRecord { +message PeriodRecord { uint32 index = 1; uint64 usage = 2; } diff --git a/core/meterer/offchain_store.go b/core/meterer/offchain_store.go index f651c0206e..14fd0bbc0e 100644 --- a/core/meterer/offchain_store.go +++ b/core/meterer/offchain_store.go @@ -249,7 +249,7 @@ func (s *OffchainStore) GetRelevantOnDemandRecords(ctx context.Context, accountI return prevPayment, nextPayment, nextDataLength, nil } -func (s *OffchainStore) GetBinRecords(ctx context.Context, accountID string, reservationPeriod uint32) ([MinNumBins]*pb.BinRecord, error) { +func (s *OffchainStore) GetPeriodRecords(ctx context.Context, accountID string, reservationPeriod uint32) ([MinNumBins]*pb.PeriodRecord, error) { // Fetch the 3 bins start from the current bin queryInput := &dynamodb.QueryInput{ TableName: aws.String(s.reservationTableName), @@ -263,16 +263,16 @@ func (s *OffchainStore) GetBinRecords(ctx context.Context, accountID string, res } bins, err := s.dynamoClient.QueryWithInput(ctx, queryInput) if err != nil { - return [MinNumBins]*pb.BinRecord{}, fmt.Errorf("failed to query payments for account: %w", err) + return [MinNumBins]*pb.PeriodRecord{}, fmt.Errorf("failed to query payments for account: %w", err) } - records := [MinNumBins]*pb.BinRecord{} + records := [MinNumBins]*pb.PeriodRecord{} for i := 0; i < len(bins) && i < int(MinNumBins); i++ { - binRecord, err := parseBinRecord(bins[i]) + periodRecord, err := parsePeriodRecord(bins[i]) if err != nil { - return [MinNumBins]*pb.BinRecord{}, fmt.Errorf("failed to parse bin %d record: %w", i, err) + return [MinNumBins]*pb.PeriodRecord{}, fmt.Errorf("failed to parse bin %d record: %w", i, err) } - records[i] = binRecord + records[i] = periodRecord } return records, nil @@ -318,7 +318,7 @@ func (s *OffchainStore) GetLargestCumulativePayment(ctx context.Context, account return payment, nil } -func parseBinRecord(bin map[string]types.AttributeValue) (*pb.BinRecord, error) { +func parsePeriodRecord(bin map[string]types.AttributeValue) (*pb.PeriodRecord, error) { reservationPeriod, ok := bin["ReservationPeriod"] if !ok { return nil, errors.New("ReservationPeriod is not present in the response") @@ -349,7 +349,7 @@ func parseBinRecord(bin map[string]types.AttributeValue) (*pb.BinRecord, error) return nil, fmt.Errorf("failed to parse BinUsage: %w", err) } - return &pb.BinRecord{ + return &pb.PeriodRecord{ Index: uint32(reservationPeriodValue), Usage: uint64(binUsageValue), }, nil diff --git a/disperser/apiserver/server_v2.go b/disperser/apiserver/server_v2.go index efe5566500..71f74bcd12 100644 --- a/disperser/apiserver/server_v2.go +++ b/disperser/apiserver/server_v2.go @@ -281,7 +281,7 @@ func (s *DispersalServerV2) GetPaymentState(ctx context.Context, req *pb.GetPaym // off-chain account specific payment state now := uint64(time.Now().Unix()) currentReservationPeriod := meterer.GetReservationPeriod(now, reservationWindow) - binRecords, err := s.meterer.OffchainStore.GetBinRecords(ctx, req.AccountId, currentReservationPeriod) + periodRecords, err := s.meterer.OffchainStore.GetPeriodRecords(ctx, req.AccountId, currentReservationPeriod) if err != nil { s.logger.Debug("failed to get reservation records, use placeholders", "err", err, "accountID", accountID) } @@ -335,7 +335,7 @@ func (s *DispersalServerV2) GetPaymentState(ctx context.Context, req *pb.GetPaym // build reply reply := &pb.GetPaymentStateReply{ PaymentGlobalParams: &paymentGlobalParams, - BinRecords: binRecords[:], + PeriodRecords: periodRecords[:], Reservation: pbReservation, CumulativePayment: largestCumulativePaymentBytes, OnchainCumulativePayment: onchainCumulativePaymentBytes,
    bin_recordsBinRecordPeriodRecord repeated

    off-chain account reservation usage records