Skip to content
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

AST Cleanup: Split After / Older into more specific types? #270

Closed
JeremyRubin opened this issue Sep 18, 2021 · 11 comments · Fixed by #654
Closed

AST Cleanup: Split After / Older into more specific types? #270

JeremyRubin opened this issue Sep 18, 2021 · 11 comments · Fixed by #654
Labels
good first issue Good for newcomers

Comments

@JeremyRubin
Copy link
Contributor

Suggestion:

While keeping the parsing and output intact for compatibility, we could modify our internal representations of After and Older to be:

AfterHeight(), AfterTime(), WaitBlocks(), WaitDuration() or an internal enum (e.g., After(Height | Time), Wait(Blocks | Duration)).

In Sapio I accomplish this at the user level, but it would probably make sense for those branches to be distinct. This also allows (as I've done in the library) to narrow the types used in the internal representations from e.g. u32s for relative timelocks to u16s making the values correct by construction. This also rules out using non-standardized values.

Users of the Library from Rust would have the improved interface, which would make it easier to write "correct" generic code as users would be able to be unconcerned with checking inputs u32s for well formedness to a Older/After clause, while users using this as a string interface would see the old API (unless we modify the spec to have the 4 types of clause).

If the more generic API of Older/After is desired, this could be accomplished with a function Older/After (or type with Into) that takes a u32 and downcasts into the appropriate type.

@sanket1729
Copy link
Member

Concept ACK. This will clean up some code here too. I can work on this post tapscript

@apoelstra
Copy link
Member

concept ack from me too

@apoelstra
Copy link
Member

I think we should do this using an internal enum, which we can convert from a u32 and do checks at that time

@JeremyRubin
Copy link
Contributor Author

if you prefer that route, you'd be welcome to take the code from sapio (i can relicense that segment under MIT license) https://github.com/sapio-lang/sapio/blob/master/sapio-base/src/timelocks.rs, but that might be a bit extra for the goals here (but i've found it pretty ergonomic in my personal use).

@apoelstra
Copy link
Member

Thanks for the offer to relicense -- though FYI we are CC0, not MIT. I don't have time today to dive into whether we'd want to go that route or implement our own (smaller) enum.

@JeremyRubin
Copy link
Contributor Author

CC0 is fine for that as well, if desired.

@tcharding
Copy link
Member

With the use of bitcoin v0.29 we now use LockTime types for After/Older - I believe this issue can be closed.

@apoelstra
Copy link
Member

I agree -- @JeremyRubin feel free to re-open but I think we have finally done this (and we fixed a pile of bugs in the process :))

@sanket1729
Copy link
Member

@apoelstra, I believe this issue want to splits the Terminal::After(PackedLockTime) into Terminal::AfterHeight(Height) and Terminal::AfterBlocks(Blocks). Same thing for sequence. We have not done that yet

@apoelstra apoelstra reopened this Dec 30, 2022
@sanket1729
Copy link
Member

This will also us to make progress on #435. I will make an attempt on this one this week.

@gerceboss
Copy link

@sanket1729 , I would like to contribute in here , can you suggest how can I start to understand the codebase? And can you also give some detail regarding this issue?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
good first issue Good for newcomers
Projects
None yet
Development

Successfully merging a pull request may close this issue.

5 participants