MCPcopy Index your code
hub / github.com/CPChain/chain

github.com/CPChain/chain @v0.5.2

Chat with this repo
repository ↗ · DeepWiki ↗ · release v0.5.2 ↗ · + Follow
6,971 symbols 25,122 edges 521 files 4,228 documented · 61% updated 3y agov0.5.3-beta.0 · 2021-09-24★ 51
What it actually does AI analysis from the code graph — generated when you open this
loading…
README

The Cyber Physical Chain

Towards a trusted future with blockchain.

Website

License: GPL v3 Pull Requests

IoT is having a profound and unprecedented impact on human society. However, without trust, it is no more than a castle built on sand. You share the benefits, but with your privacy and financial safety as the cost.

For us, trust is of utmost concern. The mission of cpchain is to build a vital IoT ecosystem which is secured by the blockchain technology. Everyone can enjoy the convenience of M2M payment, self-driving, wearable monitoring, etc. to the fullest extent without worry.

We are shaping a trusted future with blockchain, from smart home to smart city, from edge to cloud computing, with you and with everyone! Please come and join us.
Follow Twitter

While the codebase has evovled much since the first commit, we owe a debt of thanks to go-ethereum for the initial codebase.

Table of Contents


Features

LBFT Consensus

We propose LBFT (Lightweight Byzantine Fault Tolerance), a two-phase algorithm aiming to achieve a fast consensus among the committee. The two phases are prepare and verification respectively.

In prepare phase, the leader of the committee member constructs a block and broadcasts to all members in the committee. Each committee member that receives the block is about to verify the block enters the verification phase. It signs a verified block, and broadcasts to other members. Once a member collects signatures from two thirds of committee members, it commits the block to the network. This two-phase process provides the robustness of our system when at most one third of committee members delay or act unexpectedly.

We further improve our LBFT algorithm to version 2.0, providing higher robust to achieve a consensus among the committee while retaining the properties of liveness and safety. The core ideas are bipartite committee and impeachment process.

The figure below illustrate the detailed steps of LBFT 2.0: LBFT 2.0

The bipartite committee refers to two separate committees, namely, the proposers committee and the validators committee. A Proposer is a node elected based on its reputation. It takes the responsibility of proposing a block and broadcasting to validators. All proposers of a certain term constitute the proposers committee.

Meanwhile, the validator committee consists of nodes nominated by CPC Foundation, governments and companies. Unlike proposers, validators cannot propose a block in normal cases. This committee validates a newly proposed block in three phases, similar to PBFT (Practical Byzantine Fault Tolerance). And it can also tolerate at most one third faulty or non-responding members.

This bipartite structure eliminates the role of the primary node of traditional PBFT protocol. In addition, it guarantees the independence of block proposal and validation, which decreases the risk and feasibility of byzantine faults.

To handle abnormal cases, we propose impeachment, a novel two-phase protocol assuring the properties of both liveness and safety in LBFT 2.0. When a validator suspects the proposer is faulty, it proposes an impeach block on behalf of the faulty proposer. The validators committee is about to achieve a consensus on this impeach block if a quorum of validators considers the proposer faulty.

Private Transactions

This feature can be enabled during compilation. Currently disabled on mainnet.

We design a data privacy mechanism that allows users to conduct private transactions on cpchain in a secure manner. Other than the valid participants, no one else has the ability to see the transaction. While private transactions are invisible for outsiders, we keep critical footprint of a transaction on chain for later audition.

A user scenario: private transaction user scenario


Installation

Download stable binaries

All versions of cpchain are built and available for download here.

The download page provides a zip file, containing the executable files that can be used without installing.

Building from source

Install latest distribution of Go if it has yet to be installed. Do not forget to configure $GOPATH. Then clone the repository to a directory that you'd like:

git clone https://bitbucket.org/cpchain/chain.git

Finally, build the programs using the following commands.

cd chain
make clear
make all

Quick Start

After installation, you are able to start running cpchain. Refer to ./build/bin/cpchain --help to check the help menu.

Connect to testnet

cd build/bin
./cpchain run --runmode testnet

Create an account

./cpchain account new --datadir ./datadir

Run a private network

cd examples/cpchain
./cpchain-all.sh

check logs
tail -f data/logs/*.log | grep number=

Run a local node

./cpchain run --datadir ./datadir --unlock <You Address>

Documentation

The above should be enough to get you up to speed. For details, please visit our documentation portal.


Tools and Libraries

CPChain Blockchain Explorer

Check our explorer and its website repository. It shows the ongoing transactions and blocks.


Contributing

Your hacks are always welcome!🔨🔨🔨

Please fork on bitbucket and make pull request there.


Contact

Shout to us at one of the following places!


License

Unless otherwise specified in the source files (or the vanilla files from go-ethereum), the licence by default is License: GPL v3

Copyright 2018-2025 © The CPChain Foundation

Extension points exported contracts — how you extend this code

Putter (Interface)
Putter wraps the database write operation supported by both batches and regular databases. [12 implementers]
database/interface.go
PrimitiveContract (Interface)
PrimitiveContract is the basic interface for native Go contracts. The implementation requires a deterministic gas count [16 …
core/vm/contracts.go
DatabaseReader (Interface)
DatabaseReader wraps the Has and Get method of a backing data store. [7 implementers]
core/rawdb/interfaces.go
Error (Interface)
Error wraps RPC errors, which contain an error code in addition to the message. [7 implementers]
api/rpc/types.go
TransactionSender (Interface)
TransactionSender wraps transaction sending. The SendTransaction method injects a signed transaction into the pending tr [5 …
interfaces.go
ChainBackend (Interface)
ChainBackend is the chain client operation interface [4 implementers]
consensus/dpor/backend/interface.go
ContractAPIbcakend (Interface)
(no doc) [57 implementers]
contracts/dpor/primitive_backend/primitive_backend.go
Service (Interface)
Service is an individual protocol that can be registered into a node. Notes: • Service life-cycle management is delega [4 …
node/service.go

Core symbols most depended-on inside this repo

Hash
called by 572
core/state/database.go
Debug
called by 506
commons/log/logger.go
Fatal
called by 382
cmd/cpchain/campaign/common/interfaces.go
Uint64
called by 338
types/block.go
Error
called by 337
cmd/cpchain/campaign/common/interfaces.go
Error
called by 273
api/rpc/types.go
Unlock
called by 267
accounts/keystore/keystore.go
NumberU64
called by 245
types/block.go

Shape

Method 3,600
Function 2,292
Struct 889
Interface 96
TypeAlias 61
FuncType 30
Route 2
Class 1

Languages

Go99%
Python1%
TypeScript1%

Modules by API surface

contracts/reward/reward.go239 symbols
contracts/pdash/pdash_contract/pdash.go199 symbols
contracts/dpor/campaign/campaign.go155 symbols
contracts/primitives_example/rpt/rpt.go150 symbols
contracts/dpor/rnode/rnode.go148 symbols
internal/cpcapi/api.go115 symbols
contracts/dpor/rpt/rpt.go103 symbols
core/blockchain.go87 symbols
types/block.go75 symbols
contracts/dpor/network/network.go73 symbols
core/vm/instructions.go72 symbols
contracts/pdash/pdash_contract/pdash_proxy.go68 symbols

For agents

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

⬇ download graph artifact