Skip to content

Commit

Permalink
feat: add isActive check to reserved payments
Browse files Browse the repository at this point in the history
  • Loading branch information
hopeyen committed Dec 12, 2024
1 parent b41ff1d commit 87e6eec
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 0 deletions.
6 changes: 6 additions & 0 deletions core/data.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import (
"fmt"
"math/big"
"strconv"
"time"

commonpb "github.com/Layr-Labs/eigenda/api/grpc/common"
"github.com/Layr-Labs/eigenda/common"
Expand Down Expand Up @@ -625,3 +626,8 @@ type BlobVersionParameters struct {
MaxNumOperators uint32
NumChunks uint32
}

func (ar *ReservedPayment) IsActive() bool {
now := uint64(time.Now().Unix())
return ar.StartTimestamp <= now && ar.EndTimestamp >= now
}
3 changes: 3 additions & 0 deletions core/meterer/meterer.go
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,9 @@ func (m *Meterer) MeterRequest(ctx context.Context, header core.PaymentMetadata,
if err != nil {
return fmt.Errorf("failed to get active reservation by account: %w", err)
}
if !reservation.IsActive() {
return fmt.Errorf("reservation not active")
}
if err := m.ServeReservationRequest(ctx, header, reservation, numSymbols, quorumNumbers); err != nil {
return fmt.Errorf("invalid reservation: %w", err)
}
Expand Down

0 comments on commit 87e6eec

Please sign in to comment.