Browse Source

json-rpc: Add the error onion if we stored it in the DB

If we can't decode the onion, because the onion got corrupted or we used
`sendonion` without specifying the `shared_secrets` used, the best we can do
is tell the caller instead.
travis-debug
Christian Decker 5 years ago
parent
commit
16b6c31010
  1. 6
      lightningd/pay.c
  2. 4
      tests/test_pay.py
  3. 10
      wallet/wallet.c
  4. 3
      wallet/wallet.h

6
lightningd/pay.c

@ -108,6 +108,10 @@ void json_add_payment_fields(struct json_stream *response,
json_add_string(response, "label", t->label);
if (t->bolt11)
json_add_string(response, "bolt11", t->bolt11);
if (t->failonion)
json_add_hex(response, "erroronion", t->failonion,
tal_count(t->failonion));
}
static struct command_result *sendpay_success(struct command *cmd,
@ -855,6 +859,7 @@ send_payment(struct lightningd *ld,
payment->path_secrets = tal_steal(payment, path_secrets);
payment->route_nodes = tal_steal(payment, ids);
payment->route_channels = tal_steal(payment, channels);
payment->failonion = NULL;
if (label != NULL)
payment->label = tal_strdup(payment, label);
else
@ -1034,6 +1039,7 @@ static struct command_result *json_sendonion(struct command *cmd,
payment->route_nodes = NULL;
payment->route_channels = NULL;
payment->bolt11 = NULL;
payment->failonion = NULL;
payment->path_secrets = tal_steal(payment, path_secrets);
if (label != NULL)

4
tests/test_pay.py

@ -2559,5 +2559,5 @@ def test_sendonion_rpc(node_factory):
try:
l1.rpc.waitsendpay(payment_hash=payment_hash)
except RpcError as e:
assert(e.error['code'] == 202)
assert(e.error['message'] == "Malformed error reply")
assert(e.error['code'] == 204)
assert(e.error['data']['raw_message'] == "400f00000000000003e80000006c")

10
wallet/wallet.c

@ -2244,6 +2244,13 @@ static struct wallet_payment *wallet_stmt2payment(const tal_t *ctx,
else
payment->bolt11 = NULL;
if (!db_column_is_null(stmt, 13))
payment->failonion =
tal_dup_arr(payment, u8, db_column_blob(stmt, 13),
db_column_bytes(stmt, 13), 0);
else
payment->failonion = NULL;
return payment;
}
@ -2273,6 +2280,7 @@ wallet_payment_by_hash(const tal_t *ctx, struct wallet *wallet,
", msatoshi_sent"
", description"
", bolt11"
", failonionreply"
" FROM payments"
" WHERE payment_hash = ?"));
@ -2492,6 +2500,7 @@ wallet_payment_list(const tal_t *ctx,
", msatoshi_sent"
", description"
", bolt11"
", failonionreply"
" FROM payments"
" WHERE payment_hash = ?;"));
db_bind_sha256(stmt, 0, payment_hash);
@ -2510,6 +2519,7 @@ wallet_payment_list(const tal_t *ctx,
", msatoshi_sent"
", description"
", bolt11"
", failonionreply"
" FROM payments;"));
}
db_query_prepared(stmt);

3
wallet/wallet.h

@ -267,6 +267,9 @@ struct wallet_payment {
/* The label of the payment. Must support `tal_len` */
const char *label;
/* If we could not decode the fail onion, just add it here. */
const u8 *failonion;
};
struct outpoint {

Loading…
Cancel
Save