Skip to content

Commit

Permalink
fix(sequencer): do not allow setting sentinel object (#1619)
Browse files Browse the repository at this point in the history
  • Loading branch information
danwt authored Dec 6, 2024
1 parent b44e6bd commit 240c85e
Show file tree
Hide file tree
Showing 4 changed files with 29 additions and 2 deletions.
2 changes: 1 addition & 1 deletion x/rollapp/keeper/invariants.go
Original file line number Diff line number Diff line change
Expand Up @@ -301,7 +301,7 @@ func LivenessEventInvariant(k Keeper) sdk.Invariant {
if ra.LivenessEventHeight != e.HubHeight {
broken = true
msg += fmt.Sprintf("| event stored but rollapp has a different liveness event height: rollapp: %s"+
", height stored on rollapp: %d: height on event: %d", e.RollappId, ra.LivenessEventHeight, e.HubHeight,
", height stored on rollapp: %d: height on event: %d\n", e.RollappId, ra.LivenessEventHeight, e.HubHeight,
)
}

Expand Down
23 changes: 23 additions & 0 deletions x/sequencer/keeper/invariants.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ var invs = uinv.NamedFuncsList[Keeper]{
{Name: "hash-index", Func: InvariantProposerAddrIndex},
{Name: "status", Func: InvariantStatus},
{Name: "tokens", Func: InvariantTokens},
{Name: "do-not-expose-sentinel", Func: InvariantDoNotExposeSentinel},
}

// RegisterInvariants registers the sequencer module invariants
Expand Down Expand Up @@ -168,3 +169,25 @@ func checkSeqTokens(seq types.Sequencer) error {
}
return nil
}

// sentinel should not be available in the global index or rollapp wise index
// (it's only available in getProposer or getSuccessor)
func InvariantDoNotExposeSentinel(k Keeper) uinv.Func {
return uinv.AnyErrorIsBreaking(func(ctx sdk.Context) error {
var errs []error
for _, s := range k.AllSequencers(ctx) {
if s.Sentinel() {
errs = append(errs, fmt.Errorf("sentinel in global index: %s", s.Address))
}
}
rollapps := k.rollappKeeper.GetAllRollapps(ctx)
for _, ra := range rollapps {
for _, s := range k.RollappSequencers(ctx, ra.RollappId) {
if s.Sentinel() {
errs = append(errs, fmt.Errorf("sentinel in rollapp index: %s", ra.RollappId))
}
}
}
return errors.Join(errs...)
})
}
3 changes: 2 additions & 1 deletion x/sequencer/keeper/msg_server_kick_proposer_test.go
Original file line number Diff line number Diff line change
@@ -1,13 +1,14 @@
package keeper_test

import (
rollapptypes "github.com/dymensionxyz/dymension/v3/x/rollapp/types"
"github.com/dymensionxyz/dymension/v3/x/sequencer/types"
"github.com/dymensionxyz/gerr-cosmos/gerrc"
"github.com/dymensionxyz/sdk-utils/utils/utest"
)

func (s *SequencerTestSuite) TestKickProposerBasicFlow() {
s.App.RollappKeeper.SetHooks(nil)
s.App.RollappKeeper.SetHooks(rollapptypes.NewMultiRollappHooks(s.k().RollappHooks()))
ra := s.createRollapp()
seqAlice := s.createSequencerWithBond(s.Ctx, ra.RollappId, alice, bond)
s.Require().True(s.k().IsProposer(s.Ctx, seqAlice))
Expand Down
3 changes: 3 additions & 0 deletions x/sequencer/keeper/proposer.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,9 @@ import (

func (k Keeper) abruptRemoveProposer(ctx sdk.Context, rollapp string) {
proposer := k.GetProposer(ctx, rollapp)
if proposer.Sentinel() {
return
}
k.removeFromNoticeQueue(ctx, proposer)
k.unbond(ctx, &proposer)
k.SetSequencer(ctx, proposer)
Expand Down

0 comments on commit 240c85e

Please sign in to comment.