diff options
author | Mission Liao <mission.liao@dexon.org> | 2018-12-25 10:06:35 +0800 |
---|---|---|
committer | Wei-Ning Huang <w@dexon.org> | 2019-04-09 21:32:55 +0800 |
commit | 6aee32cd8c3d7f0c7d99bf1fe4951fdf6c534be9 (patch) | |
tree | a8020f5aace2a3f3ac3de3bcbe98bdc8226245a6 /vendor/github.com/dexon-foundation/dexon-consensus/core/utils.go | |
parent | b39d0be8e1fd2e870fafd2c23e7d5cb220696a60 (diff) | |
download | dexon-6aee32cd8c3d7f0c7d99bf1fe4951fdf6c534be9.tar dexon-6aee32cd8c3d7f0c7d99bf1fe4951fdf6c534be9.tar.gz dexon-6aee32cd8c3d7f0c7d99bf1fe4951fdf6c534be9.tar.bz2 dexon-6aee32cd8c3d7f0c7d99bf1fe4951fdf6c534be9.tar.lz dexon-6aee32cd8c3d7f0c7d99bf1fe4951fdf6c534be9.tar.xz dexon-6aee32cd8c3d7f0c7d99bf1fe4951fdf6c534be9.tar.zst dexon-6aee32cd8c3d7f0c7d99bf1fe4951fdf6c534be9.zip |
vendor: sync DEXON core and fix conflicts/missings (#101)
Merging these commits in DEXON consensus core:
- https://github.com/dexon-foundation/dexon-consensus/commit/dce509a13ef5873b9cae3c1cabdb97e219b6fb7d
- https://github.com/dexon-foundation/dexon-consensus/commit/6d1c1aeea0d3e75d10cbb2712c68b4c422ba8ba6
- https://github.com/dexon-foundation/dexon-consensus/commit/c1ed57c4abaf1f4758e52f082bb7114ad00c8b39
Diffstat (limited to 'vendor/github.com/dexon-foundation/dexon-consensus/core/utils.go')
-rw-r--r-- | vendor/github.com/dexon-foundation/dexon-consensus/core/utils.go | 43 |
1 files changed, 21 insertions, 22 deletions
diff --git a/vendor/github.com/dexon-foundation/dexon-consensus/core/utils.go b/vendor/github.com/dexon-foundation/dexon-consensus/core/utils.go index 671d68018..0c2d15588 100644 --- a/vendor/github.com/dexon-foundation/dexon-consensus/core/utils.go +++ b/vendor/github.com/dexon-foundation/dexon-consensus/core/utils.go @@ -18,6 +18,7 @@ package core import ( + "context" "errors" "fmt" "math/rand" @@ -146,27 +147,6 @@ func HashConfigurationBlock( ) } -// VerifyBlock verifies the signature of types.Block. -func VerifyBlock(b *types.Block) (err error) { - hash, err := hashBlock(b) - if err != nil { - return - } - if hash != b.Hash { - err = ErrIncorrectHash - return - } - pubKey, err := crypto.SigToPub(b.Hash, b.Signature) - if err != nil { - return - } - if !b.ProposerID.Equal(types.NewNodeID(pubKey)) { - err = ErrIncorrectSignature - return - } - return -} - // VerifyAgreementResult perform sanity check against a types.AgreementResult // instance. func VerifyAgreementResult( @@ -201,7 +181,7 @@ func VerifyAgreementResult( if _, exist := notarySet[vote.ProposerID]; !exist { return ErrIncorrectVoteProposer } - ok, err := verifyVoteSignature(&vote) + ok, err := utils.VerifyVoteSignature(&vote) if err != nil { return err } @@ -235,3 +215,22 @@ func isTravisCI() bool { func getDKGThreshold(config *types.Config) int { return int(config.DKGSetSize/3) + 1 } + +// checkWithCancel is a helper to perform periodic checking with cancel. +func checkWithCancel(parentCtx context.Context, interval time.Duration, + checker func() bool) (ret bool) { + ctx, cancel := context.WithCancel(parentCtx) + defer cancel() +Loop: + for { + select { + case <-ctx.Done(): + break Loop + case <-time.After(interval): + } + if ret = checker(); ret { + return + } + } + return +} |