Skip to content

Commit 9a47eb8

Browse files
committed
tapcli+rpcserver: switch manual fee unit to sat/vB
1 parent b8624ed commit 9a47eb8

File tree

2 files changed

+24
-16
lines changed

2 files changed

+24
-16
lines changed

cmd/tapcli/assets.go

Lines changed: 15 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ import (
1010
"github.com/lightninglabs/taproot-assets/tapcfg"
1111
"github.com/lightninglabs/taproot-assets/taprpc"
1212
"github.com/lightninglabs/taproot-assets/taprpc/mintrpc"
13+
"github.com/lightningnetwork/lnd/lnwallet/chainfee"
1314
"github.com/urfave/cli"
1415
)
1516

@@ -50,7 +51,7 @@ var (
5051
groupByGroupName = "by_group"
5152
assetIDName = "asset_id"
5253
shortResponseName = "short"
53-
feeRateName = "fee_rate"
54+
feeRateName = "sat_per_vbyte"
5455
assetAmountName = "amount"
5556
burnOverrideConfirmationName = "override_confirmation_destroy_assets"
5657
)
@@ -261,7 +262,7 @@ var finalizeBatchCommand = cli.Command{
261262
},
262263
cli.Uint64Flag{
263264
Name: feeRateName,
264-
Usage: "if set, the fee rate in sat/kw to use for " +
265+
Usage: "if set, the fee rate in sat/vB to use for " +
265266
"the minting transaction",
266267
},
267268
},
@@ -270,11 +271,20 @@ var finalizeBatchCommand = cli.Command{
270271

271272
func parseFeeRate(ctx *cli.Context) (uint32, error) {
272273
if ctx.IsSet(feeRateName) {
273-
feeRate := ctx.Uint64(feeRateName)
274-
if feeRate > math.MaxUint32 {
274+
userFeeRate := ctx.Uint64(feeRateName)
275+
if userFeeRate > math.MaxUint32 {
275276
return 0, fmt.Errorf("fee rate exceeds 2^32")
276277
}
277278

279+
// Convert from sat/vB to sat/kw. Round up to the fee floor if
280+
// the specified feerate is too low.
281+
feeRate := chainfee.SatPerKVByte(userFeeRate * 1000).
282+
FeePerKWeight()
283+
284+
if feeRate < chainfee.FeePerKwFloor {
285+
feeRate = chainfee.FeePerKwFloor
286+
}
287+
278288
return uint32(feeRate), nil
279289
}
280290

@@ -531,7 +541,7 @@ var sendAssetsCommand = cli.Command{
531541
},
532542
cli.Uint64Flag{
533543
Name: feeRateName,
534-
Usage: "if set, the fee rate in sat/kw to use for " +
544+
Usage: "if set, the fee rate in sat/vB to use for " +
535545
"the anchor transaction",
536546
},
537547
// TODO(roasbeef): add arg for file name to write sender proof

rpcserver.go

Lines changed: 9 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -491,26 +491,24 @@ func (r *rpcServer) MintAsset(ctx context.Context,
491491
}
492492
}
493493

494-
// checkFeeRateSanity ensures that the provided fee rate is above the same
495-
// minimum fee used as a floor in the fee estimator.
494+
// checkFeeRateSanity ensures that the provided fee rate, in sat/kw, is above
495+
// the same minimum fee used as a floor in the fee estimator.
496496
func checkFeeRateSanity(rpcFeeRate uint32) (*chainfee.SatPerKWeight, error) {
497-
var feeRate *chainfee.SatPerKWeight
497+
feeFloor := uint32(chainfee.FeePerKwFloor)
498498
switch {
499499
// No manual fee rate was set, which is the default.
500500
case rpcFeeRate == 0:
501+
return nil, nil
501502

502503
// A manual fee was set but is below a reasonable floor.
503-
case rpcFeeRate < uint32(chainfee.FeePerKwFloor):
504-
return nil, fmt.Errorf("manual fee rate %d below floor of %d",
505-
rpcFeeRate, uint32(chainfee.FeePerKwFloor))
504+
case rpcFeeRate < feeFloor:
505+
return nil, fmt.Errorf("manual fee rate below floor: "+
506+
"(fee_rate=%d, floor=%d sat/kw)", rpcFeeRate, feeFloor)
506507

508+
// Set the fee rate for this transaction.
507509
default:
508-
// Set the fee rate for this transaction.
509-
manualFeeRate := chainfee.SatPerKWeight(rpcFeeRate)
510-
feeRate = &manualFeeRate
510+
return fn.Ptr(chainfee.SatPerKWeight(rpcFeeRate)), nil
511511
}
512-
513-
return feeRate, nil
514512
}
515513

516514
// FinalizeBatch attempts to finalize the current pending batch.

0 commit comments

Comments
 (0)