-
Notifications
You must be signed in to change notification settings - Fork 409
Introduce IsMine logic in ChannelMonitor for SpendableOutputDescriptor detection #552
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
Introduce IsMine logic in ChannelMonitor for SpendableOutputDescriptor detection #552
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nice! All the comments are pretty simple and mostly just asking for better names.
lightning/src/ln/channelmonitor.rs
Outdated
break; | ||
} | ||
} | ||
let revokeable_script = if let Ok(local_delayedkey) = chan_utils::derive_private_key(&self.secp_ctx, &local_tx.per_commitment_point, delayed_payment_base_key) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why return this? I think we should be setting it here, make this fn take &mut self
and do the local_tx.tx.add_local_sig
call in it. This would be a good step towards DRY'ing up calls to local_tx.tx.add_local_sig
so that we only ever do it once (which a reasonable ChannelKeys would enforce anyway).
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Okay to delay it in its own dry'up local_tx.tx.add_local_sig
PR ?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Sure, I suppose that'll have to come either way.
eb45bb6
to
15986c8
Compare
@TheBlueMatt, addressed most of your comment, let me know if you find new issues/names suits you. |
lightning/src/ln/channelmonitor.rs
Outdated
} else { | ||
match self.key_storage { | ||
Storage::Local { ref shutdown_pubkey, .. } => { | ||
let our_channel_close_key_hash = Hash160::hash(&shutdown_pubkey.serialize()); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is also an addition of a Hash160 calculation per output in the block.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Aside from the one comment about additional hashing, ACK.
Sadly needs rebase as well now. |
Previously, we would generate SpendableOutputDescriptor::StaticOutput in OnchainTxHandler even if our claiming transaction wouldn't confirm onchain, misbehaving user wallet to think it receives more funds than in reality. Fix tests in consequence
is_paying_spendable_output Add ChannelMonitor::broadcasted_local_revokable_script to detect onchain local txn paying back to us. Fix tests in consequence
is_paying_spendable_output Add ChannelMonitor::broadcasted_remote_payment_script to detect onchain remote txn paying back to us.
is_paying_spendable_output Add ChannelMonitor::shutdown_script to detect onchain tx paying back to us
We delay SpendableOutputDescriptor until reaching ANTI_REORG_DELAY to avoid misleading user wallet in case of reorg and alternative settlement on a channel output. Fix tests in consequence.
0f9b21e
to
5a9d6f4
Compare
lightning/src/ln/functional_tests.rs
Outdated
|
||
let (_, our_payment_hash) = route_payment(&nodes[1], &vec!(&nodes[0])[..], 3_000_000); | ||
|
||
let commitment_tx = nodes[0].node.channel_state.lock().unwrap().by_id.get_mut(&chan_1.2).unwrap().channel_monitor().get_latest_local_commitment_txn(); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please use the new macro here.
Cover previously missing SpendableOuputDescriptor for timeout tx on non-revoked remote commitment tx. Fix lightningdevkit#338
5a9d6f4
to
1c7b6c8
Compare
Previously SpendableOutputDescriptor detection was spread in a lot of different places (ChannelMonitor local/remote tx parsing, OnchainTxHandler claim tx generation, closing tx monitoring, ...). This patch gather everything in one new method ChannelMonitor::is_mine. To cover some cases, a bit more of caching is done in ChannelMonitor struct.
Cases covered:
Also introduces MaturingOutput to prevent generating bogus SpendableOuputDescriptor in case of reorg < ANTI_REORG_DELAY.
Takes new commit from #532