Shred Delivery and Sender are now live! Get earliest access to raw Solana data and optimized transaction sending. Learn about Shred Delivery | Learn about Sender
简体中文
通过实时 slot 和 block 流,监控 Solana 网络共识、区块生成和网络状态变化。
const subscribeRequest: SubscribeRequest = { slots: { slotSubscribe: { filterByCommitment: false // Receive all commitment levels } }, commitment: CommitmentLevel.CONFIRMED };
import { StreamManager } from './stream-manager'; // From quickstart guide async function monitorNetworkHealth() { const streamManager = new StreamManager( "your-grpc-endpoint", "your-api-key", handleNetworkHealth ); const subscribeRequest: SubscribeRequest = { slots: { slotSubscribe: { filterByCommitment: false // Track all commitment levels } }, commitment: CommitmentLevel.PROCESSED }; await streamManager.connect(subscribeRequest); } let lastSlot = 0; let lastTimestamp = Date.now(); const slotTimes: number[] = []; function handleNetworkHealth(data: any): void { if (data.slot) { const slot = data.slot; const currentTime = Date.now(); console.log(`\n📊 Slot Update:`); console.log(` Slot: ${slot.slot}`); console.log(` Parent: ${slot.parentSlot}`); console.log(` Status: ${slot.status}`); // Calculate slot timing if (lastSlot > 0) { const slotDiff = slot.slot - lastSlot; const timeDiff = currentTime - lastTimestamp; if (slotDiff === 1) { // Normal slot progression const slotTime = timeDiff; slotTimes.push(slotTime); // Keep last 100 slot times for analysis if (slotTimes.length > 100) { slotTimes.shift(); } const avgSlotTime = slotTimes.reduce((a, b) => a + b, 0) / slotTimes.length; console.log(` Slot Time: ${slotTime}ms`); console.log(` Avg Slot Time: ${avgSlotTime.toFixed(1)}ms`); // Alert on slow slots if (slotTime > 800) { console.log(` ⚠️ SLOW SLOT: ${slotTime}ms (normal ~400ms)`); } } else if (slotDiff > 1) { console.log(` ⚠️ SKIPPED ${slotDiff - 1} SLOTS`); } } lastSlot = slot.slot; lastTimestamp = currentTime; } }
async function monitorBlockProduction() { const streamManager = new StreamManager( "your-grpc-endpoint", "your-api-key", handleBlockProduction ); const subscribeRequest: SubscribeRequest = { blocksMeta: { blockMetaSubscribe: {} }, commitment: CommitmentLevel.CONFIRMED }; await streamManager.connect(subscribeRequest); } function handleBlockProduction(data: any): void { if (data.blockMeta) { const blockMeta = data.blockMeta; console.log(`\n🧱 Block Produced:`); console.log(` Slot: ${blockMeta.slot}`); console.log(` Block Height: ${blockMeta.blockHeight}`); console.log(` Block Hash: ${blockMeta.blockhash}`); console.log(` Parent Hash: ${blockMeta.parentBlockhash}`); console.log(` Transactions: ${blockMeta.transactionCount}`); console.log(` Block Time: ${new Date(blockMeta.blockTime * 1000).toISOString()}`); if (blockMeta.rewards?.length > 0) { console.log(` Rewards:`); blockMeta.rewards.forEach((reward: any) => { console.log(` ${reward.pubkey}: ${reward.lamports} lamports (${reward.rewardType})`); }); } // Alert on high transaction count if (blockMeta.transactionCount > 3000) { console.log(` 🔥 HIGH ACTIVITY: ${blockMeta.transactionCount} transactions`); } } }
async function monitorDEXBlocks() { const streamManager = new StreamManager( "your-grpc-endpoint", "your-api-key", handleDEXBlock ); const subscribeRequest: SubscribeRequest = { blocks: { blockSubscribe: { accountInclude: [ "9WzDXwBbmkg8ZTbNMqUxvQRAyrZzDsGYdLVL9zYtAWWM", // Raydium V4 "JUP6LkbZbjS1jKKwapdHNy74zcZ3tLUZoi5QNyVTaV4" // Jupiter ], includeTransactions: true, includeAccounts: false, includeEntries: false } }, commitment: CommitmentLevel.CONFIRMED }; await streamManager.connect(subscribeRequest); } function handleDEXBlock(data: any): void { if (data.block) { const block = data.block; console.log(`\n🔄 DEX Activity Block:`); console.log(` Slot: ${block.slot}`); console.log(` Block Hash: ${block.blockhash}`); console.log(` Total Transactions: ${block.transactions?.length || 0}`); if (block.transactions) { let dexTxCount = 0; let totalFees = 0; block.transactions.forEach((tx: any) => { if (tx.meta && !tx.meta.err) { dexTxCount++; totalFees += tx.meta.fee || 0; } }); console.log(` DEX Transactions: ${dexTxCount}`); console.log(` Total Fees: ${(totalFees / 1e9).toFixed(4)} SOL`); console.log(` Avg Fee: ${(totalFees / dexTxCount / 1e9).toFixed(6)} SOL`); } } }
插槽数据结构
{ slot: number; // Current slot number parentSlot: number; // Parent slot number status: string; // "processed", "confirmed", "finalized" }
区块元数据结构
{ slot: number; blockHeight: number; blockhash: string; parentBlockhash: string; blockTime: number; // Unix timestamp transactionCount: number; rewards: Array<{ pubkey: string; lamports: number; rewardType: string; // "fee", "rent", "voting", "staking" }>; }
完整区块结构
{ slot: number; parentSlot: number; blockhash: string; previousBlockhash: string; transactions: Transaction[]; // Full transaction data accounts: AccountUpdate[]; // Account state changes entries: Entry[]; // Block entries (if included) }
// Monitor slot timing deviations const targetSlotTime = 400; // ms const tolerance = 200; // ms if (Math.abs(slotTime - targetSlotTime) > tolerance) { console.log(`Network performance issue detected`); }
缺失的插槽
高流量
时间问题
此页面对您有帮助吗?