Skip to content

Commit 046024c

Browse files
committed
go/worker/common/committee: Split committee and suspension detection
1 parent 9b2373c commit 046024c

3 files changed

Lines changed: 29 additions & 21 deletions

File tree

go/roothash/api/commitment/pool.go

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -250,7 +250,6 @@ func (p *Pool) AddVerifiedExecutorCommitment(c *scheduler.Committee, ec *Executo
250250
"round", ec.Header.Header.Round,
251251
"node_id", ec.NodeID,
252252
"scheduler_id", ec.Header.SchedulerID,
253-
"rank", rank,
254253
)
255254
return ErrBadExecutorCommitment
256255
}

go/worker/common/committee/group.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -206,7 +206,7 @@ func (g *Group) CommitteeTransition(ctx context.Context, committee *scheduler.Co
206206
}
207207

208208
g.logger.Info("committee transition complete",
209-
"epoch", epochNumber,
209+
"committee", g.committee.Committee,
210210
"executor_roles", g.committee.Roles,
211211
)
212212

go/worker/common/committee/node.go

Lines changed: 28 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -94,7 +94,6 @@ type Node struct {
9494
latestRound uint64
9595
latestHeight int64
9696

97-
committeeRound uint64
9897
lastBlockInfo *runtime.BlockInfo
9998
dispatchInfoCh chan struct{}
10099
activeDescriptor *registry.Runtime
@@ -400,6 +399,18 @@ func (n *Node) worker() { //nolint: gocyclo
400399
return
401400
}
402401
}
402+
403+
// Start watching epochs so that we know when to recheck runtime suspension
404+
// and transactions.
405+
epochCh, epochSub, err := n.Consensus.Beacon().WatchEpochs(n.ctx)
406+
if err != nil {
407+
n.logger.Error("failed to watch epochs",
408+
"err", err,
409+
)
410+
return
411+
}
412+
defer epochSub.Close()
413+
403414
// Start watching runtime committees so we know when the runtime committee
404415
// changes and can update our worker role accordingly.
405416
cmCh, cmSub, err := n.Consensus.Scheduler().WatchCommittees(n.ctx)
@@ -459,6 +470,8 @@ func (n *Node) worker() { //nolint: gocyclo
459470
case <-n.stopCh:
460471
n.logger.Info("termination requested")
461472
return
473+
case epoch := <-epochCh:
474+
n.handleEpoch(n.ctx, epoch)
462475
case cm := <-cmCh:
463476
n.handleCommittee(n.ctx, cm)
464477
case blk := <-blkCh:
@@ -498,14 +511,7 @@ func (n *Node) worker() { //nolint: gocyclo
498511
}
499512
}
500513

501-
func (n *Node) handleCommittee(ctx context.Context, committee *scheduler.Committee) {
502-
if committee.Kind != scheduler.KindComputeExecutor {
503-
return
504-
}
505-
if committee.RuntimeID != n.Runtime.ID() {
506-
return
507-
}
508-
514+
func (n *Node) handleEpoch(ctx context.Context, _ beacon.EpochTime) {
509515
rs, err := n.Consensus.RootHash().GetRuntimeState(ctx, &roothash.RuntimeRequest{
510516
RuntimeID: n.Runtime.ID(),
511517
Height: consensus.HeightLatest,
@@ -526,17 +532,28 @@ func (n *Node) handleCommittee(ctx context.Context, committee *scheduler.Committ
526532
n.handleSuspend()
527533
atomic.StoreUint32(&n.runtimeSuspended, 1)
528534
case false:
529-
n.handleCommitteeTransition(rs.Committee)
530535
atomic.StoreUint32(&n.runtimeSuspended, 0)
531536
}
532537

533-
n.committeeRound = rs.LastBlock.Header.Round
534538
n.activeDescriptor = rs.Runtime
535539

536540
select {
537541
case n.dispatchInfoCh <- struct{}{}:
538542
default:
539543
}
544+
545+
n.TxPool.RecheckTxs()
546+
}
547+
548+
func (n *Node) handleCommittee(ctx context.Context, committee *scheduler.Committee) {
549+
if committee.Kind != scheduler.KindComputeExecutor {
550+
return
551+
}
552+
if committee.RuntimeID != n.Runtime.ID() {
553+
return
554+
}
555+
556+
n.handleCommitteeTransition(committee)
540557
}
541558

542559
func (n *Node) handleRuntimeBlock(ctx context.Context, blk *roothash.AnnotatedBlock) {
@@ -610,21 +627,13 @@ func (n *Node) handleDispatchInfo() {
610627
return
611628
}
612629

613-
if n.lastBlockInfo.RuntimeBlock.Header.Round < n.committeeRound {
614-
return
615-
}
616-
617630
di := &runtime.DispatchInfo{
618631
BlockInfo: n.lastBlockInfo,
619632
ActiveDescriptor: n.activeDescriptor,
620633
}
621634

622635
n.TxPool.ProcessDispatchInfo(di)
623636

624-
if n.lastBlockInfo.RuntimeBlock.Header.Round == n.committeeRound {
625-
n.TxPool.RecheckTxs()
626-
}
627-
628637
for _, hooks := range n.hooks {
629638
hooks.HandleNewDispatchInfo(di)
630639
}

0 commit comments

Comments
 (0)