How oraichain/wasmd works
This project is Wasm Zone’s implementation of a Cosmos SDK-based blockchain that has native support for executing wasm smart contracts. It started as a fork of Gaia and incorporates an additional module (x/wasm) that enables smart contracts. In essence, the project is a full-fledged blockchain node application with its own command-line interface, consensus engine, module infrastructure, and integrated smart contract execution environment.
Main Components
• Node/Application Layer: The core of the blockchain (found in the “app” directory and “cmd/wasmd”). This includes the node’s initialization, configuration, command-line interfaces, and runtime flags.
• Modules:
• Core Cosmos SDK modules inherited from Gaia.
• The smart contract module “x/wasm” that adds CosmWasm capabilities.
• Additional modules like “x/tokenfactory” (see directory “x/tokenfactory”) for specialized functionalities.
• WASM Engine: The dependency “wasmvm” which is responsible for loading and executing smart contracts.
• API/CLI Components: Components for user interaction, transaction submission, and querying the blockchain state (visible in “cmd/config”, “cmd/keys.go”, and CLI commands under “x/wasm/client”).
• Database/State Storage: The underlying persistent state storage and genesis configuration (configured in “app/app.go” and related files) holding accounts, contracts, and proposals.
• Testing and Infrastructure: The extensive test suites (directories like “tests”, “benchmarks”, “scripts”, “docs”) that illustrate integration testing, migration, and chain orchestration processes.
• Integration with External Services: Docker-related files, CI configurations (.circleci, GitHub actions, etc.), and the protobuf definitions (in the “proto” directory) that facilitate integration with external tools and clients.
Relationships and Interactions
• The node/application layer (wasmd) is responsible for managing blockchain consensus and invoking module-specific logic (including x/wasm).
• The x/wasm module interacts with the wasmvm runtime to load, validate, and execute smart contracts, passing along encoded JSON messages (with support from the cosmos-sdk encoding layer).
• API/CLI interfaces enable users to submit transactions, query state, and trigger smart contract executions.
• The genesis configuration and runtime parameters set initial conditions and allow for upgrades (see “app/upgrades” and “INTEGRATION.md”), which creates dependencies between the main application and upgrade mechanisms.
• The testing suites simulate end-to-end scenarios including IBC, governance proposals, and interchain testing (in “tests/e2e”, “tests/ibctesting”, “tests/system”, etc.), thereby showing the interactions between on-chain modules and external clients.
Architectural Patterns and Design Principles
• Modularity: The design adheres to the typical Cosmos SDK architecture, where individual modules (like x/wasm, x/tokenfactory) plug into a common application.
• Plugin/Extension: The wasm execution environment (imported via wasmvm) acts as an extension point for contract execution.
• Separation of concerns: There is a clear distinction between the core blockchain logic, application state management, smart contract execution, and auxiliary tools/scripts.
• Integration through Protobuf: The use of protobuf files (located in the “proto” directory) ensures that components (internal modules and external clients) maintain a clear, versioned communication protocol.