-
Notifications
You must be signed in to change notification settings - Fork 227
Expand file tree
/
Copy pathsubroundBlock.go
More file actions
730 lines (585 loc) · 18.6 KB
/
Copy pathsubroundBlock.go
File metadata and controls
730 lines (585 loc) · 18.6 KB
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
package v1
import (
"bytes"
"context"
"time"
"github.com/multiversx/mx-chain-core-go/core"
"github.com/multiversx/mx-chain-core-go/core/check"
"github.com/multiversx/mx-chain-core-go/data"
"github.com/multiversx/mx-chain-go/common"
"github.com/multiversx/mx-chain-go/consensus"
"github.com/multiversx/mx-chain-go/consensus/spos"
"github.com/multiversx/mx-chain-go/consensus/spos/bls"
)
// maxAllowedSizeInBytes defines how many bytes are allowed as payload in a message
const maxAllowedSizeInBytes = uint32(core.MegabyteSize * 95 / 100)
// subroundBlock defines the data needed by the subround Block
type subroundBlock struct {
*spos.Subround
processingThresholdPercentage int
}
// NewSubroundBlock creates a subroundBlock object
func NewSubroundBlock(
baseSubround *spos.Subround,
extend func(subroundId int),
processingThresholdPercentage int,
) (*subroundBlock, error) {
err := checkNewSubroundBlockParams(baseSubround)
if err != nil {
return nil, err
}
srBlock := subroundBlock{
Subround: baseSubround,
processingThresholdPercentage: processingThresholdPercentage,
}
srBlock.Job = srBlock.doBlockJob
srBlock.Check = srBlock.doBlockConsensusCheck
srBlock.Extend = extend
return &srBlock, nil
}
func checkNewSubroundBlockParams(
baseSubround *spos.Subround,
) error {
if baseSubround == nil {
return spos.ErrNilSubround
}
if check.IfNil(baseSubround.ConsensusStateHandler) {
return spos.ErrNilConsensusState
}
err := spos.ValidateConsensusCore(baseSubround.ConsensusCoreHandler)
return err
}
// doBlockJob method does the job of the subround Block
func (sr *subroundBlock) doBlockJob(ctx context.Context) bool {
isSelfLeader := sr.IsSelfLeaderInCurrentRound() && sr.ShouldConsiderSelfKeyInConsensus()
if !isSelfLeader && !sr.IsMultiKeyLeaderInCurrentRound() { // is NOT self leader in this round?
return false
}
if sr.RoundHandler().Index() <= sr.getRoundInLastCommittedBlock() {
return false
}
if sr.IsLeaderJobDone(sr.Current()) {
return false
}
if sr.IsSubroundFinished(sr.Current()) {
return false
}
metricStatTime := time.Now()
defer sr.computeSubroundProcessingMetric(metricStatTime, common.MetricCreatedProposedBlock)
header, err := sr.createHeader()
if err != nil {
printLogMessage(ctx, "doBlockJob.createHeader", err)
return false
}
header, body, err := sr.createBlock(header)
if err != nil {
printLogMessage(ctx, "doBlockJob.createBlock", err)
return false
}
sentWithSuccess := sr.sendBlock(header, body)
if !sentWithSuccess {
return false
}
leader, errGetLeader := sr.GetLeader()
if errGetLeader != nil {
log.Debug("doBlockJob.GetLeader", "error", errGetLeader)
return false
}
err = sr.SetJobDone(leader, sr.Current(), true)
if err != nil {
log.Debug("doBlockJob.SetSelfJobDone", "error", err.Error())
return false
}
// placeholder for subroundBlock.doBlockJob script
sr.ConsensusCoreHandler.ScheduledProcessor().StartScheduledProcessing(header, body, sr.GetRoundTimeStamp())
return true
}
func printLogMessage(ctx context.Context, baseMessage string, err error) {
if common.IsContextDone(ctx) {
log.Debug(baseMessage + " context is closing")
return
}
log.Debug(baseMessage, "error", err.Error())
}
func (sr *subroundBlock) sendBlock(header data.HeaderHandler, body data.BodyHandler) bool {
marshalizedBody, err := sr.Marshalizer().Marshal(body)
if err != nil {
log.Debug("sendBlock.Marshal: body", "error", err.Error())
return false
}
marshalizedHeader, err := sr.Marshalizer().Marshal(header)
if err != nil {
log.Debug("sendBlock.Marshal: header", "error", err.Error())
return false
}
if sr.couldBeSentTogether(marshalizedBody, marshalizedHeader) {
return sr.sendHeaderAndBlockBody(header, body, marshalizedBody, marshalizedHeader)
}
if !sr.sendBlockBody(body, marshalizedBody) || !sr.sendBlockHeader(header, marshalizedHeader) {
return false
}
return true
}
func (sr *subroundBlock) couldBeSentTogether(marshalizedBody []byte, marshalizedHeader []byte) bool {
bodyAndHeaderSize := uint32(len(marshalizedBody) + len(marshalizedHeader))
log.Debug("couldBeSentTogether",
"body size", len(marshalizedBody),
"header size", len(marshalizedHeader),
"body and header size", bodyAndHeaderSize,
"max allowed size in bytes", maxAllowedSizeInBytes)
return bodyAndHeaderSize <= maxAllowedSizeInBytes
}
func (sr *subroundBlock) createBlock(header data.HeaderHandler) (data.HeaderHandler, data.BodyHandler, error) {
startTime := sr.GetRoundTimeStamp()
maxTime := time.Duration(sr.EndTime())
haveTimeInCurrentSubround := func() bool {
return sr.RoundHandler().RemainingTime(startTime, maxTime) > 0
}
finalHeader, blockBody, err := sr.BlockProcessor().CreateBlock(
header,
haveTimeInCurrentSubround,
)
if err != nil {
return nil, nil, err
}
return finalHeader, blockBody, nil
}
// sendHeaderAndBlockBody method sends the proposed header and block body in the subround Block
func (sr *subroundBlock) sendHeaderAndBlockBody(
headerHandler data.HeaderHandler,
bodyHandler data.BodyHandler,
marshalizedBody []byte,
marshalizedHeader []byte,
) bool {
headerHash := sr.Hasher().Compute(string(marshalizedHeader))
leader, errGetLeader := sr.GetLeader()
if errGetLeader != nil {
log.Debug("sendBlockBodyAndHeader.GetLeader", "error", errGetLeader)
return false
}
cnsMsg := consensus.NewConsensusMessage(
headerHash,
nil,
marshalizedBody,
marshalizedHeader,
[]byte(leader),
nil,
int(bls.MtBlockBodyAndHeader),
sr.RoundHandler().Index(),
sr.ChainID(),
nil,
nil,
nil,
sr.GetAssociatedPid([]byte(leader)),
nil,
)
err := sr.BroadcastMessenger().BroadcastConsensusMessage(cnsMsg)
if err != nil {
log.Debug("sendHeaderAndBlockBody.BroadcastConsensusMessage", "error", err.Error())
return false
}
log.Debug("step 1: block body and header have been sent",
"nonce", headerHandler.GetNonce(),
"hash", headerHash)
sr.SetData(headerHash)
sr.SetBody(bodyHandler)
sr.SetHeader(headerHandler)
return true
}
// sendBlockBody method sends the proposed block body in the subround Block
func (sr *subroundBlock) sendBlockBody(bodyHandler data.BodyHandler, marshalizedBody []byte) bool {
leader, errGetLeader := sr.GetLeader()
if errGetLeader != nil {
log.Debug("sendBlockBody.GetLeader", "error", errGetLeader)
return false
}
cnsMsg := consensus.NewConsensusMessage(
nil,
nil,
marshalizedBody,
nil,
[]byte(leader),
nil,
int(bls.MtBlockBody),
sr.RoundHandler().Index(),
sr.ChainID(),
nil,
nil,
nil,
sr.GetAssociatedPid([]byte(leader)),
nil,
)
err := sr.BroadcastMessenger().BroadcastConsensusMessage(cnsMsg)
if err != nil {
log.Debug("sendBlockBody.BroadcastConsensusMessage", "error", err.Error())
return false
}
log.Debug("step 1: block body has been sent")
sr.SetBody(bodyHandler)
return true
}
// sendBlockHeader method sends the proposed block header in the subround Block
func (sr *subroundBlock) sendBlockHeader(headerHandler data.HeaderHandler, marshalizedHeader []byte) bool {
headerHash := sr.Hasher().Compute(string(marshalizedHeader))
leader, errGetLeader := sr.GetLeader()
if errGetLeader != nil {
log.Debug("sendBlockBody.GetLeader", "error", errGetLeader)
return false
}
cnsMsg := consensus.NewConsensusMessage(
headerHash,
nil,
nil,
marshalizedHeader,
[]byte(leader),
nil,
int(bls.MtBlockHeader),
sr.RoundHandler().Index(),
sr.ChainID(),
nil,
nil,
nil,
sr.GetAssociatedPid([]byte(leader)),
nil,
)
err := sr.BroadcastMessenger().BroadcastConsensusMessage(cnsMsg)
if err != nil {
log.Debug("sendBlockHeader.BroadcastConsensusMessage", "error", err.Error())
return false
}
log.Debug("step 1: block header has been sent",
"nonce", headerHandler.GetNonce(),
"hash", headerHash)
sr.SetData(headerHash)
sr.SetHeader(headerHandler)
return true
}
func (sr *subroundBlock) createHeader() (data.HeaderHandler, error) {
var nonce uint64
var prevHash []byte
var prevRandSeed []byte
currentHeader := sr.Blockchain().GetCurrentBlockHeader()
if check.IfNil(currentHeader) {
nonce = sr.Blockchain().GetGenesisHeader().GetNonce() + 1
prevHash = sr.Blockchain().GetGenesisHeaderHash()
prevRandSeed = sr.Blockchain().GetGenesisHeader().GetRandSeed()
} else {
nonce = currentHeader.GetNonce() + 1
prevHash = sr.Blockchain().GetCurrentBlockHeaderHash()
prevRandSeed = currentHeader.GetRandSeed()
}
round := uint64(sr.RoundHandler().Index())
hdr, err := sr.BlockProcessor().CreateNewHeader(round, nonce)
if err != nil {
return nil, err
}
if sr.EnableEpochsHandler().IsFlagEnabledInEpoch(common.EquivalentMessagesFlag, hdr.GetEpoch()) {
return nil, ErrEquivalentMessagesFlagEnabledWithConsensusV1
}
err = hdr.SetPrevHash(prevHash)
if err != nil {
return nil, err
}
leader, errGetLeader := sr.GetLeader()
if errGetLeader != nil {
return nil, errGetLeader
}
randSeed, err := sr.SigningHandler().CreateSignatureForPublicKey(prevRandSeed, []byte(leader))
if err != nil {
return nil, err
}
err = hdr.SetShardID(sr.ShardCoordinator().SelfId())
if err != nil {
return nil, err
}
err = hdr.SetTimeStamp(uint64(sr.RoundHandler().TimeStamp().Unix()))
if err != nil {
return nil, err
}
err = hdr.SetPrevRandSeed(prevRandSeed)
if err != nil {
return nil, err
}
err = hdr.SetRandSeed(randSeed)
if err != nil {
return nil, err
}
err = hdr.SetChainID(sr.ChainID())
if err != nil {
return nil, err
}
return hdr, nil
}
// receivedBlockBodyAndHeader method is called when a block body and a block header is received
func (sr *subroundBlock) receivedBlockBodyAndHeader(ctx context.Context, cnsDta *consensus.Message) bool {
sw := core.NewStopWatch()
sw.Start("receivedBlockBodyAndHeader")
defer func() {
sw.Stop("receivedBlockBodyAndHeader")
log.Debug("time measurements of receivedBlockBodyAndHeader", sw.GetMeasurements()...)
}()
node := string(cnsDta.PubKey)
if sr.IsConsensusDataSet() {
return false
}
if !sr.IsNodeLeaderInCurrentRound(node) { // is NOT this node leader in current round?
sr.PeerHonestyHandler().ChangeScore(
node,
spos.GetConsensusTopicID(sr.ShardCoordinator()),
spos.LeaderPeerHonestyDecreaseFactor,
)
return false
}
if sr.IsBlockBodyAlreadyReceived() {
return false
}
if sr.IsHeaderAlreadyReceived() {
return false
}
if !sr.CanProcessReceivedMessage(cnsDta, sr.RoundHandler().Index(), sr.Current()) {
return false
}
header := sr.BlockProcessor().DecodeBlockHeader(cnsDta.Header)
if headerHasProof(header) {
return false
}
sr.SetData(cnsDta.BlockHeaderHash)
sr.SetBody(sr.BlockProcessor().DecodeBlockBody(cnsDta.Body))
sr.SetHeader(header)
isInvalidData := check.IfNil(sr.GetBody()) || sr.isInvalidHeaderOrData()
if isInvalidData {
return false
}
log.Debug("step 1: block body and header have been received",
"nonce", sr.GetHeader().GetNonce(),
"hash", cnsDta.BlockHeaderHash)
sw.Start("processReceivedBlock")
blockProcessedWithSuccess := sr.processReceivedBlock(ctx, cnsDta)
sw.Stop("processReceivedBlock")
sr.PeerHonestyHandler().ChangeScore(
node,
spos.GetConsensusTopicID(sr.ShardCoordinator()),
spos.LeaderPeerHonestyIncreaseFactor,
)
return blockProcessedWithSuccess
}
func (sr *subroundBlock) isInvalidHeaderOrData() bool {
return sr.GetData() == nil || check.IfNil(sr.GetHeader()) || sr.GetHeader().CheckFieldsForNil() != nil
}
// receivedBlockBody method is called when a block body is received through the block body channel
func (sr *subroundBlock) receivedBlockBody(ctx context.Context, cnsDta *consensus.Message) bool {
node := string(cnsDta.PubKey)
if !sr.IsNodeLeaderInCurrentRound(node) { // is NOT this node leader in current round?
sr.PeerHonestyHandler().ChangeScore(
node,
spos.GetConsensusTopicID(sr.ShardCoordinator()),
spos.LeaderPeerHonestyDecreaseFactor,
)
return false
}
if sr.IsBlockBodyAlreadyReceived() {
return false
}
if !sr.CanProcessReceivedMessage(cnsDta, sr.RoundHandler().Index(), sr.Current()) {
return false
}
sr.SetBody(sr.BlockProcessor().DecodeBlockBody(cnsDta.Body))
if check.IfNil(sr.GetBody()) {
return false
}
log.Debug("step 1: block body has been received")
blockProcessedWithSuccess := sr.processReceivedBlock(ctx, cnsDta)
sr.PeerHonestyHandler().ChangeScore(
node,
spos.GetConsensusTopicID(sr.ShardCoordinator()),
spos.LeaderPeerHonestyIncreaseFactor,
)
return blockProcessedWithSuccess
}
func (sr *subroundBlock) receivedFullHeader(headerHandler data.HeaderHandler) {
if sr.ShardCoordinator().SelfId() != headerHandler.GetShardID() {
log.Debug("subroundBlock.ReceivedFullHeader early exit", "headerShardID", headerHandler.GetShardID(), "selfShardID", sr.ShardCoordinator().SelfId())
return
}
if !sr.EnableEpochsHandler().IsFlagEnabledInEpoch(common.EquivalentMessagesFlag, headerHandler.GetEpoch()) {
log.Debug("subroundBlock.ReceivedFullHeader early exit", "flagNotEnabled in header epoch", headerHandler.GetEpoch())
return
}
log.Debug("subroundBlock.ReceivedFullHeader", "nonce", headerHandler.GetNonce(), "epoch", headerHandler.GetEpoch())
lastCommittedBlockHash := sr.Blockchain().GetCurrentBlockHeaderHash()
if bytes.Equal(lastCommittedBlockHash, headerHandler.GetPrevHash()) {
// Need to switch to consensus v2
log.Debug("subroundBlock.ReceivedFullHeader switching epoch")
go sr.EpochNotifier().CheckEpoch(headerHandler)
}
}
// receivedBlockHeader method is called when a block header is received through the block header channel.
// If the block header is valid, then the validatorRoundStates map corresponding to the node which sent it,
// is set on true for the subround Block
func (sr *subroundBlock) receivedBlockHeader(ctx context.Context, cnsDta *consensus.Message) bool {
node := string(cnsDta.PubKey)
if sr.IsConsensusDataSet() {
return false
}
if !sr.IsNodeLeaderInCurrentRound(node) { // is NOT this node leader in current round?
sr.PeerHonestyHandler().ChangeScore(
node,
spos.GetConsensusTopicID(sr.ShardCoordinator()),
spos.LeaderPeerHonestyDecreaseFactor,
)
return false
}
if sr.IsHeaderAlreadyReceived() {
return false
}
if !sr.CanProcessReceivedMessage(cnsDta, sr.RoundHandler().Index(), sr.Current()) {
return false
}
header := sr.BlockProcessor().DecodeBlockHeader(cnsDta.Header)
if headerHasProof(header) {
return false
}
sr.SetData(cnsDta.BlockHeaderHash)
sr.SetHeader(header)
if sr.isInvalidHeaderOrData() {
return false
}
log.Debug("step 1: block header has been received",
"nonce", sr.GetHeader().GetNonce(),
"hash", cnsDta.BlockHeaderHash)
blockProcessedWithSuccess := sr.processReceivedBlock(ctx, cnsDta)
sr.PeerHonestyHandler().ChangeScore(
node,
spos.GetConsensusTopicID(sr.ShardCoordinator()),
spos.LeaderPeerHonestyIncreaseFactor,
)
return blockProcessedWithSuccess
}
func headerHasProof(headerHandler data.HeaderHandler) bool {
if check.IfNil(headerHandler) {
return false
}
return !check.IfNilReflect(headerHandler.GetPreviousProof())
}
func (sr *subroundBlock) processReceivedBlock(ctx context.Context, cnsDta *consensus.Message) bool {
if check.IfNil(sr.GetBody()) {
return false
}
if check.IfNil(sr.GetHeader()) {
return false
}
defer func() {
sr.SetProcessingBlock(false)
}()
sr.SetProcessingBlock(true)
shouldNotProcessBlock := sr.GetExtendedCalled() || cnsDta.RoundIndex < sr.RoundHandler().Index()
if shouldNotProcessBlock {
log.Debug("canceled round, extended has been called or round index has been changed",
"round", sr.RoundHandler().Index(),
"subround", sr.Name(),
"cnsDta round", cnsDta.RoundIndex,
"extended called", sr.GetExtendedCalled(),
)
return false
}
node := string(cnsDta.PubKey)
startTime := sr.GetRoundTimeStamp()
maxTime := sr.RoundHandler().TimeDuration() * time.Duration(sr.processingThresholdPercentage) / 100
remainingTimeInCurrentRound := func() time.Duration {
return sr.RoundHandler().RemainingTime(startTime, maxTime)
}
metricStatTime := time.Now()
defer sr.computeSubroundProcessingMetric(metricStatTime, common.MetricProcessedProposedBlock)
err := sr.BlockProcessor().ProcessBlock(
sr.GetHeader(),
sr.GetBody(),
remainingTimeInCurrentRound,
)
if cnsDta.RoundIndex < sr.RoundHandler().Index() {
log.Debug("canceled round, round index has been changed",
"round", sr.RoundHandler().Index(),
"subround", sr.Name(),
"cnsDta round", cnsDta.RoundIndex,
)
return false
}
if err != nil {
sr.printCancelRoundLogMessage(ctx, err)
sr.SetRoundCanceled(true)
return false
}
err = sr.SetJobDone(node, sr.Current(), true)
if err != nil {
sr.printCancelRoundLogMessage(ctx, err)
return false
}
sr.ConsensusCoreHandler.ScheduledProcessor().StartScheduledProcessing(sr.GetHeader(), sr.GetBody(), sr.GetRoundTimeStamp())
return true
}
func (sr *subroundBlock) printCancelRoundLogMessage(ctx context.Context, err error) {
if common.IsContextDone(ctx) {
log.Debug("canceled round as the context is closing")
return
}
log.Debug("canceled round",
"round", sr.RoundHandler().Index(),
"subround", sr.Name(),
"error", err.Error())
}
func (sr *subroundBlock) computeSubroundProcessingMetric(startTime time.Time, metric string) {
subRoundDuration := sr.EndTime() - sr.StartTime()
if subRoundDuration == 0 {
// can not do division by 0
return
}
percent := uint64(time.Since(startTime)) * 100 / uint64(subRoundDuration)
sr.AppStatusHandler().SetUInt64Value(metric, percent)
}
// doBlockConsensusCheck method checks if the consensus in the subround Block is achieved
func (sr *subroundBlock) doBlockConsensusCheck() bool {
if sr.GetRoundCanceled() {
return false
}
if sr.IsSubroundFinished(sr.Current()) {
return true
}
threshold := sr.Threshold(sr.Current())
if sr.isBlockReceived(threshold) {
log.Debug("step 1: subround has been finished",
"subround", sr.Name())
sr.SetStatus(sr.Current(), spos.SsFinished)
return true
}
return false
}
// isBlockReceived method checks if the block was received from the leader in the current round
func (sr *subroundBlock) isBlockReceived(threshold int) bool {
n := 0
for i := 0; i < len(sr.ConsensusGroup()); i++ {
node := sr.ConsensusGroup()[i]
isJobDone, err := sr.JobDone(node, sr.Current())
if err != nil {
log.Debug("isBlockReceived.JobDone",
"node", node,
"subround", sr.Name(),
"error", err.Error())
continue
}
if isJobDone {
n++
}
}
return n >= threshold
}
func (sr *subroundBlock) getRoundInLastCommittedBlock() int64 {
roundInLastCommittedBlock := int64(0)
currentHeader := sr.Blockchain().GetCurrentBlockHeader()
if !check.IfNil(currentHeader) {
roundInLastCommittedBlock = int64(currentHeader.GetRound())
}
return roundInLastCommittedBlock
}
// IsInterfaceNil returns true if there is no value under the interface
func (sr *subroundBlock) IsInterfaceNil() bool {
return sr == nil
}