Skip to content

Commit

Permalink
refactor: minor updates and cleanup
Browse files Browse the repository at this point in the history
  • Loading branch information
hopeyen committed Oct 8, 2024
1 parent e98e773 commit c55e7c0
Showing 1 changed file with 3 additions and 58 deletions.
61 changes: 3 additions & 58 deletions core/meterer/offchain_store.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@ import (
commonaws "github.com/Layr-Labs/eigenda/common/aws"
commondynamodb "github.com/Layr-Labs/eigenda/common/aws/dynamodb"
"github.com/Layr-Labs/eigensdk-go/logging"
"github.com/aws/aws-sdk-go-v2/feature/dynamodb/attributevalue"
"github.com/aws/aws-sdk-go-v2/service/dynamodb/types"
)

Expand Down Expand Up @@ -90,12 +89,7 @@ func (s *OffchainStore) UpdateReservationBin(ctx context.Context, accountID stri
"BinIndex": &types.AttributeValueMemberN{Value: strconv.FormatUint(binIndex, 10)},
}

update := map[string]types.AttributeValue{
"BinUsage": &types.AttributeValueMemberN{Value: strconv.FormatUint(uint64(size), 10)},
}

fmt.Println("increment the item in a table", s.reservationTableName)
res, err := s.dynamoClient.UpdateItemIncrement(ctx, s.reservationTableName, key, update)
res, err := s.dynamoClient.IncrementBy(ctx, s.reservationTableName, key, "BinUsage", size)
if err != nil {
return 0, fmt.Errorf("failed to increment bin usage: %w", err)
}
Expand All @@ -118,15 +112,12 @@ func (s *OffchainStore) UpdateReservationBin(ctx context.Context, accountID stri
return binUsageValue, nil
}

func (s *OffchainStore) UpdateGlobalBin(ctx context.Context, binIndex uint64, size uint32) (uint64, error) {
func (s *OffchainStore) UpdateGlobalBin(ctx context.Context, binIndex uint64, size uint64) (uint64, error) {
key := map[string]types.AttributeValue{
"BinIndex": &types.AttributeValueMemberN{Value: strconv.FormatUint(binIndex, 10)},
}

update := map[string]types.AttributeValue{
"BinUsage": &types.AttributeValueMemberN{Value: strconv.FormatUint(uint64(size), 10)},
}
res, err := s.dynamoClient.UpdateItemIncrement(ctx, s.globalBinTableName, key, update)
res, err := s.dynamoClient.IncrementBy(ctx, s.globalBinTableName, key, "BinUsage", size)
if err != nil {
return 0, err
}
Expand All @@ -149,52 +140,6 @@ func (s *OffchainStore) UpdateGlobalBin(ctx context.Context, binIndex uint64, si
return binUsageValue, nil
}

func (s *OffchainStore) FindReservationBin(ctx context.Context, accountID string, binIndex uint64) (*ReservationBin, error) {
key := map[string]types.AttributeValue{
"AccountID": &types.AttributeValueMemberS{Value: accountID},
"BinIndex": &types.AttributeValueMemberN{Value: strconv.FormatUint(binIndex, 10)},
}

result, err := s.dynamoClient.GetItem(ctx, s.reservationTableName, key)
if err != nil {
return nil, err
}

if result == nil {
return nil, errors.New("reservation not found")
}

var reservation ReservationBin
err = attributevalue.UnmarshalMap(result, &reservation)
if err != nil {
return nil, err
}

return &reservation, nil
}

// Find all reservation bins for a given account
func (s *OffchainStore) FindReservationBins(ctx context.Context, accountID string) ([]ReservationBin, error) {
result, err := s.dynamoClient.QueryIndex(ctx, s.reservationTableName, "AccountIDIndex", "AccountID = :accountID", commondynamodb.ExpresseionValues{
":accountID": &types.AttributeValueMemberS{Value: accountID},
})
if err != nil {
return nil, err
}

if result == nil {
return nil, errors.New("reservation not found")
}

var reservations []ReservationBin
err = attributevalue.UnmarshalListOfMaps(result, &reservations)
if err != nil {
return nil, err
}

return reservations, nil
}

func (s *OffchainStore) AddOnDemandPayment(ctx context.Context, blobHeader BlobHeader, blobSizeCharged uint32) error {
result, err := s.dynamoClient.GetItem(ctx, s.onDemandTableName,
commondynamodb.Item{
Expand Down

0 comments on commit c55e7c0

Please sign in to comment.