mcpField
S
shredstream

shredstream

github.com/agiprolabs数据与数据库456428 次安装8 周前更新
代码仓库

关于 shredstream

面向 Solana 数据消费方的预执行交易数据技能,介绍通过 Jito、Shyft 或 Triton 获取 shreds,并解析交易意图。它侧重低延迟信号,同时说明预执行数据缺少执行结果等信息。

主要功能

  1. 01获取验证者执行前的交易数据
  2. 02介绍 Jito、Shyft 与 Triton 方案
  3. 03通过 UDP 或 gRPC 接收数据
  4. 04解析交易账户与指令
  5. 05提供部署要求及解析脚本

适用场景

  1. 01在交易执行前检测交易意图
  2. 02构建低延迟 Solana 交易监控
  3. 03将预执行信号与 Yellowstone 确认数据结合
  4. 04分析 shreds 中的程序指令

安装

复制下面的命令,在终端中运行。

$npx skills add https://github.com/agiprolabs/claude-trading-skills --skill shredstream

安装后在 Claude Code 中输入/shredstream确认已加载。

包含的文件

除 SKILL.md 外,安装时一起下载的参考资料和脚本。

references/
deployment.md
proto_reference.md
providers_compared.md
scripts/
parse_shredstream_entries.py
rabbitstream_monitor.py

详细介绍

ShredStream — Solana 执行前数据

ShredStream 可在验证者执行区块之前提供交易数据 — 通常比标准 Yellowstone gRPC 提前 100-500ms。你看到的是交易的意图,而不是已确认的结果。

这是获取 Solana 数据、用于时间敏感型交易策略的最快途径。

工作原理

Solana 验证者通过将交易序列化为 shred(每个约 1,228 字节,大小适合 UDP MTU)来生成区块。Shred 通过 Turbine(Solana 的扇出协议,需经过 2-3 跳)传播。ShredStream 通过 Jito 的 Block Engine 直接从领导者验证者接收 shred,从而绕过 Turbine。

Leader Validator
     │
     ├── Turbine (standard, 2-3 hops, 200-500ms)
     │       └── Your RPC Node → Yellowstone gRPC (post-execution)
     │
     └── Jito Block Engine (direct)
              └── ShredStream Proxy (your server)
                   ├── UDP shreds → Your RPC/Validator (faster block building)
                   └── gRPC entries → Your Trading Bot (decoded transactions)
你能获取什么,不能获取什么
可用(执行前)不可用(需要执行)
交易签名成功/失败状态
账户密钥(公钥)余额变化(执行前/后)
指令(程序、账户、数据)日志消息
地址查找表引用内部指令(CPI)
Slot 编号Token 余额变化
消耗的计算单元

关键权衡:速度与完整性。你可以看到即将发生什么,但无法确认交易是否真的成功。你看到的某些交易最终会失败。

获取执行前数据的三种方式

提供商产品延迟获取方式费用
JitoShredStream Proxy距领导者约 10-50ms申请 + 授权密钥对免费(测试版)
ShyftRabbitStream比 gRPC 快约 15-100msShyft gRPC 套餐199 美元/月起
TritonDeshred(SubscribeDeshred)距 shred 的 p50 延迟约 6.3msTriton 客户约 2,900 美元/月起

详细对比请参阅 references/providers_compared.md。

选项 1:Jito ShredStream Proxy

最直接的方式 — 在你自己的服务器上运行 Jito 的开源代理。

获取访问权限
  1. 生成 Solana 密钥对:solana-keygen new -o shred_auth.json
  2. 使用你的公钥填写 Jito 的表单
  3. 等待审批(你的密钥对将加入白名单)
  4. 无需质押,测试版期间免费
运行代理
# Clone and build
git clone https://github.com/jito-labs/shredstream-proxy.git --recurse-submodules
cd shredstream-proxy

# Run with gRPC enabled (key flag: --grpc-service-port)
RUST_LOG=info cargo run --release --bin jito-shredstream-proxy -- shredstream \
    --block-engine-url https://mainnet.block-engine.jito.wtf \
    --auth-keypair /path/to/shred_auth.json \
    --desired-regions ny,amsterdam \
    --dest-ip-ports 127.0.0.1:8001 \
    --grpc-service-port 7777

Docker(UDP 需要主机网络):

docker run -d --name shredstream-proxy --rm \
  --network host \
  -e RUST_LOG=info \
  -e BLOCK_ENGINE_URL=https://mainnet.block-engine.jito.wtf \
  -e AUTH_KEYPAIR=/app/shred_auth.json \
  -e DESIRED_REGIONS=ny,amsterdam \
  -e DEST_IP_PORTS=127.0.0.1:8001 \
  -e GRPC_SERVICE_PORT=7777 \
  -v /path/to/shred_auth.json:/app/shred_auth.json \
  jitolabs/jito-shredstream-proxy shredstream
配置
参数说明示例
BLOCK_ENGINE_URLJito 区块引擎端点https://mainnet.block-engine.jito.wtf
AUTH_KEYPAIR已加入白名单的 Solana 密钥对路径shred_auth.json
DESIRED_REGIONS最多 2 个,以逗号分隔ny,amsterdam
DEST_IP_PORTS转发原始 shred 的目标位置(UDP)127.0.0.1:8001
GRPC_SERVICE_PORT启用 gRPC 条目流7777
SRC_BIND_PORT接收 shred 的 UDP 端口20000

可用区域:amsterdam、dublin、frankfurt、london、ny、salt-lake-city、singapore、tokyo

验证是否正常运行
# Check shreds are arriving via UDP
sudo tcpdump 'udp and dst port 20000'
# Should see many ~1200-byte packets continuously
通过 gRPC 接收数据
use jito_protos::shredstream::{
    shredstream_proxy_client::ShredstreamProxyClient,
    SubscribeEntriesRequest,
};

let mut client = ShredstreamProxyClient::connect("http://127.0.0.1:7777").await?;
let mut stream = client
    .subscribe_entries(SubscribeEntriesRequest {})
    .await?
    .into_inner();

while let Some(entry) = stream.message().await? {
    let entries: Vec<solana_entry::entry::Entry> =
        bincode::deserialize(&entry.entries)?;

    for e in &entries {
        for tx in &e.transactions {
            let sig = tx.signatures[0];
            let msg = tx.message();
            // Parse instructions, accounts, etc.
        }
    }

    println!("Slot {}: {} entries, {} transactions",
        entry.slot,
        entries.len(),
        entries.iter().map(|e| e.transactions.len()).sum::<usize>()
    );
}

选项 2:Shyft RabbitStream

可直接替换 Yellowstone gRPC — 使用相同的 SubscribeRequest 格式,只需更换端点。无需运行基础设施,即可获取执行前数据的最简单方式。

export GRPC_ENDPOINT="https://rabbitstream.ny.shyft.to"
export GRPC_TOKEN="your-shyft-x-token"
# Same code as yellowstone-grpc, just different endpoint
import grpc

endpoint = "rabbitstream.ny.shyft.to"
token = os.environ["GRPC_TOKEN"]

# ... standard Yellowstone connection code ...
# Subscribe to transactions — same filter format
request = SubscribeRequest(
    transactions={
        "pumpfun": SubscribeRequestFilterTransactions(
            account_include=["6EF8rrecthR5Dkzon8Nwu78hRvfCKubJ14M5uBEwF6P"],
            vote=False,
            failed=False,
        )
    },
    commitment=CommitmentLevel.PROCESSED,
)

限制:仅支持交易过滤器。不支持账户、slot 或区块订阅。meta 字段为空(没有执行结果)。

区域端点:rabbitstream.{ny,va,ams,fra}.shyft.to

选项 3:Triton Deshred

通过 Triton 的 SubscribeDeshred RPC 实现最低延迟(p50 约 6.3ms)。使用相同的 Yellowstone 客户端,但调用不同的方法。

// Requires yellowstone-grpc-client with Deshred support
let (mut tx, mut stream) = client.subscribe_deshred().await?;

tx.send(SubscribeDeshredRequest {
    deshred_transactions: hashmap!{
        "pumpfun".to_string() => SubscribeRequestFilterDeshredTransactions {
            vote: Some(false),
            account_include: vec!["6EF8rrecthR5Dkzon8Nwu78hRvfCKubJ14M5uBEwF6P".into()],
            ..Default::default()
        }
    },
    ..Default::default()
}).await?;

访问权限:仅限 Triton 客户,付费测试版,需要使用其定制的 Agave 验证者分支。

解析执行前交易

没有执行元数据后,解析会更简单,但需要了解特定程序的知识。

识别程序
# From a raw VersionedTransaction (post-deserialization)
account_keys = [str(k) for k in tx.message.account_keys]
for ix in tx.message.instructions:
    program_id = account_keys[ix.program_id_index]
    if program_id == "6EF8rrecthR5Dkzon8Nwu78hRvfCKubJ14M5uBEwF6P":
        # This is a PumpFun instruction
        discriminator = ix.data[:8]
        # Decode instruction data per PumpFun IDL
指令判别符

大多数 Solana 程序使用 8 字节判别符(指令名称的 Anchor SHA256 哈希)。将 instruction.data[:8] 与各程序的已知值进行匹配。

# Common approach
PUMPFUN_CREATE = bytes.fromhex("181ec828051c0777")
PUMPFUN_BUY = bytes.fromhex("66063d1201daebea")
PUMPFUN_SELL = bytes.fromhex("33e685a4017f83ad")

disc = ix.data[:8]
if disc == PUMPFUN_BUY:
    # Parse buy parameters from remaining bytes
    ...

警告:判别符值因程序而异,也可能随程序版本变化。请务必对照当前程序 IDL 进行验证。有关 PumpFun 专用解析,请参阅 pumpfun-mechanics 技能。

常见架构:ShredStream + Yellowstone

大多数生产系统会同时使用两者:

ShredStream (pre-execution)          Yellowstone gRPC (post-execution)
         │                                      │
         ▼                                      ▼
  Intent Detection                    Confirmation + Reconciliation
  "Wallet X is buying token Y"       "Buy succeeded, wallet now holds Z"
         │                                      │
         ▼                                      ▼
  Pre-compute Response                Execute / Update State
  (route, sign, prepare bundle)       (record PnL, update positions)

这样既能利用 ShredStream 的速度优势检测信号,又能利用 Yellowstone 可靠地管理状态。

部署要求

  • 需要公网 IP — NAT 会导致 UDP shred 传输中断
  • 使用主机网络 — Docker 桥接模式会丢弃 shred 数据包
  • 开放用于接收 shreds 的 UDP 端口 20000
  • 靠近验证器部署 — 推荐法兰克福、纽约、阿姆斯特丹、伦敦和东京
  • 优先选择裸金属服务器 — 共享 NIC 会使云 VM 增加 1-5ms 的抖动

完整的基础设施指南请参阅 references/deployment.md。

文件

参考资料
  • references/providers_compared.md — Jito ShredStream、Shyft RabbitStream 和 Triton Deshred 对比
  • references/deployment.md — 基础设施要求、区域选择、防火墙配置
  • references/proto_reference.md — ShredStream protobuf 定义和 Entry 解析
脚本
  • scripts/parse_shredstream_entries.py — 解码并分析 ShredStream gRPC entries
  • scripts/rabbitstream_monitor.py — 连接 Shyft RabbitStream,监控执行前的交易

评论

支持 Markdown