Returns the highest slot that can be retransmitted
curl https://rpc.orbitflare.com -X POST -H "Content-Type: application/json" -d '{ "jsonrpc": "2.0", "id": 1, "method": "getMaxRetransmitSlot" }'
import { Connection } from '@solana/web3.js'; const connection = new Connection('https://rpc.orbitflare.com'); // Get max retransmit slot const maxRetransmitSlot = await connection.getMaxRetransmitSlot(); console.log('Max retransmit slot:', maxRetransmitSlot); // Check if a slot can be retransmitted async function canRetransmitSlot(slot: number) { const maxRetransmitSlot = await connection.getMaxRetransmitSlot(); return slot <= maxRetransmitSlot; } // Get retransmit range async function getRetransmitRange() { const maxRetransmitSlot = await connection.getMaxRetransmitSlot(); const firstAvailableBlock = await connection.getFirstAvailableBlock(); return { startSlot: firstAvailableBlock, endSlot: maxRetransmitSlot, totalSlots: maxRetransmitSlot - firstAvailableBlock + 1 }; }
interface RetransmitPlan { startSlot: number; endSlot: number; totalSlots: number; availableSlots: number[]; missingSlots: number[]; } async function planRetransmission( targetSlots: number[] ): Promise<RetransmitPlan> { const maxRetransmitSlot = await connection.getMaxRetransmitSlot(); const firstAvailableBlock = await connection.getFirstAvailableBlock(); const availableSlots = targetSlots.filter( slot => slot >= firstAvailableBlock && slot <= maxRetransmitSlot ); const missingSlots = targetSlots.filter( slot => slot < firstAvailableBlock || slot > maxRetransmitSlot ); return { startSlot: firstAvailableBlock, endSlot: maxRetransmitSlot, totalSlots: maxRetransmitSlot - firstAvailableBlock + 1, availableSlots, missingSlots }; }
interface SlotAlert { type: 'pruned' | 'unavailable'; message: string; slot: number; maxRetransmitSlot: number; } class SlotMonitor { private previousMaxSlot: number | null = null; async monitorSlots( targetSlots: number[] ): Promise<SlotAlert[]> { const maxRetransmitSlot = await connection.getMaxRetransmitSlot(); const alerts: SlotAlert[] = []; // Check for pruned slots if (this.previousMaxSlot !== null && maxRetransmitSlot < this.previousMaxSlot) { alerts.push({ type: 'pruned', message: `Slots ${maxRetransmitSlot + 1} to ${this.previousMaxSlot} have been pruned`, slot: this.previousMaxSlot, maxRetransmitSlot }); } // Check target slots availability for (const slot of targetSlots) { if (slot > maxRetransmitSlot) { alerts.push({ type: 'unavailable', message: `Slot ${slot} is beyond max retransmit slot`, slot, maxRetransmitSlot }); } } this.previousMaxSlot = maxRetransmitSlot; return alerts; } }
interface HistoricalData { availableRange: { start: number; end: number; total: number; }; prunedSlots: number[]; availableSlots: number[]; metadata: { timestamp: number; maxRetransmitSlot: number; }; } async function manageHistoricalData( targetRange: { start: number; end: number } ): Promise<HistoricalData> { const maxRetransmitSlot = await connection.getMaxRetransmitSlot(); const firstAvailableBlock = await connection.getFirstAvailableBlock(); const availableSlots = []; const prunedSlots = []; for (let slot = targetRange.start; slot <= targetRange.end; slot++) { if (slot >= firstAvailableBlock && slot <= maxRetransmitSlot) { availableSlots.push(slot); } else { prunedSlots.push(slot); } } return { availableRange: { start: firstAvailableBlock, end: maxRetransmitSlot, total: maxRetransmitSlot - firstAvailableBlock + 1 }, prunedSlots, availableSlots, metadata: { timestamp: Date.now(), maxRetransmitSlot } }; }