Skip to content

Commit 07f2ea1

Browse files
mergify[bot]mpoke
andauthored
fix!: enable consumer to be relaunched after failed attempt (backport #2271) (#2272)
fix!: enable consumer to be relaunched after failed attempt (#2271) * enable consumer to be relaunched after failed attempt * fix UT (cherry picked from commit e196a63) Co-authored-by: Marius Poke <[email protected]>
1 parent 76e6ca4 commit 07f2ea1

File tree

3 files changed

+19
-3
lines changed

3 files changed

+19
-3
lines changed

x/ccv/provider/keeper/consumer_lifecycle.go

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -97,6 +97,21 @@ func (k Keeper) BeginBlockLaunchConsumers(ctx sdk.Context) error {
9797
ctx.Logger().Error("could not launch chain",
9898
"consumerId", consumerId,
9999
"error", err)
100+
101+
// reset spawn time to zero so that owner can try again later
102+
initializationRecord, err := k.GetConsumerInitializationParameters(ctx, consumerId)
103+
if err != nil {
104+
return errorsmod.Wrapf(ccv.ErrInvalidConsumerState,
105+
"getting initialization parameters, consumerId(%s): %s", consumerId, err.Error())
106+
}
107+
initializationRecord.SpawnTime = time.Time{}
108+
err = k.SetConsumerInitializationParameters(ctx, consumerId, initializationRecord)
109+
if err != nil {
110+
return fmt.Errorf("setting consumer initialization parameters, consumerId(%s): %w", consumerId, err)
111+
}
112+
// also set the phase to registered
113+
k.SetConsumerPhase(ctx, consumerId, types.CONSUMER_PHASE_REGISTERED)
114+
100115
continue
101116
}
102117

x/ccv/provider/keeper/consumer_lifecycle_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -322,7 +322,7 @@ func TestBeginBlockLaunchConsumers(t *testing.T) {
322322
// fifth chain corresponds to an Opt-In chain with no opted-in validators and hence the
323323
// chain launch is NOT successful
324324
phase = providerKeeper.GetConsumerPhase(ctx, "4")
325-
require.Equal(t, providertypes.CONSUMER_PHASE_INITIALIZED, phase)
325+
require.Equal(t, providertypes.CONSUMER_PHASE_REGISTERED, phase)
326326
_, found = providerKeeper.GetConsumerGenesis(ctx, "4")
327327
require.False(t, found)
328328
}

x/ccv/provider/keeper/msg_server.go

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -406,7 +406,7 @@ func (k msgServer) CreateConsumer(goCtx context.Context, msg *types.MsgCreateCon
406406
if spawnTime, initialized := k.Keeper.InitializeConsumer(ctx, consumerId); initialized {
407407
if err := k.Keeper.PrepareConsumerForLaunch(ctx, consumerId, time.Time{}, spawnTime); err != nil {
408408
return &resp, errorsmod.Wrapf(ccvtypes.ErrInvalidConsumerState,
409-
"cannot prepare chain with consumer id (%s) for launch", consumerId)
409+
"prepare consumer for launch, consumerId(%s), spawnTime(%s): %s", consumerId, spawnTime, err.Error())
410410
}
411411

412412
// add SpawnTime event attribute
@@ -584,7 +584,8 @@ func (k msgServer) UpdateConsumer(goCtx context.Context, msg *types.MsgUpdateCon
584584
if spawnTime, initialized := k.Keeper.InitializeConsumer(ctx, consumerId); initialized {
585585
if err := k.Keeper.PrepareConsumerForLaunch(ctx, consumerId, previousSpawnTime, spawnTime); err != nil {
586586
return &resp, errorsmod.Wrapf(ccvtypes.ErrInvalidConsumerState,
587-
"cannot prepare chain with consumer id (%s) for launch", consumerId)
587+
"prepare consumer for launch, consumerId(%s), previousSpawnTime(%s), spawnTime(%s): %s",
588+
consumerId, previousSpawnTime, spawnTime, err.Error())
588589
}
589590
}
590591

0 commit comments

Comments
 (0)