hashgraph

package
v0.0.0-...-81345a1 Latest Latest
Warning

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

Go to latest
Published: Jun 21, 2017 License: Apache-2.0 Imports: 13 Imported by: 0

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.

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.

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.

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.

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.

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.

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

Constants

This section is empty.

Variables

View Source
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 NewEvent

func NewEvent(transactions [][]byte,
	parents []string,
	creator []byte,
	index int) Event

func (*Event) Creator

func (e *Event) Creator() string

func (*Event) Hash

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

sha256 hash of body and signature

func (*Event) Hex

func (e *Event) Hex() string

func (*Event) Index

func (e *Event) Index() int

func (*Event) Marshal

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

gob encoding of body and signature

func (*Event) OtherParent

func (e *Event) OtherParent() string

func (*Event) SelfParent

func (e *Event) SelfParent() string

func (*Event) SetRoundReceived

func (e *Event) SetRoundReceived(rr int)

func (*Event) SetWireInfo

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

func (*Event) Sign

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

ecdsa sig

func (*Event) ToWire

func (e *Event) ToWire() WireEvent

func (*Event) Transactions

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

func (*Event) Unmarshal

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

func (*Event) Verify

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

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
}

func (*EventBody) Hash

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

func (*EventBody) Marshal

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

gob encoding of body only

func (*EventBody) Unmarshal

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

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 NewHashgraph(participants map[string]int, store Store, commitCh chan []Event, logger *logrus.Logger) Hashgraph

func (*Hashgraph) Ancestor

func (h *Hashgraph) Ancestor(x, y string) bool

true if y is an ancestor of x

func (*Hashgraph) ConsensusEvents

func (h *Hashgraph) ConsensusEvents() []string

func (*Hashgraph) DecideFame

func (h *Hashgraph) DecideFame() error

decide if witnesses are famous

func (*Hashgraph) DecideRoundReceived

func (h *Hashgraph) DecideRoundReceived() error

assign round received and timestamp to all events

func (*Hashgraph) DivideRounds

func (h *Hashgraph) DivideRounds() error

func (*Hashgraph) FindOrder

func (h *Hashgraph) FindOrder() error

func (*Hashgraph) FromParentsLatest

func (h *Hashgraph) FromParentsLatest(event Event) error

true if parents are last known events of respective creators

func (*Hashgraph) InitEventCoordinates

func (h *Hashgraph) InitEventCoordinates(event *Event) error

initialize arrays of last ancestors and first descendants

func (*Hashgraph) InsertEvent

func (h *Hashgraph) InsertEvent(event Event) error

func (*Hashgraph) Known

func (h *Hashgraph) Known() map[int]int

number of events per participants

func (*Hashgraph) MedianTimestamp

func (h *Hashgraph) MedianTimestamp(eventHashes []string) time.Time

func (*Hashgraph) OldestSelfAncestorToSee

func (h *Hashgraph) OldestSelfAncestorToSee(x, y string) string

oldest self-ancestor of x to see y

func (*Hashgraph) ParentRound

func (h *Hashgraph) ParentRound(x string) int

max of parent rounds

func (*Hashgraph) ReadWireInfo

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

func (*Hashgraph) Round

func (h *Hashgraph) Round(x string) int

func (*Hashgraph) RoundDiff

func (h *Hashgraph) RoundDiff(x, y string) (int, error)

round(x) - round(y)

func (*Hashgraph) RoundInc

func (h *Hashgraph) RoundInc(x string) bool

true if round of x should be incremented

func (*Hashgraph) See

func (h *Hashgraph) See(x, y string) bool

true if x sees y

func (*Hashgraph) SelfAncestor

func (h *Hashgraph) SelfAncestor(x, y string) bool

true if y is a self-ancestor of x

func (*Hashgraph) SetWireInfo

func (h *Hashgraph) SetWireInfo(event *Event) error

func (*Hashgraph) StronglySee

func (h *Hashgraph) StronglySee(x, y string) bool

true if x strongly sees y

func (*Hashgraph) SuperMajority

func (h *Hashgraph) SuperMajority() int

func (*Hashgraph) UpdateAncestorFirstDescendant

func (h *Hashgraph) UpdateAncestorFirstDescendant(event Event) error

update first decendant of each last ancestor to point to event

func (*Hashgraph) Witness

func (h *Hashgraph) Witness(x string) bool

true if x is a witness (first event of a round for the owner)

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) GetEvent

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

func (*InmemStore) GetRound

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

func (*InmemStore) Known

func (s *InmemStore) Known() map[int]int

func (*InmemStore) LastFrom

func (s *InmemStore) LastFrom(participant string) (string, error)

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

func (*InmemStore) SetRound

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

type Key

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

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 RoundEvent struct {
	Witness bool
	Famous  Trilean
}

type RoundInfo

type RoundInfo struct {
	Events map[string]RoundEvent
}

func NewRoundInfo

func NewRoundInfo() *RoundInfo

func (*RoundInfo) AddEvent

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

func (*RoundInfo) FamousWitnesses

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

return famous witnesses

func (*RoundInfo) Marshal

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

func (*RoundInfo) PseudoRandomNumber

func (r *RoundInfo) PseudoRandomNumber() *big.Int

func (*RoundInfo) SetFame

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

func (*RoundInfo) Unmarshal

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

func (*RoundInfo) Witnesses

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

return witnesses

func (*RoundInfo) WitnessesDecided

func (r *RoundInfo) WitnessesDecided() bool

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
}

type Trilean

type Trilean int
const (
	Undefined Trilean = iota
	True
	False
)

func (Trilean) String

func (t Trilean) String() string

type WireBody

type WireBody struct {
	Transactions [][]byte

	SelfParentIndex      int
	OtherParentCreatorID int
	OtherParentIndex     int
	CreatorID            int

	Timestamp time.Time
	Index     int
}

type WireEvent

type WireEvent struct {
	Body WireBody
	R, S *big.Int
}

Jump to

Keyboard shortcuts

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