Skip to content
This repository has been archived by the owner on May 30, 2023. It is now read-only.

db / state initialized #9

Open
dubbelosix opened this issue May 3, 2023 · 0 comments
Open

db / state initialized #9

dubbelosix opened this issue May 3, 2023 · 0 comments
Assignees

Comments

@dubbelosix
Copy link

two storages: ledger, state. demo_app is currently using ledger slot number to determine if storage has been initialized or not

let mut item_numbers = ledger_db.get_next_items_numbers();
    if item_numbers.slot_number == 1 {
        print!("No history detected. Initializing chain...");
        demo.init_chain(());
        println!("Done.");
    } else {
        println!("Chain is already initialized. Skipping initialization.");
    }

problem with this is, if for some reason after initializing the ledger, sync fails (eg:

  • due to incorrect authentication token,
  • or because the light client is not running, has crashed etc),
    slot number will remain at 1 and when the demo rollup tries to start again, it ends up attempting to re-initialize the db and panics.
No history detected. Initializing chain...initializing runtime
thread 'main' panicked at 'called `Result::unwrap()` on an `Err` value: ModuleError(Token address already exists)', 
sov-modules/sov-app-template/src/lib.rs:88:14

I think using slot_number == 1 is not a good indication of is chain initialized / do we need to run init_chain.
(a trivial case is to run init_chain and check slot number - and it's still 1!)

we need a better check to know that the state is "initialized" because there can be any number of failures once chain is initialized and before slot number advances. or we can make init_chain fail gracefully if its called multiple times, but this still requires some notion of knowing the chain has been "initialized"

in the shorter term, I can also just catch_unwind and detect the condition, or it can be as simple as adding "nuke the db" to the instructions, since that ends up working. a better solution is to have something queryable that tells us if both ledger and state have been "initialized". could also just be a boolean flag, but might be overkill?

@preston-evans98 lmk wyt

since this is just a demo, we can also just add instructions

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant