Skip to content

The Big Refactor ™️#15

Merged
darosior merged 7 commits intorevault:masterfrom
darosior:tx_struct
Sep 26, 2020
Merged

The Big Refactor ™️#15
darosior merged 7 commits intorevault:masterfrom
darosior:tx_struct

Conversation

@darosior
Copy link
Copy Markdown
Member

I had basically two choices for the first implem: going with traits vs going with a big enum. This was a bad choice and this refactor reverts it to The Right Thing which was to use traits. So: sorry for the big diff, but it had to be done.

This:

  • Makes transactions actual types (not variants), this allows for even more type-safety.
  • Creates additional trait to enforce the prevouts / txouts types at compile time.
  • Expose a nicer API: no more Result (compile time ❤️)

I also found a bug as i went through this.

@darosior
Copy link
Copy Markdown
Member Author

Still need some polish but almost good

@darosior darosior force-pushed the tx_struct branch 2 times, most recently from a8be767 to 1612395 Compare September 21, 2020 21:31
@darosior darosior marked this pull request as ready for review September 21, 2020 21:31
@darosior
Copy link
Copy Markdown
Member Author

Rebased and squashed, this is now ready for review

@darosior
Copy link
Copy Markdown
Member Author

Wrt #15 (comment) i wonder how far we should go with type safety. We could for example have rust into_prevout(&self, vout: u32) return the well-typed RevaultPrevout instead of a generalistic OutPoint. This would however incur a high complexity cost (we'd basically need our own boutique Transaction).

I think the current state is a good tradeoff (obviously), but i'm really interested in your opinions as well.

@edouardparis
Copy link
Copy Markdown
Member

ACK ccb869d

Benefits:
- Enforce types at compilation
- Better API (no Result at creation, errors are statics, more
  fine-grained)
- Actual types (no enum variant)

Drawbacks:
- Boilerplate, partially handled by macros

Signed-off-by: Antoine Poinsot <darosior@protonmail.com>
Separated from the next one to highlight the usage of the new API.

Lot of tests removal here: what was tested would not even compile anymore
now :-).

Signed-off-by: Antoine Poinsot <darosior@protonmail.com>
This is definitely *WAY* nicer to use. The only downside of this one is
the panical-libbitcoinconsensus-assertion but hey, i left a FIXME!

I found a bug, too.

Signed-off-by: Antoine Poinsot <darosior@protonmail.com>
This corrects a typo that -surprinsingly enough- passed all the tests..
And fixes the tests satisfier.

Added some drive-by sanity checks for the 512 seconds granularity
"feature" of CSV.

Signed-off-by: Antoine Poinsot <darosior@protonmail.com>
It's dumb and annoying af

Signed-off-by: Antoine Poinsot <darosior@protonmail.com>
Signed-off-by: Antoine Poinsot <darosior@protonmail.com>
Now it's done at compile time. Not removing libibtcoinconsensus' one as i expect to get it back

Signed-off-by: Antoine Poinsot <darosior@protonmail.com>
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 9c8f8f8

@JSwambo
Copy link
Copy Markdown
Member

JSwambo commented Sep 26, 2020

Wrt #15 (comment) i wonder how far we should go with type safety. We could for example have rust into_prevout(&self, vout: u32) return the well-typed RevaultPrevout instead of a generalistic OutPoint. This would however incur a high complexity cost (we'd basically need our own boutique Transaction).

I think the current state is a good tradeoff (obviously), but i'm really interested in your opinions as well.

I think so too. I think type-safety here helps us guarantee that signatures are only generated for RevaultTransactions that conform to the protocol and avoids unnecessary exposure of private keys for inappropriate transactions.

What would be gained from having returning RevaultPrevOut instead of OutPoint?

@darosior
Copy link
Copy Markdown
Member Author

What would be gained from having returning RevaultPrevOut instead of OutPoint?

Typically it'd have prevented my mistake in #15 (comment) . Which was:

// ..Or the spend_tx's change
let _sec_emer_tx = EmergencyTransaction::new(
       (VaultPrevout::new(spend_tx.into_prevout(1)), RBF_SEQUENCE),
  );

Instead of

// ..Or the spend_tx's change
let _sec_emer_tx = EmergencyTransaction::new(
       (VaultPrevout::new(spend_tx.into_prevout(0)), RBF_SEQUENCE),
  );

Sneaky, isn't it ? If into_prevout was strongly typed this would not have compiled at all. Anyways i think i can hack something similar using PSBTs, working on it now.

@darosior darosior merged commit 45178e8 into revault:master Sep 26, 2020
@darosior darosior deleted the tx_struct branch September 26, 2020 12:23
darosior added a commit that referenced this pull request Sep 26, 2020
…ctions

cf19162 transactions: allow caller to set nLockTime (anti fee-snipping) (Antoine Poinsot)
f57f94d transactions: refactor RevaultTransaction into using traits (Antoine Poinsot)

Pull request description:

  Based on #15.

  It adds a new parameter to the transactions constructor for them to be able to set the transaction's `nLockTime`.

ACKs for top commit:
  darosior:
    ACK cf19162 (re-applying Jacob's ACK)

Tree-SHA512: 0d956839f08cb926c6156e328ad30b3c8c7de8bb1c2b665c6e2134880e383788533fcf4f5546fa71a4f9256b5509a108e17d553107fbacff5de703caddae9580
darosior added a commit that referenced this pull request Oct 2, 2020
2855c5b scripts: expose a raw interface to the unvault script (Antoine Poinsot)
4ab3f78 cleanup dependencies (Antoine Poinsot)

Pull request description:

  This is based on #10 (itself base on #15 ...), see:
  - cd829a3
  - 5feaa58

  This adds an interface to fix #14 .
  Good news: we can apparently support threshold-based managers set.
  Question news: [what now](https://github.com/re-vault/practical-revault/issues/19#issuecomment-699479602) ?

ACKs for top commit:
  JSwambo:
    Ack 2855c5b

Tree-SHA512: 02f02191e935193ca9baf989cdb64a7d0d528f9274e719eab49f1dbef515647950611a9ca7f68e31a06d51e604487e7cc7e8e4bb4301b658a3916cbffcf96a56
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