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

Add PaymentHash to Record #2930

Merged
merged 2 commits into from
May 10, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
12 changes: 6 additions & 6 deletions lightning/src/chain/chainmonitor.rs
Original file line number Diff line number Diff line change
Expand Up @@ -301,7 +301,7 @@ where C::Target: chain::Filter,
monitor_state: &MonitorHolder<ChannelSigner>
) -> Result<(), ()> where FN: Fn(&ChannelMonitor<ChannelSigner>, &TransactionData) -> Vec<TransactionOutputs> {
let monitor = &monitor_state.monitor;
let logger = WithChannelMonitor::from(&self.logger, &monitor);
let logger = WithChannelMonitor::from(&self.logger, &monitor, None);
let mut txn_outputs;
{
txn_outputs = process(monitor, txdata);
Expand Down Expand Up @@ -599,15 +599,15 @@ where C::Target: chain::Filter,
pub fn archive_fully_resolved_channel_monitors(&self) {
let mut have_monitors_to_prune = false;
for (_, monitor_holder) in self.monitors.read().unwrap().iter() {
let logger = WithChannelMonitor::from(&self.logger, &monitor_holder.monitor);
let logger = WithChannelMonitor::from(&self.logger, &monitor_holder.monitor, None);
if monitor_holder.monitor.is_fully_resolved(&logger) {
have_monitors_to_prune = true;
}
}
if have_monitors_to_prune {
let mut monitors = self.monitors.write().unwrap();
monitors.retain(|funding_txo, monitor_holder| {
let logger = WithChannelMonitor::from(&self.logger, &monitor_holder.monitor);
let logger = WithChannelMonitor::from(&self.logger, &monitor_holder.monitor, None);
if monitor_holder.monitor.is_fully_resolved(&logger) {
log_info!(logger,
"Archiving fully resolved ChannelMonitor for funding txo {}",
Expand Down Expand Up @@ -715,7 +715,7 @@ where C::Target: chain::Filter,
P::Target: Persist<ChannelSigner>,
{
fn watch_channel(&self, funding_outpoint: OutPoint, monitor: ChannelMonitor<ChannelSigner>) -> Result<ChannelMonitorUpdateStatus, ()> {
let logger = WithChannelMonitor::from(&self.logger, &monitor);
let logger = WithChannelMonitor::from(&self.logger, &monitor, None);
let mut monitors = self.monitors.write().unwrap();
let entry = match monitors.entry(funding_outpoint) {
hash_map::Entry::Occupied(_) => {
Expand Down Expand Up @@ -760,7 +760,7 @@ where C::Target: chain::Filter,
let monitors = self.monitors.read().unwrap();
match monitors.get(&funding_txo) {
None => {
let logger = WithContext::from(&self.logger, update.counterparty_node_id, Some(channel_id));
let logger = WithContext::from(&self.logger, update.counterparty_node_id, Some(channel_id), None);
log_error!(logger, "Failed to update channel monitor: no such monitor registered");

// We should never ever trigger this from within ChannelManager. Technically a
Expand All @@ -773,7 +773,7 @@ where C::Target: chain::Filter,
},
Some(monitor_state) => {
let monitor = &monitor_state.monitor;
let logger = WithChannelMonitor::from(&self.logger, &monitor);
let logger = WithChannelMonitor::from(&self.logger, &monitor, None);
log_trace!(logger, "Updating ChannelMonitor to id {} for channel {}", update.update_id, log_funding_info!(monitor));
let update_res = monitor.update_monitor(update, &self.broadcaster, &self.fee_estimator, &self.logger);

Expand Down
41 changes: 22 additions & 19 deletions lightning/src/chain/channelmonitor.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1195,26 +1195,28 @@ pub(crate) struct WithChannelMonitor<'a, L: Deref> where L::Target: Logger {
logger: &'a L,
peer_id: Option<PublicKey>,
channel_id: Option<ChannelId>,
payment_hash: Option<PaymentHash>,
}

impl<'a, L: Deref> Logger for WithChannelMonitor<'a, L> where L::Target: Logger {
fn log(&self, mut record: Record) {
record.peer_id = self.peer_id;
record.channel_id = self.channel_id;
record.payment_hash = self.payment_hash;
self.logger.log(record)
}
}

impl<'a, L: Deref> WithChannelMonitor<'a, L> where L::Target: Logger {
pub(crate) fn from<S: WriteableEcdsaChannelSigner>(logger: &'a L, monitor: &ChannelMonitor<S>) -> Self {
Self::from_impl(logger, &*monitor.inner.lock().unwrap())
pub(crate) fn from<S: WriteableEcdsaChannelSigner>(logger: &'a L, monitor: &ChannelMonitor<S>, payment_hash: Option<PaymentHash>) -> Self {
Self::from_impl(logger, &*monitor.inner.lock().unwrap(), payment_hash)
}

pub(crate) fn from_impl<S: WriteableEcdsaChannelSigner>(logger: &'a L, monitor_impl: &ChannelMonitorImpl<S>) -> Self {
pub(crate) fn from_impl<S: WriteableEcdsaChannelSigner>(logger: &'a L, monitor_impl: &ChannelMonitorImpl<S>, payment_hash: Option<PaymentHash>) -> Self {
let peer_id = monitor_impl.counterparty_node_id;
let channel_id = Some(monitor_impl.channel_id());
WithChannelMonitor {
logger, peer_id, channel_id,
logger, peer_id, channel_id, payment_hash,
}
}
}
Expand Down Expand Up @@ -1356,7 +1358,7 @@ impl<Signer: WriteableEcdsaChannelSigner> ChannelMonitor<Signer> {
where L::Target: Logger
{
let mut inner = self.inner.lock().unwrap();
let logger = WithChannelMonitor::from_impl(logger, &*inner);
let logger = WithChannelMonitor::from_impl(logger, &*inner, None);
inner.provide_initial_counterparty_commitment_tx(txid,
htlc_outputs, commitment_number, their_cur_per_commitment_point, feerate_per_kw,
to_broadcaster_value_sat, to_countersignatory_value_sat, &logger);
Expand All @@ -1376,7 +1378,7 @@ impl<Signer: WriteableEcdsaChannelSigner> ChannelMonitor<Signer> {
logger: &L,
) where L::Target: Logger {
let mut inner = self.inner.lock().unwrap();
let logger = WithChannelMonitor::from_impl(logger, &*inner);
let logger = WithChannelMonitor::from_impl(logger, &*inner, None);
inner.provide_latest_counterparty_commitment_tx(
txid, htlc_outputs, commitment_number, their_per_commitment_point, &logger)
}
Expand Down Expand Up @@ -1404,7 +1406,7 @@ impl<Signer: WriteableEcdsaChannelSigner> ChannelMonitor<Signer> {
L::Target: Logger,
{
let mut inner = self.inner.lock().unwrap();
let logger = WithChannelMonitor::from_impl(logger, &*inner);
let logger = WithChannelMonitor::from_impl(logger, &*inner, Some(*payment_hash));
inner.provide_payment_preimage(
payment_hash, payment_preimage, broadcaster, fee_estimator, &logger)
}
Expand All @@ -1426,7 +1428,7 @@ impl<Signer: WriteableEcdsaChannelSigner> ChannelMonitor<Signer> {
L::Target: Logger,
{
let mut inner = self.inner.lock().unwrap();
let logger = WithChannelMonitor::from_impl(logger, &*inner);
let logger = WithChannelMonitor::from_impl(logger, &*inner, None);
inner.update_monitor(updates, broadcaster, fee_estimator, &logger)
}

Expand Down Expand Up @@ -1461,7 +1463,7 @@ impl<Signer: WriteableEcdsaChannelSigner> ChannelMonitor<Signer> {
F::Target: chain::Filter, L::Target: Logger,
{
let lock = self.inner.lock().unwrap();
let logger = WithChannelMonitor::from_impl(logger, &*lock);
let logger = WithChannelMonitor::from_impl(logger, &*lock, None);
log_trace!(&logger, "Registering funding outpoint {}", &lock.get_funding_txo().0);
filter.register_tx(&lock.get_funding_txo().0.txid, &lock.get_funding_txo().1);
for (txid, outputs) in lock.get_outputs_to_watch().iter() {
Expand Down Expand Up @@ -1621,7 +1623,7 @@ impl<Signer: WriteableEcdsaChannelSigner> ChannelMonitor<Signer> {
{
let mut inner = self.inner.lock().unwrap();
let fee_estimator = LowerBoundedFeeEstimator::new(&**fee_estimator);
let logger = WithChannelMonitor::from_impl(logger, &*inner);
let logger = WithChannelMonitor::from_impl(logger, &*inner, None);
inner.queue_latest_holder_commitment_txn_for_broadcast(broadcaster, &fee_estimator, &logger);
}

Expand All @@ -1632,7 +1634,7 @@ impl<Signer: WriteableEcdsaChannelSigner> ChannelMonitor<Signer> {
pub fn unsafe_get_latest_holder_commitment_txn<L: Deref>(&self, logger: &L) -> Vec<Transaction>
where L::Target: Logger {
let mut inner = self.inner.lock().unwrap();
let logger = WithChannelMonitor::from_impl(logger, &*inner);
let logger = WithChannelMonitor::from_impl(logger, &*inner, None);
inner.unsafe_get_latest_holder_commitment_txn(&logger)
}

Expand Down Expand Up @@ -1662,7 +1664,7 @@ impl<Signer: WriteableEcdsaChannelSigner> ChannelMonitor<Signer> {
L::Target: Logger,
{
let mut inner = self.inner.lock().unwrap();
let logger = WithChannelMonitor::from_impl(logger, &*inner);
let logger = WithChannelMonitor::from_impl(logger, &*inner, None);
inner.block_connected(
header, txdata, height, broadcaster, fee_estimator, &logger)
}
Expand All @@ -1682,7 +1684,7 @@ impl<Signer: WriteableEcdsaChannelSigner> ChannelMonitor<Signer> {
L::Target: Logger,
{
let mut inner = self.inner.lock().unwrap();
let logger = WithChannelMonitor::from_impl(logger, &*inner);
let logger = WithChannelMonitor::from_impl(logger, &*inner, None);
inner.block_disconnected(
header, height, broadcaster, fee_estimator, &logger)
}
Expand Down Expand Up @@ -1710,7 +1712,7 @@ impl<Signer: WriteableEcdsaChannelSigner> ChannelMonitor<Signer> {
{
let bounded_fee_estimator = LowerBoundedFeeEstimator::new(fee_estimator);
let mut inner = self.inner.lock().unwrap();
let logger = WithChannelMonitor::from_impl(logger, &*inner);
let logger = WithChannelMonitor::from_impl(logger, &*inner, None);
inner.transactions_confirmed(
header, txdata, height, broadcaster, &bounded_fee_estimator, &logger)
}
Expand All @@ -1734,7 +1736,7 @@ impl<Signer: WriteableEcdsaChannelSigner> ChannelMonitor<Signer> {
{
let bounded_fee_estimator = LowerBoundedFeeEstimator::new(fee_estimator);
let mut inner = self.inner.lock().unwrap();
let logger = WithChannelMonitor::from_impl(logger, &*inner);
let logger = WithChannelMonitor::from_impl(logger, &*inner, None);
inner.transaction_unconfirmed(
txid, broadcaster, &bounded_fee_estimator, &logger
);
Expand Down Expand Up @@ -1762,7 +1764,7 @@ impl<Signer: WriteableEcdsaChannelSigner> ChannelMonitor<Signer> {
{
let bounded_fee_estimator = LowerBoundedFeeEstimator::new(fee_estimator);
let mut inner = self.inner.lock().unwrap();
let logger = WithChannelMonitor::from_impl(logger, &*inner);
let logger = WithChannelMonitor::from_impl(logger, &*inner, None);
inner.best_block_updated(
header, height, broadcaster, &bounded_fee_estimator, &logger
)
Expand Down Expand Up @@ -1802,7 +1804,7 @@ impl<Signer: WriteableEcdsaChannelSigner> ChannelMonitor<Signer> {
{
let fee_estimator = LowerBoundedFeeEstimator::new(fee_estimator);
let mut inner = self.inner.lock().unwrap();
let logger = WithChannelMonitor::from_impl(logger, &*inner);
let logger = WithChannelMonitor::from_impl(logger, &*inner, None);
let current_height = inner.best_block.height;
inner.onchain_tx_handler.rebroadcast_pending_claims(
current_height, FeerateStrategy::HighestOfPreviousOrNew, &broadcaster, &fee_estimator, &logger,
Expand All @@ -1821,7 +1823,7 @@ impl<Signer: WriteableEcdsaChannelSigner> ChannelMonitor<Signer> {
{
let fee_estimator = LowerBoundedFeeEstimator::new(fee_estimator);
let mut inner = self.inner.lock().unwrap();
let logger = WithChannelMonitor::from_impl(logger, &*inner);
let logger = WithChannelMonitor::from_impl(logger, &*inner, None);
let current_height = inner.best_block.height;
inner.onchain_tx_handler.rebroadcast_pending_claims(
current_height, FeerateStrategy::RetryPrevious, &broadcaster, &fee_estimator, &logger,
Expand Down Expand Up @@ -5260,7 +5262,8 @@ mod tests {
best_block, dummy_key, channel_id);

let chan_id = monitor.inner.lock().unwrap().channel_id();
let context_logger = WithChannelMonitor::from(&logger, &monitor);
let payment_hash = PaymentHash([1; 32]);
let context_logger = WithChannelMonitor::from(&logger, &monitor, Some(payment_hash));
log_error!(context_logger, "This is an error");
log_warn!(context_logger, "This is an error");
log_debug!(context_logger, "This is an error");
Expand Down
9 changes: 6 additions & 3 deletions lightning/src/ln/channel.rs
Original file line number Diff line number Diff line change
Expand Up @@ -923,25 +923,28 @@ pub(super) struct WithChannelContext<'a, L: Deref> where L::Target: Logger {
pub logger: &'a L,
pub peer_id: Option<PublicKey>,
pub channel_id: Option<ChannelId>,
pub payment_hash: Option<PaymentHash>,
}

impl<'a, L: Deref> Logger for WithChannelContext<'a, L> where L::Target: Logger {
fn log(&self, mut record: Record) {
record.peer_id = self.peer_id;
record.channel_id = self.channel_id;
record.payment_hash = self.payment_hash;
self.logger.log(record)
}
}

impl<'a, 'b, L: Deref> WithChannelContext<'a, L>
where L::Target: Logger {
pub(super) fn from<S: Deref>(logger: &'a L, context: &'b ChannelContext<S>) -> Self
pub(super) fn from<S: Deref>(logger: &'a L, context: &'b ChannelContext<S>, payment_hash: Option<PaymentHash>) -> Self
where S::Target: SignerProvider
{
WithChannelContext {
logger,
peer_id: Some(context.counterparty_node_id),
channel_id: Some(context.channel_id),
payment_hash
}
}
}
Expand Down Expand Up @@ -1571,7 +1574,7 @@ impl<SP: Deref> ChannelContext<SP> where SP::Target: SignerProvider {
L::Target: Logger,
SP::Target: SignerProvider,
{
let logger = WithContext::from(logger, Some(counterparty_node_id), Some(open_channel_fields.temporary_channel_id));
let logger = WithContext::from(logger, Some(counterparty_node_id), Some(open_channel_fields.temporary_channel_id), None);
let announced_channel = if (open_channel_fields.channel_flags & 1) == 1 { true } else { false };

let channel_value_satoshis = our_funding_satoshis.saturating_add(open_channel_fields.funding_satoshis);
Expand Down Expand Up @@ -7859,7 +7862,7 @@ impl<SP: Deref> InboundV1Channel<SP> where SP::Target: SignerProvider {
F::Target: FeeEstimator,
L::Target: Logger,
{
let logger = WithContext::from(logger, Some(counterparty_node_id), Some(msg.common_fields.temporary_channel_id));
let logger = WithContext::from(logger, Some(counterparty_node_id), Some(msg.common_fields.temporary_channel_id), None);

// First check the channel type is known, failing before we do anything else if we don't
// support this channel type.
Expand Down
Loading
Loading