参数
此方法不接受任何参数。响应
可重新传输的最高 slot
代码示例
基本请求
复制
curl https://fra.rpc.orbitflare.com?api_key=YOUR-API-KEY -X POST -H "Content-Type: application/json" -d '{
"jsonrpc": "2.0",
"id": 1,
"method": "getMaxRetransmitSlot"
}'
使用 web3.js
复制
import { Connection } from '@solana/web3.js';
const connection = new Connection('https://fra.rpc.orbitflare.com?api_key=YOUR-API-KEY');
// 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
};
}
注意事项
- 返回可重新传输的最高 slot
- 用于确定可重新传输的 slot 范围
- 响应是即时的,因为它从当前状态读取
- 超出此值的 slot 无法被重新传输
- 随着节点修剪旧数据,此值可能会改变
最佳实践
- 使用此方法确定重新传输的可用性
- 在适当时缓存结果以减少 RPC 负载
- 考虑 slot 修剪的影响
- 监控最大重传 slot 的变化
- 结合其他 slot 相关方法使用
常见错误
| 错误码 | 消息 | 解决方案 |
|---|---|---|
| -32601 | Method not found | 验证是否连接到 Solana RPC 节点 |
| -32007 | Slot information unavailable | 节点可能正在启动或同步中 |
用例
-
重传规划
复制
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 }; } -
Slot 可用性监控
复制
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 } }; }