storage

package
v0.107.0 Latest Latest
Warning

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

Go to latest
Published: Dec 3, 2024 License: MIT Imports: 18 Imported by: 2

Documentation

Index

Constants

View Source
const (
	ExecBlock       byte = 1
	ExecTransaction byte = 2
)

Executable subtypes.

Variables

View Source
var Bucket = []byte("DB")

Bucket represents bucket used in boltdb to store all the data.

View Source
var ErrKeyNotFound = errors.New("key not found")

ErrKeyNotFound is an error returned by Store implementations when a certain key is not found.

Functions

func BatchToOperations added in v0.98.1

func BatchToOperations(batch *MemBatch) []dboper.Operation

BatchToOperations converts a batch of changes into array of dboper.Operation.

Types

type BoltDBStore

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

BoltDBStore it is the storage implementation for storing and retrieving blockchain data.

func NewBoltDBStore

func NewBoltDBStore(cfg dbconfig.BoltDBOptions) (*BoltDBStore, error)

NewBoltDBStore returns a new ready to use BoltDB storage with created bucket.

func (*BoltDBStore) Close

func (s *BoltDBStore) Close() error

Close releases all db resources.

func (*BoltDBStore) Get

func (s *BoltDBStore) Get(key []byte) (val []byte, err error)

Get implements the Store interface.

func (*BoltDBStore) PutChangeSet added in v0.97.2

func (s *BoltDBStore) PutChangeSet(puts map[string][]byte, stores map[string][]byte) error

PutChangeSet implements the Store interface.

func (*BoltDBStore) Seek

func (s *BoltDBStore) Seek(rng SeekRange, f func(k, v []byte) bool)

Seek implements the Store interface.

func (*BoltDBStore) SeekGC added in v0.98.2

func (s *BoltDBStore) SeekGC(rng SeekRange, keep func(k, v []byte) bool) error

SeekGC implements the Store interface.

type KeyPrefix

type KeyPrefix uint8

KeyPrefix is a constant byte added as a prefix for each key stored.

const (
	DataExecutable KeyPrefix = 0x01
	// DataMPT is used for MPT node entries identified by Uint256.
	DataMPT KeyPrefix = 0x03
	// DataMPTAux is used to store additional MPT data like height-root
	// mappings and local/validated heights.
	DataMPTAux KeyPrefix = 0x04
	STStorage  KeyPrefix = 0x70
	// STTempStorage is used to store contract storage items during state sync process
	// in order not to mess up the previous state which has its own items stored by
	// STStorage prefix. Once state exchange process is completed, all items with
	// STStorage prefix will be replaced with STTempStorage-prefixed ones.
	STTempStorage                  KeyPrefix = 0x71
	STNEP11Transfers               KeyPrefix = 0x72
	STNEP17Transfers               KeyPrefix = 0x73
	STTokenTransferInfo            KeyPrefix = 0x74
	IXHeaderHashList               KeyPrefix = 0x80
	SYSCurrentBlock                KeyPrefix = 0xc0
	SYSCurrentHeader               KeyPrefix = 0xc1
	SYSStateSyncCurrentBlockHeight KeyPrefix = 0xc2
	SYSStateSyncPoint              KeyPrefix = 0xc3
	// SYSStateChangeStage is used to store the phase of a state changing process
	// which is one of the state jump or state reset. Its value is one byte containing
	// state reset / state jump stages bits (first seven bits are reserved for that)
	// and the last bit reserved for the state reset process marker (set to 1 on
	// unfinished state reset and to 0 on unfinished state jump).
	SYSStateChangeStage KeyPrefix = 0xc4
	SYSVersion          KeyPrefix = 0xf0
)

KeyPrefix constants.

type KeyValue

type KeyValue struct {
	Key   []byte
	Value []byte
}

KeyValue represents key-value pair.

type KeyValueExists added in v0.98.0

type KeyValueExists struct {
	KeyValue

	Exists bool
}

KeyValueExists represents key-value pair with indicator whether the item exists in the persistent storage.

type LevelDBStore

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

LevelDBStore is the official storage implementation for storing and retrieving blockchain data.

func NewLevelDBStore

func NewLevelDBStore(cfg dbconfig.LevelDBOptions) (*LevelDBStore, error)

NewLevelDBStore returns a new LevelDBStore object that will initialize the database found at the given path.

func (*LevelDBStore) Close

func (s *LevelDBStore) Close() error

Close implements the Store interface.

func (*LevelDBStore) Get

func (s *LevelDBStore) Get(key []byte) ([]byte, error)

Get implements the Store interface.

func (*LevelDBStore) PutChangeSet added in v0.97.2

func (s *LevelDBStore) PutChangeSet(puts map[string][]byte, stores map[string][]byte) error

PutChangeSet implements the Store interface.

func (*LevelDBStore) Seek

func (s *LevelDBStore) Seek(rng SeekRange, f func(k, v []byte) bool)

Seek implements the Store interface.

func (*LevelDBStore) SeekGC added in v0.98.2

func (s *LevelDBStore) SeekGC(rng SeekRange, keep func(k, v []byte) bool) error

SeekGC implements the Store interface.

type MemBatch

type MemBatch struct {
	Put     []KeyValueExists
	Deleted []KeyValueExists
}

MemBatch represents a changeset to be persisted.

type MemCachedStore

type MemCachedStore struct {
	MemoryStore
	// contains filtered or unexported fields
}

MemCachedStore is a wrapper around persistent store that caches all changes being made for them to be later flushed in one batch.

func NewMemCachedStore

func NewMemCachedStore(lower Store) *MemCachedStore

NewMemCachedStore creates a new MemCachedStore object.

func NewPrivateMemCachedStore added in v0.98.2

func NewPrivateMemCachedStore(lower Store) *MemCachedStore

NewPrivateMemCachedStore creates a new private (unlocked) MemCachedStore object. Private cached stores are closed after Persist.

func (*MemCachedStore) Close

func (s *MemCachedStore) Close() error

Close implements Store interface, clears up memory and closes the lower layer Store.

func (*MemCachedStore) Delete added in v0.98.2

func (s *MemCachedStore) Delete(key []byte)

Delete drops KV pair from the store. Never returns an error.

func (*MemCachedStore) Get

func (s *MemCachedStore) Get(key []byte) ([]byte, error)

Get implements the Store interface.

func (*MemCachedStore) GetBatch

func (s *MemCachedStore) GetBatch() *MemBatch

GetBatch returns currently accumulated changeset.

func (*MemCachedStore) GetStorageChanges added in v0.98.2

func (s *MemCachedStore) GetStorageChanges() map[string][]byte

GetStorageChanges returns all current storage changes. It can only be done for private MemCachedStore.

func (*MemCachedStore) Persist

func (s *MemCachedStore) Persist() (int, error)

Persist flushes all the MemoryStore contents into the (supposedly) persistent store ps. MemCachedStore remains accessible for the most part of this action (any new changes will be cached in memory).

func (*MemCachedStore) PersistSync added in v0.98.0

func (s *MemCachedStore) PersistSync() (int, error)

PersistSync flushes all the MemoryStore contents into the (supposedly) persistent store ps. It's different from Persist in that it blocks MemCachedStore completely while flushing things from memory to persistent store.

func (*MemCachedStore) Put added in v0.98.2

func (s *MemCachedStore) Put(key, value []byte)

Put puts new KV pair into the store.

func (*MemCachedStore) PutChangeSet added in v0.98.2

func (s *MemCachedStore) PutChangeSet(puts map[string][]byte, stores map[string][]byte) error

PutChangeSet implements the Store interface. Never returns an error.

func (*MemCachedStore) Seek

func (s *MemCachedStore) Seek(rng SeekRange, f func(k, v []byte) bool)

Seek implements the Store interface.

func (*MemCachedStore) SeekAsync added in v0.98.0

func (s *MemCachedStore) SeekAsync(ctx context.Context, rng SeekRange, cutPrefix bool) chan KeyValue

SeekAsync returns non-buffered channel with matching KeyValue pairs. Key and value slices may not be copied and may be modified. SeekAsync can guarantee that key-value items are sorted by key in ascending way.

type MemoryStore

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

MemoryStore is an in-memory implementation of a Store, mainly used for testing. Do not use MemoryStore in production.

func NewMemoryStore

func NewMemoryStore() *MemoryStore

NewMemoryStore creates a new MemoryStore object.

func (*MemoryStore) Close

func (s *MemoryStore) Close() error

Close implements Store interface and clears up memory. Never returns an error.

func (*MemoryStore) Get

func (s *MemoryStore) Get(key []byte) ([]byte, error)

Get implements the Store interface.

func (*MemoryStore) PutChangeSet added in v0.97.2

func (s *MemoryStore) PutChangeSet(puts map[string][]byte, stores map[string][]byte) error

PutChangeSet implements the Store interface. Never returns an error.

func (*MemoryStore) Seek

func (s *MemoryStore) Seek(rng SeekRange, f func(k, v []byte) bool)

Seek implements the Store interface.

func (*MemoryStore) SeekGC added in v0.98.2

func (s *MemoryStore) SeekGC(rng SeekRange, keep func(k, v []byte) bool) error

SeekGC implements the Store interface.

type SeekRange added in v0.98.1

type SeekRange struct {
	// Prefix denotes the Seek's lookup key.
	// If used directly with MemCachedStore's or MemoryStore's Seek, SeekAsync or
	// SeekGC empty Prefix is not supported due to internal MemoryStore cache
	// architecture; otherwise empty prefix can be used safely.
	Prefix []byte
	// Start denotes value appended to the Prefix to start Seek from.
	// Seeking starting from some key includes this key to the result;
	// if no matching key was found then next suitable key is picked up.
	// Start may be empty. Empty Start means seeking through all keys in
	// the DB with matching Prefix.
	// Empty Prefix and empty Start can be combined, which means seeking
	// through all keys in the DB, but see the Prefix's comment.
	Start []byte
	// Backwards denotes whether Seek direction should be reversed, i.e.
	// whether seeking should be performed in a descending way.
	// Backwards can be safely combined with Prefix and Start.
	Backwards bool
	// SearchDepth is the depth of Seek operation, denotes the number of cached
	// DAO layers to perform search. Use 1 to fetch the latest changes from upper
	// in-memory layer of cached DAO. Default 0 value denotes searching through
	// the whole set of cached layers.
	SearchDepth int
}

SeekRange represents options for Store.Seek operation.

type Store

type Store interface {
	Get([]byte) ([]byte, error)
	// PutChangeSet allows to push prepared changeset to the Store.
	PutChangeSet(puts map[string][]byte, stor map[string][]byte) error
	// Seek can guarantee that provided key (k) and value (v) are the only valid until the next call to f.
	// Seek continues iteration until false is returned from f.
	// Key and value slices should not be modified.
	// Seek can guarantee that key-value items are sorted by key in ascending way.
	Seek(rng SeekRange, f func(k, v []byte) bool)
	// SeekGC is similar to Seek, but the function should return true if current
	// KV pair should be kept and false if it's to be deleted; there is no way to
	// do an early exit here. SeekGC only works with the current Store, it won't
	// go down to layers below and it takes a full write lock, so use it carefully.
	SeekGC(rng SeekRange, keep func(k, v []byte) bool) error
	Close() error
}

Store is the underlying KV backend for the blockchain data, it's not intended to be used directly, you wrap it with some memory cache layer most of the time.

func NewStore

func NewStore(cfg dbconfig.DBConfiguration) (Store, error)

NewStore creates storage with preselected in configuration database type.

Directories

Path Synopsis
Package dbconfig is a micropackage that contains storage DB configuration options.
Package dbconfig is a micropackage that contains storage DB configuration options.
Package dboper contains a type used to represent single DB operation.
Package dboper contains a type used to represent single DB operation.

Jump to

Keyboard shortcuts

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