跳转到主要内容

参数

此方法不接受任何参数。

响应

result
number
可重新传输的最高 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
  };
}

注意事项

  1. 返回可重新传输的最高 slot
  2. 用于确定可重新传输的 slot 范围
  3. 响应是即时的,因为它从当前状态读取
  4. 超出此值的 slot 无法被重新传输
  5. 随着节点修剪旧数据,此值可能会改变

最佳实践

  1. 使用此方法确定重新传输的可用性
  2. 在适当时缓存结果以减少 RPC 负载
  3. 考虑 slot 修剪的影响
  4. 监控最大重传 slot 的变化
  5. 结合其他 slot 相关方法使用

常见错误

错误码消息解决方案
-32601Method not found验证是否连接到 Solana RPC 节点
-32007Slot information unavailable节点可能正在启动或同步中

用例

  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
      };
    }
    
  2. 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;
      }
    }
    
  3. 历史数据管理
    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
        }
      };
    }