database

package
v1.3.0 Latest Latest
Warning

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

Go to latest
Published: Mar 4, 2024 License: MIT Imports: 39 Imported by: 0

Documentation

Overview

For key value stores where buckets are not supported, we add a byte to the key to represent a bucket. For now, all buckets are hard coded, but we could change that in the future.

Buckets are not really enough to index everything we wish to index. So we have labels as well. Labels are shifted 8 bits left, so they can be combined with the buckets to create a unique key.

This allows us to put the raw directory block at DBlockBucket+L_raw, and meta data about the directory block at DBlockBucket+MetaLabel

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func GetReceipt added in v1.1.0

func GetReceipt(manager *MerkleManager, element Hash, anchor Hash) (r *merkle.Receipt, err error)

GetReceipt Given a merkle tree and two elements, produce a proof that the element was used to derive the DAG at the anchor Note that the element must be added to the Merkle Tree before the anchor, but the anchor can be any element after the element, or even the element itself.

func GetSignaturesForSigner added in v1.0.0

func GetSignaturesForSigner(transaction *Transaction, signer protocol.Signer) ([]protocol.Signature, error)

func Restore added in v1.2.10

func Restore(db Beginner, file ioutil.SectionReader, opts *RestoreOptions) error

func UpdateAccount added in v1.0.0

func UpdateAccount[T protocol.Account](batch *Batch, url *url.URL, fn func(T) error) (T, error)

Types

type Account

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

func (*Account) AnchorChain added in v1.0.0

func (c *Account) AnchorChain(partition string) *AccountAnchorChain

func (*Account) AnchorSequenceChain added in v1.0.0

func (c *Account) AnchorSequenceChain() *Chain2

func (*Account) BptChain added in v1.3.0

func (c *Account) BptChain() *Chain2

func (*Account) BptReceipt added in v1.0.0

func (a *Account) BptReceipt() (*merkle.Receipt, error)

BptReceipt builds a BPT receipt for the account.

func (*Account) ChainByName added in v1.0.0

func (a *Account) ChainByName(name string) (*Chain2, error)

ChainByName returns account Chain2 for the named chain, or a not found error if there is no such chain.

func (*Account) Chains added in v1.0.0

func (c *Account) Chains() values.Set[*protocol.ChainMetadata]

func (*Account) Commit added in v1.0.0

func (a *Account) Commit() error

func (*Account) Data

func (c *Account) Data() *AccountData

func (*Account) Directory added in v1.0.0

func (c *Account) Directory() values.Set[*url.URL]

func (*Account) Events added in v1.2.0

func (c *Account) Events() *AccountEvents

func (*Account) GetChainByName added in v1.0.0

func (a *Account) GetChainByName(name string) (*Chain, error)

GetChainByName calls ChainByName and Get.

func (*Account) GetIndexChainByName added in v1.0.0

func (a *Account) GetIndexChainByName(name string) (*Chain, error)

GetChainByName calls ChainByName, Index, and Get.

func (*Account) Hash added in v1.1.0

func (a *Account) Hash() ([32]byte, error)

Hash retrieves or calculates the state hash of the account.

func (*Account) IsDirty added in v1.0.0

func (c *Account) IsDirty() bool

func (*Account) Key added in v1.1.1

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

func (*Account) Main added in v1.0.0

func (c *Account) Main() values.Value[protocol.Account]

func (*Account) MainChain added in v1.0.0

func (c *Account) MainChain() *Chain2

func (*Account) MajorBlockChain added in v1.0.0

func (c *Account) MajorBlockChain() *Chain2

func (*Account) MarkDirty added in v1.2.4

func (r *Account) MarkDirty() error

MarkDirty artificially marks the account as dirty.

func (*Account) Pending added in v1.0.0

func (c *Account) Pending() values.Set[*url.TxID]

func (*Account) Resolve added in v1.0.0

func (c *Account) Resolve(key *record.Key) (record.Record, *record.Key, error)

func (*Account) RootChain added in v1.0.0

func (c *Account) RootChain() *Chain2

func (*Account) ScratchChain added in v1.0.0

func (c *Account) ScratchChain() *Chain2

func (*Account) SignatureChain added in v1.0.0

func (c *Account) SignatureChain() *Chain2

func (*Account) StateReceipt added in v0.5.1

func (a *Account) StateReceipt() (*merkle.Receipt, error)

StateReceipt returns a Merkle receipt for the account state in the BPT.

func (*Account) SyntheticAnchors added in v1.0.0

func (c *Account) SyntheticAnchors() values.Set[[32]byte]

func (*Account) SyntheticForAnchor added in v0.6.0

func (c *Account) SyntheticForAnchor(anchor [32]byte) values.Set[*url.TxID]

func (*Account) SyntheticSequenceChain added in v1.0.0

func (c *Account) SyntheticSequenceChain(partition string) *Chain2

func (*Account) Transaction added in v1.1.0

func (c *Account) Transaction(hash [32]byte) *AccountTransaction

func (*Account) UpdatedChains added in v1.0.2

func (a *Account) UpdatedChains() ([]*protocol.BlockEntry, error)

UpdatedChains returns a block entry for every chain updated in the current database batch.

func (*Account) Url added in v1.0.0

func (r *Account) Url() *url.URL

func (*Account) VerifyHash added in v1.0.0

func (a *Account) VerifyHash(hash []byte) error

func (*Account) Walk added in v1.1.1

func (c *Account) Walk(opts record.WalkOptions, fn record.WalkFunc) error

type AccountAnchorChain added in v1.0.0

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

func (*AccountAnchorChain) BPT added in v1.0.0

func (c *AccountAnchorChain) BPT() *Chain2

func (*AccountAnchorChain) Commit added in v1.0.0

func (c *AccountAnchorChain) Commit() error

func (*AccountAnchorChain) IsDirty added in v1.0.0

func (c *AccountAnchorChain) IsDirty() bool

func (*AccountAnchorChain) Key added in v1.1.1

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

func (*AccountAnchorChain) Resolve added in v1.0.0

func (c *AccountAnchorChain) Resolve(key *record.Key) (record.Record, *record.Key, error)

func (*AccountAnchorChain) Root added in v1.0.0

func (c *AccountAnchorChain) Root() *Chain2

func (*AccountAnchorChain) Walk added in v1.1.1

type AccountData added in v1.0.0

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

func (*AccountData) Commit added in v1.0.0

func (c *AccountData) Commit() error

func (*AccountData) Entry added in v1.0.0

func (c *AccountData) Entry() values.Counted[[32]byte]

func (*AccountData) IsDirty added in v1.0.0

func (c *AccountData) IsDirty() bool

func (*AccountData) Key added in v1.1.1

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

func (*AccountData) Resolve added in v1.0.0

func (c *AccountData) Resolve(key *record.Key) (record.Record, *record.Key, error)

func (*AccountData) Transaction added in v1.0.0

func (c *AccountData) Transaction(entryHash [32]byte) values.Value[[32]byte]

func (*AccountData) Walk added in v1.1.1

func (c *AccountData) Walk(opts record.WalkOptions, fn record.WalkFunc) error

type AccountEvents added in v1.2.0

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

func (*AccountEvents) BPT added in v1.2.0

func (c *AccountEvents) BPT() *bpt.BPT

func (*AccountEvents) Backlog added in v1.2.0

func (c *AccountEvents) Backlog() *AccountEventsBacklog

func (*AccountEvents) Commit added in v1.2.0

func (c *AccountEvents) Commit() error

func (*AccountEvents) IsDirty added in v1.2.0

func (c *AccountEvents) IsDirty() bool

func (*AccountEvents) Key added in v1.2.0

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

func (*AccountEvents) Major added in v1.2.0

func (c *AccountEvents) Major() *AccountEventsMajor

func (*AccountEvents) Minor added in v1.2.0

func (c *AccountEvents) Minor() *AccountEventsMinor

func (*AccountEvents) Resolve added in v1.2.0

func (c *AccountEvents) Resolve(key *record.Key) (record.Record, *record.Key, error)

func (*AccountEvents) Walk added in v1.2.0

type AccountEventsBacklog added in v1.2.0

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

func (*AccountEventsBacklog) Commit added in v1.2.0

func (c *AccountEventsBacklog) Commit() error

func (*AccountEventsBacklog) Expired added in v1.2.0

func (c *AccountEventsBacklog) Expired() values.Set[*url.TxID]

func (*AccountEventsBacklog) IsDirty added in v1.2.0

func (c *AccountEventsBacklog) IsDirty() bool

func (*AccountEventsBacklog) Key added in v1.2.0

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

func (*AccountEventsBacklog) Resolve added in v1.2.0

func (c *AccountEventsBacklog) Resolve(key *record.Key) (record.Record, *record.Key, error)

func (*AccountEventsBacklog) Walk added in v1.2.0

type AccountEventsMajor added in v1.2.0

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

func (*AccountEventsMajor) Blocks added in v1.2.0

func (c *AccountEventsMajor) Blocks() values.Set[uint64]

func (*AccountEventsMajor) Commit added in v1.2.0

func (c *AccountEventsMajor) Commit() error

func (*AccountEventsMajor) IsDirty added in v1.2.0

func (c *AccountEventsMajor) IsDirty() bool

func (*AccountEventsMajor) Key added in v1.2.0

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

func (*AccountEventsMajor) Pending added in v1.2.0

func (c *AccountEventsMajor) Pending(block uint64) values.Set[*url.TxID]

func (*AccountEventsMajor) Resolve added in v1.2.0

func (c *AccountEventsMajor) Resolve(key *record.Key) (record.Record, *record.Key, error)

func (*AccountEventsMajor) Walk added in v1.2.0

type AccountEventsMinor added in v1.2.0

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

func (*AccountEventsMinor) Blocks added in v1.2.0

func (c *AccountEventsMinor) Blocks() values.Set[uint64]

func (*AccountEventsMinor) Commit added in v1.2.0

func (c *AccountEventsMinor) Commit() error

func (*AccountEventsMinor) IsDirty added in v1.2.0

func (c *AccountEventsMinor) IsDirty() bool

func (*AccountEventsMinor) Key added in v1.2.0

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

func (*AccountEventsMinor) Resolve added in v1.2.0

func (c *AccountEventsMinor) Resolve(key *record.Key) (record.Record, *record.Key, error)

func (*AccountEventsMinor) Votes added in v1.2.0

func (*AccountEventsMinor) Walk added in v1.2.0

type AccountIterator added in v1.1.1

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

func (*AccountIterator) Err added in v1.1.1

func (it *AccountIterator) Err() error

func (*AccountIterator) Next added in v1.1.1

func (it *AccountIterator) Next() bool

func (*AccountIterator) Value added in v1.2.0

func (it *AccountIterator) Value() *Account

type AccountTransaction added in v1.1.0

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

func (*AccountTransaction) Commit added in v1.1.0

func (c *AccountTransaction) Commit() error

func (*AccountTransaction) History added in v1.1.0

func (c *AccountTransaction) History() values.Set[uint64]

func (*AccountTransaction) IsDirty added in v1.1.0

func (c *AccountTransaction) IsDirty() bool

func (*AccountTransaction) Key added in v1.1.1

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

func (*AccountTransaction) Payments added in v1.1.0

func (c *AccountTransaction) Payments() values.Set[[32]byte]

func (*AccountTransaction) RecordHistory added in v1.1.0

func (c *AccountTransaction) RecordHistory(msg messaging.Message) error

RecordHistory adds the message to the signature chain and history.

func (*AccountTransaction) Resolve added in v1.1.0

func (c *AccountTransaction) Resolve(key *record.Key) (record.Record, *record.Key, error)

func (*AccountTransaction) Signatures added in v1.1.0

func (c *AccountTransaction) Signatures() values.Set[*SignatureSetEntry]

func (*AccountTransaction) ValidatorSignatures added in v1.1.0

func (c *AccountTransaction) ValidatorSignatures() values.Set[protocol.KeySignature]

func (*AccountTransaction) Votes added in v1.1.0

func (c *AccountTransaction) Votes() values.Set[*VoteEntry]

func (*AccountTransaction) Walk added in v1.1.1

type Batch

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

func NewBatch added in v1.1.0

func NewBatch(id string, store keyvalue.Store, writable bool, logger log.Logger) *Batch

func (*Batch) Account

func (b *Batch) Account(u *url.URL) *Account

func (*Batch) AccountTransaction added in v1.1.0

func (b *Batch) AccountTransaction(id *url.TxID) *AccountTransaction

func (*Batch) BPT added in v1.1.1

func (c *Batch) BPT() *bpt.BPT

func (*Batch) Begin added in v0.5.1

func (b *Batch) Begin(writable bool) *Batch

func (*Batch) BptReceipt added in v0.5.1

func (b *Batch) BptReceipt(key *record.Key, value [32]byte) (*merkle.Receipt, error)

BptReceipt builds a BPT receipt for the given key.

func (*Batch) Collect added in v1.2.10

func (batch *Batch) Collect(file io.WriteSeeker, partition *url.URL, opts *CollectOptions) error

Collect collects a snapshot of the database.

WARNING: If the batch is nested (if it is not a root batch), Collect may cause excessive memory consumption until the root batch is discarded.

func (*Batch) Commit

func (b *Batch) Commit() error

Commit commits pending writes to the key-value store or the parent batch. Attempting to use the Batch after calling Commit or Discard will result in a panic.

func (*Batch) DeleteAccountState_TESTONLY added in v1.0.0

func (b *Batch) DeleteAccountState_TESTONLY(url *url.URL) error

DeleteAccountState_TESTONLY is intended for testing purposes only. It deletes an account from the database. It will panic if the batch's store is not a key-value store.

func (*Batch) Discard

func (b *Batch) Discard()

Discard discards pending writes. Attempting to use the Batch after calling Discard will result in a panic.

func (*Batch) ForEachAccount added in v1.1.0

func (b *Batch) ForEachAccount(fn func(account *Account, hash [32]byte) error) error

func (*Batch) GetBptRootHash added in v1.2.6

func (b *Batch) GetBptRootHash() ([32]byte, error)

GetBptRootHash returns the BPT root hash, after applying updates as necessary for modified accounts.

func (*Batch) GetMinorRootChainAnchor added in v0.5.1

func (b *Batch) GetMinorRootChainAnchor(describe *config.Describe) ([]byte, error)

func (*Batch) IsDirty added in v1.0.0

func (c *Batch) IsDirty() bool

func (*Batch) IterateAccounts added in v1.1.1

func (b *Batch) IterateAccounts() *AccountIterator

func (*Batch) Key added in v1.1.1

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

func (*Batch) Message added in v1.1.0

func (c *Batch) Message(hash [32]byte) *Message

func (*Batch) Message2 added in v1.1.0

func (b *Batch) Message2(hash []byte) *Message

func (*Batch) Resolve added in v1.0.0

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

func (*Batch) SaveAccounts added in v1.0.0

func (b *Batch) SaveAccounts(file io.WriteSeeker, collect func(*Account) ([]byte, error)) error

func (*Batch) SetObserver added in v1.1.0

func (b *Batch) SetObserver(observer Observer)

SetObserver sets the database observer.

func (*Batch) SystemData added in v1.0.0

func (c *Batch) SystemData(partition string) *SystemData

func (*Batch) Transaction

func (b *Batch) Transaction(id []byte) *Transaction

Transaction returns an Transaction for the given hash.

func (*Batch) Transaction2 added in v1.1.0

func (b *Batch) Transaction2(id [32]byte) *Transaction

func (*Batch) Update added in v0.5.1

func (b *Batch) Update(fn func(batch *Batch) error) error

Update runs the function with a writable transaction and commits if the function succeeds.

func (*Batch) UpdatedAccounts added in v1.0.2

func (b *Batch) UpdatedAccounts() []*Account

UpdatedAccounts returns every account updated in this database batch.

func (*Batch) View added in v0.5.1

func (b *Batch) View(fn func(batch *Batch) error) error

View runs the function with a read-only transaction.

func (*Batch) Walk added in v1.1.1

func (c *Batch) Walk(opts record.WalkOptions, fn record.WalkFunc) error

type Beginner added in v1.0.0

type Beginner interface {
	Updater
	Begin(bool) *Batch
	SetObserver(Observer)
}

A Beginner can be a Database or a Batch

type BlockStateSynthTxnEntry added in v1.0.0

type BlockStateSynthTxnEntry struct {
	Account     *url.URL `json:"account,omitempty" form:"account" query:"account" validate:"required"`
	Transaction []byte   `json:"transaction,omitempty" form:"transaction" query:"transaction" validate:"required"`
	ChainEntry  uint64   `json:"chainEntry,omitempty" form:"chainEntry" query:"chainEntry" validate:"required"`
	// contains filtered or unexported fields
}

func (*BlockStateSynthTxnEntry) Compare added in v1.0.0

func (*BlockStateSynthTxnEntry) Copy added in v1.0.0

func (*BlockStateSynthTxnEntry) CopyAsInterface added in v1.0.0

func (v *BlockStateSynthTxnEntry) CopyAsInterface() interface{}

func (*BlockStateSynthTxnEntry) Equal added in v1.0.0

func (*BlockStateSynthTxnEntry) IsValid added in v1.0.0

func (v *BlockStateSynthTxnEntry) IsValid() error

func (*BlockStateSynthTxnEntry) MarshalBinary added in v1.0.0

func (v *BlockStateSynthTxnEntry) MarshalBinary() ([]byte, error)

func (*BlockStateSynthTxnEntry) MarshalJSON added in v1.0.0

func (v *BlockStateSynthTxnEntry) MarshalJSON() ([]byte, error)

func (*BlockStateSynthTxnEntry) UnmarshalBinary added in v1.0.0

func (v *BlockStateSynthTxnEntry) UnmarshalBinary(data []byte) error

func (*BlockStateSynthTxnEntry) UnmarshalBinaryFrom added in v1.0.0

func (v *BlockStateSynthTxnEntry) UnmarshalBinaryFrom(rd io.Reader) error

func (*BlockStateSynthTxnEntry) UnmarshalJSON added in v1.0.0

func (v *BlockStateSynthTxnEntry) UnmarshalJSON(data []byte) error

type Chain

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

Chain manages a Merkle tree (chain).

func (*Chain) AddEntry

func (c *Chain) AddEntry(entry []byte, unique bool) error

AddEntry adds an entry to the chain

func (*Chain) Anchor

func (c *Chain) Anchor() []byte

Anchor calculates the anchor of the current Merkle state.

func (*Chain) AnchorAt added in v0.5.1

func (c *Chain) AnchorAt(height uint64) ([]byte, error)

AnchorAt calculates the anchor of the chain at the given height.

func (*Chain) CurrentState added in v0.5.1

func (c *Chain) CurrentState() *merkle.State

CurrentState returns the current state of the chain.

func (*Chain) Entries

func (c *Chain) Entries(start int64, end int64) ([][]byte, error)

Entries returns entries in the given range.

func (*Chain) Entry

func (c *Chain) Entry(height int64) ([]byte, error)

Entry loads the entry in the chain at the given height.

func (*Chain) EntryAs added in v0.5.1

func (c *Chain) EntryAs(height int64, value encoding.BinaryUnmarshaler) error

EntryAs loads and unmarshals the entry in the chain at the given height.

func (*Chain) Height

func (c *Chain) Height() int64

Height returns the height of the chain.

func (*Chain) HeightOf

func (c *Chain) HeightOf(hash []byte) (int64, error)

HeightOf returns the height of the given entry in the chain.

func (*Chain) Pending

func (c *Chain) Pending() [][]byte

Pending returns the pending roots of the current Merkle state.

func (*Chain) Receipt

func (c *Chain) Receipt(from, to int64) (*merkle.Receipt, error)

Receipt builds a receipt from one index to another

func (*Chain) State

func (c *Chain) State(height int64) (*merkle.State, error)

State returns the state of the chain at the given height.

type Chain2 added in v1.0.0

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

Chain2 is a wrapper for Chain.

func (*Chain2) Account added in v1.0.0

func (c *Chain2) Account() *url.URL

Account returns the URL of the account.

func (*Chain2) Anchor added in v1.2.10

func (c *Chain2) Anchor() ([]byte, error)

Anchor calculates the anchor of the current Merkle state.

func (*Chain2) Commit added in v1.0.0

func (c *Chain2) Commit() error

func (*Chain2) Entry added in v1.1.0

func (c *Chain2) Entry(height int64) ([]byte, error)

Entry loads the entry in the chain at the given height.

func (*Chain2) Get added in v1.0.0

func (c *Chain2) Get() (*Chain, error)

Get converts the Chain2 to a Chain, updating the account's chains index and loading the chain head.

func (*Chain2) Head added in v1.1.0

func (c *Chain2) Head() values.Value[*merkle.State]

func (*Chain2) Index added in v1.0.0

func (c *Chain2) Index() *Chain2

Index returns the index chain of this chain. Index will panic if called on an index chain.

func (*Chain2) IndexOf added in v1.1.0

func (c *Chain2) IndexOf(hash []byte) (int64, error)

IndexOf returns the index of the given entry in the chain.

func (*Chain2) Inner added in v1.0.0

func (c *Chain2) Inner() *MerkleManager

func (*Chain2) IsDirty added in v1.0.0

func (c *Chain2) IsDirty() bool

func (*Chain2) Key added in v1.0.0

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

func (*Chain2) Name added in v1.0.0

func (c *Chain2) Name() string

Name returns the name of the chain.

func (*Chain2) Resolve added in v1.0.0

func (c *Chain2) Resolve(key *record.Key) (record.Record, *record.Key, error)

func (*Chain2) Type added in v1.0.0

func (c *Chain2) Type() merkle.ChainType

Type returns the type of the chain.

func (*Chain2) Url added in v1.0.0

func (c *Chain2) Url() *url.URL

Url returns the URL of the chain: {account}#chain/{name}.

func (*Chain2) Walk added in v1.1.1

func (c *Chain2) Walk(opts database.WalkOptions, fn database.WalkFunc) error

type CollectMetrics added in v1.2.0

type CollectMetrics struct {
	Messages struct {
		Count      int
		Collecting int
	}
}

type CollectOptions added in v1.1.1

type CollectOptions struct {
	BuildIndex     bool
	Predicate      func(database.Record) (bool, error)
	DidWriteHeader func(*snapshot.Writer) error

	Metrics *CollectMetrics
}

type Database

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

Database is an Accumulate database.

func New

func New(store keyvalue.Beginner, logger log.Logger) *Database

New creates a new database using the given key-value store.

func Open

func Open(cfg *config.Config, logger log.Logger) (*Database, error)

Open opens a key-value store and creates a new database with it.

func OpenBadger added in v0.5.1

func OpenBadger(filepath string, logger log.Logger) (*Database, error)

func OpenInMemory added in v0.5.1

func OpenInMemory(logger log.Logger) *Database

func (*Database) Begin

func (d *Database) Begin(writable bool) *Batch

Begin starts a new batch.

func (*Database) Close

func (d *Database) Close() error

Close closes the database and the key-value store.

func (*Database) Collect added in v1.1.1

func (db *Database) Collect(file io.WriteSeeker, partition *url.URL, opts *CollectOptions) error

Collect collects a snapshot of the database.

Collect is a wrapper around Batch.Collect.

func (*Database) SetObserver added in v1.1.0

func (d *Database) SetObserver(observer Observer)

SetObserver sets the database observer.

func (*Database) Store added in v1.1.1

func (d *Database) Store() (keyvalue.Beginner, error)

Store returns the underlying key-value store. Store may return an error in the future.

func (*Database) Update added in v0.5.1

func (d *Database) Update(fn func(batch *Batch) error) error

Update runs the function with a writable transaction and commits if the function succeeds.

func (*Database) View added in v0.5.1

func (d *Database) View(fn func(batch *Batch) error) error

View runs the function with a read-only transaction.

type Hash added in v1.1.0

type Hash []byte

This Stateful Merkle Tree implementation handles 256 bit hashes

func (Hash) BinarySize added in v1.1.0

func (h Hash) BinarySize() int

func (Hash) Bytes added in v1.1.0

func (h Hash) Bytes() []byte

func (Hash) Bytes32 added in v1.1.0

func (h Hash) Bytes32() [32]byte

func (Hash) Combine added in v1.1.0

func (h Hash) Combine(right Hash) Hash

Combine Hash this hash (the left hash) with the given right hash to produce a new hash

func (Hash) Copy added in v1.1.0

func (h Hash) Copy() Hash

Copy Make a copy of a Hash (so the caller cannot modify the original version)

func (Hash) Equal added in v1.1.0

func (h Hash) Equal(g Hash) bool

func (Hash) MarshalBinary added in v1.1.0

func (h Hash) MarshalBinary() ([]byte, error)

func (*Hash) UnmarhsalBinary added in v1.1.0

func (h *Hash) UnmarhsalBinary(b []byte) error

type HashFunc added in v1.1.0

type HashFunc func([]byte) Hash

type HashList added in v1.1.0

type HashList [][]byte

func (HashList) BinarySize added in v1.1.0

func (l HashList) BinarySize() int

func (HashList) MarshalBinary added in v1.1.0

func (l HashList) MarshalBinary() ([]byte, error)

func (*HashList) UnmarhsalBinary added in v1.1.0

func (l *HashList) UnmarhsalBinary(b []byte) error

type MerkleManager added in v1.1.0

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

func NewChain added in v1.1.0

func NewChain(logger log.Logger, store record.Store, key *record.Key, markPower int64, typ merkle.ChainType, namefmt string) *MerkleManager

func (*MerkleManager) AddHash added in v1.1.0

func (m *MerkleManager) AddHash(hash Hash, unique bool) error

AddHash adds a Hash to the Chain controlled by the ChainManager. If unique is true, the hash will not be added if it is already in the chain.

func (*MerkleManager) BuildReceipt added in v1.1.0

func (m *MerkleManager) BuildReceipt(r *merkle.Receipt) error

BuildReceipt takes the values collected by GetReceipt and flushes out the data structures in the receipt to represent a fully populated version.

func (*MerkleManager) Commit added in v1.1.0

func (c *MerkleManager) Commit() error

func (*MerkleManager) Element added in v1.1.0

func (c *MerkleManager) Element(index uint64) values.Value[[]byte]

func (*MerkleManager) ElementIndex added in v1.1.0

func (c *MerkleManager) ElementIndex(hash []byte) values.Value[uint64]

func (*MerkleManager) Get added in v1.1.0

func (m *MerkleManager) Get(element int64) (Hash, error)

Get the nth leaf node

func (*MerkleManager) GetAnyState added in v1.1.0

func (m *MerkleManager) GetAnyState(element int64) (ms *merkle.State, err error)

GetAnyState We only store the state at MarkPoints. This function computes a missing state even if one isn't stored for a particular element.

func (*MerkleManager) GetElementIndex added in v1.1.0

func (m *MerkleManager) GetElementIndex(hash []byte) (int64, error)

GetElementIndex Get an Element of a Merkle Tree from the database

func (*MerkleManager) GetIntermediate added in v1.1.0

func (m *MerkleManager) GetIntermediate(element, height int64) (Left, Right Hash, err error)

GetIntermediate Return the last two hashes that were combined to create the local Merkle Root at the given index. The element provided must be odd, and the Pending List must be fully populated up to height specified.

func (*MerkleManager) GetRange added in v1.1.0

func (m *MerkleManager) GetRange(begin, end int64) ([][]byte, error)

GetRange returns the list of hashes with indexes indicated by range: (begin,end) begin must be before or equal to end. The hash with index begin upto but not including end are the hashes returned. Indexes are zero based, so the first hash in the merkle.State is at 0

func (*MerkleManager) GetState added in v1.1.0

func (m *MerkleManager) GetState(element int64) *merkle.State

GetState Query the database for the merkle state for a given index, i.e. the state Note that not every element in the Merkle Tree has a stored state; states are stored at the frequency indicated by the Mark Power. We also store the state of the chain at the end of a block regardless, but this state overwrites the previous block state.

If no state exists in the database for the element, GetState returns nil

func (*MerkleManager) Head added in v1.1.0

func (c *MerkleManager) Head() values.Value[*merkle.State]

func (*MerkleManager) IsDirty added in v1.1.0

func (c *MerkleManager) IsDirty() bool

func (*MerkleManager) Key added in v1.1.1

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

func (*MerkleManager) MarkFreq added in v1.1.0

func (c *MerkleManager) MarkFreq() int64

func (*MerkleManager) MarkMask added in v1.1.0

func (c *MerkleManager) MarkMask() int64

func (*MerkleManager) MarkPower added in v1.1.0

func (c *MerkleManager) MarkPower() int64

func (*MerkleManager) Name added in v1.1.0

func (c *MerkleManager) Name() string

func (*MerkleManager) Resolve added in v1.1.0

func (c *MerkleManager) Resolve(key *record.Key) (record.Record, *record.Key, error)

func (*MerkleManager) States added in v1.1.0

func (c *MerkleManager) States(index uint64) values.Value[*merkle.State]

func (*MerkleManager) Type added in v1.1.0

func (c *MerkleManager) Type() merkle.ChainType

func (*MerkleManager) Walk added in v1.1.1

type Message added in v1.1.0

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

func (*Message) Cause added in v1.1.0

func (c *Message) Cause() values.Set[*url.TxID]

func (*Message) Commit added in v1.1.0

func (c *Message) Commit() error

func (*Message) FindSigners added in v1.1.0

func (m *Message) FindSigners(u *url.URL) ([]*url.URL, error)

FindSigners return signers that are equal to or a child of the given URL. FindSigners only returns an error if the signer list cannot be retrieved. FindSigners returns nil, if no matching signers are found.

func (*Message) IsDirty added in v1.1.0

func (c *Message) IsDirty() bool

func (*Message) Key added in v1.1.1

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

func (*Message) Main added in v1.1.0

func (m *Message) Main() values.Value[messaging.Message]

func (*Message) Produced added in v1.1.0

func (c *Message) Produced() values.Set[*url.TxID]

func (*Message) Resolve added in v1.1.0

func (c *Message) Resolve(key *record.Key) (record.Record, *record.Key, error)

func (*Message) Signers added in v1.1.0

func (c *Message) Signers() values.Set[*url.URL]

func (*Message) Walk added in v1.1.1

func (c *Message) Walk(opts record.WalkOptions, fn record.WalkFunc) error

type Observer added in v1.1.0

type Observer interface {
	DidChangeAccount(batch *Batch, account *Account) (hash.Hasher, error)
}

type ReceiptList added in v1.1.0

type ReceiptList struct {

	// MerkleState merkle.State at the beginning of the list.
	MerkleState      *merkle.State   `json:"merkleState,omitempty" form:"merkleState" query:"merkleState" validate:"required"`
	Elements         [][]byte        `json:"elements,omitempty" form:"elements" query:"elements" validate:"required"`
	Receipt          *merkle.Receipt `json:"receipt,omitempty" form:"receipt" query:"receipt" validate:"required"`
	ContinuedReceipt *merkle.Receipt `json:"continuedReceipt,omitempty" form:"continuedReceipt" query:"continuedReceipt" validate:"required"`
	// contains filtered or unexported fields
}

func GetReceiptList added in v1.1.0

func GetReceiptList(manager *MerkleManager, Start int64, End int64) (r *ReceiptList, err error)

GetReceiptList Given a merkle tree with a start point and an end point, create a ReceiptList for all the elements from the start hash to the end hash, inclusive.

func NewReceiptList added in v1.1.0

func NewReceiptList() *ReceiptList

NewReceiptList Return a new ReceiptList with at least a MerkleState initialized

func (*ReceiptList) Copy added in v1.1.0

func (v *ReceiptList) Copy() *ReceiptList

func (*ReceiptList) CopyAsInterface added in v1.1.0

func (v *ReceiptList) CopyAsInterface() interface{}

func (*ReceiptList) Equal added in v1.1.0

func (v *ReceiptList) Equal(u *ReceiptList) bool

func (*ReceiptList) Included added in v1.1.0

func (r *ReceiptList) Included(entry []byte) bool

Included Tests an entry for inclusion in the given ReceiptList Note that while a ReceiptList proves inclusion in a Merkle Tree, and the fact that the list of elements proceed in order up to and including the anchor point, the ReceiptList does not necessarily prove the indices of the elements in the Merkle Tree. This could be solved by salting Receipts with the index of the hash at the anchor point.

func (*ReceiptList) IsValid added in v1.1.0

func (v *ReceiptList) IsValid() error

func (*ReceiptList) MarshalBinary added in v1.1.0

func (v *ReceiptList) MarshalBinary() ([]byte, error)

func (*ReceiptList) MarshalJSON added in v1.1.0

func (v *ReceiptList) MarshalJSON() ([]byte, error)

func (*ReceiptList) UnmarshalBinary added in v1.1.0

func (v *ReceiptList) UnmarshalBinary(data []byte) error

func (*ReceiptList) UnmarshalBinaryFrom added in v1.1.0

func (v *ReceiptList) UnmarshalBinaryFrom(rd io.Reader) error

func (*ReceiptList) UnmarshalJSON added in v1.1.0

func (v *ReceiptList) UnmarshalJSON(data []byte) error

func (*ReceiptList) Validate added in v1.1.0

func (r *ReceiptList) Validate(opts *merkle.ValidateOptions) bool

Validate Take a receipt and validate that the element hash progresses to the Merkle Dag Root hash (MDRoot) in the receipt

type RestoreMetrics added in v1.2.0

type RestoreMetrics struct {
	Records struct {
		Restoring int
	}
}

type RestoreOptions added in v1.1.1

type RestoreOptions struct {
	BatchRecordLimit int
	SkipHashCheck    bool
	Predicate        func(*snapshot.RecordEntry, database.Value) (bool, error)

	Metrics *RestoreMetrics
}

type SigOrTxn added in v0.6.0

type SigOrTxn struct {
	Transaction *protocol.Transaction `json:"transaction,omitempty" form:"transaction" query:"transaction" validate:"required"`
	Signature   protocol.Signature    `json:"signature,omitempty" form:"signature" query:"signature" validate:"required"`
	Txid        *url.TxID             `json:"txid,omitempty" form:"txid" query:"txid" validate:"required"`
	// contains filtered or unexported fields
}

func (*SigOrTxn) Copy added in v0.6.0

func (v *SigOrTxn) Copy() *SigOrTxn

func (*SigOrTxn) CopyAsInterface added in v0.6.0

func (v *SigOrTxn) CopyAsInterface() interface{}

func (*SigOrTxn) Equal added in v0.6.0

func (v *SigOrTxn) Equal(u *SigOrTxn) bool

func (*SigOrTxn) IsValid added in v0.6.0

func (v *SigOrTxn) IsValid() error

func (*SigOrTxn) MarshalBinary added in v0.6.0

func (v *SigOrTxn) MarshalBinary() ([]byte, error)

func (*SigOrTxn) MarshalJSON added in v0.6.0

func (v *SigOrTxn) MarshalJSON() ([]byte, error)

func (*SigOrTxn) UnmarshalBinary added in v0.6.0

func (v *SigOrTxn) UnmarshalBinary(data []byte) error

func (*SigOrTxn) UnmarshalBinaryFrom added in v0.6.0

func (v *SigOrTxn) UnmarshalBinaryFrom(rd io.Reader) error

func (*SigOrTxn) UnmarshalJSON added in v0.6.0

func (v *SigOrTxn) UnmarshalJSON(data []byte) error

type SigSetEntry added in v1.0.0

type SigSetEntry struct {
	Type             protocol.SignatureType `json:"type,omitempty" form:"type" query:"type" validate:"required"`
	KeyEntryIndex    uint64                 `json:"keyEntryIndex,omitempty" form:"keyEntryIndex" query:"keyEntryIndex" validate:"required"`
	SignatureHash    [32]byte               `json:"signatureHash,omitempty" form:"signatureHash" query:"signatureHash" validate:"required"`
	ValidatorKeyHash *[32]byte              `json:"validatorKeyHash,omitempty" form:"validatorKeyHash" query:"validatorKeyHash" validate:"required"`
	// contains filtered or unexported fields
}

func (*SigSetEntry) Compare added in v1.0.0

func (s *SigSetEntry) Compare(t *SigSetEntry) int

func (*SigSetEntry) Copy added in v1.0.0

func (v *SigSetEntry) Copy() *SigSetEntry

func (*SigSetEntry) CopyAsInterface added in v1.0.0

func (v *SigSetEntry) CopyAsInterface() interface{}

func (*SigSetEntry) Equal added in v1.0.0

func (v *SigSetEntry) Equal(u *SigSetEntry) bool

func (*SigSetEntry) IsValid added in v1.0.0

func (v *SigSetEntry) IsValid() error

func (*SigSetEntry) MarshalBinary added in v1.0.0

func (v *SigSetEntry) MarshalBinary() ([]byte, error)

func (*SigSetEntry) MarshalJSON added in v1.0.0

func (v *SigSetEntry) MarshalJSON() ([]byte, error)

func (*SigSetEntry) UnmarshalBinary added in v1.0.0

func (v *SigSetEntry) UnmarshalBinary(data []byte) error

func (*SigSetEntry) UnmarshalBinaryFrom added in v1.0.0

func (v *SigSetEntry) UnmarshalBinaryFrom(rd io.Reader) error

func (*SigSetEntry) UnmarshalJSON added in v1.0.0

func (v *SigSetEntry) UnmarshalJSON(data []byte) error

type SignatureSet added in v0.5.1

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

func (*SignatureSet) Add added in v0.5.1

func (s *SignatureSet) Add(keyEntryIndex uint64, newSignature protocol.Signature) (int, error)

Add adds a signature to the signature set. Add does nothing if the signature set already includes the signer's public key. The entry hash must refer to a signature chain entry.

func (*SignatureSet) Count added in v0.5.1

func (s *SignatureSet) Count() int

func (*SignatureSet) Entries added in v1.0.0

func (s *SignatureSet) Entries() []SigSetEntry

func (*SignatureSet) Version added in v1.0.0

func (s *SignatureSet) Version() uint64

type SignatureSetEntry added in v1.1.0

type SignatureSetEntry struct {

	// KeyIndex is the index of the public key entry in the signer.
	KeyIndex uint64 `json:"keyIndex" form:"keyIndex" query:"keyIndex" validate:"required"`
	// Version is the signer version.
	Version uint64 `json:"version,omitempty" form:"version" query:"version" validate:"required"`
	// Path is the authority/delegation path.
	Path []*url.URL `json:"path,omitempty" form:"path" query:"path" validate:"required"`
	// Hash is the hash of the signature.
	Hash [32]byte `json:"hash,omitempty" form:"hash" query:"hash" validate:"required"`
	// contains filtered or unexported fields
}

func (*SignatureSetEntry) Copy added in v1.1.0

func (*SignatureSetEntry) CopyAsInterface added in v1.1.0

func (v *SignatureSetEntry) CopyAsInterface() interface{}

func (*SignatureSetEntry) Equal added in v1.1.0

func (*SignatureSetEntry) IsValid added in v1.1.0

func (v *SignatureSetEntry) IsValid() error

func (*SignatureSetEntry) MarshalBinary added in v1.1.0

func (v *SignatureSetEntry) MarshalBinary() ([]byte, error)

func (*SignatureSetEntry) MarshalJSON added in v1.1.0

func (v *SignatureSetEntry) MarshalJSON() ([]byte, error)

func (*SignatureSetEntry) PathHash added in v1.1.0

func (a *SignatureSetEntry) PathHash() [32]byte

PathHash returns a hash derived from the delegation path.

func (*SignatureSetEntry) UnmarshalBinary added in v1.1.0

func (v *SignatureSetEntry) UnmarshalBinary(data []byte) error

func (*SignatureSetEntry) UnmarshalBinaryFrom added in v1.1.0

func (v *SignatureSetEntry) UnmarshalBinaryFrom(rd io.Reader) error

func (*SignatureSetEntry) UnmarshalJSON added in v1.1.0

func (v *SignatureSetEntry) UnmarshalJSON(data []byte) error

type SparseHashList added in v1.1.0

type SparseHashList [][]byte

func (SparseHashList) BinarySize added in v1.1.0

func (l SparseHashList) BinarySize(height int64) int

func (SparseHashList) Copy added in v1.1.0

func (l SparseHashList) Copy() SparseHashList

func (SparseHashList) MarshalBinary added in v1.1.0

func (l SparseHashList) MarshalBinary(height int64) ([]byte, error)

func (*SparseHashList) UnmarshalBinary added in v1.1.0

func (l *SparseHashList) UnmarshalBinary(height int64, data []byte) error

type SystemData added in v1.0.0

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

func (*SystemData) Commit added in v1.0.0

func (c *SystemData) Commit() error

func (*SystemData) IsDirty added in v1.0.0

func (c *SystemData) IsDirty() bool

func (*SystemData) Key added in v1.1.1

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

func (*SystemData) Resolve added in v1.0.0

func (c *SystemData) Resolve(key *record.Key) (record.Record, *record.Key, error)

func (*SystemData) SyntheticIndexIndex added in v1.0.0

func (c *SystemData) SyntheticIndexIndex(block uint64) values.Value[uint64]

func (*SystemData) Walk added in v1.1.1

func (c *SystemData) Walk(opts record.WalkOptions, fn record.WalkFunc) error

type Transaction

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

func (*Transaction) AddSignature added in v0.5.1

func (t *Transaction) AddSignature(keyEntryIndex uint64, newSignature protocol.Signature) (int, error)

AddSignature loads the appropriate signature set and adds the signature to it.

func (*Transaction) AddSystemSignature added in v1.0.0

func (t *Transaction) AddSystemSignature(net config.NetworkUrl, newSignature protocol.Signature) (int, error)

AddSystemSignature adds a system signature to the operator signature set. AddSystemSignature panics if the signature is not a system signature.

func (*Transaction) Chains added in v1.0.0

func (*Transaction) Commit added in v1.0.0

func (c *Transaction) Commit() error

func (*Transaction) IsDirty added in v1.0.0

func (c *Transaction) IsDirty() bool

func (*Transaction) Key added in v1.1.1

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

func (*Transaction) Main added in v1.0.0

func (c *Transaction) Main() values.Value[*SigOrTxn]

func (*Transaction) Produced added in v1.0.0

func (c *Transaction) Produced() values.Set[*url.TxID]

func (*Transaction) ReadSignatures added in v0.5.1

func (t *Transaction) ReadSignatures(signer *url.URL) (*SignatureSet, error)

ReadSignatures returns a read-only signature set for the given signer.

func (*Transaction) ReadSignaturesForSigner added in v0.6.0

func (t *Transaction) ReadSignaturesForSigner(signer protocol.Signer2) (*SignatureSet, error)

SignaturesForSigner returns a read-only signature set for the given signer account.

func (*Transaction) Resolve added in v1.0.0

func (c *Transaction) Resolve(key *record.Key) (record.Record, *record.Key, error)

func (*Transaction) RestoreSignatureSets added in v1.0.0

func (t *Transaction) RestoreSignatureSets(signer *url.URL, version uint64, entries []SigSetEntry) error

RestoreSignatureSets is specifically only to be used to restore a transaction's signature sets from a snapshot.

func (*Transaction) Signatures added in v0.5.1

func (t *Transaction) Signatures(signer *url.URL) (*SignatureSet, error)

Signatures returns a signature set for the given signer.

func (*Transaction) SignaturesForSigner added in v0.6.0

func (t *Transaction) SignaturesForSigner(signer protocol.Signer2) (*SignatureSet, error)

SignaturesForSigner returns a signature set for the given signer account.

func (*Transaction) Status added in v1.0.0

func (*Transaction) Walk added in v1.1.1

func (c *Transaction) Walk(opts record.WalkOptions, fn record.WalkFunc) error

type TransactionChainEntry added in v1.0.0

type TransactionChainEntry struct {
	Account *url.URL `json:"account,omitempty" form:"account" query:"account" validate:"required"`
	// Chain is the name of the chain.
	Chain string `json:"chain,omitempty" form:"chain" query:"chain" validate:"required"`
	// ChainIndex is the index of the entry in the chain's index chain.
	ChainIndex uint64 `json:"chainIndex,omitempty" form:"chainIndex" query:"chainIndex" validate:"required"`
	// AnchorIndex is the index of the entry in the anchor chain's index chain.
	AnchorIndex uint64 `json:"anchorIndex,omitempty" form:"anchorIndex" query:"anchorIndex" validate:"required"`
	// contains filtered or unexported fields
}

func (*TransactionChainEntry) Compare added in v1.0.0

func (*TransactionChainEntry) Copy added in v1.0.0

func (*TransactionChainEntry) CopyAsInterface added in v1.0.0

func (v *TransactionChainEntry) CopyAsInterface() interface{}

func (*TransactionChainEntry) Equal added in v1.0.0

func (*TransactionChainEntry) IsValid added in v1.0.0

func (v *TransactionChainEntry) IsValid() error

func (*TransactionChainEntry) MarshalBinary added in v1.0.0

func (v *TransactionChainEntry) MarshalBinary() ([]byte, error)

func (*TransactionChainEntry) UnmarshalBinary added in v1.0.0

func (v *TransactionChainEntry) UnmarshalBinary(data []byte) error

func (*TransactionChainEntry) UnmarshalBinaryFrom added in v1.0.0

func (v *TransactionChainEntry) UnmarshalBinaryFrom(rd io.Reader) error

type Updater added in v1.0.0

type Updater interface {
	Viewer
	Update(func(batch *Batch) error) error
}

type Viewer added in v1.0.0

type Viewer interface {
	View(func(batch *Batch) error) error
}

type VoteEntry added in v1.1.0

type VoteEntry struct {

	// Authority is the URL of the authority.
	Authority *url.URL `json:"authority,omitempty" form:"authority" query:"authority" validate:"required"`
	// Hash is the hash of the signature.
	Hash [32]byte `json:"hash,omitempty" form:"hash" query:"hash" validate:"required"`
	// contains filtered or unexported fields
}

func (*VoteEntry) Copy added in v1.1.0

func (v *VoteEntry) Copy() *VoteEntry

func (*VoteEntry) CopyAsInterface added in v1.1.0

func (v *VoteEntry) CopyAsInterface() interface{}

func (*VoteEntry) Equal added in v1.1.0

func (v *VoteEntry) Equal(u *VoteEntry) bool

func (*VoteEntry) IsValid added in v1.1.0

func (v *VoteEntry) IsValid() error

func (*VoteEntry) MarshalBinary added in v1.1.0

func (v *VoteEntry) MarshalBinary() ([]byte, error)

func (*VoteEntry) MarshalJSON added in v1.1.0

func (v *VoteEntry) MarshalJSON() ([]byte, error)

func (*VoteEntry) UnmarshalBinary added in v1.1.0

func (v *VoteEntry) UnmarshalBinary(data []byte) error

func (*VoteEntry) UnmarshalBinaryFrom added in v1.1.0

func (v *VoteEntry) UnmarshalBinaryFrom(rd io.Reader) error

func (*VoteEntry) UnmarshalJSON added in v1.1.0

func (v *VoteEntry) UnmarshalJSON(data []byte) error

Directories

Path Synopsis
smt
common
For key value stores where buckets are not supported, we add a byte to the key to represent a bucket.
For key value stores where buckets are not supported, we add a byte to the key to represent a bucket.

Jump to

Keyboard shortcuts

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