diff options
author | haoping-ku <haoping.ku@dexon.org> | 2018-11-29 14:30:02 +0800 |
---|---|---|
committer | GitHub <noreply@github.com> | 2018-11-29 14:30:02 +0800 |
commit | daf3bab93c323b173345811adc9a334dad4a7094 (patch) | |
tree | 8a3957ec1f77262ce92c56f0384b0dedc307628c /core/utils.go | |
parent | 8470ac070f097b261fddc42991a4d2e9ec998db6 (diff) | |
download | dexon-consensus-daf3bab93c323b173345811adc9a334dad4a7094.tar dexon-consensus-daf3bab93c323b173345811adc9a334dad4a7094.tar.gz dexon-consensus-daf3bab93c323b173345811adc9a334dad4a7094.tar.bz2 dexon-consensus-daf3bab93c323b173345811adc9a334dad4a7094.tar.lz dexon-consensus-daf3bab93c323b173345811adc9a334dad4a7094.tar.xz dexon-consensus-daf3bab93c323b173345811adc9a334dad4a7094.tar.zst dexon-consensus-daf3bab93c323b173345811adc9a334dad4a7094.zip |
core: syncer: add syncer (#346)
Diffstat (limited to 'core/utils.go')
-rw-r--r-- | core/utils.go | 45 |
1 files changed, 45 insertions, 0 deletions
diff --git a/core/utils.go b/core/utils.go index 441aac1..bc5e336 100644 --- a/core/utils.go +++ b/core/utils.go @@ -167,6 +167,51 @@ func VerifyBlock(b *types.Block) (err error) { return } +// VerifyAgreementResult perform sanity check against a types.AgreementResult +// instance. +func VerifyAgreementResult( + res *types.AgreementResult, cache *utils.NodeSetCache) error { + notarySet, err := cache.GetNotarySet( + res.Position.Round, res.Position.ChainID) + if err != nil { + return err + } + if len(res.Votes) < len(notarySet)/3*2+1 { + return ErrNotEnoughVotes + } + if len(res.Votes) > len(notarySet) { + return ErrIncorrectVoteProposer + } + for _, vote := range res.Votes { + if res.IsEmptyBlock { + if (vote.BlockHash != common.Hash{}) { + return ErrIncorrectVoteBlockHash + } + } else { + if vote.BlockHash != res.BlockHash { + return ErrIncorrectVoteBlockHash + } + } + if vote.Type != types.VoteCom { + return ErrIncorrectVoteType + } + if vote.Position != res.Position { + return ErrIncorrectVotePosition + } + if _, exist := notarySet[vote.ProposerID]; !exist { + return ErrIncorrectVoteProposer + } + ok, err := verifyVoteSignature(&vote) + if err != nil { + return err + } + if !ok { + return ErrIncorrectVoteSignature + } + } + return nil +} + // DiffUint64 calculates difference between two uint64. func DiffUint64(a, b uint64) uint64 { if a > b { |