Skip to content

Optimize mint/redeem flows: read createdEventBlob from submit response, drop re-fetch round-trip #44

@gyorgybalazsi

Description

@gyorgybalazsi

Follow-up from PR #41.

Context

PR #41 migrated cbtc-lib off the deprecated submit-and-wait-for-transaction-tree JSON Ledger API endpoint. As part of preserving identical behavior, two flows still re-fetch from active contracts after submit:

  • src/mint_redeem/mint.rs:194-211create_deposit_account calls list_deposit_accounts after submit.
  • src/mint_redeem/redeem.rs:222-239create_withdraw_account calls list_withdraw_accounts after submit.

This re-fetch was originally there to populate the canonical struct (via *Account::from_active_contract). The migration's updated comments correctly note that the flat submit response under verbose=true already carries createArgument and createdEventBlob, so the re-fetch is no longer strictly necessary.

GitHub Copilot raised this during PR #41 review: #41 (comment)

Proposal

Apply the pattern already used by credentials.rs:425-447 and redeem.rs:475-498 (the submit_withdraw flow):

let created_event_value = &created_event["value"];
let active_contract = JsActiveContract {
    created_event: Box::new(ledger::models::CreatedEvent {
        contract_id: created_event_value["contractId"].as_str().unwrap_or("").to_string(),
        template_id: template_id.to_string(),
        create_argument: Some(Some(created_event_value["createArgument"].clone())),
        created_event_blob: created_event_value["createdEventBlob"].as_str().unwrap_or("").to_string(),
        ..Default::default()
    }),
    reassignment_counter: 0,
    synchronizer_id: String::new(),
};
return DepositAccount::from_active_contract(&active_contract);

…replacing the list_deposit_accounts / list_withdraw_accounts round-trip.

Benefits

  • Shaves one network round-trip per mint and redeem-create flow.
  • Brings these flows into structural parity with the credentials and submit_withdraw flows.

Risks / verification

  • Verify list_deposit_accounts / list_withdraw_accounts aren't doing anything else load-bearing (e.g., waiting for indexing) before removing the call.
  • The error paths change slightly: a missing createdEventBlob in the submit response would now produce an empty-string blob instead of an error from the list-call. Worth confirming this is fine.
  • Integration test (examples/integration_test.rs) covers both flows end-to-end.

Affected code

  • src/mint_redeem/mint.rscreate_deposit_account
  • src/mint_redeem/redeem.rscreate_withdraw_account

Metadata

Metadata

Assignees

No one assigned

    Labels

    maintenanceMaintenance, deps, and upgrade work

    Type

    No type
    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