lnrpc+lnd+config: add coin selection strategy to all on-chain rpcs

In this commit, we add the coin selection strategy option
to all on-chain RPCs `FundPsbt`, `BatchOpenChannel`, `EstimateFee`,
`SendMany`, `SendCoins`, `SendOutputs`.
This commit is contained in:
Mohamed Awnallah 2024-03-26 19:01:48 +02:00
parent 5599b3c9e2
commit 7c2c0dcf98
No known key found for this signature in database
GPG Key ID: 5D55706029E9B87E
7 changed files with 4081 additions and 3816 deletions

File diff suppressed because it is too large Load Diff

View File

@ -1091,6 +1091,18 @@ message LightningAddress {
string host = 2;
}
enum CoinSelectionStrategy {
// Use the coin selection strategy defined in the global configuration
// (lnd.conf).
STRATEGY_USE_GLOBAL_CONFIG = 0;
// Select the largest available coins first during coin selection.
STRATEGY_LARGEST = 1;
// Randomly select the available coins during coin selection.
STRATEGY_RANDOM = 2;
}
message EstimateFeeRequest {
// The map from addresses to amounts for the transaction.
map<string, int64> AddrToAmount = 1;
@ -1105,6 +1117,9 @@ message EstimateFeeRequest {
// Whether unconfirmed outputs should be used as inputs for the transaction.
bool spend_unconfirmed = 4;
// The strategy to use for selecting coins during fees estimation.
CoinSelectionStrategy coin_selection_strategy = 5;
}
message EstimateFeeResponse {
@ -1145,6 +1160,9 @@ message SendManyRequest {
// Whether unconfirmed outputs should be used as inputs for the transaction.
bool spend_unconfirmed = 8;
// The strategy to use for selecting coins during sending many requests.
CoinSelectionStrategy coin_selection_strategy = 9;
}
message SendManyResponse {
// The id of the transaction
@ -1187,6 +1205,9 @@ message SendCoinsRequest {
// Whether unconfirmed outputs should be used as inputs for the transaction.
bool spend_unconfirmed = 9;
// The strategy to use for selecting coins.
CoinSelectionStrategy coin_selection_strategy = 10;
}
message SendCoinsResponse {
// The transaction ID of the transaction
@ -2115,6 +2136,9 @@ message BatchOpenChannelRequest {
// An optional label for the batch transaction, limited to 500 characters.
string label = 6;
// The strategy to use for selecting coins during batch opening channels.
CoinSelectionStrategy coin_selection_strategy = 7;
}
message BatchOpenChannel {

View File

@ -2655,6 +2655,19 @@
"in": "query",
"required": false,
"type": "boolean"
},
{
"name": "coin_selection_strategy",
"description": "The strategy to use for selecting coins during fees estimation.\n\n - STRATEGY_USE_GLOBAL_CONFIG: Use the coin selection strategy defined in the global configuration\n(lnd.conf).\n - STRATEGY_LARGEST: Select the largest available coins first during coin selection.\n - STRATEGY_RANDOM: Randomly select the available coins during coin selection.",
"in": "query",
"required": false,
"type": "string",
"enum": [
"STRATEGY_USE_GLOBAL_CONFIG",
"STRATEGY_LARGEST",
"STRATEGY_RANDOM"
],
"default": "STRATEGY_USE_GLOBAL_CONFIG"
}
],
"tags": [
@ -3460,6 +3473,10 @@
"label": {
"type": "string",
"description": "An optional label for the batch transaction, limited to 500 characters."
},
"coin_selection_strategy": {
"$ref": "#/definitions/lnrpcCoinSelectionStrategy",
"description": "The strategy to use for selecting coins during batch opening channels."
}
}
},
@ -4435,6 +4452,16 @@
}
}
},
"lnrpcCoinSelectionStrategy": {
"type": "string",
"enum": [
"STRATEGY_USE_GLOBAL_CONFIG",
"STRATEGY_LARGEST",
"STRATEGY_RANDOM"
],
"default": "STRATEGY_USE_GLOBAL_CONFIG",
"description": " - STRATEGY_USE_GLOBAL_CONFIG: Use the coin selection strategy defined in the global configuration\n(lnd.conf).\n - STRATEGY_LARGEST: Select the largest available coins first during coin selection.\n - STRATEGY_RANDOM: Randomly select the available coins during coin selection."
},
"lnrpcCommitmentType": {
"type": "string",
"enum": [
@ -6912,6 +6939,10 @@
"spend_unconfirmed": {
"type": "boolean",
"description": "Whether unconfirmed outputs should be used as inputs for the transaction."
},
"coin_selection_strategy": {
"$ref": "#/definitions/lnrpcCoinSelectionStrategy",
"description": "The strategy to use for selecting coins."
}
}
},
@ -6985,6 +7016,10 @@
"spend_unconfirmed": {
"type": "boolean",
"description": "Whether unconfirmed outputs should be used as inputs for the transaction."
},
"coin_selection_strategy": {
"$ref": "#/definitions/lnrpcCoinSelectionStrategy",
"description": "The strategy to use for selecting coins during sending many requests."
}
}
},

View File

@ -9,6 +9,7 @@ import (
"github.com/btcsuite/btcd/chaincfg"
"github.com/btcsuite/btcd/txscript"
"github.com/btcsuite/btcd/wire"
"github.com/btcsuite/btcwallet/wallet"
"github.com/lightningnetwork/lnd/lnwallet"
"github.com/lightningnetwork/lnd/lnwire"
)
@ -179,3 +180,30 @@ func MarshalOutPoint(op *wire.OutPoint) *OutPoint {
OutputIndex: op.Index,
}
}
// UnmarshallCoinSelectionStrategy converts a lnrpc.CoinSelectionStrategy proto
// type to its wallet.CoinSelectionStrategy counterpart type, considering
// a global default strategy if necessary.
//
// The globalStrategy parameter specifies the default coin selection strategy
// to use if the strategy is set to STRATEGY_USE_GLOBAL_CONFIG. This allows
// flexibility in defining a default strategy at a global level.
func UnmarshallCoinSelectionStrategy(strategy CoinSelectionStrategy,
globalStrategy wallet.CoinSelectionStrategy) (
wallet.CoinSelectionStrategy, error) {
switch strategy {
case CoinSelectionStrategy_STRATEGY_USE_GLOBAL_CONFIG:
return globalStrategy, nil
case CoinSelectionStrategy_STRATEGY_LARGEST:
return wallet.CoinSelectionLargest, nil
case CoinSelectionStrategy_STRATEGY_RANDOM:
return wallet.CoinSelectionRandom, nil
default:
return nil, fmt.Errorf("unknown coin selection strategy "+
"%v", strategy)
}
}

File diff suppressed because it is too large Load Diff

View File

@ -813,6 +813,9 @@ message SendOutputsRequest {
// Whether unconfirmed outputs should be used as inputs for the transaction.
bool spend_unconfirmed = 5;
// The strategy to use for selecting coins during sending the outputs.
lnrpc.CoinSelectionStrategy coin_selection_strategy = 6;
}
message SendOutputsResponse {
/*
@ -1308,6 +1311,9 @@ message FundPsbtRequest {
// accounts, no change type should be provided as the coin selection key
// scope will always be used to generate the change address.
ChangeAddressType change_type = 8;
// The strategy to use for selecting coins during funding the PSBT.
lnrpc.CoinSelectionStrategy coin_selection_strategy = 10;
}
message FundPsbtResponse {
/*

View File

@ -949,6 +949,16 @@
"description": "- `p2wkh`: Pay to witness key hash (`WITNESS_PUBKEY_HASH` = 0)\n- `np2wkh`: Pay to nested witness key hash (`NESTED_PUBKEY_HASH` = 1)\n- `p2tr`: Pay to taproot pubkey (`TAPROOT_PUBKEY` = 4)",
"title": "`AddressType` has to be one of:"
},
"lnrpcCoinSelectionStrategy": {
"type": "string",
"enum": [
"STRATEGY_USE_GLOBAL_CONFIG",
"STRATEGY_LARGEST",
"STRATEGY_RANDOM"
],
"default": "STRATEGY_USE_GLOBAL_CONFIG",
"description": " - STRATEGY_USE_GLOBAL_CONFIG: Use the coin selection strategy defined in the global configuration\n(lnd.conf).\n - STRATEGY_LARGEST: Select the largest available coins first during coin selection.\n - STRATEGY_RANDOM: Randomly select the available coins during coin selection."
},
"lnrpcOutPoint": {
"type": "object",
"properties": {
@ -1467,6 +1477,10 @@
"change_type": {
"$ref": "#/definitions/walletrpcChangeAddressType",
"description": "The address type for the change. If empty, P2WPKH addresses will be used\nfor default accounts and single imported public keys. For custom\naccounts, no change type should be provided as the coin selection key\nscope will always be used to generate the change address."
},
"coin_selection_strategy": {
"$ref": "#/definitions/lnrpcCoinSelectionStrategy",
"description": "The strategy to use for selecting coins during funding the PSBT."
}
}
},
@ -1909,6 +1923,10 @@
"spend_unconfirmed": {
"type": "boolean",
"description": "Whether unconfirmed outputs should be used as inputs for the transaction."
},
"coin_selection_strategy": {
"$ref": "#/definitions/lnrpcCoinSelectionStrategy",
"description": "The strategy to use for selecting coins during sending the outputs."
}
}
},