Skip to content

Commit

Permalink
channel_fail_permanent: Use a channel-level error, not an all-channel…
Browse files Browse the repository at this point in the history
…s error.

Fixes: ElementsProject#1229
  • Loading branch information
ZmnSCPxj authored and cdecker committed Mar 17, 2018
1 parent d49915c commit 234d67d
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 10 deletions.
15 changes: 6 additions & 9 deletions lightningd/channel.c
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
#include <bitcoin/script.h>
#include <ccan/crypto/hkdf_sha256/hkdf_sha256.h>
#include <ccan/tal/str/str.h>
#include <common/wire_error.h>
#include <gossipd/gen_gossip_wire.h>
#include <inttypes.h>
#include <lightningd/channel.h>
Expand Down Expand Up @@ -287,6 +288,7 @@ void channel_fail_permanent(struct channel *channel, const char *fmt, ...)
va_list ap;
char *why;
u8 *msg;
struct channel_id cid;

va_start(ap, fmt);
why = tal_vfmt(channel, fmt, ap);
Expand All @@ -305,15 +307,10 @@ void channel_fail_permanent(struct channel *channel, const char *fmt, ...)

/* We can have multiple errors, eg. onchaind failures. */
if (!channel->error) {
/* BOLT #1:
*
* The channel is referred to by `channel_id` unless `channel_id` is
* zero (ie. all bytes zero), in which case it refers to all
* channels. */
static const struct channel_id all_channels;
u8 *msg = tal_dup_arr(NULL, u8, (const u8 *)why, strlen(why), 0);
channel->error = towire_error(channel, &all_channels, msg);
tal_free(msg);
derive_channel_id(&cid,
&channel->funding_txid,
channel->funding_outnum);
channel->error = towire_errorfmt(channel, &cid, "%s", why);
}

channel_set_owner(channel, NULL);
Expand Down
3 changes: 2 additions & 1 deletion tests/test_lightningd.py
Original file line number Diff line number Diff line change
Expand Up @@ -1246,8 +1246,9 @@ def test_permfail(self):
l2.daemon.wait_for_log(' to ONCHAIN')
l2.daemon.wait_for_log('Propose handling OUR_UNILATERAL/DELAYED_OUTPUT_TO_US by OUR_DELAYED_RETURN_TO_WALLET (.*) after 5 blocks')

cid = l1.rpc.listpeers(l2.info['id'])['peers'][0]['channels'][0]['channel_id']
wait_for(lambda: l1.rpc.listpeers(l2.info['id'])['peers'][0]['channels'][0]['status'] ==
['CHANNELD_NORMAL:Received error from peer: channel ALL: Internal error: Failing due to dev-fail command',
['CHANNELD_NORMAL:Received error from peer: channel {}: Internal error: Failing due to dev-fail command'.format(cid),
'ONCHAIN:Tracking their unilateral close',
'ONCHAIN:All outputs resolved: waiting 99 more blocks before forgetting channel'])

Expand Down

0 comments on commit 234d67d

Please sign in to comment.