Skip to content

Commit 5515581

Browse files
committed
closingd: don't punish peers who can't negotiate properly.
This is a transitional patch so we can still close channels cleanly; for want of a better option, I hooked it into --deprecated-apis. Signed-off-by: Rusty Russell <[email protected]>
1 parent a01b414 commit 5515581

File tree

3 files changed

+22
-10
lines changed

3 files changed

+22
-10
lines changed

closingd/closing.c

Lines changed: 18 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -343,11 +343,14 @@ static uint64_t receive_offer(struct crypto_state *cs,
343343
struct feerange {
344344
enum side higher_side;
345345
u64 min, max;
346+
347+
bool allow_mistakes;
346348
};
347349

348350
static void init_feerange(struct feerange *feerange,
349351
u64 commitment_fee,
350-
const u64 offer[NUM_SIDES])
352+
const u64 offer[NUM_SIDES],
353+
bool allow_mistakes)
351354
{
352355
feerange->min = 0;
353356

@@ -374,13 +377,17 @@ static void adjust_feerange(struct crypto_state *cs,
374377
struct feerange *feerange,
375378
u64 offer, enum side side)
376379
{
377-
if (offer < feerange->min || offer > feerange->max)
378-
peer_failed(PEER_FD, cs, channel_id,
379-
"%s offer %"PRIu64
380-
" not between %"PRIu64" and %"PRIu64,
381-
side == LOCAL ? "local" : "remote",
382-
offer, feerange->min, feerange->max);
380+
if (offer < feerange->min || offer > feerange->max) {
381+
if (!feerange->allow_mistakes || side != REMOTE)
382+
peer_failed(PEER_FD, cs, channel_id,
383+
"%s offer %"PRIu64
384+
" not between %"PRIu64" and %"PRIu64,
385+
side == LOCAL ? "local" : "remote",
386+
offer, feerange->min, feerange->max);
383387

388+
status_trace("Allowing deprecated out-of-range fee");
389+
return;
390+
}
384391

385392
/* BOLT #2:
386393
*
@@ -444,6 +451,7 @@ int main(int argc, char *argv[])
444451
u64 next_index[NUM_SIDES], revocations_received;
445452
u64 gossip_index;
446453
enum side whose_turn;
454+
bool deprecated_api;
447455

448456
subdaemon_setup(argc, argv);
449457

@@ -466,7 +474,8 @@ int main(int argc, char *argv[])
466474
&reconnected,
467475
&next_index[LOCAL],
468476
&next_index[REMOTE],
469-
&revocations_received))
477+
&revocations_received,
478+
&deprecated_api))
470479
master_badmsg(WIRE_CLOSING_INIT, msg);
471480

472481
status_trace("satoshi_out = %"PRIu64"/%"PRIu64,
@@ -512,7 +521,7 @@ int main(int argc, char *argv[])
512521
}
513522

514523
/* Now we have first two points, we can init fee range. */
515-
init_feerange(&feerange, commitment_fee, offer);
524+
init_feerange(&feerange, commitment_fee, offer, deprecated_api);
516525

517526
/* Now apply the one constraint from above (other is inside loop). */
518527
adjust_feerange(&cs, &channel_id, &feerange,

closingd/closing_wire.csv

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,8 @@ closing_init,,reconnected,bool
2424
closing_init,,next_index_local,u64
2525
closing_init,,next_index_remote,u64
2626
closing_init,,revocations_received,u64
27+
# This means we allow closing negotiations out of bounds.
28+
closing_init,,deprecated_api,bool
2729

2830
# We received an offer, save signature.
2931
closing_received_signature,2002

lightningd/peer_control.c

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1975,7 +1975,8 @@ static void peer_start_closingd(struct peer *peer,
19751975
reconnected,
19761976
peer->next_index[LOCAL],
19771977
peer->next_index[REMOTE],
1978-
num_revocations);
1978+
num_revocations,
1979+
deprecated_apis);
19791980

19801981
/* We don't expect a response: it will give us feedback on
19811982
* signatures sent and received, then closing_complete. */

0 commit comments

Comments
 (0)