blockstore

package
v0.0.0-...-7621e06 Latest Latest
Warning

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

Go to latest
Published: Feb 16, 2024 License: Apache-2.0 Imports: 10 Imported by: 2

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

This package requires Cgo to access RocksDB (via grocksdb).

Compatibility

We aim to support all Solana Rust versions since mainnet genesis. Test fixtures are added for each major revision.

Index

Constants

View Source
const (
	// CfDefault is the default column family, which is required by RocksDB.
	CfDefault = "default"

	// CfMeta contains slot metadata (SlotMeta)
	//
	// Similar to a block header, but not cryptographically authenticated.
	CfMeta = "meta"

	// CfErasureMeta contains erasure coding metadata
	CfErasureMeta = "erasure_meta"

	// CfRoot is a single cell specifying the current root slot number
	CfRoot = "root"

	// CfDataShred contains ledger data.
	//
	// One or more shreds make up a single entry.
	// The shred => entry surjection is indicated by SlotMeta.EntryEndIndexes
	CfDataShred = "data_shred"

	// CfCodeShred contains FEC shreds used to fix data shreds
	CfCodeShred = "code_shred"

	// CfDeadSlots contains slots that have been marked as dead
	CfDeadSlots = "dead_slots"

	CfBlockHeight = "block_height"

	CfBankHash = "bank_hashes"

	CfTxStatus = "transaction_status"

	CfTxStatusIndex = "transaction_status_index"

	CfAddressSig = "address_signatures"

	CfTxMemos = "transaction_memos"

	CfRewards = "rewards"

	CfBlockTime = "blocktime"

	CfPerfSamples = "perf_samples"

	CfProgramCosts = "program_costs"

	CfOptimisticSlots = "optimistic_slots"
)

Column families

Variables

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

Functions

func GetBincode

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

func GetDataShredsFromIter

func GetDataShredsFromIter(
	iter *grocksdb.Iterator,
	slot uint64,
	startIdx, endIdx uint32,
	revision int,
) ([]shred.Shred, error)

GetDataShredsFromIter is like GetDataShreds, but takes a custom iterator. The iterator must be seeked to the indicated slot/startIdx.

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 ParseShredKey

func ParseShredKey(key []byte) (slot uint64, index uint64, ok bool)

ParseShredKey decodes the RocksDB keys in CfDataShred or CfCodeShred.

func ParseSlotKey

func ParseSlotKey(key []byte) (slot uint64, ok bool)

ParseSlotKey decodes the RocksDB keys in CfMeta, CfRoot.

Types

type BlockWalk

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

BlockWalk walks blocks in ascending order over multiple RocksDB databases.

func NewBlockWalk

func NewBlockWalk(handles []WalkHandle, shredRevision int) (*BlockWalk, error)

func (*BlockWalk) Close

func (m *BlockWalk) Close()

func (*BlockWalk) Current

func (m *BlockWalk) Current() *DB

func (*BlockWalk) Entries

func (m *BlockWalk) Entries(meta *SlotMeta) ([][]shred.Entry, error)

Entries returns the entries at the current cursor. Caller must have made an ok call to BlockWalk.Next before calling this.

func (*BlockWalk) Next

func (m *BlockWalk) Next() (meta *SlotMeta, ok bool)

Next seeks to the next slot.

func (*BlockWalk) Seek

func (m *BlockWalk) Seek(slot uint64) bool

Seek skips ahead to a specific slot. The caller must call BlockWalk.Next after Seek.

func (*BlockWalk) SlotsAvailable

func (m *BlockWalk) SlotsAvailable() (total uint64)

SlotsAvailable returns the number of contiguous slots that lay ahead.

type BlockWalkI

type BlockWalkI interface {
	Seek(slot uint64) (ok bool)
	SlotsAvailable() (total uint64)
	Next() (meta *SlotMeta, ok bool)
	Close()

	// Entries returns the block contents of a slot.
	//
	// The outer returned slice contains batches of entries.
	// Each batch is made up from multiple shreds and shreds and batches are aligned.
	// The SlotMeta.EntryEndIndexes mark the indexes of the last shreds in each batch,
	// thus `len(SlotMeta.EntryEndIndexes)` equals `len(batches)`.
	//
	// The inner slices are the entries in each shred batch, usually sized one.
	Entries(meta *SlotMeta) (batches [][]shred.Entry, err error)
}

BlockWalkI abstracts iterators over block data.

The main (and only) implementation in this package is BlockWalk.

type DB

DB is RocksDB wrapper

func OpenReadOnly

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

OpenReadOnly attaches to a blockstore in read-only mode.

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

func OpenReadWrite

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

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 (*grocksdb.DB).TryCatchUpWithPrimary.

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

func (*DB) Close

func (d *DB) Close()

func (*DB) GetAllCodeShreds

func (d *DB) GetAllCodeShreds(slot uint64) ([]shred.Shred, error)

func (*DB) GetAllDataShreds

func (d *DB) GetAllDataShreds(slot uint64, revision int) ([]shred.Shred, error)

func (*DB) GetCodeShred

func (d *DB) GetCodeShred(slot, index uint64) shred.Shred

func (*DB) GetDataShred

func (d *DB) GetDataShred(slot, index uint64, revision int) shred.Shred

func (*DB) GetDataShreds

func (d *DB) GetDataShreds(slot uint64, startIdx, endIdx uint32, revision int) ([]shred.Shred, error)

func (*DB) GetEntries

func (d *DB) GetEntries(meta *SlotMeta, shredRevision int) ([]Entries, error)

func (*DB) GetRawCodeShred

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

func (*DB) GetRawDataShred

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

func (*DB) GetSlotMeta

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

GetSlotMeta returns the shredding metadata of a given slot.

func (*DB) MaxRoot

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

MaxRoot returns the last known root slot.

type Entries

type Entries struct {
	Entries []shred.Entry
	Raw     []byte
	Shreds  []shred.Shred
}

func DataShredsToEntries

func DataShredsToEntries(meta *SlotMeta, shreds []shred.Shred) (entries []Entries, err error)

DataShredsToEntries reassembles shreds to entries containing transactions.

func (*Entries) Slot

func (e *Entries) Slot() uint64

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,flow"`
	IsConnected         bool     `yaml:"is_connected"`
	// shred indexes that mark the end of an entry (used for shreds => entry mapping)
	NumEntryEndIndexes uint64   `bin:"sizeof=EntryEndIndexes" yaml:"-"`
	EntryEndIndexes    []uint32 `yaml:"completed_data_indexes,flow"`
}

SlotMeta is data stored in CfMeta

func (*SlotMeta) IsFull

func (s *SlotMeta) IsFull() bool

type SubEntries

type SubEntries struct {
	Entries []shred.Entry
}

func (*SubEntries) UnmarshalWithDecoder

func (se *SubEntries) UnmarshalWithDecoder(decoder *bin.Decoder) (err error)

type WalkHandle

type WalkHandle struct {
	DB    *DB
	Start uint64
	Stop  uint64 // inclusive
}

Jump to

Keyboard shortcuts

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