Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Avoid calling TRANSMITTERS.keys to save some gas #17

Open
krebernisak opened this issue Dec 29, 2021 · 0 comments
Open

Avoid calling TRANSMITTERS.keys to save some gas #17

krebernisak opened this issue Dec 29, 2021 · 0 comments

Comments

@krebernisak
Copy link
Collaborator

@archseer suggested this part could possibly be refactored to save some gas.

Consider this snippet from contracts/ocr2/src/contract.rs:

    // validate new config
    require!(f != 0, InvalidInput);
    require!(signers_len <= MAX_ORACLES, TooManySigners);
    require!(transmitters.len() == signers.len(), InvalidInput);
    require!(3 * (usize::from(f)) < signers_len, InvalidInput);
    require!(onchain_config.is_empty(), InvalidInput);
    require!(!offchain_config.is_empty(), InvalidInput);

    let (_total, mut response) = pay_oracles(&mut deps, &config, response)?;
    // TODO: pay_oracles already loads all the transmitters, avoid calling TRANSMITTERS.keys

    // Clear out oracles
    let keys: Vec<_> = TRANSMITTERS
        .keys(deps.storage, None, None, Order::Ascending)
        .collect();
    for key in keys {
        TRANSMITTERS.remove(deps.storage, &to_addr(key));
    }
    let keys: Vec<_> = SIGNERS
        .keys(deps.storage, None, None, Order::Ascending)
        .collect();
    for key in keys {
        SIGNERS.remove(deps.storage, &key);
    }
@ghost ghost assigned archseer Dec 29, 2021
@aalu1418 aalu1418 transferred this issue from another repository Jan 3, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants