From 2d185c5385712eed5df974a47e2cf8ad28ce64e8 Mon Sep 17 00:00:00 2001 From: Boris Nagaev Date: Sun, 31 Aug 2025 20:06:25 -0300 Subject: [PATCH 1/3] bump LND Include https://github.com/lightningnetwork/lnd/pull/10067 add sats_per_kweight option when crafting a transaction (continue) --- go.mod | 2 ++ go.sum | 4 ++-- 2 files changed, 4 insertions(+), 2 deletions(-) diff --git a/go.mod b/go.mod index d55e0ba..d6f2ab2 100644 --- a/go.mod +++ b/go.mod @@ -192,4 +192,6 @@ require ( // allows us to specify that as an option. replace google.golang.org/protobuf => github.com/lightninglabs/protobuf-go-hex-display v1.33.0-hex-display +replace github.com/lightningnetwork/lnd => github.com/starius/lnd v0.19.2-beta.kweight-selection2 + go 1.24.6 diff --git a/go.sum b/go.sum index 43bdd4d..9fa782a 100644 --- a/go.sum +++ b/go.sum @@ -355,8 +355,6 @@ github.com/lightninglabs/protobuf-go-hex-display v1.33.0-hex-display h1:Y2WiPkBS github.com/lightninglabs/protobuf-go-hex-display v1.33.0-hex-display/go.mod h1:c6P6GXX6sHbq/GpV6MGZEdwhWPcYBgnhAHhKbcUYpos= github.com/lightningnetwork/lightning-onion v1.2.1-0.20240815225420-8b40adf04ab9 h1:6D3LrdagJweLLdFm1JNodZsBk6iU4TTsBBFLQ4yiXfI= github.com/lightningnetwork/lightning-onion v1.2.1-0.20240815225420-8b40adf04ab9/go.mod h1:EDqJ3MuZIbMq0QI1czTIKDJ/GS8S14RXPwapHw8cw6w= -github.com/lightningnetwork/lnd v0.19.0-beta.rc5.0.20250905045430-9d74ec47701c h1:GVMiT7IwHgRCCsih7KWlOHlsyFBy7JZIGKhiSTOzduw= -github.com/lightningnetwork/lnd v0.19.0-beta.rc5.0.20250905045430-9d74ec47701c/go.mod h1:qvNSmsYOEmvb6JIewrv7vF4S2mjUTEYSxAp9m/U94Lw= github.com/lightningnetwork/lnd/clock v1.1.1 h1:OfR3/zcJd2RhH0RU+zX/77c0ZiOnIMsDIBjgjWdZgA0= github.com/lightningnetwork/lnd/clock v1.1.1/go.mod h1:mGnAhPyjYZQJmebS7aevElXKTFDuO+uNFFfMXK1W8xQ= github.com/lightningnetwork/lnd/fn/v2 v2.0.8 h1:r2SLz7gZYQPVc3IZhU82M66guz3Zk2oY+Rlj9QN5S3g= @@ -483,6 +481,8 @@ github.com/soheilhy/cmux v0.1.5 h1:jjzc5WVemNEDTLwv9tlmemhC73tI08BNOIGwBOo10Js= github.com/soheilhy/cmux v0.1.5/go.mod h1:T7TcVDs9LWfQgPlPsdngu6I6QIoyIFZDDC6sNE1GqG0= github.com/spf13/pflag v1.0.5 h1:iy+VFUOCP1a+8yFto/drg2CJ5u0yRoB7fZw3DKv/JXA= github.com/spf13/pflag v1.0.5/go.mod h1:McXfInJRrz4CZXVZOBLb0bTZqETkiAhM9Iw0y3An2Bg= +github.com/starius/lnd v0.19.2-beta.kweight-selection2 h1:idGvTEGnBU4fedk25wyzZwlbbv8TKlf/MpvmvEiugvY= +github.com/starius/lnd v0.19.2-beta.kweight-selection2/go.mod h1:qvNSmsYOEmvb6JIewrv7vF4S2mjUTEYSxAp9m/U94Lw= github.com/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME= github.com/stretchr/objx v0.1.1/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME= github.com/stretchr/objx v0.2.0/go.mod h1:qt09Ya8vawLte6SNmTgCsAVtYtaKzEcn8ATUoHMkEqE= From 6f922de87d4e1769cd02a567491bc88a2f213b55 Mon Sep 17 00:00:00 2001 From: Boris Nagaev Date: Sun, 31 Aug 2025 19:36:26 -0300 Subject: [PATCH 2/3] SendCoins: use SatPerVbyte instead of SatPerByte SatPerByte is deprecated. --- lightning_client.go | 24 ++++++++++++------------ 1 file changed, 12 insertions(+), 12 deletions(-) diff --git a/lightning_client.go b/lightning_client.go index 8060274..67eff0f 100644 --- a/lightning_client.go +++ b/lightning_client.go @@ -209,12 +209,12 @@ type LightningClient interface { // SendCoins sends the passed amount of (or all) coins to the passed // address. Either amount or sendAll must be specified, while - // confTarget, satsPerByte are optional and may be set to zero in which + // confTarget, satsPerVByte are optional and may be set to zero in which // case automatic conf target and fee will be used. Returns the tx id // upon success. SendCoins(ctx context.Context, addr btcutil.Address, amount btcutil.Amount, sendAll bool, confTarget int32, - satsPerByte int64, label string) (string, error) + satsPerVByte chainfee.SatPerVByte, label string) (string, error) // ChannelBalance returns a summary of our channel balances. ChannelBalance(ctx context.Context) (*ChannelBalance, error) @@ -3592,12 +3592,12 @@ func (s *lightningClient) Connect(ctx context.Context, peer route.Vertex, } // SendCoins sends the passed amount of (or all) coins to the passed address. -// Either amount or sendAll must be specified, while confTarget, satsPerByte are -// optional and may be set to zero in which case automatic conf target and fee -// will be used. Returns the tx id upon success. +// Either amount or sendAll must be specified, while confTarget, satsPerVByte +// are optional and may be set to zero in which case automatic conf target and +// fee will be used. Returns the tx id upon success. func (s *lightningClient) SendCoins(ctx context.Context, addr btcutil.Address, amount btcutil.Amount, sendAll bool, confTarget int32, - satsPerByte int64, label string) (string, error) { + satsPerVByte chainfee.SatPerVByte, label string) (string, error) { rpcCtx, cancel := context.WithTimeout(ctx, s.timeout) defer cancel() @@ -3605,12 +3605,12 @@ func (s *lightningClient) SendCoins(ctx context.Context, addr btcutil.Address, rpcCtx = s.adminMac.WithMacaroonAuth(rpcCtx) req := &lnrpc.SendCoinsRequest{ - Addr: addr.String(), - Amount: int64(amount), - TargetConf: confTarget, - SatPerByte: satsPerByte, - SendAll: sendAll, - Label: label, + Addr: addr.String(), + Amount: int64(amount), + TargetConf: confTarget, + SatPerVbyte: uint64(satsPerVByte), + SendAll: sendAll, + Label: label, } resp, err := s.client.SendCoins(rpcCtx, req) From 2d3562b9d5924cb9cf2f1e92964f9e5aa7925953 Mon Sep 17 00:00:00 2001 From: Boris Nagaev Date: Sun, 31 Aug 2025 21:12:00 -0300 Subject: [PATCH 3/3] switch from SatPerVbyte to SatPerKw fields in APIs Use SatPerKw instead of SatPerVbyte in SendCoins, CloseChannel, and walletrpc.BumpFee APIs. Added new option WithSendCoinsFeerate for SendCoins and WithOpenChannelFeerate for OpenChannel API specifying feerate in sats/kw. Use new fields provided by https://github.com/lightningnetwork/lnd/pull/10067 --- lightning_client.go | 64 +++++++++++++++++++++++++++++++++++++-------- walletkit_client.go | 4 +-- 2 files changed, 55 insertions(+), 13 deletions(-) diff --git a/lightning_client.go b/lightning_client.go index 67eff0f..4a0b12d 100644 --- a/lightning_client.go +++ b/lightning_client.go @@ -81,6 +81,13 @@ func WithRemoteMaxHtlc(maxHtlc uint32) OpenChannelOption { } } +// WithOpenChannelFeerate specifies feerate in sats/kw for OpenChannel request. +func WithOpenChannelFeerate(satPerKw chainfee.SatPerKWeight) OpenChannelOption { + return func(r *lnrpc.OpenChannelRequest) { + r.SatPerKw = uint64(satPerKw) + } +} + // LightningClient exposes base lightning functionality. type LightningClient interface { ServiceClient[lnrpc.LightningClient] @@ -214,7 +221,8 @@ type LightningClient interface { // upon success. SendCoins(ctx context.Context, addr btcutil.Address, amount btcutil.Amount, sendAll bool, confTarget int32, - satsPerVByte chainfee.SatPerVByte, label string) (string, error) + satsPerVByte chainfee.SatPerVByte, label string, + opts ...SendCoinsOption) (string, error) // ChannelBalance returns a summary of our channel balances. ChannelBalance(ctx context.Context) (*ChannelBalance, error) @@ -3149,10 +3157,19 @@ func (p *ChannelClosedUpdate) CloseTxid() chainhash.Hash { // CloseChannelRequest. type CloseChannelOption func(r *lnrpc.CloseChannelRequest) -// SatPerVbyte is an option for setting the fee rate of a CloseChannelRequest. +// SatPerVbyte is an option for setting the fee rate of a CloseChannelRequest +// specified in sats/vbyte. func SatPerVbyte(satPerVbyte chainfee.SatPerVByte) CloseChannelOption { return func(r *lnrpc.CloseChannelRequest) { - r.SatPerVbyte = uint64(satPerVbyte) + r.SatPerKw = uint64(satPerVbyte.FeePerKWeight()) + } +} + +// SatPerKw is an option for setting the fee rate of a CloseChannelRequest +// specified in sats/kw. +func SatPerKw(satPerKw chainfee.SatPerKWeight) CloseChannelOption { + return func(r *lnrpc.CloseChannelRequest) { + r.SatPerKw = uint64(satPerKw) } } @@ -3160,7 +3177,15 @@ func SatPerVbyte(satPerVbyte chainfee.SatPerVByte) CloseChannelOption { // willing to pay on a CloseChannelRequest. func MaxFeePerVbyte(maxFeePerVbyte chainfee.SatPerVByte) CloseChannelOption { return func(r *lnrpc.CloseChannelRequest) { - r.MaxFeePerVbyte = uint64(maxFeePerVbyte) + r.MaxFeePerKw = uint64(maxFeePerVbyte.FeePerKWeight()) + } +} + +// MaxFeePerKw is an option for setting the maximum fee rate a closer is +// willing to pay on a CloseChannelRequest. +func MaxFeePerKw(maxFeePerKw chainfee.SatPerKWeight) CloseChannelOption { + return func(r *lnrpc.CloseChannelRequest) { + r.MaxFeePerKw = uint64(maxFeePerKw) } } @@ -3591,13 +3616,26 @@ func (s *lightningClient) Connect(ctx context.Context, peer route.Vertex, return err } +// SendCoinsOption is an option used in SendCoins call. +type SendCoinsOption func(*lnrpc.SendCoinsRequest) + +// WithSendCoinsFeerate specifies feerate in sats/kw for SendCoins request. +// To use it pass satsPerVByte=0 and WithSendCoinsFeerate(desired_feerate) to +// SendCoins. +func WithSendCoinsFeerate(satPerKw chainfee.SatPerKWeight) SendCoinsOption { + return func(req *lnrpc.SendCoinsRequest) { + req.SatPerKw = uint64(satPerKw) + } +} + // SendCoins sends the passed amount of (or all) coins to the passed address. // Either amount or sendAll must be specified, while confTarget, satsPerVByte // are optional and may be set to zero in which case automatic conf target and // fee will be used. Returns the tx id upon success. func (s *lightningClient) SendCoins(ctx context.Context, addr btcutil.Address, amount btcutil.Amount, sendAll bool, confTarget int32, - satsPerVByte chainfee.SatPerVByte, label string) (string, error) { + satsPerVByte chainfee.SatPerVByte, label string, + opts ...SendCoinsOption) (string, error) { rpcCtx, cancel := context.WithTimeout(ctx, s.timeout) defer cancel() @@ -3605,12 +3643,16 @@ func (s *lightningClient) SendCoins(ctx context.Context, addr btcutil.Address, rpcCtx = s.adminMac.WithMacaroonAuth(rpcCtx) req := &lnrpc.SendCoinsRequest{ - Addr: addr.String(), - Amount: int64(amount), - TargetConf: confTarget, - SatPerVbyte: uint64(satsPerVByte), - SendAll: sendAll, - Label: label, + Addr: addr.String(), + Amount: int64(amount), + TargetConf: confTarget, + SatPerKw: uint64(satsPerVByte.FeePerKWeight()), + SendAll: sendAll, + Label: label, + } + + for _, opt := range opts { + opt(req) } resp, err := s.client.SendCoins(rpcCtx, req) diff --git a/walletkit_client.go b/walletkit_client.go index cb639d1..23bb080 100644 --- a/walletkit_client.go +++ b/walletkit_client.go @@ -809,8 +809,8 @@ func (m *walletKitClient) BumpFee(ctx context.Context, op wire.OutPoint, TxidBytes: op.Hash[:], OutputIndex: op.Index, }, - SatPerVbyte: uint64(feeRate.FeePerVByte()), - Immediate: false, + SatPerKw: uint64(feeRate), + Immediate: false, } for _, opt := range opts {