Skip to content

Commit df28c3a

Browse files
committed
Drop fuzztarget feature entirely
Some time ago we started transitioning to `cfg(fuzzing)` instead of exposing a full feature. Here we complete the transition.
1 parent 8e7f241 commit df28c3a

15 files changed

+81
-82
lines changed

fuzz/Cargo.toml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ authors = ["Automatically generated"]
55
publish = false
66
# Because the function is unused it gets dropped before we link lightning, so
77
# we have to duplicate build.rs here. Note that this is only required for
8-
# fuzztarget mode.
8+
# fuzzing mode.
99

1010
[package.metadata]
1111
cargo-fuzz = true
@@ -18,7 +18,7 @@ stdin_fuzz = []
1818

1919
[dependencies]
2020
afl = { version = "0.4", optional = true }
21-
lightning = { path = "../lightning", features = ["fuzztarget"] }
21+
lightning = { path = "../lightning", features = ["regex"] }
2222
bitcoin = { version = "0.27", features = ["fuzztarget", "secp-lowmemory"] }
2323
hex = "0.3"
2424
honggfuzz = { version = "0.5", optional = true }

lightning/Cargo.toml

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,6 @@ Still missing tons of error-handling. See GitHub issues for suggested projects i
1111
"""
1212

1313
[features]
14-
fuzztarget = ["bitcoin/fuzztarget", "regex"]
1514
# Internal test utilities exposed to other repo crates
1615
_test_utils = ["hex", "regex", "bitcoin/bitcoinconsensus"]
1716
# Unlog messages superior at targeted level.

lightning/src/chain/chainmonitor.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -474,15 +474,15 @@ where C::Target: chain::Filter,
474474
/// This wrapper avoids having to update some of our tests for now as they assume the direct
475475
/// chain::Watch API wherein we mark a monitor fully-updated by just calling
476476
/// channel_monitor_updated once with the highest ID.
477-
#[cfg(any(test, feature = "fuzztarget"))]
477+
#[cfg(any(test, fuzzing))]
478478
pub fn force_channel_monitor_updated(&self, funding_txo: OutPoint, monitor_update_id: u64) {
479479
self.pending_monitor_events.lock().unwrap().push(MonitorEvent::UpdateCompleted {
480480
funding_txo,
481481
monitor_update_id,
482482
});
483483
}
484484

485-
#[cfg(any(test, feature = "fuzztarget", feature = "_test_utils"))]
485+
#[cfg(any(test, fuzzing, feature = "_test_utils"))]
486486
pub fn get_and_clear_pending_events(&self) -> Vec<events::Event> {
487487
use util::events::EventsProvider;
488488
let events = core::cell::RefCell::new(Vec::new());
@@ -630,9 +630,9 @@ where C::Target: chain::Filter,
630630
// We should never ever trigger this from within ChannelManager. Technically a
631631
// user could use this object with some proxying in between which makes this
632632
// possible, but in tests and fuzzing, this should be a panic.
633-
#[cfg(any(test, feature = "fuzztarget"))]
633+
#[cfg(any(test, fuzzing))]
634634
panic!("ChannelManager generated a channel update for a channel that was not yet registered!");
635-
#[cfg(not(any(test, feature = "fuzztarget")))]
635+
#[cfg(not(any(test, fuzzing)))]
636636
Err(ChannelMonitorUpdateErr::PermanentFailure)
637637
},
638638
Some(monitor_state) => {

lightning/src/chain/channelmonitor.rs

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,7 @@ use sync::Mutex;
5959

6060
/// An update generated by the underlying Channel itself which contains some new information the
6161
/// ChannelMonitor should be made aware of.
62-
#[cfg_attr(any(test, feature = "fuzztarget", feature = "_test_utils"), derive(PartialEq))]
62+
#[cfg_attr(any(test, fuzzing, feature = "_test_utils"), derive(PartialEq))]
6363
#[derive(Clone)]
6464
#[must_use]
6565
pub struct ChannelMonitorUpdate {
@@ -441,7 +441,7 @@ impl_writeable_tlv_based_enum_upgradable!(OnchainEvent,
441441

442442
);
443443

444-
#[cfg_attr(any(test, feature = "fuzztarget", feature = "_test_utils"), derive(PartialEq))]
444+
#[cfg_attr(any(test, fuzzing, feature = "_test_utils"), derive(PartialEq))]
445445
#[derive(Clone)]
446446
pub(crate) enum ChannelMonitorUpdateStep {
447447
LatestHolderCommitmentTXInfo {
@@ -711,9 +711,9 @@ pub(crate) struct ChannelMonitorImpl<Signer: Sign> {
711711
/// Transaction outputs to watch for on-chain spends.
712712
pub type TransactionOutputs = (Txid, Vec<(u32, TxOut)>);
713713

714-
#[cfg(any(test, feature = "fuzztarget", feature = "_test_utils"))]
715-
/// Used only in testing and fuzztarget to check serialization roundtrips don't change the
716-
/// underlying object
714+
#[cfg(any(test, fuzzing, feature = "_test_utils"))]
715+
/// Used only in testing and fuzzing to check serialization roundtrips don't change the underlying
716+
/// object
717717
impl<Signer: Sign> PartialEq for ChannelMonitor<Signer> {
718718
fn eq(&self, other: &Self) -> bool {
719719
let inner = self.inner.lock().unwrap();
@@ -722,9 +722,9 @@ impl<Signer: Sign> PartialEq for ChannelMonitor<Signer> {
722722
}
723723
}
724724

725-
#[cfg(any(test, feature = "fuzztarget", feature = "_test_utils"))]
726-
/// Used only in testing and fuzztarget to check serialization roundtrips don't change the
727-
/// underlying object
725+
#[cfg(any(test, fuzzing, feature = "_test_utils"))]
726+
/// Used only in testing and fuzzing to check serialization roundtrips don't change the underlying
727+
/// object
728728
impl<Signer: Sign> PartialEq for ChannelMonitorImpl<Signer> {
729729
fn eq(&self, other: &Self) -> bool {
730730
if self.latest_update_id != other.latest_update_id ||

lightning/src/lib.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -18,8 +18,8 @@
1818
//! generated/etc. This makes it a good candidate for tight integration into an existing wallet
1919
//! instead of having a rather-separate lightning appendage to a wallet.
2020
21-
#![cfg_attr(not(any(test, feature = "fuzztarget", feature = "_test_utils")), deny(missing_docs))]
22-
#![cfg_attr(not(any(test, feature = "fuzztarget", feature = "_test_utils")), forbid(unsafe_code))]
21+
#![cfg_attr(not(any(test, fuzzing, feature = "_test_utils")), deny(missing_docs))]
22+
#![cfg_attr(not(any(test, fuzzing, feature = "_test_utils")), forbid(unsafe_code))]
2323
#![deny(broken_intra_doc_links)]
2424

2525
// In general, rust is absolutely horrid at supporting users doing things like,
@@ -43,7 +43,7 @@ extern crate bitcoin;
4343
extern crate core;
4444

4545
#[cfg(any(test, feature = "_test_utils"))] extern crate hex;
46-
#[cfg(any(test, feature = "fuzztarget", feature = "_test_utils"))] extern crate regex;
46+
#[cfg(any(test, fuzzing, feature = "_test_utils"))] extern crate regex;
4747

4848
#[cfg(not(feature = "std"))] extern crate core2;
4949

lightning/src/ln/chan_utils.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1251,7 +1251,7 @@ impl CommitmentTransaction {
12511251
if let &Some(ref b_htlcout) = b {
12521252
a_htlcout.cltv_expiry.cmp(&b_htlcout.cltv_expiry)
12531253
// Note that due to hash collisions, we have to have a fallback comparison
1254-
// here for fuzztarget mode (otherwise at least chanmon_fail_consistency
1254+
// here for fuzzing mode (otherwise at least chanmon_fail_consistency
12551255
// may fail)!
12561256
.then(a_htlcout.payment_hash.0.cmp(&b_htlcout.payment_hash.0))
12571257
// For non-HTLC outputs, if they're copying our SPK we don't really care if we

lightning/src/ln/channel.rs

Lines changed: 34 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@ use io;
4646
use prelude::*;
4747
use core::{cmp,mem,fmt};
4848
use core::ops::Deref;
49-
#[cfg(any(test, feature = "fuzztarget", debug_assertions))]
49+
#[cfg(any(test, fuzzing, debug_assertions))]
5050
use sync::Mutex;
5151
use bitcoin::hashes::hex::ToHex;
5252

@@ -670,9 +670,9 @@ pub(super) struct Channel<Signer: Sign> {
670670
// `next_remote_commit_tx_fee_msat` properly predict what the next commitment transaction fee will
671671
// be, by comparing the cached values to the fee of the tranaction generated by
672672
// `build_commitment_transaction`.
673-
#[cfg(any(test, feature = "fuzztarget"))]
673+
#[cfg(any(test, fuzzing))]
674674
next_local_commitment_tx_fee_info_cached: Mutex<Option<CommitmentTxInfoCached>>,
675-
#[cfg(any(test, feature = "fuzztarget"))]
675+
#[cfg(any(test, fuzzing))]
676676
next_remote_commitment_tx_fee_info_cached: Mutex<Option<CommitmentTxInfoCached>>,
677677

678678
/// lnd has a long-standing bug where, upon reconnection, if the channel is not yet confirmed
@@ -684,7 +684,7 @@ pub(super) struct Channel<Signer: Sign> {
684684
/// See-also <https://github.com/lightningnetwork/lnd/issues/4006>
685685
pub workaround_lnd_bug_4006: Option<msgs::FundingLocked>,
686686

687-
#[cfg(any(test, feature = "fuzztarget"))]
687+
#[cfg(any(test, fuzzing))]
688688
// When we receive an HTLC fulfill on an outbound path, we may immediately fulfill the
689689
// corresponding HTLC on the inbound path. If, then, the outbound path channel is
690690
// disconnected and reconnected (before we've exchange commitment_signed and revoke_and_ack
@@ -697,7 +697,7 @@ pub(super) struct Channel<Signer: Sign> {
697697
channel_type: ChannelTypeFeatures,
698698
}
699699

700-
#[cfg(any(test, feature = "fuzztarget"))]
700+
#[cfg(any(test, fuzzing))]
701701
struct CommitmentTxInfoCached {
702702
fee: u64,
703703
total_pending_htlcs: usize,
@@ -940,14 +940,14 @@ impl<Signer: Sign> Channel<Signer> {
940940

941941
announcement_sigs: None,
942942

943-
#[cfg(any(test, feature = "fuzztarget"))]
943+
#[cfg(any(test, fuzzing))]
944944
next_local_commitment_tx_fee_info_cached: Mutex::new(None),
945-
#[cfg(any(test, feature = "fuzztarget"))]
945+
#[cfg(any(test, fuzzing))]
946946
next_remote_commitment_tx_fee_info_cached: Mutex::new(None),
947947

948948
workaround_lnd_bug_4006: None,
949949

950-
#[cfg(any(test, feature = "fuzztarget"))]
950+
#[cfg(any(test, fuzzing))]
951951
historical_inbound_htlc_fulfills: HashSet::new(),
952952

953953
// We currently only actually support one channel type, so don't retry with new types
@@ -1245,14 +1245,14 @@ impl<Signer: Sign> Channel<Signer> {
12451245

12461246
announcement_sigs: None,
12471247

1248-
#[cfg(any(test, feature = "fuzztarget"))]
1248+
#[cfg(any(test, fuzzing))]
12491249
next_local_commitment_tx_fee_info_cached: Mutex::new(None),
1250-
#[cfg(any(test, feature = "fuzztarget"))]
1250+
#[cfg(any(test, fuzzing))]
12511251
next_remote_commitment_tx_fee_info_cached: Mutex::new(None),
12521252

12531253
workaround_lnd_bug_4006: None,
12541254

1255-
#[cfg(any(test, feature = "fuzztarget"))]
1255+
#[cfg(any(test, fuzzing))]
12561256
historical_inbound_htlc_fulfills: HashSet::new(),
12571257

12581258
channel_type,
@@ -1650,7 +1650,7 @@ impl<Signer: Sign> Channel<Signer> {
16501650
}
16511651
}
16521652
if pending_idx == core::usize::MAX {
1653-
#[cfg(any(test, feature = "fuzztarget"))]
1653+
#[cfg(any(test, fuzzing))]
16541654
// If we failed to find an HTLC to fulfill, make sure it was previously fulfilled and
16551655
// this is simply a duplicate claim, not previously failed and we lost funds.
16561656
debug_assert!(self.historical_inbound_htlc_fulfills.contains(&htlc_id_arg));
@@ -1676,7 +1676,7 @@ impl<Signer: Sign> Channel<Signer> {
16761676
if htlc_id_arg == htlc_id {
16771677
// Make sure we don't leave latest_monitor_update_id incremented here:
16781678
self.latest_monitor_update_id -= 1;
1679-
#[cfg(any(test, feature = "fuzztarget"))]
1679+
#[cfg(any(test, fuzzing))]
16801680
debug_assert!(self.historical_inbound_htlc_fulfills.contains(&htlc_id_arg));
16811681
return UpdateFulfillFetch::DuplicateClaim {};
16821682
}
@@ -1697,11 +1697,11 @@ impl<Signer: Sign> Channel<Signer> {
16971697
self.holding_cell_htlc_updates.push(HTLCUpdateAwaitingACK::ClaimHTLC {
16981698
payment_preimage: payment_preimage_arg, htlc_id: htlc_id_arg,
16991699
});
1700-
#[cfg(any(test, feature = "fuzztarget"))]
1700+
#[cfg(any(test, fuzzing))]
17011701
self.historical_inbound_htlc_fulfills.insert(htlc_id_arg);
17021702
return UpdateFulfillFetch::NewClaim { monitor_update, htlc_value_msat, msg: None };
17031703
}
1704-
#[cfg(any(test, feature = "fuzztarget"))]
1704+
#[cfg(any(test, fuzzing))]
17051705
self.historical_inbound_htlc_fulfills.insert(htlc_id_arg);
17061706

17071707
{
@@ -1782,7 +1782,7 @@ impl<Signer: Sign> Channel<Signer> {
17821782
}
17831783
}
17841784
if pending_idx == core::usize::MAX {
1785-
#[cfg(any(test, feature = "fuzztarget"))]
1785+
#[cfg(any(test, fuzzing))]
17861786
// If we failed to find an HTLC to fail, make sure it was previously fulfilled and this
17871787
// is simply a duplicate fail, not previously failed and we failed-back too early.
17881788
debug_assert!(self.historical_inbound_htlc_fulfills.contains(&htlc_id_arg));
@@ -1795,7 +1795,7 @@ impl<Signer: Sign> Channel<Signer> {
17951795
match pending_update {
17961796
&HTLCUpdateAwaitingACK::ClaimHTLC { htlc_id, .. } => {
17971797
if htlc_id_arg == htlc_id {
1798-
#[cfg(any(test, feature = "fuzztarget"))]
1798+
#[cfg(any(test, fuzzing))]
17991799
debug_assert!(self.historical_inbound_htlc_fulfills.contains(&htlc_id_arg));
18001800
return Ok(None);
18011801
}
@@ -2367,7 +2367,7 @@ impl<Signer: Sign> Channel<Signer> {
23672367

23682368
let num_htlcs = included_htlcs + addl_htlcs;
23692369
let res = Self::commit_tx_fee_msat(self.feerate_per_kw, num_htlcs, self.opt_anchors());
2370-
#[cfg(any(test, feature = "fuzztarget"))]
2370+
#[cfg(any(test, fuzzing))]
23712371
{
23722372
let mut fee = res;
23732373
if fee_spike_buffer_htlc.is_some() {
@@ -2445,7 +2445,7 @@ impl<Signer: Sign> Channel<Signer> {
24452445

24462446
let num_htlcs = included_htlcs + addl_htlcs;
24472447
let res = Self::commit_tx_fee_msat(self.feerate_per_kw, num_htlcs, self.opt_anchors());
2448-
#[cfg(any(test, feature = "fuzztarget"))]
2448+
#[cfg(any(test, fuzzing))]
24492449
{
24502450
let mut fee = res;
24512451
if fee_spike_buffer_htlc.is_some() {
@@ -2728,7 +2728,7 @@ impl<Signer: Sign> Channel<Signer> {
27282728
return Err((None, ChannelError::Close("Funding remote cannot afford proposed new fee".to_owned())));
27292729
}
27302730
}
2731-
#[cfg(any(test, feature = "fuzztarget"))]
2731+
#[cfg(any(test, fuzzing))]
27322732
{
27332733
if self.is_outbound() {
27342734
let projected_commit_tx_info = self.next_local_commitment_tx_fee_info_cached.lock().unwrap().take();
@@ -3035,7 +3035,7 @@ impl<Signer: Sign> Channel<Signer> {
30353035
return Err(ChannelError::Close("Received an unexpected revoke_and_ack".to_owned()));
30363036
}
30373037

3038-
#[cfg(any(test, feature = "fuzztarget"))]
3038+
#[cfg(any(test, fuzzing))]
30393039
{
30403040
*self.next_local_commitment_tx_fee_info_cached.lock().unwrap() = None;
30413041
*self.next_remote_commitment_tx_fee_info_cached.lock().unwrap() = None;
@@ -4466,9 +4466,9 @@ impl<Signer: Sign> Channel<Signer> {
44664466
// If we generated the funding transaction and it doesn't match what it
44674467
// should, the client is really broken and we should just panic and
44684468
// tell them off. That said, because hash collisions happen with high
4469-
// probability in fuzztarget mode, if we're fuzzing we just close the
4469+
// probability in fuzzing mode, if we're fuzzing we just close the
44704470
// channel and move on.
4471-
#[cfg(not(feature = "fuzztarget"))]
4471+
#[cfg(not(fuzzing))]
44724472
panic!("Client called ChannelManager::funding_transaction_generated with bogus transaction!");
44734473
}
44744474
self.update_time_counter += 1;
@@ -4480,7 +4480,7 @@ impl<Signer: Sign> Channel<Signer> {
44804480
if input.witness.is_empty() {
44814481
// We generated a malleable funding transaction, implying we've
44824482
// just exposed ourselves to funds loss to our counterparty.
4483-
#[cfg(not(feature = "fuzztarget"))]
4483+
#[cfg(not(fuzzing))]
44844484
panic!("Client called ChannelManager::funding_transaction_generated with bogus transaction!");
44854485
}
44864486
}
@@ -4937,9 +4937,9 @@ impl<Signer: Sign> Channel<Signer> {
49374937
// Prior to static_remotekey, my_current_per_commitment_point was critical to claiming
49384938
// current to_remote balances. However, it no longer has any use, and thus is now simply
49394939
// set to a dummy (but valid, as required by the spec) public key.
4940-
// fuzztarget mode marks a subset of pubkeys as invalid so that we can hit "invalid pubkey"
4940+
// fuzzing mode marks a subset of pubkeys as invalid so that we can hit "invalid pubkey"
49414941
// branches, but we unwrap it below, so we arbitrarily select a dummy pubkey which is both
4942-
// valid, and valid in fuzztarget mode's arbitrary validity criteria:
4942+
// valid, and valid in fuzzing mode's arbitrary validity criteria:
49434943
let mut pk = [2; 33]; pk[1] = 0xff;
49444944
let dummy_pubkey = PublicKey::from_slice(&pk).unwrap();
49454945
let data_loss_protect = if self.cur_counterparty_commitment_transaction_number + 1 < INITIAL_COMMITMENT_NUMBER {
@@ -5225,7 +5225,7 @@ impl<Signer: Sign> Channel<Signer> {
52255225
let counterparty_commitment_txid = commitment_stats.tx.trust().txid();
52265226
let (signature, htlc_signatures);
52275227

5228-
#[cfg(any(test, feature = "fuzztarget"))]
5228+
#[cfg(any(test, fuzzing))]
52295229
{
52305230
if !self.is_outbound() {
52315231
let projected_commit_tx_info = self.next_remote_commitment_tx_fee_info_cached.lock().unwrap().take();
@@ -5711,9 +5711,9 @@ impl<Signer: Sign> Writeable for Channel<Signer> {
57115711

57125712
self.channel_update_status.write(writer)?;
57135713

5714-
#[cfg(any(test, feature = "fuzztarget"))]
5714+
#[cfg(any(test, fuzzing))]
57155715
(self.historical_inbound_htlc_fulfills.len() as u64).write(writer)?;
5716-
#[cfg(any(test, feature = "fuzztarget"))]
5716+
#[cfg(any(test, fuzzing))]
57175717
for htlc in self.historical_inbound_htlc_fulfills.iter() {
57185718
htlc.write(writer)?;
57195719
}
@@ -5975,9 +5975,9 @@ impl<'a, Signer: Sign, K: Deref> ReadableArgs<(&'a K, u32)> for Channel<Signer>
59755975

59765976
let channel_update_status = Readable::read(reader)?;
59775977

5978-
#[cfg(any(test, feature = "fuzztarget"))]
5978+
#[cfg(any(test, fuzzing))]
59795979
let mut historical_inbound_htlc_fulfills = HashSet::new();
5980-
#[cfg(any(test, feature = "fuzztarget"))]
5980+
#[cfg(any(test, fuzzing))]
59815981
{
59825982
let htlc_fulfills_len: u64 = Readable::read(reader)?;
59835983
for _ in 0..htlc_fulfills_len {
@@ -6151,14 +6151,14 @@ impl<'a, Signer: Sign, K: Deref> ReadableArgs<(&'a K, u32)> for Channel<Signer>
61516151

61526152
announcement_sigs,
61536153

6154-
#[cfg(any(test, feature = "fuzztarget"))]
6154+
#[cfg(any(test, fuzzing))]
61556155
next_local_commitment_tx_fee_info_cached: Mutex::new(None),
6156-
#[cfg(any(test, feature = "fuzztarget"))]
6156+
#[cfg(any(test, fuzzing))]
61576157
next_remote_commitment_tx_fee_info_cached: Mutex::new(None),
61586158

61596159
workaround_lnd_bug_4006: None,
61606160

6161-
#[cfg(any(test, feature = "fuzztarget"))]
6161+
#[cfg(any(test, fuzzing))]
61626162
historical_inbound_htlc_fulfills,
61636163

61646164
channel_type: channel_type.unwrap(),

0 commit comments

Comments
 (0)