Browse Source

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 <rusty@rustcorp.com.au>
ppa-0.6.1
Rusty Russell 7 years ago
committed by Christian Decker
parent
commit
bd1aa935b9
  1. 17
      closingd/closing.c
  2. 2
      closingd/closing_wire.csv
  3. 3
      lightningd/peer_control.c

17
closingd/closing.c

@ -343,11 +343,14 @@ static uint64_t receive_offer(struct crypto_state *cs,
struct feerange { struct feerange {
enum side higher_side; enum side higher_side;
u64 min, max; u64 min, max;
bool allow_mistakes;
}; };
static void init_feerange(struct feerange *feerange, static void init_feerange(struct feerange *feerange,
u64 commitment_fee, u64 commitment_fee,
const u64 offer[NUM_SIDES]) const u64 offer[NUM_SIDES],
bool allow_mistakes)
{ {
feerange->min = 0; feerange->min = 0;
@ -374,13 +377,17 @@ static void adjust_feerange(struct crypto_state *cs,
struct feerange *feerange, struct feerange *feerange,
u64 offer, enum side side) u64 offer, enum side side)
{ {
if (offer < feerange->min || offer > feerange->max) if (offer < feerange->min || offer > feerange->max) {
if (!feerange->allow_mistakes || side != REMOTE)
peer_failed(PEER_FD, cs, channel_id, peer_failed(PEER_FD, cs, channel_id,
"%s offer %"PRIu64 "%s offer %"PRIu64
" not between %"PRIu64" and %"PRIu64, " not between %"PRIu64" and %"PRIu64,
side == LOCAL ? "local" : "remote", side == LOCAL ? "local" : "remote",
offer, feerange->min, feerange->max); offer, feerange->min, feerange->max);
status_trace("Allowing deprecated out-of-range fee");
return;
}
/* BOLT #2: /* BOLT #2:
* *
@ -444,6 +451,7 @@ int main(int argc, char *argv[])
u64 next_index[NUM_SIDES], revocations_received; u64 next_index[NUM_SIDES], revocations_received;
u64 gossip_index; u64 gossip_index;
enum side whose_turn; enum side whose_turn;
bool deprecated_api;
subdaemon_setup(argc, argv); subdaemon_setup(argc, argv);
@ -466,7 +474,8 @@ int main(int argc, char *argv[])
&reconnected, &reconnected,
&next_index[LOCAL], &next_index[LOCAL],
&next_index[REMOTE], &next_index[REMOTE],
&revocations_received)) &revocations_received,
&deprecated_api))
master_badmsg(WIRE_CLOSING_INIT, msg); master_badmsg(WIRE_CLOSING_INIT, msg);
status_trace("satoshi_out = %"PRIu64"/%"PRIu64, status_trace("satoshi_out = %"PRIu64"/%"PRIu64,
@ -512,7 +521,7 @@ int main(int argc, char *argv[])
} }
/* Now we have first two points, we can init fee range. */ /* Now we have first two points, we can init fee range. */
init_feerange(&feerange, commitment_fee, offer); init_feerange(&feerange, commitment_fee, offer, deprecated_api);
/* Now apply the one constraint from above (other is inside loop). */ /* Now apply the one constraint from above (other is inside loop). */
adjust_feerange(&cs, &channel_id, &feerange, adjust_feerange(&cs, &channel_id, &feerange,

2
closingd/closing_wire.csv

@ -24,6 +24,8 @@ closing_init,,reconnected,bool
closing_init,,next_index_local,u64 closing_init,,next_index_local,u64
closing_init,,next_index_remote,u64 closing_init,,next_index_remote,u64
closing_init,,revocations_received,u64 closing_init,,revocations_received,u64
# This means we allow closing negotiations out of bounds.
closing_init,,deprecated_api,bool
# We received an offer, save signature. # We received an offer, save signature.
closing_received_signature,2002 closing_received_signature,2002

Can't render this file because it has a wrong number of fields in line 3.

3
lightningd/peer_control.c

@ -1976,7 +1976,8 @@ static void peer_start_closingd(struct peer *peer,
reconnected, reconnected,
peer->next_index[LOCAL], peer->next_index[LOCAL],
peer->next_index[REMOTE], peer->next_index[REMOTE],
num_revocations); num_revocations,
deprecated_apis);
/* We don't expect a response: it will give us feedback on /* We don't expect a response: it will give us feedback on
* signatures sent and received, then closing_complete. */ * signatures sent and received, then closing_complete. */

Loading…
Cancel
Save