Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix!: enable consumer to be relaunched after failed attempt (backport #2271) #2272

Merged
merged 1 commit into from
Sep 13, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading