@@ -953,6 +953,23 @@ REGISTER_PLUGIN_HOOK(rbf_channel,
953
953
rbf_channel_hook_serialize ,
954
954
struct rbf_channel_payload * );
955
955
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
+
956
973
static struct amount_sat calculate_reserve (struct channel_config * their_config ,
957
974
struct amount_sat funding_total ,
958
975
enum side opener )
@@ -1391,6 +1408,24 @@ static void handle_peer_tx_sigs_sent(struct subd *dualopend,
1391
1408
& channel -> funding ,
1392
1409
& channel -> funding_txid ,
1393
1410
& 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 ));
1394
1429
}
1395
1430
}
1396
1431
@@ -1688,6 +1723,24 @@ static void handle_peer_tx_sigs_msg(struct subd *dualopend,
1688
1723
& channel -> funding ,
1689
1724
& channel -> funding_txid ,
1690
1725
& 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 ));
1691
1744
}
1692
1745
1693
1746
/* Send notification with peer's signed PSBT */
0 commit comments