@@ -370,15 +370,17 @@ func (e *GlobalConsensusEngine) estimateSeniorityFromConfig() uint64 {
370
370
func (e * GlobalConsensusEngine ) evaluateForProposals (
371
371
data * consensustime.GlobalEvent ,
372
372
) {
373
- info , err := e .proverRegistry .GetProverInfo (e .getProverAddress ())
373
+ self , err := e .proverRegistry .GetProverInfo (e .getProverAddress ())
374
374
var effectiveSeniority uint64
375
- if err != nil || info == nil {
375
+ if err != nil || self == nil {
376
376
effectiveSeniority = e .estimateSeniorityFromConfig ()
377
377
} else {
378
- effectiveSeniority = info .Seniority
378
+ effectiveSeniority = self .Seniority
379
379
}
380
380
381
- shardDescriptors := []provers.ShardDescriptor {}
381
+ pendingFilters := [][]byte {}
382
+ proposalDescriptors := []provers.ShardDescriptor {}
383
+ decideDescriptors := []provers.ShardDescriptor {}
382
384
shardKeys := e .hypergraph .Commit ()
383
385
for key := range shardKeys {
384
386
shards , err := e .shardsStore .GetAppShards (
@@ -415,16 +417,14 @@ func (e *GlobalConsensusEngine) evaluateForProposals(
415
417
}
416
418
417
419
allocated := false
418
- for _ , prover := range info {
419
- if bytes .Equal (prover .Address , e .getProverAddress ()) {
420
- allocated = true
420
+ pending := false
421
+ for _ , allocation := range self .Allocations {
422
+ if bytes .Equal (allocation .ConfirmationFilter , filter ) {
423
+ allocated = allocation .Status != 4
424
+ pending = allocation .Status == 0
421
425
}
422
426
}
423
427
424
- if allocated {
425
- continue
426
- }
427
-
428
428
size := e .hypergraph .GetSize (& key , path )
429
429
resp , err := e .hypergraph .GetChildrenForPath (
430
430
e .ctx ,
@@ -486,8 +486,23 @@ func (e *GlobalConsensusEngine) evaluateForProposals(
486
486
zap .Int ("ring" , len (above )/ 8 ),
487
487
zap .Int ("shard_count" , int (shardCount )),
488
488
)
489
- shardDescriptors = append (
490
- shardDescriptors ,
489
+
490
+ if allocated && pending {
491
+ pendingFilters = append (pendingFilters , filter )
492
+ }
493
+ if ! allocated {
494
+ proposalDescriptors = append (
495
+ proposalDescriptors ,
496
+ provers.ShardDescriptor {
497
+ Filter : filter ,
498
+ Size : size .Uint64 (),
499
+ Ring : uint8 (len (above ) / 8 ),
500
+ Shards : shardCount ,
501
+ },
502
+ )
503
+ }
504
+ decideDescriptors = append (
505
+ decideDescriptors ,
491
506
provers.ShardDescriptor {
492
507
Filter : filter ,
493
508
Size : size .Uint64 (),
@@ -497,18 +512,35 @@ func (e *GlobalConsensusEngine) evaluateForProposals(
497
512
)
498
513
}
499
514
}
500
- proposals , err := e .proposer .PlanAndAllocate (
501
- uint64 (data .Frame .Header .Difficulty ),
502
- shardDescriptors ,
503
- 0 ,
504
- )
505
- if err != nil {
506
- e .logger .Error ("could not plan shard allocations" , zap .Error (err ))
507
- } else {
508
- e .logger .Info (
509
- "proposed joins" ,
510
- zap .Int ("proposals" , len (proposals )),
515
+ if len (proposalDescriptors ) != 0 {
516
+ proposals , err := e .proposer .PlanAndAllocate (
517
+ uint64 (data .Frame .Header .Difficulty ),
518
+ proposalDescriptors ,
519
+ 0 ,
511
520
)
521
+ if err != nil {
522
+ e .logger .Error ("could not plan shard allocations" , zap .Error (err ))
523
+ } else {
524
+ e .logger .Info (
525
+ "proposed joins" ,
526
+ zap .Int ("proposals" , len (proposals )),
527
+ )
528
+ }
529
+ }
530
+ if len (pendingFilters ) != 0 {
531
+ err = e .proposer .DecideJoins (
532
+ uint64 (data .Frame .Header .Difficulty ),
533
+ decideDescriptors ,
534
+ pendingFilters ,
535
+ )
536
+ if err != nil {
537
+ e .logger .Error ("could not decide shard allocations" , zap .Error (err ))
538
+ } else {
539
+ e .logger .Info (
540
+ "decided on joins" ,
541
+ zap .Int ("joins" , len (pendingFilters )),
542
+ )
543
+ }
512
544
}
513
545
}
514
546
0 commit comments