| Crates.io | qudag-dag |
| lib.rs | qudag-dag |
| version | 0.5.0 |
| created_at | 2025-06-20 18:02:22.529716+00 |
| updated_at | 2025-06-23 20:51:18.494141+00 |
| description | DAG consensus implementation for QuDAG - QR-Avalanche algorithm with Byzantine fault tolerance |
| homepage | |
| repository | https://github.com/ruvnet/QuDAG |
| max_upload_size | |
| id | 1719949 |
| size | 362,368 |
DAG consensus implementation with QR-Avalanche algorithm for the QuDAG protocol.
Add to your Cargo.toml:
[dependencies]
qudag-dag = "0.1"
use qudag_dag::{Dag, Vertex, VertexId};
use std::collections::HashSet;
#[tokio::main]
async fn main() -> Result<(), Box<dyn std::error::Error>> {
// Create a new DAG
let dag = Dag::new(100); // Max 100 concurrent messages
// Create and submit a message
let message = qudag_dag::DagMessage {
id: VertexId::new(),
payload: b"Hello, DAG!".to_vec(),
parents: HashSet::new(), // Genesis message
timestamp: std::time::SystemTime::now(),
};
dag.submit_message(message).await?;
Ok(())
}
use qudag_dag::{QrDag, Vertex, VertexId};
use std::collections::HashSet;
// Create a DAG consensus instance
let mut dag = QrDag::new();
// Add vertices to the DAG
let vertex_id = VertexId::new();
let vertex = Vertex::new(vertex_id, b"vertex data".to_vec(), HashSet::new());
dag.add_vertex(vertex)?;
// Get consensus status
if let Some(status) = dag.get_confidence("vertex_id") {
println!("Consensus status: {:?}", status);
}
// Get current tips
let tips = dag.get_tips();
println!("Current tips: {:?}", tips);
use qudag_dag::{TipSelection, TipSelectionConfig};
let config = TipSelectionConfig {
max_parents: 2,
min_weight_threshold: 0.1,
selection_strategy: Default::default(),
};
let tip_selector = TipSelection::new(config);
// Use tip selector for parent selection...
use qudag_dag::{ConsensusConfig, QrDag};
use std::time::Duration;
let config = ConsensusConfig {
query_sample_size: 10,
finality_threshold: 0.8,
finality_timeout: Duration::from_secs(5),
confirmation_depth: 3,
};
let dag = QrDag::with_config(config);
The crate provides comprehensive error types:
DagError: Main error type for DAG operationsVertexError: Vertex-specific validation errorsConsensusError: Consensus algorithm errorsoptimizations: Enable performance optimizations (validation cache, traversal index)validation-cache: Enable vertex validation cachingtraversal-index: Enable graph traversal indexingLicensed under either MIT or Apache-2.0 at your option.