Skip to content

Commit 24b285c

Browse files
committed
df: fail channel if peer sends witnesses that aren't paid for
The receiving node: ... - MUST fail the channel if: - the `witness_stack` weight lowers the effective `feerate` below the agreed upon transaction `feerate`
1 parent 9aff815 commit 24b285c

File tree

1 file changed

+53
-0
lines changed

1 file changed

+53
-0
lines changed

lightningd/dual_open_control.c

Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -953,6 +953,23 @@ REGISTER_PLUGIN_HOOK(rbf_channel,
953953
rbf_channel_hook_serialize,
954954
struct rbf_channel_payload *);
955955

956+
static bool feerate_satisfied(struct wally_psbt *psbt,
957+
u32 funding_feerate)
958+
{
959+
struct wally_tx *wtx;
960+
size_t tx_weight;
961+
struct amount_sat fee_paid, expected_fee;
962+
963+
wtx = psbt_final_tx(NULL, psbt);
964+
tx_weight = wally_tx_weight(wtx);
965+
tal_free(wtx);
966+
967+
fee_paid = psbt_compute_fee(psbt);
968+
expected_fee = amount_tx_fee(funding_feerate, tx_weight);
969+
970+
return amount_sat_greater_eq(fee_paid, expected_fee);
971+
}
972+
956973
static struct amount_sat calculate_reserve(struct channel_config *their_config,
957974
struct amount_sat funding_total,
958975
enum side opener)
@@ -1391,6 +1408,24 @@ static void handle_peer_tx_sigs_sent(struct subd *dualopend,
13911408
&channel->funding,
13921409
&channel->funding_txid,
13931410
&channel->remote_funding_locked);
1411+
1412+
/* BOLT-f53ca2301232db780843e894f55d95d512f297f9 #2
1413+
* The receiving node: ...
1414+
* - MUST fail the channel if:
1415+
* - the `witness_stack` weight lowers the
1416+
* effective `feerate` below the agreed upon
1417+
* transaction `feerate`
1418+
*/
1419+
if (!feerate_satisfied(inflight->funding_psbt,
1420+
inflight->funding->feerate))
1421+
channel_fail_permanent(channel,
1422+
REASON_PROTOCOL,
1423+
"Agreed feerate %dperkw not"
1424+
" met with witnesses %s",
1425+
inflight->funding->feerate,
1426+
type_to_string(tmpctx,
1427+
struct wally_psbt,
1428+
inflight->funding_psbt));
13941429
}
13951430
}
13961431

@@ -1688,6 +1723,24 @@ static void handle_peer_tx_sigs_msg(struct subd *dualopend,
16881723
&channel->funding,
16891724
&channel->funding_txid,
16901725
&channel->remote_funding_locked);
1726+
1727+
/* BOLT-f53ca2301232db780843e894f55d95d512f297f9 #2
1728+
* The receiving node: ...
1729+
* - MUST fail the channel if:
1730+
* - the `witness_stack` weight lowers the
1731+
* effective `feerate` below the agreed upon
1732+
* transaction `feerate`
1733+
*/
1734+
if (!feerate_satisfied(inflight->funding_psbt,
1735+
inflight->funding->feerate))
1736+
channel_fail_permanent(channel,
1737+
REASON_PROTOCOL,
1738+
"Agreed feerate %dperkw not"
1739+
" met with witnesses %s",
1740+
inflight->funding->feerate,
1741+
type_to_string(tmpctx,
1742+
struct wally_psbt,
1743+
inflight->funding_psbt));
16911744
}
16921745

16931746
/* Send notification with peer's signed PSBT */

0 commit comments

Comments
 (0)