-
Notifications
You must be signed in to change notification settings - Fork 11
/
committee.go
775 lines (714 loc) · 21.5 KB
/
committee.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
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
// Copyright (c) 2019 IoTeX
// 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 <http://www.gnu.org/licenses/>.
package committee
import (
"context"
"encoding/hex"
"math"
"math/big"
"sort"
"strconv"
"strings"
"sync"
"sync/atomic"
"time"
ethereum "github.com/ethereum/go-ethereum"
"github.com/ethereum/go-ethereum/common"
lru "github.com/hashicorp/golang-lru"
// require sqlite3 driver
_ "github.com/mattn/go-sqlite3"
"github.com/pkg/errors"
"go.uber.org/zap"
"github.com/iotexproject/iotex-election/carrier"
"github.com/iotexproject/iotex-election/db"
"github.com/iotexproject/iotex-election/types"
)
// CalcGravityChainHeight calculates the corresponding gravity chain height for an epoch
type CalcGravityChainHeight func(uint64) (uint64, error)
// Config defines the config of the committee
type Config struct {
NumOfRetries uint8 `yaml:"numOfRetries"`
GravityChainAPIs []string `yaml:"gravityChainAPIs"`
GravityChainHeightInterval uint64 `yaml:"gravityChainHeightInterval"`
GravityChainStartHeight uint64 `yaml:"gravityChainStartHeight"`
GravityChainCeilingHeight uint64 `yaml:"gravityChainCeilingHeight"`
RegisterContractAddress string `yaml:"registerContractAddress"`
StakingContractAddress string `yaml:"stakingContractAddress"`
PaginationSize uint8 `yaml:"paginationSize"`
VoteThreshold string `yaml:"voteThreshold"`
ScoreThreshold string `yaml:"scoreThreshold"`
SelfStakingThreshold string `yaml:"selfStakingThreshold"`
CacheSize uint32 `yaml:"cacheSize"`
NumOfFetchInParallel uint8 `yaml:"numOfFetchInParallel"`
SkipManifiedCandidate bool `yaml:"skipManifiedCandidate"`
GravityChainBatchSize uint64 `yaml:"gravityChainBatchSize"`
}
// STATUS represents the status of committee
type STATUS uint8
const (
// STARTING stands for a starting status
STARTING STATUS = iota
// ACTIVE stands for an active status
ACTIVE
// INACTIVE stands for an inactive status
INACTIVE
)
// EthHardForkHeight stands for the height of ethereum hard fork
const EthHardForkHeight = 8581700
type (
// Committee defines an interface of an election committee
// It could be considered as a light state db of gravity chain, that
Committee interface {
// Start starts the committee service
Start(context.Context) error
// Stop stops the committee service
Stop(context.Context) error
// ResultByHeight returns the result on a specific ethereum height
ResultByHeight(uint64) (*types.ElectionResult, error)
//RawDataByHeight returns the bucket list and registration list and mintTime
RawDataByHeight(uint64) ([]*types.Bucket, []*types.Registration, time.Time, error)
// HeightByTime returns the nearest result before time
HeightByTime(time.Time) (uint64, error)
// LatestHeight returns the height with latest result
LatestHeight() uint64
// Status returns the committee status
Status() STATUS
// PutNativePollByEpoch puts one native poll record on IoTeX chain
PutNativePollByEpoch(uint64, time.Time, []*types.Bucket) error
// NativeBucketsByEpoch returns a list of Bucket of a given epoch number
NativeBucketsByEpoch(uint64) ([]*types.Bucket, error)
}
committee struct {
archive PollArchive
carrier carrier.Carrier
retryLimit uint8
paginationSize uint8
fetchInParallel uint8
skipManifiedCandidate bool
voteThreshold *big.Int
scoreThreshold *big.Int
selfStakingThreshold *big.Int
interval uint64
cache *lru.Cache
startHeight uint64
currentHeight uint64
lastUpdateTimestamp int64
terminate chan bool
terminatedCarrier bool
terminatedArchive bool
mutex sync.RWMutex
gravityChainBatchSize uint64
ceilingHeight uint64
}
rawData struct {
mintTime time.Time
noNewStakingEvent bool
migration bool
buckets []*types.Bucket
registrations []*types.Registration
}
)
// NewCommittee creates a committee
func NewCommittee(archive PollArchive, cfg Config) (Committee, error) {
if !common.IsHexAddress(cfg.StakingContractAddress) {
return nil, errors.New("Invalid staking contract address")
}
carrier, err := carrier.NewEthereumVoteCarrier(
12,
time.Minute,
cfg.GravityChainAPIs,
common.HexToAddress(cfg.RegisterContractAddress),
common.HexToAddress(cfg.StakingContractAddress),
)
if err != nil {
return nil, err
}
zap.L().Info(
"Carrier created",
zap.String("registerContractAddress", cfg.RegisterContractAddress),
zap.String("stakingContractAddress", cfg.StakingContractAddress),
)
voteThreshold, ok := new(big.Int).SetString(cfg.VoteThreshold, 10)
if !ok {
return nil, errors.New("Invalid vote threshold")
}
scoreThreshold, ok := new(big.Int).SetString(cfg.ScoreThreshold, 10)
if !ok {
return nil, errors.New("Invalid score threshold")
}
selfStakingThreshold, ok := new(big.Int).SetString(cfg.SelfStakingThreshold, 10)
if !ok {
return nil, errors.New("Invalid self staking threshold")
}
fetchInParallel := uint8(10)
if cfg.NumOfFetchInParallel > 0 {
fetchInParallel = cfg.NumOfFetchInParallel
}
gravityChainBatchSize := uint64(10)
if cfg.GravityChainBatchSize > 0 {
gravityChainBatchSize = cfg.GravityChainBatchSize
}
cache, err := lru.New(int(cfg.CacheSize))
if err != nil {
return nil, err
}
return &committee{
archive: archive,
cache: cache,
carrier: carrier,
retryLimit: cfg.NumOfRetries,
paginationSize: cfg.PaginationSize,
fetchInParallel: fetchInParallel,
skipManifiedCandidate: cfg.SkipManifiedCandidate,
voteThreshold: voteThreshold,
scoreThreshold: scoreThreshold,
selfStakingThreshold: selfStakingThreshold,
terminate: make(chan bool),
terminatedCarrier: false,
terminatedArchive: false,
startHeight: cfg.GravityChainStartHeight,
ceilingHeight: cfg.GravityChainCeilingHeight,
interval: cfg.GravityChainHeightInterval,
currentHeight: 0,
gravityChainBatchSize: gravityChainBatchSize,
}, nil
}
func (ec *committee) Start(ctx context.Context) (err error) {
ec.mutex.Lock()
defer ec.mutex.Unlock()
if err = ec.archive.Start(ctx); err != nil {
return err
}
ceilingHeight := ec.ceilingHeight
if ceilingHeight >= ec.interval {
ceilingHeight -= ec.interval
}
if ec.latestHeightInArchive() >= ceilingHeight && ec.ceilingHeight != 0 {
zap.L().Info("stop syncing")
ec.terminateCarrier(ctx)
return nil
}
tip, err := ec.carrier.Tip()
if err != nil {
return errors.Wrap(err, "failed to get tip height")
}
tipChan := make(chan uint64)
reportChan := make(chan error)
go func() {
zap.L().Info("catching up via network")
gap := ec.interval * ec.gravityChainBatchSize
for h := ec.nextHeight() + gap; h < tip; h += gap {
zap.L().Info("catching up to", zap.Uint64("height", h))
data, err := ec.fetchInBatch(h)
if err != nil {
zap.L().Error("failed to fetch data", zap.Error(err))
}
if err := ec.storeInBatch(data); err != nil {
zap.L().Error("failed to catch up via network", zap.Uint64("height", h), zap.Error(err))
}
}
data, err := ec.fetchInBatch(tip)
if err != nil {
zap.L().Error("failed to fetch data", zap.Error(err))
}
if err := ec.storeInBatch(data); err != nil {
zap.L().Error("failed to catch up via network", zap.Error(err))
}
zap.L().Info("subscribing to new block")
ec.carrier.SubscribeNewBlock(tipChan, reportChan, ec.terminate)
for {
select {
case <-ec.terminate:
return
case tip := <-tipChan:
if ec.currentHeight >= ec.ceilingHeight && ec.ceilingHeight != 0 {
zap.L().Info("stop syncing")
ec.terminateCarrier(ctx)
return
}
zap.L().Info("new ethereum block", zap.Uint64("height", tip))
if err := ec.Sync(tip); err != nil {
zap.L().Error("failed to sync", zap.Error(err))
}
case err := <-reportChan:
zap.L().Error("something goes wrong", zap.Error(err))
}
}
}()
return nil
}
func (ec *committee) terminateCarrier(ctx context.Context) {
if !ec.terminatedCarrier {
close(ec.terminate)
ec.carrier.Close()
ec.terminatedCarrier = true
}
}
func (ec *committee) terminateArchive(ctx context.Context) error {
if !ec.terminatedArchive {
ec.terminatedArchive = true
return ec.archive.Stop(ctx)
}
return nil
}
func (ec *committee) Stop(ctx context.Context) error {
ec.mutex.Lock()
defer ec.mutex.Unlock()
ec.terminateCarrier(ctx)
return ec.terminateArchive(ctx)
}
func (ec *committee) Status() STATUS {
lastUpdateTimestamp := atomic.LoadInt64(&ec.lastUpdateTimestamp)
switch {
case lastUpdateTimestamp == 0:
return STARTING
case lastUpdateTimestamp > time.Now().Add(-5*time.Minute).Unix():
return ACTIVE
default:
return INACTIVE
}
}
func (ec *committee) Sync(tipHeight uint64) error {
data, err := ec.fetchInBatch(tipHeight)
if err != nil {
return err
}
if len(data) == 0 {
return nil
}
ec.mutex.Lock()
defer ec.mutex.Unlock()
return ec.storeInBatch(data)
}
func (ec *committee) PutNativePollByEpoch(epochNum uint64, mintTime time.Time, buckets []*types.Bucket) error {
return ec.archive.PutNativePoll(epochNum, mintTime, buckets)
}
func (ec *committee) NativeBucketsByEpoch(epochNum uint64) ([]*types.Bucket, error) {
return ec.archive.NativeBuckets(epochNum)
}
func (ec *committee) nextHeight() uint64 {
height := ec.latestHeightInArchive()
if height == 0 {
return ec.startHeight
}
return height + ec.interval
}
func (ec *committee) fetchInBatch(tipHeight uint64) (retval map[uint64]*rawData, err error) {
if ec.currentHeight < tipHeight {
ec.currentHeight = tipHeight
}
retval = map[uint64]*rawData{}
var wg sync.WaitGroup
var lock sync.RWMutex
limiter := make(chan bool, ec.fetchInParallel)
for nextHeight := ec.nextHeight(); nextHeight <= ec.currentHeight; nextHeight += ec.interval {
wg.Add(1)
go func(height uint64) {
defer func() {
<-limiter
wg.Done()
}()
limiter <- true
data, e := ec.retryFetchDataByHeight(height)
lock.Lock()
defer lock.Unlock()
retval[height] = data
if e != nil {
err = e
}
}(nextHeight)
}
wg.Wait()
return
}
func (ec *committee) storeInBatch(data map[uint64]*rawData) error {
heights := make([]uint64, 0, len(data))
mintTimes := make([]time.Time, 0, len(data))
arrOfRegs := make([][]*types.Registration, 0, len(data))
arrOfBuckets := make([][]*types.Bucket, 0, len(data))
for height := range data {
heights = append(heights, height)
mintTimes = append(mintTimes, data[height].mintTime)
arrOfRegs = append(arrOfRegs, data[height].registrations)
if data[height].noNewStakingEvent {
arrOfBuckets = append(arrOfBuckets, nil)
} else {
arrOfBuckets = append(arrOfBuckets, data[height].buckets)
}
}
indice := map[uint64]int{}
for i, height := range heights {
if _, ok := indice[height]; ok {
return errors.Errorf("duplicate height %d", height)
}
indice[height] = i
}
sort.Slice(heights, func(i, j int) bool {
return heights[i] < heights[j]
})
for _, height := range heights {
index := indice[height]
if err := ec.archive.PutPoll(height, mintTimes[index], arrOfRegs[index], arrOfBuckets[index]); err != nil {
return err
}
}
atomic.StoreInt64(&ec.lastUpdateTimestamp, time.Now().Unix())
return nil
}
func (ec *committee) LatestHeight() uint64 {
ec.mutex.RLock()
defer ec.mutex.RUnlock()
return ec.latestHeightInArchive()
}
func (ec *committee) latestHeightInArchive() uint64 {
tipHeight, err := ec.archive.TipHeight()
if err != nil {
return 0
}
return tipHeight
}
func (ec *committee) HeightByTime(ts time.Time) (uint64, error) {
ec.mutex.RLock()
defer ec.mutex.RUnlock()
// Make sure that we already got a block after the timestamp, such that the height
// we return here is the last one before ts
return ec.archive.HeightBefore(ts)
}
func (ec *committee) RawDataByHeight(height uint64) ([]*types.Bucket, []*types.Registration, time.Time, error) {
ec.mutex.RLock()
defer ec.mutex.RUnlock()
return ec.rawDataByHeight(height)
}
func (ec *committee) rawDataByHeight(height uint64) ([]*types.Bucket, []*types.Registration, time.Time, error) {
timestamp, err := ec.archive.MintTime(height)
if err != nil {
return nil, nil, time.Time{}, err
}
regs, err := ec.archive.Registrations(height)
if err != nil {
return nil, nil, time.Time{}, err
}
buckets, err := ec.archive.Buckets(height)
if err != nil {
return nil, nil, time.Time{}, err
}
return buckets, regs, timestamp, nil
}
func (ec *committee) ResultByHeight(height uint64) (*types.ElectionResult, error) {
ec.mutex.RLock()
defer ec.mutex.RUnlock()
return ec.resultByHeight(height)
}
func (ec *committee) resultByHeight(height uint64) (*types.ElectionResult, error) {
zap.L().Debug("fetch result from DB and calculate", zap.Uint64("height", height))
if height < ec.startHeight {
return nil, errors.Errorf(
"height %d is lower than start height %d",
height,
ec.startHeight,
)
}
if (height-ec.startHeight)%ec.interval != 0 {
return nil, errors.Errorf(
"height %d is an invalid height",
height,
)
}
if cacheResult, ok := ec.cache.Get(height); ok {
if result, as := cacheResult.(*types.ElectionResult); as {
return result, nil
}
return nil, errors.Errorf(
"lru cache type assertion has error",
)
}
//calculate the result from DB
calculator, err := ec.calculator(height, true)
if err != nil {
return nil, err
}
regs, err := ec.archive.Registrations(height)
if err != nil {
return nil, err
}
if err := calculator.AddRegistrations(regs); err != nil {
return nil, err
}
buckets, err := ec.archive.Buckets(height)
if err != nil {
return nil, err
}
if err := calculator.AddBuckets(buckets); err != nil {
return nil, err
}
result, err := calculator.Calculate()
if err != nil {
return nil, err
}
if err := ec.handleEthereumHardFork(height, result); err != nil {
return nil, err
}
ec.cache.Add(height, result)
return result, nil
}
func (ec *committee) calcWeightedVotes(v *types.Bucket, now time.Time) *big.Int {
if now.Before(v.StartTime()) {
return big.NewInt(0)
}
remainingTime := v.RemainingTime(now).Seconds()
weight := float64(1)
if remainingTime > 0 {
weight += math.Log(math.Ceil(remainingTime/86400)) / math.Log(1.2) / 100
}
amount := new(big.Float).SetInt(v.Amount())
weightedAmount, _ := amount.Mul(amount, big.NewFloat(weight)).Int(nil)
return weightedAmount
}
func (ec *committee) fetchBucketsByHeight(height uint64, force bool) (bool, []*types.Bucket, error) {
if height > ec.interval && height != ec.startHeight && !force {
if !ec.carrier.HasStakingEvents(new(big.Int).SetUint64(height-ec.interval+1), new(big.Int).SetUint64(height)) {
return true, nil, nil
}
}
buckets, err := ec.fetchBucketsFromEthereum(height)
return false, buckets, err
}
func (ec *committee) fetchBucketsFromEthereum(height uint64) ([]*types.Bucket, error) {
var allBuckets []*types.Bucket
previousIndex := big.NewInt(0)
for {
var buckets []*types.Bucket
var err error
if previousIndex, buckets, err = ec.carrier.Buckets(
height,
previousIndex,
ec.paginationSize,
); err != nil {
return nil, err
}
allBuckets = append(allBuckets, buckets...)
if len(buckets) < int(ec.paginationSize) {
break
}
}
zap.L().Debug("fetch buckets by height from ethereum", zap.Int("number of buckets", len(allBuckets)))
return allBuckets, nil
}
func (ec *committee) bucketFilter(v *types.Bucket) bool {
return ec.voteThreshold.Cmp(v.Amount()) > 0
}
func (ec *committee) candidateFilter(c *types.Candidate) bool {
return ec.selfStakingThreshold.Cmp(c.SelfStakingTokens()) > 0 ||
ec.scoreThreshold.Cmp(c.Score()) > 0
}
func (ec *committee) getMintTimeByHeight(height uint64) (time.Time, error) {
mintTime, err := ec.carrier.BlockTimestamp(height)
switch errors.Cause(err) {
case nil:
break
case ethereum.NotFound:
return mintTime, db.ErrNotExist
default:
return mintTime, err
}
return mintTime, nil
}
func (ec *committee) calculator(height uint64, dbflag bool) (*types.ResultCalculator, error) {
var timestamp time.Time
var err error
if dbflag {
timestamp, err = ec.archive.MintTime(height)
} else {
timestamp, err = ec.getMintTimeByHeight(height)
}
if err != nil {
return nil, err
}
return types.NewResultCalculator(
timestamp,
ec.skipManifiedCandidate,
ec.bucketFilter,
ec.calcWeightedVotes,
ec.candidateFilter,
), nil
}
func (ec *committee) fetchRegistrationsByHeight(height uint64) ([]*types.Registration, error) {
var allCandidates []*types.Registration
previousIndex := big.NewInt(1)
for {
var candidates []*types.Registration
var err error
if previousIndex, candidates, err = ec.carrier.Registrations(
height,
previousIndex,
ec.paginationSize,
); err != nil {
return nil, err
}
allCandidates = append(allCandidates, candidates...)
if len(candidates) < int(ec.paginationSize) {
break
}
}
zap.L().Debug("fetch registrations by height from ethereum", zap.Int("number of registrations", len(allCandidates)))
return allCandidates, nil
}
func (ec *committee) FetchResultByHeight(height uint64) (*types.ElectionResult, error) {
if height == 0 {
var err error
height, err = ec.carrier.Tip()
if err != nil {
return nil, err
}
}
return ec.fetchResultByHeight(height)
}
func (ec *committee) fetchResultByHeight(height uint64) (*types.ElectionResult, error) {
zap.L().Info("fetch result from ethereum", zap.Uint64("height", height))
calculator, err := ec.calculator(height, false)
if err != nil {
return nil, err
}
regs, err := ec.fetchRegistrationsByHeight(height)
if err != nil {
return nil, err
}
if err := calculator.AddRegistrations(regs); err != nil {
return nil, err
}
_, buckets, err := ec.fetchBucketsByHeight(height, true)
if err != nil {
return nil, err
}
if err := calculator.AddBuckets(buckets); err != nil {
return nil, err
}
res, err := calculator.Calculate()
if err != nil {
return nil, err
}
if err := ec.handleEthereumHardFork(height, res); err != nil {
return nil, err
}
return res, nil
}
func (ec *committee) fetchDataByHeight(height uint64) (*rawData, error) {
zap.L().Info("fetch from ethereum", zap.Uint64("height", height))
regs, err := ec.fetchRegistrationsByHeight(height)
if err != nil {
return nil, err
}
noChange, buckets, err := ec.fetchBucketsByHeight(height, false)
if err != nil {
return nil, err
}
mintTime, err := ec.getMintTimeByHeight(height)
if err != nil {
return nil, err
}
return &rawData{
mintTime: mintTime,
noNewStakingEvent: noChange,
registrations: regs,
buckets: buckets,
}, nil
}
func atos(a []int64) string {
if len(a) == 0 {
return ""
}
b := make([]string, len(a))
for i, v := range a {
b[i] = strconv.FormatInt(v, 10)
}
return strings.Join(b, ",")
}
func (ec *committee) handleEthereumHardFork(height uint64, result *types.ElectionResult) error {
if height != EthHardForkHeight {
return nil
}
for _, delegate := range result.Delegates() {
name := hex.EncodeToString(delegate.Name())
switch name {
case "000000696f746578636f7265":
score, ok := new(big.Int).SetString("85373235544231218078559584", 10)
if ok {
delegate.SetScore(score)
}
case "00000000006d6574616e7978":
score, ok := new(big.Int).SetString("59632560935643656968902530", 10)
if ok {
delegate.SetScore(score)
}
case "67616d6566616e7461737900":
score, ok := new(big.Int).SetString("53200765151851838442704552", 10)
if ok {
delegate.SetScore(score)
}
case "00000000707265616e67656c":
score, ok := new(big.Int).SetString("50419789330925706718338211", 10)
if ok {
delegate.SetScore(score)
}
case "00007976616c696461746f72":
score, ok := new(big.Int).SetString("49956076291800440218188229", 10)
if ok {
delegate.SetScore(score)
}
case "000000636f696e6765636b6f":
score, ok := new(big.Int).SetString("45541967921325925112783154", 10)
if ok {
delegate.SetScore(score)
}
case "000000696f7465787465616d":
score, ok := new(big.Int).SetString("42048368188254741149181523", 10)
if ok {
delegate.SetScore(score)
}
case "0000626c6f636b666f6c696f":
score, ok := new(big.Int).SetString("40118847473353343676639849", 10)
if ok {
delegate.SetScore(score)
}
case "696f7478706c6f726572696f":
score, ok := new(big.Int).SetString("38637407472542613934244717", 10)
if ok {
delegate.SetScore(score)
}
case "0068756f626977616c6c6574":
score, ok := new(big.Int).SetString("19826333897499304850764901", 10)
if ok {
delegate.SetScore(score)
}
case "636f6e73656e7375736e6574":
score, ok := new(big.Int).SetString("4562820963931216603918007", 10)
if ok {
delegate.SetScore(score)
}
default:
continue
}
}
return nil
}
func (ec *committee) retryFetchDataByHeight(height uint64) (data *rawData, err error) {
for i := uint8(0); i < ec.retryLimit; i++ {
if data, err = ec.fetchDataByHeight(height); err == nil {
break
}
zap.L().Error(
"failed to fetch result by height",
zap.Error(err),
zap.Uint64("height", height),
zap.Uint8("tried", i+1),
)
}
return
}