whiteflag

package
v0.5.8-rc1 Latest Latest
Warning

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

Go to latest
Published: Apr 27, 2021 License: Apache-2.0 Imports: 14 Imported by: 0

Documentation

Index

Constants

View Source
const (
	LeafHashPrefix = 0
	NodeHashPrefix = 1
)

Domain separation prefixes

Variables

View Source
var (
	// ErrMilestoneApprovedInvalidBundle is returned when a milestone approves an invalid bundle in its past cone.
	ErrMilestoneApprovedInvalidBundle = errors.New("the milestone approved an invalid bundle")

	// ErrIncludedTailsSumDoesntMatch is returned when the sum of the included tails a milestone approves does not match the referenced tails minus the excluded tails.
	ErrIncludedTailsSumDoesntMatch = errors.New("the sum of the included tails doesn't match the referenced tails minus the excluded tails")
)

Functions

func ComputeWhiteFlagMutations

func ComputeWhiteFlagMutations(cachedTxMetas map[string]*tangle.CachedMetadata, cachedBundles map[string]*tangle.CachedBundle, merkleTreeHashFunc crypto.Hash, trunkHash hornet.Hash, branchHash ...hornet.Hash) (*tangle.WhiteFlagMutations, error)

ComputeConfirmation computes the ledger changes in accordance to the white-flag rules for the cone referenced by trunk and branch. Via a post-order depth-first search the approved bundles of the given cone are traversed and in their corresponding order applied/mutated against the previous ledger state, respectively previous applied mutations. Bundles within the approving cone must obey to strict schematics and be valid. Bundles causing conflicts are ignored but do not create an error. It also computes the merkle tree root hash consisting out of the tail transaction hashes of the bundles which are part of the set which mutated the ledger state when applying the white-flag approach. The ledger state must be write locked while this function is getting called in order to ensure consistency. all cachedTxMetas and cachedBundles have to be released outside.

Types

type ConfirmedMilestoneStats

type ConfirmedMilestoneStats struct {
	Index            milestone.Index
	ConfirmationTime int64
	Txs              tangle.CachedTransactions
	TxsConfirmed     int
	TxsConflicting   int
	TxsValue         int
	TxsZeroValue     int
	Collecting       time.Duration
	Total            time.Duration
}

func ConfirmMilestone

func ConfirmMilestone(cachedTxMetas map[string]*tangle.CachedMetadata, cachedMsBundle *tangle.CachedBundle, forEachConfirmedTx func(txMeta *tangle.CachedMetadata, index milestone.Index, confTime int64), onMilestoneConfirmed func(confirmation *tangle.WhiteFlagConfirmation)) (*ConfirmedMilestoneStats, error)

ConfirmMilestone traverses a milestone and collects all unconfirmed tx, then the ledger diffs are calculated, the ledger state is checked and all tx are marked as confirmed. all cachedTxMetas have to be released outside.

type Hasher

type Hasher struct {
	crypto.Hash
}

Hasher implements the RFC6962 tree hashing algorithm.

func NewHasher

func NewHasher(h crypto.Hash) *Hasher

NewHasher creates a new Hasher on the passed in hash function.

func (*Hasher) EmptyRoot

func (t *Hasher) EmptyRoot() []byte

EmptyRoot returns a special case for an empty tree.

func (*Hasher) HashLeaf

func (t *Hasher) HashLeaf(hash hornet.Hash) []byte

HashLeaf returns the Merkle tree leaf hash of the input hash.

func (*Hasher) HashNode

func (t *Hasher) HashNode(l, r []byte) []byte

HashNode returns the inner Merkle tree node hash of the two child nodes l and r.

func (*Hasher) TreeHash

func (t *Hasher) TreeHash(tailHashes []hornet.Hash) []byte

TreeHash computes the Merkle tree hash of the provided hashes.

Jump to

Keyboard shortcuts

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