Skip to content

Commit

Permalink
uncomment payments code
Browse files Browse the repository at this point in the history
  • Loading branch information
dmanc committed Dec 20, 2024
1 parent 57881ce commit 9546607
Showing 1 changed file with 23 additions and 25 deletions.
48 changes: 23 additions & 25 deletions disperser/apiserver/disperse_blob_v2.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,12 @@ import (
"context"
"errors"
"fmt"
"math/big"
"time"

"github.com/Layr-Labs/eigenda/api"
pb "github.com/Layr-Labs/eigenda/api/grpc/disperser/v2"
"github.com/Layr-Labs/eigenda/core"
corev2 "github.com/Layr-Labs/eigenda/core/v2"
"github.com/Layr-Labs/eigenda/disperser/common"
dispv2 "github.com/Layr-Labs/eigenda/disperser/common/v2"
Expand Down Expand Up @@ -146,34 +148,30 @@ func (s *DispersalServerV2) validateDispersalRequest(ctx context.Context, req *p
if err != nil {
return api.NewErrorInvalidArg(fmt.Sprintf("invalid blob header: %s", err.Error()))
}
// TODO(ian-shim): enable this check for authentication
// if blobHeader.PaymentMetadata == nil {
// return api.NewErrorInvalidArg("payment metadata is required")
// }
// if err = s.authenticator.AuthenticateBlobRequest(blobHeader); err != nil {
// return api.NewErrorInvalidArg(fmt.Sprintf("authentication failed: %s", err.Error()))
// }

// TODO(ian-shim): enable this check when we have payment metadata + authentication in disperser client
// if len(blobHeader.PaymentMetadata.AccountID) == 0 || blobHeader.PaymentMetadata.ReservationPeriod == 0 || blobHeader.PaymentMetadata.CumulativePayment == nil {
// return api.NewErrorInvalidArg("invalid payment metadata")
// }
if err = s.authenticator.AuthenticateBlobRequest(blobHeader); err != nil {
return api.NewErrorInvalidArg(fmt.Sprintf("authentication failed: %s", err.Error()))
}

if len(blobHeader.PaymentMetadata.AccountID) == 0 || blobHeader.PaymentMetadata.ReservationPeriod == 0 || blobHeader.PaymentMetadata.CumulativePayment == nil {
return api.NewErrorInvalidArg("invalid payment metadata")
}

// handle payments and check rate limits
// reservationPeriod := blobHeaderProto.GetPaymentHeader().GetReservationPeriod()
// cumulativePayment := new(big.Int).SetBytes(blobHeaderProto.GetPaymentHeader().GetCumulativePayment())
// accountID := blobHeaderProto.GetPaymentHeader().GetAccountId()

// paymentHeader := core.PaymentMetadata{
// AccountID: accountID,
// ReservationPeriod: reservationPeriod,
// CumulativePayment: cumulativePayment,
// }

// err := s.meterer.MeterRequest(ctx, paymentHeader, blobLength, blobHeader.QuorumNumbers)
// if err != nil {
// return api.NewErrorResourceExhausted(err.Error())
// }
reservationPeriod := blobHeaderProto.GetPaymentHeader().GetReservationPeriod()
cumulativePayment := new(big.Int).SetBytes(blobHeaderProto.GetPaymentHeader().GetCumulativePayment())
accountID := blobHeaderProto.GetPaymentHeader().GetAccountId()

paymentHeader := core.PaymentMetadata{
AccountID: accountID,
ReservationPeriod: reservationPeriod,
CumulativePayment: cumulativePayment,
}

err = s.meterer.MeterRequest(ctx, paymentHeader, blobLength, blobHeader.QuorumNumbers)
if err != nil {
return api.NewErrorResourceExhausted(err.Error())
}

commitments, err := s.prover.GetCommitmentsForPaddedLength(data)
if err != nil {
Expand Down

0 comments on commit 9546607

Please sign in to comment.