Skip to content

Commit

Permalink
add error to kickProposer flow
Browse files Browse the repository at this point in the history
  • Loading branch information
mtsitrin committed Nov 10, 2024
1 parent 5f6c7f6 commit 9a482ba
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 7 deletions.
6 changes: 4 additions & 2 deletions x/rollapp/keeper/sequencer_hooks.go
Original file line number Diff line number Diff line change
@@ -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"
)
Expand Down Expand Up @@ -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
}
5 changes: 4 additions & 1 deletion x/sequencer/keeper/fraud.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
13 changes: 9 additions & 4 deletions x/sequencer/types/hooks.go
Original file line number Diff line number Diff line change
Expand Up @@ -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{}
Expand All @@ -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{}
Expand All @@ -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
}

0 comments on commit 9a482ba

Please sign in to comment.