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

IBC: refactor for typed storage #1445

Closed
Tracked by #2021
cwgoes opened this issue May 22, 2023 · 0 comments · Fixed by #2062
Closed
Tracked by #2021

IBC: refactor for typed storage #1445

cwgoes opened this issue May 22, 2023 · 0 comments · Fixed by #2062
Assignees

Comments

@cwgoes
Copy link
Collaborator

cwgoes commented May 22, 2023

We should create helper functions to ensure that we never write values of the wrong type to particular storage keys, and we should avoid mingling code which handles logic and code which handles serialisation.

For example (from shared/src/ledger/ibc/mod.rs)

    // the client counter
    let key = client_counter_key();
    let value = 0_u64.to_be_bytes().to_vec();
    storage
        .write_bytes(&key, value)
        .expect("Unable to write the initial client counter");

This should be refactored into (in some appropriate file):

pub fn write_client_counter(value: u64) {
    let key = client_counter_key();
    let value = value.to_be_bytes().to_vec();
    storage
        .write_bytes(&key, value.to_be_bytes())
        .expect("Unable to write the client counter");
}

such that the original code needs to be only

ibc_storage::write_client_counter(0_u64);

Does this make sense? We should apply this pattern generally, starting with the IBC code.

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

Successfully merging a pull request may close this issue.

2 participants