Skip to content

Commit 16f7555

Browse files
committed
cre-1601: on 1st round make prior outcome wantShards equal to the current data from the arbiter
1 parent 3198932 commit 16f7555

File tree

2 files changed

+12
-10
lines changed

2 files changed

+12
-10
lines changed

pkg/workflows/ring/plugin.go

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -173,15 +173,6 @@ func (p *Plugin) getHealthyShards(shardHealth map[uint32]int) []uint32 {
173173
}
174174

175175
func (p *Plugin) Outcome(_ context.Context, outctx ocr3types.OutcomeContext, _ types.Query, aos []types.AttributedObservation) (ocr3types.Outcome, error) {
176-
// Bootstrap with 1 shard on first round; subsequent rounds build on prior outcome
177-
prior := &pb.Outcome{}
178-
if outctx.PreviousOutcome == nil {
179-
prior.Routes = map[string]*pb.WorkflowRoute{}
180-
prior.State = &pb.RoutingState{Id: outctx.SeqNr, State: &pb.RoutingState_RoutableShards{RoutableShards: 1}}
181-
} else if err := proto.Unmarshal(outctx.PreviousOutcome, prior); err != nil {
182-
return nil, err
183-
}
184-
185176
currentShardHealth, allWorkflows, nows, wantShardVotes := p.collectShardInfo(aos)
186177
p.lggr.Infow("RingOCR Outcome collect shard info", "currentShardHealth", currentShardHealth, "wantShardVotes", wantShardVotes)
187178

@@ -202,6 +193,15 @@ func (p *Plugin) Outcome(_ context.Context, outctx ocr3types.OutcomeContext, _ t
202193
slices.Sort(votes)
203194
wantShards := votes[len(votes)/2]
204195

196+
// Bootstrap from Arbiter's current shard count on 1st round; subsequent rounds build on prior outcome
197+
prior := &pb.Outcome{}
198+
if outctx.PreviousOutcome == nil {
199+
prior.Routes = map[string]*pb.WorkflowRoute{}
200+
prior.State = &pb.RoutingState{Id: outctx.SeqNr, State: &pb.RoutingState_RoutableShards{RoutableShards: wantShards}}
201+
} else if err := proto.Unmarshal(outctx.PreviousOutcome, prior); err != nil {
202+
return nil, err
203+
}
204+
205205
allWorkflows = uniqueSorted(allWorkflows)
206206

207207
healthyShards := p.getHealthyShards(currentShardHealth)

pkg/workflows/ring/plugin_test.go

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -131,7 +131,9 @@ func TestPlugin_Outcome(t *testing.T) {
131131

132132
// Check consensus results
133133
require.NotNil(t, outcomeProto.State)
134-
require.Equal(t, intialSeqNr+1, outcomeProto.State.Id, "ID should match SeqNr")
134+
// When bootstrapping without PreviousOutcome, we use wantShards from observations (3)
135+
// Since consensus wantShards (3) equals bootstrap shards, no transition needed - ID stays the same
136+
require.Equal(t, intialSeqNr, outcomeProto.State.Id, "ID should match SeqNr (no transition needed)")
135137
t.Logf("Outcome - ID: %d, HealthyShards: %v", outcomeProto.State.Id, outcomeProto.State.GetRoutableShards())
136138
t.Logf("Workflows assigned: %d", len(outcomeProto.Routes))
137139

0 commit comments

Comments
 (0)