Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 3 additions & 4 deletions supernode/services/cascade/adaptors/lumera.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,9 +18,8 @@ type LumeraClient interface {

// Action Module
GetAction(ctx context.Context, actionID string) (*actiontypes.QueryGetActionResponse, error)
GetActionParams(ctx context.Context) (*actiontypes.QueryParamsResponse, error)
FinalizeAction(ctx context.Context, actionID string, rqids []string) (*action_msg.FinalizeActionResult, error)

GetActionFee(ctx context.Context, dataSize string) (*actiontypes.QueryGetActionFeeResponse, error)
// Auth
Verify(ctx context.Context, creator string, file []byte, sigBytes []byte) error
}
Expand All @@ -40,8 +39,8 @@ func (c *Client) GetAction(ctx context.Context, actionID string) (*actiontypes.Q
return c.lc.Action().GetAction(ctx, actionID)
}

func (c *Client) GetActionParams(ctx context.Context) (*actiontypes.QueryParamsResponse, error) {
return c.lc.Action().GetParams(ctx)
func (c *Client) GetActionFee(ctx context.Context, dataSize string) (*actiontypes.QueryGetActionFeeResponse, error) {
return c.lc.Action().GetActionFee(ctx, dataSize)
}

func (c *Client) FinalizeAction(ctx context.Context, actionID string, rqids []string) (*action_msg.FinalizeActionResult, error) {
Expand Down
21 changes: 11 additions & 10 deletions supernode/services/cascade/helper.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import (
"context"
"encoding/base64"
"fmt"
"strconv"
"strings"

"cosmossdk.io/math"
Expand Down Expand Up @@ -201,21 +202,21 @@ func verifyIDs(ticketMetadata, metadata codec.Layout) error {
// verifyActionFee checks if the action fee is sufficient for the given data size
// It fetches action parameters, calculates the required fee, and compares it with the action price
func (task *CascadeRegistrationTask) verifyActionFee(ctx context.Context, action *actiontypes.Action, dataSize int, fields logtrace.Fields) error {
// Fetch action parameters
params, err := task.lumeraClient.GetActionParams(ctx)

dataSizeInKBs := dataSize / 1024
fee, err := task.lumeraClient.GetActionFee(ctx, strconv.Itoa(dataSizeInKBs))
if err != nil {
return task.wrapErr(ctx, "failed to get action parameters", err, fields)
return task.wrapErr(ctx, "failed to get action fee", err, fields)
}

// Get base fee and fee per byte
baseFee := params.Params.BaseActionFee
feePerByte := params.Params.FeePerByte.Amount
// Parse fee amount from string to int64
amount, err := strconv.ParseInt(fee.Amount, 10, 64)
if err != nil {
return task.wrapErr(ctx, "failed to parse fee amount", err, fields)
}

// Calculate per-byte fee based on data size
perByteFee := sdk.NewCoin(baseFee.Denom, feePerByte.Mul(math.NewInt(int64(dataSize))))

// Calculate total fee
requiredFee := baseFee.Add(perByteFee)
requiredFee := sdk.NewCoin("ulume", math.NewInt(amount))

// Log the calculated fee
logtrace.Info(ctx, "calculated required fee", logtrace.Fields{
Expand Down