pchain_runtime/lib.rs
1/*
2 Copyright © 2023, ParallelChain Lab
3 Licensed under the Apache License, Version 2.0: http://www.apache.org/licenses/LICENSE-2.0
4*/
5
6//! ParallelChain Mainnet Runtime is a **State Transition Function** to transit from an input state of the blockchain to next state.
7//! It is also the sole system component to handle Smart Contract that is primarily built from Rust code by using
8//! ParallelChain Smart Contract Development Kit (SDK).
9//!
10//! ```text
11//! f(WS, BD, TX) -> (WS', R)
12//!
13//! WS = World state represented by set of key-value pairs
14//! BD = Blockchain Data
15//! TX = Transaction, which is essentially a sequence of Commands
16//! R = Receipt, which is a sequence of Command Receipts correspondingly.
17//! ```
18//!
19//! ### Example
20//!
21//! ```rust
22//! // prepare world state (ws), transaction (tx), and blockchain data (bd),
23//! // and call transition.
24//! let result = pchain_runtime::Runtime::new().transition(ws, tx, bd);
25//! ```
26//!
27//! In summary, a state [transition] function intakes Transaction, Blockchain and World State to [execute](execution),
28//! and output transition result which could be a success result or an [error]. The transition follows
29//! the data [types] definitions of ParallelChain Mainnet and the [formulas] in this library.
30//! When transiting the state by executing smart [contract], it uses [wasmer] as underlying WebAssembly runtime,
31//! which is gas-metered, and the [gas] [cost] incurred will be set to transaction receipt.
32
33#![cfg_attr(
34 feature = "cargo-clippy",
35 allow(clippy::new_without_default, clippy::result_large_err)
36)]
37
38pub mod contract;
39
40pub mod cost;
41
42pub mod error;
43pub use error::TransitionError;
44
45pub mod execution;
46
47pub mod formulas;
48
49pub mod gas;
50
51pub mod transition;
52pub use transition::{cbi_version, Runtime, TransitionResult, ValidatorChanges};
53
54pub mod types;
55pub use types::{BlockProposalStats, BlockchainParams, ValidatorPerformance};
56
57pub mod wasmer;
58pub use crate::wasmer::cache::Cache;
59
60pub mod read_write_set;