Skip to content

Commit

Permalink
even better
Browse files Browse the repository at this point in the history
  • Loading branch information
Yaroms committed Mar 17, 2024
1 parent 092146b commit d7df249
Show file tree
Hide file tree
Showing 3 changed files with 6 additions and 9 deletions.
2 changes: 1 addition & 1 deletion x/pairing/keeper/msg_server_relay_payment.go
Original file line number Diff line number Diff line change
Expand Up @@ -144,7 +144,7 @@ func (k msgServer) RelayPayment(goCtx context.Context, msg *types.MsgRelayPaymen
continue
}

if k.IsDoubleSpend(ctx, relay.SpecId, epochStart, project.Index, providerAddr, strconv.FormatUint(relay.SessionId, 16)) {
if paymentHandler.IsDoubleSpend(ctx, relay.SpecId, epochStart, project.Index, providerAddr, strconv.FormatUint(relay.SessionId, 16)) {
utils.LavaFormatWarning("double spending detected", err,
utils.Attribute{Key: "epoch", Value: epochStart},
utils.Attribute{Key: "client", Value: clientAddr.String()},
Expand Down
5 changes: 1 addition & 4 deletions x/pairing/keeper/provider_payment_storage.go
Original file line number Diff line number Diff line change
Expand Up @@ -137,10 +137,7 @@ func (k EpochPaymentHandler) GetTotalUsedCUForConsumerPerEpoch(ctx sdk.Context,
// get the uniquePaymentStorageClientProvider object
uniquePayment, found := k.GetUniquePaymentStorageClientProviderCached(ctx, uniquePaymentKey)
if !found {
uniquePayment, found = k.GetUniquePaymentStorageClientProvider(ctx, uniquePaymentKey)
if found {
k.SetUniquePaymentStorageClientProviderCached(ctx, uniquePayment)
}
k.SetUniquePaymentStorageClientProviderCached(ctx, uniquePayment)
}
if !found {
utils.LavaFormatError("could not find uniquePaymentStorageClientProvider object", fmt.Errorf("unique payment object not found"),
Expand Down
8 changes: 4 additions & 4 deletions x/pairing/keeper/unique_payment_storage_client_provider.go
Original file line number Diff line number Diff line change
Expand Up @@ -78,16 +78,16 @@ func (k Keeper) GetAllUniquePaymentStorageClientProvider(ctx sdk.Context) (list
return
}

func (k Keeper) AddUniquePaymentStorageClientProvider(ctx sdk.Context, chainID string, block uint64, projectID string, providerAddress sdk.AccAddress, uniqueIdentifier string, usedCU uint64) *types.UniquePaymentStorageClientProvider {
func (k EpochPaymentHandler) AddUniquePaymentStorageClientProvider(ctx sdk.Context, chainID string, block uint64, projectID string, providerAddress sdk.AccAddress, uniqueIdentifier string, usedCU uint64) *types.UniquePaymentStorageClientProvider {
key := k.EncodeUniquePaymentKey(ctx, projectID, providerAddress, uniqueIdentifier, chainID)
entry := types.UniquePaymentStorageClientProvider{Index: key, Block: block, UsedCU: usedCU}
k.SetUniquePaymentStorageClientProvider(ctx, entry)
k.SetUniquePaymentStorageClientProviderCached(ctx, entry)
return &entry
}

func (k Keeper) IsDoubleSpend(ctx sdk.Context, chainID string, block uint64, projectID string, providerAddress sdk.AccAddress, uniqueIdentifier string) bool {
func (k EpochPaymentHandler) IsDoubleSpend(ctx sdk.Context, chainID string, block uint64, projectID string, providerAddress sdk.AccAddress, uniqueIdentifier string) bool {
key := k.EncodeUniquePaymentKey(ctx, projectID, providerAddress, uniqueIdentifier, chainID)
_, found := k.GetUniquePaymentStorageClientProvider(ctx, key)
_, found := k.GetUniquePaymentStorageClientProviderCached(ctx, key)
return found
}

Expand Down

0 comments on commit d7df249

Please sign in to comment.