From 9a482ba033e990ff0d430590489898eb7bf039ee Mon Sep 17 00:00:00 2001 From: Michael Tsitrin Date: Sun, 10 Nov 2024 15:16:11 +0200 Subject: [PATCH] add error to kickProposer flow --- x/rollapp/keeper/sequencer_hooks.go | 6 ++++-- x/sequencer/keeper/fraud.go | 5 ++++- x/sequencer/types/hooks.go | 13 +++++++++---- 3 files changed, 17 insertions(+), 7 deletions(-) diff --git a/x/rollapp/keeper/sequencer_hooks.go b/x/rollapp/keeper/sequencer_hooks.go index 619a37588..149fac43c 100644 --- a/x/rollapp/keeper/sequencer_hooks.go +++ b/x/rollapp/keeper/sequencer_hooks.go @@ -1,6 +1,7 @@ package keeper import ( + errorsmod "cosmossdk.io/errors" sdk "github.com/cosmos/cosmos-sdk/types" sequencertypes "github.com/dymensionxyz/dymension/v3/x/sequencer/types" ) @@ -32,9 +33,10 @@ func (h SequencerHooks) AfterChooseNewProposer(ctx sdk.Context, rollapp string, } } -func (h SequencerHooks) AfterKickProposer(ctx sdk.Context, kicked sequencertypes.Sequencer) { +func (h SequencerHooks) AfterKickProposer(ctx sdk.Context, kicked sequencertypes.Sequencer) error { err := h.Keeper.HardForkToLatest(ctx, kicked.RollappId) if err != nil { - h.Keeper.Logger(ctx).Error("hard fork after kick proposer", "error", err) + return errorsmod.Wrap(err, "hard fork to latest") } + return nil } diff --git a/x/sequencer/keeper/fraud.go b/x/sequencer/keeper/fraud.go index 2bf168197..3c8290c98 100644 --- a/x/sequencer/keeper/fraud.go +++ b/x/sequencer/keeper/fraud.go @@ -26,7 +26,10 @@ func (k Keeper) TryKickProposer(ctx sdk.Context, kicker types.Sequencer) error { k.SetSequencer(ctx, proposer) // This will call hard fork on the rollapp, which will also optOut all sequencers - k.hooks.AfterKickProposer(ctx, proposer) + err := k.hooks.AfterKickProposer(ctx, proposer) + if err != nil { + return errorsmod.Wrap(err, "kick proposer callbacks") + } // optIn the kicker if err := kicker.SetOptedIn(ctx, true); err != nil { diff --git a/x/sequencer/types/hooks.go b/x/sequencer/types/hooks.go index 7a139eb10..57e87b77e 100644 --- a/x/sequencer/types/hooks.go +++ b/x/sequencer/types/hooks.go @@ -4,7 +4,7 @@ import sdk "github.com/cosmos/cosmos-sdk/types" type Hooks interface { AfterChooseNewProposer(ctx sdk.Context, rollapp string, before, after Sequencer) - AfterKickProposer(ctx sdk.Context, kicked Sequencer) + AfterKickProposer(ctx sdk.Context, kicked Sequencer) error } var _ Hooks = NoOpHooks{} @@ -14,7 +14,8 @@ type NoOpHooks struct{} func (n NoOpHooks) AfterChooseNewProposer(ctx sdk.Context, rollapp string, before, after Sequencer) { } -func (n NoOpHooks) AfterKickProposer(ctx sdk.Context, kicked Sequencer) { +func (n NoOpHooks) AfterKickProposer(ctx sdk.Context, kicked Sequencer) error { + return nil } var _ Hooks = MultiHooks{} @@ -31,8 +32,12 @@ func (m MultiHooks) AfterChooseNewProposer(ctx sdk.Context, rollapp string, befo } } -func (m MultiHooks) AfterKickProposer(ctx sdk.Context, kicked Sequencer) { +func (m MultiHooks) AfterKickProposer(ctx sdk.Context, kicked Sequencer) error { for _, h := range m { - h.AfterKickProposer(ctx, kicked) + err := h.AfterKickProposer(ctx, kicked) + if err != nil { + return err + } } + return nil }