blockchain

package
v0.0.0-...-2e52d37 Latest Latest
Warning

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

Go to latest
Published: Jan 18, 2022 License: MIT Imports: 7 Imported by: 1

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Block

type Block struct {
	types.View
	QC        *QC
	Proposer  identity.NodeID
	Timestamp time.Time
	Payload   []*message.Transaction
	PrevID    crypto.Identifier
	Sig       crypto.Signature
	ID        crypto.Identifier
	Ts        time.Duration
}

func MakeBlock

func MakeBlock(view types.View, qc *QC, prevID crypto.Identifier, payload []*message.Transaction, proposer identity.NodeID) *Block

MakeBlock creates an unsigned block

type BlockChain

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

func NewBlockchain

func NewBlockchain(n int) *BlockChain

func (*BlockChain) AddBlock

func (bc *BlockChain) AddBlock(block *Block)

func (*BlockChain) AddVote

func (bc *BlockChain) AddVote(vote *Vote) (bool, *QC)

func (*BlockChain) CommitBlock

func (bc *BlockChain) CommitBlock(id crypto.Identifier, view types.View) ([]*Block, []*Block, error)

CommitBlock prunes blocks and returns committed blocks up to the last committed one and prunedBlocks

func (*BlockChain) Exists

func (bc *BlockChain) Exists(id crypto.Identifier) bool

func (*BlockChain) GetBlockByID

func (bc *BlockChain) GetBlockByID(id crypto.Identifier) (*Block, error)

func (*BlockChain) GetBlockByView

func (bc *BlockChain) GetBlockByView(view types.View) *Block

func (*BlockChain) GetBlockIntervals

func (bc *BlockChain) GetBlockIntervals() float64

func (*BlockChain) GetChainGrowth

func (bc *BlockChain) GetChainGrowth() float64

func (*BlockChain) GetChildrenBlocks

func (bc *BlockChain) GetChildrenBlocks(id crypto.Identifier) []*Block

func (*BlockChain) GetCommittedBlocks

func (bc *BlockChain) GetCommittedBlocks() int

func (*BlockChain) GetGrandParentBlock

func (bc *BlockChain) GetGrandParentBlock(id crypto.Identifier) (*Block, error)

func (*BlockChain) GetHighestCommitted

func (bc *BlockChain) GetHighestCommitted() int

func (*BlockChain) GetParentBlock

func (bc *BlockChain) GetParentBlock(id crypto.Identifier) (*Block, error)

type BlockContainer

type BlockContainer struct {
	Block *Block
}

BlockContainer wraps a block to implement forest.Vertex In addition, it holds some additional properties for efficient processing of blocks by the Finalizer

func (*BlockContainer) GetBlock

func (b *BlockContainer) GetBlock() *Block

func (*BlockContainer) Level

func (b *BlockContainer) Level() uint64

func (*BlockContainer) Parent

func (b *BlockContainer) Parent() (crypto.Identifier, uint64)

func (*BlockContainer) VertexID

func (b *BlockContainer) VertexID() crypto.Identifier

functions implementing forest.vertex

type LevelledForest

type LevelledForest struct {
	LowestLevel uint64
	// contains filtered or unexported fields
}

LevelledForest contains multiple trees (which is a potentially disconnected planar graph). Each vertexContainer in the graph has a level (view) and a hash. A vertexContainer can only have one parent with strictly smaller level (view). A vertexContainer can have multiple children, all with strictly larger level (view). A LevelledForest provides the ability to prune all vertices up to a specific level. A tree whose root is below the pruning threshold might decompose into multiple disconnected subtrees as a result of pruning.

func NewLevelledForest

func NewLevelledForest() *LevelledForest

NewLevelledForest initializes a LevelledForest

func (*LevelledForest) AddVertex

func (f *LevelledForest) AddVertex(vertex Vertex)

AddVertex adds vertex to forest if vertex is within non-pruned levels Handles repeated addition of same vertex (keeps first added vertex). If vertex is at or below pruning level: method is NoOp. UNVALIDATED: requires that vertex would pass validity check LevelledForest.VerifyVertex(vertex).

func (*LevelledForest) GetChildren

func (f *LevelledForest) GetChildren(id crypto.Identifier) VertexIterator

GetChildren returns a VertexIterator to iterate over the children An empty VertexIterator is returned, if no vertices are known whose parent is `id` , `level`

func (*LevelledForest) GetNumberOfChildren

func (f *LevelledForest) GetNumberOfChildren(id crypto.Identifier) int

GetVerticesAtLevel returns a VertexIterator to iterate over the Vertices at the specified height

func (*LevelledForest) GetNumberOfVerticesAtLevel

func (f *LevelledForest) GetNumberOfVerticesAtLevel(level uint64) int

GetVerticesAtLevel returns a VertexIterator to iterate over the Vertices at the specified height

func (*LevelledForest) GetVertex

func (f *LevelledForest) GetVertex(id crypto.Identifier) (Vertex, bool)

GetVertex returns (<full vertex>, true) if the vertex with `id` and `level` was found (nil, false) if full vertex is unknown

func (*LevelledForest) GetVerticesAtLevel

func (f *LevelledForest) GetVerticesAtLevel(level uint64) VertexIterator

GetVerticesAtLevel returns a VertexIterator to iterate over the Vertices at the specified height An empty VertexIterator is returned, if no vertices are known at the specified `level`

func (*LevelledForest) HasVertex

func (f *LevelledForest) HasVertex(id crypto.Identifier) bool

HasVertex returns true iff full vertex exists

func (*LevelledForest) PruneUpToLevel

func (f *LevelledForest) PruneUpToLevel(level uint64) ([]*Block, int, error)

PruneUpToLevel prunes all blocks UP TO but NOT INCLUDING `level`

func (*LevelledForest) VerifyVertex

func (f *LevelledForest) VerifyVertex(vertex Vertex) error

VerifyVertex verifies that vertex satisfies the following conditions (1)

type QC

type QC struct {
	Leader  identity.NodeID
	View    types.View
	BlockID crypto.Identifier
	Signers []identity.NodeID
	crypto.AggSig
	crypto.Signature
}

type Quorum

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

func NewQuorum

func NewQuorum(total int) *Quorum

func (*Quorum) Add

func (q *Quorum) Add(vote *Vote) (bool, *QC)

Add adds id to quorum ack records

type Vertex

type Vertex interface {
	// VertexID returns the vertex's ID (in most cases its hash)
	VertexID() crypto.Identifier
	// Level returns the vertex's level
	Level() uint64
	// Parent returns the returns the parents (level, ID)
	Parent() (crypto.Identifier, uint64)
	// GetBlock returns the block contained in vertex
	GetBlock() *Block
}

type VertexIterator

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

VertexIterator is a stateful iterator for VertexList. Internally operates directly on the Vertex Containers It has one-element look ahead for skipping empty vertex containers.

func (*VertexIterator) HasNext

func (it *VertexIterator) HasNext() bool

HasNext returns true if and only if there is a next Vertex

func (*VertexIterator) NextVertex

func (it *VertexIterator) NextVertex() Vertex

NextVertex returns the next Vertex or nil if there is none

type VertexList

type VertexList []*vertexContainer

type VertexSet

type VertexSet map[crypto.Identifier]*vertexContainer

type Vote

type Vote struct {
	types.View
	Voter   identity.NodeID
	BlockID crypto.Identifier
	crypto.Signature
}

func MakeVote

func MakeVote(view types.View, voter identity.NodeID, id crypto.Identifier) *Vote

Jump to

Keyboard shortcuts

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