> ## Documentation Index
> Fetch the complete documentation index at: https://www.helius.dev/docs/llms.txt
> Use this file to discover all available pages before exploring further.

# LaserStream 히스토리컬 리플레이: 누락된 데이터 백필

> 연결 끊김에서 복구하고 LaserStream의 히스토리컬 리플레이 기능으로 누락된 Solana 블록체인 데이터를 백필하세요. 트랜잭션을 놓치지 마세요.

<Info>
  **비트를 놓치지 마세요**: LaserStream의 히스토리컬 리플레이는 연결 끊김에서 복구하고 블록체인 활동의 지난 24시간 동안 누락된 데이터를 백필할 수 있도록 보장합니다.
</Info>

## 히스토리컬 리플레이란?

히스토리컬 리플레이는 최근 블록체인 데이터를 특정 시작점에서 재생할 수 있게 하는 LaserStream의 기능입니다. 이는 연결 끊김을 처리하고 실시간 앱에서 데이터의 연속성을 보장하는 데 유용합니다.

## 재생할 수 있는 최대 시간

어떤 커밋 수준에서도 최대 약 24시간 (\~216,000 슬롯)의 기록을 재생할 수 있습니다. 해당 기간 내에 `fromSlot`를 전달하면 LaserStream은 그 시점부터 현재까지 스트리밍합니다.

**오래된 리플레이는 완료된 데이터를 반환합니다.** LaserStream은 대략 지난 20분의 슬롯을 메모리에 유지하며, 그 이전의 모든 데이터는 완료된 블록만을 포함하는 히스토리컬 스토어에서 제공합니다. 따라서 \~20분 이상 지난 `fromSlot`를 재생하면 데이터는 완료된 체인을 반영합니다 — 그 범위에서 포크되거나 삭제된 슬롯, 슬롯 내 계정 업데이트는 볼 수 없습니다. 최근 \~20분 이내의 슬롯은 포크 및 슬롯 내 계정 업데이트를 포함한 진짜 커밋 의미를 제공합니다.

<Warning>
  **제한된 시간 창**: 히스토리컬 리플레이는 최근 \~24시간만을 다룹니다. 과거 임의 지점의 데이터를 재생할 수 없습니다.
</Warning>

<CardGroup cols={2}>
  <Card title="연결 끊김 처리" icon="clock-rotate-left">
    짧은 연결 끊김(최대 24시간) 동안 손실된 데이터 복구
  </Card>

  <Card title="응용 프로그램 부트스트랩" icon="rocket">
    최근 24시간의 컨텍스트로 응용 프로그램 시작
  </Card>

  <Card title="최근 이벤트 분석" icon="magnifying-glass">
    최근 트랜잭션 및 계정 변경 검토
  </Card>

  <Card title="최근 데이터로 테스트" icon="flask">
    테스트 및 개발에 실제 최근 데이터 사용
  </Card>
</CardGroup>

## 작동 방식

<Steps>
  <Step title="시작점 지정">
    `fromSlot` 파라미터를 사용하여 재생 시작점을 설정하세요 (마지막 \~216,000 슬롯 내에 있어야 함)
  </Step>

  <Step title="히스토리컬 데이터 스트리밍">
    LaserStream은 지정된 슬롯부터 모든 이벤트를 전달합니다
  </Step>

  <Step title="실시간으로 따라잡기">
    현재 슬롯에 도달할 때까지 히스토리컬 데이터를 스트리밍합니다
  </Step>

  <Step title="실시간 스트리밍 계속">
    실시간 데이터 스트리밍으로 매끄럽게 전환
  </Step>
</Steps>

<Note>
  **자동 재연결**: [LaserStream SDK](https://github.com/helius-labs/laserstream-sdk)는 자동으로 재연결 및 리플레이를 처리합니다. 추가 코드가 필요하지 않습니다!
</Note>

## 빠른 시작

<Tip>
  [Helius 대시보드](https://dashboard.helius.dev/laserstream)에서 LaserStream을 시작하세요. 메인넷은 비즈니스 또는 프로페셔널 플랜이 필요하며, Devnet은 개발자 이상에서 사용할 수 있습니다. 자세한 내용은 [요금제 및 가격](/docs/ko/billing/plans)을 참조하세요.
</Tip>

<Tabs>
  <Tab title="gRPC">
    ```typescript theme={"system"}
    import { subscribe, CommitmentLevel, LaserstreamConfig, SubscribeRequest } from 'helius-laserstream';

    // Pick a slot within the last ~216,000 slots (≈24 h). For a real start
    // value, call `getSlot` first and subtract however far back you want to replay.
    // Note: replays older than ~20 min return finalized data even at processed/confirmed;
    // slots within the last ~20 min carry true commitment semantics.
    const fromSlot = 419_800_000;

    const subscriptionRequest: SubscribeRequest = {
      transactions: {
        "token-filter": { // user-defined label for this filter
          accountInclude: ['TokenkegQfeZyiNwAJbNbGKPFXCWuBvf9Ss623VQ5DA'],
          vote: false,
          failed: false
        }
      },
      commitment: CommitmentLevel.CONFIRMED,
      accounts: {},
      slots: {},
      blocks: {},
      blocksMeta: {},
      entry: {},
      accountsDataSlice: [],
      fromSlot, // u64 slot number; must fall inside the replay window
    };

    const config: LaserstreamConfig = {
      apiKey: 'YOUR_API_KEY',
      endpoint: 'https://laserstream-mainnet-ewr.helius-rpc.com', // Choose your closest region
    };

    await subscribe(config, subscriptionRequest, 
      async (data) => {
        console.log('Received data:', data);
      }, 
      async (error) => {
        console.error('Error:', error);
      }
    );
    ```
  </Tab>
</Tabs>

## 구성 옵션

<ParamField path="fromSlot" type="number" required>
  `u64`로 재생을 시작할 슬롯 번호입니다. 재생 창(마지막 \~216,000 슬롯 / 현재 슬롯에서 \~24시간) 내에 있어야 합니다.

  **예시**: `currentSlot - 1000`

  **중요**: 창보다 오래된 슬롯을 전달하면 LaserStream은 요청을 `Operation was attempted past the valid range`로 거부합니다.
</ParamField>

## 사용 사례

<AccordionGroup>
  <Accordion title="짧은 연결 끊김 후 재연결">
    응용 프로그램이 짧은 연결 끊김(24시간 이내) 후 다시 연결되면, 히스토리컬 리플레이를 사용하여 데이터를 놓치지 않도록 할 수 있습니다. `getCurrentSlot`는 Helius RPC를 호출하며; `lastProcessedSlot`는 메모리 하단에 유지됩니다 — 응용 프로그램에 적합한 방식으로 이를 지속적으로 저장하세요 (Redis, Postgres, 파일 등).

    ```typescript theme={"system"}
    async function getCurrentSlot(): Promise<number> {
      const r = await fetch(`https://mainnet.helius-rpc.com/?api-key=${process.env.HELIUS_API_KEY}`, {
        method: 'POST',
        headers: { 'Content-Type': 'application/json' },
        body: JSON.stringify({ jsonrpc: '2.0', id: 1, method: 'getSlot', params: [{ commitment: 'confirmed' }] }),
      });
      const { result } = await r.json();
      return result as number;
    }

    // Load the last slot you processed from wherever you store it.
    let lastProcessedSlot = Number(process.env.LAST_PROCESSED_SLOT ?? 0);

    // Check if it's still within the replay window
    const currentSlot = await getCurrentSlot();
    const maxReplaySlot = currentSlot - 216_000;

    if (lastProcessedSlot < maxReplaySlot) {
      console.warn('Disconnection too long, some data may be lost');
      lastProcessedSlot = maxReplaySlot;
    }

    const subscriptionRequest: SubscribeRequest = {
      // ... your subscription config
      fromSlot: lastProcessedSlot, // pass as number, not string
    };

    await subscribe(config, subscriptionRequest,
      async (data) => {
        // your handler here
        if (data.transaction?.slot) {
          lastProcessedSlot = Number(data.transaction.slot);
          // persist `lastProcessedSlot` here so the next reconnect picks up
        }
      }
    );
    ```
  </Accordion>

  <Accordion title="최근 컨텍스트로 부트스트랩">
    최근 몇 분의 컨텍스트로 응용 프로그램 시작:

    ```typescript theme={"system"}
    // Get a slot from 10 minutes ago (within the 24-hour window)
    const currentSlot = await getCurrentSlot();
    const startSlot = currentSlot - 1500; // ~10 minutes ago

    const subscriptionRequest: SubscribeRequest = {
      // ... your subscription config
      fromSlot: startSlot, // u64 number
    };
    ```
  </Accordion>

  <Accordion title="최근 데이터로 테스트">
    테스트에 최근 히스토리컬 데이터 사용 (최근 24시간 제한):

    ```typescript theme={"system"}
    // Test with data from the last 5 minutes
    const currentSlot = await getCurrentSlot();
    const testStartSlot = currentSlot - 750; // ~5 minutes ago
    const testEndSlot = currentSlot - 150;   // ~1 minute ago

    const subscriptionRequest: SubscribeRequest = {
      // ... your subscription config
      fromSlot: testStartSlot, // u64 number
    };

    // Stop processing when reaching the test end slot
    const stream = await subscribe(config, subscriptionRequest,
      async (data) => {
        const slot = Number(data.transaction?.slot ?? data.account?.slot ?? 0);
        if (slot >= testEndSlot) {
          stream.cancel();
          return;
        }
        // your test handler here
      }
    );
    ```
  </Accordion>
</AccordionGroup>

## 다음 단계

<CardGroup cols={2}>
  <Card title="LaserStream gRPC" icon="bolt" href="/docs/ko/laserstream/grpc">
    gRPC 스트리밍 기능 및 특성에 대해 자세히 알아보세요
  </Card>

  <Card title="시작하기" icon="rocket" href="https://dashboard.helius.dev/laserstream">
    Helius 대시보드에서 LaserStream을 활성화하고 스트리밍을 시작하세요.
  </Card>

  <Card title="SDK 문서" icon="github" href="https://github.com/helius-labs/laserstream-sdk">
    전체 SDK 문서를 봅니다
  </Card>

  <Card title="지원 요청" icon="headset" href="/docs/ko/support">
    구현에 대한 도움 받기
  </Card>
</CardGroup>
