whiteflag

package
v0.5.4 Latest Latest
Warning

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

Go to latest
Published: Sep 24, 2020 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

This section is empty.

Types

type Confirmation

type Confirmation struct {
	// The index of the milestone that got confirmed.
	MilestoneIndex milestone.Index
	// The transaction hash of the tail transaction of the milestone that got confirmed.
	MilestoneHash hornet.Hash
	// The ledger mutations and referenced transactions of this milestone.
	Mutations *WhiteFlagMutations
}

Confirmation represents a confirmation done via a milestone under the "white-flag" approach.

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 *Confirmation)) (*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.

type WhiteFlagMutations

type WhiteFlagMutations struct {
	// The tails of bundles which mutate the ledger in the order in which they were applied.
	TailsIncluded hornet.Hashes
	// The tails of bundles which were excluded as they were conflicting with the mutations.
	TailsExcludedConflicting hornet.Hashes
	// The tails which were excluded because they were part of a zero or spam value transfer.
	TailsExcludedZeroValue hornet.Hashes
	// The tails which were referenced by the milestone (should be the sum of TailsIncluded + TailsExcludedConflicting + TailsExcludedZeroValue).
	TailsReferenced hornet.Hashes
	// Contains the updated state of the addresses which were mutated by the given confirmation.
	NewAddressState map[string]int64
	// Contains the mutations to the state of the addresses for the given confirmation.
	AddressMutations map[string]int64
	// The merkle tree root hash of all tails.
	MerkleTreeHash []byte
}

WhiteFlagMutations contains the ledger mutations and referenced transactions applied to a cone under the "white-flag" approach.

func ComputeWhiteFlagMutations

func ComputeWhiteFlagMutations(cachedTxMetas map[string]*tangle.CachedMetadata, cachedBundles map[string]*tangle.CachedBundle, merkleTreeHashFunc crypto.Hash, trunkHash hornet.Hash, branchHash ...hornet.Hash) (*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.

Jump to

Keyboard shortcuts

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