From 9a47eb8fbbc8236731c3547a2dd3e7669717fdb3 Mon Sep 17 00:00:00 2001 From: Jonathan Harvey-Buschel Date: Thu, 14 Dec 2023 12:31:00 -0500 Subject: [PATCH] tapcli+rpcserver: switch manual fee unit to sat/vB --- cmd/tapcli/assets.go | 20 +++++++++++++++----- rpcserver.go | 20 +++++++++----------- 2 files changed, 24 insertions(+), 16 deletions(-) diff --git a/cmd/tapcli/assets.go b/cmd/tapcli/assets.go index 6626a8f26..50ff5b5eb 100644 --- a/cmd/tapcli/assets.go +++ b/cmd/tapcli/assets.go @@ -10,6 +10,7 @@ import ( "github.com/lightninglabs/taproot-assets/tapcfg" "github.com/lightninglabs/taproot-assets/taprpc" "github.com/lightninglabs/taproot-assets/taprpc/mintrpc" + "github.com/lightningnetwork/lnd/lnwallet/chainfee" "github.com/urfave/cli" ) @@ -50,7 +51,7 @@ var ( groupByGroupName = "by_group" assetIDName = "asset_id" shortResponseName = "short" - feeRateName = "fee_rate" + feeRateName = "sat_per_vbyte" assetAmountName = "amount" burnOverrideConfirmationName = "override_confirmation_destroy_assets" ) @@ -261,7 +262,7 @@ var finalizeBatchCommand = cli.Command{ }, cli.Uint64Flag{ Name: feeRateName, - Usage: "if set, the fee rate in sat/kw to use for " + + Usage: "if set, the fee rate in sat/vB to use for " + "the minting transaction", }, }, @@ -270,11 +271,20 @@ var finalizeBatchCommand = cli.Command{ func parseFeeRate(ctx *cli.Context) (uint32, error) { if ctx.IsSet(feeRateName) { - feeRate := ctx.Uint64(feeRateName) - if feeRate > math.MaxUint32 { + userFeeRate := ctx.Uint64(feeRateName) + if userFeeRate > math.MaxUint32 { return 0, fmt.Errorf("fee rate exceeds 2^32") } + // Convert from sat/vB to sat/kw. Round up to the fee floor if + // the specified feerate is too low. + feeRate := chainfee.SatPerKVByte(userFeeRate * 1000). + FeePerKWeight() + + if feeRate < chainfee.FeePerKwFloor { + feeRate = chainfee.FeePerKwFloor + } + return uint32(feeRate), nil } @@ -531,7 +541,7 @@ var sendAssetsCommand = cli.Command{ }, cli.Uint64Flag{ Name: feeRateName, - Usage: "if set, the fee rate in sat/kw to use for " + + Usage: "if set, the fee rate in sat/vB to use for " + "the anchor transaction", }, // TODO(roasbeef): add arg for file name to write sender proof diff --git a/rpcserver.go b/rpcserver.go index edb739c54..16da1bf6d 100644 --- a/rpcserver.go +++ b/rpcserver.go @@ -491,26 +491,24 @@ func (r *rpcServer) MintAsset(ctx context.Context, } } -// checkFeeRateSanity ensures that the provided fee rate is above the same -// minimum fee used as a floor in the fee estimator. +// checkFeeRateSanity ensures that the provided fee rate, in sat/kw, is above +// the same minimum fee used as a floor in the fee estimator. func checkFeeRateSanity(rpcFeeRate uint32) (*chainfee.SatPerKWeight, error) { - var feeRate *chainfee.SatPerKWeight + feeFloor := uint32(chainfee.FeePerKwFloor) switch { // No manual fee rate was set, which is the default. case rpcFeeRate == 0: + return nil, nil // A manual fee was set but is below a reasonable floor. - case rpcFeeRate < uint32(chainfee.FeePerKwFloor): - return nil, fmt.Errorf("manual fee rate %d below floor of %d", - rpcFeeRate, uint32(chainfee.FeePerKwFloor)) + case rpcFeeRate < feeFloor: + return nil, fmt.Errorf("manual fee rate below floor: "+ + "(fee_rate=%d, floor=%d sat/kw)", rpcFeeRate, feeFloor) + // Set the fee rate for this transaction. default: - // Set the fee rate for this transaction. - manualFeeRate := chainfee.SatPerKWeight(rpcFeeRate) - feeRate = &manualFeeRate + return fn.Ptr(chainfee.SatPerKWeight(rpcFeeRate)), nil } - - return feeRate, nil } // FinalizeBatch attempts to finalize the current pending batch.