Skip to content

Take the full funding transaction from the user on generation #856

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 1 commit into from
Apr 10, 2021

Conversation

TheBlueMatt
Copy link
Collaborator

Instead of relying on the user to ensure the funding transaction is
correct (and panicing when it is confirmed), we should check it is
correct when it is generated. By taking the full funding transaciton
from the user on generation, we can also handle broadcasting for
them instead of doing so via an event.

@ariard
Copy link

ariard commented Mar 26, 2021

Concept ACK, will be needed for dual-funding/splicing support anyway.

@codecov
Copy link

codecov bot commented Mar 26, 2021

Codecov Report

Merging #856 (26a2f25) into main (fe85696) will increase coverage by 1.87%.
The diff coverage is 83.65%.

❗ Current head 26a2f25 differs from pull request most recent head 3f2efcd. Consider uploading reports for the commit 3f2efcd to get more accurate results
Impacted file tree graph

@@            Coverage Diff             @@
##             main     #856      +/-   ##
==========================================
+ Coverage   90.60%   92.48%   +1.87%     
==========================================
  Files          51       51              
  Lines       27109    33438    +6329     
==========================================
+ Hits        24563    30925    +6362     
+ Misses       2546     2513      -33     
Impacted Files Coverage Δ
lightning/src/util/events.rs 19.23% <11.11%> (-4.67%) ⬇️
lightning/src/ln/channelmanager.rs 87.39% <78.04%> (+4.17%) ⬆️
background-processor/src/lib.rs 98.73% <100.00%> (-1.27%) ⬇️
lightning/src/ln/chanmon_update_fail_tests.rs 97.63% <100.00%> (+0.07%) ⬆️
lightning/src/ln/channel.rs 91.82% <100.00%> (+4.68%) ⬆️
lightning/src/ln/functional_test_utils.rs 96.69% <100.00%> (+1.47%) ⬆️
lightning/src/ln/functional_tests.rs 98.41% <100.00%> (+1.51%) ⬆️
lightning/src/routing/router.rs 96.87% <0.00%> (-0.10%) ⬇️
lightning/src/ln/reorg_tests.rs 99.63% <0.00%> (+0.06%) ⬆️
... and 8 more

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update fe85696...3f2efcd. Read the comment docs.

Copy link
Contributor

@valentinewallace valentinewallace left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This looks super reasonable to me! I love API improvements like this. Let's get rid of PendingHTLCsForwardable next 🤪

Copy link
Contributor

@valentinewallace valentinewallace left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Just some nits, the code LGTM 💯

@TheBlueMatt TheBlueMatt added this to the 0.0.14 milestone Apr 5, 2021
Copy link

@ariard ariard left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Minor comments, otherwise sounds good to me :)

for inp in funding_transaction.input.iter() {
if inp.witness.is_empty() {
return Err(APIError::APIMisuseError {
err: "Funding transaction must be fully signed and spend Segwit outputs".to_owned()
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

By transaction must be fully signed you meant use only SIGHASH_ALL otherwise you might have in-flight malleability breaking the signatures for the first commitment transaction ?

Ideally we have the signatures available in the witnesses so in the future we might parse them to verify sighash types flag to protect users against footgunish behaviors.

Copy link
Collaborator Author

@TheBlueMatt TheBlueMatt Apr 7, 2021

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't think so - the witness can change but that's fine, it'd only be if the transaction is, eg, SIGHASH_SINGLE and someone on the network can arbitrarily change where the transaction funds are going. I dont think we need to document "don't construct the transaction such that someone can arbitrarily modify it".

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If the witness change in the wrong way with a SIGHASH_SINGLE as you point it that's not fine. Should we document "don't construct the transaction such that someone can arbitrarily modify it " ? I would say we suffer from cognitive dissonance there. It's quite obvious to us but in practice users might authorize malleation or even RBF for fee management (see https://lists.linuxfoundation.org/pipermail/lightning-dev/2021-March/002981.html).

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Right, I guess we could re-enforce the last line - if you don't broadcast the transaction yourself, you can't RBF either :).

err: "Multiple outputs matched the expected script and value".to_owned()
});
}
if idx > u16::max_value() as usize {
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If you assume minimal-sized output (8 bytes value + 2 bytes scriptPubkey), given that MAX_STANDARD_TX_WEIGHT is about 100k bytes, I think you can just reject a transaction with an idx above 10_000 ?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sure, but its nice to get an error instead of a panic, even if you did something kinda stupid.

@TheBlueMatt TheBlueMatt mentioned this pull request Apr 7, 2021
3 tasks
@ariard
Copy link

ariard commented Apr 9, 2021

Code Review b42f594

If you wanna document more malleation risks, I'm happy.

@TheBlueMatt
Copy link
Collaborator Author

Added a note

        /// Do NOT broadcast the funding transaction yourself. When we have safely received our
        /// counterparty's signature the funding transaction will automatically be broadcast via the
        /// [`BroadcasterInterface`] provided when this `ChannelManager` was constructed.
+       ///
+       /// Note that this includes RBF or similar transaction replacement strategies - lightning does
+       /// not currently support replacing a funding transaction on an existing channel. Instead,
+       /// create a new channel with a conflicting funding transaction.

@ariard
Copy link

ariard commented Apr 9, 2021

Code Review ACK 26a2f25 Thanks for the comment :)

Instead of relying on the user to ensure the funding transaction is
correct (and panicing when it is confirmed), we should check it is
correct when it is generated. By taking the full funding transaciton
from the user on generation, we can also handle broadcasting for
them instead of doing so via an event.
@TheBlueMatt
Copy link
Collaborator Author

Squashed with no changes, will merge after CI.

$ git diff-tree -U3 26a2f258 3f2efcdf
$

@TheBlueMatt TheBlueMatt merged commit 8088e4b into lightningdevkit:main Apr 10, 2021
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.

3 participants