Documentation ¶
Index ¶
- Variables
- func Update(d DB, fn func(txn Transaction) error) error
- func View(d DB, fn func(txn Transaction) error) error
- type Bucket
- type BufferedTransaction
- func (t *BufferedTransaction) Commit() error
- func (t *BufferedTransaction) Delete(key []byte) error
- func (t *BufferedTransaction) Discard() error
- func (t *BufferedTransaction) Flush() error
- func (t *BufferedTransaction) Get(key []byte, cb func([]byte) error) error
- func (t *BufferedTransaction) Impl() any
- func (t *BufferedTransaction) NewIterator() (Iterator, error)
- func (t *BufferedTransaction) Set(key, val []byte) error
- type DB
- type EventListener
- type Iterator
- type SelectiveListener
- type SyncTransaction
- func (t *SyncTransaction) Commit() error
- func (t *SyncTransaction) Delete(key []byte) error
- func (t *SyncTransaction) Discard() error
- func (t *SyncTransaction) Get(key []byte, cb func([]byte) error) error
- func (t *SyncTransaction) Impl() any
- func (t *SyncTransaction) NewIterator() (Iterator, error)
- func (t *SyncTransaction) Set(key, val []byte) error
- type Transaction
Constants ¶
This section is empty.
Variables ¶
var ErrKeyNotFound = errors.New("key not found")
ErrKeyNotFound is returned when key isn't found on a txn.Get.
Functions ¶
Types ¶
type Bucket ¶
type Bucket byte
const ( StateTrie Bucket = iota // state metadata (e.g., the state root) Unused // Previously held contract storage roots and is now unused. May be reused in the future. ContractClassHash // maps contract addresses and class hashes ContractStorage // contract storages Class // maps class hashes to classes ContractNonce // contract nonce ChainHeight // Latest height of the blockchain BlockHeaderNumbersByHash BlockHeadersByNumber TransactionBlockNumbersAndIndicesByHash // maps transaction hashes to block number and index TransactionsByBlockNumberAndIndex // maps block number and index to transaction ReceiptsByBlockNumberAndIndex // maps block number and index to transaction receipt StateUpdatesByBlockNumber ClassesTrie ContractStorageHistory ContractNonceHistory ContractClassHashHistory ContractDeploymentHeight L1Height SchemaVersion Pending BlockCommitments Temporary // used temporarily for migrations SchemaIntermediateState )
Pebble does not support buckets to differentiate between groups of keys like Bolt or MDBX does. We use a global prefix list as a poor man's bucket alternative.
type BufferedTransaction ¶ added in v0.4.1
type BufferedTransaction struct {
// contains filtered or unexported fields
}
BufferedTransaction buffers the updates in the memory to be later flushed to the underlying Transaction
func NewBufferedTransaction ¶ added in v0.4.1
func NewBufferedTransaction(txn Transaction) *BufferedTransaction
func (*BufferedTransaction) Commit ¶ added in v0.4.1
func (t *BufferedTransaction) Commit() error
Commit : see db.Transaction.Commit
func (*BufferedTransaction) Delete ¶ added in v0.4.1
func (t *BufferedTransaction) Delete(key []byte) error
Delete : see db.Transaction.Delete
func (*BufferedTransaction) Discard ¶ added in v0.4.1
func (t *BufferedTransaction) Discard() error
Discard : see db.Transaction.Discard
func (*BufferedTransaction) Flush ¶ added in v0.4.1
func (t *BufferedTransaction) Flush() error
Flush applies the pending changes to the underlying Transaction
func (*BufferedTransaction) Get ¶ added in v0.4.1
func (t *BufferedTransaction) Get(key []byte, cb func([]byte) error) error
Get : see db.Transaction.Get
func (*BufferedTransaction) Impl ¶ added in v0.4.1
func (t *BufferedTransaction) Impl() any
Impl : see db.Transaction.Impl
func (*BufferedTransaction) NewIterator ¶ added in v0.4.1
func (t *BufferedTransaction) NewIterator() (Iterator, error)
NewIterator : see db.Transaction.NewIterator
func (*BufferedTransaction) Set ¶ added in v0.4.1
func (t *BufferedTransaction) Set(key, val []byte) error
Set : see db.Transaction.Set
type DB ¶
type DB interface { io.Closer // NewTransaction returns a transaction on this database, it should block if an update transaction is requested // while another one is still in progress NewTransaction(update bool) (Transaction, error) // View creates a read-only transaction and calls fn with the given transaction // View should handle committing or discarding the transaction. Transaction should be discarded when fn // returns an error View(fn func(txn Transaction) error) error // Update creates a read-write transaction and calls fn with the given transaction // Update should handle committing or discarding the transaction. Transaction should be discarded when fn // returns an error Update(fn func(txn Transaction) error) error // Impl returns the underlying database object Impl() any // WithListener registers an EventListener WithListener(listener EventListener) DB }
DB is a key-value database
type EventListener ¶ added in v0.7.0
type Iterator ¶
type Iterator interface { io.Closer // Valid returns true if the iterator is positioned at a valid key/value pair. Valid() bool // Next moves the iterator to the next key/value pair. It returns whether the // iterator is valid after the call. Once invalid, the iterator remains // invalid. Next() bool // Key returns the key at the current position. Key() []byte // Value returns the value at the current position. Value() ([]byte, error) // Seek would seek to the provided key if present. If absent, it would seek to the next // key in lexicographical order Seek(key []byte) bool }
Iterator is an iterator over a DB's key/value pairs.
type SelectiveListener ¶ added in v0.7.0
type SelectiveListener struct { OnIOCb func(write bool, duration time.Duration) OnCommitCb func(duration time.Duration) }
func (*SelectiveListener) OnCommit ¶ added in v0.7.4
func (l *SelectiveListener) OnCommit(duration time.Duration)
type SyncTransaction ¶ added in v0.7.2
type SyncTransaction struct {
// contains filtered or unexported fields
}
func NewSyncTransaction ¶ added in v0.7.2
func NewSyncTransaction(txn Transaction) *SyncTransaction
func (*SyncTransaction) Commit ¶ added in v0.7.2
func (t *SyncTransaction) Commit() error
Commit : see db.Transaction.Commit
func (*SyncTransaction) Delete ¶ added in v0.7.2
func (t *SyncTransaction) Delete(key []byte) error
Delete : see db.Transaction.Delete
func (*SyncTransaction) Discard ¶ added in v0.7.2
func (t *SyncTransaction) Discard() error
Discard : see db.Transaction.Discard
func (*SyncTransaction) Get ¶ added in v0.7.2
func (t *SyncTransaction) Get(key []byte, cb func([]byte) error) error
Get : see db.Transaction.Get
func (*SyncTransaction) Impl ¶ added in v0.7.2
func (t *SyncTransaction) Impl() any
Impl : see db.Transaction.Impl
func (*SyncTransaction) NewIterator ¶ added in v0.7.2
func (t *SyncTransaction) NewIterator() (Iterator, error)
NewIterator : see db.Transaction.NewIterator
func (*SyncTransaction) Set ¶ added in v0.7.2
func (t *SyncTransaction) Set(key, val []byte) error
Set : see db.Transaction.Set
type Transaction ¶
type Transaction interface { // NewIterator returns an iterator over the database's key/value pairs. NewIterator() (Iterator, error) // Discard discards all the changes done to the database with this transaction Discard() error // Commit flushes all the changes pending on this transaction to the database, making the changes visible to other // transaction Commit() error // Set updates the value of the given key Set(key, val []byte) error // Delete removes the key from the database Delete(key []byte) error // Get fetches the value for the given key, should return ErrKeyNotFound if key is not present // Caller should not assume that the slice would stay valid after the call to cb Get(key []byte, cb func([]byte) error) error // Impl returns the underlying transaction object Impl() any }
Transaction provides an interface to access the database's state at the point the transaction was created Updates done to the database with a transaction should be only visible to other newly created transaction after the transaction is committed.
func NewMemTransaction ¶ added in v0.3.0
func NewMemTransaction() Transaction