mirror of
https://github.com/aljazceru/lightning.git
synced 2026-01-24 08:14:19 +01:00
common: use struct onionreply.
This makes it clear we're dealing with a message which is a wrapped error reply (needing unwrap_onionreply), not an already-wrapped one. Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
This commit is contained in:
@@ -47,6 +47,7 @@ LIGHTNINGD_COMMON_OBJS := \
|
||||
common/msg_queue.o \
|
||||
common/node_id.o \
|
||||
common/onion.o \
|
||||
common/onionreply.o \
|
||||
common/param.o \
|
||||
common/per_peer_state.o \
|
||||
common/permute_tx.o \
|
||||
|
||||
@@ -40,7 +40,7 @@ struct htlc_in {
|
||||
enum onion_type failcode;
|
||||
|
||||
/* For a remote error. */
|
||||
const u8 *failuremsg;
|
||||
const struct onionreply *failuremsg;
|
||||
|
||||
/* If failcode & UPDATE, this is the channel which failed. */
|
||||
struct short_channel_id failoutchannel;
|
||||
@@ -72,7 +72,7 @@ struct htlc_out {
|
||||
enum onion_type failcode;
|
||||
|
||||
/* For a remote error. */
|
||||
const u8 *failuremsg;
|
||||
const struct onionreply *failuremsg;
|
||||
|
||||
/* If we fulfilled, here's the preimage. */
|
||||
/* FIXME: This is basically unused, except as a bool! */
|
||||
|
||||
@@ -255,7 +255,7 @@ void notify_sendpay_success(struct lightningd *ld,
|
||||
static void sendpay_failure_notification_serialize(struct json_stream *stream,
|
||||
const struct wallet_payment *payment,
|
||||
int pay_errcode,
|
||||
const u8 *onionreply,
|
||||
const struct onionreply *onionreply,
|
||||
const struct routing_failure *fail,
|
||||
char *errmsg)
|
||||
{
|
||||
@@ -283,14 +283,14 @@ REGISTER_NOTIFICATION(sendpay_failure,
|
||||
void notify_sendpay_failure(struct lightningd *ld,
|
||||
const struct wallet_payment *payment,
|
||||
int pay_errcode,
|
||||
const u8 *onionreply,
|
||||
const struct onionreply *onionreply,
|
||||
const struct routing_failure *fail,
|
||||
const char *errmsg)
|
||||
{
|
||||
void (*serialize)(struct json_stream *,
|
||||
const struct wallet_payment *,
|
||||
int,
|
||||
const u8 *,
|
||||
const struct onionreply *,
|
||||
const struct routing_failure *,
|
||||
const char *) = sendpay_failure_notification_gen.serialize;
|
||||
|
||||
|
||||
@@ -17,6 +17,8 @@
|
||||
#include <wallet/wallet.h>
|
||||
#include <wire/gen_onion_wire.h>
|
||||
|
||||
struct onionreply;
|
||||
|
||||
bool notifications_have_topic(const char *topic);
|
||||
|
||||
struct notification {
|
||||
@@ -61,7 +63,7 @@ void notify_sendpay_success(struct lightningd *ld,
|
||||
void notify_sendpay_failure(struct lightningd *ld,
|
||||
const struct wallet_payment *payment,
|
||||
int pay_errcode,
|
||||
const u8 *onionreply,
|
||||
const struct onionreply *onionreply,
|
||||
const struct routing_failure *fail,
|
||||
const char *errmsg);
|
||||
|
||||
|
||||
@@ -6,6 +6,7 @@
|
||||
#include <common/json_helpers.h>
|
||||
#include <common/jsonrpc_errors.h>
|
||||
#include <common/onion.h>
|
||||
#include <common/onionreply.h>
|
||||
#include <common/param.h>
|
||||
#include <common/timeout.h>
|
||||
#include <gossipd/gen_gossip_wire.h>
|
||||
@@ -172,14 +173,14 @@ json_add_routefail_info(struct json_stream *js,
|
||||
void json_sendpay_fail_fields(struct json_stream *js,
|
||||
const struct wallet_payment *payment,
|
||||
int pay_errcode,
|
||||
const u8 *onionreply,
|
||||
const struct onionreply *onionreply,
|
||||
const struct routing_failure *fail)
|
||||
{
|
||||
/* "immediate_routing_failure" is before payment creation. */
|
||||
if (payment)
|
||||
json_add_payment_fields(js, payment);
|
||||
if (pay_errcode == PAY_UNPARSEABLE_ONION)
|
||||
json_add_hex_talarr(js, "onionreply", onionreply);
|
||||
json_add_hex_talarr(js, "onionreply", onionreply->contents);
|
||||
else
|
||||
json_add_routefail_info(js,
|
||||
fail->erring_index,
|
||||
@@ -210,7 +211,7 @@ static struct command_result *
|
||||
sendpay_fail(struct command *cmd,
|
||||
const struct wallet_payment *payment,
|
||||
int pay_errcode,
|
||||
const u8 *onionreply,
|
||||
const struct onionreply *onionreply,
|
||||
const struct routing_failure *fail,
|
||||
const char *errmsg)
|
||||
{
|
||||
@@ -243,7 +244,7 @@ static void tell_waiters_failed(struct lightningd *ld,
|
||||
const struct sha256 *payment_hash,
|
||||
const struct wallet_payment *payment,
|
||||
int pay_errcode,
|
||||
const u8 *onionreply,
|
||||
const struct onionreply *onionreply,
|
||||
const struct routing_failure *fail,
|
||||
const char *details)
|
||||
{
|
||||
@@ -620,7 +621,7 @@ static struct command_result *wait_payment(struct lightningd *ld,
|
||||
u64 partid)
|
||||
{
|
||||
struct wallet_payment *payment;
|
||||
u8 *failonionreply;
|
||||
struct onionreply *failonionreply;
|
||||
bool faildestperm;
|
||||
int failindex;
|
||||
enum onion_type failcode;
|
||||
|
||||
@@ -5,6 +5,7 @@
|
||||
|
||||
struct htlc_out;
|
||||
struct lightningd;
|
||||
struct onionreply;
|
||||
struct preimage;
|
||||
struct sha256;
|
||||
struct json_stream;
|
||||
@@ -28,7 +29,7 @@ void json_add_payment_fields(struct json_stream *response,
|
||||
void json_sendpay_fail_fields(struct json_stream *js,
|
||||
const struct wallet_payment *t,
|
||||
int pay_errcode,
|
||||
const u8 *onionreply,
|
||||
const struct onionreply *onionreply,
|
||||
const struct routing_failure *fail);
|
||||
|
||||
#endif /* LIGHTNING_LIGHTNINGD_PAY_H */
|
||||
|
||||
@@ -9,6 +9,7 @@
|
||||
#include <common/json_command.h>
|
||||
#include <common/jsonrpc_errors.h>
|
||||
#include <common/onion.h>
|
||||
#include <common/onionreply.h>
|
||||
#include <common/overflows.h>
|
||||
#include <common/param.h>
|
||||
#include <common/sphinx.h>
|
||||
@@ -96,7 +97,7 @@ static bool htlc_out_update_state(struct channel *channel,
|
||||
|
||||
static void fail_in_htlc(struct htlc_in *hin,
|
||||
enum onion_type failcode,
|
||||
const u8 *failuremsg,
|
||||
const struct onionreply *failuremsg,
|
||||
const struct short_channel_id *out_channelid)
|
||||
{
|
||||
struct failed_htlc failed_htlc;
|
||||
@@ -105,7 +106,7 @@ static void fail_in_htlc(struct htlc_in *hin,
|
||||
assert(failcode || failuremsg);
|
||||
hin->failcode = failcode;
|
||||
if (failuremsg)
|
||||
hin->failuremsg = tal_dup_arr(hin, u8, failuremsg, tal_count(failuremsg), 0);
|
||||
hin->failuremsg = dup_onionreply(hin, failuremsg);
|
||||
|
||||
/* We need this set, since we send it to channeld. */
|
||||
if (hin->failcode & UPDATE)
|
||||
@@ -125,7 +126,7 @@ static void fail_in_htlc(struct htlc_in *hin,
|
||||
|
||||
failed_htlc.id = hin->key.id;
|
||||
failed_htlc.failcode = hin->failcode;
|
||||
failed_htlc.failreason = cast_const(u8 *, hin->failuremsg);
|
||||
failed_htlc.failreason = hin->failuremsg;
|
||||
if (failed_htlc.failcode & UPDATE)
|
||||
failed_htlc.scid = &hin->failoutchannel;
|
||||
else
|
||||
@@ -1079,9 +1080,7 @@ static bool peer_failed_our_htlc(struct channel *channel,
|
||||
|
||||
hout->failcode = failed->failcode;
|
||||
if (!failed->failcode)
|
||||
hout->failuremsg = tal_dup_arr(hout, u8, failed->failreason,
|
||||
tal_count(failed->failreason), 0);
|
||||
|
||||
hout->failuremsg = dup_onionreply(hout, failed->failreason);
|
||||
else
|
||||
hout->failuremsg = NULL;
|
||||
|
||||
@@ -1796,7 +1795,7 @@ static void add_fulfill(u64 id, enum side side,
|
||||
static void add_fail(u64 id, enum side side,
|
||||
enum onion_type failcode,
|
||||
const struct short_channel_id *failing_channel,
|
||||
const u8 *failuremsg,
|
||||
const struct onionreply *failuremsg,
|
||||
const struct failed_htlc ***failed_htlcs,
|
||||
enum side **failed_sides)
|
||||
{
|
||||
@@ -1813,8 +1812,7 @@ static void add_fail(u64 id, enum side side,
|
||||
newf->scid = NULL;
|
||||
|
||||
if (failuremsg)
|
||||
newf->failreason
|
||||
= tal_dup_arr(newf, u8, failuremsg, tal_count(failuremsg), 0);
|
||||
newf->failreason = dup_onionreply(newf, failuremsg);
|
||||
else
|
||||
newf->failreason = NULL;
|
||||
|
||||
|
||||
Reference in New Issue
Block a user