Module sync

Source
Expand description

Manages synchronization with darkfid

§Sync Module

The sync module is responsible for synchronizing the explorer’s database with the Darkfi blockchain network. It ensures consistency between the explorer and the blockchain by fetching missing blocks, handling reorganizations (reorgs), and subscribing to live updates through Darkfi’s JSON-RPC service.

§Responsibilities

  • Block Synchronization: Handles fetching and storing blocks from a Darkfi blockchain node during startup or when syncing, ensuring the explorer stays synchronized with the latest confirmed blocks.
  • Real-Time Updates: Subscribes to Darkfi’s JSON-RPC notification service, allowing the explorer to process and sync new blocks as they are confirmed.
  • Reorg Handling: Detects and resolves blockchain reorganizations by identifying the last common block (in case of divergence) and re-aligning the explorer’s state with the latest blockchain state. Reorgs are an importnt part of synchronization because they prevent syncing invalid or outdated states, ensuring the explorer maintains an accurate view of a Darkfi blockchain network.

Functions§

subscribe_sync_blocks
Subscribes to darkfid’s JSON-RPC notification endpoint that serves new confirmed blocks. Upon receiving them, store them to the database.