massa icon indicating copy to clipboard operation
massa copied to clipboard

Simplify and refactor final state initialization and checks on the DB after bootstrap.

Open Leo-Besancon opened this issue 1 year ago • 0 comments

  • remove the is_db_valid function completely
  • after the bootstrap of the db (or its initialization or loading from disk) is done, create final_state by passing it the db and letting it initialize all its subsystems in its constructor:
    • pos_state = PosState::try_from_db(&db).map_err(||e| format!("could not init PosState in FinalState: {}"), e)?;
    • async_pool = AsyncPool::try_from_db(&db).map_err(||e| format!("could not AsyncPool state in FinalState: {}"), e)?;
    • ... each of those constructors initializes the subsystem but also checks the db validity on the prefix subset(s) they manage

That way we have each module take responsibility for checking its own parts of the db properly and we reduce the error surface when adding new elements to the db (eg. forgetting to add them to is_db_valid).

Originally posted by @damip in https://github.com/massalabs/massa/pull/4197#discussion_r1257199516

Leo-Besancon avatar Jul 08 '23 09:07 Leo-Besancon