From 5d71e70f5bee2315e015a01ca70aa4977e22397f Mon Sep 17 00:00:00 2001 From: Mark Cherepovskyi Date: Tue, 3 Sep 2024 17:48:01 +0300 Subject: [PATCH 1/3] implement update handler --- app/app.go | 35 ++++++++++++++++++++++++++++------- 1 file changed, 28 insertions(+), 7 deletions(-) diff --git a/app/app.go b/app/app.go index d590d64e..4fd1ec41 100644 --- a/app/app.go +++ b/app/app.go @@ -1110,12 +1110,12 @@ func New( "v1.1.4-rc1", func(ctx sdk.Context, plan upgradetypes.Plan, fromVM module.VersionMap) (module.VersionMap, error) { app.RootupdaterKeeper.SetParams(ctx, rootupdatermoduletypes.Params{ - ContractAddress: "0xBF926a23B4A0bcA301F97Ccd27358b55Dc4C7D3C", - Root: "0x00", - LastSignedRoot: "0x00", - LastSignedRootIndex: "0x00", - EventName: "RootUpdated", - RootTimestamp: 1724316208, + SourceContractAddress: "0xBF926a23B4A0bcA301F97Ccd27358b55Dc4C7D3C", + Root: "0x00", + LastSignedRoot: "0x00", + LastSignedRootIndex: "0x00", + EventName: "RootUpdated", + RootTimestamp: 1724316208, }) fromVM[rootupdatermoduletypes.ModuleName] = rootupdatermodule.AppModule{}.ConsensusVersion() @@ -1127,7 +1127,7 @@ func New( "v1.1.4-rc2", func(ctx sdk.Context, plan upgradetypes.Plan, fromVM module.VersionMap) (module.VersionMap, error) { params := app.RootupdaterKeeper.GetParams(ctx) - params.ContractAddress = "0xc1534912902BBe8C54626e2D69288C76a843bc0E" + params.SourceContractAddress = "0xc1534912902BBe8C54626e2D69288C76a843bc0E" app.RootupdaterKeeper.SetParams(ctx, params) return app.mm.RunMigrations(ctx, app.configurator, fromVM) }, @@ -1161,6 +1161,27 @@ func New( }, ) + app.UpgradeKeeper.SetUpgradeHandler( + "v1.1.4-rc6", + func(ctx sdk.Context, plan upgradetypes.Plan, fromVM module.VersionMap) (module.VersionMap, error) { + oldParams := app.RootupdaterKeeper.GetParams(ctx) + + app.RootupdaterKeeper.SetParams(ctx, rootupdatermoduletypes.Params{ + SourceContractAddress: "0xBF926a23B4A0bcA301F97Ccd27358b55Dc4C7D3C", + DestinationContractAddress: "0x2af05993a27df83094a963af64b5d25296230544", + EventName: "RootUpdated", + RootTimestamp: oldParams.RootTimestamp, + Root: oldParams.Root, + LastSignedRootIndex: oldParams.LastSignedRootIndex, + LastSignedRoot: oldParams.LastSignedRoot, + BlockHeight: oldParams.BlockHeight, + }) + fromVM[rootupdatermoduletypes.ModuleName] = rootupdatermodule.AppModule{}.ConsensusVersion() + + return app.mm.RunMigrations(ctx, app.configurator, fromVM) + }, + ) + if loadLatest { if err := app.LoadLatestVersion(); err != nil { tmos.Exit(err.Error()) From 21505f900a7fb2be1b7d2f2d4847b78551feddd2 Mon Sep 17 00:00:00 2001 From: Mark Cherepovskyi Date: Tue, 3 Sep 2024 18:33:47 +0300 Subject: [PATCH 2/3] migrations --- app/app.go | 43 +- x/rootupdater/keeper/migrations.go | 24 + x/rootupdater/migrations/v2/main.go | 35 ++ x/rootupdater/migrations/v2/old_params.go | 597 ++++++++++++++++++++++ x/rootupdater/module.go | 14 +- 5 files changed, 677 insertions(+), 36 deletions(-) create mode 100644 x/rootupdater/keeper/migrations.go create mode 100644 x/rootupdater/migrations/v2/main.go create mode 100644 x/rootupdater/migrations/v2/old_params.go diff --git a/app/app.go b/app/app.go index 4fd1ec41..40c26951 100644 --- a/app/app.go +++ b/app/app.go @@ -1109,14 +1109,14 @@ func New( app.UpgradeKeeper.SetUpgradeHandler( "v1.1.4-rc1", func(ctx sdk.Context, plan upgradetypes.Plan, fromVM module.VersionMap) (module.VersionMap, error) { - app.RootupdaterKeeper.SetParams(ctx, rootupdatermoduletypes.Params{ - SourceContractAddress: "0xBF926a23B4A0bcA301F97Ccd27358b55Dc4C7D3C", - Root: "0x00", - LastSignedRoot: "0x00", - LastSignedRootIndex: "0x00", - EventName: "RootUpdated", - RootTimestamp: 1724316208, - }) + //app.RootupdaterKeeper.SetParams(ctx, rootupdatermoduletypes.Params{ + // ContractAddress: "0xBF926a23B4A0bcA301F97Ccd27358b55Dc4C7D3C", + // Root: "0x00", + // LastSignedRoot: "0x00", + // LastSignedRootIndex: "0x00", + // EventName: "RootUpdated", + // RootTimestamp: 1724316208, + //}) fromVM[rootupdatermoduletypes.ModuleName] = rootupdatermodule.AppModule{}.ConsensusVersion() return app.mm.RunMigrations(ctx, app.configurator, fromVM) @@ -1126,9 +1126,9 @@ func New( app.UpgradeKeeper.SetUpgradeHandler( "v1.1.4-rc2", func(ctx sdk.Context, plan upgradetypes.Plan, fromVM module.VersionMap) (module.VersionMap, error) { - params := app.RootupdaterKeeper.GetParams(ctx) - params.SourceContractAddress = "0xc1534912902BBe8C54626e2D69288C76a843bc0E" - app.RootupdaterKeeper.SetParams(ctx, params) + //params := app.RootupdaterKeeper.GetParams(ctx) + //params.ContractAddress = "0xc1534912902BBe8C54626e2D69288C76a843bc0E" + //app.RootupdaterKeeper.SetParams(ctx, params) return app.mm.RunMigrations(ctx, app.configurator, fromVM) }, ) @@ -1161,27 +1161,6 @@ func New( }, ) - app.UpgradeKeeper.SetUpgradeHandler( - "v1.1.4-rc6", - func(ctx sdk.Context, plan upgradetypes.Plan, fromVM module.VersionMap) (module.VersionMap, error) { - oldParams := app.RootupdaterKeeper.GetParams(ctx) - - app.RootupdaterKeeper.SetParams(ctx, rootupdatermoduletypes.Params{ - SourceContractAddress: "0xBF926a23B4A0bcA301F97Ccd27358b55Dc4C7D3C", - DestinationContractAddress: "0x2af05993a27df83094a963af64b5d25296230544", - EventName: "RootUpdated", - RootTimestamp: oldParams.RootTimestamp, - Root: oldParams.Root, - LastSignedRootIndex: oldParams.LastSignedRootIndex, - LastSignedRoot: oldParams.LastSignedRoot, - BlockHeight: oldParams.BlockHeight, - }) - fromVM[rootupdatermoduletypes.ModuleName] = rootupdatermodule.AppModule{}.ConsensusVersion() - - return app.mm.RunMigrations(ctx, app.configurator, fromVM) - }, - ) - if loadLatest { if err := app.LoadLatestVersion(); err != nil { tmos.Exit(err.Error()) diff --git a/x/rootupdater/keeper/migrations.go b/x/rootupdater/keeper/migrations.go new file mode 100644 index 00000000..7fdb0fc4 --- /dev/null +++ b/x/rootupdater/keeper/migrations.go @@ -0,0 +1,24 @@ +package keeper + +import ( + sdk "github.com/cosmos/cosmos-sdk/types" + v2 "github.com/rarimo/rarimo-core/x/rootupdater/migrations/v2" +) + +type Migrator struct { + keeper Keeper +} + +func NewMigrator(keeper Keeper) Migrator { + return Migrator{ + keeper: keeper, + } +} + +func (m Migrator) Migrate1to2(ctx sdk.Context) error { + if err := v2.MigrateStore(ctx, m.keeper.storeKey, m.keeper.cdc); err != nil { + return err + } + + return nil +} diff --git a/x/rootupdater/migrations/v2/main.go b/x/rootupdater/migrations/v2/main.go new file mode 100644 index 00000000..5a060653 --- /dev/null +++ b/x/rootupdater/migrations/v2/main.go @@ -0,0 +1,35 @@ +package v2 + +import ( + "fmt" + "github.com/cosmos/cosmos-sdk/codec" + storetypes "github.com/cosmos/cosmos-sdk/store/types" + sdk "github.com/cosmos/cosmos-sdk/types" + "github.com/rarimo/rarimo-core/x/rootupdater/types" +) + +func MigrateStore(ctx sdk.Context, storeKey storetypes.StoreKey, cdc codec.BinaryCodec) error { + ctx.Logger().Info(fmt.Sprintf("Performing v1.1.4-rc6 %s module migrations", types.ModuleName)) + + store := ctx.KVStore(storeKey) + + oldParamsBytes := store.Get(types.KeyPrefix(types.ParamsKey)) + store.Delete(types.KeyPrefix(types.ParamsKey)) + + oldParams := OldParamas{} + cdc.MustUnmarshal(oldParamsBytes, &oldParams) + params := types.Params{ + DestinationContractAddress: "0x2af05993a27df83094a963af64b5d25296230544", + SourceContractAddress: oldParams.ContractAddress, + Root: oldParams.Root, + RootTimestamp: oldParams.RootTimestamp, + LastSignedRootIndex: oldParams.LastSignedRootIndex, + LastSignedRoot: oldParams.LastSignedRoot, + BlockHeight: oldParams.BlockHeight, + EventName: oldParams.EventName, + } + + store.Set(types.KeyPrefix(types.ParamsKey), cdc.MustMarshal(¶ms)) + + return nil +} diff --git a/x/rootupdater/migrations/v2/old_params.go b/x/rootupdater/migrations/v2/old_params.go new file mode 100644 index 00000000..68584cdd --- /dev/null +++ b/x/rootupdater/migrations/v2/old_params.go @@ -0,0 +1,597 @@ +package v2 + +import ( + fmt "fmt" + _ "github.com/gogo/protobuf/gogoproto" + proto "github.com/gogo/protobuf/proto" + io "io" + math "math" + math_bits "math/bits" +) + +// Reference imports to suppress errors if they are not otherwise used. +var _ = proto.Marshal +var _ = fmt.Errorf +var _ = math.Inf + +// This is a compile-time assertion to ensure that this generated file +// is compatible with the proto package it is being compiled against. +// A compilation error at this line likely means your copy of the +// proto package needs to be updated. +const _ = proto.GoGoProtoPackageIsVersion3 // please upgrade the proto package + +// OldParamas defines the parameters for the module. +type OldParamas struct { + ContractAddress string `protobuf:"bytes,1,opt,name=contract_address,json=contractAddress,proto3" json:"contract_address,omitempty"` + Root string `protobuf:"bytes,2,opt,name=root,proto3" json:"root,omitempty"` + LastSignedRoot string `protobuf:"bytes,3,opt,name=last_signed_root,json=lastSignedRoot,proto3" json:"last_signed_root,omitempty"` + LastSignedRootIndex string `protobuf:"bytes,4,opt,name=last_signed_root_index,json=lastSignedRootIndex,proto3" json:"last_signed_root_index,omitempty"` + EventName string `protobuf:"bytes,5,opt,name=event_name,json=eventName,proto3" json:"event_name,omitempty"` + RootTimestamp int64 `protobuf:"varint,6,opt,name=root_timestamp,json=rootTimestamp,proto3" json:"root_timestamp,omitempty"` + BlockHeight uint64 `protobuf:"varint,7,opt,name=block_height,json=blockHeight,proto3" json:"block_height,omitempty"` +} + +func (m *OldParamas) Reset() { *m = OldParamas{} } +func (m *OldParamas) String() string { return proto.CompactTextString(m) } +func (*OldParamas) ProtoMessage() {} +func (*OldParamas) Descriptor() ([]byte, []int) { + return fileDescriptor_31e4e5f76db9f10e, []int{0} +} +func (m *OldParamas) XXX_Unmarshal(b []byte) error { + return m.Unmarshal(b) +} +func (m *OldParamas) XXX_Marshal(b []byte, deterministic bool) ([]byte, error) { + if deterministic { + return xxx_messageInfo_Params.Marshal(b, m, deterministic) + } else { + b = b[:cap(b)] + n, err := m.MarshalToSizedBuffer(b) + if err != nil { + return nil, err + } + return b[:n], nil + } +} +func (m *OldParamas) XXX_Merge(src proto.Message) { + xxx_messageInfo_Params.Merge(m, src) +} +func (m *OldParamas) XXX_Size() int { + return m.Size() +} +func (m *OldParamas) XXX_DiscardUnknown() { + xxx_messageInfo_Params.DiscardUnknown(m) +} + +var xxx_messageInfo_Params proto.InternalMessageInfo + +func (m *OldParamas) GetContractAddress() string { + if m != nil { + return m.ContractAddress + } + return "" +} + +func (m *OldParamas) GetRoot() string { + if m != nil { + return m.Root + } + return "" +} + +func (m *OldParamas) GetLastSignedRoot() string { + if m != nil { + return m.LastSignedRoot + } + return "" +} + +func (m *OldParamas) GetLastSignedRootIndex() string { + if m != nil { + return m.LastSignedRootIndex + } + return "" +} + +func (m *OldParamas) GetEventName() string { + if m != nil { + return m.EventName + } + return "" +} + +func (m *OldParamas) GetRootTimestamp() int64 { + if m != nil { + return m.RootTimestamp + } + return 0 +} + +func (m *OldParamas) GetBlockHeight() uint64 { + if m != nil { + return m.BlockHeight + } + return 0 +} + +func init() { + proto.RegisterType((*OldParamas)(nil), "rarimo.rarimocore.rootupdater.Params") +} + +func init() { proto.RegisterFile("rootupdater/params.proto", fileDescriptor_31e4e5f76db9f10e) } + +var fileDescriptor_31e4e5f76db9f10e = []byte{ + // 314 bytes of a gzipped FileDescriptorProto + 0x1f, 0x8b, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0xff, 0x5c, 0x91, 0xc1, 0x4a, 0x03, 0x31, + 0x10, 0x86, 0x9b, 0xb6, 0x56, 0x1a, 0xb5, 0x96, 0x28, 0x12, 0x84, 0x2e, 0x55, 0x10, 0xd6, 0x83, + 0xbb, 0x48, 0x9f, 0x40, 0x4f, 0x8a, 0x20, 0xb2, 0x7a, 0xf2, 0xb2, 0xa4, 0xbb, 0x61, 0x1b, 0x6c, + 0x36, 0x4b, 0x32, 0x95, 0xfa, 0x14, 0xfa, 0x58, 0x1e, 0x7b, 0xf4, 0x28, 0xed, 0x8b, 0x48, 0x66, + 0x2d, 0x54, 0x4f, 0x33, 0x7c, 0xff, 0x97, 0x39, 0xfc, 0xa1, 0xdc, 0x1a, 0x03, 0xb3, 0x2a, 0x17, + 0x20, 0x6d, 0x5c, 0x09, 0x2b, 0xb4, 0x8b, 0x2a, 0x6b, 0xc0, 0xb0, 0x81, 0x15, 0x56, 0x69, 0x13, + 0xd5, 0x23, 0x33, 0x56, 0x46, 0x1b, 0xee, 0xf1, 0x61, 0x61, 0x0a, 0x83, 0x66, 0xec, 0xb7, 0xfa, + 0xd1, 0xe9, 0x7b, 0x93, 0x76, 0x1e, 0xf0, 0x0a, 0x3b, 0xa7, 0xfd, 0xcc, 0x94, 0x60, 0x45, 0x06, + 0xa9, 0xc8, 0x73, 0x2b, 0x9d, 0xe3, 0x64, 0x48, 0xc2, 0x6e, 0xb2, 0xbf, 0xe6, 0x57, 0x35, 0x66, + 0x8c, 0xb6, 0xfd, 0x69, 0xde, 0xc4, 0x18, 0x77, 0x16, 0xd2, 0xfe, 0x54, 0x38, 0x48, 0x9d, 0x2a, + 0x4a, 0x99, 0xa7, 0x98, 0xb7, 0x30, 0xef, 0x79, 0xfe, 0x88, 0x38, 0xf1, 0xe6, 0x88, 0x1e, 0xfd, + 0x37, 0x53, 0x55, 0xe6, 0x72, 0xce, 0xdb, 0xe8, 0x1f, 0xfc, 0xf5, 0x6f, 0x7d, 0xc4, 0x06, 0x94, + 0xca, 0x57, 0x59, 0x42, 0x5a, 0x0a, 0x2d, 0xf9, 0x16, 0x8a, 0x5d, 0x24, 0xf7, 0x42, 0x4b, 0x76, + 0x46, 0x7b, 0x78, 0x07, 0x94, 0x96, 0x0e, 0x84, 0xae, 0x78, 0x67, 0x48, 0xc2, 0x56, 0xb2, 0xe7, + 0xe9, 0xd3, 0x1a, 0xb2, 0x13, 0xba, 0x3b, 0x9e, 0x9a, 0xec, 0x25, 0x9d, 0x48, 0x55, 0x4c, 0x80, + 0x6f, 0x0f, 0x49, 0xd8, 0x4e, 0x76, 0x90, 0xdd, 0x20, 0xba, 0xbe, 0xfb, 0x5c, 0x06, 0x64, 0xb1, + 0x0c, 0xc8, 0xf7, 0x32, 0x20, 0x1f, 0xab, 0xa0, 0xb1, 0x58, 0x05, 0x8d, 0xaf, 0x55, 0xd0, 0x78, + 0xbe, 0x2c, 0x14, 0x4c, 0x66, 0xe3, 0x28, 0x33, 0x3a, 0xae, 0x4b, 0xfe, 0x1d, 0x17, 0xbe, 0xec, + 0x78, 0x1e, 0x6f, 0x7e, 0x0d, 0xbc, 0x55, 0xd2, 0x8d, 0x3b, 0xd8, 0xf2, 0xe8, 0x27, 0x00, 0x00, + 0xff, 0xff, 0x0e, 0x6b, 0x5d, 0x49, 0xb6, 0x01, 0x00, 0x00, +} + +func (m *OldParamas) Marshal() (dAtA []byte, err error) { + size := m.Size() + dAtA = make([]byte, size) + n, err := m.MarshalToSizedBuffer(dAtA[:size]) + if err != nil { + return nil, err + } + return dAtA[:n], nil +} + +func (m *OldParamas) MarshalTo(dAtA []byte) (int, error) { + size := m.Size() + return m.MarshalToSizedBuffer(dAtA[:size]) +} + +func (m *OldParamas) MarshalToSizedBuffer(dAtA []byte) (int, error) { + i := len(dAtA) + _ = i + var l int + _ = l + if m.BlockHeight != 0 { + i = encodeVarintParams(dAtA, i, uint64(m.BlockHeight)) + i-- + dAtA[i] = 0x38 + } + if m.RootTimestamp != 0 { + i = encodeVarintParams(dAtA, i, uint64(m.RootTimestamp)) + i-- + dAtA[i] = 0x30 + } + if len(m.EventName) > 0 { + i -= len(m.EventName) + copy(dAtA[i:], m.EventName) + i = encodeVarintParams(dAtA, i, uint64(len(m.EventName))) + i-- + dAtA[i] = 0x2a + } + if len(m.LastSignedRootIndex) > 0 { + i -= len(m.LastSignedRootIndex) + copy(dAtA[i:], m.LastSignedRootIndex) + i = encodeVarintParams(dAtA, i, uint64(len(m.LastSignedRootIndex))) + i-- + dAtA[i] = 0x22 + } + if len(m.LastSignedRoot) > 0 { + i -= len(m.LastSignedRoot) + copy(dAtA[i:], m.LastSignedRoot) + i = encodeVarintParams(dAtA, i, uint64(len(m.LastSignedRoot))) + i-- + dAtA[i] = 0x1a + } + if len(m.Root) > 0 { + i -= len(m.Root) + copy(dAtA[i:], m.Root) + i = encodeVarintParams(dAtA, i, uint64(len(m.Root))) + i-- + dAtA[i] = 0x12 + } + if len(m.ContractAddress) > 0 { + i -= len(m.ContractAddress) + copy(dAtA[i:], m.ContractAddress) + i = encodeVarintParams(dAtA, i, uint64(len(m.ContractAddress))) + i-- + dAtA[i] = 0xa + } + return len(dAtA) - i, nil +} + +func encodeVarintParams(dAtA []byte, offset int, v uint64) int { + offset -= sovParams(v) + base := offset + for v >= 1<<7 { + dAtA[offset] = uint8(v&0x7f | 0x80) + v >>= 7 + offset++ + } + dAtA[offset] = uint8(v) + return base +} +func (m *OldParamas) Size() (n int) { + if m == nil { + return 0 + } + var l int + _ = l + l = len(m.ContractAddress) + if l > 0 { + n += 1 + l + sovParams(uint64(l)) + } + l = len(m.Root) + if l > 0 { + n += 1 + l + sovParams(uint64(l)) + } + l = len(m.LastSignedRoot) + if l > 0 { + n += 1 + l + sovParams(uint64(l)) + } + l = len(m.LastSignedRootIndex) + if l > 0 { + n += 1 + l + sovParams(uint64(l)) + } + l = len(m.EventName) + if l > 0 { + n += 1 + l + sovParams(uint64(l)) + } + if m.RootTimestamp != 0 { + n += 1 + sovParams(uint64(m.RootTimestamp)) + } + if m.BlockHeight != 0 { + n += 1 + sovParams(uint64(m.BlockHeight)) + } + return n +} + +func sovParams(x uint64) (n int) { + return (math_bits.Len64(x|1) + 6) / 7 +} +func sozParams(x uint64) (n int) { + return sovParams(uint64((x << 1) ^ uint64((int64(x) >> 63)))) +} +func (m *OldParamas) Unmarshal(dAtA []byte) error { + l := len(dAtA) + iNdEx := 0 + for iNdEx < l { + preIndex := iNdEx + var wire uint64 + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowParams + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + wire |= uint64(b&0x7F) << shift + if b < 0x80 { + break + } + } + fieldNum := int32(wire >> 3) + wireType := int(wire & 0x7) + if wireType == 4 { + return fmt.Errorf("proto: Params: wiretype end group for non-group") + } + if fieldNum <= 0 { + return fmt.Errorf("proto: Params: illegal tag %d (wire type %d)", fieldNum, wire) + } + switch fieldNum { + case 1: + if wireType != 2 { + return fmt.Errorf("proto: wrong wireType = %d for field ContractAddress", wireType) + } + var stringLen uint64 + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowParams + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + stringLen |= uint64(b&0x7F) << shift + if b < 0x80 { + break + } + } + intStringLen := int(stringLen) + if intStringLen < 0 { + return ErrInvalidLengthParams + } + postIndex := iNdEx + intStringLen + if postIndex < 0 { + return ErrInvalidLengthParams + } + if postIndex > l { + return io.ErrUnexpectedEOF + } + m.ContractAddress = string(dAtA[iNdEx:postIndex]) + iNdEx = postIndex + case 2: + if wireType != 2 { + return fmt.Errorf("proto: wrong wireType = %d for field Root", wireType) + } + var stringLen uint64 + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowParams + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + stringLen |= uint64(b&0x7F) << shift + if b < 0x80 { + break + } + } + intStringLen := int(stringLen) + if intStringLen < 0 { + return ErrInvalidLengthParams + } + postIndex := iNdEx + intStringLen + if postIndex < 0 { + return ErrInvalidLengthParams + } + if postIndex > l { + return io.ErrUnexpectedEOF + } + m.Root = string(dAtA[iNdEx:postIndex]) + iNdEx = postIndex + case 3: + if wireType != 2 { + return fmt.Errorf("proto: wrong wireType = %d for field LastSignedRoot", wireType) + } + var stringLen uint64 + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowParams + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + stringLen |= uint64(b&0x7F) << shift + if b < 0x80 { + break + } + } + intStringLen := int(stringLen) + if intStringLen < 0 { + return ErrInvalidLengthParams + } + postIndex := iNdEx + intStringLen + if postIndex < 0 { + return ErrInvalidLengthParams + } + if postIndex > l { + return io.ErrUnexpectedEOF + } + m.LastSignedRoot = string(dAtA[iNdEx:postIndex]) + iNdEx = postIndex + case 4: + if wireType != 2 { + return fmt.Errorf("proto: wrong wireType = %d for field LastSignedRootIndex", wireType) + } + var stringLen uint64 + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowParams + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + stringLen |= uint64(b&0x7F) << shift + if b < 0x80 { + break + } + } + intStringLen := int(stringLen) + if intStringLen < 0 { + return ErrInvalidLengthParams + } + postIndex := iNdEx + intStringLen + if postIndex < 0 { + return ErrInvalidLengthParams + } + if postIndex > l { + return io.ErrUnexpectedEOF + } + m.LastSignedRootIndex = string(dAtA[iNdEx:postIndex]) + iNdEx = postIndex + case 5: + if wireType != 2 { + return fmt.Errorf("proto: wrong wireType = %d for field EventName", wireType) + } + var stringLen uint64 + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowParams + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + stringLen |= uint64(b&0x7F) << shift + if b < 0x80 { + break + } + } + intStringLen := int(stringLen) + if intStringLen < 0 { + return ErrInvalidLengthParams + } + postIndex := iNdEx + intStringLen + if postIndex < 0 { + return ErrInvalidLengthParams + } + if postIndex > l { + return io.ErrUnexpectedEOF + } + m.EventName = string(dAtA[iNdEx:postIndex]) + iNdEx = postIndex + case 6: + if wireType != 0 { + return fmt.Errorf("proto: wrong wireType = %d for field RootTimestamp", wireType) + } + m.RootTimestamp = 0 + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowParams + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + m.RootTimestamp |= int64(b&0x7F) << shift + if b < 0x80 { + break + } + } + case 7: + if wireType != 0 { + return fmt.Errorf("proto: wrong wireType = %d for field BlockHeight", wireType) + } + m.BlockHeight = 0 + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowParams + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + m.BlockHeight |= uint64(b&0x7F) << shift + if b < 0x80 { + break + } + } + default: + iNdEx = preIndex + skippy, err := skipParams(dAtA[iNdEx:]) + if err != nil { + return err + } + if (skippy < 0) || (iNdEx+skippy) < 0 { + return ErrInvalidLengthParams + } + if (iNdEx + skippy) > l { + return io.ErrUnexpectedEOF + } + iNdEx += skippy + } + } + + if iNdEx > l { + return io.ErrUnexpectedEOF + } + return nil +} +func skipParams(dAtA []byte) (n int, err error) { + l := len(dAtA) + iNdEx := 0 + depth := 0 + for iNdEx < l { + var wire uint64 + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return 0, ErrIntOverflowParams + } + if iNdEx >= l { + return 0, io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + wire |= (uint64(b) & 0x7F) << shift + if b < 0x80 { + break + } + } + wireType := int(wire & 0x7) + switch wireType { + case 0: + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return 0, ErrIntOverflowParams + } + if iNdEx >= l { + return 0, io.ErrUnexpectedEOF + } + iNdEx++ + if dAtA[iNdEx-1] < 0x80 { + break + } + } + case 1: + iNdEx += 8 + case 2: + var length int + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return 0, ErrIntOverflowParams + } + if iNdEx >= l { + return 0, io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + length |= (int(b) & 0x7F) << shift + if b < 0x80 { + break + } + } + if length < 0 { + return 0, ErrInvalidLengthParams + } + iNdEx += length + case 3: + depth++ + case 4: + if depth == 0 { + return 0, ErrUnexpectedEndOfGroupParams + } + depth-- + case 5: + iNdEx += 4 + default: + return 0, fmt.Errorf("proto: illegal wireType %d", wireType) + } + if iNdEx < 0 { + return 0, ErrInvalidLengthParams + } + if depth == 0 { + return iNdEx, nil + } + } + return 0, io.ErrUnexpectedEOF +} + +var ( + ErrInvalidLengthParams = fmt.Errorf("proto: negative length found during unmarshaling") + ErrIntOverflowParams = fmt.Errorf("proto: integer overflow") + ErrUnexpectedEndOfGroupParams = fmt.Errorf("proto: unexpected end of group") +) diff --git a/x/rootupdater/module.go b/x/rootupdater/module.go index 833b64b2..9d7d3798 100644 --- a/x/rootupdater/module.go +++ b/x/rootupdater/module.go @@ -91,16 +91,18 @@ func (AppModuleBasic) GetQueryCmd() *cobra.Command { type AppModule struct { AppModuleBasic - keeper keeper.Keeper + keeper keeper.Keeper + migrator keeper.Migrator } func NewAppModule( cdc codec.Codec, - keeper keeper.Keeper, + kp keeper.Keeper, ) AppModule { return AppModule{ AppModuleBasic: NewAppModuleBasic(cdc), - keeper: keeper, + keeper: kp, + migrator: keeper.NewMigrator(kp), } } @@ -121,6 +123,10 @@ func (am AppModule) LegacyQuerierHandler(_ *codec.LegacyAmino) sdk.Querier { func (am AppModule) RegisterServices(cfg module.Configurator) { types.RegisterMsgServer(cfg.MsgServer(), keeper.NewMsgServerImpl(am.keeper)) types.RegisterQueryServer(cfg.QueryServer(), am.keeper) + + if err := cfg.RegisterMigration(types.ModuleName, 1, am.migrator.Migrate1to2); err != nil { + panic(err) + } } // RegisterInvariants registers the invariants of the module. If an invariant deviates from its predicted value, the InvariantRegistry triggers appropriate logic (most often the chain will be halted) @@ -144,7 +150,7 @@ func (am AppModule) ExportGenesis(ctx sdk.Context, cdc codec.JSONCodec) json.Raw } // ConsensusVersion is a sequence number for state-breaking change of the module. It should be incremented on each consensus-breaking change introduced by the module. To avoid wrong/empty versions, the initial version should be set to 1 -func (AppModule) ConsensusVersion() uint64 { return 1 } +func (AppModule) ConsensusVersion() uint64 { return 2 } // BeginBlock contains the logic that is automatically triggered at the beginning of each block func (am AppModule) BeginBlock(_ sdk.Context, _ abci.RequestBeginBlock) {} From 4fc04817b015338276a95373639339af33c0ca6d Mon Sep 17 00:00:00 2001 From: Mark Cherepovskyi Date: Tue, 3 Sep 2024 20:45:44 +0300 Subject: [PATCH 3/3] update handler --- app/app.go | 7 +++++++ go.mod | 1 - go.sum | 4 ---- 3 files changed, 7 insertions(+), 5 deletions(-) diff --git a/app/app.go b/app/app.go index 40c26951..274458a5 100644 --- a/app/app.go +++ b/app/app.go @@ -1161,6 +1161,13 @@ func New( }, ) + app.UpgradeKeeper.SetUpgradeHandler( + "v1.1.4-rc6", + func(ctx sdk.Context, plan upgradetypes.Plan, fromVM module.VersionMap) (module.VersionMap, error) { + return app.mm.RunMigrations(ctx, app.configurator, fromVM) + }, + ) + if loadLatest { if err := app.LoadLatestVersion(); err != nil { tmos.Exit(err.Error()) diff --git a/go.mod b/go.mod index acb24bd7..39514b86 100644 --- a/go.mod +++ b/go.mod @@ -92,7 +92,6 @@ require ( github.com/felixge/httpsnoop v1.0.4 // indirect github.com/fsnotify/fsnotify v1.7.0 // indirect github.com/gballet/go-libpcsclite v0.0.0-20190607065134-2772fd86a8ff // indirect - github.com/ghodss/yaml v1.0.0 // indirect github.com/gin-gonic/gin v1.8.1 // indirect github.com/github/smimesign v0.2.0 // indirect github.com/go-kit/kit v0.12.0 // indirect diff --git a/go.sum b/go.sum index 66c35e63..c8b6f34b 100644 --- a/go.sum +++ b/go.sum @@ -810,7 +810,6 @@ github.com/gballet/go-libpcsclite v0.0.0-20190607065134-2772fd86a8ff h1:tY80oXqG github.com/gballet/go-libpcsclite v0.0.0-20190607065134-2772fd86a8ff/go.mod h1:x7DCsMOv1taUwEWCzT4cmDeAkigA5/QCwUodaVOe8Ww= github.com/getkin/kin-openapi v0.53.0/go.mod h1:7Yn5whZr5kJi6t+kShccXS8ae1APpYTW6yheSwk8Yi4= github.com/getkin/kin-openapi v0.61.0/go.mod h1:7Yn5whZr5kJi6t+kShccXS8ae1APpYTW6yheSwk8Yi4= -github.com/ghodss/yaml v1.0.0 h1:wQHKEahhL6wmXdzwWG11gIVCkOv05bNOh+Rxn0yngAk= github.com/ghodss/yaml v1.0.0/go.mod h1:4dBDuWmgqj2HViK6kFavaiC9ZROes6MMH2rRYeMEF04= github.com/gin-contrib/sse v0.1.0 h1:Y/yl/+YNO8GZSjAhjMsSuLt29uWRFHdHYUb5lYOV9qE= github.com/gin-contrib/sse v0.1.0/go.mod h1:RHrZQHXnP2xjPF+u1gW/2HnVO7nvIa9PG3Gm+fLHvGI= @@ -1154,7 +1153,6 @@ github.com/json-iterator/go v1.1.8/go.mod h1:KdQUCv79m/52Kvf8AW2vK1V8akMuk1QjK/u github.com/json-iterator/go v1.1.9/go.mod h1:KdQUCv79m/52Kvf8AW2vK1V8akMuk1QjK/uOdHXbAo4= github.com/json-iterator/go v1.1.10/go.mod h1:KdQUCv79m/52Kvf8AW2vK1V8akMuk1QjK/uOdHXbAo4= github.com/json-iterator/go v1.1.12 h1:PV8peI4a0ysnczrg+LtxykD8LfKY9ML6u2jnxaEnrnM= -github.com/json-iterator/go v1.1.12/go.mod h1:e30LSqwooZae/UwlEbR2852Gd8hjQvJoHmT4TnhNGBo= github.com/jstemmer/go-junit-report v0.0.0-20190106144839-af01ea7f8024/go.mod h1:6v2b51hI/fHJwM22ozAgKL4VKDeJcHhJFhtBdhmNjmU= github.com/jstemmer/go-junit-report v0.9.1/go.mod h1:Brl9GWCQeLvo8nXZwPNNblvFj/XSXhF0NWZEnDohbsk= github.com/jsternberg/zap-logfmt v1.0.0/go.mod h1:uvPs/4X51zdkcm5jXl5SYoN+4RK21K8mysFmDaM/h+o= @@ -1279,7 +1277,6 @@ github.com/modern-go/concurrent v0.0.0-20180306012644-bacd9c7ef1dd/go.mod h1:6dJ github.com/modern-go/reflect2 v0.0.0-20180701023420-4b7aa43c6742/go.mod h1:bx2lNnkwVCuqBIxFjflWJWanXIb3RllmbCylyMrvgv0= github.com/modern-go/reflect2 v1.0.1/go.mod h1:bx2lNnkwVCuqBIxFjflWJWanXIb3RllmbCylyMrvgv0= github.com/modern-go/reflect2 v1.0.2 h1:xBagoLtFs94CBntxluKeaWgTMpvLxC4ur3nMaC9Gz0M= -github.com/modern-go/reflect2 v1.0.2/go.mod h1:yWuevngMOJpCy52FWWMvUC8ws7m/LJsjYzDa0/r8luk= github.com/modocache/gover v0.0.0-20171022184752-b58185e213c5/go.mod h1:caMODM3PzxT8aQXRPkAt8xlV/e7d7w8GM5g0fa5F0D8= github.com/mschoch/smat v0.0.0-20160514031455-90eadee771ae/go.mod h1:qAyveg+e4CE+eKJXWVjKXM4ck2QobLqTDytGJbLLhJg= github.com/mtibben/percent v0.2.1 h1:5gssi8Nqo8QU/r2pynCm+hBQHpkB/uNK7BJCFogWdzs= @@ -1533,7 +1530,6 @@ github.com/subosito/gotenv v1.6.0 h1:9NlTDc1FTs4qu0DDq7AEtTPNw6SVm7uBMsUCUjABIf8 github.com/subosito/gotenv v1.6.0/go.mod h1:Dk4QP5c2W3ibzajGcXpNraDfq2IrhjMIvMSWPKKo0FU= github.com/syndtr/goleveldb v1.0.1-0.20210819022825-2ae1ddf74ef7 h1:epCh84lMvA70Z7CTTCmYQn2CKbY8j86K7/FAIr141uY= github.com/syndtr/goleveldb v1.0.1-0.20210819022825-2ae1ddf74ef7/go.mod h1:q4W45IWZaF22tdD+VEXcAWRA037jwmWEB5VWYORlTpc= -github.com/tecbot/gorocksdb v0.0.0-20191217155057-f0fad39f321c/go.mod h1:ahpPrc7HpcfEWDQRZEmnXMzHY03mLDYMCxeDzy46i+8= github.com/tendermint/btcd v0.1.1 h1:0VcxPfflS2zZ3RiOAHkBiFUcPvbtRj5O7zHmcJWHV7s= github.com/tendermint/btcd v0.1.1/go.mod h1:DC6/m53jtQzr/NFmMNEu0rxf18/ktVoVtMrnDD5pN+U= github.com/tendermint/crypto v0.0.0-20191022145703-50d29ede1e15 h1:hqAk8riJvK4RMWx1aInLzndwxKalgi5rTqgfXxOxbEI=