dfinity / examples

Example applications, microservices, and code samples for the Internet Computer
https://dfinity.org
Apache License 2.0
548 stars 395 forks source link

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

Closed dantol29 closed 3 weeks ago

dantol29 commented 3 months ago

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();
}
github-actions[bot] commented 2 months ago

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

altkdf commented 1 month ago

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.

dantol29 commented 1 month ago

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 commented 1 month ago

Opened the PR

marc0olo commented 3 weeks ago

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