From 78a14591106bf2b24b22543c6f2d1aa9c9658c49 Mon Sep 17 00:00:00 2001 From: insumity Date: Tue, 3 Sep 2024 17:11:49 +0200 Subject: [PATCH] renamed stop time to removal time --- x/ccv/provider/keeper/consumer_lifecycle.go | 88 +++++++-------- .../keeper/consumer_lifecycle_test.go | 102 +++++++++--------- x/ccv/provider/keeper/msg_server.go | 4 +- x/ccv/provider/keeper/permissionless.go | 8 +- x/ccv/provider/keeper/relay.go | 6 +- x/ccv/provider/keeper/relay_test.go | 10 +- x/ccv/provider/module.go | 2 +- x/ccv/provider/types/errors.go | 2 +- x/ccv/provider/types/keys.go | 48 ++++----- x/ccv/provider/types/keys_test.go | 8 +- 10 files changed, 139 insertions(+), 139 deletions(-) diff --git a/x/ccv/provider/keeper/consumer_lifecycle.go b/x/ccv/provider/keeper/consumer_lifecycle.go index 6f97662557..5c927c7d05 100644 --- a/x/ccv/provider/keeper/consumer_lifecycle.go +++ b/x/ccv/provider/keeper/consumer_lifecycle.go @@ -354,9 +354,9 @@ func (k Keeper) MakeConsumerGenesis( return gen, hash, nil } -// StopAndPrepareForConsumerDeletion sets the phase of the chain to stopped and prepares to get the state of the -// chain deleted after unbonding period elapses -func (k Keeper) StopAndPrepareForConsumerDeletion(ctx sdk.Context, consumerId string) error { +// StopAndPrepareForConsumerRemoval sets the phase of the chain to stopped and prepares to get the state of the +// chain removed after unbonding period elapses +func (k Keeper) StopAndPrepareForConsumerRemoval(ctx sdk.Context, consumerId string) error { // The phase of the chain is immediately set to stopped, albeit its state is removed later (see below). // Setting the phase here helps in not considering this chain when we look at launched chains (e.g., in `QueueVSCPackets) k.SetConsumerPhase(ctx, consumerId, types.ConsumerPhase_CONSUMER_PHASE_STOPPED) @@ -366,23 +366,23 @@ func (k Keeper) StopAndPrepareForConsumerDeletion(ctx sdk.Context, consumerId st if err != nil { return err } - stopTime := ctx.BlockTime().Add(unbondingPeriod) + removalTime := ctx.BlockTime().Add(unbondingPeriod) - if err := k.SetConsumerStopTime(ctx, consumerId, stopTime); err != nil { - return errorsmod.Wrapf(types.ErrInvalidStopTime, "cannot set stop time: %s", err.Error()) + if err := k.SetConsumerRemovalTime(ctx, consumerId, removalTime); err != nil { + return errorsmod.Wrapf(types.ErrInvalidRemovalTime, "cannot set removal time: %s", err.Error()) } - if err := k.AppendConsumerToBeStopped(ctx, consumerId, stopTime); err != nil { - return errorsmod.Wrapf(ccv.ErrInvalidConsumerState, "cannot set consumer to be stopped: %s", err.Error()) + if err := k.AppendConsumerToBeRemoved(ctx, consumerId, removalTime); err != nil { + return errorsmod.Wrapf(ccv.ErrInvalidConsumerState, "cannot set consumer to be removed: %s", err.Error()) } return nil } -// BeginBlockStopConsumers iterates over the pending consumer proposals and stop/removes the chain if the stop time has passed -func (k Keeper) BeginBlockStopConsumers(ctx sdk.Context) { +// BeginBlockRemoveConsumers iterates over the pending consumer proposals and stop/removes the chain if the removal time has passed +func (k Keeper) BeginBlockRemoveConsumers(ctx sdk.Context) { // TODO (PERMISSIONLESS): parameterize the limit for _, consumerId := range k.GetConsumersReadyToStop(ctx, 200) { - stopTime, err := k.GetConsumerStopTime(ctx, consumerId) + removalTime, err := k.GetConsumerRemovalTime(ctx, consumerId) if err != nil { k.Logger(ctx).Error("chain could not be stopped", "consumerId", consumerId, @@ -390,8 +390,8 @@ func (k Keeper) BeginBlockStopConsumers(ctx sdk.Context) { continue } - // Remove consumer to prevent re-trying stopping this chain. - err = k.RemoveConsumerToBeStopped(ctx, consumerId, stopTime) + // Remove consumer to prevent re-trying removing this chain. + err = k.RemoveConsumerToBeRemoved(ctx, consumerId, removalTime) if err != nil { ctx.Logger().Error("could not remove consumer from to-be-stopped queue", "consumerId", consumerId, @@ -416,7 +416,7 @@ func (k Keeper) BeginBlockStopConsumers(ctx sdk.Context) { k.Logger(ctx).Info("executed consumer deletion", "consumer id", consumerId, - "stop time", stopTime, + "removal time", removalTime, ) } } @@ -426,26 +426,26 @@ func (k Keeper) BeginBlockStopConsumers(ctx sdk.Context) { func (k Keeper) GetConsumersReadyToStop(ctx sdk.Context, limit uint32) []string { store := ctx.KVStore(k.storeKey) - stopTimeToConsumerIdsKeyPrefix := types.StopTimeToConsumerIdsKeyPrefix() - iterator := storetypes.KVStorePrefixIterator(store, []byte{stopTimeToConsumerIdsKeyPrefix}) + removalTimeToConsumerIdsKeyPrefix := types.RemovalTimeToConsumerIdsKeyPrefix() + iterator := storetypes.KVStorePrefixIterator(store, []byte{removalTimeToConsumerIdsKeyPrefix}) defer iterator.Close() result := []string{} for ; iterator.Valid(); iterator.Next() { - stopTime, err := types.ParseTime(stopTimeToConsumerIdsKeyPrefix, iterator.Key()) + removalTime, err := types.ParseTime(removalTimeToConsumerIdsKeyPrefix, iterator.Key()) if err != nil { - k.Logger(ctx).Error("failed to parse stop time", + k.Logger(ctx).Error("failed to parse removal time", "error", err) continue } - if stopTime.After(ctx.BlockTime()) { + if removalTime.After(ctx.BlockTime()) { return result } - consumers, err := k.GetConsumersToBeStopped(ctx, stopTime) + consumers, err := k.GetConsumersToBeRemoved(ctx, removalTime) if err != nil { k.Logger(ctx).Error("failed to retrieve consumers to stop", - "stop time", stopTime, + "removal time", removalTime, "error", err) continue } @@ -514,7 +514,7 @@ func (k Keeper) DeleteConsumerChain(ctx sdk.Context, consumerId string) (err err k.DeleteConsumerRewardsAllocation(ctx, consumerId) k.DeleteConsumerOwnerAddress(ctx, consumerId) - k.DeleteConsumerStopTime(ctx, consumerId) + k.DeleteConsumerRemovalTime(ctx, consumerId) // TODO (PERMISSIONLESS) add newly-added state to be deleted // Note that we do not delete ConsumerIdToChainIdKey and ConsumerIdToPhase, as well @@ -530,35 +530,35 @@ func (k Keeper) DeleteConsumerChain(ctx sdk.Context, consumerId string) (err err // Setters and Getters // -// GetConsumerStopTime returns the stop time associated with the to-be-stopped chain with consumer id -func (k Keeper) GetConsumerStopTime(ctx sdk.Context, consumerId string) (time.Time, error) { +// GetConsumerRemovalTime returns the removal time associated with the to-be-removed chain with consumer id +func (k Keeper) GetConsumerRemovalTime(ctx sdk.Context, consumerId string) (time.Time, error) { store := ctx.KVStore(k.storeKey) - buf := store.Get(types.ConsumerIdToStopTimeKey(consumerId)) + buf := store.Get(types.ConsumerIdToRemovalTimeKey(consumerId)) if buf == nil { - return time.Time{}, fmt.Errorf("failed to retrieve stop time for consumer id (%s)", consumerId) + return time.Time{}, fmt.Errorf("failed to retrieve removal time for consumer id (%s)", consumerId) } var time time.Time if err := time.UnmarshalBinary(buf); err != nil { - return time, fmt.Errorf("failed to unmarshal stop time for consumer id (%s): %w", consumerId, err) + return time, fmt.Errorf("failed to unmarshal removal time for consumer id (%s): %w", consumerId, err) } return time, nil } -// SetConsumerStopTime sets the stop time associated with this consumer id -func (k Keeper) SetConsumerStopTime(ctx sdk.Context, consumerId string, stopTime time.Time) error { +// SetConsumerRemovalTime sets the removal time associated with this consumer id +func (k Keeper) SetConsumerRemovalTime(ctx sdk.Context, consumerId string, removalTime time.Time) error { store := ctx.KVStore(k.storeKey) - buf, err := stopTime.MarshalBinary() + buf, err := removalTime.MarshalBinary() if err != nil { - return fmt.Errorf("failed to marshal stop time (%+v) for consumer id (%s): %w", stopTime, consumerId, err) + return fmt.Errorf("failed to marshal removal time (%+v) for consumer id (%s): %w", removalTime, consumerId, err) } - store.Set(types.ConsumerIdToStopTimeKey(consumerId), buf) + store.Set(types.ConsumerIdToRemovalTimeKey(consumerId), buf) return nil } -// DeleteConsumerStopTime deletes the stop time associated with this consumer id -func (k Keeper) DeleteConsumerStopTime(ctx sdk.Context, consumerId string) { +// DeleteConsumerRemovalTime deletes the removal time associated with this consumer id +func (k Keeper) DeleteConsumerRemovalTime(ctx sdk.Context, consumerId string) { store := ctx.KVStore(k.storeKey) - store.Delete(types.ConsumerIdToStopTimeKey(consumerId)) + store.Delete(types.ConsumerIdToRemovalTimeKey(consumerId)) } // getConsumerIdsBasedOnTime returns all the consumer ids stored under this specific `key(time)` @@ -658,17 +658,17 @@ func (k Keeper) RemoveConsumerToBeLaunched(ctx sdk.Context, consumerId string, s return k.removeConsumerIdFromTime(ctx, consumerId, types.SpawnTimeToConsumerIdsKey, spawnTime) } -// GetConsumersToBeStopped returns all the consumer ids of chains stored under this stop time -func (k Keeper) GetConsumersToBeStopped(ctx sdk.Context, stopTime time.Time) (types.ConsumerIds, error) { - return k.getConsumerIdsBasedOnTime(ctx, types.StopTimeToConsumerIdsKey, stopTime) +// GetConsumersToBeRemoved returns all the consumer ids of chains stored under this removal time +func (k Keeper) GetConsumersToBeRemoved(ctx sdk.Context, removalTime time.Time) (types.ConsumerIds, error) { + return k.getConsumerIdsBasedOnTime(ctx, types.RemovalTimeToConsumerIdsKey, removalTime) } -// AppendConsumerToBeStopped appends the provider consumer id for the given stop time -func (k Keeper) AppendConsumerToBeStopped(ctx sdk.Context, consumerId string, stopTime time.Time) error { - return k.appendConsumerIdOnTime(ctx, consumerId, types.StopTimeToConsumerIdsKey, stopTime) +// AppendConsumerToBeRemoved appends the provider consumer id for the given removal time +func (k Keeper) AppendConsumerToBeRemoved(ctx sdk.Context, consumerId string, removalTime time.Time) error { + return k.appendConsumerIdOnTime(ctx, consumerId, types.RemovalTimeToConsumerIdsKey, removalTime) } -// RemoveConsumerToBeStopped removes consumer id from the given stop time -func (k Keeper) RemoveConsumerToBeStopped(ctx sdk.Context, consumerId string, stopTime time.Time) error { - return k.removeConsumerIdFromTime(ctx, consumerId, types.StopTimeToConsumerIdsKey, stopTime) +// RemoveConsumerToBeRemoved removes consumer id from the given removal time +func (k Keeper) RemoveConsumerToBeRemoved(ctx sdk.Context, consumerId string, removalTime time.Time) error { + return k.removeConsumerIdFromTime(ctx, consumerId, types.RemovalTimeToConsumerIdsKey, removalTime) } diff --git a/x/ccv/provider/keeper/consumer_lifecycle_test.go b/x/ccv/provider/keeper/consumer_lifecycle_test.go index c00c2525c0..47e7b4420f 100644 --- a/x/ccv/provider/keeper/consumer_lifecycle_test.go +++ b/x/ccv/provider/keeper/consumer_lifecycle_test.go @@ -648,17 +648,17 @@ func TestBeginBlockStopConsumers(t *testing.T) { chainIds := []string{"chain1", "chain2", "chain3"} consumerIds := []string{"consumerId1", "consumerId2", "consumerId3"} - err := providerKeeper.SetConsumerStopTime(ctx, consumerIds[0], now.Add(-time.Hour)) + err := providerKeeper.SetConsumerRemovalTime(ctx, consumerIds[0], now.Add(-time.Hour)) require.NoError(t, err) - err = providerKeeper.AppendConsumerToBeStopped(ctx, consumerIds[0], now.Add(-time.Hour)) + err = providerKeeper.AppendConsumerToBeRemoved(ctx, consumerIds[0], now.Add(-time.Hour)) require.NoError(t, err) - err = providerKeeper.SetConsumerStopTime(ctx, consumerIds[1], now) + err = providerKeeper.SetConsumerRemovalTime(ctx, consumerIds[1], now) require.NoError(t, err) - err = providerKeeper.AppendConsumerToBeStopped(ctx, consumerIds[1], now) + err = providerKeeper.AppendConsumerToBeRemoved(ctx, consumerIds[1], now) require.NoError(t, err) - err = providerKeeper.SetConsumerStopTime(ctx, consumerIds[2], now.Add(time.Hour)) + err = providerKeeper.SetConsumerRemovalTime(ctx, consumerIds[2], now.Add(time.Hour)) require.NoError(t, err) - err = providerKeeper.AppendConsumerToBeStopped(ctx, consumerIds[2], now.Add(time.Hour)) + err = providerKeeper.AppendConsumerToBeRemoved(ctx, consumerIds[2], now.Add(time.Hour)) require.NoError(t, err) // @@ -703,7 +703,7 @@ func TestBeginBlockStopConsumers(t *testing.T) { err = providerKeeper.SetConsumerChain(ctx, "channelID") require.NoError(t, err) - // the chain is considered to be stopped and ready for deletion (i.e., `StopAndPrepareForConsumerDeletion` is called) + // the chain is considered to be stopped and ready for deletion (i.e., `StopAndPrepareForConsumerRemoval` is called) providerKeeper.SetConsumerPhase(ctx, consumerId, providertypes.ConsumerPhase_CONSUMER_PHASE_STOPPED) } @@ -711,14 +711,14 @@ func TestBeginBlockStopConsumers(t *testing.T) { // Test execution // - providerKeeper.BeginBlockStopConsumers(ctx) + providerKeeper.BeginBlockRemoveConsumers(ctx) // Only the 3rd (final) proposal is still stored as pending phase := providerKeeper.GetConsumerPhase(ctx, consumerIds[0]) require.Equal(t, providertypes.ConsumerPhase_CONSUMER_PHASE_DELETED, phase) phase = providerKeeper.GetConsumerPhase(ctx, consumerIds[1]) require.Equal(t, providertypes.ConsumerPhase_CONSUMER_PHASE_DELETED, phase) - // third chain had a stopTime in the future and hence did not get deleted + // third chain had a removal time in the future and hence did not get deleted phase = providerKeeper.GetConsumerPhase(ctx, consumerIds[2]) require.Equal(t, providertypes.ConsumerPhase_CONSUMER_PHASE_STOPPED, phase) } @@ -730,26 +730,26 @@ func TestGetConsumersReadyToStop(t *testing.T) { // no chains to-be-stopped exist require.Empty(t, providerKeeper.GetConsumersReadyToStop(ctx, 3)) - err := providerKeeper.AppendConsumerToBeStopped(ctx, "consumerId1", time.Unix(10, 0)) + err := providerKeeper.AppendConsumerToBeRemoved(ctx, "consumerId1", time.Unix(10, 0)) require.NoError(t, err) - err = providerKeeper.AppendConsumerToBeStopped(ctx, "consumerId2", time.Unix(20, 0)) + err = providerKeeper.AppendConsumerToBeRemoved(ctx, "consumerId2", time.Unix(20, 0)) require.NoError(t, err) - err = providerKeeper.AppendConsumerToBeStopped(ctx, "consumerId3", time.Unix(30, 0)) + err = providerKeeper.AppendConsumerToBeRemoved(ctx, "consumerId3", time.Unix(30, 0)) require.NoError(t, err) - // time has not yet reached the stop time of "consumerId1" + // time has not yet reached the removal time of "consumerId1" ctx = ctx.WithBlockTime(time.Unix(9, 999999999)) require.Empty(t, providerKeeper.GetConsumersReadyToStop(ctx, 3)) - // time has reached the stop time of "consumerId1" + // time has reached the removal time of "consumerId1" ctx = ctx.WithBlockTime(time.Unix(10, 0)) require.Equal(t, []string{"consumerId1"}, providerKeeper.GetConsumersReadyToStop(ctx, 3)) - // time has reached the stop time of "consumerId1" and "consumerId2" + // time has reached the removal time of "consumerId1" and "consumerId2" ctx = ctx.WithBlockTime(time.Unix(20, 0)) require.Equal(t, []string{"consumerId1", "consumerId2"}, providerKeeper.GetConsumersReadyToStop(ctx, 3)) - // time has reached the stop time of all chains + // time has reached the removal time of all chains ctx = ctx.WithBlockTime(time.Unix(30, 0)) require.Equal(t, []string{"consumerId1", "consumerId2", "consumerId3"}, providerKeeper.GetConsumersReadyToStop(ctx, 3)) } @@ -820,22 +820,22 @@ func TestStopConsumerChain(t *testing.T) { // Setters and Getters // -// TestConsumerStopTime tests the getter, setter, and deletion of the consumer id to stop times methods -func TestConsumerStopTime(t *testing.T) { +// TestConsumerRemovalTime tests the getter, setter, and deletion of the consumer id to removal times methods +func TestConsumerRemovalTime(t *testing.T) { providerKeeper, ctx, ctrl, _ := testkeeper.GetProviderKeeperAndCtx(t, testkeeper.NewInMemKeeperParams(t)) defer ctrl.Finish() - _, err := providerKeeper.GetConsumerStopTime(ctx, "consumerId") + _, err := providerKeeper.GetConsumerRemovalTime(ctx, "consumerId") require.Error(t, err) - expectedStopTime := time.Unix(1234, 56789) - providerKeeper.SetConsumerStopTime(ctx, "consumerId", expectedStopTime) - actualStopTime, err := providerKeeper.GetConsumerStopTime(ctx, "consumerId") + expectedRemovalTime := time.Unix(1234, 56789) + providerKeeper.SetConsumerRemovalTime(ctx, "consumerId", expectedRemovalTime) + actualRemovalTime, err := providerKeeper.GetConsumerRemovalTime(ctx, "consumerId") require.NoError(t, err) - require.Equal(t, actualStopTime, expectedStopTime) + require.Equal(t, actualRemovalTime, expectedRemovalTime) - providerKeeper.DeleteConsumerStopTime(ctx, "consumerId") - _, err = providerKeeper.GetConsumerStopTime(ctx, "consumerId") + providerKeeper.DeleteConsumerRemovalTime(ctx, "consumerId") + _, err = providerKeeper.GetConsumerRemovalTime(ctx, "consumerId") require.Error(t, err) } @@ -905,68 +905,68 @@ func TestConsumersToBeLaunched(t *testing.T) { require.Equal(t, []string{"consumerId5"}, consumers.Ids) } -// TestConsumersToBeStopped tests `AppendConsumerToBeLaunched`, `GetConsumersToBeLaunched`, and `RemoveConsumerToBeLaunched` -func TestConsumersToBeStopped(t *testing.T) { +// TestConsumersToBeRemoved tests `AppendConsumerToBeRemoved`, `GetConsumersToBeRemoved`, and `RemoveConsumerToBeRemoved` +func TestConsumersToBeRemoved(t *testing.T) { providerKeeper, ctx, ctrl, _ := testkeeper.GetProviderKeeperAndCtx(t, testkeeper.NewInMemKeeperParams(t)) defer ctrl.Finish() - stopTime := time.Now() - err := providerKeeper.AppendConsumerToBeStopped(ctx, "consumerId1", stopTime) + removalTime := time.Now() + err := providerKeeper.AppendConsumerToBeRemoved(ctx, "consumerId1", removalTime) require.NoError(t, err) - consumers, err := providerKeeper.GetConsumersToBeStopped(ctx, stopTime) + consumers, err := providerKeeper.GetConsumersToBeRemoved(ctx, removalTime) require.NoError(t, err) require.Equal(t, []string{"consumerId1"}, consumers.Ids) - err = providerKeeper.AppendConsumerToBeStopped(ctx, "consumerId2", stopTime) + err = providerKeeper.AppendConsumerToBeRemoved(ctx, "consumerId2", removalTime) require.NoError(t, err) - consumers, err = providerKeeper.GetConsumersToBeStopped(ctx, stopTime) + consumers, err = providerKeeper.GetConsumersToBeRemoved(ctx, removalTime) require.NoError(t, err) require.Equal(t, []string{"consumerId1", "consumerId2"}, consumers.Ids) - err = providerKeeper.AppendConsumerToBeStopped(ctx, "consumerId3", stopTime) + err = providerKeeper.AppendConsumerToBeRemoved(ctx, "consumerId3", removalTime) require.NoError(t, err) - consumers, err = providerKeeper.GetConsumersToBeStopped(ctx, stopTime) + consumers, err = providerKeeper.GetConsumersToBeRemoved(ctx, removalTime) require.NoError(t, err) require.Equal(t, []string{"consumerId1", "consumerId2", "consumerId3"}, consumers.Ids) - err = providerKeeper.RemoveConsumerToBeStopped(ctx, "consumerId2", stopTime) + err = providerKeeper.RemoveConsumerToBeRemoved(ctx, "consumerId2", removalTime) require.NoError(t, err) - consumers, err = providerKeeper.GetConsumersToBeStopped(ctx, stopTime) + consumers, err = providerKeeper.GetConsumersToBeRemoved(ctx, removalTime) require.NoError(t, err) require.Equal(t, []string{"consumerId1", "consumerId3"}, consumers.Ids) - // also add consumer ids under a different stop time and verify everything under the original stop time is still there - stopTimePlusOneHour := stopTime.Add(time.Hour) - err = providerKeeper.AppendConsumerToBeStopped(ctx, "consumerId4", stopTimePlusOneHour) + // also add consumer ids under a different removal time and verify everything under the original removal time is still there + removalTimePlusOneHour := removalTime.Add(time.Hour) + err = providerKeeper.AppendConsumerToBeRemoved(ctx, "consumerId4", removalTimePlusOneHour) require.NoError(t, err) - consumers, err = providerKeeper.GetConsumersToBeStopped(ctx, stopTimePlusOneHour) + consumers, err = providerKeeper.GetConsumersToBeRemoved(ctx, removalTimePlusOneHour) require.NoError(t, err) require.Equal(t, []string{"consumerId4"}, consumers.Ids) - consumers, err = providerKeeper.GetConsumersToBeStopped(ctx, stopTime) + consumers, err = providerKeeper.GetConsumersToBeRemoved(ctx, removalTime) require.NoError(t, err) require.Equal(t, []string{"consumerId1", "consumerId3"}, consumers.Ids) - // start removing all consumers from `stopTime` - err = providerKeeper.RemoveConsumerToBeStopped(ctx, "consumerId3", stopTime) + // start removing all consumers from `removalTime` + err = providerKeeper.RemoveConsumerToBeRemoved(ctx, "consumerId3", removalTime) require.NoError(t, err) - err = providerKeeper.RemoveConsumerToBeStopped(ctx, "consumerId1", stopTime) + err = providerKeeper.RemoveConsumerToBeRemoved(ctx, "consumerId1", removalTime) require.NoError(t, err) - consumers, err = providerKeeper.GetConsumersToBeStopped(ctx, stopTime) + consumers, err = providerKeeper.GetConsumersToBeRemoved(ctx, removalTime) require.NoError(t, err) require.Empty(t, consumers.Ids) - // remove from `stopTimePlusOneHour` - err = providerKeeper.RemoveConsumerToBeStopped(ctx, "consumerId4", stopTimePlusOneHour) + // remove from `removalTimePlusOneHour` + err = providerKeeper.RemoveConsumerToBeRemoved(ctx, "consumerId4", removalTimePlusOneHour) require.NoError(t, err) - consumers, err = providerKeeper.GetConsumersToBeStopped(ctx, stopTimePlusOneHour) + consumers, err = providerKeeper.GetConsumersToBeRemoved(ctx, removalTimePlusOneHour) require.NoError(t, err) require.Empty(t, consumers.Ids) - // add another consumer for `stopTime` - err = providerKeeper.AppendConsumerToBeStopped(ctx, "consumerId5", stopTime) + // add another consumer for `removalTime` + err = providerKeeper.AppendConsumerToBeRemoved(ctx, "consumerId5", removalTime) require.NoError(t, err) - consumers, err = providerKeeper.GetConsumersToBeStopped(ctx, stopTime) + consumers, err = providerKeeper.GetConsumersToBeRemoved(ctx, removalTime) require.NoError(t, err) require.Equal(t, []string{"consumerId5"}, consumers.Ids) } diff --git a/x/ccv/provider/keeper/msg_server.go b/x/ccv/provider/keeper/msg_server.go index ed74b8f9d8..b24e09ae4d 100644 --- a/x/ccv/provider/keeper/msg_server.go +++ b/x/ccv/provider/keeper/msg_server.go @@ -343,7 +343,7 @@ func (k msgServer) CreateConsumer(goCtx context.Context, msg *types.MsgCreateCon return &resp, nil } -// UpdateConsumer updates the record of a consumer chain +// UpdateConsumer updates the metadata, power-shaping or initialization parameters of a consumer chain func (k msgServer) UpdateConsumer(goCtx context.Context, msg *types.MsgUpdateConsumer) (*types.MsgUpdateConsumerResponse, error) { ctx := sdk.UnwrapSDKContext(goCtx) resp := types.MsgUpdateConsumerResponse{} @@ -473,7 +473,7 @@ func (k msgServer) RemoveConsumer(goCtx context.Context, msg *types.MsgRemoveCon "chain with consumer id: %s has to be in its launched phase", consumerId) } - err = k.Keeper.StopAndPrepareForConsumerDeletion(ctx, consumerId) + err = k.Keeper.StopAndPrepareForConsumerRemoval(ctx, consumerId) return &resp, err } diff --git a/x/ccv/provider/keeper/permissionless.go b/x/ccv/provider/keeper/permissionless.go index ecedda108d..039b016ffd 100644 --- a/x/ccv/provider/keeper/permissionless.go +++ b/x/ccv/provider/keeper/permissionless.go @@ -119,11 +119,11 @@ func (k Keeper) GetConsumerInitializationParameters(ctx sdk.Context, consumerId if bz == nil { return types.ConsumerInitializationParameters{}, fmt.Errorf("failed to retrieve initialization parameters for consumer id (%s)", consumerId) } - var record types.ConsumerInitializationParameters - if err := record.Unmarshal(bz); err != nil { - return types.ConsumerInitializationParameters{}, fmt.Errorf("failed to unmarshal stop time for consumer id (%s): %w", consumerId, err) + var initializationParameters types.ConsumerInitializationParameters + if err := initializationParameters.Unmarshal(bz); err != nil { + return types.ConsumerInitializationParameters{}, fmt.Errorf("failed to unmarshal initialization parameters for consumer id (%s): %w", consumerId, err) } - return record, nil + return initializationParameters, nil } // SetConsumerInitializationParameters sets the initialization parameters associated with this consumer id diff --git a/x/ccv/provider/keeper/relay.go b/x/ccv/provider/keeper/relay.go index ad26912013..b0a9024528 100644 --- a/x/ccv/provider/keeper/relay.go +++ b/x/ccv/provider/keeper/relay.go @@ -30,7 +30,7 @@ func (k Keeper) OnAcknowledgementPacket(ctx sdk.Context, packet channeltypes.Pac "error", err, ) if consumerId, ok := k.GetChannelIdToConsumerId(ctx, packet.SourceChannel); ok { - return k.StopAndPrepareForConsumerDeletion(ctx, consumerId) + return k.StopAndPrepareForConsumerRemoval(ctx, consumerId) } return errorsmod.Wrapf(providertypes.ErrUnknownConsumerChannelId, "recv ErrorAcknowledgement on unknown channel %s", packet.SourceChannel) } @@ -50,7 +50,7 @@ func (k Keeper) OnTimeoutPacket(ctx sdk.Context, packet channeltypes.Packet) err ) } k.Logger(ctx).Info("packet timeout, deleting the consumer:", "consumerId", consumerId) - return k.StopAndPrepareForConsumerDeletion(ctx, consumerId) + return k.StopAndPrepareForConsumerRemoval(ctx, consumerId) } // EndBlockVSU contains the EndBlock logic needed for @@ -166,7 +166,7 @@ func (k Keeper) SendVSCPacketsToChain(ctx sdk.Context, consumerId, channelId str // Not able to send packet over IBC! k.Logger(ctx).Error("cannot send VSC, removing consumer:", "consumerId", consumerId, "vscid", data.ValsetUpdateId, "err", err.Error()) - err := k.StopAndPrepareForConsumerDeletion(ctx, consumerId) + err := k.StopAndPrepareForConsumerRemoval(ctx, consumerId) if err != nil { k.Logger(ctx).Info("consumer chain failed to stop:", "consumerId", consumerId, "error", err.Error()) } diff --git a/x/ccv/provider/keeper/relay_test.go b/x/ccv/provider/keeper/relay_test.go index 4bd95b7d0f..088590f206 100644 --- a/x/ccv/provider/keeper/relay_test.go +++ b/x/ccv/provider/keeper/relay_test.go @@ -514,13 +514,13 @@ func TestSendVSCPacketsToChainFailure(t *testing.T) { providerKeeper.SendVSCPacketsToChain(ctx, "consumerId", "CCVChannelID") // Verify the chain is about to be deleted - stopTime, err := providerKeeper.GetConsumerStopTime(ctx, "consumerId") + removalTime, err := providerKeeper.GetConsumerRemovalTime(ctx, "consumerId") require.NoError(t, err) - require.Equal(t, ctx.BlockTime().Add(unbondingTime), stopTime) + require.Equal(t, ctx.BlockTime().Add(unbondingTime), removalTime) // Increase the block time by `unbondingTime` so the chain actually gets deleted ctx = ctx.WithBlockTime(ctx.BlockTime().Add(unbondingTime)) - providerKeeper.BeginBlockStopConsumers(ctx) + providerKeeper.BeginBlockRemoveConsumers(ctx) // Pending VSC packets should be deleted in DeleteConsumerChain require.Empty(t, providerKeeper.GetPendingVSCPackets(ctx, "consumerId")) @@ -570,7 +570,7 @@ func TestOnTimeoutPacketStopsChain(t *testing.T) { // increase the block time by `unbondingTime` so the chain actually gets deleted ctx = ctx.WithBlockTime(ctx.BlockTime().Add(unbondingTime)) - providerKeeper.BeginBlockStopConsumers(ctx) + providerKeeper.BeginBlockRemoveConsumers(ctx) testkeeper.TestProviderStateIsCleanedAfterConsumerChainIsDeleted(t, ctx, providerKeeper, "consumerId", "channelID", false) } @@ -621,7 +621,7 @@ func TestOnAcknowledgementPacketWithAckError(t *testing.T) { // increase the block time by `unbondingTime` so the chain actually gets deleted ctx = ctx.WithBlockTime(ctx.BlockTime().Add(unbondingTime)) - providerKeeper.BeginBlockStopConsumers(ctx) + providerKeeper.BeginBlockRemoveConsumers(ctx) testkeeper.TestProviderStateIsCleanedAfterConsumerChainIsDeleted(t, ctx, providerKeeper, "consumerId", "channelID", false) } diff --git a/x/ccv/provider/module.go b/x/ccv/provider/module.go index 30ac49363a..2f089509ee 100644 --- a/x/ccv/provider/module.go +++ b/x/ccv/provider/module.go @@ -176,7 +176,7 @@ func (am AppModule) BeginBlock(ctx context.Context) error { // Create clients to consumer chains that are due to be spawned am.keeper.BeginBlockLaunchConsumers(sdkCtx) // Stop and remove state for any consumer chains that are due to be stopped - am.keeper.BeginBlockStopConsumers(sdkCtx) + am.keeper.BeginBlockRemoveConsumers(sdkCtx) // Check for replenishing slash meter before any slash packets are processed for this block am.keeper.BeginBlockCIS(sdkCtx) // BeginBlock logic needed for the Reward Distribution sub-protocol diff --git a/x/ccv/provider/types/errors.go b/x/ccv/provider/types/errors.go index b4fe49942f..933e363f73 100644 --- a/x/ccv/provider/types/errors.go +++ b/x/ccv/provider/types/errors.go @@ -36,7 +36,7 @@ var ( ErrInvalidTransformToOptIn = errorsmod.Register(ModuleName, 40, "invalid transform to Opt In chain") ErrCannotCreateTopNChain = errorsmod.Register(ModuleName, 41, "cannot create Top N chain outside permissionlessly") ErrCannotPrepareForLaunch = errorsmod.Register(ModuleName, 42, "cannot prepare chain for launch") - ErrInvalidStopTime = errorsmod.Register(ModuleName, 43, "invalid stop time") + ErrInvalidRemovalTime = errorsmod.Register(ModuleName, 43, "invalid removal time") ErrInvalidMsgCreateConsumer = errorsmod.Register(ModuleName, 44, "invalid create consumer message") ErrInvalidMsgUpdateConsumer = errorsmod.Register(ModuleName, 45, "invalid update consumer message") ErrInvalidMsgAssignConsumerKey = errorsmod.Register(ModuleName, 46, "invalid assign consumer key message") diff --git a/x/ccv/provider/types/keys.go b/x/ccv/provider/types/keys.go index 5f6010d260..ef7eae0172 100644 --- a/x/ccv/provider/types/keys.go +++ b/x/ccv/provider/types/keys.go @@ -139,11 +139,11 @@ const ( ConsumerIdToPhaseKeyName = "ConsumerIdToPhaseKey" - ConsumerIdToStopTimeKeyName = "ConsumerIdToStopTimeKey" + ConsumerIdToRemovalTimeKeyName = "ConsumerIdToRemovalTimeKey" SpawnTimeToConsumerIdsKeyName = "SpawnTimeToConsumerIdsKeyName" - StopTimeToConsumerIdsKeyName = "StopTimeToConsumerIdsKeyName" + RemovalTimeToConsumerIdsKeyName = "RemovalTimeToConsumerIdsKeyName" ProviderConsAddrToOptedInConsumerIdsKeyName = "ProviderConsAddrToOptedInConsumerIdsKeyName" @@ -364,16 +364,16 @@ func getKeyPrefixes() map[string]byte { // ConsumerIdToPhaseKeyName is the key for storing the phase of a consumer chain with the given consumer id ConsumerIdToPhaseKeyName: 49, - // ConsumerIdToStopTimeKeyName is the key for storing the stop time of a consumer chain that is to be removed - ConsumerIdToStopTimeKeyName: 50, + // ConsumerIdToRemovalTimeKeyName is the key for storing the removal time of a consumer chain that is to be removed + ConsumerIdToRemovalTimeKeyName: 50, // SpawnTimeToConsumerIdKeyName is the key for storing pending initialized consumers that are to be launched. // For a specific spawn time, it might store multiple consumer chain ids for chains that are to be launched. SpawnTimeToConsumerIdsKeyName: 51, - // StopTimeToConsumerIdKeyName is the key for storing pending launched consumers that are to be stopped. - // For a specific stop time, it might store multiple consumer chain ids for chains that are to be stopped. - StopTimeToConsumerIdsKeyName: 52, + // RemovalTimeToConsumerIdsKeyName is the key for storing pending launched consumers that are to be removed. + // For a specific removal time, it might store multiple consumer chain ids for chains that are to be removed. + RemovalTimeToConsumerIdsKeyName: 52, // ProviderConsAddrToOptedInConsumerIdsKeyName is the key for storing all the consumer ids that a validator // is currently opted in to. @@ -665,17 +665,17 @@ func ConsumerIdToMetadataKey(consumerId string) []byte { return StringIdWithLenKey(ConsumerIdToMetadataKeyPrefix(), consumerId) } -// ConsumerIdToInitializationParametersKeyPrefix returns the key prefix for storing consumer initialization records +// ConsumerIdToInitializationParametersKeyPrefix returns the key prefix for storing consumer initialization parameters func ConsumerIdToInitializationParametersKeyPrefix() byte { return mustGetKeyPrefix(ConsumerIdToInitializationParametersKeyName) } -// ConsumerIdToInitializationParametersKey returns the key used to store the initialization record that corresponds to this consumer id +// ConsumerIdToInitializationParametersKey returns the key used to store the initialization parameters that corresponds to this consumer id func ConsumerIdToInitializationParametersKey(consumerId string) []byte { return StringIdWithLenKey(ConsumerIdToInitializationParametersKeyPrefix(), consumerId) } -// ConsumerIdToPowerShapingParametersKey returns the key used to store the update record that corresponds to this consumer id +// ConsumerIdToPowerShapingParametersKey returns the key used to store the power-shaping parameters that corresponds to this consumer id func ConsumerIdToPowerShapingParametersKey(consumerId string) []byte { return StringIdWithLenKey(mustGetKeyPrefix(ConsumerIdToPowerShapingParameters), consumerId) } @@ -685,15 +685,15 @@ func ConsumerIdToPhaseKey(consumerId string) []byte { return StringIdWithLenKey(mustGetKeyPrefix(ConsumerIdToPhaseKeyName), consumerId) } -// ConsumerIdToStopTimeKeyPrefix returns the key prefix for storing the stop times of consumer chains -// that are about to be stopped -func ConsumerIdToStopTimeKeyPrefix() byte { - return mustGetKeyPrefix(ConsumerIdToStopTimeKeyName) +// ConsumerIdToRemovalTimeKeyPrefix returns the key prefix for storing the removal times of consumer chains +// that are about to be removed +func ConsumerIdToRemovalTimeKeyPrefix() byte { + return mustGetKeyPrefix(ConsumerIdToRemovalTimeKeyName) } -// ConsumerIdToStopTimeKey returns the key used to store the stop time that corresponds to a to-be-stopped chain with consumer id -func ConsumerIdToStopTimeKey(consumerId string) []byte { - return StringIdWithLenKey(ConsumerIdToStopTimeKeyPrefix(), consumerId) +// ConsumerIdToRemovalTimeKey returns the key used to store the removal time that corresponds to a to-be-removed chain with consumer id +func ConsumerIdToRemovalTimeKey(consumerId string) []byte { + return StringIdWithLenKey(ConsumerIdToRemovalTimeKeyPrefix(), consumerId) } // SpawnTimeToConsumerIdsKeyPrefix returns the key prefix for storing pending chains that are to be launched @@ -712,17 +712,17 @@ func SpawnTimeToConsumerIdsKey(spawnTime time.Time) []byte { ) } -// StopTimeToConsumerIdsKeyPrefix returns the key prefix for storing pending chains that are to be stopped -func StopTimeToConsumerIdsKeyPrefix() byte { - return mustGetKeyPrefix(StopTimeToConsumerIdsKeyName) +// RemovalTimeToConsumerIdsKeyPrefix returns the key prefix for storing pending chains that are to be removed +func RemovalTimeToConsumerIdsKeyPrefix() byte { + return mustGetKeyPrefix(RemovalTimeToConsumerIdsKeyName) } -// StopTimeToConsumerIdsKey returns the key prefix for storing the stop times of consumer chains -// that are about to be stopped -func StopTimeToConsumerIdsKey(spawnTime time.Time) []byte { +// RemovalTimeToConsumerIdsKey returns the key prefix for storing the removal times of consumer chains +// that are about to be removed +func RemovalTimeToConsumerIdsKey(spawnTime time.Time) []byte { return ccvtypes.AppendMany( // append the prefix - []byte{StopTimeToConsumerIdsKeyPrefix()}, + []byte{RemovalTimeToConsumerIdsKeyPrefix()}, // append the time sdk.FormatTimeBytes(spawnTime), ) diff --git a/x/ccv/provider/types/keys_test.go b/x/ccv/provider/types/keys_test.go index 741b036c78..92ec762845 100644 --- a/x/ccv/provider/types/keys_test.go +++ b/x/ccv/provider/types/keys_test.go @@ -134,11 +134,11 @@ func TestPreserveBytePrefix(t *testing.T) { i++ require.Equal(t, byte(49), providertypes.ConsumerIdToPhaseKey("13")[0]) i++ - require.Equal(t, byte(50), providertypes.ConsumerIdToStopTimeKeyPrefix()) + require.Equal(t, byte(50), providertypes.ConsumerIdToRemovalTimeKeyPrefix()) i++ require.Equal(t, byte(51), providertypes.SpawnTimeToConsumerIdsKeyPrefix()) i++ - require.Equal(t, byte(52), providertypes.StopTimeToConsumerIdsKeyPrefix()) + require.Equal(t, byte(52), providertypes.RemovalTimeToConsumerIdsKeyPrefix()) i++ require.Equal(t, byte(53), providertypes.ProviderConsAddrToOptedInConsumerIdsKey(providertypes.NewProviderConsAddress([]byte{0x05}))[0]) i++ @@ -208,9 +208,9 @@ func getAllFullyDefinedKeys() [][]byte { providertypes.ConsumerIdToInitializationParametersKey("13"), providertypes.ConsumerIdToPowerShapingParametersKey("13"), providertypes.ConsumerIdToPhaseKey("13"), - providertypes.ConsumerIdToStopTimeKey("13"), + providertypes.ConsumerIdToRemovalTimeKey("13"), providertypes.SpawnTimeToConsumerIdsKey(time.Time{}), - providertypes.StopTimeToConsumerIdsKey(time.Time{}), + providertypes.RemovalTimeToConsumerIdsKey(time.Time{}), providertypes.ProviderConsAddrToOptedInConsumerIdsKey(providertypes.NewProviderConsAddress([]byte{0x05})), providertypes.ClientIdToConsumerIdKey("clientId"), }