Skip to content
New issue

Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? # to your account

Split miniscript into descriptor and miniscript crates. #783

Open
storopoli opened this issue Dec 10, 2024 · 1 comment
Open

Split miniscript into descriptor and miniscript crates. #783

storopoli opened this issue Dec 10, 2024 · 1 comment

Comments

@storopoli
Copy link
Contributor

Moving from rust-bitcoin/rust-bitcoin#3695

From @sanket1729:

It is a lot of work, but conceptually it should be possible to split rust-miniscript into descriptors and miniscript. For people who want simple descriptors without miniscript can then use it.

From @apoelstra:

"let's split rust-miniscript into two crates", which I think is a great idea, though it will be a lot of work, and we'll need to spend a bunch of time bikeshedding which parts go into which pieces, and we'll also want to think a bit about how the new descriptors crate would relate to bitcoin-addresses. (Maybe miniscript should depend on addresses which depends on descriptors/bech32/base58/etc?)

@apoelstra
Copy link
Member

It seems to me that a descriptors crate should definitely have:

  • the expression/checksum parsing modules
  • the DescriptorPublicKey type

and definitely not have

  • Miniscript
  • the policy types
  • the interpreter and satisfier and PSBT finalizer

Although it may make sense to have a basic satisfier and finalizer that can only handle simple templates.

However, I'm not sure what would need to happen to the Descriptor enum

pub enum Descriptor<Pk: MiniscriptKey> {
    Bare(Bare<Pk>),
    Pkh(Pkh<Pk>),
    Wpkh(Wpkh<Pk>),
    Sh(Sh<Pk>),
    Wsh(Wsh<Pk>),
    Tr(Tr<Pk>),
}

You can see that Pkh, Wpkh and the key-only form of Tr, and possibly the basic multisig/sortedmulti forms of Bare/Sh/Wsh, might make sense in a descriptors crate while everything else is generic Miniscript and would not make sense. However, Rust does not give a good way to split things up like this.

We could attempt to replace the Descriptor enum with a Descriptor trait, though things like parsing would be pretty difficult (would need to return a Box<dyn Descriptor> and then the trait would need some sort of downcasting ability I guess?). This is something people have requested anyway, notably to experiment with CTV and APO. But I feel like I've tried it and really struggled. It may be that removing the Ctx parameter #723 would make this possible while it's currently impossible?

If we were throwing around Box<dyn Descriptor> then the trait would need to be object-safe -- this means no methods returning Self and no associated types. Is that feasible?

Without converting the enum to a trait I think this idea is just dead in the water, because it would mean that descriptors and miniscript traits would need different and incompatible Descriptor types. If we did convert the enum to a trait, this introduces some more questions -- what parts should be part of the API? Would rust-miniscript need to define an extension trait? Would it be possible to implement this extension trait generically for everything supporting the basic trait?

# for free to join this conversation on GitHub. Already have an account? # to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants