Skip to content

Refactor, second episode: move to PSBTs#21

Merged
darosior merged 12 commits intorevault:masterfrom
darosior:psbt
Oct 3, 2020
Merged

Refactor, second episode: move to PSBTs#21
darosior merged 12 commits intorevault:masterfrom
darosior:psbt

Conversation

@darosior
Copy link
Copy Markdown
Member

@darosior darosior commented Oct 1, 2020

This is based on #10 (as pretty much everything now..) and implements the usage of PSBT in our RevaultTransaction management, from the creation to the satisfaction.

This unlocked a few side improvements, such as:

  • Get rid of the RevaultSatisfier struct
  • Libbitcoinconsensus verification is back!
  • Even more typesafety (eg for TxOuts and script descriptors)

The methods of the RevaultTransaction traits have been modified with BIP174 roles in mind, which will likely guide us toward less footguns downstream.

@darosior darosior changed the title Refactor, season 2: move to PSBTs Refactor, second episode: move to PSBTs Oct 2, 2020
@darosior
Copy link
Copy Markdown
Member Author

darosior commented Oct 2, 2020

Rebased after #10 rebase.

@darosior
Copy link
Copy Markdown
Member Author

darosior commented Oct 2, 2020

Rebased after #10 merge 🎉

sigmap: &'a mut BTreeMap<bitcoin::PublicKey, Vec<u8>>,
sequence: u32,
) -> RevaultInputSatisfier {
// This hack isn't going to last, see above.
Copy link
Copy Markdown
Member Author

@darosior darosior Oct 2, 2020

Choose a reason for hiding this comment

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

Actually it is, here or upstream :)

@darosior darosior force-pushed the psbt branch 2 times, most recently from 5f84d66 to 5e4dd40 Compare October 2, 2020 13:11
@darosior
Copy link
Copy Markdown
Member Author

darosior commented Oct 2, 2020

Rebased on master and to clean up the history. Since 931274e breaks bisectability i wonder if i should squash it on 8af4279.

Also added a commit at the root as we broke master again...

bitcoin::Address::p2wsh(witness_script, bitcoin::Network::Bitcoin)
.script_pubkey();
if expected_script_pubkey
!= psbtin
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

weird indentation, Is it rustfmt ?

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

Yeah..

src/txins.rs Outdated
/// Get a reference to the txout this txin refers
fn txout(&self) -> &T;
/// Get the actual txout this txin refers
fn get_txout(self) -> T;
Copy link
Copy Markdown
Member

@JSwambo JSwambo Oct 2, 2020

Choose a reason for hiding this comment

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

rename to as_outpoint(), as_txout(), into_txout() as per #19 ?

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

I considered doing an actual cleanup PR for this and the documentation (maybe some more test cov as well). I could avoid introducing more here but... That incurs some non-trivial rebases (opened the issue after finishing this, fwiw)

@@ -12,28 +15,36 @@ pub trait RevaultTxOut: fmt::Debug + Clone + PartialEq {
fn inner_txout(&self) -> &TxOut;
/// Get the actual inner txout
fn get_txout(self) -> TxOut;
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Here too (#19)... as_ and into_

Copy link
Copy Markdown
Member

@JSwambo JSwambo left a comment

Choose a reason for hiding this comment

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

Ack 5e4dd40

Copy link
Copy Markdown
Member

@edouardparis edouardparis left a comment

Choose a reason for hiding this comment

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

ACK 30305bc

Signed-off-by: Antoine Poinsot <darosior@protonmail.com>
Signed-off-by: Antoine Poinsot <darosior@protonmail.com>
Signed-off-by: Antoine Poinsot <darosior@protonmail.com>
This also removes the useless test_transaction_creation() test, just
added to highlight the API.

Signed-off-by: Antoine Poinsot <darosior@protonmail.com>
Still prep work for PSBT integration

Signed-off-by: Antoine Poinsot <darosior@protonmail.com>
This avoids confusion, also some slight drive-by doc improvements.

Signed-off-by: Antoine Poinsot <darosior@protonmail.com>
This was coming. PrevOuts can be reused and with the inclusion of the
TxOut into them we lost the Copy, intuitively bounding their lifetimes
to one usage.

Besides, we had those monstruous inputs in RevaultTransactions'
new()s.

Now that their sequence is bounded to them, they are one-shot
transaction inputs, and their usage is much more intuitive!

Of course, this helps me with PSBT as well :-)

Signed-off-by: Antoine Poinsot <darosior@protonmail.com>
Signed-off-by: Antoine Poinsot <darosior@protonmail.com>
This:
- Replaces the inner Transaction by a PSBT in RevaultTransaction
- Adapts the API to use BIP174 roles (somewhat)
- Implements the satisfaction as part of the RevaultTransaction, under
  the Finalizer role.
- Still makes use of our internal satisfier (even though the pub API is now
  part of RevaultTransaction).
- Reuses some logic from Miniscript descriptors until upstream implements
  comprehensive PSBT support for them.

Signed-off-by: Antoine Poinsot <darosior@protonmail.com>
Signed-off-by: Antoine Poinsot <darosior@protonmail.com>
We won't finalize a transaction that does not pass the
libbitcoinconsensus check.

Signed-off-by: Antoine Poinsot <darosior@protonmail.com>
Signed-off-by: Antoine Poinsot <darosior@protonmail.com>
@darosior
Copy link
Copy Markdown
Member Author

darosior commented Oct 2, 2020

Ok so:

  • improved the API for the add_signature() method as pointed by @edouardparis
  • addressed @JSwambo nits
  • squashed some commits to maintain bisectability (rebase master -x "cargo test")

Can you re review please ?

Copy link
Copy Markdown
Member

@edouardparis edouardparis left a comment

Choose a reason for hiding this comment

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

ACK a0e0ff5

@darosior darosior mentioned this pull request Oct 3, 2020
@darosior darosior merged commit 71fc7f8 into revault:master Oct 3, 2020
darosior added a commit that referenced this pull request Oct 3, 2020
e1ab2c6 transactions: remove state consistency TODO and useless alloc (Antoine Poinsot)
3d2b1f5 transactions: centralize the signature_hash() method (Antoine Poinsot)
6d63c38 transactions: don't unwrap in add_signature() (Antoine Poinsot)
108fc00 Improve documentation, remove error mod (Antoine Poinsot)
1715199 Cargo: use latest stable Miniscript version (Antoine Poinsot)
bead86f Change method names to conventional ones (Antoine Poinsot)

Pull request description:

  Based on #21

ACKs for top commit:
  JSwambo:
    Ack e1ab2c6

Tree-SHA512: 09e938dc55bf8b3b5330cc2a36695f940d3ccb5ad806a4409eea2160b859f3903cbcf0e69e02567173ade31b573f8a793a42d08bc64a498ef98ddb0aa8c506b2
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