spos

package
v1.999.0 Latest Latest
Warning

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

Go to latest
Published: Nov 17, 2022 License: GPL-3.0 Imports: 26 Imported by: 0

Documentation

Index

Constants

View Source
const LeaderPeerHonestyDecreaseFactor = -4

LeaderPeerHonestyDecreaseFactor specifies the factor with which the honesty of the leader should be decreased if it proposed a block or sent the final info, in an incorrect allocated slot/time-frame/round

View Source
const LeaderPeerHonestyIncreaseFactor = 2

LeaderPeerHonestyIncreaseFactor specifies the factor with which the honesty of the leader should be increased if it proposed a block or sent the final info, in its correct allocated slot/time-frame/round

View Source
const MaxNumOfMessageTypeAccepted = 1

MaxNumOfMessageTypeAccepted represents the maximum number of the same message type accepted in one round to be received from the same public key

View Source
const MaxThresholdPercent = 95

MaxThresholdPercent specifies the max allocated time percent for doing Job as a percentage of the total time of one round

View Source
const ValidatorPeerHonestyDecreaseFactor = -2

ValidatorPeerHonestyDecreaseFactor specifies the factor with which the honesty of the validator should be decreased if it sent the signature, in an incorrect allocated slot/time-frame/round

View Source
const ValidatorPeerHonestyIncreaseFactor = 1

ValidatorPeerHonestyIncreaseFactor specifies the factor with which the honesty of the validator should be increased if it sent the signature, in its correct allocated slot/time-frame/round

Variables

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 ErrInvalidBodySize = errors.New("invalid body size")

ErrInvalidBodySize signals that an invalid body size has been received from consensus topic

View Source
var ErrInvalidCacheSize = errors.New("invalid cache size")

ErrInvalidCacheSize signals an invalid size provided for cache

View Source
var ErrInvalidChainID = errors.New("invalid chain ID in consensus")

ErrInvalidChainID signals that an invalid chain ID has been provided

View Source
var ErrInvalidHeader = errors.New("header is invalid")

ErrInvalidHeader is raised when header is invalid

View Source
var ErrInvalidHeaderHashSize = errors.New("invalid header hash size")

ErrInvalidHeaderHashSize signals that an invalid header hash size has been received from consensus topic

View Source
var ErrInvalidHeaderSize = errors.New("invalid header size")

ErrInvalidHeaderSize signals that an invalid header size has been received from consensus topic

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 ErrInvalidMessage = errors.New("invalid message")

ErrInvalidMessage signals that an invalid message has been received from consensus topic

View Source
var ErrInvalidMessageType = errors.New("invalid message type")

ErrInvalidMessageType signals that an invalid message type has been received from consensus topic

View Source
var ErrInvalidMetaHeader = errors.New("meta header is invalid")

ErrInvalidMetaHeader is raised when an invalid meta header was provided

View Source
var ErrInvalidPublicKeyBitmapSize = errors.New("invalid public key bitmap size")

ErrInvalidPublicKeyBitmapSize signals that an invalid public key bitmap size has been received from consensus topic

View Source
var ErrInvalidPublicKeySize = errors.New("invalid public key size")

ErrInvalidPublicKeySize signals that an invalid public key size has been received from consensus topic

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

ErrInvalidSignature is raised when signature is invalid

View Source
var ErrInvalidSignatureSize = errors.New("invalid signature size")

ErrInvalidSignatureSize signals that an invalid signature size has been received from consensus topic

View Source
var ErrMessageForFutureRound = errors.New("message is for future round")

ErrMessageForFutureRound is raised when message is for future round

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 ErrMessageTypeLimitReached = errors.New("consensus message type limit has been reached")

ErrMessageTypeLimitReached signals that a consensus message type limit has been reached for a public key

View Source
var ErrNilAlarmScheduler = errors.New("alarm scheduler is nil")

ErrNilAlarmScheduler is raised when a valid alarm scheduler is expected but nil is provided

View Source
var ErrNilAntifloodHandler = errors.New("nil antiflood handler")

ErrNilAntifloodHandler signals that a nil antiflood handler has been provided

View Source
var ErrNilAppStatusHandler = errors.New("nil AppStatusHandler")

ErrNilAppStatusHandler defines the error for setting a nil AppStatusHandler

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 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 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 ErrNilConsensusCore = errors.New("consensus core is nil")

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

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 ErrNilFallbackHeaderValidator = errors.New("nil fallback header validator")

ErrNilFallbackHeaderValidator signals that a nil fallback header validator has been provided

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 ErrNilHeaderHash = errors.New("header hash is nil")

ErrNilHeaderHash is raised when a nil header hash is provided

View Source
var ErrNilHeaderIntegrityVerifier = errors.New("nil header integrity verifier")

ErrNilHeaderIntegrityVerifier signals that a nil header integrity verifier has been provided

View Source
var ErrNilHeaderSigVerifier = errors.New("nil header sig verifier")

ErrNilHeaderSigVerifier signals that a nil header sig verifier has been provided

View Source
var ErrNilHeadersSubscriber = errors.New("headers subscriber is nil")

ErrNilHeadersSubscriber is raised when a valid headers subscriber is expected but nil is provided

View Source
var ErrNilInterceptorsContainer = errors.New("interceptor container is nil")

ErrNilInterceptorsContainer is raised when a nil interceptor container is provided

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 ErrNilNetworkShardingCollector = errors.New("nil network sharding collector")

ErrNilNetworkShardingCollector defines the error for setting a nil network sharding collector

View Source
var ErrNilNodeRedundancyHandler = errors.New("nil node redundancy handler")

ErrNilNodeRedundancyHandler signals that provided node redundancy handler is nil

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

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

View Source
var ErrNilParameter = errors.New("parameter is nil")

ErrNilParameter is raised when a nil parameter is provided

View Source
var ErrNilPeerHonestyHandler = errors.New("nil peer honesty handler")

ErrNilPeerHonestyHandler signals that a nil peer honesty handler has been provided

View Source
var ErrNilPeerSignatureHandler = errors.New("trying to set nil peerSignatureHandler")

ErrNilPeerSignatureHandler signals that a nil peerSignatureHandler object has been provided

View Source
var ErrNilPoolAdder = errors.New("nil pool adder")

ErrNilPoolAdder signals that a nil pool adder has been provided

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 ErrNilRoundHandler = errors.New("roundHandler is nil")

ErrNilRoundHandler is raised when a valid roundHandler is expected but nil 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 ErrNilScheduledProcessor = errors.New("nil scheduled processor")

ErrNilScheduledProcessor signals that the provided scheduled processor is nil

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 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 ErrNilWorker = errors.New("worker is nil")

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

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

ErrNilWorkerArgs signals that nil a workerArgs has been provided

View Source
var ErrNodeIsNotInEligibleList = errors.New("node is not in eligible list")

ErrNodeIsNotInEligibleList is raised when a node is not in eligible list

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 ErrOriginatorMismatch = errors.New("consensus message originator mismatch")

ErrOriginatorMismatch signals that an original consensus message has been re-broadcast manually by another peer

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

ErrRoundCanceled is raised when round is canceled

Functions

func GetConsensusTopicID

func GetConsensusTopicID(shardCoordinator sharding.Coordinator) string

GetConsensusTopicID will construct and return the topic ID based on shard coordinator

func NewConsensusMessageValidator

func NewConsensusMessageValidator(args *ArgsConsensusMessageValidator) (*consensusMessageValidator, error)

NewConsensusMessageValidator creates a new consensusMessageValidator object

func NewRoundConsensus

func NewRoundConsensus(
	eligibleNodes map[string]struct{},
	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 NewScheduledProcessorWrapper

func NewScheduledProcessorWrapper(args ScheduledProcessorWrapperArgs) (*scheduledProcessorWrapper, error)

NewScheduledProcessorWrapper creates a new processor for scheduled transactions

func ValidateConsensusCore

func ValidateConsensusCore(container ConsensusCoreHandler) error

ValidateConsensusCore checks for nil all the container objects

Types

type ArgsConsensusMessageValidator

type ArgsConsensusMessageValidator struct {
	ConsensusState       *ConsensusState
	ConsensusService     ConsensusService
	PeerSignatureHandler crypto.PeerSignatureHandler
	SignatureSize        int
	PublicKeySize        int
	HasherSize           int
	ChainID              []byte
}

ArgsConsensusMessageValidator holds the consensus message validator arguments

type ConsensusCore

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

ConsensusCore implements ConsensusCoreHandler and provides access to common functionality

for the rest of the consensus structures

func NewConsensusCore

func NewConsensusCore(
	args *ConsensusCoreArgs,
) (*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) 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) EpochStartRegistrationHandler

func (cc *ConsensusCore) EpochStartRegistrationHandler() epochStart.RegistrationHandler

EpochStartRegistrationHandler returns the epoch start registration handler

func (*ConsensusCore) FallbackHeaderValidator

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

FallbackHeaderValidator will return the fallback header validator which will be used in subrounds

func (*ConsensusCore) GetAntiFloodHandler

func (cc *ConsensusCore) GetAntiFloodHandler() consensus.P2PAntifloodHandler

GetAntiFloodHandler will return the antiflood handler which will be used in subrounds

func (*ConsensusCore) Hasher

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

Hasher gets the Hasher stored in the ConsensusCore

func (*ConsensusCore) HeaderSigVerifier

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

HeaderSigVerifier returns the sig verifier handler which will be used in subrounds

func (*ConsensusCore) IsInterfaceNil

func (cc *ConsensusCore) IsInterfaceNil() bool

IsInterfaceNil returns true if there is no value under the interface

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

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

NodeRedundancyHandler will return the node redundancy handler which will be used in subrounds

func (*ConsensusCore) NodesCoordinator

func (cc *ConsensusCore) NodesCoordinator() nodesCoordinator.NodesCoordinator

NodesCoordinator gets the NodesCoordinator stored in the ConsensusCore

func (*ConsensusCore) PeerHonestyHandler

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

PeerHonestyHandler will return the peer honesty handler which will be used in subrounds

func (*ConsensusCore) PrivateKey

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

PrivateKey returns the BLS private key stored in the ConsensusStore

func (*ConsensusCore) RoundHandler

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

RoundHandler gets the RoundHandler stored in the ConsensusCore

func (*ConsensusCore) ScheduledProcessor

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

ScheduledProcessor will return the scheduled processor

func (*ConsensusCore) ShardCoordinator

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

ShardCoordinator gets the ShardCoordinator stored in the ConsensusCore

func (*ConsensusCore) SingleSigner

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

SingleSigner returns the bls single signer stored in the ConsensusStore

func (*ConsensusCore) SyncTimer

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

SyncTimer gets the SyncTimer stored in the ConsensusCore

type ConsensusCoreArgs

type ConsensusCoreArgs struct {
	BlockChain                    data.ChainHandler
	BlockProcessor                process.BlockProcessor
	Bootstrapper                  process.Bootstrapper
	BroadcastMessenger            consensus.BroadcastMessenger
	ChronologyHandler             consensus.ChronologyHandler
	Hasher                        hashing.Hasher
	Marshalizer                   marshal.Marshalizer
	BlsPrivateKey                 crypto.PrivateKey
	BlsSingleSigner               crypto.SingleSigner
	MultiSigner                   crypto.MultiSigner
	RoundHandler                  consensus.RoundHandler
	ShardCoordinator              sharding.Coordinator
	NodesCoordinator              nodesCoordinator.NodesCoordinator
	SyncTimer                     ntp.SyncTimer
	EpochStartRegistrationHandler epochStart.RegistrationHandler
	AntifloodHandler              consensus.P2PAntifloodHandler
	PeerHonestyHandler            consensus.PeerHonestyHandler
	HeaderSigVerifier             consensus.HeaderSigVerifier
	FallbackHeaderValidator       consensus.FallbackHeaderValidator
	NodeRedundancyHandler         consensus.NodeRedundancyHandler
	ScheduledProcessor            consensus.ScheduledProcessor
}

ConsensusCoreArgs store all arguments that are needed to create a ConsensusCore object

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
	// 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
	// GetAntiFloodHandler returns the antiflood handler which will be used in subrounds
	GetAntiFloodHandler() consensus.P2PAntifloodHandler
	// 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
	// RoundHandler gets the RoundHandler stored in the ConsensusCore
	RoundHandler() consensus.RoundHandler
	// ShardCoordinator gets the ShardCoordinator stored in the ConsensusCore
	ShardCoordinator() sharding.Coordinator
	// SyncTimer gets the SyncTimer stored in the ConsensusCore
	SyncTimer() ntp.SyncTimer
	// NodesCoordinator gets the NodesCoordinator stored in the ConsensusCore
	NodesCoordinator() nodesCoordinator.NodesCoordinator
	// EpochStartRegistrationHandler gets the RegistrationHandler stored in the ConsensusCore
	EpochStartRegistrationHandler() epochStart.RegistrationHandler
	// PrivateKey returns the private key stored in the ConsensusStore used for randomness and leader's signature generation
	PrivateKey() crypto.PrivateKey
	// SingleSigner returns the single signer stored in the ConsensusStore used for randomness and leader's signature generation
	SingleSigner() crypto.SingleSigner
	// PeerHonestyHandler returns the peer honesty handler which will be used in subrounds
	PeerHonestyHandler() consensus.PeerHonestyHandler
	// HeaderSigVerifier returns the sig verifier handler which will be used in subrounds
	HeaderSigVerifier() consensus.HeaderSigVerifier
	// FallbackHeaderValidator returns the fallback header validator handler which will be used in subrounds
	FallbackHeaderValidator() consensus.FallbackHeaderValidator
	// NodeRedundancyHandler returns the node redundancy handler which will be used in subrounds
	NodeRedundancyHandler() consensus.NodeRedundancyHandler
	// ScheduledProcessor returns the scheduled txs processor
	ScheduledProcessor() consensus.ScheduledProcessor
	// IsInterfaceNil returns true if there is no value under the interface
	IsInterfaceNil() bool
}

ConsensusCoreHandler encapsulates all needed data for the Consensus

type ConsensusDataIndexer

type ConsensusDataIndexer interface {
	SaveRoundsInfo(roundsInfos []*indexer.RoundInfo)
	IsInterfaceNil() bool
}

ConsensusDataIndexer defines the actions that a consensus data indexer has to do

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
	// IsMessageWithBlockBodyAndHeader returns if the current messageType is about block body and header
	IsMessageWithBlockBodyAndHeader(consensus.MessageType) bool
	// IsMessageWithBlockBody returns if the current messageType is about block body
	IsMessageWithBlockBody(consensus.MessageType) bool
	// IsMessageWithBlockHeader returns if the current messageType is about block header
	IsMessageWithBlockHeader(consensus.MessageType) bool
	// IsMessageWithSignature returns if the current messageType is about signature
	IsMessageWithSignature(consensus.MessageType) bool
	// IsMessageWithFinalInfo returns if the current messageType is about header final info
	IsMessageWithFinalInfo(consensus.MessageType) bool
	// IsMessageTypeValid returns if the current messageType is valid
	IsMessageTypeValid(consensus.MessageType) bool
	// IsSubroundSignature returns if the current subround is about signature
	IsSubroundSignature(int) bool
	// IsSubroundStartRound returns if the current subround is about start round
	IsSubroundStartRound(int) bool
	// GetMaxMessagesInARoundPerPeer returns the maximum number of messages a peer can send per round
	GetMaxMessagesInARoundPerPeer() uint32
	// IsInterfaceNil returns true if there is no value under the interface
	IsInterfaceNil() 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
	Body   data.BodyHandler
	Header data.HeaderHandler

	RoundIndex                  int64
	RoundTimeStamp              time.Time
	RoundCanceled               bool
	ExtendedCalled              bool
	WaitingAllSignaturesTimeOut 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) AddReceivedHeader

func (cns *ConsensusState) AddReceivedHeader(headerHandler data.HeaderHandler)

AddReceivedHeader append the provided header to the inner received headers list

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 int64,
	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) FallbackThreshold

func (rthr ConsensusState) FallbackThreshold(subroundId int) int

FallbackThreshold returns the fallback threshold of agreements needed in the given subround id

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 []byte,
	round uint64,
	shardId uint32,
	nodesCoordinator nodesCoordinator.NodesCoordinator,
	epoch uint32,
) ([]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) GetReceivedHeaders

func (cns *ConsensusState) GetReceivedHeaders() []data.HeaderHandler

GetReceivedHeaders returns the received headers list

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

func (cns *ConsensusState) IsSubroundFinished(subroundID int) bool

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

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 map[string]struct{})

SetEligibleList sets the eligible list ID's

func (ConsensusState) SetFallbackThreshold

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

SetFallbackThreshold sets the fallback threshold of agreements needed in the given subround id

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 HeaderSigVerifier

type HeaderSigVerifier interface {
	VerifyRandSeed(header data.HeaderHandler) error
	VerifyLeaderSignature(header data.HeaderHandler) error
	VerifySignature(header data.HeaderHandler) error
	IsInterfaceNil() bool
}

HeaderSigVerifier encapsulates methods that check if header signature is correct

type PoolAdder

type PoolAdder interface {
	Put(key []byte, value interface{}, sizeInBytes int) (evicted bool)
	IsInterfaceNil() bool
}

PoolAdder adds data in a key-value pool

type ScheduledProcessorWrapperArgs

type ScheduledProcessorWrapperArgs struct {
	SyncTimer                ntp.SyncTimer
	Processor                process.ScheduledBlockProcessor
	RoundTimeDurationHandler process.RoundTimeDurationHandler
}

ScheduledProcessorWrapperArgs holds the arguments required to instantiate the pipelineExecution

type Subround

type Subround struct {
	ConsensusCoreHandler
	*ConsensusState

	Job    func(ctx context.Context) 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,
	chainID []byte,
	currentPid core.PeerID,
	appStatusHandler core.AppStatusHandler,
) (*Subround, error)

NewSubround creates a new SubroundId object

func (*Subround) AppStatusHandler

func (sr *Subround) AppStatusHandler() core.AppStatusHandler

AppStatusHandler method returns the appStatusHandler instance

func (*Subround) ChainID

func (sr *Subround) ChainID() []byte

ChainID method returns the current chain ID

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

func (sr *Subround) ConsensusChannel() chan bool

ConsensusChannel method returns the consensus channel

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

func (sr *Subround) CurrentPid() core.PeerID

CurrentPid returns the current p2p peer ID

func (*Subround) DoWork

func (sr *Subround) DoWork(ctx context.Context, roundHandler consensus.RoundHandler) 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) EndTime

func (sr *Subround) EndTime() int64

EndTime method returns the upper time limit of the Subround

func (Subround) FallbackThreshold

func (rthr Subround) FallbackThreshold(subroundId int) int

FallbackThreshold returns the fallback threshold of agreements needed in the given subround id

func (*Subround) IsInterfaceNil

func (sr *Subround) IsInterfaceNil() bool

IsInterfaceNil returns true if there is no value under the interface

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 map[string]struct{})

SetEligibleList sets the eligible list ID's

func (Subround) SetFallbackThreshold

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

SetFallbackThreshold sets the fallback threshold of agreements needed in the given subround id

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
	IsInterfaceNil() bool
}

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(args *WorkerArgs) (*Worker, error)

NewWorker creates a new Worker object

func (*Worker) AddReceivedHeaderHandler

func (wrk *Worker) AddReceivedHeaderHandler(handler func(data.HeaderHandler))

AddReceivedHeaderHandler adds a new handler function for a received header

func (*Worker) AddReceivedMessageCall

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

AddReceivedMessageCall adds a new handler function for a received messege type

func (*Worker) Close

func (wrk *Worker) Close() error

Close will close the endless running go routine

func (*Worker) DisplayStatistics

func (wrk *Worker) DisplayStatistics()

DisplayStatistics logs the consensus messages split on proposed headers

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

func (wrk *Worker) IsInterfaceNil() bool

IsInterfaceNil returns true if there is no value under the interface

func (*Worker) ProcessReceivedMessage

func (wrk *Worker) ProcessReceivedMessage(message p2p.MessageP2P, fromConnectedPeer core.PeerID) error

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

func (*Worker) ReceivedHeader

func (wrk *Worker) ReceivedHeader(headerHandler data.HeaderHandler, _ []byte)

ReceivedHeader process the received header, calling each received header handler registered in worker instance

func (*Worker) RemoveAllReceivedMessagesCalls

func (wrk *Worker) RemoveAllReceivedMessagesCalls()

RemoveAllReceivedMessagesCalls removes all the functions handlers

func (*Worker) ResetConsensusMessages

func (wrk *Worker) ResetConsensusMessages()

ResetConsensusMessages resets at the start of each round all the previous consensus messages received

func (*Worker) StartWorking

func (wrk *Worker) StartWorking()

StartWorking actually starts the consensus working mechanism

type WorkerArgs

type WorkerArgs struct {
	ConsensusService         ConsensusService
	BlockChain               data.ChainHandler
	BlockProcessor           process.BlockProcessor
	ScheduledProcessor       consensus.ScheduledProcessor
	Bootstrapper             process.Bootstrapper
	BroadcastMessenger       consensus.BroadcastMessenger
	ConsensusState           *ConsensusState
	ForkDetector             process.ForkDetector
	Marshalizer              marshal.Marshalizer
	Hasher                   hashing.Hasher
	RoundHandler             consensus.RoundHandler
	ShardCoordinator         sharding.Coordinator
	PeerSignatureHandler     crypto.PeerSignatureHandler
	SyncTimer                ntp.SyncTimer
	HeaderSigVerifier        HeaderSigVerifier
	HeaderIntegrityVerifier  process.HeaderIntegrityVerifier
	ChainID                  []byte
	NetworkShardingCollector consensus.NetworkShardingCollector
	AntifloodHandler         consensus.P2PAntifloodHandler
	PoolAdder                PoolAdder
	SignatureSize            int
	PublicKeySize            int
	AppStatusHandler         core.AppStatusHandler
	NodeRedundancyHandler    consensus.NodeRedundancyHandler
}

WorkerArgs holds the consensus worker arguments

type WorkerHandler

type WorkerHandler interface {
	Close() error
	StartWorking()
	// AddReceivedMessageCall adds a new handler function for a received message type
	AddReceivedMessageCall(messageType consensus.MessageType, receivedMessageCall func(ctx context.Context, cnsDta *consensus.Message) bool)
	// AddReceivedHeaderHandler adds a new handler function for a received header
	AddReceivedHeaderHandler(handler func(data.HeaderHandler))
	// RemoveAllReceivedMessagesCalls removes all the functions handlers
	RemoveAllReceivedMessagesCalls()
	// ProcessReceivedMessage method redirects the received message to the channel which should handle it
	ProcessReceivedMessage(message p2p.MessageP2P, fromConnectedPeer core.PeerID) 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()
	// DisplayStatistics method displays statistics of worker at the end of the round
	DisplayStatistics()
	// ReceivedHeader method is a wired method through which worker will receive headers from network
	ReceivedHeader(headerHandler data.HeaderHandler, headerHash []byte)
	//  ResetConsensusMessages resets at the start of each round all the previous consensus messages received
	ResetConsensusMessages()
	// IsInterfaceNil returns true if there is no value under the interface
	IsInterfaceNil() bool
}

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