use crate::chain::{BestBlock, WatchedOutput};
use crate::chain::chaininterface::{BroadcasterInterface, FeeEstimator, LowerBoundedFeeEstimator};
use crate::chain::transaction::{OutPoint, TransactionData};
-use crate::chain::keysinterface::{SpendableOutputDescriptor, StaticPaymentOutputDescriptor, DelayedPaymentOutputDescriptor, Sign, KeysInterface};
+use crate::chain::keysinterface::{SpendableOutputDescriptor, StaticPaymentOutputDescriptor, DelayedPaymentOutputDescriptor, Sign, SignerProvider, EntropySource};
#[cfg(anchors)]
use crate::chain::onchaintx::ClaimEvent;
use crate::chain::onchaintx::OnchainTxHandler;
use crate::util::byte_utils;
use crate::util::events::Event;
#[cfg(anchors)]
-use crate::util::events::{AnchorDescriptor, BumpTransactionEvent};
+use crate::util::events::{AnchorDescriptor, HTLCDescriptor, BumpTransactionEvent};
use crate::prelude::*;
use core::{cmp, mem};
log_trace!(logger, "Updating ChannelMonitor: channel force closed, should broadcast: {}", should_broadcast);
self.lockdown_from_offchain = true;
if *should_broadcast {
+ // There's no need to broadcast our commitment transaction if we've seen one
+ // confirmed (even with 1 confirmation) as it'll be rejected as
+ // duplicate/conflicting.
+ let detected_funding_spend = self.funding_spend_confirmed.is_some() ||
+ self.onchain_events_awaiting_threshold_conf.iter().find(|event| match event.event {
+ OnchainEvent::FundingSpendConfirmation { .. } => true,
+ _ => false,
+ }).is_some();
+ if detected_funding_spend {
+ continue;
+ }
self.broadcast_latest_holder_commitment_txn(broadcaster, logger);
// If the channel supports anchor outputs, we'll need to emit an external
// event to be consumed such that a child transaction is broadcast with a
pending_htlcs,
}));
},
+ ClaimEvent::BumpHTLC {
+ target_feerate_sat_per_1000_weight, htlcs,
+ } => {
+ let mut htlc_descriptors = Vec::with_capacity(htlcs.len());
+ for htlc in htlcs {
+ htlc_descriptors.push(HTLCDescriptor {
+ channel_keys_id: self.channel_keys_id,
+ channel_value_satoshis: self.channel_value_satoshis,
+ channel_parameters: self.onchain_tx_handler.channel_transaction_parameters.clone(),
+ commitment_txid: htlc.commitment_txid,
+ per_commitment_number: htlc.per_commitment_number,
+ htlc: htlc.htlc,
+ preimage: htlc.preimage,
+ counterparty_sig: htlc.counterparty_sig,
+ });
+ }
+ ret.push(Event::BumpTransaction(BumpTransactionEvent::HTLCResolution {
+ target_feerate_sat_per_1000_weight,
+ htlc_descriptors,
+ }));
+ }
}
}
ret
for &(ref htlc, _, _) in holder_tx.htlc_outputs.iter() {
if let Some(transaction_output_index) = htlc.transaction_output_index {
- let htlc_output = if htlc.offered {
- HolderHTLCOutput::build_offered(htlc.amount_msat, htlc.cltv_expiry)
+ let (htlc_output, aggregable) = if htlc.offered {
+ let htlc_output = HolderHTLCOutput::build_offered(
+ htlc.amount_msat, htlc.cltv_expiry, self.onchain_tx_handler.opt_anchors()
+ );
+ (htlc_output, false)
+ } else {
+ let payment_preimage = if let Some(preimage) = self.payment_preimages.get(&htlc.payment_hash) {
+ preimage.clone()
} else {
- let payment_preimage = if let Some(preimage) = self.payment_preimages.get(&htlc.payment_hash) {
- preimage.clone()
- } else {
- // We can't build an HTLC-Success transaction without the preimage
- continue;
- };
- HolderHTLCOutput::build_accepted(payment_preimage, htlc.amount_msat)
+ // We can't build an HTLC-Success transaction without the preimage
+ continue;
};
- let htlc_package = PackageTemplate::build_package(holder_tx.txid, transaction_output_index, PackageSolvingData::HolderHTLCOutput(htlc_output), htlc.cltv_expiry, false, conf_height);
+ let htlc_output = HolderHTLCOutput::build_accepted(
+ payment_preimage, htlc.amount_msat, self.onchain_tx_handler.opt_anchors()
+ );
+ (htlc_output, self.onchain_tx_handler.opt_anchors())
+ };
+ let htlc_package = PackageTemplate::build_package(
+ holder_tx.txid, transaction_output_index,
+ PackageSolvingData::HolderHTLCOutput(htlc_output),
+ htlc.cltv_expiry, aggregable, conf_height
+ );
claim_requests.push(htlc_package);
}
}
if let Some(new_outputs) = new_outputs_option {
watch_outputs.push(new_outputs);
}
- // Since there may be multiple HTLCs (all from the same commitment) being
- // claimed by the counterparty within the same transaction, and
- // `check_spend_counterparty_htlc` already checks for all of them, we can
- // safely break from our loop.
+ // Since there may be multiple HTLCs for this channel (all spending the
+ // same commitment tx) being claimed by the counterparty within the same
+ // transaction, and `check_spend_counterparty_htlc` already checks all the
+ // ones relevant to this channel, we can safely break from our loop.
break;
}
}
const MAX_ALLOC_SIZE: usize = 64*1024;
-impl<'a, K: KeysInterface> ReadableArgs<&'a K>
- for (BlockHash, ChannelMonitor<K::Signer>) {
- fn read<R: io::Read>(reader: &mut R, keys_manager: &'a K) -> Result<Self, DecodeError> {
+impl<'a, 'b, ES: EntropySource, SP: SignerProvider> ReadableArgs<(&'a ES, &'b SP)>
+ for (BlockHash, ChannelMonitor<SP::Signer>) {
+ fn read<R: io::Read>(reader: &mut R, args: (&'a ES, &'b SP)) -> Result<Self, DecodeError> {
macro_rules! unwrap_obj {
($key: expr) => {
match $key {
}
}
+ let (entropy_source, signer_provider) = args;
+
let _ver = read_ver_prefix!(reader, SERIALIZATION_VERSION);
let latest_update_id: u64 = Readable::read(reader)?;
return Err(DecodeError::InvalidValue);
}
}
- let onchain_tx_handler: OnchainTxHandler<K::Signer> = ReadableArgs::read(
- reader, (keys_manager, channel_value_satoshis, channel_keys_id)
+ let onchain_tx_handler: OnchainTxHandler<SP::Signer> = ReadableArgs::read(
+ reader, (entropy_source, signer_provider, channel_value_satoshis, channel_keys_id)
)?;
let lockdown_from_offchain = Readable::read(reader)?;
});
let mut secp_ctx = Secp256k1::new();
- secp_ctx.seeded_randomize(&keys_manager.get_secure_random_bytes());
+ secp_ctx.seeded_randomize(&entropy_source.get_secure_random_bytes());
Ok((best_block.block_hash(), ChannelMonitor::from_impl(ChannelMonitorImpl {
latest_update_id,
use crate::ln::{PaymentPreimage, PaymentHash};
use crate::ln::chan_utils;
use crate::ln::chan_utils::{HTLCOutputInCommitment, ChannelPublicKeys, ChannelTransactionParameters, HolderCommitmentTransaction, CounterpartyChannelTransactionParameters};
- use crate::ln::channelmanager::{self, PaymentSendFailure, PaymentId};
+ use crate::ln::channelmanager::{PaymentSendFailure, PaymentId};
use crate::ln::functional_test_utils::*;
use crate::ln::script::ShutdownScript;
use crate::util::errors::APIError;
let node_cfgs = create_node_cfgs(3, &chanmon_cfgs);
let node_chanmgrs = create_node_chanmgrs(3, &node_cfgs, &[None, None, None]);
let nodes = create_network(3, &node_cfgs, &node_chanmgrs);
- let channel = create_announced_chan_between_nodes(
- &nodes, 0, 1, channelmanager::provided_init_features(), channelmanager::provided_init_features());
- create_announced_chan_between_nodes(
- &nodes, 1, 2, channelmanager::provided_init_features(), channelmanager::provided_init_features());
+ let channel = create_announced_chan_between_nodes(&nodes, 0, 1);
+ create_announced_chan_between_nodes(&nodes, 1, 2);
// Rebalance somewhat
send_payment(&nodes[0], &[&nodes[1]], 10_000_000);
let (_, pre_update_monitor) = <(BlockHash, ChannelMonitor<InMemorySigner>)>::read(
&mut io::Cursor::new(&get_monitor!(nodes[1], channel.2).encode()),
- &nodes[1].keys_manager.backing).unwrap();
+ (&nodes[1].keys_manager.backing, &nodes[1].keys_manager.backing)).unwrap();
// If the ChannelManager tries to update the channel, however, the ChainMonitor will pass
// the update through to the ChannelMonitor which will refuse it (as the channel is closed).
SecretKey::from_slice(&[41; 32]).unwrap(),
SecretKey::from_slice(&[41; 32]).unwrap(),
SecretKey::from_slice(&[41; 32]).unwrap(),
- SecretKey::from_slice(&[41; 32]).unwrap(),
[41; 32],
0,
[0; 32],