-
Notifications
You must be signed in to change notification settings - Fork 146
/
validator.go
634 lines (538 loc) · 19.3 KB
/
validator.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
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
// Copyright 2018-2019 The PlatON Network Authors
// This file is part of the PlatON-Go library.
//
// The PlatON-Go library is free software: you can redistribute it and/or modify
// it under the terms of the GNU Lesser General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// The PlatON-Go library 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 Lesser General Public License for more details.
//
// You should have received a copy of the GNU Lesser General Public License
// along with the PlatON-Go library. If not, see <http://www.gnu.org/licenses/>.
package validator
import (
"encoding/hex"
"errors"
"fmt"
"sync"
"github.com/PlatONnetwork/PlatON-Go/core/state"
"github.com/PlatONnetwork/PlatON-Go/consensus/cbft/utils"
"github.com/PlatONnetwork/PlatON-Go/common"
cvm "github.com/PlatONnetwork/PlatON-Go/common/vm"
"github.com/PlatONnetwork/PlatON-Go/consensus"
"github.com/PlatONnetwork/PlatON-Go/core"
"github.com/PlatONnetwork/PlatON-Go/core/cbfttypes"
"github.com/PlatONnetwork/PlatON-Go/core/types"
"github.com/PlatONnetwork/PlatON-Go/core/vm"
"github.com/PlatONnetwork/PlatON-Go/crypto"
"github.com/PlatONnetwork/PlatON-Go/crypto/bls"
"github.com/PlatONnetwork/PlatON-Go/event"
"github.com/PlatONnetwork/PlatON-Go/log"
"github.com/PlatONnetwork/PlatON-Go/p2p/discover"
"github.com/PlatONnetwork/PlatON-Go/params"
"github.com/PlatONnetwork/PlatON-Go/rlp"
)
func newValidators(nodes []params.CbftNode, validBlockNumber uint64) *cbfttypes.Validators {
vds := &cbfttypes.Validators{
Nodes: make(cbfttypes.ValidateNodeMap, len(nodes)),
ValidBlockNumber: validBlockNumber,
}
for i, node := range nodes {
pubkey, err := node.Node.ID.Pubkey()
if err != nil {
panic(err)
}
blsPubKey := node.BlsPubKey
vds.Nodes[node.Node.ID] = &cbfttypes.ValidateNode{
Index: uint32(i),
Address: crypto.PubkeyToAddress(*pubkey),
PubKey: pubkey,
NodeID: node.Node.ID,
BlsPubKey: &blsPubKey,
}
}
return vds
}
type StaticAgency struct {
consensus.Agency
validators *cbfttypes.Validators
}
func NewStaticAgency(nodes []params.CbftNode) consensus.Agency {
return &StaticAgency{
validators: newValidators(nodes, 0),
}
}
func (d *StaticAgency) Flush(header *types.Header) error {
return nil
}
func (d *StaticAgency) Sign(interface{}) error {
return nil
}
func (d *StaticAgency) VerifySign(interface{}) error {
return nil
}
func (d *StaticAgency) VerifyHeader(header *types.Header, statedb *state.StateDB) error {
return nil
}
func (d *StaticAgency) GetLastNumber(blockNumber uint64) uint64 {
return 0
}
func (d *StaticAgency) GetValidator(uint64) (*cbfttypes.Validators, error) {
return d.validators, nil
}
func (d *StaticAgency) IsCandidateNode(nodeID discover.NodeID) bool {
return false
}
func (d *StaticAgency) OnCommit(block *types.Block) error {
return nil
}
type InnerAgency struct {
consensus.Agency
blocksPerNode uint64
defaultBlocksPerRound uint64
offset uint64
blockchain *core.BlockChain
defaultValidators *cbfttypes.Validators
}
func NewInnerAgency(nodes []params.CbftNode, chain *core.BlockChain, blocksPerNode, offset int) consensus.Agency {
return &InnerAgency{
blocksPerNode: uint64(blocksPerNode),
defaultBlocksPerRound: uint64(len(nodes) * blocksPerNode),
offset: uint64(offset),
blockchain: chain,
defaultValidators: newValidators(nodes, 1),
}
}
func (ia *InnerAgency) Flush(header *types.Header) error {
return nil
}
func (ia *InnerAgency) Sign(interface{}) error {
return nil
}
func (ia *InnerAgency) VerifySign(interface{}) error {
return nil
}
func (ia *InnerAgency) VerifyHeader(header *types.Header, stateDB *state.StateDB) error {
return nil
}
func (ia *InnerAgency) GetLastNumber(blockNumber uint64) uint64 {
var lastBlockNumber uint64
if blockNumber <= ia.defaultBlocksPerRound {
lastBlockNumber = ia.defaultBlocksPerRound
} else {
vds, err := ia.GetValidator(blockNumber)
if err != nil {
log.Error("Get validator fail", "blockNumber", blockNumber)
return 0
}
if vds.ValidBlockNumber == 0 && blockNumber%ia.defaultBlocksPerRound == 0 {
return blockNumber
}
// lastNumber = vds.ValidBlockNumber + ia.blocksPerNode * vds.Len() - 1
lastBlockNumber = vds.ValidBlockNumber + ia.blocksPerNode*uint64(vds.Len()) - 1
// May be `CurrentValidators ` had not updated, so we need to calcuate `lastBlockNumber`
// via `blockNumber`.
if lastBlockNumber < blockNumber {
blocksPerRound := ia.blocksPerNode * uint64(vds.Len())
if blockNumber%blocksPerRound == 0 {
lastBlockNumber = blockNumber
} else {
baseNum := blockNumber - (blockNumber % blocksPerRound)
lastBlockNumber = baseNum + blocksPerRound
}
}
}
//log.Debug("Get last block number", "blockNumber", blockNumber, "lastBlockNumber", lastBlockNumber)
return lastBlockNumber
}
func (ia *InnerAgency) GetValidator(blockNumber uint64) (v *cbfttypes.Validators, err error) {
defaultValidators := *ia.defaultValidators
baseNumber := blockNumber
if blockNumber == 0 {
baseNumber = 1
}
defaultValidators.ValidBlockNumber = ((baseNumber-1)/ia.defaultBlocksPerRound)*ia.defaultBlocksPerRound + 1
if blockNumber <= ia.defaultBlocksPerRound {
return &defaultValidators, nil
}
// Otherwise, get validators from inner contract.
vdsCftNum := blockNumber - ia.offset - 1
block := ia.blockchain.GetBlockByNumber(vdsCftNum)
if block == nil {
log.Error("Get the block fail, use default validators", "number", vdsCftNum)
return &defaultValidators, nil
}
state, err := ia.blockchain.StateAt(block.Root())
if err != nil {
log.Error("Get the state fail, use default validators", "number", block.Number(), "hash", block.Hash(), "error", err)
return &defaultValidators, nil
}
b := state.GetState(cvm.ValidatorInnerContractAddr, []byte(vm.CurrentValidatorKey))
if len(b) == 0 {
return &defaultValidators, nil
}
var vds vm.Validators
err = rlp.DecodeBytes(b, &vds)
if err != nil {
log.Error("RLP decode fail, use default validators", "number", block.Number(), "error", err)
return &defaultValidators, nil
}
var validators cbfttypes.Validators
validators.Nodes = make(cbfttypes.ValidateNodeMap, len(vds.ValidateNodes))
for _, node := range vds.ValidateNodes {
pubkey, _ := node.NodeID.Pubkey()
blsPubKey := node.BlsPubKey
validators.Nodes[node.NodeID] = &cbfttypes.ValidateNode{
Index: uint32(node.Index),
Address: node.Address,
PubKey: pubkey,
NodeID: node.NodeID,
BlsPubKey: &blsPubKey,
}
}
validators.ValidBlockNumber = vds.ValidBlockNumber
return &validators, nil
}
func (ia *InnerAgency) IsCandidateNode(nodeID discover.NodeID) bool {
return true
}
func (ia *InnerAgency) OnCommit(block *types.Block) error {
return nil
}
// ValidatorPool a pool storing validators.
type ValidatorPool struct {
agency consensus.Agency
lock sync.RWMutex
// Current node's public key
nodeID discover.NodeID
// A block number which validators switch point.
switchPoint uint64
lastNumber uint64
epoch uint64
prevValidators *cbfttypes.Validators // Previous validators
currentValidators *cbfttypes.Validators // Current validators
}
// NewValidatorPool new a validator pool.
func NewValidatorPool(agency consensus.Agency, blockNumber uint64, epoch uint64, nodeID discover.NodeID) *ValidatorPool {
pool := &ValidatorPool{
agency: agency,
nodeID: nodeID,
epoch: epoch,
}
// FIXME: Check `GetValidator` return error
if agency.GetLastNumber(blockNumber) == blockNumber {
pool.prevValidators, _ = agency.GetValidator(blockNumber)
pool.currentValidators, _ = agency.GetValidator(NextRound(blockNumber))
pool.lastNumber = agency.GetLastNumber(NextRound(blockNumber))
pool.epoch += 1
} else {
pool.currentValidators, _ = agency.GetValidator(blockNumber)
pool.prevValidators = pool.currentValidators
pool.lastNumber = agency.GetLastNumber(blockNumber)
}
// When validator mode is `static`, the `ValidatorBlockNumber` always 0,
// means we are using static validators. Otherwise, represent use current
// validators validate start from `ValidatorBlockNumber` block,
// so `ValidatorBlockNumber` - 1 is the switch point.
if pool.currentValidators.ValidBlockNumber > 0 {
pool.switchPoint = pool.currentValidators.ValidBlockNumber - 1
}
log.Debug("Update validator", "validators", pool.currentValidators.String(), "switchpoint", pool.switchPoint, "epoch", pool.epoch, "lastNumber", pool.lastNumber)
return pool
}
// Reset reset validator pool.
func (vp *ValidatorPool) Reset(blockNumber uint64, epoch uint64) {
if vp.agency.GetLastNumber(blockNumber) == blockNumber {
vp.prevValidators, _ = vp.agency.GetValidator(blockNumber)
vp.currentValidators, _ = vp.agency.GetValidator(NextRound(blockNumber))
vp.lastNumber = vp.agency.GetLastNumber(NextRound(blockNumber))
vp.epoch = epoch + 1
} else {
vp.currentValidators, _ = vp.agency.GetValidator(blockNumber)
vp.prevValidators = vp.currentValidators
vp.lastNumber = vp.agency.GetLastNumber(blockNumber)
vp.epoch = epoch
}
if vp.currentValidators.ValidBlockNumber > 0 {
vp.switchPoint = vp.currentValidators.ValidBlockNumber - 1
}
log.Debug("Update validator", "validators", vp.currentValidators.String(), "switchpoint", vp.switchPoint, "epoch", vp.epoch, "lastNumber", vp.lastNumber)
}
// ShouldSwitch check if should switch validators at the moment.
func (vp *ValidatorPool) ShouldSwitch(blockNumber uint64) bool {
if blockNumber == 0 {
return false
}
if blockNumber == vp.switchPoint {
return true
}
return blockNumber == vp.lastNumber
}
// EqualSwitchPoint returns boolean which representment the switch point
// equal the inputs number.
func (vp *ValidatorPool) EqualSwitchPoint(number uint64) bool {
return vp.switchPoint > 0 && vp.switchPoint == number
}
func (vp *ValidatorPool) EnableVerifyEpoch(epoch uint64) error {
if epoch+1 == vp.epoch || epoch == vp.epoch {
return nil
}
return fmt.Errorf("enable verify epoch:%d,%d, request:%d", vp.epoch-1, vp.epoch, epoch)
}
func (vp *ValidatorPool) MockSwitchPoint(number uint64) {
vp.switchPoint = number
}
// Update switch validators.
func (vp *ValidatorPool) Update(blockNumber uint64, epoch uint64, eventMux *event.TypeMux) error {
vp.lock.Lock()
defer vp.lock.Unlock()
// Only updated once
if blockNumber <= vp.switchPoint {
log.Debug("Already update validator before", "blockNumber", blockNumber, "switchPoint", vp.switchPoint)
return errors.New("already updated before")
}
nds, err := vp.agency.GetValidator(NextRound(blockNumber))
if err != nil {
log.Error("Get validator error", "blockNumber", blockNumber, "err", err)
return err
}
vp.prevValidators = vp.currentValidators
vp.currentValidators = nds
vp.switchPoint = nds.ValidBlockNumber - 1
vp.lastNumber = vp.agency.GetLastNumber(NextRound(blockNumber))
vp.epoch = epoch
log.Info("Update validator", "validators", nds.String(), "switchpoint", vp.switchPoint, "epoch", vp.epoch, "lastNumber", vp.lastNumber)
isValidatorBefore := vp.isValidator(epoch-1, vp.nodeID)
isValidatorAfter := vp.isValidator(epoch, vp.nodeID)
if isValidatorBefore {
// If we are still a consensus node, that adding
// new validators as consensus peer, and removing
// validators. Added as consensus peersis because
// we need to keep connect with other validators
// in the consensus stages. Also we are not needed
// to keep connect with old validators.
if isValidatorAfter {
for _, nodeID := range vp.currentValidators.NodeList() {
if node, _ := vp.prevValidators.FindNodeByID(nodeID); node == nil {
eventMux.Post(cbfttypes.AddValidatorEvent{NodeID: nodeID})
log.Trace("Post AddValidatorEvent", "nodeID", nodeID.String())
}
}
for _, nodeID := range vp.prevValidators.NodeList() {
if node, _ := vp.currentValidators.FindNodeByID(nodeID); node == nil {
eventMux.Post(cbfttypes.RemoveValidatorEvent{NodeID: nodeID})
log.Trace("Post RemoveValidatorEvent", "nodeID", nodeID.String())
}
}
} else {
for _, nodeID := range vp.prevValidators.NodeList() {
eventMux.Post(cbfttypes.RemoveValidatorEvent{NodeID: nodeID})
log.Trace("Post RemoveValidatorEvent", "nodeID", nodeID.String())
}
}
} else {
// We are become a consensus node, that adding all
// validators as consensus peer except us. Added as
// consensus peers is because we need to keep connecting
// with other validators in the consensus stages.
if isValidatorAfter {
for _, nodeID := range vp.currentValidators.NodeList() {
eventMux.Post(cbfttypes.AddValidatorEvent{NodeID: nodeID})
log.Trace("Post AddValidatorEvent", "nodeID", nodeID.String())
}
}
}
return nil
}
// GetValidatorByNodeID get the validator by node id.
func (vp *ValidatorPool) GetValidatorByNodeID(epoch uint64, nodeID discover.NodeID) (*cbfttypes.ValidateNode, error) {
vp.lock.RLock()
defer vp.lock.RUnlock()
return vp.getValidatorByNodeID(epoch, nodeID)
}
func (vp *ValidatorPool) getValidatorByNodeID(epoch uint64, nodeID discover.NodeID) (*cbfttypes.ValidateNode, error) {
if vp.epochToBlockNumber(epoch) <= vp.switchPoint {
return vp.prevValidators.FindNodeByID(nodeID)
}
return vp.currentValidators.FindNodeByID(nodeID)
}
// GetValidatorByAddr get the validator by address.
func (vp *ValidatorPool) GetValidatorByAddr(epoch uint64, addr common.Address) (*cbfttypes.ValidateNode, error) {
vp.lock.RLock()
defer vp.lock.RUnlock()
return vp.getValidatorByAddr(epoch, addr)
}
func (vp *ValidatorPool) getValidatorByAddr(epoch uint64, addr common.Address) (*cbfttypes.ValidateNode, error) {
if vp.epochToBlockNumber(epoch) <= vp.switchPoint {
return vp.prevValidators.FindNodeByAddress(addr)
}
return vp.currentValidators.FindNodeByAddress(addr)
}
// GetValidatorByIndex get the validator by index.
func (vp *ValidatorPool) GetValidatorByIndex(epoch uint64, index uint32) (*cbfttypes.ValidateNode, error) {
vp.lock.RLock()
defer vp.lock.RUnlock()
return vp.getValidatorByIndex(epoch, index)
}
func (vp *ValidatorPool) getValidatorByIndex(epoch uint64, index uint32) (*cbfttypes.ValidateNode, error) {
if vp.epochToBlockNumber(epoch) <= vp.switchPoint {
return vp.prevValidators.FindNodeByIndex(int(index))
}
return vp.currentValidators.FindNodeByIndex(int(index))
}
// GetNodeIDByIndex get the node id by index.
func (vp *ValidatorPool) GetNodeIDByIndex(epoch uint64, index int) discover.NodeID {
vp.lock.RLock()
defer vp.lock.RUnlock()
return vp.getNodeIDByIndex(epoch, index)
}
func (vp *ValidatorPool) getNodeIDByIndex(epoch uint64, index int) discover.NodeID {
if vp.epochToBlockNumber(epoch) <= vp.switchPoint {
return vp.prevValidators.NodeID(index)
}
return vp.currentValidators.NodeID(index)
}
// GetIndexByNodeID get the index by node id.
func (vp *ValidatorPool) GetIndexByNodeID(epoch uint64, nodeID discover.NodeID) (uint32, error) {
vp.lock.RLock()
defer vp.lock.RUnlock()
return vp.getIndexByNodeID(epoch, nodeID)
}
func (vp *ValidatorPool) getIndexByNodeID(epoch uint64, nodeID discover.NodeID) (uint32, error) {
if vp.epochToBlockNumber(epoch) <= vp.switchPoint {
return vp.prevValidators.Index(nodeID)
}
return vp.currentValidators.Index(nodeID)
}
// ValidatorList get the validator list.
func (vp *ValidatorPool) ValidatorList(epoch uint64) []discover.NodeID {
vp.lock.RLock()
defer vp.lock.RUnlock()
return vp.validatorList(epoch)
}
func (vp *ValidatorPool) validatorList(epoch uint64) []discover.NodeID {
if vp.epochToBlockNumber(epoch) <= vp.switchPoint {
return vp.prevValidators.NodeList()
}
return vp.currentValidators.NodeList()
}
func (vp *ValidatorPool) Validators(epoch uint64) *cbfttypes.Validators {
if vp.epochToBlockNumber(epoch) <= vp.switchPoint {
return vp.prevValidators
}
return vp.currentValidators
}
// VerifyHeader verify block's header.
func (vp *ValidatorPool) VerifyHeader(header *types.Header) error {
_, err := crypto.Ecrecover(header.SealHash().Bytes(), header.Signature())
if err != nil {
return err
}
// todo: need confirmed.
return vp.agency.VerifyHeader(header, nil)
}
// IsValidator check if the node is validator.
func (vp *ValidatorPool) IsValidator(epoch uint64, nodeID discover.NodeID) bool {
vp.lock.RLock()
defer vp.lock.RUnlock()
return vp.isValidator(epoch, nodeID)
}
func (vp *ValidatorPool) isValidator(epoch uint64, nodeID discover.NodeID) bool {
_, err := vp.getValidatorByNodeID(epoch, nodeID)
return err == nil
}
// IsCandidateNode check if the node is candidate node.
func (vp *ValidatorPool) IsCandidateNode(nodeID discover.NodeID) bool {
return vp.agency.IsCandidateNode(nodeID)
}
// Len return number of validators.
func (vp *ValidatorPool) Len(epoch uint64) int {
vp.lock.RLock()
defer vp.lock.RUnlock()
if vp.epochToBlockNumber(epoch) <= vp.switchPoint {
return vp.prevValidators.Len()
}
return vp.currentValidators.Len()
}
// Verify verifies signature using the specified validator's bls public key.
func (vp *ValidatorPool) Verify(epoch uint64, validatorIndex uint32, msg, signature []byte) error {
validator, err := vp.GetValidatorByIndex(epoch, validatorIndex)
if err != nil {
return err
}
return validator.Verify(msg, signature)
}
// VerifyAggSig verifies aggregation signature using the specified validators' public keys.
func (vp *ValidatorPool) VerifyAggSig(epoch uint64, validatorIndexes []uint32, msg, signature []byte) bool {
vp.lock.RLock()
validators := vp.currentValidators
if vp.epochToBlockNumber(epoch) <= vp.switchPoint {
validators = vp.prevValidators
}
nodeList, err := validators.NodeListByIndexes(validatorIndexes)
if err != nil {
vp.lock.RUnlock()
return false
}
vp.lock.RUnlock()
var pub bls.PublicKey
for _, node := range nodeList {
pub.Add(node.BlsPubKey)
}
var sig bls.Sign
err = sig.Deserialize(signature)
if err != nil {
return false
}
return sig.Verify(&pub, string(msg))
}
func (vp *ValidatorPool) VerifyAggSigByBA(epoch uint64, vSet *utils.BitArray, msg, signature []byte) error {
vp.lock.RLock()
validators := vp.currentValidators
if vp.epochToBlockNumber(epoch) <= vp.switchPoint {
validators = vp.prevValidators
}
nodeList, err := validators.NodeListByBitArray(vSet)
if err != nil || len(nodeList) == 0 {
vp.lock.RUnlock()
return fmt.Errorf("not found validators: %v", err)
}
vp.lock.RUnlock()
var pub bls.PublicKey
pub.Deserialize(nodeList[0].BlsPubKey.Serialize())
for i := 1; i < len(nodeList); i++ {
pub.Add(nodeList[i].BlsPubKey)
}
var sig bls.Sign
err = sig.Deserialize(signature)
if err != nil {
return err
}
if !sig.Verify(&pub, string(msg)) {
log.Error("Verify signature fail", "epoch", epoch, "vSet", vSet.String(), "msg", hex.EncodeToString(msg), "signature", hex.EncodeToString(signature), "nodeList", nodeList, "validators", validators.String())
return errors.New("bls verifies signature fail")
}
return nil
}
func (vp *ValidatorPool) epochToBlockNumber(epoch uint64) uint64 {
if epoch > vp.epoch {
panic(fmt.Sprintf("get unknown epoch, current:%d, request:%d", vp.epoch, epoch))
}
if epoch+1 == vp.epoch {
return vp.switchPoint
}
return vp.switchPoint + 1
}
func (vp *ValidatorPool) Flush(header *types.Header) error {
return vp.agency.Flush(header)
}
func (vp *ValidatorPool) Commit(block *types.Block) error {
return vp.agency.OnCommit(block)
}
func NextRound(blockNumber uint64) uint64 {
return blockNumber + 1
}