Skip to content

Commit

Permalink
refactor: minor cleanup
Browse files Browse the repository at this point in the history
  • Loading branch information
hopeyen committed Dec 16, 2024
1 parent 09bf5b1 commit 407ea88
Show file tree
Hide file tree
Showing 5 changed files with 6 additions and 40 deletions.
29 changes: 1 addition & 28 deletions api/clients/v2/disperser_client.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -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{
Expand Down Expand Up @@ -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)
}

Expand Down
1 change: 1 addition & 0 deletions core/indexer/indexer_suite_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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")
Expand Down
1 change: 0 additions & 1 deletion core/meterer/offchain_store.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
Expand Down
2 changes: 0 additions & 2 deletions core/meterer/onchain_state.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ package meterer

import (
"context"
"fmt"
"sync"
"sync/atomic"

Expand Down Expand Up @@ -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
}

Expand Down
13 changes: 4 additions & 9 deletions disperser/apiserver/server_v2.go
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -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)}
}

Expand Down Expand Up @@ -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
}

0 comments on commit 407ea88

Please sign in to comment.