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 error handling in checkpointing module #257

Merged
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
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,8 @@ unbonding output
* [#253](https://github.com/babylonlabs-io/babylon/pull/253) Upgrade cometbft dependency
* [#256](https://github.com/babylonlabs-io/babylon/pull/256) Removes retry library
from core Babylon repository
* [#257](https://github.com/babylonlabs-io/babylon/pull/257) Fix error handling
in checkpointing module

### State Machine Breaking

Expand Down
45 changes: 28 additions & 17 deletions x/checkpointing/keeper/keeper.go
Original file line number Diff line number Diff line change
Expand Up @@ -277,8 +277,12 @@ func (k *Keeper) SetEpochingKeeper(ek types.EpochingKeeper) {
// and records the associated state update in lifecycle
func (k Keeper) SetCheckpointSubmitted(ctx context.Context, epoch uint64) {
sdkCtx := sdk.UnwrapSDKContext(ctx)
ckpt := k.setCheckpointStatus(ctx, epoch, types.Sealed, types.Submitted)
err := sdkCtx.EventManager().EmitTypedEvent(
ckpt, err := k.setCheckpointStatus(ctx, epoch, types.Sealed, types.Submitted)
if err != nil {
k.Logger(sdkCtx).Error("failed to set checkpoint status to SUBMITTED for epoch %v: %v", epoch, err)
return
}
err = sdkCtx.EventManager().EmitTypedEvent(
&types.EventCheckpointSubmitted{Checkpoint: ckpt},
)
if err != nil {
Expand All @@ -290,8 +294,12 @@ func (k Keeper) SetCheckpointSubmitted(ctx context.Context, epoch uint64) {
// and records the associated state update in lifecycle
func (k Keeper) SetCheckpointConfirmed(ctx context.Context, epoch uint64) {
sdkCtx := sdk.UnwrapSDKContext(ctx)
ckpt := k.setCheckpointStatus(ctx, epoch, types.Submitted, types.Confirmed)
err := sdkCtx.EventManager().EmitTypedEvent(
ckpt, err := k.setCheckpointStatus(ctx, epoch, types.Submitted, types.Confirmed)
if err != nil {
k.Logger(sdkCtx).Error("failed to set checkpoint status to CONFIRMED for epoch %v: %v", epoch, err)
return
}
err = sdkCtx.EventManager().EmitTypedEvent(
&types.EventCheckpointConfirmed{Checkpoint: ckpt},
)
if err != nil {
Expand All @@ -308,11 +316,15 @@ func (k Keeper) SetCheckpointConfirmed(ctx context.Context, epoch uint64) {
func (k Keeper) SetCheckpointFinalized(ctx context.Context, epoch uint64) {
sdkCtx := sdk.UnwrapSDKContext(ctx)
// set the checkpoint's status to be finalised
ckpt := k.setCheckpointStatus(ctx, epoch, types.Confirmed, types.Finalized)
ckpt, err := k.setCheckpointStatus(ctx, epoch, types.Confirmed, types.Finalized)
if err != nil {
k.Logger(sdkCtx).Error("failed to set checkpoint status to FINALIZED for epoch %v: %v", epoch, err)
return
}
// remember the last finalised epoch
k.SetLastFinalizedEpoch(ctx, epoch)
// emit event
err := sdkCtx.EventManager().EmitTypedEvent(
err = sdkCtx.EventManager().EmitTypedEvent(
&types.EventCheckpointFinalized{Checkpoint: ckpt},
)
if err != nil {
Expand All @@ -328,8 +340,12 @@ func (k Keeper) SetCheckpointFinalized(ctx context.Context, epoch uint64) {
// and records the associated state update in lifecycle
func (k Keeper) SetCheckpointForgotten(ctx context.Context, epoch uint64) {
sdkCtx := sdk.UnwrapSDKContext(ctx)
ckpt := k.setCheckpointStatus(ctx, epoch, types.Submitted, types.Sealed)
err := sdkCtx.EventManager().EmitTypedEvent(
ckpt, err := k.setCheckpointStatus(ctx, epoch, types.Submitted, types.Sealed)
if err != nil {
k.Logger(sdkCtx).Error("failed to set checkpoint status to SEALED for epoch %v: %v", epoch, err)
return
}
err = sdkCtx.EventManager().EmitTypedEvent(
&types.EventCheckpointForgotten{Checkpoint: ckpt},
)
if err != nil {
Expand All @@ -339,18 +355,13 @@ func (k Keeper) SetCheckpointForgotten(ctx context.Context, epoch uint64) {

// setCheckpointStatus sets a ckptWithMeta to the given state,
// and records the state update in its lifecycle
func (k Keeper) setCheckpointStatus(ctx context.Context, epoch uint64, from types.CheckpointStatus, to types.CheckpointStatus) *types.RawCheckpointWithMeta {
func (k Keeper) setCheckpointStatus(ctx context.Context, epoch uint64, from types.CheckpointStatus, to types.CheckpointStatus) (*types.RawCheckpointWithMeta, error) {
ckptWithMeta, err := k.GetRawCheckpoint(ctx, epoch)
if err != nil {
// TODO: ignore err for now
return nil
return nil, err
}
if ckptWithMeta.Status != from {
err = types.ErrInvalidCkptStatus.Wrapf("the status of the checkpoint should be %s", from.String())
if err != nil {
// TODO: ignore err for now
return nil
}
return nil, types.ErrInvalidCkptStatus.Wrapf("the status of the checkpoint should be %s", from.String())
}
ckptWithMeta.Status = to // set status
ckptWithMeta.RecordStateUpdate(ctx, to) // record state update to the lifecycle
Expand All @@ -360,7 +371,7 @@ func (k Keeper) setCheckpointStatus(ctx context.Context, epoch uint64, from type
}
statusChangeMsg := fmt.Sprintf("Checkpointing: checkpoint status for epoch %v successfully changed from %v to %v", epoch, from.String(), to.String())
k.Logger(sdk.UnwrapSDKContext(ctx)).Info(statusChangeMsg)
return ckptWithMeta
return ckptWithMeta, nil
}

func (k Keeper) UpdateCheckpoint(ctx context.Context, ckptWithMeta *types.RawCheckpointWithMeta) error {
Expand Down
Loading