bpt

package
v1.2.0-rc.1 Latest Latest
Warning

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

Go to latest
Published: Jul 5, 2023 License: MIT Imports: 20 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func ForEach

func ForEach(b *BPT, fn func(key record.KeyHash, hash [32]byte) error) error

ForEach calls the callback for each BPT entry.

func LoadSnapshotV1

func LoadSnapshotV1(b *BPT, file ioutil2.SectionReader, storeState func(key storage.Key, hash [32]byte, reader ioutil2.SectionReader) error) error

LoadSnapshotV1 restores a snapshot to the BPT

func ReadSnapshotV1

func ReadSnapshotV1(file ioutil2.SectionReader, storeState func(key storage.Key, hash [32]byte, reader ioutil2.SectionReader) error) error

ReadSnapshotV1 reads a snapshot

func SaveSnapshotV1

func SaveSnapshotV1(b *BPT, file io.WriteSeeker, loadState func(key storage.Key, hash [32]byte) ([]byte, error)) error

SaveSnapshotV1 Saves a snapshot of the state of the BVN/DVN. 1) The first thing done is copy the entire BVN and persist it to disk 2) Then all the states are pulled from the database and persisted. As long as the BVN is captured in its entirety within a block, the states can be persisted over other blocks (as long as we don't delete any of those states

Snapshot Format:

8 byte count of nodes (NumNodes)
[count of nodes]node   -- each node is a Fixed length
[count of nodes]value  -- each value is variable length

node:

32 byte Key    -- 8 byte offset from end of nodes to value
32 byte Hash   -- Hash of the value of the BPT entry
8  byte offset -- from end of list of nodes to start of the value

value:

8  byte                  -- length of value
n  [length of value]byte -- the bytes of the value

Types

type BPT

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

func New

func New(parent database.Record, logger log.Logger, store database.Store, key *database.Key, label string) *BPT

New returns a new BPT.

func (*BPT) Commit

func (b *BPT) Commit() error

Commit commits the BPT.

func (*BPT) Delete added in v1.2.0

func (b *BPT) Delete(key [32]byte) error

Delete removes the entry for the given key, if present. Delete may defer the actual update.

func (*BPT) Get

func (b *BPT) Get(key [32]byte) ([32]byte, error)

Get retrieves the latest hash associated with the given key.

func (*BPT) GetReceipt

func (b *BPT) GetReceipt(key [32]byte) (*merkle.Receipt, error)

GetReceipt Returns the receipt for the current state for the given chainID

func (*BPT) GetRootHash

func (b *BPT) GetRootHash() ([32]byte, error)

GetRootHash returns the root hash of the BPT, loading nodes, executing pending updates, and recalculating hashes if necessary.

func (*BPT) Insert

func (b *BPT) Insert(key, hash [32]byte) error

Insert updates or inserts a hash for the given key. Insert may defer the actual update.

func (*BPT) IsDirty

func (b *BPT) IsDirty() bool

IsDirty returns true if the BPT has pending updates.

func (*BPT) Iterate

func (b *BPT) Iterate(window int) *Iterator

Iterate returns an iterator that iterates over the BPT, reading N entries at a time where N = window. Iterate panics if window is negative or zero.

func (*BPT) Key

func (c *BPT) Key() *record.Key

func (*BPT) Resolve

func (b *BPT) Resolve(key *database.Key) (database.Record, *database.Key, error)

Resolve implements database.Record.

func (*BPT) Walk

func (b *BPT) Walk(opts database.WalkOptions, fn database.WalkFunc) error

WalkChanges implements [record.Record].

type Iterator

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

Iterator iterates over the BPT.

func (*Iterator) Err

func (it *Iterator) Err() error

Err returns the error if one has occurred.

func (*Iterator) Next

func (it *Iterator) Next() bool

Next returns the next N results. Next returns false if there are no more results or if an error occurs. The caller must return Err after Next returns false to check for an error.

func (*Iterator) Value added in v1.2.0

func (it *Iterator) Value() []KeyValuePair

type KeyValuePair

type KeyValuePair struct {
	Key, Value [32]byte
}

Jump to

Keyboard shortcuts

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