Skip to content

Commit

Permalink
fix(rollapp): DRS atomic iteration, DRS import/export genesis (#1404)
Browse files Browse the repository at this point in the history
  • Loading branch information
keruch authored Nov 5, 2024
1 parent 5111f26 commit b4e5688
Show file tree
Hide file tree
Showing 6 changed files with 196 additions and 39 deletions.
2 changes: 2 additions & 0 deletions proto/dymensionxyz/dymension/rollapp/genesis.proto
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,8 @@ message GenesisState {
repeated App appList = 8 [(gogoproto.nullable) = false];
repeated RollappRegisteredDenoms registeredDenoms = 9 [(gogoproto.nullable) = false];
repeated SequencerHeightPair sequencerHeightPairs = 10 [(gogoproto.nullable) = false];
// VulnerableDrsVersions is a list of DRS versions that are marked vulnerable
repeated uint32 vulnerable_drs_versions = 11;
}

message SequencerHeightPair {
Expand Down
15 changes: 14 additions & 1 deletion x/rollapp/genesis.go
Original file line number Diff line number Diff line change
Expand Up @@ -44,13 +44,20 @@ func InitGenesis(ctx sdk.Context, k keeper.Keeper, genState types.GenesisState)
}
}
}

// Set all the sequencer height pairs
for _, elem := range genState.SequencerHeightPairs {
err := k.SaveSequencerHeight(ctx, elem.Sequencer, elem.Height)
if err != nil {
panic(err)
}
}
// Set all the vulnerable DRS versions
for _, elem := range genState.VulnerableDrsVersions {
err := k.SetVulnerableDRSVersion(ctx, elem)
if err != nil {
panic(err)
}
}

k.SetParams(ctx, genState.Params)
}
Expand Down Expand Up @@ -92,5 +99,11 @@ func ExportGenesis(ctx sdk.Context, k keeper.Keeper) *types.GenesisState {
panic(err)
}

drsVersions, err := k.GetAllVulnerableDRSVersions(ctx)
if err != nil {
panic(err)
}
genesis.VulnerableDrsVersions = drsVersions

return genesis
}
10 changes: 8 additions & 2 deletions x/rollapp/keeper/msg_server_mark_vulnerable_rollapps.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import (
sdk "github.com/cosmos/cosmos-sdk/types"
"github.com/dymensionxyz/gerr-cosmos/gerrc"
"github.com/dymensionxyz/sdk-utils/utils/uevent"
"github.com/osmosis-labs/osmosis/v15/osmoutils"

"github.com/dymensionxyz/dymension/v3/x/rollapp/types"
)
Expand Down Expand Up @@ -68,9 +69,14 @@ func (k Keeper) MarkVulnerableRollapps(ctx sdk.Context, drsVersions []uint32) (i

_, vulnerable := vulnerableVersions[bd.DrsVersion]
if vulnerable {
err := k.MarkRollappAsVulnerable(ctx, rollapp.RollappId)
// If this fails, no state change happens
err := osmoutils.ApplyFuncIfNoError(ctx, func(ctx sdk.Context) error {
return k.MarkRollappAsVulnerable(ctx, rollapp.RollappId)
})
if err != nil {
return 0, fmt.Errorf("freeze rollapp: %w", err)
// We do not want to fail if one rollapp cannot to be marked as vulnerable
k.Logger(ctx).With("rollapp_id", rollapp.RollappId, "drs_version", bd.DrsVersion, "error", err.Error()).
Error("Failed to mark rollapp as vulnerable")
}
vulnerableNum++
}
Expand Down
10 changes: 10 additions & 0 deletions x/rollapp/types/genesis.go
Original file line number Diff line number Diff line change
Expand Up @@ -85,5 +85,15 @@ func (gs GenesisState) Validate() error {
appIndexMap[index] = struct{}{}
}

// Check for duplicated index in vulnerable DRS versions
vulnerableDRSVersionIndexMap := make(map[uint32]struct{})

for _, elem := range gs.VulnerableDrsVersions {
if _, ok := vulnerableDRSVersionIndexMap[elem]; ok {
return errors.New("duplicated index for VulnerableDrsVersions")
}
vulnerableDRSVersionIndexMap[elem] = struct{}{}
}

return gs.Params.Validate()
}
185 changes: 149 additions & 36 deletions x/rollapp/types/genesis.pb.go

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

13 changes: 13 additions & 0 deletions x/rollapp/types/genesis_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,7 @@ func TestGenesisState_Validate(t *testing.T) {
CreationHeight: 1,
},
},
VulnerableDrsVersions: []uint32{1, 2},
},
valid: true,
},
Expand Down Expand Up @@ -141,6 +142,18 @@ func TestGenesisState_Validate(t *testing.T) {
},
valid: false,
},
{
desc: "duplicated VulnerableDrsVersions",
genState: &types.GenesisState{
Params: types.DefaultParams(),
RollappList: []types.Rollapp{},
StateInfoList: []types.StateInfo{},
LatestStateInfoIndexList: []types.StateInfoIndex{},
BlockHeightToFinalizationQueueList: []types.BlockHeightToFinalizationQueue{},
VulnerableDrsVersions: []uint32{1, 1},
},
valid: false,
},
} {
t.Run(tc.desc, func(t *testing.T) {
err := tc.genState.Validate()
Expand Down

0 comments on commit b4e5688

Please sign in to comment.