Documentation ¶
Index ¶
- Variables
- func NewIndexHashedNodesCoordinator(arguments ArgNodesCoordinator) (*indexHashedNodesCoordinator, error)
- func NewIndexHashedNodesCoordinatorWithRater(indexNodesCoordinator *indexHashedNodesCoordinator, ...) (*indexHashedNodesCoordinatorWithRater, error)
- func NewMultiShardCoordinator(numberOfShards, selfId uint32) (*multiShardCoordinator, error)
- func NewValidator(pubKey []byte, address []byte) (*validator, error)
- func NewXorValidatorsShuffler(nodesShard uint32, nodesMeta uint32, hysteresis float32, adaptivity bool) *randXORShuffler
- type ArgNodesCoordinator
- type ArgsUpdateNodes
- type Cacher
- type ChanceComputer
- type Coordinator
- type EpochHandler
- type EpochStartSubscriber
- type EpochValidators
- type Genesis
- type InitialBalance
- type InitialNode
- type NodeInfo
- type NodesCoordinator
- type NodesCoordinatorRegistry
- type NodesPerShardSetter
- type NodesSetup
- func (ns *NodesSetup) GetShardIDForPubKey(pubKey []byte) (uint32, error)
- func (ns *NodesSetup) InitialEligibleNodesPubKeysForShard(shardId uint32) ([]string, error)
- func (ns *NodesSetup) InitialNodesInfo() (map[uint32][]*NodeInfo, map[uint32][]*NodeInfo)
- func (ns *NodesSetup) InitialNodesInfoForShard(shardId uint32) ([]*NodeInfo, []*NodeInfo, error)
- func (ns *NodesSetup) InitialNodesPubKeys() map[uint32][]string
- func (ns *NodesSetup) NumberOfShards() uint32
- type NodesShuffler
- type OneShardCoordinator
- func (osc *OneShardCoordinator) CommunicationIdentifier(destShardID uint32) string
- func (osc *OneShardCoordinator) ComputeId(_ state.AddressContainer) uint32
- func (osc *OneShardCoordinator) IsInterfaceNil() bool
- func (osc *OneShardCoordinator) NumberOfShards() uint32
- func (osc *OneShardCoordinator) SameShard(_, _ state.AddressContainer) bool
- func (osc *OneShardCoordinator) SelfId() uint32
- type PublicKeysSelector
- type RaterHandler
- type RatingChance
- type RatingReader
- type RatingReaderSetter
- type RatingReaderWithChanceComputer
- type SelectionBasedProvider
- type SerializableValidator
- type Validator
Constants ¶
This section is empty.
Variables ¶
var ErrCouldNotParseAddress = errors.New("could not parse node's address")
ErrCouldNotParseAddress signals that a given address could not be parsed
var ErrCouldNotParsePubKey = errors.New("could not parse node's public key")
ErrCouldNotParsePubKey signals that a given public key could not be parsed
var ErrEligibleSelectionMismatch = errors.New("invalid eligible validator selection")
ErrEligibleSelectionMismatch signals a mismatch between the eligible list and the group selection bitmap
var ErrEligibleTooFewSelections = errors.New("too few selections for consensus group")
ErrEligibleTooFewSelections signals an invalid selection for consensus group
var ErrEligibleTooManySelections = errors.New("too many selections for consensus group")
ErrEligibleTooManySelections signals an invalid selection for consensus group
var ErrEpochNodesConfigDesNotExist = errors.New("epoch nodes configuration does not exist")
ErrEpochNodesConfigDesNotExist signals that the epoch nodes configuration is missing
var ErrInvalidConsensusGroupSize = errors.New("invalid consensus group size")
ErrInvalidConsensusGroupSize signals that the consensus size is invalid (e.g. value is negative)
var ErrInvalidNumberOfShards = errors.New("the number of shards must be greater than zero")
ErrInvalidNumberOfShards signals that an invalid number of shards was passed to the sharding registry
var ErrInvalidNumberPubKeys = errors.New("invalid number of public keys")
ErrInvalidNumberPubKeys signals that an invalid number of public keys was used
var ErrInvalidShardId = errors.New("shard id must be smaller than the total number of shards")
ErrInvalidShardId signals that an invalid shard is was passed
var ErrMinNodesPerShardSmallerThanConsensusSize = errors.New("minimum nodes per shard is smaller than consensus group size")
ErrMinNodesPerShardSmallerThanConsensusSize signals that an invalid min nodes per shard has been provided
var ErrMissingMetachainNodes = errors.New("no metachain nodes configured")
ErrMissingMetachainNodes signals that metachain nodes were not configured
var ErrNegativeOrZeroConsensusGroupSize = errors.New("negative or zero consensus group size")
ErrNegativeOrZeroConsensusGroupSize signals that an invalid consensus group size has been provided
var ErrNilAddress = errors.New("nil address")
ErrNilAddress signals that the address is nil
var ErrNilAddressConverter = errors.New("trying to set nil address converter")
ErrNilAddressConverter signals that a nil address converter has been provided
var ErrNilBootStorer = errors.New("nil boot storer provided")
ErrNilBootStorer signals that a nil boot storer was provided
var ErrNilCacher = errors.New("nil cacher")
ErrNilCacher signals that a nil cacher has been provided
var ErrNilChanceComputer = errors.New("nil chance computer")
ErrNilChanceComputer signals that the chanceComputer is nil
var ErrNilEpochHandler = errors.New("nil epoch handler")
ErrNilEpochHandler signals that a nil epoch handler has been provided
var ErrNilHasher = errors.New("nil hasher")
ErrNilHasher signals that a nil hasher has been provided
var ErrNilInputNodesMap = errors.New("nil input nodes map")
ErrNilInputNodesMap signals that a nil nodes map was provided
var ErrNilNodesCoordinator = errors.New("nil nodesCoordinator")
ErrNilNodesCoordinator signals that the nodesCoordinator is nil
var ErrNilPubKey = errors.New("nil public key")
ErrNilPubKey signals that the public key is nil
var ErrNilRandomness = errors.New("nil randomness source")
ErrNilRandomness signals that a nil randomness source has been provided
var ErrNilRater = errors.New("nil rater")
ErrNilRater signals that the rater is nil
var ErrNilShardCoordinator = errors.New("trying to set nil shard coordinator")
ErrNilShardCoordinator signals that a nil shard coordinator has been provided
var ErrNilShuffler = errors.New("nil nodes shuffler provided")
ErrNilShuffler signals that a nil shuffler was provided
var ErrNoPubKeys = errors.New("no public keys defined")
ErrNoPubKeys signals an error when public keys are missing
var ErrNodesSizeSmallerThanMinNoOfNodes = errors.New("length of nodes defined is smaller than min nodes per shard required")
ErrNodesSizeSmallerThanMinNoOfNodes signals that there are not enough nodes defined in genesis file
var ErrNotImplemented = errors.New("feature not implemented")
ErrNotImplemented signals a call of a non implemented functionality
var ErrPublicKeyNotFoundInGenesis = errors.New("public key is not valid, it is missing from genesis file")
ErrPublicKeyNotFoundInGenesis signals an error when the public key is not in genesis file
var ErrShardIdOutOfRange = errors.New("shard id out of range")
ErrShardIdOutOfRange signals an error when shard id is out of range
var ErrSmallMetachainEligibleListSize = errors.New("small metachain eligible list size")
ErrSmallMetachainEligibleListSize signals that the eligible validators list's size is less than the consensus size
var ErrSmallShardEligibleListSize = errors.New("small shard eligible list size")
ErrSmallShardEligibleListSize signals that the eligible validators list's size is less than the consensus size
var ErrValidatorNotFound = errors.New("validator not found")
ErrValidatorNotFound signals that the validator has not been found
Functions ¶
func NewIndexHashedNodesCoordinator ¶
func NewIndexHashedNodesCoordinator(arguments ArgNodesCoordinator) (*indexHashedNodesCoordinator, error)
NewIndexHashedNodesCoordinator creates a new index hashed group selector
func NewIndexHashedNodesCoordinatorWithRater ¶
func NewIndexHashedNodesCoordinatorWithRater( indexNodesCoordinator *indexHashedNodesCoordinator, rater RatingReaderWithChanceComputer, ) (*indexHashedNodesCoordinatorWithRater, error)
NewIndexHashedNodesCoordinatorWithRater creates a new index hashed group selector
func NewMultiShardCoordinator ¶
NewMultiShardCoordinator returns a new multiShardCoordinator and initializes the masks
func NewValidator ¶
NewValidator creates a new instance of a validator
Types ¶
type ArgNodesCoordinator ¶
type ArgNodesCoordinator struct { ShardConsensusGroupSize int MetaConsensusGroupSize int Hasher hashing.Hasher Shuffler NodesShuffler EpochStartSubscriber EpochStartSubscriber BootStorer storage.Storer ShardIDAsObserver uint32 NbShards uint32 EligibleNodes map[uint32][]Validator WaitingNodes map[uint32][]Validator SelfPublicKey []byte Epoch uint32 ConsensusGroupCache Cacher }
ArgNodesCoordinator holds all dependencies required by the nodes coordinator in order to create new instances
type ArgsUpdateNodes ¶
type ArgsUpdateNodes struct { Eligible map[uint32][]Validator Waiting map[uint32][]Validator NewNodes []Validator Leaving []Validator Rand []byte NbShards uint32 }
ArgsUpdateNodes holds the parameters required by the shuffler to generate a new nodes configuration
type Cacher ¶
type Cacher interface { // Put adds a value to the cache. Returns true if an eviction occurred. Put(key []byte, value interface{}) (evicted bool) // Get looks up a key's value from the cache. Get(key []byte) (value interface{}, ok bool) }
Cacher provides the capabilities needed to store and retrieve information needed in the NodesCoordinator
type ChanceComputer ¶
type ChanceComputer interface { //GetChance returns the chances for the the rating GetChance(uint32) uint32 //IsInterfaceNil verifies if the interface is nil IsInterfaceNil() bool }
ChanceComputer provides chance computation capabilities based on a rating
type Coordinator ¶
type Coordinator interface { NumberOfShards() uint32 ComputeId(address state.AddressContainer) uint32 SelfId() uint32 SameShard(firstAddress, secondAddress state.AddressContainer) bool CommunicationIdentifier(destShardID uint32) string IsInterfaceNil() bool }
Coordinator defines what a shard state coordinator should hold
type EpochHandler ¶
EpochHandler defines a struct able to output current epoch
type EpochStartSubscriber ¶
type EpochStartSubscriber interface { RegisterHandler(handler epochStart.EpochStartHandler) UnregisterHandler(handler epochStart.EpochStartHandler) }
EpochStartSubscriber provides Register and Unregister functionality for the end of epoch events
type EpochValidators ¶
type EpochValidators struct { EligibleValidators map[string][]*SerializableValidator `json:"eligibleValidators"` WaitingValidators map[string][]*SerializableValidator `json:"waitingValidators"` }
EpochValidators holds one epoch configuration for a nodes coordinator
type Genesis ¶
type Genesis struct {
InitialBalances []*InitialBalance `json:"initialBalances"`
}
Genesis hold data for decoded data from json file
func NewGenesisConfig ¶
NewGenesisConfig creates a new decoded genesis structure from json config file
func (*Genesis) InitialNodesBalances ¶
func (g *Genesis) InitialNodesBalances(shardCoordinator Coordinator, adrConv state.AddressConverter) (map[string]*big.Int, error)
InitialNodesBalances - gets the initial balances of the nodes
type InitialBalance ¶
type InitialBalance struct { PubKey string `json:"pubkey"` Balance string `json:"balance"` // contains filtered or unexported fields }
InitialBalance holds data from json and decoded data from genesis process
type InitialNode ¶
InitialNode holds data from json
type NodeInfo ¶
type NodeInfo struct {
// contains filtered or unexported fields
}
NodeInfo holds node info
func (*NodeInfo) AssignedShard ¶
AssignedShard gets the node assigned shard
type NodesCoordinator ¶
type NodesCoordinator interface { NodesPerShardSetter PublicKeysSelector ComputeConsensusGroup(randomness []byte, round uint64, shardId uint32, epoch uint32) (validatorsGroup []Validator, err error) GetValidatorWithPublicKey(publicKey []byte, epoch uint32) (validator Validator, shardId uint32, err error) LoadState(key []byte) error GetSavedStateKey() []byte ShardIdForEpoch(epoch uint32) (uint32, error) GetConsensusWhitelistedNodes(epoch uint32) (map[string]struct{}, error) ConsensusGroupSize(uint32) int GetNumTotalEligible() uint64 IsInterfaceNil() bool }
NodesCoordinator defines the behaviour of a struct able to do validator group selection
type NodesCoordinatorRegistry ¶
type NodesCoordinatorRegistry struct { EpochsConfig map[string]*EpochValidators `json:"epochConfigs"` CurrentEpoch uint32 `json:"currentEpoch"` }
NodesCoordinatorRegistry holds the data that can be used to initialize a nodes coordinator
type NodesPerShardSetter ¶
type NodesPerShardSetter interface { SetNodesPerShards( eligible map[uint32][]Validator, waiting map[uint32][]Validator, epoch uint32, ) error ComputeLeaving(allValidators []Validator) []Validator }
NodesPerShardSetter provides polymorphism functionality for nodesCoordinator
type NodesSetup ¶
type NodesSetup struct { StartTime int64 `json:"startTime"` RoundDuration uint64 `json:"roundDuration"` ConsensusGroupSize uint32 `json:"consensusGroupSize"` MinNodesPerShard uint32 `json:"minNodesPerShard"` ChainID string `json:"chainID"` MetaChainConsensusGroupSize uint32 `json:"metaChainConsensusGroupSize"` MetaChainMinNodes uint32 `json:"metaChainMinNodes"` InitialNodes []*InitialNode `json:"initialNodes"` Hysteresis float32 `json:"hysteresis"` Adaptivity bool `json:"adaptivity"` // contains filtered or unexported fields }
NodesSetup hold data for decoded data from json file
func NewNodesSetup ¶
func NewNodesSetup(nodesFilePath string) (*NodesSetup, error)
NewNodesSetup creates a new decoded nodes structure from json config file
func (*NodesSetup) GetShardIDForPubKey ¶
func (ns *NodesSetup) GetShardIDForPubKey(pubKey []byte) (uint32, error)
GetShardIDForPubKey returns the allocated shard ID from public key
func (*NodesSetup) InitialEligibleNodesPubKeysForShard ¶
func (ns *NodesSetup) InitialEligibleNodesPubKeysForShard(shardId uint32) ([]string, error)
InitialEligibleNodesPubKeysForShard - gets initial nodes public keys for shard
func (*NodesSetup) InitialNodesInfo ¶
func (ns *NodesSetup) InitialNodesInfo() (map[uint32][]*NodeInfo, map[uint32][]*NodeInfo)
InitialNodesInfo - gets initial nodes info
func (*NodesSetup) InitialNodesInfoForShard ¶
func (ns *NodesSetup) InitialNodesInfoForShard(shardId uint32) ([]*NodeInfo, []*NodeInfo, error)
InitialNodesInfoForShard - gets initial nodes info for shard
func (*NodesSetup) InitialNodesPubKeys ¶
func (ns *NodesSetup) InitialNodesPubKeys() map[uint32][]string
InitialNodesPubKeys - gets initial nodes public keys
func (*NodesSetup) NumberOfShards ¶
func (ns *NodesSetup) NumberOfShards() uint32
NumberOfShards returns the calculated number of shards
type NodesShuffler ¶
type NodesShuffler interface { UpdateParams(numNodesShard uint32, numNodesMeta uint32, hysteresis float32, adaptivity bool) UpdateNodeLists(args ArgsUpdateNodes) (map[uint32][]Validator, map[uint32][]Validator, []Validator) IsInterfaceNil() bool }
NodesShuffler provides shuffling functionality for nodes
type OneShardCoordinator ¶
type OneShardCoordinator struct{}
OneShardCoordinator creates a shard coordinator object
func (*OneShardCoordinator) CommunicationIdentifier ¶
func (osc *OneShardCoordinator) CommunicationIdentifier(destShardID uint32) string
CommunicationIdentifier returns the identifier between current shard ID and destination shard ID for this implementation, it will always return "_0" as there is a single shard
func (*OneShardCoordinator) ComputeId ¶
func (osc *OneShardCoordinator) ComputeId(_ state.AddressContainer) uint32
ComputeId gets shard for the given address
func (*OneShardCoordinator) IsInterfaceNil ¶
func (osc *OneShardCoordinator) IsInterfaceNil() bool
IsInterfaceNil returns true if there is no value under the interface
func (*OneShardCoordinator) NumberOfShards ¶
func (osc *OneShardCoordinator) NumberOfShards() uint32
NumberOfShards gets number of shards
func (*OneShardCoordinator) SameShard ¶
func (osc *OneShardCoordinator) SameShard(_, _ state.AddressContainer) bool
SameShard returns weather two addresses belong to the same shard
func (*OneShardCoordinator) SelfId ¶
func (osc *OneShardCoordinator) SelfId() uint32
SelfId gets shard of the current node
type PublicKeysSelector ¶
type PublicKeysSelector interface { GetValidatorsIndexes(publicKeys []string, epoch uint32) ([]uint64, error) GetAllEligibleValidatorsPublicKeys(epoch uint32) (map[uint32][][]byte, error) GetAllWaitingValidatorsPublicKeys(epoch uint32) (map[uint32][][]byte, error) GetConsensusValidatorsPublicKeys(randomness []byte, round uint64, shardId uint32, epoch uint32) ([]string, error) GetConsensusValidatorsRewardsAddresses(randomness []byte, round uint64, shardId uint32, epoch uint32) ([]string, error) GetOwnPublicKey() []byte }
PublicKeysSelector allows retrieval of eligible validators public keys
type RaterHandler ¶
type RaterHandler interface { RatingReader //GetChance returns the chances for the the rating GetChance(uint32) uint32 //GetStartRating gets the start rating values GetStartRating() uint32 //ComputeIncreaseProposer computes the new rating for the increaseLeader ComputeIncreaseProposer(val uint32) uint32 //ComputeDecreaseProposer computes the new rating for the decreaseLeader ComputeDecreaseProposer(val uint32) uint32 //ComputeIncreaseValidator computes the new rating for the increaseValidator ComputeIncreaseValidator(val uint32) uint32 //ComputeDecreaseValidator computes the new rating for the decreaseValidator ComputeDecreaseValidator(val uint32) uint32 }
RaterHandler provides Rating Computation Capabilites for the Nodes Coordinator and ValidatorStatistics
type RatingChance ¶
type RatingChance interface { //GetMaxThreshold returns the threshold until this ChancePercentage holds GetMaxThreshold() uint32 //GetChancePercentage returns the percentage for the RatingChance GetChancePercentage() uint32 //IsInterfaceNil verifies if the interface is nil IsInterfaceNil() bool }
RatingChance provides the methods needed for the computation of chances from the Rating
type RatingReader ¶
type RatingReader interface { //GetRating gets the rating for the public key GetRating(string) uint32 //UpdateRatingFromTempRating sets the rating to the value of the tempRating for the public keys UpdateRatingFromTempRating([]string) error //IsInterfaceNil verifies if the interface is nil IsInterfaceNil() bool }
RatingReader provides rating reading capabilities for the ratingHandler
type RatingReaderSetter ¶
type RatingReaderSetter interface { //SetRatingReader sets the rating SetRatingReader(RatingReader) //IsInterfaceNil verifies if the interface is nil IsInterfaceNil() bool }
RatingReaderSetter provides the capabilities to set a RatingReader
type RatingReaderWithChanceComputer ¶
type RatingReaderWithChanceComputer interface { RatingReader GetChance(uint32) uint32 }
RatingReaderWithChanceComputer provides chance computation capabilities with Rater
type SelectionBasedProvider ¶
type SelectionBasedProvider struct {
// contains filtered or unexported fields
}
SelectionBasedProvider will handle the returning of the consensus group by simulating a reslicing of the expanded eligible list. A comparison between a real reslicing and this can be found in common_test.go
func NewSelectionBasedProvider ¶
func NewSelectionBasedProvider(hasher hashing.Hasher, maxSize uint32) *SelectionBasedProvider
NewSelectionBasedProvider will return a new instance of SelectionBasedProvider
func (*SelectionBasedProvider) Get ¶
func (sbp *SelectionBasedProvider) Get(randomness []byte, numValidators int64, expandedEligibleList []Validator) ([]Validator, error)
Get will return the consensus group based on the randomness. After a validator is chosen, it is added to the slice so it won't be selected again so next time a new validator is needed, the index is recalculated until the validator doesn't exist in that slice
type SerializableValidator ¶
SerializableValidator holds the minimal data required for marshalling and un-marshalling a validator