bitcoinspv

package
v0.0.0-...-420fffb Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Sep 23, 2025 License: MPL-2.0 Imports: 20 Imported by: 0

README

Bitcoin-SPV

This relayer is responsible for syncing the SPV Light Client with a BTC node.

Setup

Dependencies
Run bitcoind node and bitcoin-lightclient

Usage

Make sure bitcoind is working

Query blockchain info:

bitcoin-cli -regtest -rpcuser=user -rpcpassword=password getblockchaininfo
Start the relayer
  • Build the bitcoin-spv binary:

    go build ./cmd/bitcoin-spv
    
  • Start the relayer:

    ./bitcoin-spv start --config ./sample-bitcoin-spv.yml
    

Relayer Flow

Following diagram explains how the bitcoin-SPV relayer interacts with BitcoinNode and LightClient and how data flows from Bitcoin node to Light Client through the SPV relayer.

Connecting
flowchart TD
    A["Bitcoin full node"] <-- 1 Connect --> B("Native SPV relayer")
    B <-- 2 Connect --> D["SPV lightclient"]
    B -- 3 Sync blocks --> D
    B <-. 4 New events listen .-> A
Sending block headers
flowchart TD
    A["Bitcoin full node"] -. 1 New blocks .-> B("Native SPV relayer")
    B -- 2 Send blockheader --> D["SPV lightclient"]

Documentation

Index

Constants

This section is empty.

Variables

View Source
var ErrRetryTimeout = errors.New("retry timed out after maximum duration")

ErrRetryTimeout indicates that the operation failed after all retry attempts.

Functions

func RetryDo

func RetryDo(
	logger zerolog.Logger,
	sleep time.Duration,
	maxSleepDuration time.Duration,
	retryableFunc func() error,
) error

RetryDo executes a func with retry

Types

type Chunk

type Chunk struct {
	Headers []wire.BlockHeader
	From    int64
	To      int64
}

Chunk represents a batch of block headers to be sent to the light client.

type ErrorCategory

type ErrorCategory int

ErrorCategory classifies errors for retry logic.

type Relayer

type Relayer struct {
	// Configuration
	Config *config.RelayerConfig
	// contains filtered or unexported fields
}

Relayer manages the Bitcoin SPV relayer functionality

func New

func New(
	cfg *config.RelayerConfig,
	parentLogger zerolog.Logger,
	btcClient clients.BTCClient,
	lcClient clients.BitcoinSPV,
	walrusHandler *WalrusHandler,
	btcIndexer btcindexer.Indexer,
) (*Relayer, error)

New creates and returns a new relayer object

func (*Relayer) FindFirstUnknownHeaderIndex

func (r *Relayer) FindFirstUnknownHeaderIndex(ctx context.Context, indexedBlocks []*types.IndexedBlock) (int, error)

FindFirstUnknownHeaderIndex finds the index of the first header not present in the light client.

func (*Relayer) ProcessHeaders

func (r *Relayer) ProcessHeaders(ctx context.Context, indexedBlocks []*types.IndexedBlock) (int, error)

ProcessHeaders takes a list of blocks, extracts their headers and submits them to the light client. Returns the count of unique headers that were submitted.

func (*Relayer) Start

func (r *Relayer) Start()

Start initializes and launches the SPV relayer goroutines for Bitcoin header verification and relay

func (*Relayer) Stop

func (r *Relayer) Stop()

Stop signals all spv relayer goroutines to shutdown. if already stopped, this is a no-op.

func (*Relayer) UploadToWalrus

func (r *Relayer) UploadToWalrus(msgBlock *wire.MsgBlock, blockHeight int64, blockHashStr string)

UploadToWalrus upload full BTC block to Walrus

func (*Relayer) WaitForShutdown

func (r *Relayer) WaitForShutdown()

WaitForShutdown waits for all relayer goroutines to complete before returning

type WalrusHandler

type WalrusHandler struct {
	// contains filtered or unexported fields
}

WalrusHandler wraps the Walrus client

func NewWalrusHandler

func NewWalrusHandler(cfg *config.RelayerConfig, parentLogger zerolog.Logger) (*WalrusHandler, error)

NewWalrusHandler creates and initializes a new WalrusHandler, nil if not enabled

func (*WalrusHandler) StoreBlock

func (wh *WalrusHandler) StoreBlock(
	rawBlockData []byte,
	blockHeight int64,
	blockHashStr string,
) (*string, error)

StoreBlock attempts to store the raw block data in Walrus.

Directories

Path Synopsis
btcwrapper/zmq
Package zmq reference is taken from https://github.com/joakimofv/go-bitcoindclient which is a go wrapper around official zmq package https://github.com/pebbe/zmq4
Package zmq reference is taken from https://github.com/joakimofv/go-bitcoindclient which is a go wrapper around official zmq package https://github.com/pebbe/zmq4
sui
btc

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL