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
- Variables
- func GetBincode[T any](db *grocksdb.DB, cf *grocksdb.ColumnFamilyHandle, key []byte) (*T, error)
- func GetDataShredsFromIter(iter *grocksdb.Iterator, slot uint64, startIdx, endIdx uint32, revision int) ([]shred.Shred, error)
- func MakeShredKey(slot, index uint64) (key [16]byte)
- func MakeSlotKey(slot uint64) (key [8]byte)
- func MultiGetBincode[T any](db *grocksdb.DB, cf *grocksdb.ColumnFamilyHandle, key ...[]byte) ([]*T, error)
- func ParseBincode[T any](data []byte) (*T, error)
- func ParseShredKey(key []byte) (slot uint64, index uint64, ok bool)
- func ParseSlotKey(key []byte) (slot uint64, ok bool)
- type BlockWalk
- type BlockWalkI
- type DB
- func (d *DB) Close()
- func (d *DB) GetAllCodeShreds(slot uint64) ([]shred.Shred, error)
- func (d *DB) GetAllDataShreds(slot uint64, revision int) ([]shred.Shred, error)
- func (d *DB) GetCodeShred(slot, index uint64) shred.Shred
- func (d *DB) GetDataShred(slot, index uint64, revision int) shred.Shred
- func (d *DB) GetDataShreds(slot uint64, startIdx, endIdx uint32, revision int) ([]shred.Shred, error)
- func (d *DB) GetEntries(meta *SlotMeta, shredRevision int) ([]Entries, error)
- func (d *DB) GetRawCodeShred(slot, index uint64) (*grocksdb.Slice, error)
- func (d *DB) GetRawDataShred(slot, index uint64) (*grocksdb.Slice, error)
- func (d *DB) GetSlotMeta(slot uint64) (*SlotMeta, error)
- func (d *DB) MaxRoot() (uint64, error)
- type Entries
- type SlotMeta
- type SubEntries
- type WalkHandle
Constants ¶
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 ¶
Functions ¶
func GetBincode ¶
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 ¶
MakeShredKey creates the RocksDB key for CfDataShred or CfCodeShred.
func MakeSlotKey ¶
MakeSlotKey creates the RocksDB key for CfMeta, CfRoot.
func MultiGetBincode ¶
func ParseBincode ¶
func ParseShredKey ¶
ParseShredKey decodes the RocksDB keys in CfDataShred or CfCodeShred.
func ParseSlotKey ¶
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) Entries ¶
Entries returns the entries at the current cursor. Caller must have made an ok call to BlockWalk.Next before calling this.
func (*BlockWalk) Seek ¶
Seek skips ahead to a specific slot. The caller must call BlockWalk.Next after Seek.
func (*BlockWalk) SlotsAvailable ¶
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 ¶
type DB struct { DB *grocksdb.DB CfDefault *grocksdb.ColumnFamilyHandle CfMeta *grocksdb.ColumnFamilyHandle CfRoot *grocksdb.ColumnFamilyHandle CfDataShred *grocksdb.ColumnFamilyHandle CfCodeShred *grocksdb.ColumnFamilyHandle CfTxStatus *grocksdb.ColumnFamilyHandle }
DB is RocksDB wrapper
func OpenReadOnly ¶
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 OpenSecondary ¶
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) GetAllDataShreds ¶
func (*DB) GetDataShreds ¶
func (*DB) GetEntries ¶
func (*DB) GetRawCodeShred ¶
func (*DB) GetRawDataShred ¶
func (*DB) GetSlotMeta ¶
GetSlotMeta returns the shredding metadata of a given slot.
type Entries ¶
func DataShredsToEntries ¶
DataShredsToEntries reassembles shreds to entries containing transactions.
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
type SubEntries ¶
func (*SubEntries) UnmarshalWithDecoder ¶
func (se *SubEntries) UnmarshalWithDecoder(decoder *bin.Decoder) (err error)