Documentation
¶
Overview ¶
Copyright 2017 Mosaic Networks Ltd
Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License.
Copyright 2017 Mosaic Networks Ltd ¶
Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License.
Copyright 2017 Mosaic Networks Ltd ¶
Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License.
Copyright 2017 Mosaic Networks Ltd ¶
Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License.
Copyright 2017 Mosaic Networks Ltd ¶
Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License.
Copyright 2017 Mosaic Networks Ltd ¶
Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License.
Copyright 2017 Mosaic Networks Ltd ¶
Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License.
Index ¶
- Variables
- type ByTimestamp
- type ByTopologicalOrder
- type ConsensusSorter
- type Event
- func (e *Event) Creator() string
- func (e *Event) Hash() ([]byte, error)
- func (e *Event) Hex() string
- func (e *Event) Index() int
- func (e *Event) Marshal() ([]byte, error)
- func (e *Event) OtherParent() string
- func (e *Event) SelfParent() string
- 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)
- type EventBody
- type EventCoordinates
- type Hashgraph
- func (h *Hashgraph) Ancestor(x, y string) bool
- func (h *Hashgraph) ConsensusEvents() []string
- func (h *Hashgraph) DecideFame() error
- func (h *Hashgraph) DecideRoundReceived() error
- func (h *Hashgraph) DivideRounds() error
- func (h *Hashgraph) FindOrder() error
- func (h *Hashgraph) FromParentsLatest(event Event) error
- func (h *Hashgraph) InitEventCoordinates(event *Event) error
- func (h *Hashgraph) InsertEvent(event Event) error
- func (h *Hashgraph) Known() map[int]int
- func (h *Hashgraph) MedianTimestamp(eventHashes []string) time.Time
- func (h *Hashgraph) OldestSelfAncestorToSee(x, y string) string
- func (h *Hashgraph) ParentRound(x string) int
- func (h *Hashgraph) ReadWireInfo(wevent WireEvent) (*Event, error)
- func (h *Hashgraph) Round(x string) int
- func (h *Hashgraph) RoundDiff(x, y string) (int, error)
- func (h *Hashgraph) RoundInc(x string) bool
- func (h *Hashgraph) See(x, y string) bool
- func (h *Hashgraph) SelfAncestor(x, y string) bool
- func (h *Hashgraph) SetWireInfo(event *Event) error
- func (h *Hashgraph) StronglySee(x, y string) bool
- func (h *Hashgraph) SuperMajority() int
- func (h *Hashgraph) UpdateAncestorFirstDescendant(event Event) error
- func (h *Hashgraph) Witness(x string) bool
- type InmemStore
- func (s *InmemStore) AddConsensusEvent(key string) error
- func (s *InmemStore) CacheSize() int
- func (s *InmemStore) Close() error
- func (s *InmemStore) ConsensusEvents() []string
- func (s *InmemStore) ConsensusEventsCount() int
- func (s *InmemStore) GetEvent(key string) (Event, error)
- func (s *InmemStore) GetRound(r int) (RoundInfo, error)
- func (s *InmemStore) Known() map[int]int
- func (s *InmemStore) LastFrom(participant string) (string, error)
- func (s *InmemStore) ParticipantEvent(particant string, index int) (string, error)
- func (s *InmemStore) ParticipantEvents(participant string, skip int) ([]string, error)
- func (s *InmemStore) RoundEvents(r int) int
- func (s *InmemStore) RoundWitnesses(r int) []string
- func (s *InmemStore) Rounds() int
- func (s *InmemStore) SetEvent(event Event) error
- func (s *InmemStore) SetRound(r int, round RoundInfo) error
- type Key
- type ParticipantEventsCache
- func (pec *ParticipantEventsCache) Add(participant string, hash string)
- func (pec *ParticipantEventsCache) Get(participant string, skip int) ([]string, error)
- func (pec *ParticipantEventsCache) GetItem(participant string, index int) (string, error)
- func (pec *ParticipantEventsCache) GetLast(participant string) (string, error)
- func (pec *ParticipantEventsCache) Known() map[int]int
- type RoundEvent
- type RoundInfo
- func (r *RoundInfo) AddEvent(x string, witness bool)
- func (r *RoundInfo) FamousWitnesses() []string
- func (r *RoundInfo) Marshal() ([]byte, error)
- func (r *RoundInfo) PseudoRandomNumber() *big.Int
- 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 WireBody
- type WireEvent
Constants ¶
This section is empty.
Variables ¶
var ( ErrKeyNotFound = errors.New("not found") ErrTooLate = errors.New("too late") )
Functions ¶
This section is empty.
Types ¶
type ByTimestamp ¶
type ByTimestamp []Event
ByTimestamp implements sort.Interface for []Event based on the timestamp field.
func (ByTimestamp) Len ¶
func (a ByTimestamp) Len() int
func (ByTimestamp) Less ¶
func (a ByTimestamp) Less(i, j int) bool
func (ByTimestamp) Swap ¶
func (a ByTimestamp) Swap(i, j int)
type ByTopologicalOrder ¶
type ByTopologicalOrder []Event
ByTopologicalOrder implements sort.Interface for []Event based on the topologicalIndex field.
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 ConsensusSorter ¶
type ConsensusSorter struct {
// contains filtered or unexported fields
}
func NewConsensusSorter ¶
func NewConsensusSorter(events []Event) ConsensusSorter
func (ConsensusSorter) GetPseudoRandomNumber ¶
func (b ConsensusSorter) GetPseudoRandomNumber(round int) *big.Int
func (ConsensusSorter) Len ¶
func (b ConsensusSorter) Len() int
func (ConsensusSorter) Less ¶
func (b ConsensusSorter) Less(i, j int) bool
func (ConsensusSorter) Swap ¶
func (b ConsensusSorter) Swap(i, j int)
type Event ¶
type Event struct {
Body EventBody
R, S *big.Int //creator's digital signature of body
// contains filtered or unexported fields
}
func (*Event) OtherParent ¶
func (*Event) SelfParent ¶
func (*Event) SetRoundReceived ¶
func (*Event) SetWireInfo ¶
func (*Event) Transactions ¶
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
Timestamp time.Time //creator's claimed timestamp of the event's creation
Index int //index in the sequence of events created by Creator
// contains filtered or unexported fields
}
type EventCoordinates ¶
type EventCoordinates struct {
// contains filtered or unexported fields
}
type Hashgraph ¶
type Hashgraph struct {
Participants map[string]int //[public key] => id
ReverseParticipants map[int]string //[id] => public key
Store Store //Persistent store of Events and Rounds
UndeterminedEvents []string //[index] => hash
LastConsensusRound *int //index of last round where the fame of all witnesses has been decided
LastCommitedRoundEvents int //number of events in round before LastConsensusRound
ConsensusTransactions int //number of consensus transactions
// contains filtered or unexported fields
}
func NewHashgraph ¶
func (*Hashgraph) ConsensusEvents ¶
func (*Hashgraph) DecideFame ¶
decide if witnesses are famous
func (*Hashgraph) DecideRoundReceived ¶
assign round received and timestamp to all events
func (*Hashgraph) DivideRounds ¶
func (*Hashgraph) FromParentsLatest ¶
true if parents are last known events of respective creators
func (*Hashgraph) InitEventCoordinates ¶
initialize arrays of last ancestors and first descendants
func (*Hashgraph) InsertEvent ¶
func (*Hashgraph) MedianTimestamp ¶
func (*Hashgraph) OldestSelfAncestorToSee ¶
oldest self-ancestor of x to see y
func (*Hashgraph) SelfAncestor ¶
true if y is a self-ancestor of x
func (*Hashgraph) SetWireInfo ¶
func (*Hashgraph) StronglySee ¶
true if x strongly sees y
func (*Hashgraph) SuperMajority ¶
func (*Hashgraph) UpdateAncestorFirstDescendant ¶
update first decendant of each last ancestor to point to event
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(key string) 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) Known ¶
func (s *InmemStore) Known() map[int]int
func (*InmemStore) ParticipantEvent ¶
func (s *InmemStore) ParticipantEvent(particant string, index int) (string, error)
func (*InmemStore) ParticipantEvents ¶
func (s *InmemStore) ParticipantEvents(participant string, skip int) ([]string, error)
func (*InmemStore) RoundEvents ¶
func (s *InmemStore) RoundEvents(r int) int
func (*InmemStore) RoundWitnesses ¶
func (s *InmemStore) RoundWitnesses(r int) []string
func (*InmemStore) Rounds ¶
func (s *InmemStore) Rounds() int
func (*InmemStore) SetEvent ¶
func (s *InmemStore) SetEvent(event Event) error
type ParticipantEventsCache ¶
type ParticipantEventsCache struct {
// contains filtered or unexported fields
}
++++++++++++++++++++++++++++++++++++++++++++++++ PARTICIPANT EVENTS CACHE
func NewParticipantEventsCache ¶
func NewParticipantEventsCache(size int, participants map[string]int) *ParticipantEventsCache
func (*ParticipantEventsCache) Add ¶
func (pec *ParticipantEventsCache) Add(participant string, hash string)
func (*ParticipantEventsCache) Get ¶
func (pec *ParticipantEventsCache) Get(participant string, skip int) ([]string, error)
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) Known ¶
func (pec *ParticipantEventsCache) Known() map[int]int
type RoundEvent ¶
type RoundInfo ¶
type RoundInfo struct {
Events map[string]RoundEvent
}
func NewRoundInfo ¶
func NewRoundInfo() *RoundInfo
func (*RoundInfo) FamousWitnesses ¶
return famous witnesses
func (*RoundInfo) PseudoRandomNumber ¶
func (*RoundInfo) WitnessesDecided ¶
return true if no witnesses' fame is left undefined
type Store ¶
type Store interface {
CacheSize() int
GetEvent(string) (Event, error)
SetEvent(Event) error
ParticipantEvents(string, int) ([]string, error)
ParticipantEvent(string, int) (string, error)
LastFrom(string) (string, error)
Known() map[int]int
ConsensusEvents() []string
ConsensusEventsCount() int
AddConsensusEvent(string) error
GetRound(int) (RoundInfo, error)
SetRound(int, RoundInfo) error
Rounds() int
RoundWitnesses(int) []string
RoundEvents(int) int
}