Skip to content

Commit 9f175de

Browse files
rustyrussellcdecker
authored andcommitted
lightningd: update feerate upon receiving revoke_and_ack from fundee.
1. l1 update_fee -> l2 2. l1 commitment_signed -> l2 (using new feerate) 3. l1 <- revoke_and_ack l2 4. l1 <- commitment_signed l2 (using new feerate) 5. l1 -> revoke_and_ack l2 When we break the connection after #3, the reconnection causes #4 to be retransmitted, but it turns out l1 wasn't telling the master to set the local feerate until it received the commitment_signed, so on reconnect it uses the old feerate, with predictable results (bad signature). Signed-off-by: Rusty Russell <[email protected]>
1 parent c106fa1 commit 9f175de

File tree

4 files changed

+19
-6
lines changed

4 files changed

+19
-6
lines changed

channeld/channel.c

Lines changed: 12 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1272,15 +1272,16 @@ static void handle_peer_commit_sig(struct peer *peer, const u8 *msg)
12721272
dump_htlcs(peer->channel, "receiving commit_sig");
12731273
peer_failed(&peer->cs,
12741274
&peer->channel_id,
1275-
"Bad commit_sig signature %"PRIu64" %s for tx %s wscript %s key %s",
1275+
"Bad commit_sig signature %"PRIu64" %s for tx %s wscript %s key %s feerate %u",
12761276
peer->next_index[LOCAL],
12771277
type_to_string(msg, secp256k1_ecdsa_signature,
12781278
&commit_sig),
12791279
type_to_string(msg, struct bitcoin_tx, txs[0]),
12801280
tal_hex(msg, wscripts[0]),
12811281
type_to_string(msg, struct pubkey,
12821282
&peer->channel->funding_pubkey
1283-
[REMOTE]));
1283+
[REMOTE]),
1284+
peer->channel->view[LOCAL].feerate_per_kw);
12841285
}
12851286

12861287
/* BOLT #2:
@@ -1332,7 +1333,8 @@ static void handle_peer_commit_sig(struct peer *peer, const u8 *msg)
13321333
static u8 *got_revoke_msg(const tal_t *ctx, u64 revoke_num,
13331334
const struct secret *per_commitment_secret,
13341335
const struct pubkey *next_per_commit_point,
1335-
const struct htlc **changed_htlcs)
1336+
const struct htlc **changed_htlcs,
1337+
u32 feerate)
13361338
{
13371339
u8 *msg;
13381340
struct changed_htlc *changed = tal_arr(tmpctx, struct changed_htlc, 0);
@@ -1350,7 +1352,7 @@ static u8 *got_revoke_msg(const tal_t *ctx, u64 revoke_num,
13501352
}
13511353

13521354
msg = towire_channel_got_revoke(ctx, revoke_num, per_commitment_secret,
1353-
next_per_commit_point, changed);
1355+
next_per_commit_point, feerate, changed);
13541356
return msg;
13551357
}
13561358

@@ -1409,7 +1411,8 @@ static void handle_peer_revoke_and_ack(struct peer *peer, const u8 *msg)
14091411
/* Tell master about things this locks in, wait for response */
14101412
msg = got_revoke_msg(NULL, peer->revocations_received++,
14111413
&old_commit_secret, &next_per_commit,
1412-
changed_htlcs);
1414+
changed_htlcs,
1415+
channel_feerate(peer->channel, LOCAL));
14131416
master_wait_sync_reply(tmpctx, peer, take(msg),
14141417
WIRE_CHANNEL_GOT_REVOKE_REPLY);
14151418

@@ -1749,6 +1752,10 @@ static void resend_commitment(struct peer *peer, const struct changed_htlc *last
17491752
struct commit_sigs *commit_sigs;
17501753
u8 *msg;
17511754

1755+
status_trace("Retransmitting commitment, feerate LOCAL=%u REMOTE=%u",
1756+
channel_feerate(peer->channel, LOCAL),
1757+
channel_feerate(peer->channel, REMOTE));
1758+
17521759
/* BOLT #2:
17531760
*
17541761
* - if `next_local_commitment_number` is equal to the commitment

channeld/channel_wire.csv

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -137,6 +137,7 @@ channel_got_revoke,,revokenum,u64
137137
channel_got_revoke,,per_commitment_secret,struct secret
138138
channel_got_revoke,,next_per_commit_point,struct pubkey
139139
# RCVD_ADD_ACK_REVOCATION, RCVD_REMOVE_ACK_REVOCATION, RCVD_ADD_REVOCATION, RCVD_REMOVE_REVOCATION
140+
channel_got_revoke,,feerate,u32
140141
channel_got_revoke,,num_changed,u16
141142
channel_got_revoke,,changed,num_changed*struct changed_htlc
142143
# Wait for reply, to make sure it's on disk before we continue

lightningd/peer_htlcs.c

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1283,10 +1283,12 @@ void peer_got_revoke(struct channel *channel, const u8 *msg)
12831283
enum onion_type *failcodes;
12841284
size_t i;
12851285
struct lightningd *ld = channel->peer->ld;
1286+
u32 feerate;
12861287

12871288
if (!fromwire_channel_got_revoke(msg, msg,
12881289
&revokenum, &per_commitment_secret,
12891290
&next_per_commitment_point,
1291+
&feerate,
12901292
&changed)) {
12911293
channel_internal_error(channel, "bad fromwire_channel_got_revoke %s",
12921294
tal_hex(channel, msg));
@@ -1345,6 +1347,10 @@ void peer_got_revoke(struct channel *channel, const u8 *msg)
13451347
return;
13461348
}
13471349

1350+
/* Update feerate: if we are funder, their revoke_and_ack has set
1351+
* this for local feerate. */
1352+
channel->channel_info.feerate_per_kw[LOCAL] = feerate;
1353+
13481354
/* FIXME: Check per_commitment_secret -> per_commit_point */
13491355
update_per_commit_point(channel, &next_per_commitment_point);
13501356

tests/test_connection.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1110,7 +1110,6 @@ def test_fundee_forget_funding_tx_unconfirmed(node_factory, bitcoind):
11101110
assert len(l2.rpc.listpeers(l1.info['id'])['peers']) == 0
11111111

11121112

1113-
@pytest.mark.xfail(strict=True)
11141113
@unittest.skipIf(not DEVELOPER, "needs --dev-disconnect")
11151114
def test_funder_feerate_reconnect(node_factory, bitcoind):
11161115
# l1 updates fees, then reconnect so l2 retransmits commitment_signed.

0 commit comments

Comments
 (0)