Skip to content

Commit 593f499

Browse files
committed
reuse shard descriptors for both join planning and confirm/reject decisions
1 parent c441353 commit 593f499

File tree

1 file changed

+56
-24
lines changed

1 file changed

+56
-24
lines changed

node/consensus/global/event_distributor.go

Lines changed: 56 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -370,15 +370,17 @@ func (e *GlobalConsensusEngine) estimateSeniorityFromConfig() uint64 {
370370
func (e *GlobalConsensusEngine) evaluateForProposals(
371371
data *consensustime.GlobalEvent,
372372
) {
373-
info, err := e.proverRegistry.GetProverInfo(e.getProverAddress())
373+
self, err := e.proverRegistry.GetProverInfo(e.getProverAddress())
374374
var effectiveSeniority uint64
375-
if err != nil || info == nil {
375+
if err != nil || self == nil {
376376
effectiveSeniority = e.estimateSeniorityFromConfig()
377377
} else {
378-
effectiveSeniority = info.Seniority
378+
effectiveSeniority = self.Seniority
379379
}
380380

381-
shardDescriptors := []provers.ShardDescriptor{}
381+
pendingFilters := [][]byte{}
382+
proposalDescriptors := []provers.ShardDescriptor{}
383+
decideDescriptors := []provers.ShardDescriptor{}
382384
shardKeys := e.hypergraph.Commit()
383385
for key := range shardKeys {
384386
shards, err := e.shardsStore.GetAppShards(
@@ -415,16 +417,14 @@ func (e *GlobalConsensusEngine) evaluateForProposals(
415417
}
416418

417419
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
421425
}
422426
}
423427

424-
if allocated {
425-
continue
426-
}
427-
428428
size := e.hypergraph.GetSize(&key, path)
429429
resp, err := e.hypergraph.GetChildrenForPath(
430430
e.ctx,
@@ -486,8 +486,23 @@ func (e *GlobalConsensusEngine) evaluateForProposals(
486486
zap.Int("ring", len(above)/8),
487487
zap.Int("shard_count", int(shardCount)),
488488
)
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,
491506
provers.ShardDescriptor{
492507
Filter: filter,
493508
Size: size.Uint64(),
@@ -497,18 +512,35 @@ func (e *GlobalConsensusEngine) evaluateForProposals(
497512
)
498513
}
499514
}
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,
511520
)
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+
}
512544
}
513545
}
514546

0 commit comments

Comments
 (0)