parallelchain-io / parallelchain-protocol

Specification for the ParallelChain (and ParallelChain Mainnet) blockchain protocols.
https://parallelchain.io
1 stars 1 forks source link

Pchain_WorldStatate_0.5: Meeting Conclusion #22

Closed ZUOYANGDING closed 10 months ago

ZUOYANGDING commented 10 months ago

Date 09/05

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

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)

image

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)

image

Remove the Cache, and move it into the crate runtime. When flush the Cache, just update the Mpt of AccountTrie/List\<StorageTrie>

lyulka commented 10 months ago

Discussion moved to parallelchain-io/pchain-world-state#1