Documentation
¶
Index ¶
- type BadgerStore
- func (s *BadgerStore) AddConsensusEvent(event Event) error
- func (s *BadgerStore) CacheSize() int
- func (s *BadgerStore) Close() error
- func (s *BadgerStore) ConsensusEvents() []string
- func (s *BadgerStore) ConsensusEventsCount() int
- func (s *BadgerStore) GetBlock(rr int) (Block, error)
- func (s *BadgerStore) GetEvent(key string) (event Event, err error)
- func (s *BadgerStore) GetFrame(rr int) (Frame, error)
- func (s *BadgerStore) GetRoot(participant string) (Root, error)
- func (s *BadgerStore) GetRound(r int) (RoundInfo, error)
- func (s *BadgerStore) KnownEvents() map[int]int
- func (s *BadgerStore) LastBlockIndex() int
- func (s *BadgerStore) LastConsensusEventFrom(participant string) (last string, isRoot bool, err error)
- func (s *BadgerStore) LastEventFrom(participant string) (last string, isRoot bool, err error)
- func (s *BadgerStore) LastRound() int
- func (s *BadgerStore) ParticipantEvent(participant string, index int) (string, error)
- func (s *BadgerStore) ParticipantEvents(participant string, skip int) ([]string, error)
- func (s *BadgerStore) Participants() (map[string]int, error)
- func (s *BadgerStore) Reset(roots map[string]Root) error
- func (s *BadgerStore) RootsBySelfParent() (map[string]Root, error)
- func (s *BadgerStore) RoundEvents(r int) int
- func (s *BadgerStore) RoundWitnesses(r int) []string
- func (s *BadgerStore) SetBlock(block Block) error
- func (s *BadgerStore) SetEvent(event Event) error
- func (s *BadgerStore) SetFrame(frame Frame) error
- func (s *BadgerStore) SetRound(r int, round RoundInfo) error
- type Block
- func (b *Block) AppendTransactions(txs [][]byte)
- func (b *Block) FrameHash() []byte
- func (b *Block) GetSignature(validator string) (res BlockSignature, err error)
- func (b *Block) GetSignatures() []BlockSignature
- func (b *Block) Hash() ([]byte, error)
- func (b *Block) Hex() string
- func (b *Block) Index() int
- func (b *Block) Marshal() ([]byte, error)
- func (b *Block) RoundReceived() int
- func (b *Block) SetSignature(bs BlockSignature) error
- func (b *Block) Sign(privKey *ecdsa.PrivateKey) (bs BlockSignature, err error)
- func (b *Block) StateHash() []byte
- func (b *Block) Transactions() [][]byte
- func (b *Block) Unmarshal(data []byte) error
- func (b *Block) Verify(sig BlockSignature) (bool, error)
- type BlockBody
- type BlockSignature
- type ByLamportTimestamp
- type ByTopologicalOrder
- type Event
- func (e *Event) BlockSignatures() []BlockSignature
- func (e *Event) Creator() string
- func (e *Event) Hash() ([]byte, error)
- func (e *Event) Hex() string
- func (e *Event) Index() int
- func (e *Event) IsLoaded() bool
- func (e *Event) Marshal() ([]byte, error)
- func (e *Event) OtherParent() string
- func (e *Event) SelfParent() string
- func (e *Event) SetLamportTimestamp(t int)
- func (e *Event) SetRound(r int)
- func (e *Event) SetRoundReceived(rr int)
- func (e *Event) SetWireInfo(selfParentIndex, otherParentCreatorID, otherParentIndex, creatorID int)
- func (e *Event) Sign(privKey *ecdsa.PrivateKey) error
- func (e *Event) ToWire() WireEvent
- func (e *Event) Transactions() [][]byte
- func (e *Event) Unmarshal(data []byte) error
- func (e *Event) Verify() (bool, error)
- func (e *Event) WireBlockSignatures() []WireBlockSignature
- type EventBody
- type EventCoordinates
- type Frame
- type Hashgraph
- func (h *Hashgraph) Bootstrap() error
- func (h *Hashgraph) CheckBlock(block Block) error
- func (h *Hashgraph) DecideFame() error
- func (h *Hashgraph) DecideRoundReceived() error
- func (h *Hashgraph) DivideRounds() error
- func (h *Hashgraph) GetAnchorBlockWithFrame() (Block, Frame, error)
- func (h *Hashgraph) GetFrame(roundReceived int) (Frame, error)
- func (h *Hashgraph) InsertEvent(event Event, setWireInfo bool) error
- func (h *Hashgraph) ProcessDecidedRounds() error
- func (h *Hashgraph) ProcessSigPool() error
- func (h *Hashgraph) ReadWireInfo(wevent WireEvent) (*Event, error)
- func (h *Hashgraph) Reset(block Block, frame Frame) error
- type InmemStore
- func (s *InmemStore) AddConsensusEvent(event Event) error
- func (s *InmemStore) CacheSize() int
- func (s *InmemStore) Close() error
- func (s *InmemStore) ConsensusEvents() []string
- func (s *InmemStore) ConsensusEventsCount() int
- func (s *InmemStore) GetBlock(index int) (Block, error)
- func (s *InmemStore) GetEvent(key string) (Event, error)
- func (s *InmemStore) GetFrame(index int) (Frame, error)
- func (s *InmemStore) GetRoot(participant string) (Root, error)
- func (s *InmemStore) GetRound(r int) (RoundInfo, error)
- func (s *InmemStore) KnownEvents() map[int]int
- func (s *InmemStore) LastBlockIndex() int
- func (s *InmemStore) LastConsensusEventFrom(participant string) (last string, isRoot bool, err error)
- func (s *InmemStore) LastEventFrom(participant string) (last string, isRoot bool, err error)
- func (s *InmemStore) LastRound() int
- func (s *InmemStore) ParticipantEvent(participant string, index int) (string, error)
- func (s *InmemStore) ParticipantEvents(participant string, skip int) ([]string, error)
- func (s *InmemStore) Participants() (map[string]int, error)
- func (s *InmemStore) Reset(roots map[string]Root) error
- func (s *InmemStore) RootsBySelfParent() (map[string]Root, error)
- func (s *InmemStore) RoundEvents(r int) int
- func (s *InmemStore) RoundWitnesses(r int) []string
- func (s *InmemStore) SetBlock(block Block) error
- func (s *InmemStore) SetEvent(event Event) error
- func (s *InmemStore) SetFrame(frame Frame) error
- func (s *InmemStore) SetRound(r int, round RoundInfo) error
- type Key
- type ParentRoundInfo
- type ParticipantBlockSignaturesCache
- func (psc *ParticipantBlockSignaturesCache) Get(participant string, skipIndex int) ([]BlockSignature, error)
- func (psc *ParticipantBlockSignaturesCache) GetItem(participant string, index int) (BlockSignature, error)
- func (psc *ParticipantBlockSignaturesCache) GetLast(participant string) (BlockSignature, error)
- func (psc *ParticipantBlockSignaturesCache) Known() map[int]int
- func (psc *ParticipantBlockSignaturesCache) Reset() error
- func (psc *ParticipantBlockSignaturesCache) Set(participant string, sig BlockSignature) error
- type ParticipantEventsCache
- func (pec *ParticipantEventsCache) Get(participant string, skipIndex int) ([]string, error)
- func (pec *ParticipantEventsCache) GetItem(participant string, index int) (string, error)
- func (pec *ParticipantEventsCache) GetLast(participant string) (string, error)
- func (pec *ParticipantEventsCache) GetLastConsensus(participant string) (string, error)
- func (pec *ParticipantEventsCache) Known() map[int]int
- func (pec *ParticipantEventsCache) Reset() error
- func (pec *ParticipantEventsCache) Set(participant string, hash string, index int) error
- type Root
- type RootEvent
- type RoundEvent
- type RoundInfo
- func (r *RoundInfo) AddEvent(x string, witness bool)
- func (r *RoundInfo) ConsensusEvents() []string
- func (r *RoundInfo) FamousWitnesses() []string
- func (r *RoundInfo) IsDecided(witness string) bool
- func (r *RoundInfo) Marshal() ([]byte, error)
- func (r *RoundInfo) RoundEvents() []string
- func (r *RoundInfo) SetConsensusEvent(x string)
- func (r *RoundInfo) SetFame(x string, f bool)
- func (r *RoundInfo) Unmarshal(data []byte) error
- func (r *RoundInfo) Witnesses() []string
- func (r *RoundInfo) WitnessesDecided() bool
- type Store
- type Trilean
- type WireBlockSignature
- type WireBody
- type WireEvent
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type BadgerStore ¶
type BadgerStore struct {
// contains filtered or unexported fields
}
func LoadBadgerStore ¶
func LoadBadgerStore(cacheSize int, path string) (*BadgerStore, error)
LoadBadgerStore creates a Store from an existing database
func NewBadgerStore ¶
NewBadgerStore creates a brand new Store with a new database
func (*BadgerStore) AddConsensusEvent ¶
func (s *BadgerStore) AddConsensusEvent(event Event) error
func (*BadgerStore) CacheSize ¶
func (s *BadgerStore) CacheSize() int
func (*BadgerStore) Close ¶
func (s *BadgerStore) Close() error
func (*BadgerStore) ConsensusEvents ¶
func (s *BadgerStore) ConsensusEvents() []string
func (*BadgerStore) ConsensusEventsCount ¶
func (s *BadgerStore) ConsensusEventsCount() int
func (*BadgerStore) KnownEvents ¶
func (s *BadgerStore) KnownEvents() map[int]int
func (*BadgerStore) LastBlockIndex ¶
func (s *BadgerStore) LastBlockIndex() int
func (*BadgerStore) LastConsensusEventFrom ¶
func (s *BadgerStore) LastConsensusEventFrom(participant string) (last string, isRoot bool, err error)
func (*BadgerStore) LastEventFrom ¶
func (s *BadgerStore) LastEventFrom(participant string) (last string, isRoot bool, err error)
func (*BadgerStore) LastRound ¶
func (s *BadgerStore) LastRound() int
func (*BadgerStore) ParticipantEvent ¶
func (s *BadgerStore) ParticipantEvent(participant string, index int) (string, error)
func (*BadgerStore) ParticipantEvents ¶
func (s *BadgerStore) ParticipantEvents(participant string, skip int) ([]string, error)
func (*BadgerStore) Participants ¶
func (s *BadgerStore) Participants() (map[string]int, error)
func (*BadgerStore) RootsBySelfParent ¶
func (s *BadgerStore) RootsBySelfParent() (map[string]Root, error)
func (*BadgerStore) RoundEvents ¶
func (s *BadgerStore) RoundEvents(r int) int
func (*BadgerStore) RoundWitnesses ¶
func (s *BadgerStore) RoundWitnesses(r int) []string
func (*BadgerStore) SetBlock ¶
func (s *BadgerStore) SetBlock(block Block) error
func (*BadgerStore) SetEvent ¶
func (s *BadgerStore) SetEvent(event Event) error
func (*BadgerStore) SetFrame ¶
func (s *BadgerStore) SetFrame(frame Frame) error
type Block ¶
type Block struct {
Body BlockBody
Signatures map[string]string // [validator hex] => signature
// contains filtered or unexported fields
}
func (*Block) AppendTransactions ¶
func (*Block) GetSignature ¶
func (b *Block) GetSignature(validator string) (res BlockSignature, err error)
func (*Block) GetSignatures ¶
func (b *Block) GetSignatures() []BlockSignature
func (*Block) RoundReceived ¶
func (*Block) SetSignature ¶
func (b *Block) SetSignature(bs BlockSignature) error
func (*Block) Sign ¶
func (b *Block) Sign(privKey *ecdsa.PrivateKey) (bs BlockSignature, err error)
func (*Block) Transactions ¶
type BlockBody ¶
type BlockBody struct {
Index int
RoundReceived int
StateHash []byte
FrameHash []byte
Transactions [][]byte
}
type BlockSignature ¶
func (*BlockSignature) Marshal ¶
func (bs *BlockSignature) Marshal() ([]byte, error)
func (*BlockSignature) ToWire ¶
func (bs *BlockSignature) ToWire() WireBlockSignature
func (*BlockSignature) Unmarshal ¶
func (bs *BlockSignature) Unmarshal(data []byte) error
func (*BlockSignature) ValidatorHex ¶
func (bs *BlockSignature) ValidatorHex() string
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
func (ByLamportTimestamp) Less ¶
func (a ByLamportTimestamp) Less(i, j int) bool
func (ByLamportTimestamp) Swap ¶
func (a ByLamportTimestamp) Swap(i, j int)
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
func (ByTopologicalOrder) Less ¶
func (a ByTopologicalOrder) Less(i, j int) bool
func (ByTopologicalOrder) Swap ¶
func (a ByTopologicalOrder) Swap(i, j int)
type Event ¶
type Event struct {
Body EventBody
Signature string //creator's digital signature of body
// contains filtered or unexported fields
}
func (*Event) BlockSignatures ¶
func (e *Event) BlockSignatures() []BlockSignature
func (*Event) OtherParent ¶
func (*Event) SelfParent ¶
func (*Event) SetLamportTimestamp ¶
func (*Event) SetRoundReceived ¶
func (*Event) SetWireInfo ¶
func (*Event) Transactions ¶
func (*Event) WireBlockSignatures ¶
func (e *Event) WireBlockSignatures() []WireBlockSignature
type EventBody ¶
type EventBody struct {
Transactions [][]byte //the payload
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
}
type EventCoordinates ¶
type EventCoordinates struct {
// contains filtered or unexported fields
}
type Frame ¶
type Hashgraph ¶
type Hashgraph struct {
Participants map[string]int //[public key] => id
ReverseParticipants map[int]string //[id] => public key
Store Store //store of Events, Rounds, and Blocks
UndeterminedEvents []string //[index] => hash . FIFO queue of Events whose consensus order is not yet determined
PendingRounds []*pendingRound //FIFO queue of Rounds which have not attained consensus yet
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
SigPool []BlockSignature //Pool of Block signatures that need to be processed
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(participants map[string]int, store Store, commitCh chan Block, logger *logrus.Entry) *Hashgraph
NewHashgraph instantiates a Hashgraph from a list of participants, underlying data store and commit channel
func (*Hashgraph) Bootstrap ¶
Bootstrap loads all Events from the Store's DB (if there is one) and feeds them to the Hashgraph (in topological order) for consensus ordering. After this method call, the Hashgraph should be in a state coherent with the 'tip' of the Hashgraph
func (*Hashgraph) CheckBlock ¶
CheckBlock returns an error if the Block does not contain valid signatures from MORE than 1/3 of participants
func (*Hashgraph) DecideFame ¶
DecideFame decides if witnesses are famous
func (*Hashgraph) DecideRoundReceived ¶
DecideRoundReceived assigns a RoundReceived to undetermined events when they reach consensus
func (*Hashgraph) DivideRounds ¶
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 ¶
GetAnchorBlockWithFrame returns the AnchorBlock and the corresponding Frame. This can be used as a base to Reset a Hashgraph
func (*Hashgraph) InsertEvent ¶
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) ProcessDecidedRounds ¶
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 ¶
ProcessSigPool runs through the SignaturePool and tries to map a Signature to a known Block. If a Signature is found to be valid for a known Block, it is appended to the block and removed from the SignaturePool
func (*Hashgraph) ReadWireInfo ¶
ReadWireInfo converts a WireEvent to an Event by replacing int IDs with the corresponding public keys.
type InmemStore ¶
type InmemStore struct {
// contains filtered or unexported fields
}
func NewInmemStore ¶
func NewInmemStore(participants map[string]int, cacheSize int) *InmemStore
func (*InmemStore) AddConsensusEvent ¶
func (s *InmemStore) AddConsensusEvent(event Event) error
func (*InmemStore) CacheSize ¶
func (s *InmemStore) CacheSize() int
func (*InmemStore) Close ¶
func (s *InmemStore) Close() error
func (*InmemStore) ConsensusEvents ¶
func (s *InmemStore) ConsensusEvents() []string
func (*InmemStore) ConsensusEventsCount ¶
func (s *InmemStore) ConsensusEventsCount() int
func (*InmemStore) KnownEvents ¶
func (s *InmemStore) KnownEvents() map[int]int
func (*InmemStore) LastBlockIndex ¶
func (s *InmemStore) LastBlockIndex() int
func (*InmemStore) LastConsensusEventFrom ¶
func (s *InmemStore) LastConsensusEventFrom(participant string) (last string, isRoot bool, err error)
func (*InmemStore) LastEventFrom ¶
func (s *InmemStore) LastEventFrom(participant string) (last string, isRoot bool, err error)
func (*InmemStore) LastRound ¶
func (s *InmemStore) LastRound() int
func (*InmemStore) ParticipantEvent ¶
func (s *InmemStore) ParticipantEvent(participant string, index int) (string, error)
func (*InmemStore) ParticipantEvents ¶
func (s *InmemStore) ParticipantEvents(participant string, skip int) ([]string, error)
func (*InmemStore) Participants ¶
func (s *InmemStore) Participants() (map[string]int, error)
func (*InmemStore) RootsBySelfParent ¶
func (s *InmemStore) RootsBySelfParent() (map[string]Root, error)
func (*InmemStore) RoundEvents ¶
func (s *InmemStore) RoundEvents(r int) int
func (*InmemStore) RoundWitnesses ¶
func (s *InmemStore) RoundWitnesses(r int) []string
func (*InmemStore) SetBlock ¶
func (s *InmemStore) SetBlock(block Block) error
func (*InmemStore) SetEvent ¶
func (s *InmemStore) SetEvent(event Event) error
func (*InmemStore) SetFrame ¶
func (s *InmemStore) SetFrame(frame Frame) error
type ParentRoundInfo ¶
type ParentRoundInfo struct {
// contains filtered or unexported fields
}
func NewBaseParentRoundInfo ¶
func NewBaseParentRoundInfo() ParentRoundInfo
type ParticipantBlockSignaturesCache ¶
type ParticipantBlockSignaturesCache struct {
// contains filtered or unexported fields
}
func NewParticipantBlockSignaturesCache ¶
func NewParticipantBlockSignaturesCache(size int, participants map[string]int) *ParticipantBlockSignaturesCache
func (*ParticipantBlockSignaturesCache) Get ¶
func (psc *ParticipantBlockSignaturesCache) Get(participant string, skipIndex int) ([]BlockSignature, error)
return participant BlockSignatures where index > skip
func (*ParticipantBlockSignaturesCache) GetItem ¶
func (psc *ParticipantBlockSignaturesCache) GetItem(participant string, index int) (BlockSignature, error)
func (*ParticipantBlockSignaturesCache) GetLast ¶
func (psc *ParticipantBlockSignaturesCache) GetLast(participant string) (BlockSignature, error)
func (*ParticipantBlockSignaturesCache) Known ¶
func (psc *ParticipantBlockSignaturesCache) Known() map[int]int
returns [participant id] => last BlockSignature Index
func (*ParticipantBlockSignaturesCache) Reset ¶
func (psc *ParticipantBlockSignaturesCache) Reset() error
func (*ParticipantBlockSignaturesCache) Set ¶
func (psc *ParticipantBlockSignaturesCache) Set(participant string, sig BlockSignature) error
type ParticipantEventsCache ¶
type ParticipantEventsCache struct {
// contains filtered or unexported fields
}
func NewParticipantEventsCache ¶
func NewParticipantEventsCache(size int, participants map[string]int) *ParticipantEventsCache
func (*ParticipantEventsCache) Get ¶
func (pec *ParticipantEventsCache) Get(participant string, skipIndex int) ([]string, error)
return participant events with index > skip
func (*ParticipantEventsCache) GetItem ¶
func (pec *ParticipantEventsCache) GetItem(participant string, index int) (string, error)
func (*ParticipantEventsCache) GetLast ¶
func (pec *ParticipantEventsCache) GetLast(participant string) (string, error)
func (*ParticipantEventsCache) GetLastConsensus ¶
func (pec *ParticipantEventsCache) GetLastConsensus(participant string) (string, error)
func (*ParticipantEventsCache) Known ¶
func (pec *ParticipantEventsCache) Known() map[int]int
returns [participant id] => lastKnownIndex
func (*ParticipantEventsCache) Reset ¶
func (pec *ParticipantEventsCache) Reset() error
type Root ¶
Root forms a base on top of which a participant's Events can be inserted. In contains the SelfParent of the first descendant of the Root, as well as other Events, belonging to a past before the Root, which might be referenced in future Events. NextRound corresponds to a proposed value for the child's Round; it is only used if the child's OtherParent is empty or NOT in the Root's Others.
func NewBaseRoot ¶
NewBaseRoot initializes a Root object for a fresh Hashgraph.
func (*Root) Marshal ¶
The JSON encoding of a Root must be DETERMINISTIC because it is itself included in the JSON encoding of a Frame. The difficulty is that Roots contain go maps for which one should not expect a de facto order of entries; we cannot use the builtin JSON codec within overriding something. Instead, we are using a third party library (ugorji/codec) that enables deterministic encoding of golang maps.
type RootEvent ¶
RootEvent contains enough information about an Event and its direct descendant to allow inserting Events on top of it.
func NewBaseRootEvent ¶
NewBaseRootEvent creates a RootEvent corresponding to the the very beginning of a Hashgraph.
type RoundEvent ¶
type RoundInfo ¶
type RoundInfo struct {
Events map[string]RoundEvent
// contains filtered or unexported fields
}
func NewRoundInfo ¶
func NewRoundInfo() *RoundInfo
func (*RoundInfo) ConsensusEvents ¶
return consensus events
func (*RoundInfo) FamousWitnesses ¶
return famous witnesses
func (*RoundInfo) RoundEvents ¶
func (*RoundInfo) SetConsensusEvent ¶
func (*RoundInfo) WitnessesDecided ¶
return true if no witnesses' fame is left undefined
type Store ¶
type Store interface {
CacheSize() int
Participants() (map[string]int, error)
RootsBySelfParent() (map[string]Root, error)
GetEvent(string) (Event, error)
SetEvent(Event) error
ParticipantEvents(string, int) ([]string, error)
ParticipantEvent(string, int) (string, error)
LastEventFrom(string) (string, bool, error)
LastConsensusEventFrom(string) (string, bool, error)
KnownEvents() map[int]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(map[string]Root) error
Close() error
}
type WireBlockSignature ¶
type WireEvent ¶
func (*WireEvent) BlockSignatures ¶
func (we *WireEvent) BlockSignatures(validator []byte) []BlockSignature