archive

package
v1.2.2 Latest Latest
Warning

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

Go to latest
Published: Dec 21, 2023 License: MIT Imports: 14 Imported by: 0

README

Archival Storage

The archival storage element of cardinal-storage tracks both the current state data of a blockchain and older, historic state (possibly to a genesis block, but not necessarily). It tracks a number of layers (128 by default) in-memory to be able to handle small reorgs quickly and efficiently (as well as serving requests about recent but not current blocks). As data is consolidated down onto the disk, it creates new versions of overwritten keys, using a roaring bitmap to track the blocks at which each value changed, in turn allowing it to determine which version of a value should be used for a given block.

In the event of reorgs larger than the in-memory set, the on-disk set can be rolled back to deal with reorgs. This implementation of archival storage does not support having multiple blocks at a given height - hypothetically a similar mechanism could be implemented to support forks / side chains, but it would be much more complicated, requiring more disk, more compute, and substantially more developer time.

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	HashToNumPrefix      = []byte("h")
	NumToHashPrefix      = []byte("n")
	NumberToWeightPrefix = []byte("w")
	RangePrefix          = []byte("r")
	DataPrefix           = []byte("v")
	ResumptionDataPrefix = []byte("e")
	RollbackPrefix       = []byte("u") // u for undo
	LatestBlockHashKey   = []byte("LatestBlockHash")
	LatestBlockWeightKey = []byte("LatestBlockWeight")
	MemoryPersistenceKey = []byte("MemoryPersistence")
)

Functions

func DataKey

func DataKey(key []byte, index uint64) []byte

func HashToNumKey

func HashToNumKey(h types.Hash) []byte

func New

func New(sdb db.Database, maxDepth int64, whitelist map[uint64]types.Hash) storage.Storage

New starts a archiveStorage instance from an empty database.

func NumToHashKey

func NumToHashKey(n uint64) []byte

func NumberToResumptionKey

func NumberToResumptionKey(n uint64) []byte

func NumberToWeightKey

func NumberToWeightKey(n uint64) []byte

func Open

func Open(sdb db.Database, maxDepth int64, whitelist map[uint64]types.Hash) (storage.Storage, error)

Open loads a archiveStorage instance from a loaded database

func RangeKey

func RangeKey(key []byte) []byte

func RollbackKey

func RollbackKey(n uint64) []byte

Types

type Initializer

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

func NewInitializer

func NewInitializer(db dbpkg.Database) *Initializer

func (*Initializer) AddData

func (init *Initializer) AddData(key, value []byte)

func (*Initializer) Close

func (init *Initializer) Close()

func (*Initializer) SetBlockData

func (init *Initializer) SetBlockData(hash, parentHash types.Hash, number uint64, weight *big.Int)

Jump to

Keyboard shortcuts

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