Skip to content

Commit 97daa92

Browse files
authored
fix: address comments from permissionless review (#2237)
* AttributeConsumerSpawnTime only on InitializeConsumer * fix error message for ValidateByteSlice * remove unnecessary errors * fix comments * add comment for consumer genesis creation * adding comment on why not removing all consumer state * improve comments
1 parent 7f99da3 commit 97daa92

File tree

5 files changed

+19
-22
lines changed

5 files changed

+19
-22
lines changed

x/ccv/provider/keeper/consumer_lifecycle.go

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,7 @@ func (k Keeper) InitializeConsumer(ctx sdk.Context, consumerId string) (time.Tim
6060
return initializationParameters.SpawnTime, true
6161
}
6262

63-
// BeginBlockLaunchConsumers launches initialized consumers that are ready to launch
63+
// BeginBlockLaunchConsumers launches initialized consumers chains for which the spawn time has passed
6464
func (k Keeper) BeginBlockLaunchConsumers(ctx sdk.Context) error {
6565
consumerIds, err := k.ConsumeIdsFromTimeQueue(
6666
ctx,
@@ -204,10 +204,10 @@ func (k Keeper) CreateConsumerClient(ctx sdk.Context, consumerId string) error {
204204
// Set minimum height for equivocation evidence from this consumer chain
205205
k.SetEquivocationEvidenceMinHeight(ctx, consumerId, initializationRecord.InitialHeight.RevisionHeight)
206206

207-
// Consumers start out with the unbonding period from the consumer addition prop
207+
// Consumers start out with the unbonding period from the initialization parameters
208208
consumerUnbondingPeriod := initializationRecord.UnbondingPeriod
209209

210-
// Create client state by getting template client from parameters and filling in zeroed fields from proposal.
210+
// Create client state by getting template client from initialization parameters
211211
clientState := k.GetTemplateClient(ctx)
212212
clientState.ChainId = chainId
213213
clientState.LatestHeight = initializationRecord.InitialHeight
@@ -351,6 +351,8 @@ func (k Keeper) MakeConsumerGenesis(
351351
}
352352
hash := tmtypes.NewValidatorSet(updatesAsValSet).Hash()
353353

354+
// note that providerFeePoolAddrStr is sent to the consumer during the IBC Channel handshake;
355+
// see HandshakeMetadata in OnChanOpenTry on the provider-side, and OnChanOpenAck on the consumer-side
354356
consumerGenesisParams := ccv.NewParams(
355357
true,
356358
initializationRecord.BlocksPerDistributionTransmission,
@@ -399,7 +401,7 @@ func (k Keeper) StopAndPrepareForConsumerRemoval(ctx sdk.Context, consumerId str
399401
return nil
400402
}
401403

402-
// BeginBlockRemoveConsumers iterates over the pending consumer proposals and stop/removes the chain if the removal time has passed
404+
// BeginBlockRemoveConsumers removes stopped consumer chain for which the removal time has passed
403405
func (k Keeper) BeginBlockRemoveConsumers(ctx sdk.Context) error {
404406
consumerIds, err := k.ConsumeIdsFromTimeQueue(
405407
ctx,
@@ -483,8 +485,11 @@ func (k Keeper) DeleteConsumerChain(ctx sdk.Context, consumerId string) (err err
483485
k.DeleteConsumerRemovalTime(ctx, consumerId)
484486

485487
// TODO (PERMISSIONLESS) add newly-added state to be deleted
488+
486489
// Note that we do not delete ConsumerIdToChainIdKey and ConsumerIdToPhase, as well
487490
// as consumer metadata, initialization and power-shaping parameters.
491+
// This is to enable block explorers and front ends to show information of
492+
// consumer chains that were removed without needing an archive node.
488493

489494
k.SetConsumerPhase(ctx, consumerId, types.CONSUMER_PHASE_DELETED)
490495
k.Logger(ctx).Info("consumer chain deleted from provider", "consumerId", consumerId)

x/ccv/provider/keeper/msg_server.go

Lines changed: 8 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -386,11 +386,6 @@ func (k msgServer) CreateConsumer(goCtx context.Context, msg *types.MsgCreateCon
386386
return &resp, errorsmod.Wrapf(types.ErrInvalidConsumerInitializationParameters,
387387
"cannot set consumer initialization parameters: %s", err.Error())
388388
}
389-
if !initializationParameters.SpawnTime.IsZero() {
390-
// add SpawnTime event attribute
391-
eventAttributes = append(eventAttributes,
392-
sdk.NewAttribute(types.AttributeConsumerSpawnTime, initializationParameters.SpawnTime.String()))
393-
}
394389

395390
// power-shaping parameters are optional and hence could be nil;
396391
// in that case, set the default
@@ -413,6 +408,10 @@ func (k msgServer) CreateConsumer(goCtx context.Context, msg *types.MsgCreateCon
413408
return &resp, errorsmod.Wrapf(ccvtypes.ErrInvalidConsumerState,
414409
"cannot prepare chain with consumer id (%s) for launch", consumerId)
415410
}
411+
412+
// add SpawnTime event attribute
413+
eventAttributes = append(eventAttributes,
414+
sdk.NewAttribute(types.AttributeConsumerSpawnTime, initializationParameters.SpawnTime.String()))
416415
}
417416

418417
// add Phase event attribute
@@ -508,12 +507,6 @@ func (k msgServer) UpdateConsumer(goCtx context.Context, msg *types.MsgUpdateCon
508507
return &resp, errorsmod.Wrapf(types.ErrInvalidConsumerInitializationParameters,
509508
"cannot set consumer initialization parameters: %s", err.Error())
510509
}
511-
512-
if !msg.InitializationParameters.SpawnTime.IsZero() {
513-
// add SpawnTime event attribute
514-
eventAttributes = append(eventAttributes,
515-
sdk.NewAttribute(types.AttributeConsumerSpawnTime, msg.InitializationParameters.SpawnTime.String()))
516-
}
517510
}
518511

519512
if msg.PowerShapingParameters != nil {
@@ -569,6 +562,10 @@ func (k msgServer) UpdateConsumer(goCtx context.Context, msg *types.MsgUpdateCon
569562
return &resp, errorsmod.Wrapf(ccvtypes.ErrInvalidConsumerState,
570563
"cannot prepare chain with consumer id (%s) for launch", consumerId)
571564
}
565+
566+
// add SpawnTime event attribute
567+
eventAttributes = append(eventAttributes,
568+
sdk.NewAttribute(types.AttributeConsumerSpawnTime, msg.InitializationParameters.SpawnTime.String()))
572569
}
573570

574571
// add Owner event attribute

x/ccv/provider/keeper/params.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ import (
1111
"github.com/cosmos/interchain-security/v6/x/ccv/provider/types"
1212
)
1313

14-
// GetTemplateClient returns the template client for provider proposals
14+
// GetTemplateClient returns the template consumer client
1515
func (k Keeper) GetTemplateClient(ctx sdk.Context) *ibctmtypes.ClientState {
1616
params := k.GetParams(ctx)
1717
return params.TemplateClient

x/ccv/provider/types/errors.go

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -6,21 +6,16 @@ import (
66

77
// Provider sentinel errors
88
var (
9-
ErrInvalidConsumerAdditionProposal = errorsmod.Register(ModuleName, 1, "invalid consumer addition proposal")
10-
ErrInvalidConsumerRemovalProp = errorsmod.Register(ModuleName, 2, "invalid consumer removal proposal")
119
ErrUnknownConsumerId = errorsmod.Register(ModuleName, 3, "no consumer chain with this consumer id")
1210
ErrUnknownConsumerChannelId = errorsmod.Register(ModuleName, 4, "no consumer chain with this channel id")
1311
ErrInvalidConsumerId = errorsmod.Register(ModuleName, 6, "invalid consumer id")
1412
ErrConsumerKeyInUse = errorsmod.Register(ModuleName, 10, "consumer key is already in use by a validator")
1513
ErrCannotAssignDefaultKeyAssignment = errorsmod.Register(ModuleName, 11, "cannot re-assign default key assignment")
1614
ErrInvalidConsumerRewardDenom = errorsmod.Register(ModuleName, 14, "invalid consumer reward denom")
1715
ErrInvalidConsumerClient = errorsmod.Register(ModuleName, 16, "ccv channel is not built on correct client")
18-
ErrConsumerChainNotFound = errorsmod.Register(ModuleName, 18, "consumer chain not found")
1916
ErrCannotOptOutFromTopN = errorsmod.Register(ModuleName, 20, "cannot opt out from a Top N chain")
20-
ErrInvalidConsumerModificationProposal = errorsmod.Register(ModuleName, 22, "invalid consumer modification proposal")
2117
ErrNoUnbondingTime = errorsmod.Register(ModuleName, 23, "provider unbonding time not found")
2218
ErrUnauthorized = errorsmod.Register(ModuleName, 25, "unauthorized")
23-
ErrBlankConsumerChainID = errorsmod.Register(ModuleName, 26, "consumer chain id must not be blank")
2419
ErrInvalidPhase = errorsmod.Register(ModuleName, 27, "cannot perform action in the current phase of consumer chain")
2520
ErrInvalidConsumerMetadata = errorsmod.Register(ModuleName, 28, "invalid consumer metadata")
2621
ErrInvalidPowerShapingParameters = errorsmod.Register(ModuleName, 29, "invalid power shaping parameters")

x/ccv/provider/types/msg.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -577,7 +577,7 @@ func ValidateInitializationParameters(initializationParameters ConsumerInitializ
577577

578578
func ValidateByteSlice(hash []byte, maxLength int) error {
579579
if len(hash) > maxLength {
580-
return fmt.Errorf("hash is too long; got: %d, max: %d", len(hash), MaxHashLength)
580+
return fmt.Errorf("hash is too long; got: %d, max: %d", len(hash), maxLength)
581581
}
582582
return nil
583583
}

0 commit comments

Comments
 (0)