Skip to content

mod-net/module-pallet

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Mod-Net Module Registry

License Build Status codecov Documentation

A production-grade decentralized module registry built on Substrate with IPFS integration for secure, distributed metadata storage.

🌟 Features

  • Multi-chain Module Registry: Manage modules across different blockchain networks
  • IPFS-Powered Storage: Decentralized metadata storage using IPFS
  • Type-safe Python Client: Easy integration with existing Python projects
  • Production-Ready: Comprehensive CI/CD, testing, and documentation
  • Modular Architecture: Extensible design for custom implementations

🏗️ Architecture

graph TD
    A[Module Registry Pallet] -->|Stores| B[(IPFS CIDs)]
    C[Python Client] -->|Interacts with| A
    C -->|Manages| B
    D[Frontend] -->|Uses| C
    E[External Services] -->|Integrates with| A
Loading

Core Components

  1. Module Registry Pallet

    • On-chain storage for module metadata references
    • Multi-chain public key support
    • Efficient storage using IPFS CIDs
  2. IPFS Integration

    • Distributed metadata storage
    • Content-addressable architecture
    • Off-chain data availability
  3. Python Client

    • Type-safe API client
    • Asynchronous operations
    • Comprehensive error handling

Prerequisites

  • Rust (latest stable, install via rustup)
  • Python 3.10+
  • IPFS daemon (installation guide)
  • Substrate dependencies:
    curl https://getsubstrate.io -sSf | bash -s -- --fast

Quick Start

  1. Clone the repository

    git clone --recursive https://github.com/Bakobiibizo/mod-net-modules.git
    cd mod-net-modules/modules
  2. Build the node

    cargo build --release
  3. Set up Python environment

    # Using standard venv
    python -m venv .venv
    source .venv/bin/activate  # On Windows: .venv\Scripts\activate
    
    # Install development dependencies
    pip install -r requirements-dev.txt
    
    # Alternative: Using uv (faster)
    # pip install uv
    # uv venv
    # source .venv/bin/activate
    # uv pip install -r requirements-dev.txt
  4. Start IPFS daemon

    ipfs daemon
  5. Run the node

    ./target/release/node-template --dev

📚 Documentation

🤝 Contributing

We welcome contributions! Please see our Contributing Guide for details.

  1. Fork the repository
  2. Create your feature branch (git checkout -b feature/AmazingFeature)
  3. Commit your changes (git commit -m 'Add some AmazingFeature')
  4. Push to the branch (git push origin feature/AmazingFeature)
  5. Open a Pull Request

📜 License

This project is licensed under the MIT-0 License - see the LICENSE file for details.

📬 Contact

Project Link: https://github.com/Bakobiibizo/mod-net-modules

🙏 Acknowledgments

Getting Started

Prerequisites

Development Environment

  1. Clone and Build

    git clone --recursive https://github.com/your-org/mod-net.git
    cd mod-net/modules
    cargo build --release
  2. Python Environment Setup

    uv venv
    source .venv/bin/activate
    uv pip install -r requirements.txt
  3. IPFS Setup

    # Start IPFS daemon
    ipfs daemon
    # Default endpoints:
    # - API: http://localhost:5001
    # - Gateway: http://localhost:8080

Fetch solochain template code:

git clone https://github.com/paritytech/polkadot-sdk-solochain-template.git solochain-template

cd solochain-template

Development Workflow

Quality Standards

  • No TODOs, placeholders, or mock implementations
  • All code must be production-ready with thorough testing
  • Type hints and documentation required for all code
  • Strict adherence to code formatting and linting rules

Git Workflow

  1. Branch Naming

    • Features: feature/descriptive-name
    • Fixes: fix/issue-description
    • Documentation: docs/topic-name
  2. Commit Messages Follow the Conventional Commits standard:

    type(scope): description
    
    [optional body]
    [optional footer]
    

Testing

  1. Rust Tests

    # Run all Rust tests
    cargo test --all
    # Run specific pallet tests
    cargo test -p pallet-module-registry
  2. Python Tests

    # Run Python tests with coverage
    pytest tests/ --cov=mod_net_client
  3. Integration Tests

    # Ensure IPFS daemon is running
    ./scripts/run-integration-tests.sh

Code Quality

  1. Rust

    # Format code
    cargo fmt --all
    # Run clippy
    cargo clippy --all-targets --all-features
  2. Python

    # Format code
    black mod_net_client tests
    isort mod_net_client tests
    # Run linters
    ruff check mod_net_client tests
    mypy mod_net_client tests

Documentation

After you build the project, you can use the following command to explore its parameters and subcommands:

./target/release/solochain-template-node -h

You can generate and view the Rust Docs for this template with this command:

cargo +nightly doc --open

Single-Node Development Chain

The following command starts a single-node development chain that doesn't persist state:

./target/release/solochain-template-node --dev

To purge the development chain's state, run the following command:

./target/release/solochain-template-node purge-chain --dev

To start the development chain with detailed logging, run the following command:

RUST_BACKTRACE=1 ./target/release/solochain-template-node -ldebug --dev

Development chains:

  • Maintain state in a tmp folder while the node is running.
  • Use the Alice and Bob accounts as default validator authorities.
  • Use the Alice account as the default sudo account.
  • Are preconfigured with a genesis state (/node/src/chain_spec.rs) that includes several pre-funded development accounts.

To persist chain state between runs, specify a base path by running a command similar to the following:

// Create a folder to use as the db base path
$ mkdir my-chain-state

// Use of that folder to store the chain state
$ ./target/release/solochain-template-node --dev --base-path ./my-chain-state/

// Check the folder structure created inside the base path after running the chain
$ ls ./my-chain-state
chains
$ ls ./my-chain-state/chains/
dev
$ ls ./my-chain-state/chains/dev
db keystore network

Connect with Polkadot-JS Apps Front-End

After you start the node locally, you can interact with it using the hosted version of the Polkadot/Substrate Portal front-end by connecting to the local node endpoint. Note: WebSocket uses the same RPC port as HTTP (defaults to 9933), there is no separate WS port. A hosted version is also available on IPFS. You can also find the source code and instructions for hosting your own instance in the polkadot-js/apps repository.

Multi-Node Local Testnet

If you want to see the multi-node consensus algorithm in action, see Simulate a network.

Project Architecture

The Mod-Net module registry consists of several key components:

Module Registry Pallet

The core Substrate pallet (pallet-module-registry) provides:

  • On-chain module registration and verification
  • Module metadata management with IPFS integration
  • Version control and dependency tracking
  • Access control and permissions

IPFS Integration

The commune-ipfs submodule provides:

Python Client

The mod_net_client package provides:

  • Type-safe interface to the module registry
  • IPFS metadata management
  • Substrate RPC interaction
  • Comprehensive test suite

Node

A blockchain node is an application that allows users to participate in a blockchain network. Substrate-based blockchain nodes expose a number of capabilities:

  • Networking: Substrate nodes use the libp2p networking stack to allow the nodes in the network to communicate with one another.
  • Consensus: Blockchains must have a way to come to consensus on the state of the network. Substrate makes it possible to supply custom consensus engines and also ships with several consensus mechanisms that have been built on top of Web3 Foundation research.
  • RPC Server: A remote procedure call (RPC) server is used to interact with Substrate nodes.

There are several files in the node directory. Take special note of the following:

  • chain_spec.rs: A chain specification is a source code file that defines a Substrate chain's initial (genesis) state. Chain specifications are useful for development and testing, and critical when architecting the launch of a production chain. Take note of the development_config and testnet_genesis functions. These functions are used to define the genesis state for the local development chain configuration. These functions identify some well-known accounts and use them to configure the blockchain's initial state.
  • service.rs: This file defines the node implementation. Take note of the libraries that this file imports and the names of the functions it invokes. In particular, there are references to consensus-related topics, such as the block finalization and forks and other consensus mechanisms such as Aura for block authoring and GRANDPA for finality.

Runtime

The Mod-Net runtime extends the Substrate runtime with our custom module registry pallet. Key features include:

  • Module registration and verification logic
  • IPFS CID storage and validation
  • Access control and permissions management
  • Version control and dependency resolution The Substrate project in this repository uses FRAME to construct a blockchain runtime. FRAME allows runtime developers to declare domain-specific logic in modules called "pallets". At the heart of FRAME is a helpful macro language that makes it easy to create pallets and flexibly compose them to create blockchains that can address a variety of needs.

Review the FRAME runtime implementation included in this template and note the following:

  • This file configures several pallets to include in the runtime. Each pallet configuration is defined by a code block that begins with impl $PALLET_NAME::Config for Runtime.
  • The pallets are composed into a single runtime by way of the #[runtime] macro, which is part of the core FRAME pallet library.

CI/CD Pipeline

Comprehensive GitHub Actions workflows ensure code quality:

  1. Rust CI (rust.yml)

    • Cargo check and build
    • Clippy linting
    • Documentation generation
    • Unit and integration tests
  2. Python CI (python.yml)

    • Black and isort formatting
    • Ruff and mypy linting
    • Unit tests with coverage
    • Type checking
  3. Integration Tests (integration.yml)

    • IPFS service container
    • Combined Rust/Python testing
    • End-to-end workflow validation

A FRAME pallet is comprised of a number of blockchain primitives, including:

  • Storage: FRAME defines a rich set of powerful storage abstractions that makes it easy to use Substrate's efficient key-value database to manage the evolving state of a blockchain.
  • Dispatchables: FRAME pallets define special types of functions that can be invoked (dispatched) from outside of the runtime in order to update its state.
  • Events: Substrate uses events to notify users of significant state changes.
  • Errors: When a dispatchable fails, it returns an error.

Each pallet has its own Config trait which serves as a configuration interface to generically define the types and parameters it depends on.

Alternatives Installations

Instead of installing dependencies and building this source directly, consider the following alternatives.

Nix

Install nix and nix-direnv for a fully plug-and-play experience for setting up the development environment. To get all the correct dependencies, activate direnv direnv allow.

Docker

Please follow the Substrate Docker instructions here to build the Docker container with the Substrate Node Template binary.

About

Module registry for Mod-Net including off chain IPFS storage worker and off chain client for it

Resources

License

Contributing

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Contributors 7