parallelchain-io / pchain-runtime

Rust implementation of the ParallelChain protocol runtime: the component which executes transactions.
Apache License 2.0
0 stars 0 forks source link

pchain-runtime v0.5 #2

Open lyulka opened 1 year ago

lyulka commented 1 year ago

Summary of planning meeting (11 Sep 2023)

v0.5 will include two sets of changes:

  1. Changes to improve code organization, understandability, and overall “cleanliness”.
  2. Changes to make pchain-runtime support v0.5 of the protocol.

In today’s meeting, we discussed the changes we want to make to improve the cleanliness of the codebase.

Changes for cleanliness

  1. Combine all of the many variables tracking gas used into two (for calls) or one (for every other command) variables. (idea).
  2. Separate transaction lifecycle logic from command “business logic”.
  3. Stop using a "queue" to implement deferred commands.
  4. Organize folders and files better.

Idea for centralizing gas metering

We can define a GasMeter type which has methods to do each “gas-metered” operation.

struct GasMeter<'a> {
    gc: u64,
    ws: &'a mut WorldState,
    receipt: Vec<CommandReceipt>,
};

impl GasMeter {
    /* Every "gas-metered" operation features as a method. */
    fn sha256(&mut self, preimage: &[u8]) -> CryptoHash;
    fn account_balance(&mut self, addr: AsRef<PublicAddress>) -> u64;
    fn account_nonce(&mut self, addr: AsRef<PublicAddress>) -> u64;
    fn return_value(&mut self, command_index: u64);    

    /* Etc. */
}
lyulka commented 1 year ago

Summary of planning meeting (12 Sep 2023)

Changes for protocol v0.5

  1. Latest versions of pchain-runtime needs to be able to support all historical transition functions. Fullnode will select the version of the transition function that it wants to use for block at a particular height. The exact block height range a version is applicable in will be a user-configurable parameter that takes different values for Mainnet, Testnet, and other networks. Example interface:
fn transitionv04(transaction: TransactionV1, ws: WorldState, b_params: BlockchainParams) -> ReceiptV1;
fn transitionv05(transaction: TransactionV2, ws: WorldState, b_params: BlockchainParams) -> ReceiptV2;
  1. New gas constants for blockchain data (e.g., $G_{txincl}$) that reflect the larger size of ReceiptV2 over ReceiptV1.
  2. New gas formulas for MPT operations that do not “double charge” 32 bytes in the key length.
  3. New function for contract address which has command index as a parameter.

Pertinent design questions

  1. How to centralize gas metering.
  2. How to make multiple versions of the transition function available (what kind of interface).
  3. How to minimize code duplication in implementing multiple versions of the transition function.
lyulka commented 11 months ago

Summary of integration meeting (07 Nov 2023)

  1. Cast the reference to the WorldState up into a ‘static lifetime reference just before we need to pass it to Wasmer.
  2. Runtime should implement some kind of transition_v1_to_v2 function that executes the version upgrade next epoch transaction between protocol v0.4 and protocol v0.5. However, we’ve identified limitations in the World State interface that makes implementing this function difficult. The World State team will hold a meeting on Thursday (edit: Friday morning) to agree on a solution. @cy6581, please await the conclusions of this meeting before starting implementation of the transition_v1_to_v2 function in earnest.