Skip to content

Commit 7915442

Browse files
jharveybRoasbeef
authored andcommitted
rpc: add fee rate arg for finalize and send calls
1 parent b095ba2 commit 7915442

File tree

7 files changed

+345
-276
lines changed

7 files changed

+345
-276
lines changed

rpcserver.go

Lines changed: 35 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,7 @@ import (
4242
"github.com/lightninglabs/taproot-assets/universe"
4343
"github.com/lightningnetwork/lnd/build"
4444
"github.com/lightningnetwork/lnd/keychain"
45+
"github.com/lightningnetwork/lnd/lnwallet/chainfee"
4546
"github.com/lightningnetwork/lnd/signal"
4647
"google.golang.org/grpc"
4748
)
@@ -443,12 +444,39 @@ func (r *rpcServer) MintAsset(ctx context.Context,
443444
}
444445
}
445446

447+
// checkFeeRateSanity ensures that the provided fee rate is above the same
448+
// minimum fee used as a floor in the fee estimator.
449+
func checkFeeRateSanity(rpcFeeRate uint32) (*chainfee.SatPerKWeight, error) {
450+
var feeRate *chainfee.SatPerKWeight
451+
switch {
452+
// No manual fee rate was set, which is the default.
453+
case rpcFeeRate == 0:
454+
455+
// A manual fee was set but is below a reasonable floor.
456+
case rpcFeeRate < uint32(chainfee.FeePerKwFloor):
457+
return nil, fmt.Errorf("manual fee rate %d below floor of %d",
458+
rpcFeeRate, uint32(chainfee.FeePerKwFloor))
459+
460+
default:
461+
// Set the fee rate for this transaction.
462+
manualFeeRate := chainfee.SatPerKWeight(rpcFeeRate)
463+
feeRate = &manualFeeRate
464+
}
465+
466+
return feeRate, nil
467+
}
468+
446469
// FinalizeBatch attempts to finalize the current pending batch.
447470
func (r *rpcServer) FinalizeBatch(_ context.Context,
448471
req *mintrpc.FinalizeBatchRequest) (*mintrpc.FinalizeBatchResponse,
449472
error) {
450473

451-
batch, err := r.cfg.AssetMinter.FinalizeBatch()
474+
feeRate, err := checkFeeRateSanity(req.FeeRate)
475+
if err != nil {
476+
return nil, err
477+
}
478+
479+
batch, err := r.cfg.AssetMinter.FinalizeBatch(feeRate)
452480
if err != nil {
453481
return nil, fmt.Errorf("unable to finalize batch: %w", err)
454482
}
@@ -1961,8 +1989,13 @@ func (r *rpcServer) SendAsset(_ context.Context,
19611989
}
19621990
}
19631991

1992+
feeRate, err := checkFeeRateSanity(req.FeeRate)
1993+
if err != nil {
1994+
return nil, err
1995+
}
1996+
19641997
resp, err := r.cfg.ChainPorter.RequestShipment(
1965-
tapfreighter.NewAddressParcel(tapAddrs...),
1998+
tapfreighter.NewAddressParcel(feeRate, tapAddrs...),
19661999
)
19672000
if err != nil {
19682001
return nil, err

taprpc/mintrpc/mint.pb.go

Lines changed: 72 additions & 62 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

taprpc/mintrpc/mint.proto

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -128,6 +128,9 @@ message FinalizeBatchRequest {
128128
possibly printed on the command line in the case of a very large batch.
129129
*/
130130
bool short_response = 1;
131+
132+
// The optional fee rate to use for the minting transaction, in sat/kw.
133+
uint32 fee_rate = 2;
131134
}
132135

133136
message FinalizeBatchResponse {

taprpc/mintrpc/mint.swagger.json

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -191,6 +191,11 @@
191191
"short_response": {
192192
"type": "boolean",
193193
"description": "If true, then the assets currently in the batch won't be returned in the\nresponse. This is mainly to avoid a lot of data being transmitted and\npossibly printed on the command line in the case of a very large batch."
194+
},
195+
"fee_rate": {
196+
"type": "integer",
197+
"format": "int64",
198+
"description": "The optional fee rate to use for the minting transaction, in sat/kw."
194199
}
195200
}
196201
},

0 commit comments

Comments
 (0)