Skip to content

Commit

Permalink
feat(sequencer): support rotation misbehavior detection (#1345)
Browse files Browse the repository at this point in the history
Co-authored-by: unknown <[email protected]>
Co-authored-by: Faulty Tolly <@faulttolerance.net>
Co-authored-by: Omri <[email protected]>
  • Loading branch information
3 people authored Oct 29, 2024
1 parent 8739ceb commit 43db5fd
Show file tree
Hide file tree
Showing 7 changed files with 125 additions and 51 deletions.
3 changes: 3 additions & 0 deletions proto/dymensionxyz/dymension/rollapp/state_info.proto
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,9 @@ message StateInfo {
(gogoproto.nullable) = false,
(gogoproto.moretags) = "yaml:\"created_at\""
];

// next sequencer is the bech32-encoded address of the next sequencer after the current sequencer
string nextProposer = 11;
}

// StateInfoSummary is a compact representation of StateInfo
Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
package types
package keeper

import (
sdk "github.com/cosmos/cosmos-sdk/types"
"github.com/cosmos/ibc-go/v7/modules/core/exported"
"github.com/dymensionxyz/dymension/v3/x/sequencer/types"
)

type AccountKeeper interface {
Expand All @@ -21,6 +22,7 @@ type ChannelKeeper interface {
type SequencerKeeper interface {
SlashLiveness(ctx sdk.Context, rollappID string) error
JailLiveness(ctx sdk.Context, rollappID string) error
GetProposer(ctx sdk.Context, rollappId string) (val types.Sequencer, found bool)
}

// BankKeeper defines the expected interface needed to retrieve account balances.
Expand Down
28 changes: 14 additions & 14 deletions x/rollapp/keeper/keeper.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,12 +22,12 @@ type Keeper struct {
paramstore paramtypes.Subspace
authority string // authority is the x/gov module account

accKeeper types.AccountKeeper
ibcClientKeeper types.IBCClientKeeper
canonicalClientKeeper types.CanonicalLightClientKeeper
channelKeeper types.ChannelKeeper
sequencerKeeper types.SequencerKeeper
bankKeeper types.BankKeeper
accKeeper AccountKeeper
ibcClientKeeper IBCClientKeeper
canonicalClientKeeper CanonicalLightClientKeeper
channelKeeper ChannelKeeper
sequencerKeeper SequencerKeeper
bankKeeper BankKeeper

vulnerableDRSVersions collections.KeySet[string]
registeredRollappDenoms collections.KeySet[collections.Pair[string, string]]
Expand All @@ -39,13 +39,13 @@ func NewKeeper(
cdc codec.BinaryCodec,
storeKey storetypes.StoreKey,
ps paramtypes.Subspace,
ak types.AccountKeeper,
channelKeeper types.ChannelKeeper,
ibcclientKeeper types.IBCClientKeeper,
sequencerKeeper types.SequencerKeeper,
bankKeeper types.BankKeeper,
ak AccountKeeper,
channelKeeper ChannelKeeper,
ibcclientKeeper IBCClientKeeper,
sequencerKeeper SequencerKeeper,
bankKeeper BankKeeper,
authority string,
canonicalClientKeeper types.CanonicalLightClientKeeper,
canonicalClientKeeper CanonicalLightClientKeeper,
) *Keeper {
// set KeyTable if it has not already been set
if !ps.HasKeyTable() {
Expand Down Expand Up @@ -94,11 +94,11 @@ func (k Keeper) Logger(ctx sdk.Context) log.Logger {
return ctx.Logger().With("module", fmt.Sprintf("x/%s", types.ModuleName))
}

func (k *Keeper) SetSequencerKeeper(sk types.SequencerKeeper) {
func (k *Keeper) SetSequencerKeeper(sk SequencerKeeper) {
k.sequencerKeeper = sk
}

func (k *Keeper) SetCanonicalClientKeeper(kk types.CanonicalLightClientKeeper) {
func (k *Keeper) SetCanonicalClientKeeper(kk CanonicalLightClientKeeper) {
k.canonicalClientKeeper = kk
}

Expand Down
5 changes: 5 additions & 0 deletions x/rollapp/keeper/liveness_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ import (
keepertest "github.com/dymensionxyz/dymension/v3/testutil/keeper"
"github.com/dymensionxyz/dymension/v3/x/rollapp/keeper"
"github.com/dymensionxyz/dymension/v3/x/rollapp/types"
seqtypes "github.com/dymensionxyz/dymension/v3/x/sequencer/types"
)

func TestLivenessArithmetic(t *testing.T) {
Expand Down Expand Up @@ -207,6 +208,10 @@ func (l livenessMockSequencerKeeper) JailLiveness(ctx sdk.Context, rollappID str
return nil
}

func (l livenessMockSequencerKeeper) GetProposer(ctx sdk.Context, rollappId string) (val seqtypes.Sequencer, found bool) {
return seqtypes.Sequencer{}, false
}

func (l livenessMockSequencerKeeper) clear(rollappID string) {
delete(l.slashes, rollappID)
delete(l.jails, rollappID)
Expand Down
10 changes: 9 additions & 1 deletion x/rollapp/keeper/msg_server_update_state.go
Original file line number Diff line number Diff line change
Expand Up @@ -97,6 +97,11 @@ func (k msgServer) UpdateState(goCtx context.Context, msg *types.MsgUpdateState)
Index: newIndex,
})

// it takes the actual proposer because the next one have already been set
// by the sequencer rotation in k.hooks.BeforeUpdateState
// the proposer we get is the one that will propose the next block.
val, _ := k.sequencerKeeper.GetProposer(ctx, msg.RollappId)

creationHeight := uint64(ctx.BlockHeight())
blockTime := ctx.BlockTime()
stateInfo := types.NewStateInfo(
Expand All @@ -109,6 +114,7 @@ func (k msgServer) UpdateState(goCtx context.Context, msg *types.MsgUpdateState)
creationHeight,
msg.BDs,
blockTime,
val.Address,
)
// Write new state information to the store indexed by <RollappId,LatestStateInfoIndex>
k.SetStateInfo(ctx, *stateInfo)
Expand Down Expand Up @@ -138,9 +144,11 @@ func (k msgServer) UpdateState(goCtx context.Context, msg *types.MsgUpdateState)
// https://github.com/dymensionxyz/dymension/issues/1085
k.IndicateLiveness(ctx, &rollapp)

events := stateInfo.GetEvents()

ctx.EventManager().EmitEvent(
sdk.NewEvent(types.EventTypeStateUpdate,
stateInfo.GetEvents()...,
events...,
),
)

Expand Down
2 changes: 2 additions & 0 deletions x/rollapp/types/state_info.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ func NewStateInfo(
height uint64,
BDs BlockDescriptors,
createdAt time.Time,
nextProposer string,
) *StateInfo {
stateInfoIndex := StateInfoIndex{RollappId: rollappId, Index: newIndex}
status := common.Status_PENDING
Expand All @@ -32,6 +33,7 @@ func NewStateInfo(
Status: status,
BDs: BDs,
CreatedAt: createdAt,
NextProposer: nextProposer,
}
}

Expand Down
124 changes: 89 additions & 35 deletions x/rollapp/types/state_info.pb.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit 43db5fd

Please sign in to comment.