/
consensus_helper.go
66 lines (51 loc) · 2.11 KB
/
consensus_helper.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
// Copyright (C) 2018 ZVChain
//
// This program is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// This program is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with this program. If not, see <https://www.gnu.org/licenses/>.
package types
import (
"github.com/zvchain/zvchain/common"
"math/big"
)
// GenesisInfo define genesis group info
type GenesisInfo struct {
Group GroupI
VrfPKs [][]byte
Pks [][]byte
}
// ConsensusHelper are consensus interface collection
type ConsensusHelper interface {
// generate genesis group and pk info of members
GenerateGenesisInfo() *GenesisInfo
// convert the vrf prove to big int
VRFProve2Value(prove []byte) *big.Int
// calculate the blockheader's qn
// it needs to be equal to the blockheader's totalQN - preHeader's totalQN
CalculateQN(bh *BlockHeader) uint64
// check the prove root hash for weight node when add block on chain
CheckProveRoot(bh *BlockHeader) (bool, error)
// check the new block
// mainly verify the cast legality and the group signature
VerifyNewBlock(bh *BlockHeader, preBH *BlockHeader) (bool, error)
// verify the blockheader: mainly verify the group signature
VerifyBlockSign(bh *BlockHeader) (bool, error)
// verify reward transaction
VerifyRewardTransaction(tx *Transaction) (bool, error)
// estimate pre block's height
EstimatePreHeight(bh *BlockHeader) uint64
// VerifyBlockHeaders checks if the group is legal and the group signature is correct
VerifyBlockHeaders(pre, bh *BlockHeader) (ok bool, err error)
GroupSkipCountsBetween(preBH *BlockHeader, h uint64) map[common.Hash]uint16
// return the min elapsed second for blocks
GetBlockMinElapse(height uint64) int32
}