blockstore

package module
v0.0.1 Latest Latest
Warning

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

Go to latest
Published: Aug 13, 2022 License: Apache-2.0 Imports: 11 Imported by: 1 module, 1 package

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

README

solana-blockstore-go

Go Reference

Go client for Solana's blockstore database.

Supported functionality:

  • Slot metas
  • Last root
  • Last block height
  • Shreds
  • Blocks (without receipts)

Documentation

Overview

Package blockstore is a read-only client for the Solana blockstore database.

For the reference implementation in Rust, see here: https://docs.rs/solana-ledger/latest/solana_ledger/blockstore/struct.Blockstore.html

Supported Solana versions: v1.12.0

Index

Constants

View Source
const (
	CfDefault     = "default"
	CfMeta        = "meta"
	CfRoot        = "root"
	CfDeadSlots   = "dead_slots"
	CfBlockHeight = "block_height"
	CfDataShred   = "data_shred"
	CfCodeShred   = "code_shred"
)

Column families

Variables

View Source
var ErrDeadSlot = errors.New("dead slot")
View Source
var ErrInvalidShredData = errors.New("invalid shred data")
View Source
var ErrNotFound = errors.New("not found")

ErrNotFound is returned when no row is found.

Functions

func GetBincode

func GetBincode[T any](db *grocksdb.DB, cf *grocksdb.ColumnFamilyHandle, key []byte) (*T, error)

func MakeShredKey

func MakeShredKey(slot, index uint64) (key [16]byte)

MakeShredKey creates the RocksDB key for CfDataShred or CfCodeShred.

func MakeSlotKey

func MakeSlotKey(slot uint64) (key [8]byte)

MakeSlotKey creates the RocksDB key for CfMeta, CfRoot.

func MultiGetBincode

func MultiGetBincode[T any](db *grocksdb.DB, cf *grocksdb.ColumnFamilyHandle, key ...[]byte) ([]*T, error)

func ParseBincode

func ParseBincode[T any](data []byte) (*T, error)

func ParseSlotKey

func ParseSlotKey(key []byte) (uint64, error)

Types

type Block

type Block struct {
	BlockHash    solana.Hash
	ParentSlot   uint64
	Transactions []solana.Transaction
}

type CompletedRange

type CompletedRange struct {
	StartIndex uint32
	EndIndex   uint32
}

type DB

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

DB wraps a RocksDB database handle.

func OpenReadOnly

func OpenReadOnly(path string) (*DB, error)

OpenReadOnly attaches to a blockstore in read-only mode.

Attaching to running validators is supported but the DB will only be a point-in-time view at the time of attaching.

func OpenSecondary

func OpenSecondary(path string, secondaryPath string) (*DB, error)

OpenSecondary attaches to a blockstore in secondary mode.

Only read operations are allowed. Unlike OpenReadOnly, allows the user to catch up the DB using DB.TryCatchUpWithPrimary.

`secondaryPath` points to a directory where the secondary instance stores its info log.

func (*DB) Close

func (d *DB) Close()

Close releases the RocksDB client.

func (*DB) GetBlock

func (d *DB) GetBlock(slot uint64) (*Block, error)

func (*DB) GetBlockHeight

func (d *DB) GetBlockHeight() (uint64, error)

GetBlockHeight returns the last known root slot.

func (*DB) GetCodingShred

func (d *DB) GetCodingShred(slot, index uint64) (*grocksdb.Slice, error)

GetCodingShred returns the content of a given coding shred.

func (*DB) GetDataShred

func (d *DB) GetDataShred(slot, index uint64) (*grocksdb.Slice, error)

GetDataShred returns the content of a given data shred.

func (*DB) GetEntriesInDataBlock

func (d *DB) GetEntriesInDataBlock(slot uint64, startIndex uint32, endIndex uint32) ([]Entry, error)

func (*DB) GetSlotEntries

func (d *DB) GetSlotEntries(
	slot uint64,
	startIndex uint64,
	allowDeadSlots bool,
) (entries []Entry, numShreds uint64, isFull bool, err error)

GetSlotEntries returns the entry vector for the slot starting with `shred_start_index`, the number of shreds that comprise the entry vector, and whether the slot is full (consumed all shreds).

See https://docs.rs/solana-ledger/latest/solana_ledger/blockstore/struct.Blockstore.html#method.get_slot_entries_with_shred_info

func (*DB) GetSlotMeta

func (d *DB) GetSlotMeta(slot uint64) (*SlotMeta, error)

GetSlotMeta returns the shredding metadata of a given slot.

func (*DB) IsSlotDead

func (d *DB) IsSlotDead(slot uint64) (bool, error)

func (*DB) IterCodingShreds

func (d *DB) IterCodingShreds(opts *grocksdb.ReadOptions) *grocksdb.Iterator

IterCodingShreds creates an iterator over CfCodeShred.

Use MakeSlotKey to construct a prefix, or MakeShredKey to seek to a specific shred.

It's the caller's responsibility to close the iterator.

func (*DB) IterDataShreds

func (d *DB) IterDataShreds(opts *grocksdb.ReadOptions) *grocksdb.Iterator

IterDataShreds creates an iterator over CfDataShred.

Use MakeSlotKey to construct a prefix, or MakeShredKey to seek to a specific shred.

It's the caller's responsibility to close the iterator.

func (*DB) IterSlotMetas

func (d *DB) IterSlotMetas(opts *grocksdb.ReadOptions) IterBincode[SlotMeta]

IterSlotMetas creates an iterator over CfMeta.

Use MakeSlotKey to seek to a specific slot.

It's the caller's responsibility to close the iterator.

func (*DB) MaxRoot

func (d *DB) MaxRoot() (uint64, error)

MaxRoot returns the last known root slot.

func (*DB) MultiGetSlotMeta

func (d *DB) MultiGetSlotMeta(slots ...uint64) ([]*SlotMeta, error)

MultiGetSlotMeta does multiple GetSlotMeta calls.

func (*DB) TryCatchUpWithPrimary

func (d *DB) TryCatchUpWithPrimary() error

TryCatchUpWithPrimary updates the client's view of the database with the latest information.

Only works with DB opened using OpenSecondary.

type Entry

type Entry struct {
	NumHashes    uint64               `yaml:"num_hashes"`
	Hash         solana.Hash          `yaml:"hash"`
	NumTxns      uint64               `bin:"sizeof=Transactions" yaml:"-"`
	Transactions []solana.Transaction `yaml:"transactions"`
}

type IterBincode

type IterBincode[T any] struct {
	*grocksdb.Iterator
}

func (IterBincode[T]) Element

func (i IterBincode[T]) Element() (*T, error)

type SlotMeta

type SlotMeta struct {
	Slot                    uint64   `yaml:"-"`
	Consumed                uint64   `yaml:"consumed"`
	Received                uint64   `yaml:"received"`
	FirstShredTimestamp     uint64   `yaml:"first_shred_timestamp"`
	LastIndex               uint64   `yaml:"last_index"`  // optional, None being math.MaxUint64
	ParentSlot              uint64   `yaml:"parent_slot"` // optional, None being math.MaxUint64
	NumNextSlots            uint64   `bin:"sizeof=NextSlots" yaml:"-"`
	NextSlots               []uint64 `yaml:"next_slots"`
	IsConnected             bool     `yaml:"is_connected"`
	NumCompletedDataIndexes uint64   `bin:"sizeof=CompletedDataIndexes" yaml:"-"`
	CompletedDataIndexes    []uint32 `yaml:"completed_data_indexes"`
}

func (*SlotMeta) IsFull

func (s *SlotMeta) IsFull() bool

Directories

Path Synopsis
ledgertool module

Jump to

Keyboard shortcuts

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