diff --git a/api/clients/v2/accountant.go b/api/clients/v2/accountant.go index 97fde8ca11..b0b3685656 100644 --- a/api/clients/v2/accountant.go +++ b/api/clients/v2/accountant.go @@ -182,41 +182,48 @@ func (a *Accountant) SetPaymentState(paymentState *disperser_rpc.GetPaymentState return fmt.Errorf("payment state cannot be nil") } else if paymentState.GetPaymentGlobalParams() == nil { return fmt.Errorf("payment global params cannot be nil") - } else if paymentState.GetOnchainCumulativePayment() == nil { - return fmt.Errorf("onchain cumulative payment cannot be nil") - } else if paymentState.GetCumulativePayment() == nil { - return fmt.Errorf("cumulative payment cannot be nil") - } else if paymentState.GetReservation() == nil { - 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().GetQuorumSplits() == nil { - return fmt.Errorf("reservation quorum split cannot be nil") } else if paymentState.GetBinRecords() == nil { return fmt.Errorf("bin records cannot be nil") } a.minNumSymbols = uint32(paymentState.GetPaymentGlobalParams().GetMinNumSymbols()) - a.onDemand.CumulativePayment = new(big.Int).SetBytes(paymentState.GetOnchainCumulativePayment()) - a.cumulativePayment = new(big.Int).SetBytes(paymentState.GetCumulativePayment()) a.pricePerSymbol = uint32(paymentState.GetPaymentGlobalParams().GetPricePerSymbol()) - - a.reservation.SymbolsPerSecond = uint64(paymentState.GetPaymentGlobalParams().GetGlobalSymbolsPerSecond()) - a.reservation.StartTimestamp = uint64(paymentState.GetReservation().GetStartTimestamp()) - a.reservation.EndTimestamp = uint64(paymentState.GetReservation().GetEndTimestamp()) a.reservationWindow = uint32(paymentState.GetPaymentGlobalParams().GetReservationWindow()) - quorumNumbers := make([]uint8, len(paymentState.GetReservation().GetQuorumNumbers())) - for i, quorum := range paymentState.GetReservation().GetQuorumNumbers() { - quorumNumbers[i] = uint8(quorum) - } - a.reservation.QuorumNumbers = quorumNumbers + if paymentState.GetOnchainCumulativePayment() == nil { + a.onDemand.CumulativePayment = big.NewInt(0) + } else { + a.onDemand.CumulativePayment = new(big.Int).SetBytes(paymentState.GetOnchainCumulativePayment()) + } + + if paymentState.GetCumulativePayment() == nil { + a.cumulativePayment = big.NewInt(0) + } else { + a.cumulativePayment = new(big.Int).SetBytes(paymentState.GetCumulativePayment()) + } + + if paymentState.GetReservation() == nil { + a.reservation.SymbolsPerSecond = uint64(0) + a.reservation.StartTimestamp = uint64(0) + a.reservation.EndTimestamp = uint64(0) + a.reservation.QuorumNumbers = make([]uint8, 0) + a.reservation.QuorumSplits = make([]uint8, 0) + } else { + a.reservation.SymbolsPerSecond = uint64(paymentState.GetReservation().GetSymbolsPerSecond()) + a.reservation.StartTimestamp = uint64(paymentState.GetReservation().GetStartTimestamp()) + a.reservation.EndTimestamp = uint64(paymentState.GetReservation().GetEndTimestamp()) + quorumNumbers := make([]uint8, len(paymentState.GetReservation().GetQuorumNumbers())) + for i, quorum := range paymentState.GetReservation().GetQuorumNumbers() { + quorumNumbers[i] = uint8(quorum) + } + a.reservation.QuorumNumbers = quorumNumbers - quorumSplits := make([]uint8, len(paymentState.GetReservation().GetQuorumSplits())) - for i, quorum := range paymentState.GetReservation().GetQuorumSplits() { - quorumSplits[i] = uint8(quorum) + quorumSplits := make([]uint8, len(paymentState.GetReservation().GetQuorumSplits())) + for i, quorum := range paymentState.GetReservation().GetQuorumSplits() { + quorumSplits[i] = uint8(quorum) + } + a.reservation.QuorumSplits = quorumSplits } - a.reservation.QuorumSplits = quorumSplits binRecords := make([]BinRecord, len(paymentState.GetBinRecords())) for i, record := range paymentState.GetBinRecords() { diff --git a/api/clients/v2/disperser_client.go b/api/clients/v2/disperser_client.go index 4e54fa3e52..8e83482421 100644 --- a/api/clients/v2/disperser_client.go +++ b/api/clients/v2/disperser_client.go @@ -3,11 +3,13 @@ package clients import ( "context" "fmt" + "math/big" "sync" "github.com/Layr-Labs/eigenda/api" disperser_rpc "github.com/Layr-Labs/eigenda/api/grpc/disperser/v2" "github.com/Layr-Labs/eigenda/core" + "github.com/Layr-Labs/eigenda/core/meterer" corev2 "github.com/Layr-Labs/eigenda/core/v2" dispv2 "github.com/Layr-Labs/eigenda/disperser/common/v2" "github.com/Layr-Labs/eigenda/encoding" @@ -80,7 +82,27 @@ func NewDisperserClient(config *DisperserClientConfig, signer corev2.BlobRequest if err != nil { return nil, fmt.Errorf("error getting signer's account ID: %w", err) } - accountant = DummyAccountant(accountID) + // accountant = DummyAccountant(accountID) + accountant = &Accountant{ + accountID: accountID, + reservation: &core.ReservedPayment{ + SymbolsPerSecond: 0, + StartTimestamp: 0, + EndTimestamp: 0, + QuorumNumbers: []uint8{}, + QuorumSplits: []byte{}, + }, + onDemand: &core.OnDemandPayment{ + CumulativePayment: big.NewInt(0), + }, + reservationWindow: 0, + pricePerSymbol: 0, + minNumSymbols: 0, + binRecords: make([]BinRecord, 3), + usageLock: sync.Mutex{}, + cumulativePayment: big.NewInt(0), + numBins: uint32(meterer.MinNumBins), + } } return &disperserClient{ diff --git a/core/meterer/offchain_store.go b/core/meterer/offchain_store.go index 4481d2cce2..2e2f8eed8b 100644 --- a/core/meterer/offchain_store.go +++ b/core/meterer/offchain_store.go @@ -310,6 +310,7 @@ func (s *OffchainStore) GetLargestCumulativePayment(ctx context.Context, account return nil, fmt.Errorf("failed to query payments for account: %w", err) } + fmt.Println("Get largest cumulative payment", payments) if len(payments) == 0 { return big.NewInt(0), nil } diff --git a/disperser/apiserver/server_v2.go b/disperser/apiserver/server_v2.go index 070f678427..0df11a9971 100644 --- a/disperser/apiserver/server_v2.go +++ b/disperser/apiserver/server_v2.go @@ -303,8 +303,10 @@ func (s *DispersalServerV2) GetPaymentState(ctx context.Context, req *pb.GetPaym } // build reply reply := &pb.GetPaymentStateReply{ - PaymentGlobalParams: &paymentGlobalParams, - BinRecords: binRecords[:], + PaymentGlobalParams: &paymentGlobalParams, + BinRecords: binRecords[:], + CumulativePayment: largestCumulativePayment.Bytes(), + OnchainCumulativePayment: onDemandPayment.CumulativePayment.Bytes(), Reservation: &pb.Reservation{ SymbolsPerSecond: reservation.SymbolsPerSecond, StartTimestamp: uint32(reservation.StartTimestamp), @@ -312,8 +314,8 @@ func (s *DispersalServerV2) GetPaymentState(ctx context.Context, req *pb.GetPaym QuorumSplits: quorumSplits, QuorumNumbers: quorumNumbers, }, - CumulativePayment: largestCumulativePayment.Bytes(), - OnchainCumulativePayment: onDemandPayment.CumulativePayment.Bytes(), } + + fmt.Println("GetPaymentState reply", reply, largestCumulativePayment, onDemandPayment.CumulativePayment) return reply, nil }