Skip to content

Commit 0daf097

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 71bebb9 commit 0daf097

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
@@ -413,11 +413,14 @@ static uint64_t receive_offer(struct crypto_state *cs,
413413
struct feerange {
414414
enum side higher_side;
415415
u64 min, max;
416+
417+
bool allow_mistakes;
416418
};
417419

418420
static void init_feerange(struct feerange *feerange,
419421
u64 commitment_fee,
420-
const u64 offer[NUM_SIDES])
422+
const u64 offer[NUM_SIDES],
423+
bool allow_mistakes)
421424
{
422425
feerange->min = 0;
423426

@@ -444,13 +447,17 @@ static void adjust_feerange(struct crypto_state *cs,
444447
struct feerange *feerange,
445448
u64 offer, enum side side)
446449
{
447-
if (offer < feerange->min || offer > feerange->max)
448-
peer_failed(PEER_FD, cs, channel_id,
449-
"%s offer %"PRIu64
450-
" not between %"PRIu64" and %"PRIu64,
451-
side == LOCAL ? "local" : "remote",
452-
offer, feerange->min, feerange->max);
450+
if (offer < feerange->min || offer > feerange->max) {
451+
if (!feerange->allow_mistakes || side != REMOTE)
452+
peer_failed(PEER_FD, cs, channel_id,
453+
"%s offer %"PRIu64
454+
" not between %"PRIu64" and %"PRIu64,
455+
side == LOCAL ? "local" : "remote",
456+
offer, feerange->min, feerange->max);
453457

458+
status_trace("Allowing deprecated out-of-range fee");
459+
return;
460+
}
454461

455462
/* BOLT #2:
456463
*
@@ -514,6 +521,7 @@ int main(int argc, char *argv[])
514521
u64 next_index[NUM_SIDES], revocations_received;
515522
u64 gossip_index;
516523
enum side whose_turn;
524+
bool deprecated_api;
517525

518526
subdaemon_setup(argc, argv);
519527

@@ -536,7 +544,8 @@ int main(int argc, char *argv[])
536544
&reconnected,
537545
&next_index[LOCAL],
538546
&next_index[REMOTE],
539-
&revocations_received))
547+
&revocations_received,
548+
&deprecated_api))
540549
master_badmsg(WIRE_CLOSING_INIT, msg);
541550

542551
status_trace("satoshi_out = %"PRIu64"/%"PRIu64,
@@ -582,7 +591,7 @@ int main(int argc, char *argv[])
582591
}
583592

584593
/* Now we have first two points, we can init fee range. */
585-
init_feerange(&feerange, commitment_fee, offer);
594+
init_feerange(&feerange, commitment_fee, offer, deprecated_api);
586595

587596
/* Now apply the one constraint from above (other is inside loop). */
588597
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
@@ -1963,7 +1963,8 @@ static void peer_start_closingd(struct peer *peer,
19631963
reconnected,
19641964
peer->next_index[LOCAL],
19651965
peer->next_index[REMOTE],
1966-
num_revocations);
1966+
num_revocations,
1967+
deprecated_apis);
19671968

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

0 commit comments

Comments
 (0)