Skip to content

Commit 6fd13d7

Browse files
authored
Merge pull request #2367 from wpaulino/remove-anchors-flag
Remove anchors config flag
2 parents 3a98c2a + 82b646c commit 6fd13d7

15 files changed

+84
-194
lines changed

.github/workflows/build.yml

+2-3
Original file line numberDiff line numberDiff line change
@@ -194,16 +194,15 @@ jobs:
194194
cargo check --no-default-features --features=no-std --release
195195
cargo check --no-default-features --features=futures --release
196196
cargo doc --release
197-
RUSTDOCFLAGS="--cfg=anchors" cargo doc --release
198197
- name: Run cargo check for Taproot build.
199198
run: |
200199
cargo check --release
201200
cargo check --no-default-features --features=no-std --release
202201
cargo check --no-default-features --features=futures --release
203202
cargo doc --release
204203
env:
205-
RUSTFLAGS: '--cfg=anchors --cfg=taproot'
206-
RUSTDOCFLAGS: '--cfg=anchors --cfg=taproot'
204+
RUSTFLAGS: '--cfg=taproot'
205+
RUSTDOCFLAGS: '--cfg=taproot'
207206

208207
fuzz:
209208
runs-on: ubuntu-latest

ci/ci-tests.sh

+2-4
Original file line numberDiff line numberDiff line change
@@ -101,9 +101,7 @@ if [ "$RUSTC_MINOR_VERSION" -gt 55 ]; then
101101
popd
102102
fi
103103

104-
echo -e "\n\nTest anchors builds"
105-
pushd lightning
106-
RUSTFLAGS="$RUSTFLAGS --cfg=anchors" cargo test --verbose --color always -p lightning
107104
echo -e "\n\nTest Taproot builds"
108-
RUSTFLAGS="$RUSTFLAGS --cfg=anchors --cfg=taproot" cargo test --verbose --color always -p lightning
105+
pushd lightning
106+
RUSTFLAGS="$RUSTFLAGS --cfg=taproot" cargo test --verbose --color always -p lightning
109107
popd

lightning/src/chain/chainmonitor.rs

+2-19
Original file line numberDiff line numberDiff line change
@@ -782,30 +782,13 @@ impl<ChannelSigner: WriteableEcdsaChannelSigner, C: Deref, T: Deref, F: Deref, L
782782
L::Target: Logger,
783783
P::Target: Persist<ChannelSigner>,
784784
{
785-
#[cfg(not(anchors))]
786-
/// Processes [`SpendableOutputs`] events produced from each [`ChannelMonitor`] upon maturity.
787-
///
788-
/// An [`EventHandler`] may safely call back to the provider, though this shouldn't be needed in
789-
/// order to handle these events.
790-
///
791-
/// [`SpendableOutputs`]: events::Event::SpendableOutputs
792-
fn process_pending_events<H: Deref>(&self, handler: H) where H::Target: EventHandler {
793-
let mut pending_events = Vec::new();
794-
for monitor_state in self.monitors.read().unwrap().values() {
795-
pending_events.append(&mut monitor_state.monitor.get_and_clear_pending_events());
796-
}
797-
for event in pending_events {
798-
handler.handle_event(event);
799-
}
800-
}
801-
#[cfg(anchors)]
802785
/// Processes [`SpendableOutputs`] events produced from each [`ChannelMonitor`] upon maturity.
803786
///
804787
/// For channels featuring anchor outputs, this method will also process [`BumpTransaction`]
805788
/// events produced from each [`ChannelMonitor`] while there is a balance to claim onchain
806789
/// within each channel. As the confirmation of a commitment transaction may be critical to the
807-
/// safety of funds, this method must be invoked frequently, ideally once for every chain tip
808-
/// update (block connected or disconnected).
790+
/// safety of funds, we recommend invoking this every 30 seconds, or lower if running in an
791+
/// environment with spotty connections, like on mobile.
809792
///
810793
/// An [`EventHandler`] may safely call back to the provider, though this shouldn't be needed in
811794
/// order to handle these events.

lightning/src/chain/channelmonitor.rs

+1-6
Original file line numberDiff line numberDiff line change
@@ -43,16 +43,13 @@ use crate::chain::{BestBlock, WatchedOutput};
4343
use crate::chain::chaininterface::{BroadcasterInterface, FeeEstimator, LowerBoundedFeeEstimator};
4444
use crate::chain::transaction::{OutPoint, TransactionData};
4545
use crate::sign::{SpendableOutputDescriptor, StaticPaymentOutputDescriptor, DelayedPaymentOutputDescriptor, WriteableEcdsaChannelSigner, SignerProvider, EntropySource};
46-
#[cfg(anchors)]
47-
use crate::chain::onchaintx::ClaimEvent;
48-
use crate::chain::onchaintx::OnchainTxHandler;
46+
use crate::chain::onchaintx::{ClaimEvent, OnchainTxHandler};
4947
use crate::chain::package::{CounterpartyOfferedHTLCOutput, CounterpartyReceivedHTLCOutput, HolderFundingOutput, HolderHTLCOutput, PackageSolvingData, PackageTemplate, RevokedOutput, RevokedHTLCOutput};
5048
use crate::chain::Filter;
5149
use crate::util::logger::Logger;
5250
use crate::util::ser::{Readable, ReadableArgs, RequiredWrapper, MaybeReadable, UpgradableRequired, Writer, Writeable, U48};
5351
use crate::util::byte_utils;
5452
use crate::events::Event;
55-
#[cfg(anchors)]
5653
use crate::events::bump_transaction::{AnchorDescriptor, HTLCDescriptor, BumpTransactionEvent};
5754

5855
use crate::prelude::*;
@@ -268,7 +265,6 @@ impl_writeable_tlv_based!(HolderSignedTx, {
268265
(14, htlc_outputs, vec_type)
269266
});
270267

271-
#[cfg(anchors)]
272268
impl HolderSignedTx {
273269
fn non_dust_htlcs(&self) -> Vec<HTLCOutputInCommitment> {
274270
self.htlc_outputs.iter().filter_map(|(htlc, _, _)| {
@@ -2538,7 +2534,6 @@ impl<Signer: WriteableEcdsaChannelSigner> ChannelMonitorImpl<Signer> {
25382534
pub fn get_and_clear_pending_events(&mut self) -> Vec<Event> {
25392535
let mut ret = Vec::new();
25402536
mem::swap(&mut ret, &mut self.pending_events);
2541-
#[cfg(anchors)]
25422537
for (claim_id, claim_event) in self.onchain_tx_handler.get_and_clear_pending_claim_events().drain(..) {
25432538
match claim_event {
25442539
ClaimEvent::BumpCommitment {

lightning/src/chain/onchaintx.rs

+30-64
Original file line numberDiff line numberDiff line change
@@ -12,15 +12,11 @@
1212
//! OnchainTxHandler objects are fully-part of ChannelMonitor and encapsulates all
1313
//! building, tracking, bumping and notifications functions.
1414
15-
#[cfg(anchors)]
1615
use bitcoin::PackedLockTime;
1716
use bitcoin::blockdata::transaction::Transaction;
1817
use bitcoin::blockdata::transaction::OutPoint as BitcoinOutPoint;
1918
use bitcoin::blockdata::script::Script;
20-
use bitcoin::hashes::Hash;
21-
#[cfg(anchors)]
22-
use bitcoin::hashes::HashEngine;
23-
#[cfg(anchors)]
19+
use bitcoin::hashes::{Hash, HashEngine};
2420
use bitcoin::hashes::sha256::Hash as Sha256;
2521
use bitcoin::hash_types::{Txid, BlockHash};
2622
use bitcoin::secp256k1::{Secp256k1, ecdsa::Signature};
@@ -29,18 +25,12 @@ use bitcoin::secp256k1;
2925
use crate::sign::{ChannelSigner, EntropySource, SignerProvider};
3026
use crate::ln::msgs::DecodeError;
3127
use crate::ln::PaymentPreimage;
32-
#[cfg(anchors)]
33-
use crate::ln::chan_utils::{self, HTLCOutputInCommitment};
34-
use crate::ln::chan_utils::{ChannelTransactionParameters, HolderCommitmentTransaction};
28+
use crate::ln::chan_utils::{self, ChannelTransactionParameters, HTLCOutputInCommitment, HolderCommitmentTransaction};
3529
use crate::chain::ClaimId;
36-
#[cfg(anchors)]
37-
use crate::chain::chaininterface::ConfirmationTarget;
38-
use crate::chain::chaininterface::{FeeEstimator, BroadcasterInterface, LowerBoundedFeeEstimator};
30+
use crate::chain::chaininterface::{ConfirmationTarget, FeeEstimator, BroadcasterInterface, LowerBoundedFeeEstimator};
3931
use crate::chain::channelmonitor::{ANTI_REORG_DELAY, CLTV_SHARED_CLAIM_BUFFER};
4032
use crate::sign::WriteableEcdsaChannelSigner;
41-
#[cfg(anchors)]
42-
use crate::chain::package::PackageSolvingData;
43-
use crate::chain::package::PackageTemplate;
33+
use crate::chain::package::{PackageSolvingData, PackageTemplate};
4434
use crate::util::logger::Logger;
4535
use crate::util::ser::{Readable, ReadableArgs, MaybeReadable, UpgradableRequired, Writer, Writeable, VecWriter};
4636

@@ -50,7 +40,6 @@ use alloc::collections::BTreeMap;
5040
use core::cmp;
5141
use core::ops::Deref;
5242
use core::mem::replace;
53-
#[cfg(anchors)]
5443
use core::mem::swap;
5544
use crate::ln::features::ChannelTypeFeatures;
5645

@@ -181,7 +170,6 @@ impl Writeable for Option<Vec<Option<(usize, Signature)>>> {
181170
}
182171
}
183172

184-
#[cfg(anchors)]
185173
/// The claim commonly referred to as the pre-signed second-stage HTLC transaction.
186174
pub(crate) struct ExternalHTLCClaim {
187175
pub(crate) commitment_txid: Txid,
@@ -193,7 +181,6 @@ pub(crate) struct ExternalHTLCClaim {
193181

194182
// Represents the different types of claims for which events are yielded externally to satisfy said
195183
// claims.
196-
#[cfg(anchors)]
197184
pub(crate) enum ClaimEvent {
198185
/// Event yielded to signal that the commitment transaction fee must be bumped to claim any
199186
/// encumbered funds and proceed to HTLC resolution, if any HTLCs exist.
@@ -216,7 +203,6 @@ pub(crate) enum ClaimEvent {
216203
pub(crate) enum OnchainClaim {
217204
/// A finalized transaction pending confirmation spending the output to claim.
218205
Tx(Transaction),
219-
#[cfg(anchors)]
220206
/// An event yielded externally to signal additional inputs must be added to a transaction
221207
/// pending confirmation spending the output to claim.
222208
Event(ClaimEvent),
@@ -263,7 +249,6 @@ pub struct OnchainTxHandler<ChannelSigner: WriteableEcdsaChannelSigner> {
263249
// - A channel has been force closed by broadcasting the holder's latest commitment transaction
264250
// - A block being connected/disconnected
265251
// - Learning the preimage for an HTLC we can claim onchain
266-
#[cfg(anchors)]
267252
pending_claim_events: Vec<(ClaimId, ClaimEvent)>,
268253

269254
// Used to link outpoints claimed in a connected block to a pending claim request. The keys
@@ -440,7 +425,6 @@ impl<'a, 'b, ES: EntropySource, SP: SignerProvider> ReadableArgs<(&'a ES, &'b SP
440425
locktimed_packages,
441426
pending_claim_requests,
442427
onchain_events_awaiting_threshold_conf,
443-
#[cfg(anchors)]
444428
pending_claim_events: Vec::new(),
445429
secp_ctx,
446430
})
@@ -461,7 +445,6 @@ impl<ChannelSigner: WriteableEcdsaChannelSigner> OnchainTxHandler<ChannelSigner>
461445
claimable_outpoints: HashMap::new(),
462446
locktimed_packages: BTreeMap::new(),
463447
onchain_events_awaiting_threshold_conf: Vec::new(),
464-
#[cfg(anchors)]
465448
pending_claim_events: Vec::new(),
466449
secp_ctx,
467450
}
@@ -475,7 +458,6 @@ impl<ChannelSigner: WriteableEcdsaChannelSigner> OnchainTxHandler<ChannelSigner>
475458
self.holder_commitment.to_broadcaster_value_sat()
476459
}
477460

478-
#[cfg(anchors)]
479461
pub(crate) fn get_and_clear_pending_claim_events(&mut self) -> Vec<(ClaimId, ClaimEvent)> {
480462
let mut events = Vec::new();
481463
swap(&mut events, &mut self.pending_claim_events);
@@ -516,7 +498,6 @@ impl<ChannelSigner: WriteableEcdsaChannelSigner> OnchainTxHandler<ChannelSigner>
516498
log_info!(logger, "{} onchain {}", log_start, log_tx!(tx));
517499
broadcaster.broadcast_transactions(&[&tx]);
518500
},
519-
#[cfg(anchors)]
520501
OnchainClaim::Event(event) => {
521502
let log_start = if bumped_feerate { "Yielding fee-bumped" } else { "Replaying" };
522503
log_info!(logger, "{} onchain event to spend inputs {:?}", log_start,
@@ -593,25 +574,22 @@ impl<ChannelSigner: WriteableEcdsaChannelSigner> OnchainTxHandler<ChannelSigner>
593574
// didn't receive confirmation of it before, or not enough reorg-safe depth on top of it).
594575
let new_timer = cached_request.get_height_timer(cur_height);
595576
if cached_request.is_malleable() {
596-
#[cfg(anchors)]
597-
{ // Attributes are not allowed on if expressions on our current MSRV of 1.41.
598-
if cached_request.requires_external_funding() {
599-
let target_feerate_sat_per_1000_weight = cached_request.compute_package_feerate(
600-
fee_estimator, ConfirmationTarget::HighPriority, force_feerate_bump
601-
);
602-
if let Some(htlcs) = cached_request.construct_malleable_package_with_external_funding(self) {
603-
return Some((
604-
new_timer,
605-
target_feerate_sat_per_1000_weight as u64,
606-
OnchainClaim::Event(ClaimEvent::BumpHTLC {
607-
target_feerate_sat_per_1000_weight,
608-
htlcs,
609-
tx_lock_time: PackedLockTime(cached_request.package_locktime(cur_height)),
610-
}),
611-
));
612-
} else {
613-
return None;
614-
}
577+
if cached_request.requires_external_funding() {
578+
let target_feerate_sat_per_1000_weight = cached_request.compute_package_feerate(
579+
fee_estimator, ConfirmationTarget::HighPriority, force_feerate_bump
580+
);
581+
if let Some(htlcs) = cached_request.construct_malleable_package_with_external_funding(self) {
582+
return Some((
583+
new_timer,
584+
target_feerate_sat_per_1000_weight as u64,
585+
OnchainClaim::Event(ClaimEvent::BumpHTLC {
586+
target_feerate_sat_per_1000_weight,
587+
htlcs,
588+
tx_lock_time: PackedLockTime(cached_request.package_locktime(cur_height)),
589+
}),
590+
));
591+
} else {
592+
return None;
615593
}
616594
}
617595

@@ -633,9 +611,6 @@ impl<ChannelSigner: WriteableEcdsaChannelSigner> OnchainTxHandler<ChannelSigner>
633611
// Untractable packages cannot have their fees bumped through Replace-By-Fee. Some
634612
// packages may support fee bumping through Child-Pays-For-Parent, indicated by those
635613
// which require external funding.
636-
#[cfg(not(anchors))]
637-
let inputs = cached_request.inputs();
638-
#[cfg(anchors)]
639614
let mut inputs = cached_request.inputs();
640615
debug_assert_eq!(inputs.len(), 1);
641616
let tx = match cached_request.finalize_untractable_package(self, logger) {
@@ -645,7 +620,6 @@ impl<ChannelSigner: WriteableEcdsaChannelSigner> OnchainTxHandler<ChannelSigner>
645620
if !cached_request.requires_external_funding() {
646621
return Some((new_timer, 0, OnchainClaim::Tx(tx)));
647622
}
648-
#[cfg(anchors)]
649623
return inputs.find_map(|input| match input {
650624
// Commitment inputs with anchors support are the only untractable inputs supported
651625
// thus far that require external funding.
@@ -771,7 +745,6 @@ impl<ChannelSigner: WriteableEcdsaChannelSigner> OnchainTxHandler<ChannelSigner>
771745
broadcaster.broadcast_transactions(&[&tx]);
772746
ClaimId(tx.txid().into_inner())
773747
},
774-
#[cfg(anchors)]
775748
OnchainClaim::Event(claim_event) => {
776749
log_info!(logger, "Yielding onchain event to spend inputs {:?}", req.outpoints());
777750
let claim_id = match claim_event {
@@ -886,14 +859,12 @@ impl<ChannelSigner: WriteableEcdsaChannelSigner> OnchainTxHandler<ChannelSigner>
886859
// input(s) that already have a confirmed spend. If such spend is
887860
// reorged out of the chain, then we'll attempt to re-spend the
888861
// inputs once we see it.
889-
#[cfg(anchors)] {
890-
#[cfg(debug_assertions)] {
891-
let existing = self.pending_claim_events.iter()
892-
.filter(|entry| entry.0 == *claim_id).count();
893-
assert!(existing == 0 || existing == 1);
894-
}
895-
self.pending_claim_events.retain(|entry| entry.0 != *claim_id);
862+
#[cfg(debug_assertions)] {
863+
let existing = self.pending_claim_events.iter()
864+
.filter(|entry| entry.0 == *claim_id).count();
865+
assert!(existing == 0 || existing == 1);
896866
}
867+
self.pending_claim_events.retain(|entry| entry.0 != *claim_id);
897868
}
898869
}
899870
break; //No need to iterate further, either tx is our or their
@@ -930,14 +901,12 @@ impl<ChannelSigner: WriteableEcdsaChannelSigner> OnchainTxHandler<ChannelSigner>
930901
outpoint, log_bytes!(claim_id.0));
931902
self.claimable_outpoints.remove(outpoint);
932903
}
933-
#[cfg(anchors)] {
934-
#[cfg(debug_assertions)] {
935-
let num_existing = self.pending_claim_events.iter()
936-
.filter(|entry| entry.0 == claim_id).count();
937-
assert!(num_existing == 0 || num_existing == 1);
938-
}
939-
self.pending_claim_events.retain(|(id, _)| *id != claim_id);
904+
#[cfg(debug_assertions)] {
905+
let num_existing = self.pending_claim_events.iter()
906+
.filter(|entry| entry.0 == claim_id).count();
907+
assert!(num_existing == 0 || num_existing == 1);
940908
}
909+
self.pending_claim_events.retain(|(id, _)| *id != claim_id);
941910
}
942911
},
943912
OnchainEvent::ContentiousOutpoint { package } => {
@@ -969,7 +938,6 @@ impl<ChannelSigner: WriteableEcdsaChannelSigner> OnchainTxHandler<ChannelSigner>
969938
log_info!(logger, "Broadcasting RBF-bumped onchain {}", log_tx!(bump_tx));
970939
broadcaster.broadcast_transactions(&[&bump_tx]);
971940
},
972-
#[cfg(anchors)]
973941
OnchainClaim::Event(claim_event) => {
974942
log_info!(logger, "Yielding RBF-bumped onchain event to spend inputs {:?}", request.outpoints());
975943
#[cfg(debug_assertions)] {
@@ -1055,7 +1023,6 @@ impl<ChannelSigner: WriteableEcdsaChannelSigner> OnchainTxHandler<ChannelSigner>
10551023
log_info!(logger, "Broadcasting onchain {}", log_tx!(bump_tx));
10561024
broadcaster.broadcast_transactions(&[&bump_tx]);
10571025
},
1058-
#[cfg(anchors)]
10591026
OnchainClaim::Event(claim_event) => {
10601027
log_info!(logger, "Yielding onchain event after reorg to spend inputs {:?}", request.outpoints());
10611028
#[cfg(debug_assertions)] {
@@ -1185,7 +1152,6 @@ impl<ChannelSigner: WriteableEcdsaChannelSigner> OnchainTxHandler<ChannelSigner>
11851152
htlc_tx
11861153
}
11871154

1188-
#[cfg(anchors)]
11891155
pub(crate) fn generate_external_htlc_claim(
11901156
&self, outp: &::bitcoin::OutPoint, preimage: &Option<PaymentPreimage>
11911157
) -> Option<ExternalHTLCClaim> {

lightning/src/chain/package.rs

+1-6
Original file line numberDiff line numberDiff line change
@@ -26,16 +26,13 @@ use crate::ln::chan_utils;
2626
use crate::ln::msgs::DecodeError;
2727
use crate::chain::chaininterface::{FeeEstimator, ConfirmationTarget, MIN_RELAY_FEE_SAT_PER_1000_WEIGHT};
2828
use crate::sign::WriteableEcdsaChannelSigner;
29-
#[cfg(anchors)]
30-
use crate::chain::onchaintx::ExternalHTLCClaim;
31-
use crate::chain::onchaintx::OnchainTxHandler;
29+
use crate::chain::onchaintx::{ExternalHTLCClaim, OnchainTxHandler};
3230
use crate::util::logger::Logger;
3331
use crate::util::ser::{Readable, Writer, Writeable, RequiredWrapper};
3432

3533
use crate::io;
3634
use crate::prelude::*;
3735
use core::cmp;
38-
#[cfg(anchors)]
3936
use core::convert::TryInto;
4037
use core::mem;
4138
use core::ops::Deref;
@@ -866,7 +863,6 @@ impl PackageTemplate {
866863
let output_weight = (8 + 1 + destination_script.len()) * WITNESS_SCALE_FACTOR;
867864
inputs_weight + witnesses_weight + transaction_weight + output_weight
868865
}
869-
#[cfg(anchors)]
870866
pub(crate) fn construct_malleable_package_with_external_funding<Signer: WriteableEcdsaChannelSigner>(
871867
&self, onchain_handler: &mut OnchainTxHandler<Signer>,
872868
) -> Option<Vec<ExternalHTLCClaim>> {
@@ -971,7 +967,6 @@ impl PackageTemplate {
971967
None
972968
}
973969

974-
#[cfg(anchors)]
975970
/// Computes a feerate based on the given confirmation target. If a previous feerate was used,
976971
/// the new feerate is below it, and `force_feerate_bump` is set, we'll use a 25% increase of
977972
/// the previous feerate instead of the new feerate.

0 commit comments

Comments
 (0)