Skip to content

Make Jet object-safe #349

@apoelstra

Description

@apoelstra

In several places, most recently BlockstreamResearch/SimplicityHL#224, we've wanted to switch jets at runtime or at least deal with multiple programs whose jet types might differ or be unknown until runtime.

To make this work we need to stop using compile-time generics for the jet. This may mean a Box<dyn Jet> or maybe it means a concrete type. In either case, we need to deal with the transaction environment. Our existing trait has

    /// Obtains a C FFI compatible environment for the jet.
    fn c_jet_env(env: &Self::Environment) -> &Self::CJetEnvironment;

    /// Obtain the FFI C pointer for the jet.
    fn c_jet_ptr(&self) -> &dyn Fn(&mut CFrameItem, CFrameItem, &Self::CJetEnvironment) -> bool;

Reflecting that depending on the type of jets used, the transaction environment should be a different struct (e.g. data for a Bitcoin vs Elements transaction). We need to invert the generics somehow so that Jet can be object-safe, and presumably we would have some sort of Environment object which was generic over the jet.

It may be that we want to use the ghostcell pattern that we use for types::Context (or maybe we even want to combine this with types::Context...though I don't think so because the type context is something that exists only at construction time, while the transaction environment exists for the whole lifecycle of a program. So probably we just want to do runtime checks.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions