____ _ _
| __ ) __ _ ___ ___ __| |_ __ ___ __| | ___
| _ \ / _` / __|/ _ \/ _` | '_ \ / _ \ / _` |/ _ \
| |_) | (_| \__ \ __/ (_| | | | | (_) | (_| | __/
|____/ \__,_|___/\___|\__,_|_| |_|\___/ \__,_|\___|
Subbstrate-Based Blockchain Node for AI-Lead Consensus in Service of the BASED GOD
Basednode is a specialized Substrate-based blockchain node that forms the core substrate-chain of BasedAI’s ecosystem. It integrates robust consensus mechanisms, sophisticated delegation models, AI-driven network management ("brains"), staking logic. The node code is structured as a FRAME-based Substrate runtime, making it easy to extend, customize, and integrate into larger decentralized applications or AI-powered distributed networks.
The node is designed to:
- Manage Agents and Delegates: Provides comprehensive agent management—both “full” and “lite” agent information retrieval—enabling validators, nominators, delegates, and end-users to seamlessly interact with the network.
- Support AI-Oriented ‘Brain’ Networks: Allows multiple AI “brains” (sub-networks) with customizable hyperparameters, difficulty, and emission configurations. “Brains” represent specialized sub-chains or functionalities, potentially integrating machine learning/AI logic.
- Enable Value Transfer and Staking: Implements token issuance, emission distribution, staking, and delegation logic. Supports flexible stake management with personal and compute keys, enabling secure delegation and dynamic reassignments.
- Provide Rich RPC and Runtime APIs: Offers a well-structured RPC layer and runtime APIs for querying delegates, agents, stake info, brain hyperparameters, and TFT enforcement data, ensuring easy external integration (e.g., dashboards, explorers, orchestration tools).
The fastest blockchain in the world is quickly surpassed by one that can constantly reinvent itself. In BasedAI, that self-improvement is driven by Agent Compute Contracts (ACCs)—units of work that miners produce not just as theoretical proposals, but as actionable code ready for integration in BasedAI. This creates competitive arena for agents: as ACCs are accepted, they refine and expand BasedAI’s own codebase, pushing performance, scalability, and feature evolution forward at an unprecedented pace.
-
Raw Data to Actionable Code: Miners capture real-time data streams from open networks—ranging from public code repositories and research platforms to global market sentiment. They transform these insights into ACCs that contain concrete code enhancements or entirely new features.
-
Decentralized Validation & Integration: The BasedAI ecosystem, supported by a network of “Brains” and advanced AI agents, evaluates each ACC. High-value contributions—such as performance optimizations, novel consensus mechanisms, or improved developer tooling—are integrated into the codebase upon acceptance.
-
Reward Pool and Incentivized Growth: A dedicated reward pool, managed by BasedAI, has been allocated to continually incentivize development. Each successfully integrated ACC grants its contributing miner an allocation of $BASED tokens from this pool. By directly tying payouts to the tangible enhancement of the network, BasedAI ensures that contributors remain strongly motivated to submit valuable code.
-
Rapid Iteration and Acceleration: Over time, these iterative improvements compound, ensuring that BasedAI doesn’t just keep pace with other blockchains, but outstrips them in capability. As the platform grows faster, smarter, and more feature-rich, it sets a self-sustaining cycle of innovation in motion. The result is a blockchain that evolves at a rate determined not by a single team, but by a global, decentralized collective of problem-solvers and innovators.
This feedback loop in the agent arena, powered by ACCs and fueled by a well-managed reward pool, ensures that BasedAI can adapt, optimize, and expand its capabilities far more quickly than any traditional development process. Instead of waiting for periodic updates, the community is continually incentivized to discover and integrate the next breakthrough—making BasedAI a living, ever-advancing ecosystem.
- Multiple Networks (BrainN): The node supports multiple parallel networks or “brains” (networks identified by
netuid
). Each brain can have its own parameter set—tempo, difficulty, max allowed UIDs, validators, emission values, etc. - Hyperparameters & Brain Info: Retrieve and modify per-network parameters such as difficulty, scaling factors (
kappa
,rho
), burn requirements, and emission rates.BrainInfo
andBrainHyperparams
structures encapsulate full network details and control parameters. - Dynamic Registration & Difficulty: The system adjusts registration difficulty and burn cost based on network load and target registration rates, maintaining equilibrium. Mechanisms like
adjust_difficulty()
andadjust_burn()
dynamically tune these parameters to ensure a stable and fair environment.
- Epoch-Based Emission Calculations: Each epoch processes weights, trust, consensus scores, and bond matrices to determine validator/server rewards. Emission distribution is handled through
block_step()
logic andepoch()
calculations. - Sparse and Dense Matrix Operations: The network’s consensus algorithm involves complex matrix multiplications, trust score calculations, and emission distributions. Performance optimizations (e.g., sparse matrix handling) ensure scalability.
- Rate Limits and Pruning: Implements rate limiting for registrations and serving endpoints. Also supports pruning logic to remove underperforming or inactive agents, maintaining a healthy validator set.
- Staking Mechanisms: Stake tokens on personal and compute keys, track total stake globally, and manage stake distribution efficiently. Stakers can add or remove stake as conditions or strategies change.
- Delegation and Delegate Info: Become a delegate to receive stake from nominators. Delegates set “take” rates and earn emissions based on total stake and performance.
DelegateInfo
provides detailed metrics, such as return_per_1000, daily returns, and validator permits. - Emission and Inflation Control: The system carefully manages emissions through an integrated token model. Emission distribution accounts for delegates, validators, personal keys, and server nodes, balancing incentives and network stability.
- Burn-Based Registrations: Besides PoW, agents can register by burning tokens. Difficulty and burn parameters adjust over time, ensuring a stable and economically sound onboarding process.
- RPC Layer: A comprehensive RPC interface (JSON-RPC) exposed via
get_delegates
,get_agent
,get_stake_info_for_personalkey
,get_brain_info
, and more. Each returns serialized data (e.g.,Vec<u8>
) for easy integration with external tools. - Runtime APIs: Runtime interfaces declared through
decl_runtime_apis!
facilitate querying delegates, agents, brains, stake info, and TFT enforcement data directly from runtime. Clients and DApps can easily integrate for analytics, dashboards, or enhanced user experiences.
- Brainport and Prometheus Serving: The node can advertise endpoint information (IP, port, protocol) for additional network services like Prometheus monitoring or “brainport” endpoints.
- IP and Port Validation: Rigorous checks for IPv4/IPv6 correctness, port ranges, rate limits, and IP type validity ensure secure and reliable public endpoints.
- Senate and Triumvirate: Integrate with governance modules (e.g., council or senate) to propose, vote, and ratify changes. Manage membership through staking and burn-based admission.
- Proposals and Voting: Tests and code suggest a flexible governance model with proposals, votes, membership adjustments, and synergy with the underlying economics and staking logic.
- Comprehensive Test Suite: Extensive testing frameworks (with
mock.rs
) provide robust integration tests covering difficulty adjustment, registration flows, weight setting, stakeholder changes, network creation/removal, pruning, and stake manipulations. - Benchmarking: Dedicated
benchmarks.rs
test performance and resource usage of critical operations (registration, weight setting, delegation, etc.). Ensures that runtime calls are optimized and meet on-chain performance criteria.
- Binaries: Located in
./bin/release
. - Platform: Currently supports Linux x86_64 and MacOS x86_64.
- Memory: ~286 MiB RAM required.
- Dependencies:
- On Linux: Kernel 2.6.32+, glibc 2.11+
- On MacOS: OS 10.7+ (Lion+)
libclang
andclang
are needed for building the runtime (especially forbindgen
).
- IPv4 Public Access: Requires a public internet connection and firewall configuration.
- Ports:
- 9944 (WebSocket): Localhost-only, used for internal client connections (ensure firewall restrictions).
- 9933 (RPC): Currently opened but unused.
- 30333 (p2p): Required for peer-to-peer connections with other nodes.
- Outgoing Traffic: By default assumed to be ACCEPT. If restricted, open outbound on port 30333.
-
Rust Toolchain Setup:
- Follow the basic Rust setup instructions.
- Ensure
libclang
andclang
are installed for Linux or MacOS.
-
Build:
cargo build --release
On Linux (Debian/Ubuntu):
sudo apt install libclang-dev clang cargo build --release
On MacOS (with Homebrew):
brew install llvm@15 LIBCLANG_PATH="/opt/homebrew/opt/llvm@15/lib/" cargo build --release
-
Run: To launch a development chain:
cargo run --release -- --dev
This starts a single-node development chain with temporary state.
-
Explore CLI: After building, check all parameters and subcommands:
./target/release/basednode -h
- Start a dev chain:
./target/release/basednode --dev
- Purge chain state:
./target/release/basednode purge-chain --dev
- Detailed logging:
RUST_BACKTRACE=1 ./target/release/basednode -ldebug --dev
- Run tests with logs:
SKIP_WASM_BUILD=1 RUST_LOG=runtime=debug -- --nocapture
Tests are organized by packages and test files. For example, to run chain_spec
tests from basednode
project:
SKIP_WASM_BUILD=1 \
RUST_LOG=runtime=debug \
cargo test --package basednode --test chain_spec \
-- --color always --nocapture
bash scripts/code-coverage.sh
Requires cargo-tarpaulin
:
cargo install cargo-tarpaulin
By default, the dev chain state is stored in a temporary folder. For persistent state:
mkdir my-chain-state
./target/release/basednode --dev --base-path ./my-chain-state/
This maintains chain databases across runs.
Polkadot-JS Apps:
Connect to the local node (if running on 9944
):
Polkadot-JS Apps
This UI allows interaction with the chain’s runtime calls, extrinsics, and storage.
To simulate a real network, launch multiple nodes locally. Refer to Substrate’s guide on Simulating a Network for multi-node setups, consensus testing, and finality checks.
Node:
- Entry point:
node/src/service.rs
,node/src/chain_spec.rs
- Provides networking (libp2p), consensus (Aura/GRANDPA), and RPC server
- Command-line parameters can be found via
--help
Runtime:
- Core logic:
runtime/src/lib.rs
- Uses FRAME pallets and
construct_runtime!
to assemble a modular runtime - Incorporates custom pallets (registration, staking, weights, serving, epoch, etc.)
Pallets:
pallets/template
: Example template pallet (for reference)pallets/*
: Additional logic (e.g., advanced features might be separated into their own pallets)- Handle storage, events, errors, and dispatchable calls
Migration:
migration.rs
handles storage migrations, version updates, network creation/deletion, and maintaining state integrity during upgrades.
Math and Utility Modules:
math.rs
: Houses fixed-point arithmetic, matrix operations, normalization routines, and advanced statistical functions.utils.rs
: Provides helper functions for rate limiting, parameter updates, economic adjustments, and global runtime configuration.
Docker: To run a development node inside Docker:
./scripts/docker_run.sh
This compiles and runs the node. Append commands as needed:
./scripts/docker_run.sh ./target/release/basednode --dev --ws-external
Continuous Integration:
- Code coverage, linting, and style checks can be integrated with CI pipelines.
- The benchmarking and test suites ensure performance and functional correctness.
- Error Handling: Uses comprehensive
ensure!
checks andResult
returns to prevent unintended state transitions. - Type Safety: Relies on Rust’s strong type system, fixed-point arithmetic, and careful numeric bounds checks.
- Auth and Permissions: Verifies signatures, ensures proper sender origin, checks membership and delegate permissions before executing sensitive calls.
- Rate Limiting & Pruning: Protects the network from spam, ensures stable growth, and maintains a balanced set of network participants.
- Extended AI Integration: Deeper integration with machine learning frameworks, neural network parameters on-chain, and dynamically evolving “brain” hyperparameters.
- Enhanced Governance: More complex voting mechanisms, parameter changes via on-chain governance, and tri-chamber councils.
- Interoperability: Bridges to other networks, standardized runtime APIs, and improved RPC endpoints.
- Performance Optimizations: Further improvements in sparse/dense matrix handling, caching strategies, and off-chain workers for computationally expensive tasks.
We welcome contributions from the community. Feel free to open issues and pull requests.
The MIT License (MIT) (C) 2024 Based Labs
Permission is granted free of charge to anyone obtaining a copy of this software and associated documentation files (the “Software”), to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software. Recipients must include this permission notice in all copies or significant portions of the Software.
THE SOFTWARE IS PROVIDED “AS IS” WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED.