examples icon indicating copy to clipboard operation
examples copied to clipboard

Store ECDSA and Schnorr keys in a static variable to avoid repeated mgmt canister calls

Open dantol29 opened this issue 1 year ago • 4 comments

BASIC_BITCOIN example

It takes approximately ~9 seconds to get public key, as well as a decent amount of gas is spent. Is there a reason why we have to call schnorr_public_key or ecdsa_public_key each time a user wants to get an address? If not then storing public keys in a static variable would maintain state across different calls to the canister and save lots of time and gas. I understand that this is just an example, but perhaps this optimization would show some devs how to reduce cycle burn rate.

Something like:

thread_local! {
    /* flexible */ static SCHNORR: RefCell<Option<SchnorrPublicKey>> = RefCell::default();
}

dantol29 avatar Sep 02 '24 12:09 dantol29

This issue is stale because it has been open for 30 days with no activity.

github-actions[bot] avatar Oct 03 '24 01:10 github-actions[bot]

It is indeed reasonable to cache the public key in a variable instead of repeatedly making calls to the management canister. We will try to address this soon, but feel free to open a PR yourself if you like.

altkdf avatar Oct 14 '24 08:10 altkdf

It is indeed reasonable to cache the public key in a variable instead of repeatedly making calls to the management canister. We will try to address this soon, but feel free to open a PR yourself if you like.

Gonna open PR soon! Thank you for the answer!

dantol29 avatar Oct 16 '24 13:10 dantol29

Opened the PR

dantol29 avatar Oct 16 '24 14:10 dantol29

closing this as the PR has been merged here: https://github.com/dfinity/examples/pull/1024

marc0olo avatar Nov 08 '24 10:11 marc0olo