Browse Source

Added wallet related error codes

New codes: FUND_MAX_EXCEEDED, FUND_CANNOT_AFFORD, FUND_DUST_LIMIT_UNMET.

The error message "Cannot afford fee" was not exactly correct because
it would also occur if the amount requested could not be afforded.  So
I changed it to the more generic "Cannot afford transaction".

Other things:

* Fixed off-by-one satoshi in fundchannel manpage.
* Changed 'arror' to 'error' because we are not pirates.
ppa-0.6.1
Mark Beckwith 7 years ago
committed by Christian Decker
parent
commit
8f0ef1636f
  1. 28
      common/wallet_tx.c
  2. 15
      doc/lightning-fundchannel.7.txt
  3. 13
      doc/lightning-withdraw.7.txt
  4. 5
      lightningd/jsonrpc_errors.h
  5. 2
      lightningd/opening_control.c
  6. 2
      tests/test_lightningd.py

28
common/wallet_tx.c

@ -12,6 +12,21 @@ void wtx_init(struct command *cmd, struct wallet_tx * wtx)
wtx->all_funds = false;
}
static bool check_amount(const struct wallet_tx *tx)
{
if (!tx->utxos) {
command_fail(tx->cmd, FUND_CANNOT_AFFORD,
"Cannot afford funding transaction");
return false;
}
if (tx->amount < 546) {
command_fail(tx->cmd, FUND_DUST_LIMIT_UNMET,
"Dust limit unmet");
return false;
}
return true;
}
bool wtx_select_utxos(struct wallet_tx * tx, u32 fee_rate_per_kw,
size_t out_len)
{
@ -21,23 +36,18 @@ bool wtx_select_utxos(struct wallet_tx * tx, u32 fee_rate_per_kw,
fee_rate_per_kw, out_len,
&tx->amount,
&fee_estimate);
if (!tx->utxos || tx->amount < 546) {
command_fail(tx->cmd, LIGHTNINGD,
"Cannot afford fee %"PRIu64,
fee_estimate);
if (!check_amount(tx))
return false;
}
tx->change = 0;
} else {
tx->utxos = wallet_select_coins(tx->cmd, tx->cmd->ld->wallet,
tx->amount,
fee_rate_per_kw, out_len,
&fee_estimate, &tx->change);
if (!tx->utxos || tx->amount < 546) {
command_fail(tx->cmd, LIGHTNINGD,
"Cannot afford funding transaction");
if (!check_amount(tx))
return false;
}
if (tx->change < 546) {
tx->change = 0;
tx->change_key_index = 0;

15
doc/lightning-fundchannel.7.txt

@ -24,7 +24,7 @@ for the channel.
'satoshi' is the amount in satoshis taken from the internal wallet to fund the channel.
The string 'all' can be used to specify all available funds.
This value must be greater than the dust limit, currently set to 546.
This value cannot be less than the dust limit, currently set to 546.
And it must be less than 1<<24 (approximately 0.16778 BTC).
RETURN VALUE
@ -35,14 +35,11 @@ On failure, an error is reported and the channel is not funded.
The following error codes may occur:
* -1. Catchall nonspecific arror.
The above error may include a descriptive message indicating:
* The 'id' is invalid.
* There are not enough funds in the internal wallet to create the transaction.
* The maximum allowed funding amount is exceeded.
* 'satoshi' is less than the dust limit.
* -1. Catchall nonspecific error.
* 300. The maximum allowed funding amount is exceeded.
* 301. There are not enough funds in the internal wallet (including fees) to
create the transaction.
* 302. The dust limit is not met.
Failure may also occur if *lightningd* and the peer cannot agree on channel
parameters (funding limits, channel reserves, fees, etc.).

13
doc/lightning-withdraw.7.txt

@ -33,11 +33,14 @@ be returned.
'tx' represents the raw bitcoin, fully signed, transaction
and 'txid' represent the bitcoin transaction id.
ERRORS
------
If an incorrect address is supplied or the 'satoshi'
parameter exceeds the amount in the internal wallet
an error message will be returned.
On failure, an error is reported and the channel is not funded.
The following error codes may occur:
* -1. Catchall nonspecific error.
* 301. There are not enough funds in the internal wallet (including fees) to
create the transaction.
* 302. The dust limit is not met.
AUTHOR
------

5
lightningd/jsonrpc_errors.h

@ -29,6 +29,11 @@
#define PAY_UNSPECIFIED_ERROR 209
#define PAY_STOPPED_RETRYING 210
/* `fundchannel` or `withdraw` errors */
#define FUND_MAX_EXCEEDED 300
#define FUND_CANNOT_AFFORD 301
#define FUND_DUST_LIMIT_UNMET 302
/* Errors from `invoice` command */
#define INVOICE_LABEL_ALREADY_EXISTS 900
#define INVOICE_PREIMAGE_ALREADY_EXISTS 901

2
lightningd/opening_control.c

@ -922,7 +922,7 @@ static void json_fund_channel(struct command *cmd,
return;
if (fc->wtx.amount > MAX_FUNDING_SATOSHI) {
command_fail(cmd, JSONRPC2_INVALID_PARAMS,
command_fail(cmd, FUND_MAX_EXCEEDED,
"Funding satoshi must be <= %d",
MAX_FUNDING_SATOSHI);
return;

2
tests/test_lightningd.py

@ -3915,7 +3915,7 @@ class LightningDTests(BaseLightningDTests):
# This should fail, can't even afford fee.
self.assertRaises(ValueError, l1.rpc.withdraw, waddr, 'all')
l1.daemon.wait_for_log('Cannot afford fee')
l1.daemon.wait_for_log('Cannot afford funding transaction')
def test_funding_change(self):
"""Add some funds, fund a channel, and make sure we remember the change

Loading…
Cancel
Save