Skip to content

shredstream/shredstream-sdk-rust

Folders and files

NameName
Last commit message
Last commit date

Latest commit

ย 

History

4 Commits
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 

Repository files navigation

Solana ShredStream SDK for Rust

Solana ShredStream SDK/Decoder for Rust, enabling ultra-low latency Solana transaction streaming via UDP shreds from ShredStream.com

Part of the ShredStream.com ecosystem โ€” ultra-low latency Solana shred streaming via UDP.

License: MIT Rust

๐Ÿ“‹ Prerequisites

  1. Create an account on ShredStream.com
  2. Launch a Shred Stream and pick your region (Frankfurt, Amsterdam, Singapore, Chicago, and more)
  3. Enter your server's IP address and the UDP port where you want to receive shreds
  4. Open your firewall for inbound UDP traffic on that port (e.g. configure your cloud provider's security group)
  5. Install Rust and Cargo:
    # Linux / macOS
    curl --proto '=https' --tlsv1.2 -sSf https://sh.rustup.rs | sh
    source $HOME/.cargo/env

๐ŸŽ Want to try before you buy? Open a ticket on our Discord to request a free trial.

๐Ÿ“ฆ Installation

# Initialize your project (skip if you already have a Cargo.toml)
cargo init myproject
cd myproject

Add shredstream to your Cargo.toml:

[dependencies]
shredstream = "2.0"

โšก Quick Start

Edit src/main.rs:

use shredstream::ShredListener;

fn main() {
    let port: u16 = std::env::var("SHREDSTREAM_PORT")
        .ok().and_then(|v| v.parse().ok()).unwrap_or(8001);
    let mut listener = ShredListener::bind(port).expect("bind");

    // Decoded transactions โ€” ready-to-use Solana transactions
    for (slot, transactions) in listener.transactions() {
        for tx in &transactions {
            println!("slot {}: {}", slot, tx.signatures[0]);
        }
    }
}

Run it:

cargo run

๐Ÿ“– API Reference

ShredListener

  • ShredListener::bind(port: u16) -> io::Result<Self> โ€” Bind with defaults (64 MB recv buf, 3 slot window, FEC enabled)
  • ShredListener::bind_with_options(port, opts) -> io::Result<Self> โ€” Custom configuration
  • ShredListener::from_socket(socket, opts) -> io::Result<Self> โ€” Adopt an existing UdpSocket
  • listener.transactions() -> TransactionIter โ€” Blocking iterator yielding (slot, Vec<VersionedTransaction>)
  • listener.shreds() -> ShredIter โ€” Blocking iterator yielding RawShred headers (no decode)
  • listener.handle_packet(&[u8]) -> Option<(u64, Vec<VersionedTransaction>)> โ€” Inject an externally-received UDP datagram
  • listener.local_addr() -> io::Result<SocketAddr> โ€” Bound socket address
  • listener.slot_count() -> usize โ€” Number of slots currently active in the window

ListenerOptions

Field Type Default Description
recv_buf usize 64 * 1024 * 1024 SO_RCVBUF size
max_age u64 3 Slot retention window
busy_poll_us Option<u32> Some(200) Linux SO_BUSY_POLL ยตs (None disables)
pool_size usize 4096 Number of 2 KiB buffers in the zero-copy pool
enable_fec bool true Reed-Solomon recovery on dropped data shreds
disable_salvage_delivery bool false Drop salvaged tail txs for lowest p99
accumulator AccumulatorConfig defaults FEC and stuck-batch tuning

AccumulatorConfig

Field Type Default Description
max_fec_sets_per_slot usize 32 Per-slot FEC buffer cap
stuck_batch_timeout Duration 50ms Force-finalize a stuck batch after this delay

Metrics

Read-only counters on &ShredListener:

Group Methods
Throughput data_shred_count_total, code_shred_count_total, bytes_received, slot_count
Decoder batches_decoded_streaming_total, batches_decoded_fallback_total, batches_skipped_total, decode_errors_total
FEC fec_recoveries_total, fec_recovery_failures_total, fec_sets_discarded_unused_total, fec_sets_evicted_early_total
Unparseable unparseable_packets, unparseable_too_short, unparseable_variant, unparseable_payload, unparseable_slot_range
Slot lifecycle slots_completed_total, slots_evicted_by_age, dropped_known_slots, harvested_batches_total, salvaged_tail_tx_total
Tail control batches_force_finalized_corrupted_total, batches_force_finalized_timeout_total
Pool / I-O pool_exhausted_count, last_io_error_kind, busy_poll_active

Helpers

  • shredstream::classify_variant(byte) -> Option<VariantKind> โ€” Classify a shred variant byte. VariantKind exposes .is_data(), .is_code(), .proof_size(), .resigned(), .merkle_suffix().
  • shredstream::pin_current_thread_to_cpu(cpu_id: usize) -> io::Result<()> โ€” Best-effort thread pinning (Linux: sched_setaffinity; macOS: hint; other: no-op)

๐ŸŽฏ Use Cases

ShredStream.com shred data powers a wide range of latency-sensitive strategies โ€” HFT, MEV extraction, token sniping, copy trading, liquidation bots, on-chain analytics, and more.

๐Ÿ’Ž PumpFun Token Sniping

ShredStream.com SDK detects PumpFun token creations ~499ms before they appear on PumpFun's live feed โ€” tested across 25 consecutive detections:

ShredStream.com SDK vs PumpFun live feed โ€” ~499ms advantage

Ready-to-run example included: see examples/pumpfun_creates.rs. Run with cargo run --release --example pumpfun_creates [port].

โš™๏ธ Configuration

OS Tuning

For high-throughput environments, increase the kernel receive buffer:

# Linux
sudo sysctl -w net.core.rmem_max=67108864
sudo sysctl -w net.core.busy_read=200

# macOS
sudo sysctl -w kern.ipc.maxsockbuf=67108864

๐Ÿš€ Launch a Shred Stream

Need a feed? Launch a Solana Shred Stream on ShredStream.com โ€” sub-millisecond delivery, multiple global regions, 5-minute setup.

๐Ÿ”— Links

๐Ÿ“„ License

MIT โ€” ShredStream.com

About

Solana ShredStream SDK/Decoder for Rust, enabling ultra-low latency Solana transaction streaming via UDP shreds from https://www.shredstream.com

Topics

Resources

License

Stars

6 stars

Watchers

0 watching

Forks

Contributors

Languages