Skip to content

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

Merged
merged 7 commits into from
Mar 20, 2020

Conversation

ariard
Copy link

@ariard ariard commented Mar 19, 2020

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:

  • static spendable output for justice tx/claim tx on remote htlc (destination_script)
  • dynamic spendable output (P2WPKH) for remote commitment tx (remotepubkey)
  • dynamic spendable output (P2WSH) for local commitment tx+HTLC txn (revokeable_script)
  • static spendable output (P2WPKH) for closing tx (shutdown_pubkey)

Also introduces MaturingOutput to prevent generating bogus SpendableOuputDescriptor in case of reorg < ANTI_REORG_DELAY.

Takes new commit from #532

@TheBlueMatt TheBlueMatt added this to the 0.0.11 milestone Mar 19, 2020
Copy link
Collaborator

@TheBlueMatt TheBlueMatt left a 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.

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) {
Copy link
Collaborator

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).

Copy link
Author

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 ?

Copy link
Collaborator

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.

@ariard ariard force-pushed the 2020-03-ismine-spendable branch from eb45bb6 to 15986c8 Compare March 19, 2020 22:43
@ariard
Copy link
Author

ariard commented Mar 19, 2020

@TheBlueMatt, addressed most of your comment, let me know if you find new issues/names suits you.

} else {
match self.key_storage {
Storage::Local { ref shutdown_pubkey, .. } => {
let our_channel_close_key_hash = Hash160::hash(&shutdown_pubkey.serialize());
Copy link
Collaborator

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.

Copy link
Collaborator

@TheBlueMatt TheBlueMatt left a 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.

@TheBlueMatt
Copy link
Collaborator

Sadly needs rebase as well now.

Antoine Riard added 6 commits March 19, 2020 22:29
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.
@ariard ariard force-pushed the 2020-03-ismine-spendable branch 2 times, most recently from 0f9b21e to 5a9d6f4 Compare March 20, 2020 18:01

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();
Copy link
Collaborator

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
@ariard ariard force-pushed the 2020-03-ismine-spendable branch from 5a9d6f4 to 1c7b6c8 Compare March 20, 2020 18:34
@TheBlueMatt TheBlueMatt merged commit 8bd155e into lightningdevkit:master Mar 20, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants