Skip to content

Commit fa8458c

Browse files
niftyneirustyrussell
authored andcommitted
dualfund: add test to make sure that tx-sigs sent before commitment
results in an error.
1 parent 30ec8cb commit fa8458c

File tree

6 files changed

+45
-2
lines changed

6 files changed

+45
-2
lines changed

common/dev_disconnect.c

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -70,7 +70,8 @@ enum dev_disconnect dev_disconnect(const struct node_id *id, int pkt_type)
7070
err(1, "lseek failure");
7171
}
7272

73-
status_peer_debug(id, "dev_disconnect: %s (%s)", dev_disconnect_line,
73+
status_peer_debug(id, "dev_disconnect: %s (%s)",
74+
dev_disconnect_line,
7475
peer_wire_name(pkt_type));
7576
return dev_disconnect_line[0];
7677
}

common/dev_disconnect.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,8 @@ enum dev_disconnect {
1212
DEV_DISCONNECT_BEFORE = '-',
1313
/* Close connection after sending packet. */
1414
DEV_DISCONNECT_AFTER = '+',
15+
/* Drop message (don't send to peer) */
16+
DEV_DISCONNECT_DROP = '$',
1517
/* Swallow all writes from now on, and do no more reads. */
1618
DEV_DISCONNECT_BLACKHOLE = '0',
1719
/* Don't use connection after sending packet, but don't close. */

connectd/multiplex.c

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -446,6 +446,14 @@ static struct io_plan *encrypt_and_send(struct peer *peer,
446446
break;
447447
case DEV_DISCONNECT_NORMAL:
448448
break;
449+
case DEV_DISCONNECT_DROP:
450+
/* Drop this message and continue */
451+
if (taken(msg))
452+
tal_free(msg);
453+
/* Tell them to read again, */
454+
io_wake(&peer->subds);
455+
return msg_queue_wait(peer->to_peer, peer->peer_outq,
456+
next, peer);
449457
case DEV_DISCONNECT_DISABLE_AFTER:
450458
peer->dev_read_enabled = false;
451459
peer->dev_writes_enabled = tal(peer, u32);

connectd/peer_exchange_initmsg.c

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -288,6 +288,7 @@ struct io_plan *peer_exchange_initmsg(struct io_conn *conn,
288288
"Blackhole not supported during handshake");
289289
break;
290290
case DEV_DISCONNECT_NORMAL:
291+
case DEV_DISCONNECT_DROP:
291292
break;
292293
case DEV_DISCONNECT_DISABLE_AFTER:
293294
next = dev_peer_write_post_sabotage;

openingd/dualopend.c

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1628,7 +1628,6 @@ static u8 *opening_negotiate_msg(const tal_t *ctx, struct state *state)
16281628
case WIRE_TX_SIGNATURES:
16291629
/* We can get these when we restart and immediately
16301630
* startup an RBF */
1631-
16321631
handle_tx_sigs(state, msg);
16331632
continue;
16341633
case WIRE_CHANNEL_READY:

tests/test_opening.py

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -216,6 +216,38 @@ def test_v2_open_sigs_reconnect_1(node_factory, bitcoind):
216216
l2.daemon.wait_for_log(r'to CHANNELD_NORMAL')
217217

218218

219+
@unittest.skipIf(TEST_NETWORK != 'regtest', 'elementsd doesnt yet support PSBT features we need')
220+
@pytest.mark.xfail
221+
@pytest.mark.openchannel('v2')
222+
def test_v2_open_sigs_out_of_order(node_factory, bitcoind):
223+
""" Test what happens if the tx-sigs get sent "before" commitment signed """
224+
disconnects = ['$WIRE_COMMITMENT_SIGNED']
225+
226+
l1, l2 = node_factory.get_nodes(2,
227+
opts=[{},
228+
{'disconnect': disconnects}])
229+
230+
l1.rpc.connect(l2.info['id'], 'localhost', l2.port)
231+
amount = 2**24
232+
chan_amount = 100000
233+
bitcoind.rpc.sendtoaddress(l1.rpc.newaddr()['bech32'], amount / 10**8 + 0.01)
234+
bitcoind.generate_block(1)
235+
# Wait for it to arrive.
236+
wait_for(lambda: len(l1.rpc.listfunds()['outputs']) > 0)
237+
238+
# Fund the channel, should error because L2 doesn't see our commitment-signed
239+
# so they think we've sent things out of order
240+
with pytest.raises(RpcError, match='tx_signatures sent before commitment sigs'):
241+
l1.rpc.fundchannel(l2.info['id'], chan_amount)
242+
243+
# L1 should remove the in-progress channel
244+
wait_for(lambda: l1.rpc.listpeerchannels()['channels'] == [])
245+
# L2 should fail it to chain
246+
l2.daemon.wait_for_logs([r'to AWAITING_UNILATERAL',
247+
# We can't broadcast this, we don't have sigs for funding
248+
'sendrawtx exit 25'])
249+
250+
219251
@pytest.mark.openchannel('v2')
220252
def test_v2_fail_second(node_factory, bitcoind):
221253
""" Open a channel succeeds; opening a second channel

0 commit comments

Comments
 (0)