balloon

package
v0.3.0-docs.0...-f96dd80 Latest Latest
Warning

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

Go to latest
Published: Aug 9, 2019 License: Apache-2.0 Imports: 10 Imported by: 0

Documentation

Overview

Package balloon implements functionality to build balloons (a layer that comprises hyper and history trees, among other stuff), control their life cycle and operate them: add event digests (or bulk of event digests), ask for proofs of membership or consistency, etc..

Index

Constants

This section is empty.

Variables

View Source
var (
	AddTotal = prometheus.NewCounter(
		prometheus.CounterOpts{
			Namespace: namespace,
			Subsystem: subSystem,
			Name:      "add_total",
			Help:      "Number of add operations",
		},
	)
	MembershipTotal = prometheus.NewCounter(
		prometheus.CounterOpts{
			Namespace: namespace,
			Subsystem: subSystem,
			Name:      "membership_total",
			Help:      "Number of membership queries.",
		},
	)
	DigestMembershipTotal = prometheus.NewGauge(
		prometheus.GaugeOpts{
			Namespace: namespace,
			Subsystem: subSystem,
			Name:      "digest_membership_total",
			Help:      "Number of membership by digest queries.",
		},
	)
	IncrementalTotal = prometheus.NewCounter(
		prometheus.CounterOpts{
			Namespace: namespace,
			Subsystem: subSystem,
			Name:      "incremental_total",
			Help:      "Number of incremental queries.",
		},
	)
)
View Source
var (
	BalloonVersionKey = []byte("version")
)

Functions

func NewFakeMembershipProof

func NewFakeMembershipProof(shouldVerify bool, hasher hashing.Hasher) *history.MembershipProof

func NewFakeQueryProof

func NewFakeQueryProof(shouldVerify bool, value []byte, hasher hashing.Hasher) *hyper.QueryProof

Types

type Balloon

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

Balloon exposes the necesary API to interact with the hyper and history trees.

func NewBalloon

func NewBalloon(store storage.Store, hasherF func() hashing.Hasher) (*Balloon, error)

NewBalloon function instanciates a balloon given a storage and a hasher function.

func (*Balloon) Add

func (b *Balloon) Add(eventDigest hashing.Digest) (*Snapshot, []*storage.Mutation, error)

Add funcion inserts an event hash into the history and hyper trees, creates a snapshot with these insertions results, and returns the snapshot along with certain mutations to do to the persistent storage.

func (*Balloon) AddBulk

func (b *Balloon) AddBulk(eventBulkDigest []hashing.Digest) ([]*Snapshot, []*storage.Mutation, error)

AddBulk funcion inserts a bulk of event hashes into the history and hyper trees, creates an array of snapshots with these insertions results, and returns the array of snapshots along with certain mutations to do to the persistent storage.

func (*Balloon) Close

func (b *Balloon) Close()

Close function closes both history and hyper trees, and restarts balloon version.

func (Balloon) QueryConsistency

func (b Balloon) QueryConsistency(start, end uint64) (*IncrementalProof, error)

QueryConsistency function asks the history tree for an incremental proof, and returns the proof if there is no error. Previously, it checks that the given parameters are correct.

func (Balloon) QueryDigestMembership

func (b Balloon) QueryDigestMembership(keyDigest hashing.Digest) (*MembershipProof, error)

QueryDigestMembership function is used when an event digest is given to ask for a membership proof against the latest balloon version. It asks the hyper tree for this proof and returns the proof if there is no error.

func (Balloon) QueryDigestMembershipConsistency

func (b Balloon) QueryDigestMembershipConsistency(keyDigest hashing.Digest, version uint64) (*MembershipProof, error)

QueryDigestMembership function is used when an event digest is given to ask for a membership proof against a certain balloon version. It asks the hyper tree for this proof and returns the proof if there is no error.

func (Balloon) QueryMembership

func (b Balloon) QueryMembership(event []byte) (*MembershipProof, error)

QueryMembership function is used when an event is given to ask for a membership proof against the latest balloon version. It just hashes the event and ask QueryDigestMembership.

func (Balloon) QueryMembershipConsistency

func (b Balloon) QueryMembershipConsistency(event []byte, version uint64) (*MembershipProof, error)

QueryMembership function is used when an event is given to ask for a membership proof against a certain balloon version. It just hashes the event and ask QueryDigestMembershipConsistency.

func (*Balloon) RefreshVersion

func (b *Balloon) RefreshVersion() error

RefreshVersion function gets the last stored version from the history-tree table and updates balloon's version.

func (Balloon) Version

func (b Balloon) Version() uint64

Version function returns the current (last) balloon version.

type IncrementalProof

type IncrementalProof struct {
	Start, End uint64
	AuditPath  history.AuditPath
	Hasher     hashing.Hasher
}

IncrementalProof is the struct required to verify a consistency proof between two events. It has the History AuditPath, and the start and end versions which corresponds to these events.

func NewIncrementalProof

func NewIncrementalProof(start, end uint64, auditPath history.AuditPath, hasher hashing.Hasher) *IncrementalProof

NewIcrementalProof function instanciates an incremental proof given the required parameters.

func (IncrementalProof) Verify

func (p IncrementalProof) Verify(snapshotStart, snapshotEnd *Snapshot) bool

Verify verifies a proof and answer from QueryMembership. Returns true if the answer and proof are correct and consistent, otherwise false. Run by a client on input that should be verified.

type MembershipProof

type MembershipProof struct {
	Exists         bool
	HyperProof     *hyper.QueryProof
	HistoryProof   *history.MembershipProof
	CurrentVersion uint64
	QueryVersion   uint64
	ActualVersion  uint64
	KeyDigest      hashing.Digest
	Hasher         hashing.Hasher
}

MembershipProof is the struct required to verify an event existence proof. It has both Hyper and History AuditPaths, if the event exists, along with current balloon version, event version, and query version.

func NewMembershipProof

func NewMembershipProof(exists bool, hyperProof *hyper.QueryProof, historyProof *history.MembershipProof, currentVersion, queryVersion, actualVersion uint64, keyDigest hashing.Digest, Hasher hashing.Hasher) *MembershipProof

NewMembershipProof function instanciates an membership proof given the required parameters.

func (MembershipProof) DigestVerify

func (p MembershipProof) DigestVerify(digest hashing.Digest, snapshot *Snapshot) bool

DigestVerify verifies a proof and answer from QueryMembership. Returns true if the answer and proof are correct and consistent, otherwise false. Run by a client on input that should be verified.

func (MembershipProof) Verify

func (p MembershipProof) Verify(event []byte, snapshot *Snapshot) bool

Verify verifies a proof and answer from QueryMembership. Returns true if the answer and proof are correct and consistent, otherwise false. Run by a client on input that should be verified.

type Snapshot

type Snapshot struct {
	EventDigest   hashing.Digest
	HistoryDigest hashing.Digest
	HyperDigest   hashing.Digest
	Version       uint64
}

Snapshot is the struct that has both history and hyper digest and the current version for that rootNode digests.

type Verifiable

type Verifiable interface {
	Verify(key []byte, expectedDigest hashing.Digest) bool
}

Directories

Path Synopsis
Package cache implements the interface to interact with a cache.
Package cache implements the interface to interact with a cache.
Package history implements the history tree (a merkel tree, append only structure) life cycle, its operations, different visitors to navigate the tree, as well as the functionality of request and verify membership and incremental proofs.
Package history implements the history tree (a merkel tree, append only structure) life cycle, its operations, different visitors to navigate the tree, as well as the functionality of request and verify membership and incremental proofs.
Package hyper implements the history tree (a sparse merkel tree) life cycle, its operations, as well as the functionality of request and verify a membersip proof.
Package hyper implements the history tree (a sparse merkel tree) life cycle, its operations, as well as the functionality of request and verify a membersip proof.

Jump to

Keyboard shortcuts

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