merkleDag

package
v0.0.0-...-349195c Latest Latest
Warning

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

Go to latest
Published: Sep 8, 2020 License: MIT Imports: 1 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type MD

type MD struct {
	MD       []*types.Hash // Array of hashes that represent the right edge of the Merkle tree
	HashList []types.Hash  // List of Hashes in the order added to the chain
}

MD Collects Hashes from some source, and allows the creation of MD Roots as desired.

func (*MD) AddToChain

func (m *MD) AddToChain(hash types.Hash)

AddToChain Add a Hash to the chain and incrementally build the MD

func (*MD) GetHashList

func (m *MD) GetHashList() (list []byte)

GetHashList Returns the list of Hashes to be stored in the Database so we can create the MD for this chain for this block. In Factom, this is much like a EntryBlock

func (*MD) GetMDRoot

func (m *MD) GetMDRoot() (MDRoot *types.Hash)

GetMDRoot Close off the Merkle Directed Acyclic Graph (Merkle DAG or MD) We take any trailing hashes in MD, hash them up and combine to create the Merkle Dag Root. Getting the closing ListMDRoot is non-destructive, which is useful for some use cases.

func (*MD) PrintMR

func (m *MD) PrintMR() (mr string)

PrintMR For debugging purposes, it is nice to get a string that shows the nil and non nil entries in c.MD Note that the "low order" entries are first in the string, so the binary is going from low order on the left to high order going right in the string rather than how binary is normally represented.

type MDNode

type MDNode struct {
	Type           uint8        // Type of data in this chain, drives validation
	SequenceNumber uint32       // sequence number of MDNodes in this chain
	Previous       types.Hash   // Hash of the previous MDNode in this chain; zeros if first block
	TotalEntries   uint64       // Total number of entries at the start of this block in this chain
	MDSTate        []types.Hash // Hashes in our intermediate state at the start of this block
	MDRoot         types.Hash   // MDRoot of all the data in this chain up to and not including this MDNode
	Hashes         []types.Hash // Hashes in this block
}

func (*MDNode) Bytes

func (n *MDNode) Bytes() (data []byte)

func (*MDNode) CompressState

func (n *MDNode) CompressState() (state []types.Hash)

CompressState First check to make sure the current state matches the total number of entries at the start of this block.

func (*MDNode) Extract

func (n *MDNode) Extract(data []byte)

func (*MDNode) SameAs

func (n *MDNode) SameAs(n2 *MDNode) bool

SameAs Compare all the data in two nodes to determine that they are the same. Any difference, and they are false

type MDReceipt

type MDReceipt struct {
	EntryHash types.Hash     // Entry Hash of the data subject to the MDReceipt
	Nodes     []*ReceiptNode // Path through the data collected by the MerkleDag
	MDRoot    types.Hash     // Merkle DAG root from the Accumulator network.

}

func (*MDReceipt) BuildMDReceipt

func (mdr *MDReceipt) BuildMDReceipt(MerkleDag MD, data types.Hash)

BuildMDReceipt Building a receipt is a bit more complex than just computing the Merkle DAG. We look at the stream of hashes as we build the MD, and detect when the Hash for which we need a receipt shows up. Then we track it through the intermediate hashes, tracking if it is combined from the right or from the left. Then when we have to calculate the Merkle DAG root, we do one more pass through the combining of the trailing hashes to finish off the receipt.

func (*MDReceipt) Validate

func (mdr *MDReceipt) Validate() bool

Validate Run down the Merkle DAG and prove that this receipt self validates

type ReceiptNode

type ReceiptNode struct {
	Right bool       // The given Hash will be on the Right (right==true) or on the left (right==false)
	Hash  types.Hash // hash to be combined at the next level
}

Jump to

Keyboard shortcuts

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