spos

package
v1.0.13 Latest Latest
Warning

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

Go to latest
Published: Jul 26, 2019 License: GPL-3.0 Imports: 18 Imported by: 0

Documentation

Index

Constants

View Source
const MaxRoundsGap = 3

MaxRoundsGap defines the maximum expected gap in terms of rounds, between metachain and shardchain, after which a block committed and broadcast from shardchain would be visible as notarized in metachain

Variables

View Source
var ErrCommitmentHashDoesNotMatch = errors.New("commitment hash does not match")

ErrCommitmentHashDoesNotMatch is raised when the commitment hash does not match expected value

View Source
var ErrEmptyConsensusGroup = errors.New("consensusGroup is empty")

ErrEmptyConsensusGroup is raised when an operation is attempted with an empty consensus group

View Source
var ErrInvalidKey = errors.New("map key is invalid")

ErrInvalidKey is raised when an invalid key is used with a map

View Source
var ErrInvalidMultiSigner = errors.New("multiSigner is invalid")

ErrInvalidMultiSigner is raised when an invalid multiSigner is used

View Source
var ErrInvalidSignature = errors.New("signature is invalid")

ErrInvalidSignature is raised when signature is invalid

View Source
var ErrMessageForPastRound = errors.New("message is for past round")

ErrMessageForPastRound is raised when message is for past round

View Source
var ErrMessageFromItself = errors.New("message is from itself")

ErrMessageFromItself is raised when a message from itself is received

View Source
var ErrNilBlockChain = errors.New("blockchain is nil")

ErrNilBlockChain is raised when a valid blockchain is expected but nil used

View Source
var ErrNilBlockProcessor = errors.New("block processor is nil")

ErrNilBlockProcessor is raised when a valid block processor is expected but nil used

View Source
var ErrNilBlocksTracker = errors.New("blocks tracker is nil")

ErrNilBlocksTracker is raised when a valid block tracker is expected but nil used

View Source
var ErrNilBlsPrivateKey = errors.New("BLS private key should not be nil")

ErrNilBlsPrivateKey is raised when the bls private key is nil

View Source
var ErrNilBlsSingleSigner = errors.New("BLS single signer should not be nil")

ErrNilBlsSingleSigner is raised when a message from itself is received

View Source
var ErrNilBody = errors.New("body is nil")

ErrNilBody is raised when an expected body is nil

View Source
var ErrNilBootstrapper = errors.New("bootstrapper is nil")

ErrNilBootstrapper is raised when a valid block processor is expected but nil used

View Source
var ErrNilBroadcastMessenger = errors.New("broadcast messenger is nil")

ErrNilBroadcastMessenger is raised when a valid broadcast messenger is expected but nil used

View Source
var ErrNilBroadcastUnnotarisedBlocks = errors.New("broadcastUnnotarisedBlocks is nil")

ErrNilBroadcastUnnotarisedBlocks is raised when a valid broadcastUnnotarisedBlocks function is expected but nil used

View Source
var ErrNilChannel = errors.New("channel is nil")

ErrNilChannel is raised when a valid channel is expected but nil used

View Source
var ErrNilChronologyHandler = errors.New("chronology handler is nil")

ErrNilChronologyHandler is raised when a valid chronology handler is expected but nil used

View Source
var ErrNilCommitment = errors.New("commitment is nil")

ErrNilCommitment is raised when a valid commitment was expected but nil was used

View Source
var ErrNilConsensusCore = errors.New("consensus core is nil")

ErrNilConsensusCore is raised when a valid ConsensusCore is expected but nil used

View Source
var ErrNilConsensusData = errors.New("consensus data is nil")

ErrNilConsensusData is raised when valid consensus data was expected but nil was received

View Source
var ErrNilConsensusGroup = errors.New("consensusGroup is null")

ErrNilConsensusGroup is raised when an operation is attempted with a nil consensus group

View Source
var ErrNilConsensusService = errors.New("consensus service is nil")

ErrNilConsensusService is raised when a valid ConsensusService is expected but nil used

View Source
var ErrNilConsensusState = errors.New("consensus state is nil")

ErrNilConsensusState is raised when a valid consensus is expected but nil used

View Source
var ErrNilDataToProcess = errors.New("nil data to process")

ErrNilDataToProcess signals that nil data was provided

View Source
var ErrNilExecuteStoredMessages = errors.New("executeStoredMessages is nil")

ErrNilExecuteStoredMessages is raised when a valid executeStoredMessages function is expected but nil used

View Source
var ErrNilForkDetector = errors.New("fork detector is nil")

ErrNilForkDetector is raised when a valid fork detector is expected but nil used

View Source
var ErrNilHasher = errors.New("hasher is nil")

ErrNilHasher is raised when a valid hasher is expected but nil used

View Source
var ErrNilHeader = errors.New("header is nil")

ErrNilHeader is raised when an expected header is nil

View Source
var ErrNilKeyGenerator = errors.New("key generator is nil")

ErrNilKeyGenerator is raised when a valid key generator is expected but nil was used

View Source
var ErrNilMarshalizer = errors.New("marshalizer is nil")

ErrNilMarshalizer is raised when a valid marshalizer is expected but nil used

View Source
var ErrNilMessage = errors.New("nil message")

ErrNilMessage signals that a nil message has been received

View Source
var ErrNilMessenger = errors.New("messenger is nil")

ErrNilMessenger is raised when a valid messenger is expected but nil used

View Source
var ErrNilMetaHeader = errors.New("meta header is nil")

ErrNilMetaHeader is raised when an expected meta header is nil

View Source
var ErrNilMultiSigner = errors.New("multiSigner is nil")

ErrNilMultiSigner is raised when a valid multiSigner is expected but nil used

View Source
var ErrNilPrivateKey = errors.New("private key is nil")

ErrNilPrivateKey is raised when a valid private key was expected but nil was used

View Source
var ErrNilPublicKey = errors.New("public key is nil")

ErrNilPublicKey is raised when a valid public key was expected but nil was used

View Source
var ErrNilRoundState = errors.New("round state is nil")

ErrNilRoundState is raised when a valid round state is expected but nil used

View Source
var ErrNilRounder = errors.New("rounder is nil")

ErrNilRounder is raised when a valid rounder is expected but nil used

View Source
var ErrNilShardCoordinator = errors.New("shard coordinator is nil")

ErrNilShardCoordinator is raised when a valid shard coordinator is expected but nil used

View Source
var ErrNilSignature = errors.New("signature is nil")

ErrNilSignature is raised when a valid signature was expected but nil was used

View Source
var ErrNilSingleSigner = errors.New("singleSigner is nil")

ErrNilSingleSigner is raised when a valid singleSigner is expected but nil used

View Source
var ErrNilSubround = errors.New("subround is nil")

ErrNilSubround is raised when a valid subround is expected but nil used

View Source
var ErrNilSyncTimer = errors.New("sync timer is nil")

ErrNilSyncTimer is raised when a valid sync timer is expected but nil used

View Source
var ErrNilValidatorGroupSelector = errors.New("validator group selector is nil")

ErrNilValidatorGroupSelector is raised when a valid validator group selector is expected but nil used

View Source
var ErrNilWorker = errors.New("worker is nil")

ErrNilWorker is raised when a valid Worker is expected but nil used

View Source
var ErrNotFoundInConsensus = errors.New("self not found in consensus group")

ErrNotFoundInConsensus is raised when self expected in consensus group but not found

View Source
var ErrRoundCanceled = errors.New("round is canceled")

ErrRoundCanceled is raised when round is canceled

View Source
var ErrSenderNotOk = errors.New("sender is invalid")

ErrSenderNotOk is raised when sender is invalid

Functions

func NewRoundConsensus

func NewRoundConsensus(
	eligibleList []string,
	consensusGroupSize int,
	selfId string,
) *roundConsensus

NewRoundConsensus creates a new roundConsensus object

func NewRoundState

func NewRoundState() *roundState

NewRoundState creates a new roundState object

func NewRoundStatus

func NewRoundStatus() *roundStatus

NewRoundStatus creates a new roundStatus object

func NewRoundThreshold

func NewRoundThreshold() *roundThreshold

NewRoundThreshold creates a new roundThreshold object

func ValidateConsensusCore

func ValidateConsensusCore(container ConsensusCoreHandler) error

ValidateConsensusCore checks for nil all the container objects

Types

type ConsensusCore

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

ConsensusCore implements ConsensusCoreHandler and provides access to common functionalities

for the rest of the consensus structures

func NewConsensusCore

func NewConsensusCore(
	blockChain data.ChainHandler,
	blockProcessor process.BlockProcessor,
	blocksTracker process.BlocksTracker,
	bootstrapper process.Bootstrapper,
	broadcastMessenger consensus.BroadcastMessenger,
	chronologyHandler consensus.ChronologyHandler,
	hasher hashing.Hasher,
	marshalizer marshal.Marshalizer,
	blsPrivateKey crypto.PrivateKey,
	blsSingleSigner crypto.SingleSigner,
	multiSigner crypto.MultiSigner,
	rounder consensus.Rounder,
	shardCoordinator sharding.Coordinator,
	syncTimer ntp.SyncTimer,
	validatorGroupSelector consensus.ValidatorGroupSelector) (*ConsensusCore, error)

NewConsensusCore creates a new ConsensusCore instance

func (*ConsensusCore) BlockProcessor

func (cc *ConsensusCore) BlockProcessor() process.BlockProcessor

BlockProcessor gets the BlockProcessor stored in the ConsensusCore

func (*ConsensusCore) Blockchain

func (cc *ConsensusCore) Blockchain() data.ChainHandler

Blockchain gets the ChainHandler stored in the ConsensusCore

func (*ConsensusCore) BlocksTracker added in v1.0.3

func (cc *ConsensusCore) BlocksTracker() process.BlocksTracker

BlocksTracker gets the BlocksTracker stored in the ConsensusCore

func (*ConsensusCore) BootStrapper

func (cc *ConsensusCore) BootStrapper() process.Bootstrapper

BootStrapper gets the Bootstrapper stored in the ConsensusCore

func (*ConsensusCore) BroadcastMessenger

func (cc *ConsensusCore) BroadcastMessenger() consensus.BroadcastMessenger

BroadcastMessenger gets the BroadcastMessenger stored in the ConsensusCore

func (*ConsensusCore) Chronology

func (cc *ConsensusCore) Chronology() consensus.ChronologyHandler

Chronology gets the ChronologyHandler stored in the ConsensusCore

func (*ConsensusCore) Hasher

func (cc *ConsensusCore) Hasher() hashing.Hasher

Hasher gets the Hasher stored in the ConsensusCore

func (*ConsensusCore) Marshalizer

func (cc *ConsensusCore) Marshalizer() marshal.Marshalizer

Marshalizer gets the Marshalizer stored in the ConsensusCore

func (*ConsensusCore) MultiSigner

func (cc *ConsensusCore) MultiSigner() crypto.MultiSigner

MultiSigner gets the MultiSigner stored in the ConsensusCore

func (*ConsensusCore) RandomnessPrivateKey added in v1.0.3

func (cc *ConsensusCore) RandomnessPrivateKey() crypto.PrivateKey

RandomnessPrivateKey returns the BLS private key stored in the ConsensusStore

func (*ConsensusCore) RandomnessSingleSigner added in v1.0.3

func (cc *ConsensusCore) RandomnessSingleSigner() crypto.SingleSigner

RandomnessSingleSigner returns the bls single signer stored in the ConsensusStore

func (*ConsensusCore) Rounder

func (cc *ConsensusCore) Rounder() consensus.Rounder

Rounder gets the Rounder stored in the ConsensusCore

func (*ConsensusCore) ShardCoordinator

func (cc *ConsensusCore) ShardCoordinator() sharding.Coordinator

ShardCoordinator gets the Coordinator stored in the ConsensusCore

func (*ConsensusCore) SyncTimer

func (cc *ConsensusCore) SyncTimer() ntp.SyncTimer

SyncTimer gets the SyncTimer stored in the ConsensusCore

func (*ConsensusCore) ValidatorGroupSelector added in v1.0.3

func (cc *ConsensusCore) ValidatorGroupSelector() consensus.ValidatorGroupSelector

ValidatorGroupSelector gets the ValidatorGroupSelector stored in the ConsensusCore

type ConsensusCoreHandler

type ConsensusCoreHandler interface {
	// Blockchain gets the ChainHandler stored in the ConsensusCore
	Blockchain() data.ChainHandler
	// BlockProcessor gets the BlockProcessor stored in the ConsensusCore
	BlockProcessor() process.BlockProcessor
	// BlocksTracker gets the BlockTracker stored in the ConsensusCore
	BlocksTracker() process.BlocksTracker
	// BootStrapper gets the Bootstrapper stored in the ConsensusCore
	BootStrapper() process.Bootstrapper
	// BroadcastMessenger gets the BroadcastMessenger stored in ConsensusCore
	BroadcastMessenger() consensus.BroadcastMessenger
	// Chronology gets the ChronologyHandler stored in the ConsensusCore
	Chronology() consensus.ChronologyHandler
	// Hasher gets the Hasher stored in the ConsensusCore
	Hasher() hashing.Hasher
	// Marshalizer gets the Marshalizer stored in the ConsensusCore
	Marshalizer() marshal.Marshalizer
	// MultiSigner gets the MultiSigner stored in the ConsensusCore
	MultiSigner() crypto.MultiSigner
	// Rounder gets the Rounder stored in the ConsensusCore
	Rounder() consensus.Rounder
	// ShardCoordinator gets the Coordinator stored in the ConsensusCore
	ShardCoordinator() sharding.Coordinator
	// SyncTimer gets the SyncTimer stored in the ConsensusCore
	SyncTimer() ntp.SyncTimer
	// ValidatorGroupSelector gets the ValidatorGroupSelector stored in the ConsensusCore
	ValidatorGroupSelector() consensus.ValidatorGroupSelector
	// RandomnessPrivateKey returns the private key stored in the ConsensusStore used for randomness generation
	RandomnessPrivateKey() crypto.PrivateKey
	// RandomnessSingleSigner returns the single signer stored in the ConsensusStore used for randomness generation
	RandomnessSingleSigner() crypto.SingleSigner
}

ConsensusCoreHandler encapsulates all needed Data for the Consensus

type ConsensusService

type ConsensusService interface {
	//InitReceivedMessages initializes the MessagesType map for all messages for the current ConsensusService
	InitReceivedMessages() map[consensus.MessageType][]*consensus.Message
	//GetStringValue gets the name of the messageType
	GetStringValue(consensus.MessageType) string
	//GetSubroundName gets the subround name for the subround id provided
	GetSubroundName(int) string
	//GetMessageRange provides the MessageType range used in checks by the consensus
	GetMessageRange() []consensus.MessageType
	//CanProceed returns if the current messageType can proceed further if previous subrounds finished
	CanProceed(*ConsensusState, consensus.MessageType) bool
	//IsMessageWithBlockHeader returns if the current messageType is about block header
	IsMessageWithBlockHeader(consensus.MessageType) bool
}

ConsensusService encapsulates the methods specifically for a consensus type (bls, bn) and will be used in the sposWorker

type ConsensusState

type ConsensusState struct {
	// hold the data on which validators do the consensus (could be for example a hash of the block header
	// proposed by the leader)
	Data      []byte
	BlockBody data.BodyHandler
	Header    data.HeaderHandler

	RoundIndex     int32
	RoundTimeStamp time.Time
	RoundCanceled  bool
	// contains filtered or unexported fields
}

ConsensusState defines the data needed by spos to do the consensus in each round

func NewConsensusState

func NewConsensusState(
	roundConsensus *roundConsensus,
	roundThreshold *roundThreshold,
	roundStatus *roundStatus,
) *ConsensusState

NewConsensusState creates a new ConsensusState object

func (*ConsensusState) CanDoSubroundJob

func (cns *ConsensusState) CanDoSubroundJob(currentSubroundId int) bool

CanDoSubroundJob method returns true if the job of the subround can be done and false otherwise

func (*ConsensusState) CanProcessReceivedMessage

func (cns *ConsensusState) CanProcessReceivedMessage(cnsDta *consensus.Message, currentRoundIndex int32,
	currentSubroundId int) bool

CanProcessReceivedMessage method returns true if the message received can be processed and false otherwise

func (ConsensusState) ComputeSize

func (rcns ConsensusState) ComputeSize(subroundId int) int

ComputeSize method returns the number of messages received from the nodes belonging to the current jobDone group related to this subround

func (ConsensusState) ConsensusGroup

func (rcns ConsensusState) ConsensusGroup() []string

ConsensusGroup returns the consensus group ID's

func (ConsensusState) ConsensusGroupIndex

func (rcns ConsensusState) ConsensusGroupIndex(pubKey string) (int, error)

ConsensusGroupIndex returns the index of given public key in the current consensus group

func (ConsensusState) ConsensusGroupSize

func (rcns ConsensusState) ConsensusGroupSize() int

ConsensusGroupSize returns the consensus group size

func (ConsensusState) EligibleList added in v1.0.3

func (rcns ConsensusState) EligibleList() []string

EligibleList returns the eligible list ID's

func (*ConsensusState) GenerateBitmap

func (cns *ConsensusState) GenerateBitmap(subroundId int) []byte

GenerateBitmap method generates a bitmap, for a given subround, in which each node will be marked with 1 if its job has been done

func (*ConsensusState) GetData

func (cns *ConsensusState) GetData() []byte

GetData gets the Data of the consensusState

func (*ConsensusState) GetLeader

func (cns *ConsensusState) GetLeader() (string, error)

GetLeader method gets the leader of the current round

func (*ConsensusState) GetNextConsensusGroup

func (cns *ConsensusState) GetNextConsensusGroup(randomSource string, vgs consensus.ValidatorGroupSelector) ([]string,
	error)

GetNextConsensusGroup gets the new consensus group for the current round based on current eligible list and a random source for the new selection

func (*ConsensusState) IsBlockBodyAlreadyReceived

func (cns *ConsensusState) IsBlockBodyAlreadyReceived() bool

IsBlockBodyAlreadyReceived method returns true if block body is already received and false otherwise

func (*ConsensusState) IsConsensusDataEqual

func (cns *ConsensusState) IsConsensusDataEqual(data []byte) bool

IsConsensusDataEqual method returns true if the consensus data for the current round is the same with the given one and false otherwise

func (*ConsensusState) IsConsensusDataSet

func (cns *ConsensusState) IsConsensusDataSet() bool

IsConsensusDataSet method returns true if the consensus data for the current round is set and false otherwise

func (*ConsensusState) IsCurrentSubroundFinished added in v1.0.3

func (cns *ConsensusState) IsCurrentSubroundFinished(currentSubroundId int) bool

IsCurrentSubroundFinished method returns true if the current subround is finished and false otherwise

func (*ConsensusState) IsHeaderAlreadyReceived

func (cns *ConsensusState) IsHeaderAlreadyReceived() bool

IsHeaderAlreadyReceived method returns true if header is already received and false otherwise

func (*ConsensusState) IsJobDone

func (cns *ConsensusState) IsJobDone(node string, currentSubroundId int) bool

IsJobDone method returns true if the node job for the current subround is done and false otherwise

func (ConsensusState) IsNodeInConsensusGroup

func (rcns ConsensusState) IsNodeInConsensusGroup(node string) bool

IsNodeInConsensusGroup method checks if the node is part of consensus group of the current round

func (ConsensusState) IsNodeInEligibleList

func (rcns ConsensusState) IsNodeInEligibleList(node string) bool

IsNodeInEligibleList method checks if the node is part of the eligible list

func (*ConsensusState) IsNodeLeaderInCurrentRound

func (cns *ConsensusState) IsNodeLeaderInCurrentRound(node string) bool

IsNodeLeaderInCurrentRound method checks if the given node is leader in the current round

func (*ConsensusState) IsNodeSelf

func (cns *ConsensusState) IsNodeSelf(node string) bool

IsNodeSelf method returns true if the message is received from itself and false otherwise

func (*ConsensusState) IsSelfJobDone

func (cns *ConsensusState) IsSelfJobDone(currentSubroundId int) bool

IsSelfJobDone method returns true if self job for the current subround is done and false otherwise

func (*ConsensusState) IsSelfLeaderInCurrentRound

func (cns *ConsensusState) IsSelfLeaderInCurrentRound() bool

IsSelfLeaderInCurrentRound method checks if the current node is leader in the current round

func (ConsensusState) JobDone

func (rcns ConsensusState) JobDone(key string, subroundId int) (bool, error)

JobDone returns the state of the action done, by the node represented by the key parameter, in subround given by the subroundId parameter

func (*ConsensusState) ProcessingBlock

func (cns *ConsensusState) ProcessingBlock() bool

ProcessingBlock gets the state of block processing

func (*ConsensusState) ResetConsensusState

func (cns *ConsensusState) ResetConsensusState()

ResetConsensusState method resets all the consensus data

func (ConsensusState) ResetRoundState

func (rcns ConsensusState) ResetRoundState()

ResetRoundState method resets the state of each node from the current jobDone group, regarding to the consensus validatorRoundStates

func (ConsensusState) ResetRoundStatus

func (rstatus ConsensusState) ResetRoundStatus()

ResetRoundStatus method resets the state of each subround

func (ConsensusState) SelfConsensusGroupIndex

func (rcns ConsensusState) SelfConsensusGroupIndex() (int, error)

SelfConsensusGroupIndex returns the index of self public key in current consensus group

func (ConsensusState) SelfJobDone

func (rcns ConsensusState) SelfJobDone(subroundId int) (bool, error)

SelfJobDone returns the self state of the action done in subround given by the subroundId parameter

func (ConsensusState) SelfPubKey

func (rcns ConsensusState) SelfPubKey() string

SelfPubKey returns selfPubKey ID

func (ConsensusState) SetConsensusGroup

func (rcns ConsensusState) SetConsensusGroup(consensusGroup []string)

SetConsensusGroup sets the consensus group ID's

func (ConsensusState) SetConsensusGroupSize

func (rcns ConsensusState) SetConsensusGroupSize(consensusGroudpSize int)

SetConsensusGroupSize sets the consensus group size

func (ConsensusState) SetEligibleList

func (rcns ConsensusState) SetEligibleList(eligibleList []string)

SetEligibleList sets the eligible list ID's

func (ConsensusState) SetJobDone

func (rcns ConsensusState) SetJobDone(key string, subroundId int, value bool) error

SetJobDone set the state of the action done, by the node represented by the key parameter, in subround given by the subroundId parameter

func (*ConsensusState) SetProcessingBlock

func (cns *ConsensusState) SetProcessingBlock(processingBlock bool)

SetProcessingBlock sets the state of block processing

func (ConsensusState) SetSelfJobDone

func (rcns ConsensusState) SetSelfJobDone(subroundId int, value bool) error

SetSelfJobDone set the self state of the action done in subround given by the subroundId parameter

func (ConsensusState) SetSelfPubKey

func (rcns ConsensusState) SetSelfPubKey(selfPubKey string)

SetSelfPubKey sets selfPubKey ID

func (ConsensusState) SetStatus

func (rstatus ConsensusState) SetStatus(subroundId int, subroundStatus SubroundStatus)

SetStatus sets the status of the given subround id

func (ConsensusState) SetThreshold

func (rthr ConsensusState) SetThreshold(subroundId int, threshold int)

SetThreshold sets the threshold of agreements needed in the given subround id

func (ConsensusState) Status

func (rstatus ConsensusState) Status(subroundId int) SubroundStatus

Status returns the status of the given subround id

func (ConsensusState) Threshold

func (rthr ConsensusState) Threshold(subroundId int) int

Threshold returns the threshold of agreements needed in the given subround id

type Subround

type Subround struct {
	ConsensusCoreHandler
	*ConsensusState

	Job    func() bool          // method does the Subround Job and send the result to the peers
	Check  func() bool          // method checks if the consensus of the Subround is done
	Extend func(subroundId int) // method is called when round time is out
	// contains filtered or unexported fields
}

Subround struct contains the needed data for one Subround and the Subround properties. It defines a Subround with it's properties (it's ID, next Subround ID, it's duration, it's name) and also it has some handler functions which should be set. Job function will be the main function of this Subround, Extend function will handle the overtime situation of the Subround and Check function will decide if in this Subround the consensus is achieved

func NewSubround

func NewSubround(
	previous int,
	current int,
	next int,
	startTime int64,
	endTime int64,
	name string,
	consensusState *ConsensusState,
	consensusStateChangedChannel chan bool,
	executeStoredMessages func(),
	container ConsensusCoreHandler,
) (*Subround, error)

NewSubround creates a new SubroundId object

func (Subround) ComputeSize

func (rcns Subround) ComputeSize(subroundId int) int

ComputeSize method returns the number of messages received from the nodes belonging to the current jobDone group related to this subround

func (Subround) ConsensusGroup

func (rcns Subround) ConsensusGroup() []string

ConsensusGroup returns the consensus group ID's

func (Subround) ConsensusGroupIndex

func (rcns Subround) ConsensusGroupIndex(pubKey string) (int, error)

ConsensusGroupIndex returns the index of given public key in the current consensus group

func (Subround) ConsensusGroupSize

func (rcns Subround) ConsensusGroupSize() int

ConsensusGroupSize returns the consensus group size

func (*Subround) Current

func (sr *Subround) Current() int

Current method returns the ID of the current Subround

func (*Subround) DoWork

func (sr *Subround) DoWork(rounder consensus.Rounder) bool

DoWork method actually does the work of this Subround. First it tries to do the Job of the Subround then it will Check the consensus. If the upper time limit of this Subround is reached, the Extend method will be called before returning. If this method returns true the chronology will advance to the next Subround.

func (Subround) EligibleList added in v1.0.3

func (rcns Subround) EligibleList() []string

EligibleList returns the eligible list ID's

func (*Subround) EndTime

func (sr *Subround) EndTime() int64

EndTime method returns the upper time limit of the Subround

func (Subround) IsNodeInConsensusGroup

func (rcns Subround) IsNodeInConsensusGroup(node string) bool

IsNodeInConsensusGroup method checks if the node is part of consensus group of the current round

func (Subround) IsNodeInEligibleList

func (rcns Subround) IsNodeInEligibleList(node string) bool

IsNodeInEligibleList method checks if the node is part of the eligible list

func (Subround) JobDone

func (rcns Subround) JobDone(key string, subroundId int) (bool, error)

JobDone returns the state of the action done, by the node represented by the key parameter, in subround given by the subroundId parameter

func (*Subround) Name

func (sr *Subround) Name() string

Name method returns the name of the Subround

func (*Subround) Next

func (sr *Subround) Next() int

Next method returns the ID of the next Subround

func (*Subround) Previous

func (sr *Subround) Previous() int

Previous method returns the ID of the previous Subround

func (Subround) ResetRoundState

func (rcns Subround) ResetRoundState()

ResetRoundState method resets the state of each node from the current jobDone group, regarding to the consensus validatorRoundStates

func (Subround) ResetRoundStatus

func (rstatus Subround) ResetRoundStatus()

ResetRoundStatus method resets the state of each subround

func (Subround) SelfConsensusGroupIndex

func (rcns Subround) SelfConsensusGroupIndex() (int, error)

SelfConsensusGroupIndex returns the index of self public key in current consensus group

func (Subround) SelfJobDone

func (rcns Subround) SelfJobDone(subroundId int) (bool, error)

SelfJobDone returns the self state of the action done in subround given by the subroundId parameter

func (Subround) SelfPubKey

func (rcns Subround) SelfPubKey() string

SelfPubKey returns selfPubKey ID

func (Subround) SetConsensusGroup

func (rcns Subround) SetConsensusGroup(consensusGroup []string)

SetConsensusGroup sets the consensus group ID's

func (Subround) SetConsensusGroupSize

func (rcns Subround) SetConsensusGroupSize(consensusGroudpSize int)

SetConsensusGroupSize sets the consensus group size

func (Subround) SetEligibleList

func (rcns Subround) SetEligibleList(eligibleList []string)

SetEligibleList sets the eligible list ID's

func (Subround) SetJobDone

func (rcns Subround) SetJobDone(key string, subroundId int, value bool) error

SetJobDone set the state of the action done, by the node represented by the key parameter, in subround given by the subroundId parameter

func (Subround) SetSelfJobDone

func (rcns Subround) SetSelfJobDone(subroundId int, value bool) error

SetSelfJobDone set the self state of the action done in subround given by the subroundId parameter

func (Subround) SetSelfPubKey

func (rcns Subround) SetSelfPubKey(selfPubKey string)

SetSelfPubKey sets selfPubKey ID

func (Subround) SetStatus

func (rstatus Subround) SetStatus(subroundId int, subroundStatus SubroundStatus)

SetStatus sets the status of the given subround id

func (Subround) SetThreshold

func (rthr Subround) SetThreshold(subroundId int, threshold int)

SetThreshold sets the threshold of agreements needed in the given subround id

func (*Subround) StartTime

func (sr *Subround) StartTime() int64

StartTime method returns the start time of the Subround

func (Subround) Status

func (rstatus Subround) Status(subroundId int) SubroundStatus

Status returns the status of the given subround id

func (Subround) Threshold

func (rthr Subround) Threshold(subroundId int) int

Threshold returns the threshold of agreements needed in the given subround id

type SubroundStatus

type SubroundStatus int

SubroundStatus defines the type used to refer the state of the current subround

const (
	// SsNotFinished defines the un-finished state of the subround
	SsNotFinished SubroundStatus = iota
	// SsFinished defines the finished state of the subround
	SsFinished
)

type SubroundsFactory

type SubroundsFactory interface {
	GenerateSubrounds() error
}

SubroundsFactory encapsulates the methods specifically for a subrounds factory type (bls, bn) for different consensus types

type Worker

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

Worker defines the data needed by spos to communicate between nodes which are in the validators group

func NewWorker

func NewWorker(
	consensusService ConsensusService,
	blockProcessor process.BlockProcessor,
	blockTracker process.BlocksTracker,
	bootstrapper process.Bootstrapper,
	broadcastMessenger consensus.BroadcastMessenger,
	consensusState *ConsensusState,
	forkDetector process.ForkDetector,
	keyGenerator crypto.KeyGenerator,
	marshalizer marshal.Marshalizer,
	rounder consensus.Rounder,
	shardCoordinator sharding.Coordinator,
	singleSigner crypto.SingleSigner,
	syncTimer ntp.SyncTimer,
) (*Worker, error)

NewWorker creates a new Worker object

func (*Worker) AddReceivedMessageCall

func (wrk *Worker) AddReceivedMessageCall(messageType consensus.MessageType, receivedMessageCall func(cnsDta *consensus.Message) bool)

AddReceivedMessageCall adds a new handler function for a received messege type

func (*Worker) BroadcastUnnotarisedBlocks added in v1.0.3

func (wrk *Worker) BroadcastUnnotarisedBlocks()

BroadcastUnnotarisedBlocks broadcasts all blocks which are not notarised yet

func (*Worker) ExecuteStoredMessages

func (wrk *Worker) ExecuteStoredMessages()

ExecuteStoredMessages tries to execute all the messages received which are valid for execution

func (*Worker) Extend

func (wrk *Worker) Extend(subroundId int)

Extend does an extension for the subround with subroundId

func (*Worker) GetConsensusStateChangedChannel

func (wrk *Worker) GetConsensusStateChangedChannel() chan bool

GetConsensusStateChangedChannel gets the channel for the consensusStateChanged

func (*Worker) ProcessReceivedMessage

func (wrk *Worker) ProcessReceivedMessage(message p2p.MessageP2P) error

ProcessReceivedMessage method redirects the received message to the channel which should handle it

func (*Worker) RemoveAllReceivedMessagesCalls

func (wrk *Worker) RemoveAllReceivedMessagesCalls()

RemoveAllReceivedMessagesCalls removes all the functions handlers

type WorkerHandler

type WorkerHandler interface {
	//AddReceivedMessageCall adds a new handler function for a received messege type
	AddReceivedMessageCall(messageType consensus.MessageType, receivedMessageCall func(cnsDta *consensus.Message) bool)
	//RemoveAllReceivedMessagesCalls removes all the functions handlers
	RemoveAllReceivedMessagesCalls()
	//ProcessReceivedMessage method redirects the received message to the channel which should handle it
	ProcessReceivedMessage(message p2p.MessageP2P) error
	//Extend does an extension for the subround with subroundId
	Extend(subroundId int)
	//GetConsensusStateChangedChannel gets the channel for the consensusStateChanged
	GetConsensusStateChangedChannel() chan bool
	//ExecuteStoredMessages tries to execute all the messages received which are valid for execution
	ExecuteStoredMessages()
	//BroadcastUnnotarisedBlocks broadcasts all blocks which are not notarised yet
	BroadcastUnnotarisedBlocks()
}

WorkerHandler represents the interface for the SposWorker

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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