hashgraph

package
v0.0.0-...-50e3d47 Latest Latest
Warning

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

Go to latest
Published: Aug 5, 2019 License: MIT Imports: 16 Imported by: 0

Documentation

Index

Constants

View Source
const (

	//ROOT_DEPTH determines how many FrameEvents are included in the Root. It
	//		is preferable not to make ROOT_DEPTH configurable because if peers use
	//		diffent values, they will produce different Roots, different Frames, and
	//		different Blocks. Perhaps this parameter should be tied to the number of
	//		Peers rather than hard-coded.
	ROOT_DEPTH = 10

	// COIN_ROUND_FREQ ...
	COIN_ROUND_FREQ = float64(4)
)

Variables

This section is empty.

Functions

func DummyInternalCommitCallback

func DummyInternalCommitCallback(b *Block) error

DummyInternalCommitCallback is used for testing

Types

type BadgerStore

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

BadgerStore struct contains the badger store and inmem store references

func NewBadgerStore

func NewBadgerStore(cacheSize int, path string) (*BadgerStore, error)

NewBadgerStore opens an existing database or creates a new one if nothing is found in path.

func (*BadgerStore) AddConsensusEvent

func (s *BadgerStore) AddConsensusEvent(event *Event) error

AddConsensusEvent ...

func (*BadgerStore) CacheSize

func (s *BadgerStore) CacheSize() int

CacheSize sets the inmem cache size

func (*BadgerStore) Close

func (s *BadgerStore) Close() error

Close ...

func (*BadgerStore) ConsensusEvents

func (s *BadgerStore) ConsensusEvents() []string

ConsensusEvents ...

func (*BadgerStore) ConsensusEventsCount

func (s *BadgerStore) ConsensusEventsCount() int

ConsensusEventsCount ...

func (*BadgerStore) FirstRound

func (s *BadgerStore) FirstRound(id uint32) (int, bool)

FirstRound ...

func (*BadgerStore) GetAllPeerSets

func (s *BadgerStore) GetAllPeerSets() (map[int][]*peers.Peer, error)

GetAllPeerSets ...

func (*BadgerStore) GetBlock

func (s *BadgerStore) GetBlock(rr int) (*Block, error)

GetBlock ...

func (*BadgerStore) GetEvent

func (s *BadgerStore) GetEvent(key string) (*Event, error)

GetEvent returns the event for the given key

func (*BadgerStore) GetFrame

func (s *BadgerStore) GetFrame(rr int) (*Frame, error)

GetFrame ...

func (*BadgerStore) GetPeerSet

func (s *BadgerStore) GetPeerSet(round int) (peerSet *peers.PeerSet, err error)

GetPeerSet ...

func (*BadgerStore) GetRoot

func (s *BadgerStore) GetRoot(participant string) (*Root, error)

GetRoot ...

func (*BadgerStore) GetRound

func (s *BadgerStore) GetRound(r int) (*RoundInfo, error)

GetRound returns the round from InMem

func (*BadgerStore) KnownEvents

func (s *BadgerStore) KnownEvents() map[uint32]int

KnownEvents ...

func (*BadgerStore) LastBlockIndex

func (s *BadgerStore) LastBlockIndex() int

LastBlockIndex ...

func (*BadgerStore) LastConsensusEventFrom

func (s *BadgerStore) LastConsensusEventFrom(participant string) (last string, err error)

LastConsensusEventFrom ...

func (*BadgerStore) LastEventFrom

func (s *BadgerStore) LastEventFrom(participant string) (last string, err error)

LastEventFrom ...

func (*BadgerStore) LastRound

func (s *BadgerStore) LastRound() int

LastRound ...

func (*BadgerStore) ParticipantEvent

func (s *BadgerStore) ParticipantEvent(participant string, index int) (string, error)

ParticipantEvent returns a given event from the given participant from InMem

func (*BadgerStore) ParticipantEvents

func (s *BadgerStore) ParticipantEvents(participant string, skip int) ([]string, error)

ParticipantEvents returns that participant's Events from InMem

func (*BadgerStore) RepertoireByID

func (s *BadgerStore) RepertoireByID() map[uint32]*peers.Peer

RepertoireByID ...

func (*BadgerStore) RepertoireByPubKey

func (s *BadgerStore) RepertoireByPubKey() map[string]*peers.Peer

RepertoireByPubKey ...

func (*BadgerStore) Reset

func (s *BadgerStore) Reset(frame *Frame) error

Reset ...

func (*BadgerStore) RoundEvents

func (s *BadgerStore) RoundEvents(r int) int

RoundEvents ...

func (*BadgerStore) RoundWitnesses

func (s *BadgerStore) RoundWitnesses(r int) []string

RoundWitnesses ...

func (*BadgerStore) SetBlock

func (s *BadgerStore) SetBlock(block *Block) error

SetBlock ...

func (*BadgerStore) SetEvent

func (s *BadgerStore) SetEvent(event *Event) error

SetEvent ...

func (*BadgerStore) SetFrame

func (s *BadgerStore) SetFrame(frame *Frame) error

SetFrame ...

func (*BadgerStore) SetPeerSet

func (s *BadgerStore) SetPeerSet(round int, peerSet *peers.PeerSet) error

SetPeerSet ...

func (*BadgerStore) SetRound

func (s *BadgerStore) SetRound(r int, round *RoundInfo) error

SetRound ...

func (*BadgerStore) StorePath

func (s *BadgerStore) StorePath() string

StorePath ...

type Block

type Block struct {
	Body       BlockBody
	Signatures map[string]string // [validator hex] => signature
	// contains filtered or unexported fields
}

Block ...

func NewBlock

func NewBlock(blockIndex,
	roundReceived int,
	frameHash []byte,
	peerSlice []*peers.Peer,
	txs [][]byte,
	itxs []InternalTransaction) *Block

NewBlock ...

func NewBlockFromFrame

func NewBlockFromFrame(blockIndex int, frame *Frame) (*Block, error)

NewBlockFromFrame ...

func (*Block) AppendTransactions

func (b *Block) AppendTransactions(txs [][]byte)

AppendTransactions ...

func (*Block) FrameHash

func (b *Block) FrameHash() []byte

FrameHash ...

func (*Block) GetSignature

func (b *Block) GetSignature(validator string) (res BlockSignature, err error)

GetSignature ...

func (*Block) GetSignatures

func (b *Block) GetSignatures() []BlockSignature

GetSignatures ...

func (*Block) Hash

func (b *Block) Hash() ([]byte, error)

Hash ...

func (*Block) Hex

func (b *Block) Hex() string

Hex ...

func (*Block) Index

func (b *Block) Index() int

Index ...

func (*Block) InternalTransactionReceipts

func (b *Block) InternalTransactionReceipts() []InternalTransactionReceipt

InternalTransactionReceipts ...

func (*Block) InternalTransactions

func (b *Block) InternalTransactions() []InternalTransaction

InternalTransactions ...

func (*Block) Marshal

func (b *Block) Marshal() ([]byte, error)

Marshal ...

func (*Block) PeersHash

func (b *Block) PeersHash() []byte

PeersHash ...

func (*Block) RoundReceived

func (b *Block) RoundReceived() int

RoundReceived ...

func (*Block) SetSignature

func (b *Block) SetSignature(bs BlockSignature) error

SetSignature ...

func (*Block) Sign

func (b *Block) Sign(privKey *ecdsa.PrivateKey) (bs BlockSignature, err error)

Sign ...

func (*Block) StateHash

func (b *Block) StateHash() []byte

StateHash ...

func (*Block) Transactions

func (b *Block) Transactions() [][]byte

Transactions ...

func (*Block) Unmarshal

func (b *Block) Unmarshal(data []byte) error

Unmarshal ...

func (*Block) Verify

func (b *Block) Verify(sig BlockSignature) (bool, error)

Verify ...

type BlockBody

type BlockBody struct {
	Index                       int
	RoundReceived               int
	StateHash                   []byte
	FrameHash                   []byte
	PeersHash                   []byte
	Transactions                [][]byte
	InternalTransactions        []InternalTransaction
	InternalTransactionReceipts []InternalTransactionReceipt
}

BlockBody ...

func (*BlockBody) Hash

func (bb *BlockBody) Hash() ([]byte, error)

Hash ...

func (*BlockBody) Marshal

func (bb *BlockBody) Marshal() ([]byte, error)

Marshal - json encoding of body only

func (*BlockBody) Unmarshal

func (bb *BlockBody) Unmarshal(data []byte) error

Unmarshal ...

type BlockSignature

type BlockSignature struct {
	Validator []byte
	Index     int //Block Index
	Signature string
}

BlockSignature ...

func (*BlockSignature) Key

func (bs *BlockSignature) Key() string

Key ...

func (*BlockSignature) Marshal

func (bs *BlockSignature) Marshal() ([]byte, error)

Marshal ...

func (*BlockSignature) ToWire

func (bs *BlockSignature) ToWire() WireBlockSignature

ToWire ...

func (*BlockSignature) Unmarshal

func (bs *BlockSignature) Unmarshal(data []byte) error

Unmarshal ...

func (*BlockSignature) ValidatorHex

func (bs *BlockSignature) ValidatorHex() string

ValidatorHex ...

type ByLamportTimestamp

type ByLamportTimestamp []*Event

ByLamportTimestamp implements sort.Interface for []Event based on the lamportTimestamp field. THIS IS A TOTAL ORDER

func (ByLamportTimestamp) Len

func (a ByLamportTimestamp) Len() int

Len ...

func (ByLamportTimestamp) Less

func (a ByLamportTimestamp) Less(i, j int) bool

Less ...

func (ByLamportTimestamp) Swap

func (a ByLamportTimestamp) Swap(i, j int)

Swap ...

type ByTopologicalOrder

type ByTopologicalOrder []*Event

ByTopologicalOrder implements sort.Interface for []Event based on the topologicalIndex field. THIS IS A PARTIAL ORDER

func (ByTopologicalOrder) Len

func (a ByTopologicalOrder) Len() int

Len ...

func (ByTopologicalOrder) Less

func (a ByTopologicalOrder) Less(i, j int) bool

Less ...

func (ByTopologicalOrder) Swap

func (a ByTopologicalOrder) Swap(i, j int)

Swap ...

type CoordinatesMap

type CoordinatesMap map[string]EventCoordinates

CoordinatesMap ...

func NewCoordinatesMap

func NewCoordinatesMap() CoordinatesMap

NewCoordinatesMap ...

func (CoordinatesMap) Copy

func (c CoordinatesMap) Copy() CoordinatesMap

Copy ...

type Event

type Event struct {
	Body      EventBody
	Signature string //creator's digital signature of body
	// contains filtered or unexported fields
}

Event ...

func NewEvent

func NewEvent(transactions [][]byte,
	internalTransactions []InternalTransaction,
	blockSignatures []BlockSignature,
	parents []string,
	creator []byte,
	index int) *Event

NewEvent ...

func (*Event) BlockSignatures

func (e *Event) BlockSignatures() []BlockSignature

BlockSignatures ...

func (*Event) Creator

func (e *Event) Creator() string

Creator ...

func (*Event) GetRound

func (e *Event) GetRound() *int

GetRound ...

func (*Event) Hash

func (e *Event) Hash() ([]byte, error)

Hash returns sha256 hash of body

func (*Event) Hex

func (e *Event) Hex() string

Hex ...

func (*Event) Index

func (e *Event) Index() int

Index ...

func (*Event) InternalTransactions

func (e *Event) InternalTransactions() []InternalTransaction

InternalTransactions ...

func (*Event) IsLoaded

func (e *Event) IsLoaded() bool

IsLoaded - True if Event contains a payload or is the initial Event of its creator

func (*Event) Marshal

func (e *Event) Marshal() ([]byte, error)

Marshal - json encoding of body and signature

func (*Event) OtherParent

func (e *Event) OtherParent() string

OtherParent ...

func (*Event) SelfParent

func (e *Event) SelfParent() string

SelfParent ...

func (*Event) SetLamportTimestamp

func (e *Event) SetLamportTimestamp(t int)

SetLamportTimestamp ...

func (*Event) SetRound

func (e *Event) SetRound(r int)

SetRound ...

func (*Event) SetRoundReceived

func (e *Event) SetRoundReceived(rr int)

SetRoundReceived ...

func (*Event) SetWireInfo

func (e *Event) SetWireInfo(selfParentIndex int,
	otherParentCreatorID uint32,
	otherParentIndex int,
	creatorID uint32)

SetWireInfo ...

func (*Event) Sign

func (e *Event) Sign(privKey *ecdsa.PrivateKey) error

Sign signs with an ecdsa sig

func (*Event) ToWire

func (e *Event) ToWire() WireEvent

ToWire ...

func (*Event) Transactions

func (e *Event) Transactions() [][]byte

Transactions ...

func (*Event) Unmarshal

func (e *Event) Unmarshal(data []byte) error

Unmarshal ...

func (*Event) Verify

func (e *Event) Verify() (bool, error)

Verify ...

func (*Event) WireBlockSignatures

func (e *Event) WireBlockSignatures() []WireBlockSignature

WireBlockSignatures ...

type EventBody

type EventBody struct {
	Transactions         [][]byte              //the payload
	InternalTransactions []InternalTransaction //peers add and removal internal consensus
	Parents              []string              //hashes of the event's parents, self-parent first
	Creator              []byte                //creator's public key
	Index                int                   //index in the sequence of events created by Creator
	BlockSignatures      []BlockSignature      //list of Block signatures signed by the Event's Creator ONLY
	// contains filtered or unexported fields
}

EventBody ...

func (*EventBody) Hash

func (e *EventBody) Hash() ([]byte, error)

Hash ...

func (*EventBody) Marshal

func (e *EventBody) Marshal() ([]byte, error)

Marshal - json encoding of body only

func (*EventBody) Unmarshal

func (e *EventBody) Unmarshal(data []byte) error

Unmarshal ...

type EventCoordinates

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

EventCoordinates ...

type Frame

type Frame struct {
	Round    int //RoundReceived
	Peers    []*peers.Peer
	Roots    map[string]*Root
	Events   []*FrameEvent         //Events with RoundReceived = Round
	PeerSets map[int][]*peers.Peer //[round] => Peers
}

Frame ...

func (*Frame) Hash

func (f *Frame) Hash() ([]byte, error)

Hash ...

func (*Frame) Marshal

func (f *Frame) Marshal() ([]byte, error)

Marshal - json encoding of Frame

func (*Frame) SortedFrameEvents

func (f *Frame) SortedFrameEvents() []*FrameEvent

SortedFrameEvents ...

func (*Frame) Unmarshal

func (f *Frame) Unmarshal(data []byte) error

Unmarshal ...

type FrameEvent

type FrameEvent struct {
	Core             *Event //EventBody + Signature
	Round            int
	LamportTimestamp int
	Witness          bool
}

FrameEvent is a wrapper around a regular Event. It contains exported fields Round, Witness, and LamportTimestamp.

type Hashgraph

type Hashgraph struct {
	Store               Store               //store of Events, Rounds, and Blocks
	UndeterminedEvents  []string            //[index] => hash . FIFO queue of Events whose consensus order is not yet determined
	PendingRounds       *PendingRoundsCache //FIFO queue of Rounds which have not attained consensus yet
	PendingSignatures   *SigPool            //Pool of Block signatures that need to be processed (matched with Blocks)
	LastConsensusRound  *int                //index of last consensus round
	FirstConsensusRound *int                //index of first consensus round (only used in tests)
	AnchorBlock         *int                //index of last block with enough signatures

	LastCommitedRoundEvents int //number of events in round before LastConsensusRound
	ConsensusTransactions   int //number of consensus transactions
	PendingLoadedEvents     int //number of loaded events that are not yet committed
	// contains filtered or unexported fields
}

Hashgraph is a DAG of Events. It also contains methods to extract a consensus order of Events and map them onto a blockchain.

func NewHashgraph

func NewHashgraph(store Store, commitCallback InternalCommitCallback, logger *logrus.Entry) *Hashgraph

NewHashgraph instantiates a Hashgraph with an underlying data store and a commit callback

func (*Hashgraph) Bootstrap

func (h *Hashgraph) Bootstrap() error

Bootstrap loads all Events from the Store's DB (if there is one) and feeds them to the Hashgraph consensus methods in topological order. It is assumed that no events are skipped/lost when loading from the database - WE CAN ONLY BOOTSTRAP FROM 0. As Events are inserted and processed, Blocks will be created and committed to the App layer (via the commit callback), so it is also assumed that the application state was reset.

func (*Hashgraph) CheckBlock

func (h *Hashgraph) CheckBlock(block *Block, peerSet *peers.PeerSet) error

CheckBlock returns an error if the Block does not contain valid signatures from MORE than 1/3 of participants

func (*Hashgraph) DecideFame

func (h *Hashgraph) DecideFame() error

DecideFame decides if witnesses are famous

func (*Hashgraph) DecideRoundReceived

func (h *Hashgraph) DecideRoundReceived() error

DecideRoundReceived assigns a RoundReceived to undetermined events when they reach consensus

func (*Hashgraph) DivideRounds

func (h *Hashgraph) DivideRounds() error

DivideRounds assigns a Round and LamportTimestamp to Events, and flags them as witnesses if necessary. Pushes Rounds in the PendingRounds queue if necessary.

func (*Hashgraph) GetAnchorBlockWithFrame

func (h *Hashgraph) GetAnchorBlockWithFrame() (*Block, *Frame, error)

GetAnchorBlockWithFrame returns the AnchorBlock and the corresponding Frame. This can be used as a base to Reset a Hashgraph

func (*Hashgraph) GetFrame

func (h *Hashgraph) GetFrame(roundReceived int) (*Frame, error)

GetFrame computes the Frame corresponding to a RoundReceived.

func (*Hashgraph) Init

func (h *Hashgraph) Init(peerSet *peers.PeerSet) error

Init sets the initial PeerSet, which also creates the corresponding Roots and updates the Repertoire.

func (*Hashgraph) InsertEvent

func (h *Hashgraph) InsertEvent(event *Event, setWireInfo bool) error

InsertEvent attempts to insert an Event in the DAG. It verifies the signature, checks the ancestors are known, and prevents the introduction of forks.

func (*Hashgraph) InsertEventAndRunConsensus

func (h *Hashgraph) InsertEventAndRunConsensus(event *Event, setWireInfo bool) error

InsertEventAndRunConsensus inserts an Event in the Hashgraph and call the consensus methods.

func (*Hashgraph) InsertFrameEvent

func (h *Hashgraph) InsertFrameEvent(frameEvent *FrameEvent) error

InsertFrameEvent inserts the FrameEvent's core Event, without checking its parents or signature. It doesnt add the Event to UndeterminedEvents either.

func (*Hashgraph) ProcessDecidedRounds

func (h *Hashgraph) ProcessDecidedRounds() error

ProcessDecidedRounds takes Rounds whose witnesses are decided, computes the corresponding Frames, maps them into Blocks, and commits the Blocks via the commit channel

func (*Hashgraph) ProcessSigPool

func (h *Hashgraph) ProcessSigPool() error

ProcessSigPool runs through the SignaturePool and tries to map a Signature to a known Block. If a Signature is valid, it is appended to the block and removed from the SignaturePool. The function also updates the AnchorBlock if necessary.

func (*Hashgraph) ReadWireInfo

func (h *Hashgraph) ReadWireInfo(wevent WireEvent) (*Event, error)

ReadWireInfo converts a WireEvent to an Event by replacing int IDs with the corresponding public keys.

func (*Hashgraph) Reset

func (h *Hashgraph) Reset(block *Block, frame *Frame) error

Reset clears the Hashgraph and resets it from a new base.

func (*Hashgraph) SetAnchorBlock

func (h *Hashgraph) SetAnchorBlock(block *Block) error

SetAnchorBlock sets the AnchorBlock index if the proposed block has collected enough signatures (+1/3) and is above the current AnchorBlock. The AnchorBlock is the latest Block that collected +1/3 signatures from validators. It is used in FastForward responses when a node wants to sync to the top of the hashgraph.

type InmemStore

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

InmemStore ...

func NewInmemStore

func NewInmemStore(cacheSize int) *InmemStore

NewInmemStore ...

func (*InmemStore) AddConsensusEvent

func (s *InmemStore) AddConsensusEvent(event *Event) error

AddConsensusEvent ...

func (*InmemStore) CacheSize

func (s *InmemStore) CacheSize() int

CacheSize ...

func (*InmemStore) Close

func (s *InmemStore) Close() error

Close ...

func (*InmemStore) ConsensusEvents

func (s *InmemStore) ConsensusEvents() []string

ConsensusEvents ...

func (*InmemStore) ConsensusEventsCount

func (s *InmemStore) ConsensusEventsCount() int

ConsensusEventsCount ...

func (*InmemStore) FirstRound

func (s *InmemStore) FirstRound(id uint32) (int, bool)

FirstRound ...

func (*InmemStore) GetAllPeerSets

func (s *InmemStore) GetAllPeerSets() (map[int][]*peers.Peer, error)

GetAllPeerSets ...

func (*InmemStore) GetBlock

func (s *InmemStore) GetBlock(index int) (*Block, error)

GetBlock ...

func (*InmemStore) GetEvent

func (s *InmemStore) GetEvent(key string) (*Event, error)

GetEvent ...

func (*InmemStore) GetFrame

func (s *InmemStore) GetFrame(index int) (*Frame, error)

GetFrame ...

func (*InmemStore) GetPeerSet

func (s *InmemStore) GetPeerSet(round int) (*peers.PeerSet, error)

GetPeerSet ...

func (*InmemStore) GetRoot

func (s *InmemStore) GetRoot(participant string) (*Root, error)

GetRoot ...

func (*InmemStore) GetRound

func (s *InmemStore) GetRound(r int) (*RoundInfo, error)

GetRound ...

func (*InmemStore) KnownEvents

func (s *InmemStore) KnownEvents() map[uint32]int

KnownEvents ...

func (*InmemStore) LastBlockIndex

func (s *InmemStore) LastBlockIndex() int

LastBlockIndex ...

func (*InmemStore) LastConsensusEventFrom

func (s *InmemStore) LastConsensusEventFrom(participant string) (last string, err error)

LastConsensusEventFrom ...

func (*InmemStore) LastEventFrom

func (s *InmemStore) LastEventFrom(participant string) (last string, err error)

LastEventFrom ...

func (*InmemStore) LastRound

func (s *InmemStore) LastRound() int

LastRound ...

func (*InmemStore) ParticipantEvent

func (s *InmemStore) ParticipantEvent(participant string, index int) (string, error)

ParticipantEvent ...

func (*InmemStore) ParticipantEvents

func (s *InmemStore) ParticipantEvents(participant string, skip int) ([]string, error)

ParticipantEvents ...

func (*InmemStore) RepertoireByID

func (s *InmemStore) RepertoireByID() map[uint32]*peers.Peer

RepertoireByID ...

func (*InmemStore) RepertoireByPubKey

func (s *InmemStore) RepertoireByPubKey() map[string]*peers.Peer

RepertoireByPubKey ...

func (*InmemStore) Reset

func (s *InmemStore) Reset(frame *Frame) error

Reset ...

func (*InmemStore) RoundEvents

func (s *InmemStore) RoundEvents(r int) int

RoundEvents ...

func (*InmemStore) RoundWitnesses

func (s *InmemStore) RoundWitnesses(r int) []string

RoundWitnesses ...

func (*InmemStore) SetBlock

func (s *InmemStore) SetBlock(block *Block) error

SetBlock ...

func (*InmemStore) SetEvent

func (s *InmemStore) SetEvent(event *Event) error

SetEvent ...

func (*InmemStore) SetFrame

func (s *InmemStore) SetFrame(frame *Frame) error

SetFrame ...

func (*InmemStore) SetPeerSet

func (s *InmemStore) SetPeerSet(round int, peerSet *peers.PeerSet) error

SetPeerSet updates the peerSetCache and participantEventsCache

func (*InmemStore) SetRound

func (s *InmemStore) SetRound(r int, round *RoundInfo) error

SetRound ...

func (*InmemStore) StorePath

func (s *InmemStore) StorePath() string

StorePath ...

type InternalCommitCallback

type InternalCommitCallback func(*Block) error

InternalCommitCallback is called by the Hashgraph to commit a Block. The InternalCommitCallback will likely itself call the ProxyCommitCallback. We add a layer of indirection because processing the CommitResponse should be handled by the Core object, not the hashgraph; the hashgraph only knows if there was an error or not.

type InternalTransaction

type InternalTransaction struct {
	Body      InternalTransactionBody
	Signature string
}

InternalTransaction ...

func NewInternalTransaction

func NewInternalTransaction(tType TransactionType, peer peers.Peer) InternalTransaction

NewInternalTransaction ...

func NewInternalTransactionJoin

func NewInternalTransactionJoin(peer peers.Peer) InternalTransaction

NewInternalTransactionJoin ...

func NewInternalTransactionLeave

func NewInternalTransactionLeave(peer peers.Peer) InternalTransaction

NewInternalTransactionLeave ...

func (*InternalTransaction) AsAccepted

AsAccepted returns a receipt to accept an InternalTransaction

func (*InternalTransaction) AsRefused

AsRefused return a receipt to refuse an InternalTransaction

func (*InternalTransaction) HashString

func (t *InternalTransaction) HashString() string

HashString returns a string representation of the body's hash. It is used in node/core as a key in a map to keep track of InternalTransactions as they are being processed asynchronously by the consensus and application.

func (*InternalTransaction) Marshal

func (t *InternalTransaction) Marshal() ([]byte, error)

Marshal ...

func (*InternalTransaction) Sign

func (t *InternalTransaction) Sign(privKey *ecdsa.PrivateKey) error

Sign returns the ecdsa signature of the SHA256 hash of the transaction's body

func (*InternalTransaction) Unmarshal

func (t *InternalTransaction) Unmarshal(data []byte) error

Unmarshal ...

func (*InternalTransaction) Verify

func (t *InternalTransaction) Verify() (bool, error)

Verify ...

type InternalTransactionBody

type InternalTransactionBody struct {
	Type TransactionType
	Peer peers.Peer
}

InternalTransactionBody ...

func (*InternalTransactionBody) Hash

func (i *InternalTransactionBody) Hash() ([]byte, error)

Hash returns the SHA256 hash of the InternalTransactionBody,

func (*InternalTransactionBody) Marshal

func (i *InternalTransactionBody) Marshal() ([]byte, error)

Marshal - json encoding of body

type InternalTransactionReceipt

type InternalTransactionReceipt struct {
	InternalTransaction InternalTransaction
	Accepted            bool
}

InternalTransactionReceipt records the decision by the application to accept or refuse and InternalTransaction

type Key

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

Key ...

func (Key) ToString

func (k Key) ToString() string

ToString ...

type OrderedPendingRounds

type OrderedPendingRounds []*PendingRound

OrderedPendingRounds ...

func (OrderedPendingRounds) Len

func (a OrderedPendingRounds) Len() int

Len returns the length

func (OrderedPendingRounds) Less

func (a OrderedPendingRounds) Less(i, j int) bool

Less returns true if element i is less than element j.

func (OrderedPendingRounds) Swap

func (a OrderedPendingRounds) Swap(i, j int)

Swap swaps 2 elements

type ParticipantEventsCache

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

ParticipantEventsCache ...

func NewParticipantEventsCache

func NewParticipantEventsCache(size int) *ParticipantEventsCache

NewParticipantEventsCache ...

func (*ParticipantEventsCache) AddPeer

func (pec *ParticipantEventsCache) AddPeer(peer *peers.Peer) error

AddPeer ...

func (*ParticipantEventsCache) Get

func (pec *ParticipantEventsCache) Get(participant string, skipIndex int) ([]string, error)

Get returns participant events with index > skip

func (*ParticipantEventsCache) GetItem

func (pec *ParticipantEventsCache) GetItem(participant string, index int) (string, error)

GetItem ...

func (*ParticipantEventsCache) GetLast

func (pec *ParticipantEventsCache) GetLast(participant string) (string, error)

GetLast ...

func (*ParticipantEventsCache) Known

func (pec *ParticipantEventsCache) Known() map[uint32]int

Known returns [participant id] => lastKnownIndex

func (*ParticipantEventsCache) Set

func (pec *ParticipantEventsCache) Set(participant string, hash string, index int) error

Set ...

type PeerSetCache

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

PeerSetCache ...

func NewPeerSetCache

func NewPeerSetCache() *PeerSetCache

NewPeerSetCache ...

func (*PeerSetCache) FirstRound

func (c *PeerSetCache) FirstRound(id uint32) (int, bool)

FirstRound ...

func (*PeerSetCache) Get

func (c *PeerSetCache) Get(round int) (*peers.PeerSet, error)

Get ...

func (*PeerSetCache) GetAll

func (c *PeerSetCache) GetAll() (map[int][]*peers.Peer, error)

GetAll ...

func (*PeerSetCache) RepertoireByID

func (c *PeerSetCache) RepertoireByID() map[uint32]*peers.Peer

RepertoireByID ...

func (*PeerSetCache) RepertoireByPubKey

func (c *PeerSetCache) RepertoireByPubKey() map[string]*peers.Peer

RepertoireByPubKey ...

func (*PeerSetCache) Set

func (c *PeerSetCache) Set(round int, peerSet *peers.PeerSet) error

Set ...

type PendingRound

type PendingRound struct {
	Index   int
	Decided bool
}

PendingRound ...

type PendingRoundsCache

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

PendingRoundsCache ...

func NewPendingRoundsCache

func NewPendingRoundsCache() *PendingRoundsCache

NewPendingRoundsCache ...

func (*PendingRoundsCache) Clean

func (c *PendingRoundsCache) Clean(processedRounds []int)

Clean ...

func (*PendingRoundsCache) GetOrderedPendingRounds

func (c *PendingRoundsCache) GetOrderedPendingRounds() OrderedPendingRounds

GetOrderedPendingRounds ...

func (*PendingRoundsCache) Queued

func (c *PendingRoundsCache) Queued(round int) bool

Queued ...

func (*PendingRoundsCache) Set

func (c *PendingRoundsCache) Set(pendingRound *PendingRound)

Set ...

func (*PendingRoundsCache) Update

func (c *PendingRoundsCache) Update(decidedRounds []int)

Update ...

type Root

type Root struct {
	Events []*FrameEvent
}

Root forms a base on top of which a participant's Events can be inserted. It contains FrameEvents sorted by Lamport timestamp.

func NewRoot

func NewRoot() *Root

NewRoot instantianted an new empty root

func (*Root) Hash

func (r *Root) Hash() (string, error)

Hash ...

func (*Root) Insert

func (r *Root) Insert(frameEvent *FrameEvent)

Insert appends a FrameEvent to the root's Event slice. It is assumend that items are inserted in topological order.

func (*Root) Marshal

func (r *Root) Marshal() ([]byte, error)

Marshal ...

func (*Root) Unmarshal

func (r *Root) Unmarshal(data []byte) error

Unmarshal decodes data into a Root object

type RoundEvent

type RoundEvent struct {
	Witness bool
	Famous  common.Trilean
}

RoundEvent ...

type RoundInfo

type RoundInfo struct {
	CreatedEvents  map[string]RoundEvent
	ReceivedEvents []string
	// contains filtered or unexported fields
}

RoundInfo ...

func NewRoundInfo

func NewRoundInfo() *RoundInfo

NewRoundInfo ...

func (*RoundInfo) AddCreatedEvent

func (r *RoundInfo) AddCreatedEvent(x string, witness bool)

AddCreatedEvent ...

func (*RoundInfo) AddReceivedEvent

func (r *RoundInfo) AddReceivedEvent(x string)

AddReceivedEvent ...

func (*RoundInfo) FamousWitnesses

func (r *RoundInfo) FamousWitnesses() []string

FamousWitnesses returns famous witnesses

func (*RoundInfo) IsDecided

func (r *RoundInfo) IsDecided(witness string) bool

IsDecided ...

func (*RoundInfo) IsQueued

func (r *RoundInfo) IsQueued() bool

IsQueued ...

func (*RoundInfo) Marshal

func (r *RoundInfo) Marshal() ([]byte, error)

Marshal ...

func (*RoundInfo) SetFame

func (r *RoundInfo) SetFame(x string, f bool)

SetFame ...

func (*RoundInfo) Unmarshal

func (r *RoundInfo) Unmarshal(data []byte) error

Unmarshal ...

func (*RoundInfo) Witnesses

func (r *RoundInfo) Witnesses() []string

Witnesses return witnesses

func (*RoundInfo) WitnessesDecided

func (r *RoundInfo) WitnessesDecided(peerSet *peers.PeerSet) bool

WitnessesDecided returns true if a super-majority of witnesses are decided, and there are no undecided witnesses. Our algorithm relies on the fact that a witness that is not yet known when a super-majority of witnesses are already decided, has no chance of ever being famous. Once a Round is decided it stays decided, even if new witnesses are added after it was first decided.

type SigPool

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

SigPool ...

func NewSigPool

func NewSigPool() *SigPool

NewSigPool ...

func (*SigPool) Add

func (sp *SigPool) Add(blockSignature BlockSignature)

Add ...

func (*SigPool) Items

func (sp *SigPool) Items() map[string]BlockSignature

Items ...

func (*SigPool) Len

func (sp *SigPool) Len() int

Len ...

func (*SigPool) Remove

func (sp *SigPool) Remove(key string)

Remove ...

func (*SigPool) RemoveSlice

func (sp *SigPool) RemoveSlice(sigs []BlockSignature)

RemoveSlice ...

func (*SigPool) Slice

func (sp *SigPool) Slice() []BlockSignature

Slice ...

type SortedFrameEvents

type SortedFrameEvents []*FrameEvent

SortedFrameEvents implements sort.Interface for []FameEvent based on the lamportTimestamp field. THIS IS A TOTAL ORDER

func (SortedFrameEvents) Len

func (a SortedFrameEvents) Len() int

Len ...

func (SortedFrameEvents) Less

func (a SortedFrameEvents) Less(i, j int) bool

Less ...

func (SortedFrameEvents) Swap

func (a SortedFrameEvents) Swap(i, j int)

Swap ...

type Store

type Store interface {
	CacheSize() int
	GetPeerSet(int) (*peers.PeerSet, error)
	SetPeerSet(int, *peers.PeerSet) error
	GetAllPeerSets() (map[int][]*peers.Peer, error)
	FirstRound(uint32) (int, bool)
	RepertoireByPubKey() map[string]*peers.Peer
	RepertoireByID() map[uint32]*peers.Peer
	GetEvent(string) (*Event, error)
	SetEvent(*Event) error
	ParticipantEvents(string, int) ([]string, error)
	ParticipantEvent(string, int) (string, error)
	LastEventFrom(string) (string, error)
	LastConsensusEventFrom(string) (string, error)
	KnownEvents() map[uint32]int
	ConsensusEvents() []string
	ConsensusEventsCount() int
	AddConsensusEvent(*Event) error
	GetRound(int) (*RoundInfo, error)
	SetRound(int, *RoundInfo) error
	LastRound() int
	RoundWitnesses(int) []string
	RoundEvents(int) int
	GetRoot(string) (*Root, error)
	GetBlock(int) (*Block, error)
	SetBlock(*Block) error
	LastBlockIndex() int
	GetFrame(int) (*Frame, error)
	SetFrame(*Frame) error
	Reset(*Frame) error
	Close() error
	StorePath() string
}

Store ...

type TransactionType

type TransactionType uint8

TransactionType ...

const (
	// PEER_ADD ...
	PEER_ADD TransactionType = iota
	// PEER_REMOVE ...
	PEER_REMOVE
)

func (TransactionType) String

func (t TransactionType) String() string

String ...

type TreKey

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

TreKey ...

func (TreKey) ToString

func (k TreKey) ToString() string

ToString ...

type WireBlockSignature

type WireBlockSignature struct {
	Index     int
	Signature string
}

WireBlockSignature ...

type WireBody

type WireBody struct {
	Transactions         [][]byte
	InternalTransactions []InternalTransaction
	BlockSignatures      []WireBlockSignature

	CreatorID            uint32
	OtherParentCreatorID uint32
	Index                int
	SelfParentIndex      int
	OtherParentIndex     int
}

WireBody ...

type WireEvent

type WireEvent struct {
	Body      WireBody
	Signature string
}

WireEvent ...

func (*WireEvent) BlockSignatures

func (we *WireEvent) BlockSignatures(validator []byte) []BlockSignature

BlockSignatures ...

Jump to

Keyboard shortcuts

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