aboutsummaryrefslogtreecommitdiffstats
path: root/vendor/github.com/dexon-foundation/dexon-consensus/core/utils.go
diff options
context:
space:
mode:
authorMission Liao <mission.liao@dexon.org>2018-12-25 10:06:35 +0800
committerWei-Ning Huang <w@byzantine-lab.io>2019-06-12 17:27:20 +0800
commit9437d34cb57503309b25ea92808705da1d78ac44 (patch)
treecd29048f0829b03f956832e270ac1aec5ce7d96a /vendor/github.com/dexon-foundation/dexon-consensus/core/utils.go
parent5e165d3cd5393492321dc598f6e595be4c4d21e4 (diff)
downloadgo-tangerine-9437d34cb57503309b25ea92808705da1d78ac44.tar
go-tangerine-9437d34cb57503309b25ea92808705da1d78ac44.tar.gz
go-tangerine-9437d34cb57503309b25ea92808705da1d78ac44.tar.bz2
go-tangerine-9437d34cb57503309b25ea92808705da1d78ac44.tar.lz
go-tangerine-9437d34cb57503309b25ea92808705da1d78ac44.tar.xz
go-tangerine-9437d34cb57503309b25ea92808705da1d78ac44.tar.zst
go-tangerine-9437d34cb57503309b25ea92808705da1d78ac44.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.go43
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
+}