Skip to content

Commit

Permalink
bumpfee: add more flags as options
Browse files Browse the repository at this point in the history
New options added: 'immediate', 'target_conf', 'budget'.
  • Loading branch information
starius committed Feb 15, 2025
1 parent b07e7b7 commit 2974fa7
Showing 1 changed file with 54 additions and 12 deletions.
66 changes: 54 additions & 12 deletions walletkit_client.go
Original file line number Diff line number Diff line change
Expand Up @@ -134,7 +134,8 @@ type WalletKitClient interface {
// child-pays-for-parent (CPFP) scenario. If the given output has been
// used in a previous BumpFee call, then a transaction replacing the
// previous is broadcast, resulting in a replace-by-fee (RBF) scenario.
BumpFee(context.Context, wire.OutPoint, chainfee.SatPerKWeight) error
BumpFee(context.Context, wire.OutPoint, chainfee.SatPerKWeight,
...BumpFeeOption) error

// ListAccounts retrieves all accounts belonging to the wallet by default.
// Optional name and addressType can be provided to filter through all the
Expand Down Expand Up @@ -737,28 +738,69 @@ func (m *walletKitClient) ListSweepsVerbose(ctx context.Context,
return result, nil
}

// BumpFeeOption customizes a BumpFee call.
type BumpFeeOption func(*walletrpc.BumpFeeRequest)

// WithImmediate is an option for enabling the immediate mode of BumpFee. The
// sweeper will sweep this input without waiting for the next batch.
func WithImmediate() BumpFeeOption {
return func(r *walletrpc.BumpFeeRequest) {
r.Immediate = true
}
}

// WithTargetConf is an option for setting the target_conf of BumpFee. If set,
// the underlying fee estimator will use the target_conf to estimate the
// starting fee rate for the fee function. The value of feeRate passed to
// BumpFee will be ignored.
func WithTargetConf(targetConf uint32) BumpFeeOption {
return func(r *walletrpc.BumpFeeRequest) {
r.TargetConf = targetConf

// We unset sat_per_vbyte, because if it is specified, it is
// used instead of target_conf.
r.SatPerVbyte = 0
}
}

// WithBudget is an option for setting the budget of BumpFee. It is the max
// amount in sats that can be used as the fees. Setting this value greater than
// the input's value may result in CPFP - one or more wallet utxos will be used
// to pay the fees specified by the budget. If not set, for new inputs, by
// default 50% of the input's value will be treated as the budget for fee
// bumping; for existing inputs, their current budgets will be retained.
func WithBudget(budget btcutil.Amount) BumpFeeOption {
return func(r *walletrpc.BumpFeeRequest) {
r.Budget = uint64(budget)
}
}

// BumpFee attempts to bump the fee of a transaction by spending one of its
// outputs at the given fee rate. This essentially results in a
// child-pays-for-parent (CPFP) scenario. If the given output has been used in a
// previous BumpFee call, then a transaction replacing the previous is
// broadcast, resulting in a replace-by-fee (RBF) scenario.
func (m *walletKitClient) BumpFee(ctx context.Context, op wire.OutPoint,
feeRate chainfee.SatPerKWeight) error {
feeRate chainfee.SatPerKWeight, opts ...BumpFeeOption) error {

rpcCtx, cancel := context.WithTimeout(ctx, m.timeout)
defer cancel()

_, err := m.client.BumpFee(
m.walletKitMac.WithMacaroonAuth(rpcCtx),
&walletrpc.BumpFeeRequest{
Outpoint: &lnrpc.OutPoint{
TxidBytes: op.Hash[:],
OutputIndex: op.Index,
},
SatPerVbyte: uint64(feeRate.FeePerKVByte() / 1000),
Immediate: false,
req := &walletrpc.BumpFeeRequest{
Outpoint: &lnrpc.OutPoint{
TxidBytes: op.Hash[:],
OutputIndex: op.Index,
},
)
SatPerVbyte: uint64(feeRate.FeePerKVByte() / 1000),
Immediate: false,
}

for _, opt := range opts {
opt(req)
}

_, err := m.client.BumpFee(m.walletKitMac.WithMacaroonAuth(rpcCtx), req)

return err
}

Expand Down

0 comments on commit 2974fa7

Please sign in to comment.