Thanks to visit codestin.com
Credit goes to github.com

Skip to content

dyodx/unshred

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

4 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

unshred

Reconstructs Solana transactions from shreds in real time.

  • Ingests shreds via UDP
  • Parallelizes processing across Forward Error Correction (FEC) sets and entry batches
  • Processes transactions via user-provided handler
  • Provides optional Prometheus metrics for system performance monitoring

Quick start

use anyhow::Result;
use unshred::{TransactionEvent, TransactionHandler, UnshredProcessor};

struct MyHandler;

impl TransactionHandler for MyHandler {
    fn handle_transaction(&self, event: &TransactionEvent) -> Result<()> {
        let signature = solana_sdk::bs58::encode(&event.transaction.signatures[0]).into_string();
        println!("Slot {}: {} with {} instructions",
            event.slot,
            signature,
            event.transaction.message.instructions().len()
        );
        Ok(())
    }
}

#[tokio::main]
async fn main() -> Result<()> {
    let processor = UnshredProcessor::builder()
        .handler(MyHandler)
        .bind_address("0.0.0.0:8001")
        .build()?;

    processor.run().await
}

Complete example

See examples/drift-monitor for a production-ready implementation that:

  • Filters transactions for Drift protocol liquidation events
  • Stores events in ClickHouse
  • Tracks system performance metrics with Prometheus
  • Generates Grafana dashboards for liquidation and system monitoring
  • Packages all components into a docker-compose deployment

shred-pipeline-dashboard

drift-liquidation-dashboard

Metrics

The example demonstrates the activation of the internal metrics for unshred:

  1. features = ["metrics"] in Cargo.toml
  2. UnshredProcessor::builder().metrics_registry(registry) to init

API

TransactionHandler

pub trait TransactionHandler: Send + Sync + 'static {
    /// Called for each reconstructed transaction
    /// # Returns
    /// * `Ok(())` - to continue processing
    /// * `Err(_)` - to log error and continue (does not stop processing)
    fn handle_transaction(&self, event: &TransactionEvent) -> Result<()>;
}

TransactionEvent

#[derive(Debug)]
pub struct TransactionEvent<'a> {
    pub slot: u64,
    pub transaction: &'a VersionedTransaction,
    /// * `Some(_)` - data shred containing this transaction was directly received via UDP
    /// * `None`    - data shred containing this transaction was recovered via code shreds
    ///
    /// Note: Estimated as the received_at_micros of the data shred that contained
    ///       the first byte of the Entry that contained this transaction.
    pub received_at_micros: Option<u64>,
    pub processed_at_micros: u64,
}

About

Reconstruct Solana transactions from shreds in real time

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages