MCPcopy Index your code
hub / github.com/Phala-Network/phala-blockchain

github.com/Phala-Network/phala-blockchain @poc3-1.2.2

Chat with this repo
repository ↗ · DeepWiki ↗ · release poc3-1.2.2 ↗ · + Follow
4,761 symbols 14,320 edges 436 files 1,024 documented · 22% updated 54d agonightly-2024-07-30 · 2024-07-30★ 37177 open issues
What it actually does AI analysis from the code graph — generated when you open this
loading…
README

Phala Blockchain

Funded by the web3 foundation

Rust

Phala Network is a TEE-Blockchain hybrid architecture implementing Confidential Contract. This repo includes:

  • node/: the main blockchain built on Substrate
  • phost/: the bridge daemon to connect the blockchain and pRuntime

Overview

The blockchain is the central compoent of the system. It records commands (confidential contract invocation), serve as the pRuntime registray, runs the native token and on-chain governance modules.

pHost is a daemon program that connects the blockchain and the pRuntime. It passes the block data from the chain to pRuntime and passes pRuntime side effects back to the chain.

Related repos:

  • phala-docs: The central repo for documentations.
  • phala-pruntime: The cotract executor running inside TEE enclaves.
  • phala-polka-apps: The Web UI and SDK to interact with confidential contract. Based on polkadot.js.
  • plibra-grant-docker: The W3F M2 docker build with the blockchain, pHost and pRuntime.

File structure

.
├── LICENSE
├── README.md
├── node                      Blockchain node
├── pallets
│   └── phala                 Phala pallet
├── phost                     The bridge deamon "pHost"
├── pruntime                  pRuntime, the TEE kernel
├── ring                      Patched ring with wasm support
├── runtime                   Phala Substrate Runtime
└── scripts
    ├── console.sh            Helper script to build & run the blockchain
    └── init.sh

Docker bulid

Plase refer to plibra-grant-docker. It includes both the blockchain and pRuntime.

Native Build

Dependencies

Expand

  • Rust

bash curl https://sh.rustup.rs -sSf | sh

  • Substrate dependecies:

bash cd node sh ./scripts/init.sh

  • LLVM 10

bash wget https://apt.llvm.org/llvm.sh chmod +x llvm.sh ./llvm.sh 10

Build the blockchain and bridge

Make sure you have Rust and LLVM-10 installed.

cargo build --release

The build script enforces LLVM-9 or newer is used. LLVM-9 is needed because of the wasm port of rust crypto library, ring. We have to compile the C code into wasm while keeping the compatibility with the current rustc.

Run

  1. Launch two local dev nodes Alice and Bob:

    bash cd node ./scripts/console.sh start alice ./scripts/console.sh start bob

    • The datadir is at $HOME/tmp/(alice|bob)
    • Can be purged by ./scripts/console.sh purge
    • The WebUI can connect to Alice at port 9944.
  2. Run pHost (please start pRuntime first):

    bash cd phost ./target/release/phost

Run with tmuxp

You can launch the full stack (semi-automatically) by:

tmuxp load ./scripts/tmuxp/three-nodes.yaml

Or a 4-node testnet-poc2 setup:

CHAIN=poc2 tmuxp load ./scripts/tmuxp/four-nodes.yaml

tmuxp is a convinient tool that can bring up a tmux session with the preconfigured commands running in panes. To play with tmuxp, it also need a tmux installed.

Extension points exported contracts — how you extend this code

Sealed (Interface)
Traits that are designed to only be implemented internally in *ring*. Usage: ``` use crate::sealed; pub trait MyType: [7 …
ring/src/lib.rs
Deserialize (Interface)
A **data structure** that can be deserialized from any data format supported by Serde. Serde provides `Deserialize` imp [42 …
serde_no_std/src/de/mod.rs
Index (Interface)
A type that can be used to index into a `serde_json::Value`. The [`get`] and [`get_mut`] methods of `Value` accept any [6 …
serde_json_no_std/src/value/index.rs
Trait (Interface)
Configure the pallet by specifying the parameters and types on which it depends. [44 implementers]
pallets/phala/src/lib.rs
Runtime (Interface)
Runtime trait. [5 implementers]
subxt/src/runtimes.rs
Resp (Interface)
(no doc) [6 implementers]
phost/src/types.rs
TransportClient (Interface)
Objects that can act as clients. > **Note**: Implementations of this trait are allowed (and encouraged, for example for [4 …
jsonrpsee/src/transport/client.rs
Trait (Interface)
(no doc) [8 implementers]
pallets/staking/src/lib.rs

Core symbols most depended-on inside this repo

map
called by 344
subxt/src/metadata.rs
clone
called by 341
pruntime/csv-core/src/writer.rs
len
called by 332
serde_json_no_std/src/map.rs
get
called by 300
pruntime/app/src/main.rs
clone
called by 253
subxt/src/lib.rs
into
called by 227
ring/src/io/writer.rs
push
called by 149
jsonrpsee/src/raw/server/core.rs
insert
called by 127
serde_json_no_std/src/map.rs

Shape

Method 1,875
Function 1,863
Class 733
Enum 194
Interface 95
Struct 1

Languages

Rust96%
C2%
TypeScript1%
Python1%
Go1%
C++1%

Modules by API surface

serde_no_std/src/private/de.rs116 symbols
pallets/staking/src/tests.rs110 symbols
serde_json_no_std/tests/test.rs103 symbols
serde_json_no_std/src/ser.rs102 symbols
ring/src/ec/suite_b/ops.rs96 symbols
serde_derive_no_std/src/internals/attr.rs89 symbols
ring/src/arithmetic/bigint.rs89 symbols
serde_json_no_std/src/de.rs83 symbols
pallets/staking/src/lib.rs75 symbols
pruntime/csv-core/src/reader.rs71 symbols
serde_json_no_std/src/value/de.rs64 symbols
serde_derive_no_std/src/de.rs62 symbols

For agents

$ claude mcp add phala-blockchain \
  -- python -m otcore.mcp_server <graph>

⬇ download graph artifact

Ask about this repo answers extend the page