From b4e5688249ede6a9b53a85e73dbe3392483f95f0 Mon Sep 17 00:00:00 2001 From: keruch <53012408+keruch@users.noreply.github.com> Date: Tue, 5 Nov 2024 23:51:32 +0300 Subject: [PATCH] fix(rollapp): DRS atomic iteration, DRS import/export genesis (#1404) --- .../dymension/rollapp/genesis.proto | 2 + x/rollapp/genesis.go | 15 +- .../msg_server_mark_vulnerable_rollapps.go | 10 +- x/rollapp/types/genesis.go | 10 + x/rollapp/types/genesis.pb.go | 185 ++++++++++++++---- x/rollapp/types/genesis_test.go | 13 ++ 6 files changed, 196 insertions(+), 39 deletions(-) diff --git a/proto/dymensionxyz/dymension/rollapp/genesis.proto b/proto/dymensionxyz/dymension/rollapp/genesis.proto index 6fa248afa..8b8abc9aa 100644 --- a/proto/dymensionxyz/dymension/rollapp/genesis.proto +++ b/proto/dymensionxyz/dymension/rollapp/genesis.proto @@ -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 { diff --git a/x/rollapp/genesis.go b/x/rollapp/genesis.go index 6df044a2c..1f07fcf61 100644 --- a/x/rollapp/genesis.go +++ b/x/rollapp/genesis.go @@ -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) } @@ -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 } diff --git a/x/rollapp/keeper/msg_server_mark_vulnerable_rollapps.go b/x/rollapp/keeper/msg_server_mark_vulnerable_rollapps.go index feef79b64..7cc0be3a3 100644 --- a/x/rollapp/keeper/msg_server_mark_vulnerable_rollapps.go +++ b/x/rollapp/keeper/msg_server_mark_vulnerable_rollapps.go @@ -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" ) @@ -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++ } diff --git a/x/rollapp/types/genesis.go b/x/rollapp/types/genesis.go index 6723ba9b6..b2d129a70 100644 --- a/x/rollapp/types/genesis.go +++ b/x/rollapp/types/genesis.go @@ -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() } diff --git a/x/rollapp/types/genesis.pb.go b/x/rollapp/types/genesis.pb.go index 7a249b75b..03cee006b 100644 --- a/x/rollapp/types/genesis.pb.go +++ b/x/rollapp/types/genesis.pb.go @@ -36,6 +36,8 @@ type GenesisState struct { AppList []App `protobuf:"bytes,8,rep,name=appList,proto3" json:"appList"` RegisteredDenoms []RollappRegisteredDenoms `protobuf:"bytes,9,rep,name=registeredDenoms,proto3" json:"registeredDenoms"` SequencerHeightPairs []SequencerHeightPair `protobuf:"bytes,10,rep,name=sequencerHeightPairs,proto3" json:"sequencerHeightPairs"` + // VulnerableDrsVersions is a list of DRS versions that are marked vulnerable + VulnerableDrsVersions []uint32 `protobuf:"varint,11,rep,packed,name=vulnerable_drs_versions,json=vulnerableDrsVersions,proto3" json:"vulnerable_drs_versions,omitempty"` } func (m *GenesisState) Reset() { *m = GenesisState{} } @@ -141,6 +143,13 @@ func (m *GenesisState) GetSequencerHeightPairs() []SequencerHeightPair { return nil } +func (m *GenesisState) GetVulnerableDrsVersions() []uint32 { + if m != nil { + return m.VulnerableDrsVersions + } + return nil +} + type SequencerHeightPair struct { Sequencer string `protobuf:"bytes,1,opt,name=sequencer,proto3" json:"sequencer,omitempty"` Height uint64 `protobuf:"varint,2,opt,name=height,proto3" json:"height,omitempty"` @@ -256,42 +265,45 @@ func init() { } var fileDescriptor_b76890aebc09aa04 = []byte{ - // 558 bytes of a gzipped FileDescriptorProto - 0x1f, 0x8b, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0xff, 0xa4, 0x94, 0x4f, 0x6f, 0xd3, 0x30, - 0x18, 0xc6, 0x9b, 0x6d, 0xb4, 0xf4, 0x2d, 0x20, 0x64, 0x26, 0x88, 0xaa, 0x2d, 0x54, 0x45, 0x82, - 0x22, 0x58, 0x22, 0xad, 0x48, 0xdc, 0x90, 0x28, 0xe3, 0x4f, 0xc5, 0x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26, 0xc7, 0x5f, 0xfb, 0x98, 0x76, 0x71, 0x92, - 0x5e, 0xdb, 0x81, 0x47, 0x12, 0x6e, 0x82, 0x8c, 0x6b, 0x6a, 0x9f, 0xc5, 0x79, 0xaf, 0x8a, 0xba, - 0x10, 0x5b, 0x7f, 0x0d, 0x37, 0x2e, 0xb0, 0xa0, 0x2d, 0x28, 0xe7, 0x72, 0x39, 0x08, 0xca, 0xee, - 0xdf, 0x0d, 0x74, 0x13, 0x8a, 0x3d, 0xa9, 0x35, 0xd7, 0x6a, 0x46, 0x63, 0xc3, 0x55, 0xab, 0xfa, - 0x47, 0xb8, 0xb5, 0xe0, 0xb8, 0x68, 0x1b, 0x40, 0x55, 0x3c, 0x22, 0x7e, 0x46, 0x54, 0x3b, 0x6d, - 0x1f, 0x6d, 0x41, 0xd1, 0x4f, 0xaf, 0x75, 0x36, 0x2a, 0xca, 0xd9, 0x34, 0x49, 0xf7, 0x5a, 0x6f, - 0x4e, 0x26, 0x96, 0x71, 0x3a, 0xb1, 0x8c, 0x5f, 0x13, 0xcb, 0xf8, 0x36, 0xb5, 0x0a, 0xa7, 0x53, - 0xab, 0xf0, 0x63, 0x6a, 0x15, 0x3e, 0x3d, 0x0a, 0x88, 0xe8, 0xf5, 0x3b, 0x76, 0x97, 0x45, 0x8b, - 0x66, 0xea, 0xa0, 0xe9, 0x0c, 0xf3, 0xc1, 0x27, 0x46, 0x31, 0xe6, 0x9d, 0xa2, 0x9c, 0x7d, 0xcd, - 0x3f, 0x01, 0x00, 0x00, 0xff, 0xff, 0x71, 0xe2, 0x44, 0xa5, 0x46, 0x06, 0x00, 0x00, + // 596 bytes of a gzipped FileDescriptorProto + 0x1f, 0x8b, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0xff, 0xa4, 0x94, 0xdf, 0x6e, 0x12, 0x4d, + 0x18, 0xc6, 0xd9, 0xc2, 0x47, 0xcb, 0xf0, 0xd5, 0x98, 0xb1, 0xda, 0x0d, 0x69, 0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00, + 0x78, 0x3b, 0x2f, 0x67, 0x66, 0xed, 0x4f, 0x00, 0x00, 0x00, 0xff, 0xff, 0xc5, 0xf9, 0xb9, 0x53, + 0x7e, 0x06, 0x00, 0x00, } func (m *GenesisState) Marshal() (dAtA []byte, err error) { @@ -314,6 +326,24 @@ func (m *GenesisState) MarshalToSizedBuffer(dAtA []byte) (int, error) { _ = i var l int _ = l + if len(m.VulnerableDrsVersions) > 0 { + dAtA2 := make([]byte, len(m.VulnerableDrsVersions)*10) + var j1 int + for _, num := range m.VulnerableDrsVersions { + for num >= 1<<7 { + dAtA2[j1] = uint8(uint64(num)&0x7f | 0x80) + num >>= 7 + j1++ + } + dAtA2[j1] = uint8(num) + j1++ + } + i -= j1 + copy(dAtA[i:], dAtA2[:j1]) + i = encodeVarintGenesis(dAtA, i, uint64(j1)) + i-- + dAtA[i] = 0x5a + } if len(m.SequencerHeightPairs) > 0 { for iNdEx := len(m.SequencerHeightPairs) - 1; iNdEx >= 0; iNdEx-- { { @@ -600,6 +630,13 @@ func (m *GenesisState) Size() (n int) { n += 1 + l + sovGenesis(uint64(l)) } } + if len(m.VulnerableDrsVersions) > 0 { + l = 0 + for _, e := range m.VulnerableDrsVersions { + l += sovGenesis(uint64(e)) + } + n += 1 + sovGenesis(uint64(l)) + l + } return n } @@ -1012,6 +1049,82 @@ func (m *GenesisState) Unmarshal(dAtA []byte) error { return err } iNdEx = postIndex + case 11: + if wireType == 0 { + var v uint32 + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowGenesis + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + v |= uint32(b&0x7F) << shift + if b < 0x80 { + break + } + } + m.VulnerableDrsVersions = append(m.VulnerableDrsVersions, v) + } else if wireType == 2 { + var packedLen int + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowGenesis + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + packedLen |= int(b&0x7F) << shift + if b < 0x80 { + break + } + } + if packedLen < 0 { + return ErrInvalidLengthGenesis + } + postIndex := iNdEx + packedLen + if postIndex < 0 { + return ErrInvalidLengthGenesis + } + if postIndex > l { + return io.ErrUnexpectedEOF + } + var elementCount int + var count int + for _, integer := range dAtA[iNdEx:postIndex] { + if integer < 128 { + count++ + } + } + elementCount = count + if elementCount != 0 && len(m.VulnerableDrsVersions) == 0 { + m.VulnerableDrsVersions = make([]uint32, 0, elementCount) + } + for iNdEx < postIndex { + var v uint32 + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowGenesis + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + v |= uint32(b&0x7F) << shift + if b < 0x80 { + break + } + } + m.VulnerableDrsVersions = append(m.VulnerableDrsVersions, v) + } + } else { + return fmt.Errorf("proto: wrong wireType = %d for field VulnerableDrsVersions", wireType) + } default: iNdEx = preIndex skippy, err := skipGenesis(dAtA[iNdEx:]) diff --git a/x/rollapp/types/genesis_test.go b/x/rollapp/types/genesis_test.go index d2c228a64..6df041e3d 100644 --- a/x/rollapp/types/genesis_test.go +++ b/x/rollapp/types/genesis_test.go @@ -61,6 +61,7 @@ func TestGenesisState_Validate(t *testing.T) { CreationHeight: 1, }, }, + VulnerableDrsVersions: []uint32{1, 2}, }, valid: true, }, @@ -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()