跳转到主要内容

参数

此方法不接受任何参数。

响应

result
number
可插入到 shred 数据库中的最高 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": "getMaxShredInsertSlot"
}'

使用 web3.js

import { Connection } from '@solana/web3.js';

const connection = new Connection('https://fra.rpc.orbitflare.com?api_key=YOUR-API-KEY');

// Get max shred insert slot
const maxShredInsertSlot = await connection.getMaxShredInsertSlot();
console.log('Max shred insert slot:', maxShredInsertSlot);

// Check if a slot can be inserted
async function canInsertSlot(slot: number) {
  const maxShredInsertSlot = await connection.getMaxShredInsertSlot();
  return slot <= maxShredInsertSlot;
}

// Get insert range
async function getInsertRange() {
  const maxShredInsertSlot = await connection.getMaxShredInsertSlot();
  const firstAvailableBlock = await connection.getFirstAvailableBlock();
  
  return {
    startSlot: firstAvailableBlock,
    endSlot: maxShredInsertSlot,
    totalSlots: maxShredInsertSlot - firstAvailableBlock + 1
  };
}

注意事项

  1. 返回可插入到 shred 数据库中的最高 slot
  2. 用于确定可进行 shred 插入的 slot 范围
  3. 响应是即时的,因为它从当前状态读取
  4. 超出此值的 slot 无法被插入
  5. 随着节点处理新的 slot,此值可能会改变

最佳实践

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

常见错误

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

用例

  1. Shred 插入规划
    interface InsertPlan {
      startSlot: number;
      endSlot: number;
      totalSlots: number;
      availableSlots: number[];
      unavailableSlots: number[];
    }
    
    async function planShredInsertion(
      targetSlots: number[]
    ): Promise<InsertPlan> {
      const maxShredInsertSlot = await connection.getMaxShredInsertSlot();
      const firstAvailableBlock = await connection.getFirstAvailableBlock();
      
      const availableSlots = targetSlots.filter(
        slot => slot >= firstAvailableBlock && slot <= maxShredInsertSlot
      );
      
      const unavailableSlots = targetSlots.filter(
        slot => slot < firstAvailableBlock || slot > maxShredInsertSlot
      );
      
      return {
        startSlot: firstAvailableBlock,
        endSlot: maxShredInsertSlot,
        totalSlots: maxShredInsertSlot - firstAvailableBlock + 1,
        availableSlots,
        unavailableSlots
      };
    }
    
  2. Slot 处理监控
    interface ProcessingAlert {
      type: 'lag' | 'gap' | 'unavailable';
      message: string;
      slot: number;
      maxShredInsertSlot: number;
    }
    
    class ProcessingMonitor {
      private previousMaxSlot: number | null = null;
      
      async monitorProcessing(
        targetSlots: number[]
      ): Promise<ProcessingAlert[]> {
        const maxShredInsertSlot = await connection.getMaxShredInsertSlot();
        const alerts: ProcessingAlert[] = [];
        
        // Check for processing lag
        if (this.previousMaxSlot !== null) {
          const expectedProgress = this.previousMaxSlot + 1;
          if (maxShredInsertSlot < expectedProgress) {
            alerts.push({
              type: 'lag',
              message: `Processing lag detected: expected ${expectedProgress}, got ${maxShredInsertSlot}`,
              slot: maxShredInsertSlot,
              maxShredInsertSlot
            });
          }
        }
        
        // Check target slots availability
        for (const slot of targetSlots) {
          if (slot > maxShredInsertSlot) {
            alerts.push({
              type: 'unavailable',
              message: `Slot ${slot} is beyond max shred insert slot`,
              slot,
              maxShredInsertSlot
            });
          }
        }
        
        this.previousMaxSlot = maxShredInsertSlot;
        return alerts;
      }
    }
    
  3. Shred 数据库管理
    interface ShredDatabaseMetrics {
      availableRange: {
        start: number;
        end: number;
        total: number;
      };
      processingRate: number;
      lag: number;
      metadata: {
        timestamp: number;
        maxShredInsertSlot: number;
      };
    }
    
    class ShredDatabaseManager {
      private previousMetrics: {
        timestamp: number;
        maxSlot: number;
      } | null = null;
      
      async getMetrics(): Promise<ShredDatabaseMetrics> {
        const maxShredInsertSlot = await connection.getMaxShredInsertSlot();
        const firstAvailableBlock = await connection.getFirstAvailableBlock();
        const currentTime = Date.now();
        
        let processingRate = 0;
        let lag = 0;
        
        if (this.previousMetrics !== null) {
          const timeDiff = (currentTime - this.previousMetrics.timestamp) / 1000; // seconds
          const slotDiff = maxShredInsertSlot - this.previousMetrics.maxSlot;
          processingRate = slotDiff / timeDiff;
          
          const currentSlot = await connection.getSlot();
          lag = currentSlot - maxShredInsertSlot;
        }
        
        this.previousMetrics = {
          timestamp: currentTime,
          maxSlot: maxShredInsertSlot
        };
        
        return {
          availableRange: {
            start: firstAvailableBlock,
            end: maxShredInsertSlot,
            total: maxShredInsertSlot - firstAvailableBlock + 1
          },
          processingRate,
          lag,
          metadata: {
            timestamp: currentTime,
            maxShredInsertSlot
          }
        };
      }
    }