Expand description
P2P networking layer for Tenzro Network
This crate provides the networking infrastructure for Tenzro Network, an AI-Native, Agentic, Tokenized Settlement Layer blockchain.
§Overview
The networking layer is built on libp2p and provides:
- Gossipsub: Pub/sub messaging for blocks, transactions, and consensus
- Kademlia DHT: Peer discovery and routing
- Identify: Peer information exchange
- Ping: Connection health monitoring
§Architecture
The network service runs an event loop in a background task and communicates with the rest of the node through async channels. This allows the networking layer to be decoupled from the rest of the application.
§Example
use tenzro_network::{NetworkService, TenzroNetworkService, NetworkConfig, NetworkMessage, MessagePayload};
// Create network service
let config = NetworkConfig::testnet();
let network = TenzroNetworkService::new(config).await?;
// Subscribe to blocks
let mut blocks_rx = network.subscribe("tenzro/blocks").await?;
// Broadcast a message
let message = NetworkMessage::new(MessagePayload::Ping);
network.broadcast("tenzro/status", message).await?;
// Receive messages
tokio::spawn(async move {
while let Some(msg) = blocks_rx.recv().await {
println!("Received block message: {:?}", msg);
}
});
§Topics
The network uses gossipsub topics for different message types:
tenzro/blocks- Block propagationtenzro/transactions- Transaction propagationtenzro/consensus- Consensus messagestenzro/attestations- TEE attestationstenzro/models- Model registrationstenzro/inference- Inference requests/responsestenzro/status- Status and discovery messages
For testnet and mainnet, topics are prefixed accordingly:
- Testnet:
tenzro/testnet/blocks/1.0.0 - Mainnet:
tenzro/mainnet/blocks/1.0.0
Re-exports§
pub use behaviour::TenzroBehaviour;pub use behaviour::TenzroNetwork;pub use block_sync_proto::BlockSyncBehaviour;pub use block_sync_proto::BlockSyncError;pub use block_sync_proto::BlockSyncRequest;pub use block_sync_proto::BlockSyncResponse;pub use block_sync_proto::BLOCK_SYNC_PROTOCOL;pub use block_sync_proto::MAX_BLOCKS_PER_RANGE;pub use block_sync_proto::MAX_BLOCK_HASHES_PER_REQUEST;pub use block_sync_proto::MAX_INBOUND_STREAMS_PER_PEER;pub use block_sync_proto::MAX_INFLIGHT_REQUESTS_PER_PEER;pub use consensus_direct_proto::ConsensusDirectBehaviour;pub use consensus_direct_proto::ConsensusDirectError;pub use consensus_direct_proto::ConsensusDirectRequest;pub use consensus_direct_proto::ConsensusDirectResponse;pub use consensus_direct_proto::CONSENSUS_DIRECT_PROTOCOL;pub use mpc_relay::session_topic as mpc_session_topic;pub use mpc_relay::MpcDidResolver;pub use mpc_relay::MpcRelayBehaviour;pub use mpc_relay::MpcRelayError;pub use mpc_relay::MpcRelayRequest;pub use mpc_relay::MpcRelayResponse;pub use mpc_relay::MPC_RELAY_GOSSIP_TOPIC_PREFIX;pub use mpc_relay::MPC_RELAY_PROTOCOL;pub use config::NetworkConfig;pub use discovery::BootstrapConfig;pub use discovery::DiscoveryConfig;pub use discovery::ProviderType;pub use error::NetworkError;pub use error::Result;pub use gossip::GossipTopics;pub use gossip::MessageDeduplicator;pub use gossip::MessageValidation;pub use gossip::TopicSubscriptions;pub use metrics::NetworkMetrics;pub use message::AgentAnnouncementMessage;pub use message::AttestationMessage;pub use message::ConsensusMessage;pub use message::InferenceRequestMessage;pub use message::InferenceResponseMessage;pub use message::MessagePayload;pub use message::ModelRegistrationMessage;pub use message::ModelSchedule;pub use message::NetworkMessage;pub use message::PaymentDetails;pub use message::PricingInfo;pub use message::ProviderAnnouncementMessage;pub use message::StatusMessage;pub use message::VoteType;pub use peer_manager::ManagedPeer;pub use peer_manager::PeerManager;pub use peer_manager::PeerManagerStats;pub use peer_manager::ValidatorRegistry;pub use peer_manager::VALIDATOR_ONLY_TOPICS;pub use peer_status::PeerStatus as PeerChainStatus;pub use peer_status::PeerStatusTracker;pub use peer_status::DEFAULT_FRESHNESS;pub use service::BlockSyncOutboundError;pub use service::InboundBlockSync;pub use service::NetworkService;pub use service::OutboundBlockSyncResult;pub use service::PeerEvent;pub use service::TenzroNetworkService;
Modules§
- behaviour
- Network behaviour combining protocols for Tenzro Network — A+++ production grade.
- block_
sync_ proto - Block-sync wire protocol for Tenzro Network.
- config
- Network configuration for Tenzro Network
- consensus_
direct_ proto - Validator-only direct-connect overlay for HotStuff-2 consensus messages.
- discovery
- Peer discovery via Kademlia DHT for Tenzro Network
- error
- Network error types for Tenzro Network
- gossip
- Gossipsub topics and message handling for Tenzro Network
- message
- Network message types for Tenzro Network
- metrics
- Prometheus metrics for Tenzro Network — A+++ production observability.
- mpc_
relay - libp2p binding for the MPC
Transportsurface used bytenzro-bridge. - peer_
manager - Peer tracking and reputation management for Tenzro Network
- peer_
status - Peer status / chain-tip tracker.
- service
- Main NetworkService for Tenzro Network
- transport
- libp2p transport setup for Tenzro Network.
Structs§
- Inbound
Request Id - The ID of an inbound request.
- Multiaddr
- Representation of a Multiaddr.
- Outbound
Request Id - The ID of an outbound request.
- PeerId
- Identifier of a peer of the network.