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= diff --git a/lightning_client.go b/lightning_client.go index 8060274..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] @@ -209,12 +216,13 @@ 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, + 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, 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, + opts ...SendCoinsOption) (string, error) { rpcCtx, cancel := context.WithTimeout(ctx, s.timeout) defer cancel() @@ -3608,11 +3646,15 @@ func (s *lightningClient) SendCoins(ctx context.Context, addr btcutil.Address, Addr: addr.String(), Amount: int64(amount), TargetConf: confTarget, - SatPerByte: satsPerByte, + SatPerKw: uint64(satsPerVByte.FeePerKWeight()), SendAll: sendAll, Label: label, } + for _, opt := range opts { + opt(req) + } + resp, err := s.client.SendCoins(rpcCtx, req) if err != nil { return "", err 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 {