How brighter47/canopy works
Purpose and Runtime Entry Points
Canopy is the Go reference implementation of the Canopy Network Protocol: a recursive blockchain framework plus seed chain. The node binary starts at cmd/main/main.go; command-line administration and queries are in cmd/cli/cli.go, cmd/cli/admin.go, and cmd/cli/query.go. The runtime is primarily Go 1.21, with a TypeScript browser wallet and explorer served independently from the node.
Node Orchestration
The controller is the central coordination boundary between networking, consensus, transaction handling, state transitions, and persistence. It owns block/consensus coordination and routes node-level work rather than embedding domain rules itself.
• controller/controller.go
• controller/consensus.go
• controller/block.go
Primary flow: P2P-delivered transactions and consensus messages enter controller-managed paths; accepted blocks are executed through the FSM and committed to storage.
Deterministic State Machine
The FSM defines consensus-critical validation and state mutation. It handles accounts, validators/committees, governance, DEX and swaps, Ethereum-oriented functionality, events, genesis, and transaction/message interpretation. State logic must remain deterministic because every validator executes it for the same block.
• fsm/state.go
• fsm/transaction.go
• fsm/automatic.go
• fsm/gov.go
• fsm/dex.go
BFT Consensus Pipeline
The BFT package implements proposer selection/election, proposals, votes, evidence, and consensus messages. It produces agreement on a block before the controller applies its state transition; evidence represents the fault-handling boundary for Byzantine behavior.
• bft/bft.go
• bft/election.go
• bft/prop.go
• bft/vote.go
• bft/evidence.go
P2P Transport and Cryptographic Boundary
Nodes discover and maintain peers, exchange protocol messages, and encrypt connections through the P2P subsystem. Cryptographic identity, signatures, key storage, hashing, BLS, secp256k1/Ed25519, and Ethereum secp256k1 support sit in shared library code. P2P supplies the distributed transport; consensus and controller own message semantics.
• p2p/p2p.go
• p2p/conn.go
• p2p/encrypt.go
• lib/crypto/key.go
• lib/crypto/keystore.go
Persistence, Data Models, and Wire Contracts
Storage maintains versioned chain state, sparse Merkle-tree verification, transactional updates, and historical indexing. Shared lib types cover blocks, transactions, certificates, configuration, peers, mempool, and plugin contracts. Protobuf definitions are the canonical cross-package/wire schema source, with generated Go bindings checked in.
• store/versioned_store.go
• store/smt.go
• store/indexer.go
• lib/.proto/tx.proto
• lib/.proto/consensus.proto
External Interfaces: RPC, UIs, and Plugins
The RPC server exposes query, administration, Ethereum-facing, and client routes over server/socket layers. Two TypeScript/Vite applications consume node-facing APIs: an explorer and a wallet. The wallet contains a manifest-driven declarative action engine that renders forms and submits action workflows. Plugin SDKs let independently implemented chain/plugin logic communicate through protobuf/RPC contracts in Go, C#, Kotlin, Python, or TypeScript.
• cmd/rpc/server.go
• cmd/rpc/routes.go
• cmd/rpc/eth.go
• cmd/rpc/web/wallet/src/actions/ActionRunner.tsx
• cmd/rpc/web/explorer/src/lib/api.ts
• plugin/go/contract/plugin.go
Deployment and Automation
Docker Compose provides a multi-node local network with per-node genesis, validator keys, keystores, and persisted state fixtures. Auto-update is a separate Go service with language-specific container images for plugin release/update coordination.
• .docker/compose.yaml
• .docker/volumes/node_1/genesis.json
• .docker/volumes/node_1/validator_key.json
• cmd/auto-update/main.go
Main entry points: controller.go Controller · server.go RPC server · bft.go BFT consensus · state.go Deterministic FSM
Components 19
Node Runtime
- Node binary
cmd/main/main.go - CLI · Runs node administration and query commands.
cmd/cli/cli.go - Controller · Routes networking, consensus, block, and state work.
controller/controller.go - Block coordination
controller/block.go
Protocol Core
- BFT consensus · Elects proposers and processes proposals, votes, and evidence.
bft/bft.go - P2P transport · Discovers peers and exchanges protocol messages.
p2p/p2p.go - Cryptography · Provides identities, keys, signatures, hashes, and curves.
lib/crypto/key.go - Deterministic FSM · Consensus-critical transaction validation and state mutation.
fsm/state.go - Governance and DEX
fsm/gov.go - Versioned store · Maintains versioned state and transactional commits.
store/versioned_store.go - SMT and indexer · Verifies sparse Merkle state and indexes history.
store/smt.go - Protobuf contracts · Canonical schemas for transactions and consensus messages.
lib/.proto/tx.proto - Shared protocol types · Defines blocks, transactions, certificates, peers, and plugin contracts.
External Interfaces
- RPC server · Exposes query, administration, client, and Ethereum-facing routes.
cmd/rpc/server.go - Browser wallet · Renders manifest-driven actions and submits workflows.
cmd/rpc/web/wallet/src/actions/ActionRunner.tsx - Block explorer · Consumes node-facing APIs.
cmd/rpc/web/explorer/src/lib/api.ts - Plugin SDKs · Lets external chain and plugin implementations use protobuf/RPC contracts.
plugin/go/contract/plugin.go
Deployment
- Local multi-node network · Provides genesis, validator keys, keystores, and persistent fixtures.
.docker/compose.yaml - Auto-update service · Coordinates language-specific plugin releases and updates.
cmd/auto-update/main.go
Connections 21
- Node binary → Controller: starts
- CLI → RPC server: admin and query
- Controller → Block coordination: coordinates
- P2P transport → Controller: transactions and messages
- Controller → BFT consensus: drives agreement
- BFT consensus → Block coordination: agreed block
- Block coordination → Deterministic FSM: executes block
- Deterministic FSM → Governance and DEX: applies domain rules
- Deterministic FSM → Versioned store: commits state
- Versioned store → SMT and indexer: verifies and indexes
- P2P transport → Cryptography: encrypted identities
- BFT consensus → Cryptography: signatures
- BFT consensus → Protobuf contracts: consensus schema
- Deterministic FSM → Shared protocol types: blocks and transactions
- RPC server → Controller: node operations
- RPC server → Versioned store: queries
- Browser wallet → RPC server: API calls
- Block explorer → RPC server: API calls
- Plugin SDKs → Protobuf contracts: protobuf/RPC contracts
- Auto-update service → Plugin SDKs: plugin releases
- Local multi-node network → Node binary: runs validator nodes