Run NodesReferenceX

archivedb

Package archivedb

import "github.com/luxfi/node/x/archivedb"

Types

Database

Database implements an ArchiveDB on top of a database.Database. An ArchiveDB is an append only database which stores all state changes happening at every height. Each record is stored in such way to perform both fast insertions and lookups.

The API is quite simple, it has two main functions, one to create a Batch write with a given height, inside this batch entries can be added with a given value or they can be deleted.

The way it works is as follows:

  • NewBatch(10) batch.Put(foo, "foo's value is bar") batch.Put(bar, "bar's value is bar")
  • NewBatch(100) batch.Put(foo, "updatedfoo's value is bar")
  • NewBatch(1000) batch.Put(bar, "updated bar's value is bar") batch.Delete(foo)

The other primary function is to read data at a given height.

The way it works is as follows:

  • Open(10) reader.Get(foo) reader.Get(bar)
  • Open(99) reader.GetHeight(foo)
  • Open(100) reader.Get(foo)
  • Open(1000) reader.Get(foo)

Requesting reader.Get(foo) at height 1000 will return ErrNotFound because foo was deleted at height 1000. When calling reader.GetHeight(foo) at height 99 it will return a tuple ("foo's value is bar", 10) returning the value of foo at height 99 (which was set at height 10).

func New(db database.Database) *Database
func (db *Database) Close() error
func (db *Database) Compact(start []byte, limit []byte) error
func (db *Database) HealthCheck(ctx context.Context) (interface{}, error)
func (db *Database) Height() (uint64, error)
func (db *Database) NewBatch(height uint64) *batch
func (db *Database) Open(height uint64) *Reader

Reader

func (r *Reader) Get(key []byte) ([]byte, error)
func (r *Reader) GetEntry(key []byte) ([]byte, uint64, bool, error)
func (r *Reader) Has(key []byte) (bool, error)