From 407ea882345146e8da4a85b3fe9cf6dc1b2f5555 Mon Sep 17 00:00:00 2001 From: hopeyen <60078528+hopeyen@users.noreply.github.com> Date: Mon, 16 Dec 2024 21:40:57 +0000 Subject: [PATCH] refactor: minor cleanup --- api/clients/v2/disperser_client.go | 29 +---------------------------- core/indexer/indexer_suite_test.go | 1 + core/meterer/offchain_store.go | 1 - core/meterer/onchain_state.go | 2 -- disperser/apiserver/server_v2.go | 13 ++++--------- 5 files changed, 6 insertions(+), 40 deletions(-) diff --git a/api/clients/v2/disperser_client.go b/api/clients/v2/disperser_client.go index 8e83482421..39b694d3a5 100644 --- a/api/clients/v2/disperser_client.go +++ b/api/clients/v2/disperser_client.go @@ -3,13 +3,11 @@ 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" @@ -82,27 +80,7 @@ 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 = &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), - } + accountant = DummyAccountant(accountID) } return &disperserClient{ @@ -254,28 +232,23 @@ func (c *disperserClient) GetBlobStatus(ctx context.Context, blobKey corev2.Blob func (c *disperserClient) GetPaymentState(ctx context.Context) (*disperser_rpc.GetPaymentStateReply, error) { err := c.initOnceGrpcConnection() if err != nil { - fmt.Println(err.Error()) return nil, api.NewErrorInternal(err.Error()) } accountID, err := c.signer.GetAccountID() if err != nil { - fmt.Println(err.Error()) return nil, fmt.Errorf("error getting signer's account ID: %w", err) } signature, err := c.signer.SignPaymentStateRequest() if err != nil { - fmt.Println(err.Error()) return nil, fmt.Errorf("error signing payment state request: %w", err) } - fmt.Println("build request") request := &disperser_rpc.GetPaymentStateRequest{ AccountId: accountID, Signature: signature, } - fmt.Println("built request", accountID, signature) return c.client.GetPaymentState(ctx, request) } diff --git a/core/indexer/indexer_suite_test.go b/core/indexer/indexer_suite_test.go index 03dd4e5cbf..1867c73aac 100644 --- a/core/indexer/indexer_suite_test.go +++ b/core/indexer/indexer_suite_test.go @@ -45,6 +45,7 @@ var _ = BeforeSuite(func() { testConfig.Deployers[0].DeploySubgraphs = false if testConfig.Environment.IsLocal() { + fmt.Println("Starting anvil") testConfig.StartAnvil() fmt.Println("Deploying experiment") diff --git a/core/meterer/offchain_store.go b/core/meterer/offchain_store.go index 2e2f8eed8b..4481d2cce2 100644 --- a/core/meterer/offchain_store.go +++ b/core/meterer/offchain_store.go @@ -310,7 +310,6 @@ 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/core/meterer/onchain_state.go b/core/meterer/onchain_state.go index 367e0c7813..aa28ecf94a 100644 --- a/core/meterer/onchain_state.go +++ b/core/meterer/onchain_state.go @@ -2,7 +2,6 @@ package meterer import ( "context" - "fmt" "sync" "sync/atomic" @@ -145,7 +144,6 @@ func (pcs *OnchainPaymentState) GetReservedPaymentByAccount(ctx context.Context, pcs.ReservationsLock.Lock() defer pcs.ReservationsLock.Unlock() if reservation, ok := (pcs.ReservedPayments)[accountID]; ok { - fmt.Println("found reservation in cache", accountID) return reservation, nil } diff --git a/disperser/apiserver/server_v2.go b/disperser/apiserver/server_v2.go index 0df11a9971..92f41d93b9 100644 --- a/disperser/apiserver/server_v2.go +++ b/disperser/apiserver/server_v2.go @@ -256,21 +256,18 @@ func (s *DispersalServerV2) GetPaymentState(ctx context.Context, req *pb.GetPaym currentReservationPeriod := meterer.GetReservationPeriod(now, reservationWindow) binRecords, err := s.meterer.OffchainStore.GetBinRecords(ctx, req.AccountId, currentReservationPeriod) if err != nil { - s.logger.Debug("failed to get active reservation", err, accountID) - // return nil, api.NewErrorNotFound("failed to get active reservation") + s.logger.Debug("failed to get reservation records, use placeholders", err, accountID) binRecords = [3]*pb.BinRecord{} } largestCumulativePayment, err := s.meterer.OffchainStore.GetLargestCumulativePayment(ctx, req.AccountId) if err != nil { - s.logger.Debug("err get largest cumulative payment", err) - // return nil, api.NewErrorNotFound("failed to get largest cumulative payment") + s.logger.Debug("failed to get largest cumulative payment, use zero value", err) largestCumulativePayment = big.NewInt(0) } // on-Chain account state reservation, err := s.meterer.ChainPaymentState.GetReservedPaymentByAccount(ctx, accountID) if err != nil { - s.logger.Debug("cannot get reservation", err) - // return nil, api.NewErrorNotFound("failed to get active reservation") + s.logger.Debug("failed to get onchain reservation, use zero values", err) reservation = &core.ReservedPayment{ SymbolsPerSecond: 0, StartTimestamp: 0, @@ -281,8 +278,7 @@ func (s *DispersalServerV2) GetPaymentState(ctx context.Context, req *pb.GetPaym } onDemandPayment, err := s.meterer.ChainPaymentState.GetOnDemandPaymentByAccount(ctx, accountID) if err != nil { - s.logger.Debug("cannot get ondemand payment", err) - // return nil, api.NewErrorNotFound("failed to get on-demand payment") + s.logger.Debug("failed to get ondemand payment, use zero value", err) onDemandPayment = &core.OnDemandPayment{CumulativePayment: big.NewInt(0)} } @@ -316,6 +312,5 @@ func (s *DispersalServerV2) GetPaymentState(ctx context.Context, req *pb.GetPaym }, } - fmt.Println("GetPaymentState reply", reply, largestCumulativePayment, onDemandPayment.CumulativePayment) return reply, nil }