Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Let ChannelSigner set and spend LN scriptpubkeys #3512

Draft
wants to merge 40 commits into
base: main
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
40 commits
Select commit Hold shift + click to select a range
a775008
Add `ChannelSigner::get_channel_parameters`
tankyleo Jan 13, 2025
42d65da
Let `ChannelSigner` set `to_remote` script pubkey
tankyleo Dec 7, 2024
857ab29
Let `ChannelSigner` set `to_local` script pubkey
tankyleo Dec 13, 2024
8283838
Let `ChannelSigner` set htlc tx script pubkey
tankyleo Dec 13, 2024
2e8b3f8
Let `ChannelSigner` build the punishment witness
tankyleo Dec 15, 2024
70b9df6
Ask `ChannelSigner` the weight of the punishment witness
tankyleo Dec 20, 2024
907684b
Remove unused `RevokedOutput` fields
tankyleo Dec 20, 2024
4234663
Let `ChannelSigner` build the htlc punishment witness
tankyleo Dec 20, 2024
b0a20d8
Remove unused `RevokedHTLCOutput` fields
tankyleo Dec 20, 2024
2868379
Ask `ChannelSigner` the weight of the htlc punishment witness
tankyleo Dec 20, 2024
77d5e24
Let `ChannelSigner` build the counterparty htlc sweep witness
tankyleo Dec 20, 2024
563efd5
Remove unused `CounterpartyOfferedHTLCOutput` fields
tankyleo Dec 20, 2024
b7a37ca
Remove unused `CounterpartyReceivedHTLCOutput` fields
tankyleo Dec 20, 2024
35901b5
Ask `ChannelSigner` the weight of counterparty htlc output sweeps
tankyleo Dec 22, 2024
b88a2ac
Let `sign_holder_commitment` build the commitment tx witness
tankyleo Dec 22, 2024
4de22fa
Let `unsafe_sign_holder_commitment` build the commitment tx witness
tankyleo Dec 22, 2024
4c96432
Let `sign_holder_htlc_transaction` build the htlc tx witness
tankyleo Dec 22, 2024
9687da3
Relax `EcdsaChannelSigner` to `ChannelSigner` in `mod chain`
tankyleo Dec 22, 2024
0e3227e
Ask `ChannelSigner` the weight of the htlc tx input
tankyleo Dec 23, 2024
a9c3844
Let `ChannelSigner` set commit tx htlc output script pubkey
tankyleo Dec 24, 2024
ec40758
Remove `TxCreationKeys` from `CommitmentTransaction::internal_build_o…
tankyleo Dec 24, 2024
207b70f
Let `ChannelSigner` set commit tx anchor output script pubkey
tankyleo Jan 14, 2025
557a754
Let `ChannelSigner` build the anchor sweep witness
tankyleo Dec 25, 2024
7ec1efc
Ask `ChannelSigner` the weight of the anchor tx input
tankyleo Jan 6, 2025
f95a7c0
Mark `PackageSolvingData::HolderHTLCOutput` weight unreachable
tankyleo Jan 7, 2025
a606d03
Remove unused `HolderFundingOutput` fields
tankyleo Jan 10, 2025
03d6a40
Add `ChannelTransactionParameters::channel_type_features`
tankyleo Jan 13, 2025
fbc1b5c
Delete `EcdsaChannelSigner::sign_justice_revoked_output`
tankyleo Jan 14, 2025
5f27ad7
Delete `EcdsaChannelSigner::sign_justice_revoked_htlc`
tankyleo Jan 14, 2025
fc2a45e
Delete `EcdsaChannelSigner::sign_counterparty_htlc_transaction`
tankyleo Jan 14, 2025
c9050a5
Delete `EcdsaChannelSigner::sign_holder_anchor_input`
tankyleo Jan 14, 2025
c20b8fc
Add `ChannelSigner::get_to_remote_witness_weight`
tankyleo Jan 16, 2025
3ab0293
Add `ChannelSigner::get_to_local_witness_weight`
tankyleo Jan 16, 2025
61fc584
Delete `StaticPaymentOutputDescriptor::witness_script`
tankyleo Jan 16, 2025
2ed352c
Delete `HTLCDescriptor::tx_input_witness`
tankyleo Jan 16, 2025
fd1a47a
Delete `TrustedCommitmentTransaction::get_htlc_sigs`
tankyleo Jan 18, 2025
6ea5589
Move commitment tx sig validation from `FundedChannel` to `ChannelSig…
tankyleo Jan 18, 2025
e2f73a5
Move htlc tx sig validation from `FundedChannel` to `ChannelSigner`
tankyleo Jan 18, 2025
ccf9824
Delete `InitialRemoteCommitmentReceiver::check_counterparty_commitmen…
tankyleo Jan 18, 2025
5fc079b
Call `validate_counterparty_revocation` on `ChannelSigner` directly
tankyleo Jan 18, 2025
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
70 changes: 35 additions & 35 deletions lightning/src/chain/chainmonitor.rs
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ use crate::chain::chaininterface::{BroadcasterInterface, FeeEstimator};
use crate::chain::channelmonitor::{ChannelMonitor, ChannelMonitorUpdate, Balance, MonitorEvent, TransactionOutputs, WithChannelMonitor};
use crate::chain::transaction::{OutPoint, TransactionData};
use crate::ln::types::ChannelId;
use crate::sign::ecdsa::EcdsaChannelSigner;
use crate::sign::ChannelSigner;
use crate::events::{self, Event, EventHandler, ReplayEvent};
use crate::util::logger::{Logger, WithContext};
use crate::util::errors::APIError;
Expand Down Expand Up @@ -96,12 +96,12 @@ use bitcoin::secp256k1::PublicKey;
/// provided for bulding transactions for a watchtower:
/// [`ChannelMonitor::initial_counterparty_commitment_tx`],
/// [`ChannelMonitor::counterparty_commitment_txs_from_update`],
/// [`ChannelMonitor::sign_to_local_justice_tx`], [`TrustedCommitmentTransaction::revokeable_output_index`],
/// [`ChannelMonitor::punish_revokeable_output`], [`TrustedCommitmentTransaction::revokeable_output_index`],
/// [`TrustedCommitmentTransaction::build_to_local_justice_tx`].
///
/// [`TrustedCommitmentTransaction::revokeable_output_index`]: crate::ln::chan_utils::TrustedCommitmentTransaction::revokeable_output_index
/// [`TrustedCommitmentTransaction::build_to_local_justice_tx`]: crate::ln::chan_utils::TrustedCommitmentTransaction::build_to_local_justice_tx
pub trait Persist<ChannelSigner: EcdsaChannelSigner> {
pub trait Persist<Signer: ChannelSigner> {
/// Persist a new channel's data in response to a [`chain::Watch::watch_channel`] call. This is
/// called by [`ChannelManager`] for new channels, or may be called directly, e.g. on startup.
///
Expand All @@ -118,7 +118,7 @@ pub trait Persist<ChannelSigner: EcdsaChannelSigner> {
///
/// [`ChannelManager`]: crate::ln::channelmanager::ChannelManager
/// [`Writeable::write`]: crate::util::ser::Writeable::write
fn persist_new_channel(&self, channel_funding_outpoint: OutPoint, monitor: &ChannelMonitor<ChannelSigner>) -> ChannelMonitorUpdateStatus;
fn persist_new_channel(&self, channel_funding_outpoint: OutPoint, monitor: &ChannelMonitor<Signer>) -> ChannelMonitorUpdateStatus;

/// Update one channel's data. The provided [`ChannelMonitor`] has already applied the given
/// update.
Expand Down Expand Up @@ -157,7 +157,7 @@ pub trait Persist<ChannelSigner: EcdsaChannelSigner> {
/// [`ChannelMonitorUpdateStatus`] for requirements when returning errors.
///
/// [`Writeable::write`]: crate::util::ser::Writeable::write
fn update_persisted_channel(&self, channel_funding_outpoint: OutPoint, monitor_update: Option<&ChannelMonitorUpdate>, monitor: &ChannelMonitor<ChannelSigner>) -> ChannelMonitorUpdateStatus;
fn update_persisted_channel(&self, channel_funding_outpoint: OutPoint, monitor_update: Option<&ChannelMonitorUpdate>, monitor: &ChannelMonitor<Signer>) -> ChannelMonitorUpdateStatus;
/// Prevents the channel monitor from being loaded on startup.
///
/// Archiving the data in a backup location (rather than deleting it fully) is useful for
Expand All @@ -172,8 +172,8 @@ pub trait Persist<ChannelSigner: EcdsaChannelSigner> {
fn archive_persisted_channel(&self, channel_funding_outpoint: OutPoint);
}

struct MonitorHolder<ChannelSigner: EcdsaChannelSigner> {
monitor: ChannelMonitor<ChannelSigner>,
struct MonitorHolder<Signer: ChannelSigner> {
monitor: ChannelMonitor<Signer>,
/// The full set of pending monitor updates for this Channel.
///
/// Note that this lock must be held from [`ChannelMonitor::update_monitor`] through to
Expand All @@ -191,7 +191,7 @@ struct MonitorHolder<ChannelSigner: EcdsaChannelSigner> {
pending_monitor_updates: Mutex<Vec<u64>>,
}

impl<ChannelSigner: EcdsaChannelSigner> MonitorHolder<ChannelSigner> {
impl<Signer: ChannelSigner> MonitorHolder<Signer> {
fn has_pending_updates(&self, pending_monitor_updates_lock: &MutexGuard<Vec<u64>>) -> bool {
!pending_monitor_updates_lock.is_empty()
}
Expand All @@ -201,14 +201,14 @@ impl<ChannelSigner: EcdsaChannelSigner> MonitorHolder<ChannelSigner> {
///
/// Note that this holds a mutex in [`ChainMonitor`] and may block other events until it is
/// released.
pub struct LockedChannelMonitor<'a, ChannelSigner: EcdsaChannelSigner> {
lock: RwLockReadGuard<'a, HashMap<OutPoint, MonitorHolder<ChannelSigner>>>,
pub struct LockedChannelMonitor<'a, Signer: ChannelSigner> {
lock: RwLockReadGuard<'a, HashMap<OutPoint, MonitorHolder<Signer>>>,
funding_txo: OutPoint,
}

impl<ChannelSigner: EcdsaChannelSigner> Deref for LockedChannelMonitor<'_, ChannelSigner> {
type Target = ChannelMonitor<ChannelSigner>;
fn deref(&self) -> &ChannelMonitor<ChannelSigner> {
impl<Signer: ChannelSigner> Deref for LockedChannelMonitor<'_, Signer> {
type Target = ChannelMonitor<Signer>;
fn deref(&self) -> &ChannelMonitor<Signer> {
&self.lock.get(&self.funding_txo).expect("Checked at construction").monitor
}
}
Expand All @@ -229,14 +229,14 @@ impl<ChannelSigner: EcdsaChannelSigner> Deref for LockedChannelMonitor<'_, Chann
/// [`ChannelManager`]: crate::ln::channelmanager::ChannelManager
/// [module-level documentation]: crate::chain::chainmonitor
/// [`rebroadcast_pending_claims`]: Self::rebroadcast_pending_claims
pub struct ChainMonitor<ChannelSigner: EcdsaChannelSigner, C: Deref, T: Deref, F: Deref, L: Deref, P: Deref>
pub struct ChainMonitor<Signer: ChannelSigner, C: Deref, T: Deref, F: Deref, L: Deref, P: Deref>
where C::Target: chain::Filter,
T::Target: BroadcasterInterface,
F::Target: FeeEstimator,
L::Target: Logger,
P::Target: Persist<ChannelSigner>,
P::Target: Persist<Signer>,
{
monitors: RwLock<HashMap<OutPoint, MonitorHolder<ChannelSigner>>>,
monitors: RwLock<HashMap<OutPoint, MonitorHolder<Signer>>>,
chain_source: Option<C>,
broadcaster: T,
logger: L,
Expand All @@ -253,12 +253,12 @@ pub struct ChainMonitor<ChannelSigner: EcdsaChannelSigner, C: Deref, T: Deref, F
event_notifier: Notifier,
}

impl<ChannelSigner: EcdsaChannelSigner, C: Deref, T: Deref, F: Deref, L: Deref, P: Deref> ChainMonitor<ChannelSigner, C, T, F, L, P>
impl<Signer: ChannelSigner, C: Deref, T: Deref, F: Deref, L: Deref, P: Deref> ChainMonitor<Signer, C, T, F, L, P>
where C::Target: chain::Filter,
T::Target: BroadcasterInterface,
F::Target: FeeEstimator,
L::Target: Logger,
P::Target: Persist<ChannelSigner>,
P::Target: Persist<Signer>,
{
/// Dispatches to per-channel monitors, which are responsible for updating their on-chain view
/// of a channel and reacting accordingly based on transactions in the given chain data. See
Expand All @@ -273,7 +273,7 @@ where C::Target: chain::Filter,
/// Calls which represent a new blockchain tip height should set `best_height`.
fn process_chain_data<FN>(&self, header: &Header, best_height: Option<u32>, txdata: &TransactionData, process: FN)
where
FN: Fn(&ChannelMonitor<ChannelSigner>, &TransactionData) -> Vec<TransactionOutputs>
FN: Fn(&ChannelMonitor<Signer>, &TransactionData) -> Vec<TransactionOutputs>
{
let err_str = "ChannelMonitor[Update] persistence failed unrecoverably. This indicates we cannot continue normal operation and must shut down.";
let funding_outpoints = hash_set_from_iter(self.monitors.read().unwrap().keys().cloned());
Expand Down Expand Up @@ -316,8 +316,8 @@ where C::Target: chain::Filter,

fn update_monitor_with_chain_data<FN>(
&self, header: &Header, best_height: Option<u32>, txdata: &TransactionData, process: FN, funding_outpoint: &OutPoint,
monitor_state: &MonitorHolder<ChannelSigner>, channel_count: usize,
) -> Result<(), ()> where FN: Fn(&ChannelMonitor<ChannelSigner>, &TransactionData) -> Vec<TransactionOutputs> {
monitor_state: &MonitorHolder<Signer>, channel_count: usize,
) -> Result<(), ()> where FN: Fn(&ChannelMonitor<Signer>, &TransactionData) -> Vec<TransactionOutputs> {
let monitor = &monitor_state.monitor;
let logger = WithChannelMonitor::from(&self.logger, &monitor, None);

Expand Down Expand Up @@ -428,7 +428,7 @@ where C::Target: chain::Filter,
///
/// Note that the result holds a mutex over our monitor set, and should not be held
/// indefinitely.
pub fn get_monitor(&self, funding_txo: OutPoint) -> Result<LockedChannelMonitor<'_, ChannelSigner>, ()> {
pub fn get_monitor(&self, funding_txo: OutPoint) -> Result<LockedChannelMonitor<'_, Signer>, ()> {
let lock = self.monitors.read().unwrap();
if lock.get(&funding_txo).is_some() {
Ok(LockedChannelMonitor { lock, funding_txo })
Expand Down Expand Up @@ -472,7 +472,7 @@ where C::Target: chain::Filter,


#[cfg(test)]
pub fn remove_monitor(&self, funding_txo: &OutPoint) -> ChannelMonitor<ChannelSigner> {
pub fn remove_monitor(&self, funding_txo: &OutPoint) -> ChannelMonitor<Signer> {
self.monitors.write().unwrap().remove(funding_txo).unwrap().monitor
}

Expand Down Expand Up @@ -670,14 +670,14 @@ where C::Target: chain::Filter,
}
}

impl<ChannelSigner: EcdsaChannelSigner, C: Deref, T: Deref, F: Deref, L: Deref, P: Deref>
chain::Listen for ChainMonitor<ChannelSigner, C, T, F, L, P>
impl<Signer: ChannelSigner, C: Deref, T: Deref, F: Deref, L: Deref, P: Deref>
chain::Listen for ChainMonitor<Signer, C, T, F, L, P>
where
C::Target: chain::Filter,
T::Target: BroadcasterInterface,
F::Target: FeeEstimator,
L::Target: Logger,
P::Target: Persist<ChannelSigner>,
P::Target: Persist<Signer>,
{
fn filtered_block_connected(&self, header: &Header, txdata: &TransactionData, height: u32) {
log_debug!(self.logger, "New best block {} at height {} provided via block_connected", header.block_hash(), height);
Expand All @@ -699,14 +699,14 @@ where
}
}

impl<ChannelSigner: EcdsaChannelSigner, C: Deref, T: Deref, F: Deref, L: Deref, P: Deref>
chain::Confirm for ChainMonitor<ChannelSigner, C, T, F, L, P>
impl<Signer: ChannelSigner, C: Deref, T: Deref, F: Deref, L: Deref, P: Deref>
chain::Confirm for ChainMonitor<Signer, C, T, F, L, P>
where
C::Target: chain::Filter,
T::Target: BroadcasterInterface,
F::Target: FeeEstimator,
L::Target: Logger,
P::Target: Persist<ChannelSigner>,
P::Target: Persist<Signer>,
{
fn transactions_confirmed(&self, header: &Header, txdata: &TransactionData, height: u32) {
log_debug!(self.logger, "{} provided transactions confirmed at height {} in block {}", txdata.len(), height, header.block_hash());
Expand Down Expand Up @@ -753,15 +753,15 @@ where
}
}

impl<ChannelSigner: EcdsaChannelSigner, C: Deref , T: Deref , F: Deref , L: Deref , P: Deref >
chain::Watch<ChannelSigner> for ChainMonitor<ChannelSigner, C, T, F, L, P>
impl<Signer: ChannelSigner, C: Deref , T: Deref , F: Deref , L: Deref , P: Deref >
chain::Watch<Signer> for ChainMonitor<Signer, C, T, F, L, P>
where C::Target: chain::Filter,
T::Target: BroadcasterInterface,
F::Target: FeeEstimator,
L::Target: Logger,
P::Target: Persist<ChannelSigner>,
P::Target: Persist<Signer>,
{
fn watch_channel(&self, funding_outpoint: OutPoint, monitor: ChannelMonitor<ChannelSigner>) -> Result<ChannelMonitorUpdateStatus, ()> {
fn watch_channel(&self, funding_outpoint: OutPoint, monitor: ChannelMonitor<Signer>) -> Result<ChannelMonitorUpdateStatus, ()> {
let logger = WithChannelMonitor::from(&self.logger, &monitor, None);
let mut monitors = self.monitors.write().unwrap();
let entry = match monitors.entry(funding_outpoint) {
Expand Down Expand Up @@ -892,12 +892,12 @@ where C::Target: chain::Filter,
}
}

impl<ChannelSigner: EcdsaChannelSigner, C: Deref, T: Deref, F: Deref, L: Deref, P: Deref> events::EventsProvider for ChainMonitor<ChannelSigner, C, T, F, L, P>
impl<Signer: ChannelSigner, C: Deref, T: Deref, F: Deref, L: Deref, P: Deref> events::EventsProvider for ChainMonitor<Signer, C, T, F, L, P>
where C::Target: chain::Filter,
T::Target: BroadcasterInterface,
F::Target: FeeEstimator,
L::Target: Logger,
P::Target: Persist<ChannelSigner>,
P::Target: Persist<Signer>,
{
/// Processes [`SpendableOutputs`] events produced from each [`ChannelMonitor`] upon maturity.
///
Expand Down
Loading
Loading