Skip to content

Refactor: bundle Prove::prove and AppRunner::run_all inputs into a struct #173

Description

@imikushin

Follow-up from PR #170 (versioned apps).

After versioned apps landed, Prove::prove and AppRunner::run_all each take 5+ map-shaped parameters, several of which have similar generic key types (B32, App). The current signatures:

fn prove(
    &self,
    norm_spell: NormalizedSpell,
    app_binaries: BTreeMap<B32, Vec<u8>>,
    app_signatures: BTreeMap<B32, AppSignature>,
    app_private_inputs: BTreeMap<App, Data>,
    prev_txs: Vec<Tx>,
    tx_ins_beamed_source_utxos: BTreeMap<usize, BeamSource>,
) -> anyhow::Result<(NormalizedSpell, Proof, u64)>;

pub fn run_all(
    &self,
    app_binaries: &BTreeMap<B32, Vec<u8>>,
    versioned_apps: &BTreeMap<B32, VersionedApp>,
    app_signatures: &BTreeMap<B32, AppSignature>,
    tx: &Transaction,
    app_public_inputs: &BTreeMap<App, Data>,
    app_private_inputs: &BTreeMap<App, Data>,
) -> Result<Vec<u64>>;

This is hard to read at call sites and easy to get wrong if more inputs are added later. Bundle them into a dedicated inputs struct (or two — one per function), e.g.:

pub struct AppRunInputs<'a> {
    pub app_binaries: &'a BTreeMap<B32, Vec<u8>>,
    pub versioned_apps: &'a BTreeMap<B32, VersionedApp>,
    pub app_signatures: &'a BTreeMap<B32, AppSignature>,
    pub app_public_inputs: &'a BTreeMap<App, Data>,
    pub app_private_inputs: &'a BTreeMap<App, Data>,
}

impl AppRunner {
    pub fn run_all(&self, inputs: &AppRunInputs<'_>, tx: &Transaction) -> Result<Vec<u64>> { ... }
}

Notes:

  • Prove is pub, but in v15 there are no external implementors — this is still a breaking change semantically; should land in a minor version bump, with a brief changelog note.
  • AppInput already exists in charms-data and may be the right place to hang most of the new bundle (it already holds app_binaries, app_private_inputs, app_signatures).

Referenced in PR #170 review comments:

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Fields

    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions