Documentation ¶
Index ¶
- Constants
- Variables
- type BoltDBOptions
- type BoltDBStore
- func (s *BoltDBStore) Close() error
- func (s *BoltDBStore) Get(key []byte) (val []byte, err error)
- func (s *BoltDBStore) PutChangeSet(puts map[string][]byte, stores map[string][]byte) error
- func (s *BoltDBStore) Seek(rng SeekRange, f func(k, v []byte) bool)
- func (s *BoltDBStore) SeekGC(rng SeekRange, keep func(k, v []byte) bool) error
- type DBConfiguration
- type KeyPrefix
- type KeyValue
- type KeyValueExists
- type LevelDBOptions
- type LevelDBStore
- func (s *LevelDBStore) Close() error
- func (s *LevelDBStore) Get(key []byte) ([]byte, error)
- func (s *LevelDBStore) PutChangeSet(puts map[string][]byte, stores map[string][]byte) error
- func (s *LevelDBStore) Seek(rng SeekRange, f func(k, v []byte) bool)
- func (s *LevelDBStore) SeekGC(rng SeekRange, keep func(k, v []byte) bool) error
- type MemBatch
- type MemCachedStore
- func (s *MemCachedStore) Close() error
- func (s *MemCachedStore) Delete(key []byte)
- func (s *MemCachedStore) Get(key []byte) ([]byte, error)
- func (s *MemCachedStore) GetBatch() *MemBatch
- func (s *MemCachedStore) GetStorageChanges() map[string][]byte
- func (s *MemCachedStore) Persist() (int, error)
- func (s *MemCachedStore) PersistSync() (int, error)
- func (s *MemCachedStore) Put(key, value []byte)
- func (s *MemCachedStore) PutChangeSet(puts map[string][]byte, stores map[string][]byte) error
- func (s *MemCachedStore) Seek(rng SeekRange, f func(k, v []byte) bool)
- func (s *MemCachedStore) SeekAsync(ctx context.Context, rng SeekRange, cutPrefix bool) chan KeyValue
- type MemoryStore
- func (s *MemoryStore) Close() error
- func (s *MemoryStore) Get(key []byte) ([]byte, error)
- func (s *MemoryStore) PutChangeSet(puts map[string][]byte, stores map[string][]byte) error
- func (s *MemoryStore) Seek(rng SeekRange, f func(k, v []byte) bool)
- func (s *MemoryStore) SeekGC(rng SeekRange, keep func(k, v []byte) bool) error
- type Operation
- type SeekRange
- type Store
Constants ¶
const ( ExecBlock byte = 1 ExecTransaction byte = 2 )
Executable subtypes.
const ( // MaxStorageKeyLen is the maximum length of a key for storage items. MaxStorageKeyLen = 64 // MaxStorageValueLen is the maximum length of a value for storage items. // It is set to be the maximum value for uint16. MaxStorageValueLen = 65535 )
Variables ¶
var Bucket = []byte("DB")
Bucket represents bucket used in boltdb to store all the data.
var ErrKeyNotFound = errors.New("key not found")
ErrKeyNotFound is an error returned by Store implementations when a certain key is not found.
Functions ¶
This section is empty.
Types ¶
type BoltDBOptions ¶
type BoltDBOptions struct {
FilePath string `yaml:"FilePath"`
}
BoltDBOptions configuration for boltdb.
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 BoltDBOptions) (*BoltDBStore, error)
NewBoltDBStore returns a new ready to use BoltDB storage with created bucket.
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
PutChangeSet implements the Store interface.
type DBConfiguration ¶
type DBConfiguration struct { Type string `yaml:"Type"` LevelDBOptions LevelDBOptions `yaml:"LevelDBOptions"` BoltDBOptions BoltDBOptions `yaml:"BoltDBOptions"` }
DBConfiguration describes configuration for DB. Supported: 'levelDB', 'boltDB'.
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 STContractID KeyPrefix = 0x51 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 SYSStateJumpStage KeyPrefix = 0xc4 SYSVersion KeyPrefix = 0xf0 )
KeyPrefix constants.
type KeyValueExists ¶ added in v0.98.0
KeyValueExists represents key-value pair with indicator whether the item exists in the persistent storage.
type LevelDBOptions ¶
type LevelDBOptions struct {
DataDirectoryPath string `yaml:"DataDirectoryPath"`
}
LevelDBOptions configuration for LevelDB.
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 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
PutChangeSet 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
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
PutChangeSet implements the Store interface. Never returns an error.
type Operation ¶ added in v0.98.1
type Operation struct { // State can be Added, Changed or Deleted. State string `json:"state"` Key []byte `json:"key"` Value []byte `json:"value,omitempty"` }
Operation represents a single KV operation (add/del/change) performed in the DB.
func BatchToOperations ¶ added in v0.98.1
BatchToOperations converts a batch of changes into array of Operations.
type SeekRange ¶ added in v0.98.1
type SeekRange struct { // Prefix denotes the Seek's lookup key. // Empty Prefix is not supported. 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. 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 }
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 DBConfiguration) (Store, error)
NewStore creates storage with preselected in configuration database type.