Target: Understand the current code, and propose idea about refactoring the arch in world_state
Current work flow when produce block :
1. Read the parent_block to open the current world state
2. start a loop to execute transactions until current block is full or approach time limit
Fullnode part:
1. get transaction from Mempool
Runtime part:
2. run commands in this transaction
3. write each result of commands into WorldState.Cache
4. if transaction success
flush the WorldState.Cache into MPT.KeyspacedInstrumentedDB.write_set
recompute the state_hash
insert update from WorldState.Cache into MPT by TrieDB
store the change into MPT.KeyspacedInstrumentedDB.write_set
else
clear WorldState.Cache
5. run next transaction
Fullnode part:
6. call commit_and_close to get the MPT.KeyspacedInstrumentedDB.write_set and updated state_hash
7. use the the updates from step 6 to build AppUpdateState for hotstuff to write the change into physical memory
Date 09/05
Target: Understand the current code, and propose idea about refactoring the arch in world_state
Current work flow when produce block :
Current structs:
struct WorldState(Mpt, Cache) struct AccountStorageState(PublicAddress, Mpt) struct Cache(<key, value>, <PublicAddress, <key, value>>) struct Mpt(KeyspacedInstrumentedDB, state_hash) struct KeyspacedInstrumentedDB(write_set, storage, TrieLevel)
AccountStorageState created/init inside WorldState, WorldState depends Mpt, Mpt depends on KeyspacedInstrumentedDB
Proposed structs:
struct WorldState(AccountTrie, List\<StorageTrie>) struct AccountTrie(Mpt) struct StorageTrie(Mpt) struct Mpt(InstrumentDB, state_hash) struct InstrumentDB(write_set, storage)
Remove the Cache, and move it into the crate runtime. When flush the Cache, just update the Mpt of AccountTrie/List\<StorageTrie>