Skip to content

Commit

Permalink
remove gas meter
Browse files Browse the repository at this point in the history
  • Loading branch information
oren-lava committed Mar 14, 2024
1 parent c4a3989 commit 092146b
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 8 deletions.
6 changes: 6 additions & 0 deletions x/pairing/keeper/epoch_payments.go
Original file line number Diff line number Diff line change
Expand Up @@ -117,6 +117,12 @@ func (k Keeper) NewEpochPaymentHandler(ctx sdk.Context) EpochPaymentHandler {
}
}

func (k EpochPaymentHandler) Flush() {
k.EpochPaymentsCache.Write()
k.ProviderPaymentStorageCache.Write()
k.UniquePaymentStorageClientProviderCache.Write()
}

// Function to add an epoch payment to the epochPayments object
func (k EpochPaymentHandler) AddEpochPayment(ctx sdk.Context, chainID string, epoch uint64, projectID string, providerAddress sdk.AccAddress, usedCU uint64, uniqueIdentifier string) uint64 {
if epoch < k.epochStorageKeeper.GetEarliestEpochStart(ctx) {
Expand Down
9 changes: 1 addition & 8 deletions x/pairing/keeper/msg_server_relay_payment.go
Original file line number Diff line number Diff line change
Expand Up @@ -159,7 +159,6 @@ func (k msgServer) RelayPayment(goCtx context.Context, msg *types.MsgRelayPaymen
// fail the TX ***

totalCUInEpochForUserProvider := paymentHandler.AddEpochPayment(ctx, relay.SpecId, epochStart, project.Index, providerAddr, relay.CuSum, strconv.FormatUint(relay.SessionId, 16))
ctx.GasMeter().RefundGas(ctx.GasMeter().GasConsumed(), "")
if badgeFound {
k.handleBadgeCu(ctx, badgeData, relay.Provider, relay.CuSum, newBadgeTimerExpiry)
}
Expand Down Expand Up @@ -318,13 +317,7 @@ func (k msgServer) RelayPayment(goCtx context.Context, msg *types.MsgRelayPaymen
}
utils.LogLavaEvent(ctx, logger, types.LatestBlocksReportEventName, latestBlockReports, "New LatestBlocks Report for provider")

paymentHandler.EpochPaymentsCache.Write()
paymentHandler.ProviderPaymentStorageCache.Write()
paymentHandler.UniquePaymentStorageClientProviderCache.Write()

// consume constant gas (dependent on the number of relays)
ctx.GasMeter().RefundGas(ctx.GasMeter().GasConsumed(), "")
ctx.GasMeter().ConsumeGas(uint64(10000+100000*len(msg.Relays)), "")
paymentHandler.Flush()

return &types.MsgRelayPaymentResponse{RejectedRelays: rejected_relays}, nil
}
Expand Down

0 comments on commit 092146b

Please sign in to comment.