core

package
v1.0.0 Latest Latest
Warning

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

Go to latest
Published: Apr 25, 2019 License: LGPL-3.0 Imports: 20 Imported by: 0

Documentation

Index

Constants

View Source
const ConfigRoundShift uint64 = 2

ConfigRoundShift refers to the difference between block's round and config round derived from its state.

For example, when round shift is 2, a block in round 0 should derive config for round 2.

View Source
const DKGDelayRound uint64 = 1

DKGDelayRound refers to the round that first DKG is run.

For example, when delay round is 1, new DKG will run at round 1. Round 0 will have neither DKG nor CRS.

Variables

View Source
var (
	ErrPreviousRoundIsNotFinished = errors.New("previous round is not finished")
	ErrRoundOutOfRange            = errors.New("round out of range")
	ErrInvalidBlock               = errors.New("invalid block")
	ErrNoValidLeader              = errors.New("no valid leader")
	ErrIncorrectCRSSignature      = errors.New("incorrect CRS signature")
	ErrBlockTooOld                = errors.New("block too old")
)

Errors returned from BA modules

View Source
var (
	ErrNoEnoughVoteInPrepareState = fmt.Errorf("no enough vote in prepare state")
	ErrNoEnoughVoteInAckState     = fmt.Errorf("no enough vote in ack state")
)

Errors for agreement state module.

View Source
var (
	ErrInvalidVote                   = fmt.Errorf("invalid vote")
	ErrNotInNotarySet                = fmt.Errorf("not in notary set")
	ErrIncorrectVoteSignature        = fmt.Errorf("incorrect vote signature")
	ErrIncorrectVotePartialSignature = fmt.Errorf("incorrect vote psig")
	ErrMismatchBlockPosition         = fmt.Errorf("mismatch block position")
)

Errors for agreement module.

View Source
var (
	ErrBlockFromOlderPosition   = errors.New("block from older position")
	ErrNotGenesisBlock          = errors.New("not a genesis block")
	ErrIsGenesisBlock           = errors.New("is a genesis block")
	ErrIncorrectParentHash      = errors.New("incorrect parent hash")
	ErrInvalidBlockHeight       = errors.New("invalid block height")
	ErrInvalidRoundID           = errors.New("invalid round id")
	ErrInvalidTimestamp         = errors.New("invalid timestamp")
	ErrNotFollowTipPosition     = errors.New("not follow tip position")
	ErrDuplicatedPendingBlock   = errors.New("duplicated pending block")
	ErrRetrySanityCheckLater    = errors.New("retry sanity check later")
	ErrRoundNotSwitch           = errors.New("round not switch")
	ErrIncorrectAgreementResult = errors.New(
		"incorrect block randomness result")
	ErrMissingRandomness = errors.New("missing block randomness")
)

Errors for sanity check error.

View Source
var (
	ErrDKGNotRegistered = fmt.Errorf(
		"not yet registered in DKG protocol")
	ErrTSigAlreadyRunning = fmt.Errorf(
		"tsig is already running")
	ErrDKGNotReady = fmt.Errorf(
		"DKG is not ready")
	ErrSkipButNoError = fmt.Errorf(
		"skip but no error")
	ErrDKGAborted = fmt.Errorf(
		"DKG is aborted")
)

Errors for configuration chain..

View Source
var (
	ErrProposerNotInNodeSet = fmt.Errorf(
		"proposer is not in node set")
	ErrIncorrectHash = fmt.Errorf(
		"hash of block is incorrect")
	ErrIncorrectSignature = fmt.Errorf(
		"signature of block is incorrect")
	ErrUnknownBlockProposed = fmt.Errorf(
		"unknown block is proposed")
	ErrIncorrectAgreementResultPosition = fmt.Errorf(
		"incorrect agreement result position")
	ErrNotEnoughVotes = fmt.Errorf(
		"not enought votes")
	ErrCRSNotReady = fmt.Errorf(
		"CRS not ready")
	ErrConfigurationNotReady = fmt.Errorf(
		"Configuration not ready")
	ErrIncorrectBlockRandomness = fmt.Errorf(
		"randomness of block is incorrect")
	ErrCannotVerifyBlockRandomness = fmt.Errorf(
		"cannot verify block randomness")
)

Errors for consensus core.

View Source
var (
	ErrNotDKGParticipant = fmt.Errorf(
		"not a DKG participant")
	ErrNotQualifyDKGParticipant = fmt.Errorf(
		"not a qualified DKG participant")
	ErrIDShareNotFound = fmt.Errorf(
		"private share not found for specific ID")
	ErrIncorrectPrivateShareSignature = fmt.Errorf(
		"incorrect private share signature")
	ErrMismatchPartialSignatureHash = fmt.Errorf(
		"mismatch partialSignature hash")
	ErrIncorrectPartialSignatureSignature = fmt.Errorf(
		"incorrect partialSignature signature")
	ErrIncorrectPartialSignature = fmt.Errorf(
		"incorrect partialSignature")
	ErrNotEnoughtPartialSignatures = fmt.Errorf(
		"not enough of partial signatures")
	ErrRoundAlreadyPurged = fmt.Errorf(
		"cache of round already been purged")
	ErrTSigNotReady = fmt.Errorf(
		"tsig not ready")
	ErrSelfMPKNotRegister = fmt.Errorf(
		"self mpk not registered")
	ErrUnableGetSelfPrvShare = fmt.Errorf(
		"unable to get self DKG PrivateShare")
	ErrSelfPrvShareMismatch = fmt.Errorf(
		"self privateShare does not match mpk registered")
)

Errors for dkg module.

View Source
var (
	ErrIncorrectVoteBlockHash = fmt.Errorf(
		"incorrect vote block hash")
	ErrIncorrectVoteType = fmt.Errorf(
		"incorrect vote type")
	ErrIncorrectVotePosition = fmt.Errorf(
		"incorrect vote position")
	ErrIncorrectVoteProposer = fmt.Errorf(
		"incorrect vote proposer")
	ErrIncorrectVotePeriod = fmt.Errorf(
		"incorrect vote period")
)

Errors for utils.

View Source
var (

	// ErrEmptyTimestamps would be reported if Block.timestamps is empty.
	ErrEmptyTimestamps = errors.New("timestamp vector should not be empty")
)
View Source
var NewNodeSetCache = utils.NewNodeSetCache

NewNodeSetCache is function alias to avoid fullnode compile error when moving it to core/utils package.

View Source
var NoRand = []byte("norand")

NoRand is the magic placeholder for randomness field in blocks for blocks proposed before DKGDelayRound.

Functions

func Debugf

func Debugf(format string, args ...interface{})

Debugf is like fmt.Printf, but only output when we are in debug mode.

func Debugln

func Debugln(args ...interface{})

Debugln is like fmt.Println, but only output when we are in debug mode.

func DiffUint64

func DiffUint64(a, b uint64) uint64

DiffUint64 calculates difference between two uint64.

func HashConfigurationBlock

func HashConfigurationBlock(
	notarySet map[types.NodeID]struct{},
	config *types.Config,
	snapshotHash common.Hash,
	prevHash common.Hash,
) common.Hash

HashConfigurationBlock returns the hash value of configuration block.

func VerifyAgreementResult

func VerifyAgreementResult(
	res *types.AgreementResult, notarySet map[types.NodeID]struct{}) error

VerifyAgreementResult perform sanity check against a types.AgreementResult instance.

Types

type Application

type Application interface {
	// PreparePayload is called when consensus core is preparing a block.
	PreparePayload(position types.Position) ([]byte, error)

	// PrepareWitness will return the witness data no lower than consensusHeight.
	PrepareWitness(consensusHeight uint64) (types.Witness, error)

	// VerifyBlock verifies if the block is valid.
	VerifyBlock(block *types.Block) types.BlockVerifyStatus

	// BlockConfirmed is called when a block is confirmed and added to lattice.
	BlockConfirmed(block types.Block)

	// BlockDelivered is called when a block is added to the compaction chain.
	BlockDelivered(hash common.Hash, position types.Position, rand []byte)
}

Application describes the application interface that interacts with DEXON consensus core.

type Consensus

type Consensus struct {
	// Node Info.
	ID types.NodeID
	// contains filtered or unexported fields
}

Consensus implements DEXON Consensus algorithm.

func NewConsensus

func NewConsensus(
	dMoment time.Time,
	app Application,
	gov Governance,
	db db.Database,
	network Network,
	prv crypto.PrivateKey,
	logger common.Logger) *Consensus

NewConsensus construct an Consensus instance.

func NewConsensusForSimulation

func NewConsensusForSimulation(
	dMoment time.Time,
	app Application,
	gov Governance,
	db db.Database,
	network Network,
	prv crypto.PrivateKey,
	logger common.Logger) *Consensus

NewConsensusForSimulation creates an instance of Consensus for simulation, the only difference with NewConsensus is nonblocking of app.

func NewConsensusFromSyncer

func NewConsensusFromSyncer(
	initBlock *types.Block,
	startWithEmpty bool,
	dMoment time.Time,
	app Application,
	gov Governance,
	db db.Database,
	networkModule Network,
	prv crypto.PrivateKey,
	confirmedBlocks []*types.Block,
	cachedMessages []types.Msg,
	logger common.Logger) (*Consensus, error)

NewConsensusFromSyncer constructs an Consensus instance from information provided from syncer.

You need to provide the initial block for this newly created Consensus instance to bootstrap with. A proper choice is the last finalized block you delivered to syncer.

NOTE: those confirmed blocks should be organized by chainID and sorted by

their positions, in ascending order.

func (*Consensus) ProcessAgreementResult

func (con *Consensus) ProcessAgreementResult(
	rand *types.AgreementResult) error

ProcessAgreementResult processes the randomness request.

func (*Consensus) ProcessVote

func (con *Consensus) ProcessVote(vote *types.Vote) (err error)

ProcessVote is the entry point to submit ont vote to a Consensus instance.

func (*Consensus) Run

func (con *Consensus) Run()

Run starts running DEXON Consensus.

func (*Consensus) Stop

func (con *Consensus) Stop()

Stop the Consensus core.

type Debug

type Debug interface {
	// BlockReceived is called when the block received in agreement.
	BlockReceived(common.Hash)
	// BlockReady is called when the block's randomness is ready.
	BlockReady(common.Hash)
}

Debug describes the application interface that requires more detailed consensus execution.

type ErrFork

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

ErrFork for fork error in agreement.

func (*ErrFork) Error

func (e *ErrFork) Error() string

type ErrForkVote

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

ErrForkVote for fork vote error in agreement.

func (*ErrForkVote) Error

func (e *ErrForkVote) Error() string

type ErrMismatchDKG

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

ErrMismatchDKG represent an attempt to run DKG protocol is failed because the register DKG protocol is mismatched, interms of round and resetCount.

func (ErrMismatchDKG) Error

func (e ErrMismatchDKG) Error() string

type ErrUnexpectedDKGResetCount

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

ErrUnexpectedDKGResetCount represents receiving a DKG message with unexpected DKG reset count.

func (ErrUnexpectedDKGResetCount) Error

type ErrUnexpectedRound

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

ErrUnexpectedRound represents receiving a DKG message with unexpected round.

func (ErrUnexpectedRound) Error

func (e ErrUnexpectedRound) Error() string

type Governance

type Governance interface {
	// Configuration returns the configuration at a given round.
	// Return the genesis configuration if round == 0.
	Configuration(round uint64) *types.Config

	// CRS returns the CRS for a given round. Return the genesis CRS if
	// round == 0.
	//
	// The CRS returned is the proposed or latest reseted one, it would be
	// changed later if corresponding DKG set failed to generate group public
	// key.
	CRS(round uint64) common.Hash

	// Propose a CRS of round.
	ProposeCRS(round uint64, signedCRS []byte)

	// NodeSet returns the node set at a given round.
	// Return the genesis node set if round == 0.
	NodeSet(round uint64) []crypto.PublicKey

	// Get the begin height of a round.
	GetRoundHeight(round uint64) uint64

	// AddDKGComplaint adds a DKGComplaint.
	AddDKGComplaint(complaint *typesDKG.Complaint)

	// DKGComplaints gets all the DKGComplaints of round.
	DKGComplaints(round uint64) []*typesDKG.Complaint

	// AddDKGMasterPublicKey adds a DKGMasterPublicKey.
	AddDKGMasterPublicKey(masterPublicKey *typesDKG.MasterPublicKey)

	// DKGMasterPublicKeys gets all the DKGMasterPublicKey of round.
	DKGMasterPublicKeys(round uint64) []*typesDKG.MasterPublicKey

	// AddDKGMPKReady adds a DKG ready message.
	AddDKGMPKReady(ready *typesDKG.MPKReady)

	// IsDKGMPKReady checks if DKG's master public key preparation is ready.
	IsDKGMPKReady(round uint64) bool

	// AddDKGFinalize adds a DKG finalize message.
	AddDKGFinalize(final *typesDKG.Finalize)

	// IsDKGFinal checks if DKG is final.
	IsDKGFinal(round uint64) bool

	// AddDKGSuccess adds a DKG success message.
	AddDKGSuccess(success *typesDKG.Success)

	// IsDKGSuccess checks if DKG is success.
	IsDKGSuccess(round uint64) bool

	// ReportForkVote reports a node for forking votes.
	ReportForkVote(vote1, vote2 *types.Vote)

	// ReportForkBlock reports a node for forking blocks.
	ReportForkBlock(block1, block2 *types.Block)

	// ResetDKG resets latest DKG data and propose new CRS.
	ResetDKG(newSignedCRS []byte)

	// DKGResetCount returns the reset count for DKG of given round.
	DKGResetCount(round uint64) uint64
}

Governance interface specifies interface to control the governance contract. Note that there are a lot more methods in the governance contract, that this interface only define those that are required to run the consensus algorithm.

type Network

type Network interface {
	// PullBlocks tries to pull blocks from the DEXON network.
	PullBlocks(hashes common.Hashes)

	// PullVotes tries to pull votes from the DEXON network.
	PullVotes(position types.Position)

	// BroadcastVote broadcasts vote to all nodes in DEXON network.
	BroadcastVote(vote *types.Vote)

	// BroadcastBlock broadcasts block to all nodes in DEXON network.
	BroadcastBlock(block *types.Block)

	// BroadcastAgreementResult broadcasts agreement result to DKG set.
	BroadcastAgreementResult(randRequest *types.AgreementResult)

	// SendDKGPrivateShare sends PrivateShare to a DKG participant.
	SendDKGPrivateShare(pub crypto.PublicKey, prvShare *typesDKG.PrivateShare)

	// BroadcastDKGPrivateShare broadcasts PrivateShare to all DKG participants.
	BroadcastDKGPrivateShare(prvShare *typesDKG.PrivateShare)

	// BroadcastDKGPartialSignature broadcasts partialSignature to all
	// DKG participants.
	BroadcastDKGPartialSignature(psig *typesDKG.PartialSignature)

	// ReceiveChan returns a channel to receive messages from DEXON network.
	ReceiveChan() <-chan types.Msg

	// ReportBadPeerChan returns a channel to report bad peer.
	ReportBadPeerChan() chan<- interface{}
}

Network describs the network interface that interacts with DEXON consensus core.

type NodeSetCache

type NodeSetCache = utils.NodeSetCache

NodeSetCache is type alias to avoid fullnode compile error when moving it to core/utils package.

type Recovery

type Recovery interface {
	// ProposeSkipBlock proposes a skip block.
	ProposeSkipBlock(height uint64) error

	// Votes gets the number of votes of given height.
	Votes(height uint64) (uint64, error)
}

Recovery interface for interacting with recovery information.

type TSigVerifier

type TSigVerifier interface {
	VerifySignature(hash common.Hash, sig crypto.Signature) bool
}

TSigVerifier is the interface verifying threshold signature.

type TSigVerifierCache

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

TSigVerifierCache is the cache for TSigVerifier.

func NewTSigVerifierCache

func NewTSigVerifierCache(
	intf TSigVerifierCacheInterface, cacheSize int) *TSigVerifierCache

NewTSigVerifierCache creats a TSigVerifierCache instance.

func (*TSigVerifierCache) Delete

func (tc *TSigVerifierCache) Delete(round uint64)

Delete the cache of given round.

func (*TSigVerifierCache) Get

func (tc *TSigVerifierCache) Get(round uint64) (TSigVerifier, bool)

Get the TSigVerifier of round and returns if it exists.

func (*TSigVerifierCache) Purge

func (tc *TSigVerifierCache) Purge(round uint64)

Purge the cache.

func (*TSigVerifierCache) Update

func (tc *TSigVerifierCache) Update(round uint64) (bool, error)

Update the cache and returns if success.

func (*TSigVerifierCache) UpdateAndGet

func (tc *TSigVerifierCache) UpdateAndGet(round uint64) (
	TSigVerifier, bool, error)

UpdateAndGet calls Update and then Get.

type TSigVerifierCacheInterface

type TSigVerifierCacheInterface interface {
	// Configuration returns the configuration at a given round.
	// Return the genesis configuration if round == 0.
	Configuration(round uint64) *types.Config

	// DKGComplaints gets all the DKGComplaints of round.
	DKGComplaints(round uint64) []*typesDKG.Complaint

	// DKGMasterPublicKeys gets all the DKGMasterPublicKey of round.
	DKGMasterPublicKeys(round uint64) []*typesDKG.MasterPublicKey

	// IsDKGFinal checks if DKG is final.
	IsDKGFinal(round uint64) bool
}

TSigVerifierCacheInterface specifies interface used by TSigVerifierCache.

type Ticker

type Ticker interface {
	// Tick would return a channel, which would be triggered until next tick.
	Tick() <-chan time.Time

	// Stop the ticker.
	Stop()

	// Retart the ticker and clear all internal data.
	Restart()
}

Ticker define the capability to tick by interval.

type TickerType

type TickerType int

TickerType is the type of ticker.

const (
	TickerBA TickerType = iota
	TickerDKG
	TickerCRS
)

TickerType enum.

Directories

Path Synopsis
dkg
dkg

Jump to

Keyboard shortcuts

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