Skip to content

Commit

Permalink
fix!: enable consumer to be relaunched after failed attempt (backport #…
Browse files Browse the repository at this point in the history
…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]>
  • Loading branch information
mergify[bot] and mpoke authored Sep 13, 2024
1 parent 76e6ca4 commit 07f2ea1
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 3 deletions.
15 changes: 15 additions & 0 deletions x/ccv/provider/keeper/consumer_lifecycle.go
Original file line number Diff line number Diff line change
Expand Up @@ -97,6 +97,21 @@ func (k Keeper) BeginBlockLaunchConsumers(ctx sdk.Context) error {
ctx.Logger().Error("could not launch chain",
"consumerId", consumerId,
"error", err)

// reset spawn time to zero so that owner can try again later
initializationRecord, err := k.GetConsumerInitializationParameters(ctx, consumerId)
if err != nil {
return errorsmod.Wrapf(ccv.ErrInvalidConsumerState,
"getting initialization parameters, consumerId(%s): %s", consumerId, err.Error())
}
initializationRecord.SpawnTime = time.Time{}
err = k.SetConsumerInitializationParameters(ctx, consumerId, initializationRecord)
if err != nil {
return fmt.Errorf("setting consumer initialization parameters, consumerId(%s): %w", consumerId, err)
}
// also set the phase to registered
k.SetConsumerPhase(ctx, consumerId, types.CONSUMER_PHASE_REGISTERED)

continue
}

Expand Down
2 changes: 1 addition & 1 deletion x/ccv/provider/keeper/consumer_lifecycle_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -322,7 +322,7 @@ func TestBeginBlockLaunchConsumers(t *testing.T) {
// fifth chain corresponds to an Opt-In chain with no opted-in validators and hence the
// chain launch is NOT successful
phase = providerKeeper.GetConsumerPhase(ctx, "4")
require.Equal(t, providertypes.CONSUMER_PHASE_INITIALIZED, phase)
require.Equal(t, providertypes.CONSUMER_PHASE_REGISTERED, phase)
_, found = providerKeeper.GetConsumerGenesis(ctx, "4")
require.False(t, found)
}
Expand Down
5 changes: 3 additions & 2 deletions x/ccv/provider/keeper/msg_server.go
Original file line number Diff line number Diff line change
Expand Up @@ -406,7 +406,7 @@ func (k msgServer) CreateConsumer(goCtx context.Context, msg *types.MsgCreateCon
if spawnTime, initialized := k.Keeper.InitializeConsumer(ctx, consumerId); initialized {
if err := k.Keeper.PrepareConsumerForLaunch(ctx, consumerId, time.Time{}, spawnTime); err != nil {
return &resp, errorsmod.Wrapf(ccvtypes.ErrInvalidConsumerState,
"cannot prepare chain with consumer id (%s) for launch", consumerId)
"prepare consumer for launch, consumerId(%s), spawnTime(%s): %s", consumerId, spawnTime, err.Error())
}

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

Expand Down

0 comments on commit 07f2ea1

Please sign in to comment.