store

package
v0.6.5 Latest Latest
Warning

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

Go to latest
Published: Jun 10, 2025 License: MIT Imports: 12 Imported by: 0

Documentation

Index

Constants

View Source
const (
	ErrFailedBatchCommit = "failed to commit batch: %v"
)
View Source
const (
	ErrNotLeafNode = "not a leaf node"
)

Variables

View Source
var (
	ErrBlockNotFound  = errors.New("block not found")
	ErrHeaderNotFound = errors.New("header not found")
)
View Source
var ErrWorkReportNotFound = errors.New("work-report not found")

Functions

func PrefixToString

func PrefixToString(p byte) string

PrefixToString converts a prefix byte to a string

Types

type Chain

type Chain struct {
	db.KVStore
}

Chain manages blockchain storage using a key-value store

func NewChain

func NewChain(db db.KVStore) *Chain

NewChain creates a new chain store using KVStore

func (*Chain) FindChildren

func (c *Chain) FindChildren(parentHash crypto.Hash) ([]block.Block, error)

FindChildren finds all immediate child blocks for a given block hash

func (*Chain) FindHeader

func (c *Chain) FindHeader(fn func(header block.Header) bool) (block.Header, error)

FindHeader searches for a header that matches the given predicate function. Returns the first matching header and nil error if found. Returns zero header and nil error if no match is found. Returns zero header and error if the chain is closed or if database operations fail.

func (*Chain) GetBlock

func (c *Chain) GetBlock(hash crypto.Hash) (block.Block, error)

GetBlock retrieves a block by its header hash

func (*Chain) GetBlockSequence

func (c *Chain) GetBlockSequence(startHash crypto.Hash, ascending bool, maxBlocks uint32) ([]block.Block, error)

GetBlockSequence retrieves a sequence of blocks. If ascending is true, returns children of the start block (exclusive). If ascending is false, returns the start block and its ancestors (inclusive).

func (*Chain) GetHeader

func (c *Chain) GetHeader(hash crypto.Hash) (block.Header, error)

GetHeader retrieves a header by its hash

func (*Chain) PutBlock

func (c *Chain) PutBlock(b block.Block) error

PutBlock stores a block and its header atomically

func (*Chain) PutHeader

func (c *Chain) PutHeader(h block.Header) error

PutHeader stores a header in the chain store

type KeyValuePair

type KeyValuePair struct {
	Key   [31]byte
	Value []byte
}

KeyValuePair represents a single key-value pair from the trie

type Shards

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

Shards responsible for storing the bundle and segments shards and justifications

func NewShards

func NewShards(db db.KVStore) *Shards

NewShards creates a new availability store

func (*Shards) GetAuditShard

func (a *Shards) GetAuditShard(erasureRoot crypto.Hash, shardIndex uint16) ([]byte, error)

GetAuditShard gets an audit shard by erasure root and shard index

func (*Shards) GetJustification

func (a *Shards) GetJustification(erasureRoot crypto.Hash, shardIndex uint16) ([][]byte, error)

GetJustification gets a justification by erasure root and shard index

func (*Shards) GetSegmentsShard

func (a *Shards) GetSegmentsShard(erasureRoot crypto.Hash, shardIndex uint16) ([][]byte, error)

GetSegmentsShard gets a segment shard by erasure root and shard index

func (*Shards) PutAllShardsAndJustifications

func (a *Shards) PutAllShardsAndJustifications(erasureRoot crypto.Hash, bundleShards [][]byte, segmentsShards [][][]byte, justifications [][][]byte) error

PutAllShardsAndJustifications stores all segment shards, audit bundle shards and justification in one batch for an erasure root we assume that the number of shards is the same for bundleShard, segmentsShard and justifications, this should be checked before calling the method

func (*Shards) PutShardsAndJustification

func (a *Shards) PutShardsAndJustification(erasureRoot crypto.Hash, shardIndex uint16, bundleShard []byte, segmentsShard [][]byte, justification [][]byte) error

PutShardsAndJustification stores segment shards, audit bundle shards and justification in one batch for an erasure root and shard index

type Ticket

type Ticket struct {
	db.KVStore
}

func NewTicket

func NewTicket(db db.KVStore) *Ticket

NewTicket creates a new ticket store using KVStore

func (*Ticket) DeleteTicket

func (t *Ticket) DeleteTicket(epoch uint32, hash crypto.BandersnatchOutputHash) error

DeleteTicket removes a ticket from the ticket store

func (*Ticket) DeleteTicketsForEpoch

func (t *Ticket) DeleteTicketsForEpoch(epoch uint32) error

DeleteTicketsForEpoch removes all tickets for a given epoch

func (*Ticket) GetTicket

func (t *Ticket) GetTicket(epoch uint32, hash crypto.BandersnatchOutputHash) (block.TicketProof, error)

GetTicket retrieves a ticket from the ticket store

func (*Ticket) GetTicketsForEpoch

func (t *Ticket) GetTicketsForEpoch(epoch uint32) ([]block.TicketProof, error)

GetTicketsForEpoch retrieves all tickets for a given epoch

func (*Ticket) PutTicket

func (t *Ticket) PutTicket(epoch uint32, ticket block.TicketProof, hash crypto.BandersnatchOutputHash) error

PutTicket stores a ticket in the ticket store

type Trie

type Trie struct {
	db.KVStore
}

func NewTrie

func NewTrie(store db.KVStore) *Trie

func (*Trie) DecreaseNodeRefCount

func (t *Trie) DecreaseNodeRefCount(hash crypto.Hash) (uint64, error)

DecreaseNodeRefCount decrements the reference count for a node Returns the new count and any error

func (*Trie) DeleteTrie

func (t *Trie) DeleteTrie(rootHash crypto.Hash) error

DeleteTrie deletes a trie from the database starting from the root hash

func (*Trie) FetchStateTrieRange

func (t *Trie) FetchStateTrieRange(rootHash crypto.Hash, startKey, endKey [31]byte, maxSize uint32) (TrieRangeResult, error)

FetchStateTrieRange retrieves a range of key-value pairs from the trie starting at startKey and ending at or before endKey. It also returns boundary nodes covering the paths from root to the start key and to the last key in the response. The response size is limited to maxSize bytes, unless the response contains only a single key/value pair.

func (*Trie) GetNode

func (t *Trie) GetNode(hash crypto.Hash) (trie.Node, error)

Get retrieves a node from the database using its hash

func (*Trie) GetNodeRefCount

func (t *Trie) GetNodeRefCount(hash crypto.Hash) (uint64, error)

GetNodeRefCount returns the reference count for a node /how many nodes links to this one (how many tries)/.

func (*Trie) GetNodeValue

func (t *Trie) GetNodeValue(node trie.Node) ([]byte, error)

GetNodeValue retrieves the value from a node /regular and embedded leaf/

func (*Trie) IncreaseNodeRefCount

func (t *Trie) IncreaseNodeRefCount(hash crypto.Hash) error

IncreaseNodeRefCount increments the reference count for a node

func (*Trie) MerklizeAndCommit

func (t *Trie) MerklizeAndCommit(pairs [][2][]byte) (crypto.Hash, error)

MerklizeAndCommit writes a series of key-value pairs to the trie

func (*Trie) TrieExists

func (t *Trie) TrieExists(rootHash crypto.Hash) (bool, error)

TrieExists checks if a trie with the given root hash exists

type TrieRangeResult

type TrieRangeResult struct {
	Pairs         []KeyValuePair // The key-value pairs in the range
	BoundaryNodes []trie.Node    // Boundary nodes covering the paths from root to the edges
}

TrieRangeResult represents the result of a trie range query

type WorkReport

type WorkReport struct {
	db.KVStore
}

WorkReport manages work reports storage using a key-value store

func NewWorkReport

func NewWorkReport(db db.KVStore) *WorkReport

NewWorkReport creates a new work report store using KVStore

func (*WorkReport) DeleteWorkReport

func (r *WorkReport) DeleteWorkReport(h crypto.Hash) error

func (*WorkReport) GetWorkReport

func (r *WorkReport) GetWorkReport(h crypto.Hash) (block.WorkReport, error)

GetWorkReport fetches a work-report by hash.

func (*WorkReport) PutWorkReport

func (r *WorkReport) PutWorkReport(report block.WorkReport) error

PutWorkReport stores a work report in the chain store

Jump to

Keyboard shortcuts

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