utils

package
v0.0.0-...-02f1fe4 Latest Latest
Warning

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

Go to latest
Published: Sep 18, 2019 License: LGPL-3.0 Imports: 10 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	// ErrNodeSetNotReady means we got nil empty node set.
	ErrNodeSetNotReady = errors.New("node set is not ready")
	// ErrCRSNotReady means we got empty CRS.
	ErrCRSNotReady = errors.New("crs is not ready")
	// ErrConfigurationNotReady means we go nil configuration.
	ErrConfigurationNotReady = errors.New("configuration is not ready")
)
View Source
var (
	// ErrInvalidDKGMasterPublicKey means the DKG MasterPublicKey is invalid.
	ErrInvalidDKGMasterPublicKey = errors.New("invalid DKG master public key")
	// ErrPayloadNotEmpty means the payload of block is not empty.
	ErrPayloadNotEmpty = errors.New("payload not empty")
)
View Source
var (
	ErrInvalidProposerID  = errors.New("invalid proposer id")
	ErrIncorrectHash      = errors.New("hash of block is incorrect")
	ErrIncorrectSignature = errors.New("signature of block is incorrect")
	ErrNoBLSSigner        = errors.New("bls signer not set")
)

Errors for signer.

Functions

func GetBAThreshold

func GetBAThreshold(config *types.Config) int

GetBAThreshold return threshold for BA votes.

func GetCRSWithPanic

func GetCRSWithPanic(accessor crsAccessor, round uint64,
	logger common.Logger) common.Hash

GetCRSWithPanic is a helper to access CRS, and panic when CRS for that round is not ready yet.

func GetConfigWithPanic

func GetConfigWithPanic(accessor configAccessor, round uint64,
	logger common.Logger) *types.Config

GetConfigWithPanic is a helper to access configs, and panic when config for that round is not ready yet.

func GetDKGNackThreshold

func GetDKGNackThreshold(config *types.Config) int

GetDKGNackThreshold return expected threshold for given nacking DKG set.

func GetDKGThreshold

func GetDKGThreshold(config *types.Config) int

GetDKGThreshold return expected threshold for given DKG set size.

func GetDKGValidThreshold

func GetDKGValidThreshold(config *types.Config) int

GetDKGValidThreshold return threshold for DKG set to considered valid.

func GetNextRoundValidationHeight

func GetNextRoundValidationHeight(begin, length uint64) uint64

GetNextRoundValidationHeight returns the block height to check if the next round is ready.

func GetRoundHeight

func GetRoundHeight(accessor interface{}, round uint64) uint64

GetRoundHeight wraps the workaround for the round height logic in fullnode.

func HashBlock

func HashBlock(block *types.Block) (common.Hash, error)

HashBlock generates hash of a types.Block.

func HashPosition

func HashPosition(position types.Position) common.Hash

HashPosition generates hash of a types.Position.

func HashVote

func HashVote(vote *types.Vote) common.Hash

HashVote generates hash of a types.Vote.

func IsDKGValid

func IsDKGValid(
	gov governanceAccessor, logger common.Logger, round, reset uint64) (
	valid bool, gpkInvalid bool)

IsDKGValid check if DKG is correctly prepared.

func LaunchDummyReceiver

func LaunchDummyReceiver(
	ctx context.Context, recv <-chan types.Msg, handler func(types.Msg)) (
	context.CancelFunc, <-chan struct{})

LaunchDummyReceiver launches a go routine to receive from the receive channel of a network module. An context is required to stop the go routine automatically. An optinal message handler could be provided.

func NeedPenaltyDKGPrivateShare

func NeedPenaltyDKGPrivateShare(
	complaint *typesDKG.Complaint, mpk *typesDKG.MasterPublicKey) (bool, error)

NeedPenaltyDKGPrivateShare checks if the proposer of dkg private share should be penalized.

func NeedPenaltyForkBlock

func NeedPenaltyForkBlock(block1, block2 *types.Block) (bool, error)

NeedPenaltyForkBlock checks if two blocks are fork block.

func NeedPenaltyForkVote

func NeedPenaltyForkVote(vote1, vote2 *types.Vote) (bool, error)

NeedPenaltyForkVote checks if two votes are fork vote.

func Rehash

func Rehash(hash common.Hash, count uint) common.Hash

Rehash hashes the hash again and again and again...

func RoundEventRetryHandlerGenerator

func RoundEventRetryHandlerGenerator(
	rEvt *RoundEvent, hEvt *common.Event) func(uint64)

RoundEventRetryHandlerGenerator generates a handler to common.Event, which would register itself to retry next round validation if round event is not triggered.

func SetDKGDelayRound

func SetDKGDelayRound(delay uint64)

SetDKGDelayRound sets the variable.

func VerifyBlockSignature

func VerifyBlockSignature(b *types.Block) (err error)

VerifyBlockSignature verifies the signature of types.Block.

func VerifyBlockSignatureWithoutPayload

func VerifyBlockSignatureWithoutPayload(b *types.Block) (err error)

VerifyBlockSignatureWithoutPayload verifies the signature of types.Block but does not check if PayloadHash is correct.

func VerifyCRSSignature

func VerifyCRSSignature(
	block *types.Block, crs common.Hash, npks *typesDKG.NodePublicKeys) bool

VerifyCRSSignature verifies the CRS signature of types.Block.

func VerifyDKGComplaint

func VerifyDKGComplaint(
	complaint *typesDKG.Complaint, mpk *typesDKG.MasterPublicKey) (bool, error)

VerifyDKGComplaint verifies if its a valid DKGCompliant.

func VerifyDKGComplaintSignature

func VerifyDKGComplaintSignature(
	complaint *typesDKG.Complaint) (bool, error)

VerifyDKGComplaintSignature verifies DKGCompliant signature.

func VerifyDKGFinalizeSignature

func VerifyDKGFinalizeSignature(
	final *typesDKG.Finalize) (bool, error)

VerifyDKGFinalizeSignature verifies DKGFinalize signature.

func VerifyDKGMPKReadySignature

func VerifyDKGMPKReadySignature(
	ready *typesDKG.MPKReady) (bool, error)

VerifyDKGMPKReadySignature verifies DKGMPKReady signature.

func VerifyDKGMasterPublicKeySignature

func VerifyDKGMasterPublicKeySignature(
	mpk *typesDKG.MasterPublicKey) (bool, error)

VerifyDKGMasterPublicKeySignature verifies DKGMasterPublicKey signature.

func VerifyDKGPartialSignatureSignature

func VerifyDKGPartialSignatureSignature(
	psig *typesDKG.PartialSignature) (bool, error)

VerifyDKGPartialSignatureSignature verifies the signature of typesDKG.PartialSignature.

func VerifyDKGPrivateShareSignature

func VerifyDKGPrivateShareSignature(
	prvShare *typesDKG.PrivateShare) (bool, error)

VerifyDKGPrivateShareSignature verifies the signature of typesDKG.PrivateShare.

func VerifyDKGSuccessSignature

func VerifyDKGSuccessSignature(
	success *typesDKG.Success) (bool, error)

VerifyDKGSuccessSignature verifies DKGSuccess signature.

func VerifyVoteSignature

func VerifyVoteSignature(vote *types.Vote) (bool, error)

VerifyVoteSignature verifies the signature of types.Vote.

Types

type ErrUnmatchedBlockHeightWithConfig

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

ErrUnmatchedBlockHeightWithConfig is for invalid parameters for NewRoundEvent.

func (ErrUnmatchedBlockHeightWithConfig) Error

type NodeSetCache

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

NodeSetCache caches node set information.

NOTE: this module doesn't handle DKG resetting and can only be used along

with utils.RoundEvent.

func NewNodeSetCache

func NewNodeSetCache(nsIntf NodeSetCacheInterface) *NodeSetCache

NewNodeSetCache constructs an NodeSetCache instance.

func (*NodeSetCache) Exists

func (cache *NodeSetCache) Exists(
	round uint64, nodeID types.NodeID) (exists bool, err error)

Exists checks if a node is in node set of that round.

func (*NodeSetCache) GetNodeSet

func (cache *NodeSetCache) GetNodeSet(round uint64) (*types.NodeSet, error)

GetNodeSet returns IDs of nodes set of this round as map.

func (*NodeSetCache) GetNotarySet

func (cache *NodeSetCache) GetNotarySet(
	round uint64) (map[types.NodeID]struct{}, error)

GetNotarySet returns of notary set of this round.

func (*NodeSetCache) GetPublicKey

func (cache *NodeSetCache) GetPublicKey(
	nodeID types.NodeID) (key crypto.PublicKey, exists bool)

GetPublicKey return public key for that node:

func (*NodeSetCache) Purge

func (cache *NodeSetCache) Purge(rID uint64)

Purge a specific round.

func (*NodeSetCache) Touch

func (cache *NodeSetCache) Touch(round uint64) (err error)

Touch updates the internal cache of round.

type NodeSetCacheInterface

type NodeSetCacheInterface 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.
	CRS(round uint64) common.Hash

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

NodeSetCacheInterface interface specifies interface used by NodeSetCache.

type RoundBasedConfig

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

RoundBasedConfig is based config for rounds and provide boundary checking for rounds.

func (*RoundBasedConfig) AppendTo

func (c *RoundBasedConfig) AppendTo(other RoundBasedConfig)

AppendTo a config from previous round.

func (*RoundBasedConfig) Contains

func (c *RoundBasedConfig) Contains(h uint64) bool

Contains checks if a block height is in this round.

func (*RoundBasedConfig) ExtendLength

func (c *RoundBasedConfig) ExtendLength()

ExtendLength extends round ending height by the length of current round.

func (*RoundBasedConfig) IsLastBlock

func (c *RoundBasedConfig) IsLastBlock(b *types.Block) bool

IsLastBlock checks if a block is the last block of this round.

func (*RoundBasedConfig) LastPeriodBeginHeight

func (c *RoundBasedConfig) LastPeriodBeginHeight() uint64

LastPeriodBeginHeight returns the begin height of last period. For example, if a round is extended twice, then the return from this method is:

begin + 2 * roundLength - roundLength

func (*RoundBasedConfig) RoundEndHeight

func (c *RoundBasedConfig) RoundEndHeight() uint64

RoundEndHeight returns next checkpoint to varify if this round is ended.

func (*RoundBasedConfig) RoundID

func (c *RoundBasedConfig) RoundID() uint64

RoundID returns the round ID of this config.

func (*RoundBasedConfig) SetRoundBeginHeight

func (c *RoundBasedConfig) SetRoundBeginHeight(begin uint64)

SetRoundBeginHeight gives the beginning height for the initial round provided when constructed.

func (*RoundBasedConfig) SetupRoundBasedFields

func (c *RoundBasedConfig) SetupRoundBasedFields(
	roundID uint64, cfg *types.Config)

SetupRoundBasedFields setup round based fields, including round ID, the length of rounds.

type RoundEvent

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

RoundEvent would be triggered when either:

  • the next DKG set setup is ready.
  • the next DKG set setup is failed, and previous DKG set already reset the CRS.

func NewRoundEvent

func NewRoundEvent(parentCtx context.Context, gov governanceAccessor,
	logger common.Logger, initPos types.Position, roundShift uint64) (
	*RoundEvent, error)

NewRoundEvent creates an RoundEvent instance.

func (*RoundEvent) LastPeriod

func (e *RoundEvent) LastPeriod() (begin uint64, length uint64)

LastPeriod returns block height related info of the last period, including begin height and round length.

func (*RoundEvent) Register

func (e *RoundEvent) Register(h roundEventFn)

Register a handler to be called when new round is confirmed or new DKG reset is detected.

The earlier registered handler has higher priority.

func (*RoundEvent) Stop

func (e *RoundEvent) Stop()

Stop the event source and block until last trigger returns.

func (*RoundEvent) TriggerInitEvent

func (e *RoundEvent) TriggerInitEvent()

TriggerInitEvent triggers event from the initial setting.

func (*RoundEvent) ValidateNextRound

func (e *RoundEvent) ValidateNextRound(blockHeight uint64) (count uint)

ValidateNextRound validate if the DKG set for next round is ready to go or failed to setup, all registered handlers would be called once some decision is made on chain.

The count of triggered events would be returned.

type RoundEventParam

type RoundEventParam struct {
	// 'Round' of next checkpoint, might be identical to previous checkpoint.
	Round uint64
	// the count of reset DKG for 'Round+1'.
	Reset uint64
	// the begin block height of this event, the end block height of this event
	// would be BeginHeight + config.RoundLength.
	BeginHeight uint64
	// The configuration for 'Round'.
	Config *types.Config
	// The CRS for 'Round'.
	CRS common.Hash
}

RoundEventParam defines the parameters passed to event handlers of RoundEvent.

func (RoundEventParam) NextCRSProposingHeight

func (e RoundEventParam) NextCRSProposingHeight() uint64

NextCRSProposingHeight returns the height to propose CRS for next round.

func (RoundEventParam) NextDKGPreparationHeight

func (e RoundEventParam) NextDKGPreparationHeight() uint64

NextDKGPreparationHeight returns the height to prepare DKG set for next round.

func (RoundEventParam) NextDKGRegisterHeight

func (e RoundEventParam) NextDKGRegisterHeight() uint64

NextDKGRegisterHeight returns the height to register DKG.

func (RoundEventParam) NextDKGResetHeight

func (e RoundEventParam) NextDKGResetHeight() uint64

NextDKGResetHeight returns the height to reset DKG for next period.

func (RoundEventParam) NextRoundHeight

func (e RoundEventParam) NextRoundHeight() uint64

NextRoundHeight returns the height of the beginning of next round.

func (RoundEventParam) NextRoundValidationHeight

func (e RoundEventParam) NextRoundValidationHeight() uint64

NextRoundValidationHeight returns the height to check if the next round is ready.

func (RoundEventParam) NextTouchNodeSetCacheHeight

func (e RoundEventParam) NextTouchNodeSetCacheHeight() uint64

NextTouchNodeSetCacheHeight returns the height to touch the node set cache.

func (RoundEventParam) RoundEndHeight

func (e RoundEventParam) RoundEndHeight() uint64

RoundEndHeight returns the round ending height of this round event.

func (RoundEventParam) String

func (e RoundEventParam) String() string

type Signer

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

Signer signs a segment of data.

func NewSigner

func NewSigner(prvKey crypto.PrivateKey) (s *Signer)

NewSigner constructs an Signer instance.

func (*Signer) SetBLSSigner

func (s *Signer) SetBLSSigner(signer blsSigner)

SetBLSSigner for signing CRSSignature

func (*Signer) SignBlock

func (s *Signer) SignBlock(b *types.Block) (err error)

SignBlock signs a types.Block.

func (*Signer) SignCRS

func (s *Signer) SignCRS(b *types.Block, crs common.Hash) (err error)

SignCRS signs CRS signature of types.Block.

func (*Signer) SignDKGComplaint

func (s *Signer) SignDKGComplaint(complaint *typesDKG.Complaint) (err error)

SignDKGComplaint signs a DKG complaint.

func (*Signer) SignDKGFinalize

func (s *Signer) SignDKGFinalize(final *typesDKG.Finalize) (err error)

SignDKGFinalize signs a DKG finalize message.

func (*Signer) SignDKGMPKReady

func (s *Signer) SignDKGMPKReady(ready *typesDKG.MPKReady) (err error)

SignDKGMPKReady signs a DKG ready message.

func (*Signer) SignDKGMasterPublicKey

func (s *Signer) SignDKGMasterPublicKey(
	mpk *typesDKG.MasterPublicKey) (err error)

SignDKGMasterPublicKey signs a DKG master public key.

func (*Signer) SignDKGPartialSignature

func (s *Signer) SignDKGPartialSignature(
	pSig *typesDKG.PartialSignature) (err error)

SignDKGPartialSignature signs a DKG partial signature.

func (*Signer) SignDKGPrivateShare

func (s *Signer) SignDKGPrivateShare(
	prvShare *typesDKG.PrivateShare) (err error)

SignDKGPrivateShare signs a DKG private share.

func (*Signer) SignDKGSuccess

func (s *Signer) SignDKGSuccess(success *typesDKG.Success) (err error)

SignDKGSuccess signs a DKG success message.

func (*Signer) SignVote

func (s *Signer) SignVote(v *types.Vote) (err error)

SignVote signs a types.Vote.

type VoteFilter

type VoteFilter struct {
	Voted    map[types.VoteHeader]struct{}
	Position types.Position
	LockIter uint64
	Period   uint64
	Confirm  bool
}

VoteFilter filters votes that are useless for now. To maximize performance, this structure is not thread-safe and will never be.

func NewVoteFilter

func NewVoteFilter() *VoteFilter

NewVoteFilter creates a new vote filter instance.

func (*VoteFilter) AddVote

func (vf *VoteFilter) AddVote(vote *types.Vote)

AddVote to the filter so the same vote will be filtered.

func (*VoteFilter) Filter

func (vf *VoteFilter) Filter(vote *types.Vote) bool

Filter checks if the vote should be filtered out.

Jump to

Keyboard shortcuts

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