ant_node/ant_protocol/mod.rs
1//! ANT protocol implementation for the Autonomi network.
2//!
3//! This module implements the wire protocol for storing and retrieving
4//! data on the Autonomi network.
5//!
6//! # Data Types
7//!
8//! The ANT protocol supports a single data type:
9//!
10//! - **Chunk**: Immutable, content-addressed data (hash == address)
11//!
12//! # Protocol Overview
13//!
14//! The protocol uses postcard serialization for compact, fast encoding.
15//! Each data type has its own message types for PUT/GET operations.
16//!
17//! ## Chunk Messages
18//!
19//! - `ChunkPutRequest` / `ChunkPutResponse` - Store chunks
20//! - `ChunkGetRequest` / `ChunkGetResponse` - Retrieve chunks
21//! - `ChunkQuoteRequest` / `ChunkQuoteResponse` - Request storage quotes
22//!
23//! ## Payment Flow
24//!
25//! 1. Client requests a quote via `ChunkQuoteRequest`
26//! 2. Node returns signed `PaymentQuote` in `ChunkQuoteResponse`
27//! 3. Client pays on Arbitrum via `PaymentVault.payForQuotes()`
28//! 4. Client sends `ChunkPutRequest` with `payment_proof`
29//! 5. Node verifies payment and stores chunk
30//!
31//! # Example
32//!
33//! ```rust,ignore
34//! use ant_node::ant_protocol::{ChunkMessage, ChunkPutRequest, ChunkGetRequest};
35//!
36//! // Create a PUT request
37//! let address = compute_address(&data);
38//! let request = ChunkPutRequest::with_payment(address, data, payment_proof);
39//! let message = ChunkMessage::PutRequest(request);
40//! let bytes = message.encode()?;
41//!
42//! // Decode a response
43//! let response = ChunkMessage::decode(&response_bytes)?;
44//! ```
45
46pub mod chunk;
47
48/// Number of nodes in a Kademlia close group.
49///
50/// Clients fetch quotes from the `CLOSE_GROUP_SIZE` closest nodes to a target
51/// address and select the median-priced quote for payment.
52pub const CLOSE_GROUP_SIZE: usize = 5;
53
54/// Minimum number of close group members that must agree for a decision to be valid.
55///
56/// This is a simple majority: `(CLOSE_GROUP_SIZE / 2) + 1`.
57pub const CLOSE_GROUP_MAJORITY: usize = (CLOSE_GROUP_SIZE / 2) + 1;
58
59// Re-export chunk types for convenience
60pub use chunk::{
61 ChunkGetRequest, ChunkGetResponse, ChunkMessage, ChunkMessageBody, ChunkPutRequest,
62 ChunkPutResponse, ChunkQuoteRequest, ChunkQuoteResponse, MerkleCandidateQuoteRequest,
63 MerkleCandidateQuoteResponse, ProtocolError, XorName, CHUNK_PROTOCOL_ID, DATA_TYPE_CHUNK,
64 MAX_CHUNK_SIZE, MAX_WIRE_MESSAGE_SIZE, PROOF_TAG_MERKLE, PROOF_TAG_SINGLE_NODE,
65 PROTOCOL_VERSION,
66};