Crate pchain_runtime
source ·Expand description
ParallelChain Mainnet Runtime is a State Transition Function to transit from an input state of the blockchain to next state. It is also the sole system component to handle Smart Contract that is primarily built from Rust code by using ParallelChain Smart Contract Development Kit (SDK).
f(WS, BD, TX) -> (WS', R)
WS = World state represented by set of key-value pairs
BD = Blockchain Data
TX = Transaction, which is essentially a sequence of Commands
R = Receipt, which is a sequence of Command Receipts correspondingly.
§Example
// prepare world state (ws), transaction (tx), and blockchain data (bd),
// and call transition.
let result = pchain_runtime::Runtime::new().transition(ws, tx, bd);
In summary, a state transition function intakes Transaction, Blockchain and World State to execute, and output transition result which could be a success result or an error. The transition follows the data types definitions of ParallelChain Mainnet and the formulas in this library. When transiting the state by executing smart contract, it uses wasmer as underlying WebAssembly runtime, which is gas-metered, and the gas cost incurred will be set to transaction receipt.
Re-exports§
pub use error::TransitionError;
pub use transition::cbi_version;
pub use transition::Runtime;
pub use transition::TransitionResult;
pub use transition::ValidatorChanges;
pub use types::BlockProposalStats;
pub use types::BlockchainParams;
pub use types::ValidatorPerformance;
pub use crate::wasmer::cache::Cache;
Modules§
- Defines types and functions that provide a convenient and succinct object-oriented interface for loading, deploying, getting information about, and executing (WASM) smart contracts.
- Defines a struct CostChange for gas counting.
- Defines TransitionError which is set of error definitions in state transitions.
- Implementation of state transition functions.
- Defines constants and formulas which are used in
pchain_runtime
. - Defines formulas in calculation of gas which is a measurement unit for transaction execution. The constants and functions in module follow the content in gas section of the Parallelchain Mainnet Protocol.
- Defines a struct that serves as a cache layer on top of World State.
- Implementation of state transition function.
- Defines common data structures to be used inside this library, or from outside application.
- Defines structs and functions to utilize wasmer as smart contract execution environment.