Skip to content

Commit b095ba2

Browse files
jharveybRoasbeef
authored andcommitted
tapfreighter: accept fee rate arg for transfers
In this commit, we add support for overriding the fee estimator and providing a target fee rate to the freighter when performing a transfer. This only applies to sends to addresses and not via interactive vPSBTs.
1 parent 729bc70 commit b095ba2

File tree

3 files changed

+35
-7
lines changed

3 files changed

+35
-7
lines changed

tapfreighter/chain_porter.go

Lines changed: 24 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ import (
2020
"github.com/lightninglabs/taproot-assets/tappsbt"
2121
"github.com/lightninglabs/taproot-assets/tapscript"
2222
"github.com/lightningnetwork/lnd/chainntnfs"
23+
"github.com/lightningnetwork/lnd/lnwallet/chainfee"
2324
)
2425

2526
// ChainPorterConfig is the main config for the chain porter.
@@ -880,14 +881,32 @@ func (p *ChainPorter) stateStep(currentPkg sendPackage) (*sendPackage, error) {
880881
// Submit the template PSBT to the wallet for funding.
881882
//
882883
// TODO(roasbeef): unlock the input UTXOs of things fail
883-
feeRate, err := p.cfg.ChainBridge.EstimateFee(
884-
ctx, tapscript.SendConfTarget,
884+
var (
885+
feeRate chainfee.SatPerKWeight
886+
err error
885887
)
886-
if err != nil {
887-
return nil, fmt.Errorf("unable to estimate fee: %w",
888-
err)
888+
889+
// First, use a manual fee rate if specified by the parcel.
890+
// TODO(jhb): Support PSBT flow / PreSignedParcels
891+
addrParcel, ok := currentPkg.Parcel.(*AddressParcel)
892+
switch {
893+
case ok && addrParcel.transferFeeRate != nil:
894+
feeRate = *addrParcel.transferFeeRate
895+
log.Infof("sending with manual fee rate")
896+
897+
default:
898+
feeRate, err = p.cfg.ChainBridge.EstimateFee(
899+
ctx, tapscript.SendConfTarget,
900+
)
901+
if err != nil {
902+
return nil, fmt.Errorf("unable to estimate "+
903+
"fee: %w", err)
904+
}
889905
}
890906

907+
readableFeeRate := feeRate.FeePerKVByte().String()
908+
log.Infof("sending with fee rate: %v", readableFeeRate)
909+
891910
vPacket := currentPkg.VirtualPacket
892911
firstRecipient, err := vPacket.FirstNonSplitRootOutput()
893912
if err != nil {

tapfreighter/parcel.go

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ import (
1717
"github.com/lightninglabs/taproot-assets/tappsbt"
1818
"github.com/lightningnetwork/lnd/chainntnfs"
1919
"github.com/lightningnetwork/lnd/keychain"
20+
"github.com/lightningnetwork/lnd/lnwallet/chainfee"
2021
)
2122

2223
// SendState is an enum that describes the current state of a pending outbound
@@ -130,20 +131,27 @@ type AddressParcel struct {
130131
// destAddrs is the list of address that should be used to satisfy the
131132
// transfer.
132133
destAddrs []*address.Tap
134+
135+
// transferFeeRate is an optional manually-set feerate specified when
136+
// requesting an asset transfer.
137+
transferFeeRate *chainfee.SatPerKWeight
133138
}
134139

135140
// A compile-time assertion to ensure AddressParcel implements the parcel
136141
// interface.
137142
var _ Parcel = (*AddressParcel)(nil)
138143

139144
// NewAddressParcel creates a new AddressParcel.
140-
func NewAddressParcel(destAddrs ...*address.Tap) *AddressParcel {
145+
func NewAddressParcel(feeRate *chainfee.SatPerKWeight,
146+
destAddrs ...*address.Tap) *AddressParcel {
147+
141148
return &AddressParcel{
142149
parcelKit: &parcelKit{
143150
respChan: make(chan *OutboundParcel, 1),
144151
errChan: make(chan error, 1),
145152
},
146-
destAddrs: destAddrs,
153+
destAddrs: destAddrs,
154+
transferFeeRate: feeRate,
147155
}
148156
}
149157

tapfreighter/wallet.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1442,6 +1442,7 @@ func (f *AssetWallet) AnchorVirtualTransactions(ctx context.Context,
14421442
return nil, fmt.Errorf("unable to get on-chain fees for psbt: "+
14431443
"%w", err)
14441444
}
1445+
log.Infof("PSBT absolute fee: %d sats", chainFees)
14451446

14461447
err = psbt.MaybeFinalizeAll(signedPsbt)
14471448
if err != nil {

0 commit comments

Comments
 (0)