@@ -79,9 +79,11 @@ use bitcoin::secp256k1::schnorr;
79
79
use bitcoin:: secp256k1:: { self , Message , PublicKey , Scalar , Secp256k1 , SecretKey } ;
80
80
81
81
use lightning:: util:: dyn_signer:: DynSigner ;
82
+
83
+ use std:: collections:: VecDeque ;
82
84
use std:: cell:: RefCell ;
83
85
use std:: cmp;
84
- use std:: sync:: atomic:: { AtomicBool , AtomicU64 , AtomicUsize , Ordering } ;
86
+ use std:: sync:: atomic:: { AtomicU64 , AtomicUsize , Ordering } ;
85
87
use std:: sync:: { Arc , Mutex } ;
86
88
87
89
#[ inline]
@@ -110,7 +112,7 @@ pub fn slice_to_be24(v: &[u8]) -> u32 {
110
112
struct InputData {
111
113
data : Vec < u8 > ,
112
114
read_pos : AtomicUsize ,
113
- halt_fee_est_reads : AtomicBool ,
115
+ fee_estimates : Mutex < VecDeque < u32 > > ,
114
116
}
115
117
impl InputData {
116
118
fn get_slice ( & self , len : usize ) -> Option < & [ u8 ] > {
@@ -137,14 +139,10 @@ struct FuzzEstimator {
137
139
}
138
140
impl FeeEstimator for FuzzEstimator {
139
141
fn get_est_sat_per_1000_weight ( & self , _: ConfirmationTarget ) -> u32 {
140
- if self . input . halt_fee_est_reads . load ( Ordering :: Acquire ) {
141
- return 253 ;
142
- }
143
- //TODO: We should actually be testing at least much more than 64k...
144
- match self . input . get_slice ( 2 ) {
145
- Some ( slice) => cmp:: max ( slice_to_be16 ( slice) as u32 , 253 ) ,
146
- None => 253 ,
142
+ if let Some ( val) = self . input . fee_estimates . lock ( ) . unwrap ( ) . pop_front ( ) {
143
+ return val;
147
144
}
145
+ return 253 ;
148
146
}
149
147
}
150
148
@@ -539,7 +537,7 @@ pub fn do_test(mut data: &[u8], logger: &Arc<dyn Logger>) {
539
537
let input = Arc :: new ( InputData {
540
538
data : data. to_vec ( ) ,
541
539
read_pos : AtomicUsize :: new ( 0 ) ,
542
- halt_fee_est_reads : AtomicBool :: new ( false ) ,
540
+ fee_estimates : Mutex :: new ( VecDeque :: new ( ) ) ,
543
541
} ) ;
544
542
let fee_est = Arc :: new ( FuzzEstimator { input : input. clone ( ) } ) ;
545
543
let router = FuzzRouter { } ;
@@ -882,12 +880,10 @@ pub fn do_test(mut data: &[u8], logger: &Arc<dyn Logger>) {
882
880
11 => {
883
881
let mut txn = broadcast. txn_broadcasted . lock ( ) . unwrap ( ) . split_off ( 0 ) ;
884
882
if !txn. is_empty ( ) {
885
- input. halt_fee_est_reads . store ( true , Ordering :: Release ) ;
886
883
loss_detector. connect_block ( & txn[ ..] ) ;
887
884
for _ in 2 ..100 {
888
885
loss_detector. connect_block ( & [ ] ) ;
889
886
}
890
- input. halt_fee_est_reads . store ( false , Ordering :: Release ) ;
891
887
}
892
888
for tx in txn. drain ( ..) {
893
889
loss_detector. funding_txn . push ( tx) ;
@@ -986,6 +982,10 @@ pub fn do_test(mut data: &[u8], logger: &Arc<dyn Logger>) {
986
982
) ;
987
983
}
988
984
} ,
985
+ 48 => {
986
+ let fee = u32:: from_le_bytes ( get_slice ! ( 4 ) . try_into ( ) . unwrap ( ) ) ;
987
+ input. fee_estimates . lock ( ) . unwrap ( ) . push_back ( fee) ;
988
+ } ,
989
989
_ => return ,
990
990
}
991
991
loss_detector. handler . process_events ( ) ;
@@ -1084,8 +1084,6 @@ fn two_peer_forwarding_seed() -> Vec<u8> {
1084
1084
// rest of open_channel and mac
1085
1085
ext_from_hex ( "030000000000000000000000000000000000000000000000000000000000000005 020900000000000000000000000000000000000000000000000000000000000000 01 0000 01021000 03000000000000000000000000000000" , & mut test) ;
1086
1086
1087
- // One feerate request returning min feerate, which our open_channel also uses (ingested by FuzzEstimator)
1088
- ext_from_hex ( "00fd" , & mut test) ;
1089
1087
// client should now respond with accept_channel (CHECK 1: type 33 to peer 03000000)
1090
1088
1091
1089
// inbound read from peer id 0 of len 18
@@ -1102,45 +1100,19 @@ fn two_peer_forwarding_seed() -> Vec<u8> {
1102
1100
ext_from_hex ( "0c005e" , & mut test) ;
1103
1101
// the funding transaction
1104
1102
ext_from_hex ( "020000000100000000000000000000000000000000000000000000000000000000000000000000000000ffffffff0150c3000000000000220020ae0000000000000000000000000000000000000000000000000000000000000000000000" , & mut test) ;
1105
- // Two feerate requests during block connection
1106
- ext_from_hex ( "00fd00fd" , & mut test) ;
1107
1103
// connect a block with no transactions, one per line
1108
1104
ext_from_hex ( "0c0000" , & mut test) ;
1109
- // Two feerate requests during block connection
1110
- ext_from_hex ( "00fd00fd" , & mut test) ;
1111
1105
ext_from_hex ( "0c0000" , & mut test) ;
1112
- // Two feerate requests during block connection
1113
- ext_from_hex ( "00fd00fd" , & mut test) ;
1114
1106
ext_from_hex ( "0c0000" , & mut test) ;
1115
- // Two feerate requests during block connection
1116
- ext_from_hex ( "00fd00fd" , & mut test) ;
1117
1107
ext_from_hex ( "0c0000" , & mut test) ;
1118
- // Two feerate requests during block connection
1119
- ext_from_hex ( "00fd00fd" , & mut test) ;
1120
1108
ext_from_hex ( "0c0000" , & mut test) ;
1121
- // Two feerate requests during block connection
1122
- ext_from_hex ( "00fd00fd" , & mut test) ;
1123
1109
ext_from_hex ( "0c0000" , & mut test) ;
1124
- // Two feerate requests during block connection
1125
- ext_from_hex ( "00fd00fd" , & mut test) ;
1126
1110
ext_from_hex ( "0c0000" , & mut test) ;
1127
- // Two feerate requests during block connection
1128
- ext_from_hex ( "00fd00fd" , & mut test) ;
1129
1111
ext_from_hex ( "0c0000" , & mut test) ;
1130
- // Two feerate requests during block connection
1131
- ext_from_hex ( "00fd00fd" , & mut test) ;
1132
1112
ext_from_hex ( "0c0000" , & mut test) ;
1133
- // Two feerate requests during block connection
1134
- ext_from_hex ( "00fd00fd" , & mut test) ;
1135
1113
ext_from_hex ( "0c0000" , & mut test) ;
1136
- // Two feerate requests during block connection
1137
- ext_from_hex ( "00fd00fd" , & mut test) ;
1138
1114
ext_from_hex ( "0c0000" , & mut test) ;
1139
- // Two feerate requests during block connection
1140
- ext_from_hex ( "00fd00fd" , & mut test) ;
1141
1115
ext_from_hex ( "0c0000" , & mut test) ;
1142
- // Two feerate requests during block connection
1143
- ext_from_hex ( "00fd00fd" , & mut test) ;
1144
1116
// by now client should have sent a channel_ready (CHECK 3: SendChannelReady to 03000000 for chan 3d000000)
1145
1117
1146
1118
// inbound read from peer id 0 of len 18
@@ -1171,17 +1143,12 @@ fn two_peer_forwarding_seed() -> Vec<u8> {
1171
1143
ext_from_hex ( "030120" , & mut test) ;
1172
1144
// init message (type 16) with static_remotekey required, no anchors/taproot, and other bits optional and mac
1173
1145
ext_from_hex ( "0010 00021aaa 0008aaa210aa2a0a9aaa 01000000000000000000000000000000" , & mut test) ;
1174
- // One feerate request on peer connection due to a list_channels call when seeing if the async
1175
- // receive offer cache needs updating
1176
- ext_from_hex ( "00fd" , & mut test) ;
1177
1146
1178
1147
// create outbound channel to peer 1 for 50k sat
1179
1148
ext_from_hex (
1180
1149
"05 01 030200000000000000000000000000000000000000000000000000000000000000 00c350 0003e8" ,
1181
1150
& mut test,
1182
1151
) ;
1183
- // One feerate requests (all returning min feerate) (gonna be ingested by FuzzEstimator)
1184
- ext_from_hex ( "00fd" , & mut test) ;
1185
1152
1186
1153
// inbound read from peer id 1 of len 18
1187
1154
ext_from_hex ( "030112" , & mut test) ;
@@ -1201,8 +1168,6 @@ fn two_peer_forwarding_seed() -> Vec<u8> {
1201
1168
1202
1169
// create the funding transaction (client should send funding_created now)
1203
1170
ext_from_hex ( "0a" , & mut test) ;
1204
- // Two feerate requests to check the dust exposure on the initial commitment tx
1205
- ext_from_hex ( "00fd00fd" , & mut test) ;
1206
1171
1207
1172
// inbound read from peer id 1 of len 18
1208
1173
ext_from_hex ( "030112" , & mut test) ;
@@ -1251,9 +1216,6 @@ fn two_peer_forwarding_seed() -> Vec<u8> {
1251
1216
// end of update_add_htlc from 0 to 1 via client and mac
1252
1217
ext_from_hex ( "ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff ab00000000000000000000000000000000000000000000000000000000000000 03000000000000000000000000000000" , & mut test) ;
1253
1218
1254
- // One feerate request to check dust exposure
1255
- ext_from_hex ( "00fd" , & mut test) ;
1256
-
1257
1219
// inbound read from peer id 0 of len 18
1258
1220
ext_from_hex ( "030012" , & mut test) ;
1259
1221
// message header indicating message length 100
@@ -1275,8 +1237,6 @@ fn two_peer_forwarding_seed() -> Vec<u8> {
1275
1237
1276
1238
// process the now-pending HTLC forward
1277
1239
ext_from_hex ( "07" , & mut test) ;
1278
- // Four feerate requests to check dust exposure while forwarding the HTLC
1279
- ext_from_hex ( "00fd00fd00fd00fd" , & mut test) ;
1280
1240
// client now sends id 1 update_add_htlc and commitment_signed (CHECK 7: UpdateHTLCs event for node 03020000 with 1 HTLCs for channel 2f000000)
1281
1241
1282
1242
// we respond with commitment_signed then revoke_and_ack (a weird, but valid, order)
@@ -1352,9 +1312,6 @@ fn two_peer_forwarding_seed() -> Vec<u8> {
1352
1312
// end of update_add_htlc from 0 to 1 via client and mac
1353
1313
ext_from_hex ( "ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff ab00000000000000000000000000000000000000000000000000000000000000 03000000000000000000000000000000" , & mut test) ;
1354
1314
1355
- // One feerate request to check dust exposure
1356
- ext_from_hex ( "00fd" , & mut test) ;
1357
-
1358
1315
// now respond to the update_fulfill_htlc+commitment_signed messages the client sent to peer 0
1359
1316
// inbound read from peer id 0 of len 18
1360
1317
ext_from_hex ( "030012" , & mut test) ;
@@ -1387,9 +1344,6 @@ fn two_peer_forwarding_seed() -> Vec<u8> {
1387
1344
// process the now-pending HTLC forward
1388
1345
ext_from_hex ( "07" , & mut test) ;
1389
1346
1390
- // Four feerate requests to check dust exposure while forwarding the HTLC
1391
- ext_from_hex ( "00fd00fd00fd00fd" , & mut test) ;
1392
-
1393
1347
// client now sends id 1 update_add_htlc and commitment_signed (CHECK 7 duplicate)
1394
1348
// we respond with revoke_and_ack, then commitment_signed, then update_fail_htlc
1395
1349
@@ -1487,9 +1441,6 @@ fn two_peer_forwarding_seed() -> Vec<u8> {
1487
1441
// end of update_add_htlc from 0 to 1 via client and mac
1488
1442
ext_from_hex ( "ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff 5200000000000000000000000000000000000000000000000000000000000000 03000000000000000000000000000000" , & mut test) ;
1489
1443
1490
- // One feerate request to check dust exposure
1491
- ext_from_hex ( "00fd" , & mut test) ;
1492
-
1493
1444
// inbound read from peer id 0 of len 18
1494
1445
ext_from_hex ( "030012" , & mut test) ;
1495
1446
// message header indicating message length 164
@@ -1511,43 +1462,27 @@ fn two_peer_forwarding_seed() -> Vec<u8> {
1511
1462
1512
1463
// process the now-pending HTLC forward
1513
1464
ext_from_hex ( "07" , & mut test) ;
1514
- // Four feerate requests to check dust exposure while forwarding the HTLC
1515
- ext_from_hex ( "00fd00fd00fd00fd" , & mut test) ;
1516
1465
// client now sends id 1 update_add_htlc and commitment_signed (CHECK 7 duplicate)
1517
1466
1518
1467
// connect a block with one transaction of len 125
1519
1468
ext_from_hex ( "0c007d" , & mut test) ;
1520
1469
// the commitment transaction for channel 2900000000000000000000000000000000000000000000000000000000000000
1521
1470
ext_from_hex ( "020000000129000000000000000000000000000000000000000000000000000000000000000000000000000000800258020000000000002200201f0000000000000000000000000000000000000000000000000000000000000013c00000000000001600143b0000000000000000000000000000000000000005000020" , & mut test) ;
1522
- // Two feerate requests during block connection
1523
- ext_from_hex ( "00fd00fd" , & mut test) ;
1524
1471
//
1525
1472
// connect a block with one transaction of len 94
1526
1473
ext_from_hex ( "0c005e" , & mut test) ;
1527
1474
// the HTLC timeout transaction
1528
1475
ext_from_hex ( "0200000001200000000000000000000000000000000000000000000000000000000000000000000000000000000001a701000000000000220020e60000000000000000000000000000000000000000000000000000000000000000000000" , & mut test) ;
1529
- // Two feerate requests during block connection
1530
- ext_from_hex ( "00fd00fd" , & mut test) ;
1531
1476
// connect a block with no transactions
1532
1477
ext_from_hex ( "0c0000" , & mut test) ;
1533
- // Two feerate requests during block connection
1534
- ext_from_hex ( "00fd00fd" , & mut test) ;
1535
1478
// connect a block with no transactions
1536
1479
ext_from_hex ( "0c0000" , & mut test) ;
1537
- // Two feerate requests during block connection
1538
- ext_from_hex ( "00fd00fd" , & mut test) ;
1539
1480
// connect a block with no transactions
1540
1481
ext_from_hex ( "0c0000" , & mut test) ;
1541
- // Two feerate requests during block connection
1542
- ext_from_hex ( "00fd00fd" , & mut test) ;
1543
1482
// connect a block with no transactions
1544
1483
ext_from_hex ( "0c0000" , & mut test) ;
1545
- // Two feerate requests during block connection
1546
- ext_from_hex ( "00fd00fd" , & mut test) ;
1547
1484
// connect a block with no transactions
1548
1485
ext_from_hex ( "0c0000" , & mut test) ;
1549
- // Two feerate requests during block connection
1550
- ext_from_hex ( "00fd00fd" , & mut test) ;
1551
1486
1552
1487
// process the now-pending HTLC forward
1553
1488
ext_from_hex ( "07" , & mut test) ;
0 commit comments