From 9bfb7a35826ca38dd9e30efb1af4ebe6f454c101 Mon Sep 17 00:00:00 2001 From: Mario Karagiorgas Date: Wed, 21 Jul 2021 21:04:34 +0300 Subject: [PATCH 01/49] Add authority cmd schedule/apply plan (WIP) --- docs/proto/em/proto-docs.md | 58 ++ proto/em/authority/v1/tx.proto | 27 +- x/authority/client/cli/tx.go | 44 ++ x/authority/types/tx.pb.go | 976 +++++++++++++++++++++++++++++---- 4 files changed, 998 insertions(+), 107 deletions(-) diff --git a/docs/proto/em/proto-docs.md b/docs/proto/em/proto-docs.md index 5fbd8c6d..f18a9229 100644 --- a/docs/proto/em/proto-docs.md +++ b/docs/proto/em/proto-docs.md @@ -18,12 +18,16 @@ - [Query](#em.authority.v1.Query) - [em/authority/v1/tx.proto](#em/authority/v1/tx.proto) + - [MsgApplyUpgrade](#em.authority.v1.MsgApplyUpgrade) + - [MsgApplyUpgradeResponse](#em.authority.v1.MsgApplyUpgradeResponse) - [MsgCreateIssuer](#em.authority.v1.MsgCreateIssuer) - [MsgCreateIssuerResponse](#em.authority.v1.MsgCreateIssuerResponse) - [MsgDestroyIssuer](#em.authority.v1.MsgDestroyIssuer) - [MsgDestroyIssuerResponse](#em.authority.v1.MsgDestroyIssuerResponse) - [MsgReplaceAuthority](#em.authority.v1.MsgReplaceAuthority) - [MsgReplaceAuthorityResponse](#em.authority.v1.MsgReplaceAuthorityResponse) + - [MsgScheduleUpgrade](#em.authority.v1.MsgScheduleUpgrade) + - [MsgScheduleUpgradeResponse](#em.authority.v1.MsgScheduleUpgradeResponse) - [MsgSetGasPrices](#em.authority.v1.MsgSetGasPrices) - [MsgSetGasPricesResponse](#em.authority.v1.MsgSetGasPricesResponse) @@ -283,6 +287,32 @@ + + +### MsgApplyUpgrade + + + +| Field | Type | Label | Description | +| ----- | ---- | ----- | ----------- | +| `authority` | [string](#string) | | | +| `plan` | [cosmos.upgrade.v1beta1.Plan](#cosmos.upgrade.v1beta1.Plan) | | | + + + + + + + + +### MsgApplyUpgradeResponse + + + + + + + ### MsgCreateIssuer @@ -367,6 +397,32 @@ + + +### MsgScheduleUpgrade + + + +| Field | Type | Label | Description | +| ----- | ---- | ----- | ----------- | +| `authority` | [string](#string) | | | +| `plan` | [cosmos.upgrade.v1beta1.Plan](#cosmos.upgrade.v1beta1.Plan) | | | + + + + + + + + +### MsgScheduleUpgradeResponse + + + + + + + ### MsgSetGasPrices @@ -410,6 +466,8 @@ | `DestroyIssuer` | [MsgDestroyIssuer](#em.authority.v1.MsgDestroyIssuer) | [MsgDestroyIssuerResponse](#em.authority.v1.MsgDestroyIssuerResponse) | | | | `SetGasPrices` | [MsgSetGasPrices](#em.authority.v1.MsgSetGasPrices) | [MsgSetGasPricesResponse](#em.authority.v1.MsgSetGasPricesResponse) | | | | `ReplaceAuthority` | [MsgReplaceAuthority](#em.authority.v1.MsgReplaceAuthority) | [MsgReplaceAuthorityResponse](#em.authority.v1.MsgReplaceAuthorityResponse) | | | +| `ScheduleUpgrade` | [MsgScheduleUpgrade](#em.authority.v1.MsgScheduleUpgrade) | [MsgScheduleUpgradeResponse](#em.authority.v1.MsgScheduleUpgradeResponse) | | | +| `ApplyUpgrade` | [MsgApplyUpgrade](#em.authority.v1.MsgApplyUpgrade) | [MsgApplyUpgradeResponse](#em.authority.v1.MsgApplyUpgradeResponse) | | | diff --git a/proto/em/authority/v1/tx.proto b/proto/em/authority/v1/tx.proto index f95d77db..a52598d6 100644 --- a/proto/em/authority/v1/tx.proto +++ b/proto/em/authority/v1/tx.proto @@ -3,6 +3,7 @@ package em.authority.v1; import "gogoproto/gogo.proto"; import "cosmos/base/v1beta1/coin.proto"; +import "cosmos/upgrade/v1beta1/upgrade.proto"; option go_package = "github.com/e-money/em-ledger/x/authority/types"; @@ -15,6 +16,10 @@ service Msg { rpc SetGasPrices(MsgSetGasPrices) returns (MsgSetGasPricesResponse); rpc ReplaceAuthority(MsgReplaceAuthority) returns (MsgReplaceAuthorityResponse); + + rpc ScheduleUpgrade(MsgScheduleUpgrade) returns (MsgScheduleUpgradeResponse); + + rpc ApplyUpgrade(MsgApplyUpgrade) returns (MsgApplyUpgradeResponse); } message MsgCreateIssuer { @@ -51,4 +56,24 @@ message MsgReplaceAuthority { message MsgReplaceAuthorityResponse { string new_authority_address = 1 [ (gogoproto.moretags) = "yaml:\"new_authority_address\"" ]; -} \ No newline at end of file +} + +message MsgScheduleUpgrade { + string authority = 1 [ (gogoproto.moretags) = "yaml:\"authority\"" ]; + cosmos.upgrade.v1beta1.Plan plan = 2 [ + (gogoproto.moretags) = "yaml:\"plan\"", + (gogoproto.nullable) = false + ]; +} + +message MsgScheduleUpgradeResponse {} + +message MsgApplyUpgrade { + string authority = 1 [ (gogoproto.moretags) = "yaml:\"authority\"" ]; + cosmos.upgrade.v1beta1.Plan plan = 2 [ + (gogoproto.moretags) = "yaml:\"plan\"", + (gogoproto.nullable) = false + ]; +} + +message MsgApplyUpgradeResponse {} \ No newline at end of file diff --git a/x/authority/client/cli/tx.go b/x/authority/client/cli/tx.go index df4a9e27..e7e8ebec 100644 --- a/x/authority/client/cli/tx.go +++ b/x/authority/client/cli/tx.go @@ -5,10 +5,13 @@ package cli import ( + "time" + "github.com/cosmos/cosmos-sdk/client" "github.com/cosmos/cosmos-sdk/client/flags" "github.com/cosmos/cosmos-sdk/client/tx" sdk "github.com/cosmos/cosmos-sdk/types" + types1 "github.com/cosmos/cosmos-sdk/x/upgrade/types" "github.com/e-money/em-ledger/util" "github.com/e-money/em-ledger/x/authority/types" "github.com/spf13/cobra" @@ -171,3 +174,44 @@ For a 24-hour grace period the former authority key is equivalent to the new one flags.AddTxFlagsToCmd(cmd) return cmd } + +func GetCmdScheduleUpgrade() *cobra.Command { + cmd := &cobra.Command{ + Use: "schedule-upg [authority_key_or_address] plan_name", + Short: "Schedule a software upgrade.", + Example: "emd tx schedule-upg emoney1n5ggspeff4fxc87dvmg0ematr3qzw5l4v20mdv 0-43", + Long: `Schedule a software upgrade.`, + Args: cobra.ExactArgs(2), + RunE: func(cmd *cobra.Command, args []string) error { + f := cmd.Flags() + + err := f.Set(flags.FlagFrom, args[0]) + if err != nil { + return err + } + + clientCtx, err := client.GetClientTxContext(cmd) + if err != nil { + return err + } + + plan := types1.Plan{ + Name: args[1], + Time: time.Now(), + } + + _ = &types.MsgScheduleUpgrade{ + Authority: clientCtx.GetFromAddress().String(), + Plan: plan, + } + + if err := msg.ValidateBasic(); err != nil { + return err + } + + return tx.GenerateOrBroadcastTxCLI(clientCtx, cmd.Flags(), msg) + }, + } + flags.AddTxFlagsToCmd(cmd) + return cmd +} diff --git a/x/authority/types/tx.pb.go b/x/authority/types/tx.pb.go index ada314cd..235f5649 100644 --- a/x/authority/types/tx.pb.go +++ b/x/authority/types/tx.pb.go @@ -8,6 +8,7 @@ import ( fmt "fmt" github_com_cosmos_cosmos_sdk_types "github.com/cosmos/cosmos-sdk/types" types "github.com/cosmos/cosmos-sdk/types" + types1 "github.com/cosmos/cosmos-sdk/x/upgrade/types" _ "github.com/gogo/protobuf/gogoproto" grpc1 "github.com/gogo/protobuf/grpc" proto "github.com/gogo/protobuf/proto" @@ -398,6 +399,182 @@ func (m *MsgReplaceAuthorityResponse) GetNewAuthorityAddress() string { return "" } +type MsgScheduleUpgrade struct { + Authority string `protobuf:"bytes,1,opt,name=authority,proto3" json:"authority,omitempty" yaml:"authority"` + Plan types1.Plan `protobuf:"bytes,2,opt,name=plan,proto3" json:"plan" yaml:"plan"` +} + +func (m *MsgScheduleUpgrade) Reset() { *m = MsgScheduleUpgrade{} } +func (m *MsgScheduleUpgrade) String() string { return proto.CompactTextString(m) } +func (*MsgScheduleUpgrade) ProtoMessage() {} +func (*MsgScheduleUpgrade) Descriptor() ([]byte, []int) { + return fileDescriptor_1601f633ca5d263c, []int{8} +} +func (m *MsgScheduleUpgrade) XXX_Unmarshal(b []byte) error { + return m.Unmarshal(b) +} +func (m *MsgScheduleUpgrade) XXX_Marshal(b []byte, deterministic bool) ([]byte, error) { + if deterministic { + return xxx_messageInfo_MsgScheduleUpgrade.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 *MsgScheduleUpgrade) XXX_Merge(src proto.Message) { + xxx_messageInfo_MsgScheduleUpgrade.Merge(m, src) +} +func (m *MsgScheduleUpgrade) XXX_Size() int { + return m.Size() +} +func (m *MsgScheduleUpgrade) XXX_DiscardUnknown() { + xxx_messageInfo_MsgScheduleUpgrade.DiscardUnknown(m) +} + +var xxx_messageInfo_MsgScheduleUpgrade proto.InternalMessageInfo + +func (m *MsgScheduleUpgrade) GetAuthority() string { + if m != nil { + return m.Authority + } + return "" +} + +func (m *MsgScheduleUpgrade) GetPlan() types1.Plan { + if m != nil { + return m.Plan + } + return types1.Plan{} +} + +type MsgScheduleUpgradeResponse struct { +} + +func (m *MsgScheduleUpgradeResponse) Reset() { *m = MsgScheduleUpgradeResponse{} } +func (m *MsgScheduleUpgradeResponse) String() string { return proto.CompactTextString(m) } +func (*MsgScheduleUpgradeResponse) ProtoMessage() {} +func (*MsgScheduleUpgradeResponse) Descriptor() ([]byte, []int) { + return fileDescriptor_1601f633ca5d263c, []int{9} +} +func (m *MsgScheduleUpgradeResponse) XXX_Unmarshal(b []byte) error { + return m.Unmarshal(b) +} +func (m *MsgScheduleUpgradeResponse) XXX_Marshal(b []byte, deterministic bool) ([]byte, error) { + if deterministic { + return xxx_messageInfo_MsgScheduleUpgradeResponse.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 *MsgScheduleUpgradeResponse) XXX_Merge(src proto.Message) { + xxx_messageInfo_MsgScheduleUpgradeResponse.Merge(m, src) +} +func (m *MsgScheduleUpgradeResponse) XXX_Size() int { + return m.Size() +} +func (m *MsgScheduleUpgradeResponse) XXX_DiscardUnknown() { + xxx_messageInfo_MsgScheduleUpgradeResponse.DiscardUnknown(m) +} + +var xxx_messageInfo_MsgScheduleUpgradeResponse proto.InternalMessageInfo + +type MsgApplyUpgrade struct { + Authority string `protobuf:"bytes,1,opt,name=authority,proto3" json:"authority,omitempty" yaml:"authority"` + Plan types1.Plan `protobuf:"bytes,2,opt,name=plan,proto3" json:"plan" yaml:"plan"` +} + +func (m *MsgApplyUpgrade) Reset() { *m = MsgApplyUpgrade{} } +func (m *MsgApplyUpgrade) String() string { return proto.CompactTextString(m) } +func (*MsgApplyUpgrade) ProtoMessage() {} +func (*MsgApplyUpgrade) Descriptor() ([]byte, []int) { + return fileDescriptor_1601f633ca5d263c, []int{10} +} +func (m *MsgApplyUpgrade) XXX_Unmarshal(b []byte) error { + return m.Unmarshal(b) +} +func (m *MsgApplyUpgrade) XXX_Marshal(b []byte, deterministic bool) ([]byte, error) { + if deterministic { + return xxx_messageInfo_MsgApplyUpgrade.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 *MsgApplyUpgrade) XXX_Merge(src proto.Message) { + xxx_messageInfo_MsgApplyUpgrade.Merge(m, src) +} +func (m *MsgApplyUpgrade) XXX_Size() int { + return m.Size() +} +func (m *MsgApplyUpgrade) XXX_DiscardUnknown() { + xxx_messageInfo_MsgApplyUpgrade.DiscardUnknown(m) +} + +var xxx_messageInfo_MsgApplyUpgrade proto.InternalMessageInfo + +func (m *MsgApplyUpgrade) GetAuthority() string { + if m != nil { + return m.Authority + } + return "" +} + +func (m *MsgApplyUpgrade) GetPlan() types1.Plan { + if m != nil { + return m.Plan + } + return types1.Plan{} +} + +type MsgApplyUpgradeResponse struct { +} + +func (m *MsgApplyUpgradeResponse) Reset() { *m = MsgApplyUpgradeResponse{} } +func (m *MsgApplyUpgradeResponse) String() string { return proto.CompactTextString(m) } +func (*MsgApplyUpgradeResponse) ProtoMessage() {} +func (*MsgApplyUpgradeResponse) Descriptor() ([]byte, []int) { + return fileDescriptor_1601f633ca5d263c, []int{11} +} +func (m *MsgApplyUpgradeResponse) XXX_Unmarshal(b []byte) error { + return m.Unmarshal(b) +} +func (m *MsgApplyUpgradeResponse) XXX_Marshal(b []byte, deterministic bool) ([]byte, error) { + if deterministic { + return xxx_messageInfo_MsgApplyUpgradeResponse.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 *MsgApplyUpgradeResponse) XXX_Merge(src proto.Message) { + xxx_messageInfo_MsgApplyUpgradeResponse.Merge(m, src) +} +func (m *MsgApplyUpgradeResponse) XXX_Size() int { + return m.Size() +} +func (m *MsgApplyUpgradeResponse) XXX_DiscardUnknown() { + xxx_messageInfo_MsgApplyUpgradeResponse.DiscardUnknown(m) +} + +var xxx_messageInfo_MsgApplyUpgradeResponse proto.InternalMessageInfo + func init() { proto.RegisterType((*MsgCreateIssuer)(nil), "em.authority.v1.MsgCreateIssuer") proto.RegisterType((*MsgCreateIssuerResponse)(nil), "em.authority.v1.MsgCreateIssuerResponse") @@ -407,48 +584,59 @@ func init() { proto.RegisterType((*MsgSetGasPricesResponse)(nil), "em.authority.v1.MsgSetGasPricesResponse") proto.RegisterType((*MsgReplaceAuthority)(nil), "em.authority.v1.MsgReplaceAuthority") proto.RegisterType((*MsgReplaceAuthorityResponse)(nil), "em.authority.v1.MsgReplaceAuthorityResponse") + proto.RegisterType((*MsgScheduleUpgrade)(nil), "em.authority.v1.MsgScheduleUpgrade") + proto.RegisterType((*MsgScheduleUpgradeResponse)(nil), "em.authority.v1.MsgScheduleUpgradeResponse") + proto.RegisterType((*MsgApplyUpgrade)(nil), "em.authority.v1.MsgApplyUpgrade") + proto.RegisterType((*MsgApplyUpgradeResponse)(nil), "em.authority.v1.MsgApplyUpgradeResponse") } func init() { proto.RegisterFile("em/authority/v1/tx.proto", fileDescriptor_1601f633ca5d263c) } var fileDescriptor_1601f633ca5d263c = []byte{ - // 569 bytes of a gzipped FileDescriptorProto - 0x1f, 0x8b, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0xff, 0xbc, 0x54, 0xc1, 0x6e, 0xd3, 0x40, - 0x10, 0x8d, 0x1b, 0xa9, 0x52, 0x97, 0x46, 0x6d, 0xdd, 0x20, 0x8c, 0xa9, 0xec, 0xb0, 0xe2, 0x90, - 0x0a, 0xe2, 0x55, 0xc2, 0x01, 0x09, 0x89, 0x43, 0xd3, 0x4a, 0x94, 0x43, 0x24, 0x64, 0x38, 0x45, - 0x42, 0x91, 0xe3, 0x0c, 0xae, 0x45, 0xec, 0x0d, 0x9e, 0x4d, 0xda, 0xdc, 0x41, 0xe2, 0xc8, 0x6f, - 0xc0, 0x97, 0xf4, 0x82, 0xd4, 0x23, 0x27, 0x83, 0x92, 0x3f, 0xc8, 0x17, 0xa0, 0x7a, 0x13, 0x27, - 0x0e, 0x96, 0x8a, 0x7a, 0xe0, 0x94, 0xc8, 0xef, 0xbd, 0x99, 0x37, 0x3b, 0x6f, 0x97, 0x68, 0x10, - 0x30, 0x67, 0x28, 0xce, 0x78, 0xe4, 0x8b, 0x31, 0x1b, 0xd5, 0x99, 0xb8, 0xb0, 0x06, 0x11, 0x17, - 0x5c, 0xdd, 0x81, 0xc0, 0x4a, 0x11, 0x6b, 0x54, 0xd7, 0xcb, 0x1e, 0xf7, 0x78, 0x82, 0xb1, 0xeb, - 0x7f, 0x92, 0xa6, 0x1b, 0x2e, 0xc7, 0x80, 0x23, 0xeb, 0x3a, 0x08, 0x6c, 0x54, 0xef, 0x82, 0x70, - 0xea, 0xcc, 0xe5, 0x7e, 0x28, 0x71, 0xfa, 0x4d, 0x21, 0x3b, 0x2d, 0xf4, 0x8e, 0x23, 0x70, 0x04, - 0xbc, 0x42, 0x1c, 0x42, 0xa4, 0x36, 0xc8, 0x56, 0x5a, 0x59, 0x53, 0x2a, 0x4a, 0x75, 0xab, 0x59, - 0x9e, 0xc5, 0xe6, 0xee, 0xd8, 0x09, 0xfa, 0xcf, 0x69, 0x0a, 0x51, 0x7b, 0x49, 0x53, 0x0f, 0xc9, - 0xa6, 0x9f, 0xa8, 0xb5, 0x8d, 0x44, 0xb0, 0x37, 0x8b, 0xcd, 0x92, 0x14, 0xc8, 0xef, 0xd4, 0x9e, - 0x13, 0xd4, 0x67, 0xa4, 0xd4, 0x83, 0x90, 0x07, 0x7e, 0xe8, 0x08, 0x9f, 0x87, 0xa8, 0x15, 0x2b, - 0xc5, 0xac, 0x22, 0x81, 0x91, 0xda, 0x59, 0x1e, 0xbd, 0x4f, 0xee, 0xad, 0x59, 0xb5, 0x01, 0x07, - 0x3c, 0x44, 0xa0, 0x1f, 0xc9, 0x6e, 0x0b, 0xbd, 0x13, 0x40, 0x11, 0xf1, 0xf1, 0x7f, 0x19, 0x83, - 0xea, 0x44, 0x5b, 0x6f, 0x99, 0xda, 0xf9, 0x21, 0x4f, 0xf5, 0x0d, 0x88, 0x97, 0x0e, 0xbe, 0x8e, - 0x7c, 0x17, 0xf0, 0x56, 0x76, 0x3e, 0x2b, 0x84, 0x78, 0x0e, 0x76, 0x06, 0x49, 0x09, 0x6d, 0xa3, - 0x52, 0xac, 0xde, 0x69, 0x1c, 0x58, 0x72, 0xa7, 0xd6, 0xf5, 0x4e, 0xad, 0xf9, 0x4e, 0xad, 0x13, - 0x70, 0x8f, 0xb9, 0x1f, 0x36, 0x4f, 0x2f, 0x63, 0xb3, 0x30, 0x8b, 0xcd, 0x3d, 0x59, 0x77, 0xa9, - 0xa6, 0xdf, 0x7f, 0x99, 0x8f, 0x3d, 0x5f, 0x9c, 0x0d, 0xbb, 0x96, 0xcb, 0x03, 0x36, 0x0f, 0x86, - 0xfc, 0xa9, 0x61, 0xef, 0x03, 0x13, 0xe3, 0x01, 0xe0, 0xa2, 0x10, 0xda, 0x5b, 0xde, 0xc2, 0xfb, - 0xfc, 0xe4, 0x57, 0xc7, 0x49, 0x47, 0xfd, 0xa2, 0x90, 0xfd, 0x16, 0x7a, 0x36, 0x0c, 0xfa, 0x8e, - 0x0b, 0x47, 0xa9, 0xf5, 0xdb, 0x8c, 0xfb, 0x82, 0x94, 0x42, 0x38, 0xef, 0x2c, 0x75, 0x72, 0x09, - 0xda, 0x2c, 0x36, 0xcb, 0x52, 0x97, 0x81, 0xa9, 0xbd, 0x1d, 0xc2, 0x79, 0xda, 0x92, 0x22, 0x79, - 0x90, 0xe3, 0x64, 0xe1, 0x54, 0x7d, 0x4b, 0xee, 0x66, 0xe4, 0x1d, 0xa7, 0xd7, 0x8b, 0x00, 0x71, - 0xee, 0xae, 0x32, 0x8b, 0xcd, 0x83, 0x9c, 0x2e, 0x0b, 0x1a, 0xb5, 0xf7, 0x57, 0xbb, 0x1d, 0xc9, - 0xaf, 0x8d, 0x4f, 0x45, 0x52, 0x6c, 0xa1, 0xa7, 0xb6, 0xc9, 0x76, 0xe6, 0x12, 0x55, 0xac, 0xb5, - 0x0b, 0x6a, 0xad, 0x65, 0x57, 0xaf, 0xde, 0xc4, 0x48, 0x9d, 0xbf, 0x23, 0xa5, 0x6c, 0xb4, 0x1f, - 0xe6, 0x49, 0x33, 0x14, 0xfd, 0xf0, 0x46, 0x4a, 0x5a, 0xbe, 0x4d, 0xb6, 0x33, 0x49, 0xcd, 0xb5, - 0xbe, 0xca, 0xc8, 0xb7, 0x9e, 0x17, 0x0f, 0xf5, 0x3d, 0xd9, 0xfd, 0x2b, 0x1a, 0x8f, 0xf2, 0xd4, - 0xeb, 0x2c, 0xfd, 0xc9, 0xbf, 0xb0, 0x16, 0x7d, 0x9a, 0xa7, 0x97, 0x13, 0x43, 0xb9, 0x9a, 0x18, - 0xca, 0xef, 0x89, 0xa1, 0x7c, 0x9d, 0x1a, 0x85, 0xab, 0xa9, 0x51, 0xf8, 0x39, 0x35, 0x0a, 0x6d, - 0x6b, 0x25, 0xf3, 0x50, 0x0b, 0x78, 0x08, 0x63, 0x06, 0x41, 0xad, 0x0f, 0x3d, 0x0f, 0x22, 0x76, - 0xb1, 0xf2, 0xbc, 0x26, 0xf9, 0xef, 0x6e, 0x26, 0x0f, 0xe3, 0xd3, 0x3f, 0x01, 0x00, 0x00, 0xff, - 0xff, 0x3b, 0x36, 0x40, 0x46, 0x7b, 0x05, 0x00, 0x00, + // 685 bytes of a gzipped FileDescriptorProto + 0x1f, 0x8b, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0xff, 0xcc, 0x55, 0xcd, 0x4e, 0xd4, 0x50, + 0x14, 0x9e, 0x32, 0x84, 0x84, 0x0b, 0x13, 0xa0, 0x60, 0xac, 0x95, 0xb4, 0xe3, 0x95, 0x05, 0x04, + 0x69, 0x33, 0xb8, 0x30, 0x31, 0x71, 0xc1, 0x80, 0x11, 0x17, 0x93, 0x90, 0xaa, 0x1b, 0x12, 0x43, + 0xee, 0xb4, 0xc7, 0xd2, 0xd8, 0xf6, 0xd6, 0xde, 0x0e, 0x30, 0x0f, 0x60, 0xe2, 0xc2, 0x44, 0x5f, + 0x43, 0xdf, 0xc3, 0x84, 0x8d, 0x09, 0x4b, 0x57, 0xa3, 0x81, 0x37, 0x98, 0x27, 0x30, 0xd3, 0xdb, + 0x76, 0xda, 0xd2, 0x04, 0x32, 0x0b, 0xe3, 0x6a, 0xa6, 0x3d, 0xdf, 0x77, 0xce, 0x77, 0x7e, 0x8b, + 0x24, 0xf0, 0x74, 0xd2, 0x8b, 0x8e, 0x69, 0xe8, 0x44, 0x7d, 0xfd, 0xa4, 0xa5, 0x47, 0x67, 0x5a, + 0x10, 0xd2, 0x88, 0x8a, 0x0b, 0xe0, 0x69, 0x99, 0x45, 0x3b, 0x69, 0xc9, 0x2b, 0x36, 0xb5, 0x69, + 0x6c, 0xd3, 0x47, 0xff, 0x38, 0x4c, 0x56, 0x4c, 0xca, 0x3c, 0xca, 0xf4, 0x2e, 0x61, 0xa0, 0x9f, + 0xb4, 0xba, 0x10, 0x91, 0x96, 0x6e, 0x52, 0xc7, 0x4f, 0xec, 0x6b, 0x89, 0xbd, 0x17, 0xd8, 0x21, + 0xb1, 0xc6, 0x90, 0xe4, 0x99, 0xa3, 0xf0, 0x37, 0x01, 0x2d, 0x74, 0x98, 0xbd, 0x1b, 0x02, 0x89, + 0xe0, 0x25, 0x63, 0x3d, 0x08, 0xc5, 0x6d, 0x34, 0x9b, 0xc5, 0x97, 0x84, 0xa6, 0xb0, 0x3e, 0xdb, + 0x5e, 0x19, 0x0e, 0xd4, 0xc5, 0x3e, 0xf1, 0xdc, 0xa7, 0x38, 0x33, 0x61, 0x63, 0x0c, 0x13, 0x37, + 0xd0, 0x8c, 0x13, 0xb3, 0xa5, 0xa9, 0x98, 0xb0, 0x34, 0x1c, 0xa8, 0x0d, 0x4e, 0xe0, 0xef, 0xb1, + 0x91, 0x00, 0xc4, 0x27, 0xa8, 0x61, 0x81, 0x4f, 0x3d, 0xc7, 0x27, 0x91, 0x43, 0x7d, 0x26, 0xd5, + 0x9b, 0xf5, 0x22, 0x23, 0x36, 0x33, 0x6c, 0x14, 0x71, 0xf8, 0x1e, 0xba, 0x5b, 0x92, 0x6a, 0x00, + 0x0b, 0xa8, 0xcf, 0x00, 0x7f, 0x40, 0x8b, 0x1d, 0x66, 0xef, 0x01, 0x8b, 0x42, 0xda, 0xff, 0x27, + 0x69, 0x60, 0x19, 0x49, 0xe5, 0x90, 0x99, 0x9c, 0x9f, 0xbc, 0xaa, 0xaf, 0x20, 0x7a, 0x41, 0xd8, + 0x41, 0xe8, 0x98, 0xc0, 0x26, 0x92, 0xf3, 0x51, 0x40, 0xc8, 0x26, 0xec, 0x28, 0x88, 0x5d, 0x48, + 0x53, 0xcd, 0xfa, 0xfa, 0xdc, 0xf6, 0xaa, 0xc6, 0x3b, 0xab, 0x8d, 0x3a, 0xaf, 0x25, 0x6d, 0xd5, + 0xf6, 0xc0, 0xdc, 0xa5, 0x8e, 0xdf, 0xde, 0x3f, 0x1f, 0xa8, 0xb5, 0xe1, 0x40, 0x5d, 0xe2, 0x7e, + 0xc7, 0x6c, 0xfc, 0xfd, 0xb7, 0xba, 0x69, 0x3b, 0xd1, 0x71, 0xaf, 0xab, 0x99, 0xd4, 0xd3, 0x93, + 0xf1, 0xe0, 0x3f, 0x5b, 0xcc, 0x7a, 0xaf, 0x47, 0xfd, 0x00, 0x58, 0xea, 0x88, 0x19, 0xb3, 0x76, + 0xaa, 0x3d, 0xa9, 0x7c, 0x3e, 0x9d, 0x2c, 0xd5, 0x4f, 0x02, 0x5a, 0xee, 0x30, 0xdb, 0x80, 0xc0, + 0x25, 0x26, 0xec, 0x64, 0xd2, 0x27, 0x49, 0xf7, 0x19, 0x6a, 0xf8, 0x70, 0x7a, 0x34, 0xe6, 0xf1, + 0x26, 0x48, 0xc3, 0x81, 0xba, 0xc2, 0x79, 0x05, 0x33, 0x36, 0xe6, 0x7d, 0x38, 0xcd, 0x42, 0x62, + 0x86, 0xee, 0x57, 0x28, 0x49, 0x95, 0x8a, 0xaf, 0xd1, 0x9d, 0x02, 0xfd, 0x88, 0x58, 0x56, 0x08, + 0x8c, 0x25, 0xea, 0x9a, 0xc3, 0x81, 0xba, 0x5a, 0x11, 0x25, 0x85, 0x61, 0x63, 0x39, 0x1f, 0x6d, + 0x27, 0x79, 0xfb, 0x45, 0x40, 0xe2, 0xa8, 0x36, 0xe6, 0x31, 0x58, 0x3d, 0x17, 0xde, 0xf0, 0xed, + 0x9a, 0x28, 0xfd, 0xe7, 0x68, 0x3a, 0x70, 0x89, 0x1f, 0x67, 0x9d, 0x6b, 0x73, 0xba, 0xb0, 0x69, + 0xa7, 0x0f, 0x5c, 0xe2, 0xb7, 0x97, 0x93, 0x36, 0xcf, 0x71, 0x87, 0x23, 0x1e, 0x36, 0x62, 0x3a, + 0x5e, 0x45, 0xf2, 0x75, 0x41, 0x59, 0xbf, 0x3e, 0xf3, 0xd1, 0xdc, 0x09, 0x02, 0xb7, 0xff, 0x1f, + 0x88, 0xe5, 0x93, 0x95, 0x57, 0x93, 0x2a, 0xdd, 0xfe, 0x31, 0x8d, 0xea, 0x1d, 0x66, 0x8b, 0x87, + 0x68, 0xbe, 0x70, 0x9e, 0x9a, 0x5a, 0xe9, 0x40, 0x6a, 0xa5, 0xab, 0x20, 0xaf, 0xdf, 0x84, 0xc8, + 0x66, 0xe2, 0x2d, 0x6a, 0x14, 0x8f, 0xc6, 0x83, 0x2a, 0x6a, 0x01, 0x22, 0x6f, 0xdc, 0x08, 0xc9, + 0xdc, 0x1f, 0xa2, 0xf9, 0xc2, 0x0d, 0xa8, 0x94, 0x9e, 0x47, 0x54, 0x4b, 0xaf, 0x5a, 0x3c, 0xf1, + 0x1d, 0x5a, 0xbc, 0xb6, 0x74, 0x6b, 0x55, 0xec, 0x32, 0x4a, 0x7e, 0x74, 0x1b, 0x54, 0x16, 0xc7, + 0x44, 0x0b, 0xe5, 0xe1, 0x7e, 0x58, 0x29, 0xb2, 0x08, 0x92, 0x37, 0x6f, 0x01, 0xca, 0x17, 0xaa, + 0x30, 0x91, 0x95, 0x85, 0xca, 0x23, 0xaa, 0x0b, 0x55, 0x35, 0x47, 0xed, 0xfd, 0xf3, 0x4b, 0x45, + 0xb8, 0xb8, 0x54, 0x84, 0x3f, 0x97, 0x8a, 0xf0, 0xf5, 0x4a, 0xa9, 0x5d, 0x5c, 0x29, 0xb5, 0x5f, + 0x57, 0x4a, 0xed, 0x50, 0xcb, 0x9d, 0x43, 0xd8, 0xf2, 0xa8, 0x0f, 0x7d, 0x1d, 0xbc, 0x2d, 0x17, + 0x2c, 0x1b, 0x42, 0xfd, 0x2c, 0xf7, 0x7d, 0x8e, 0x4f, 0x63, 0x77, 0x26, 0xfe, 0x66, 0x3e, 0xfe, + 0x1b, 0x00, 0x00, 0xff, 0xff, 0xa1, 0x45, 0xee, 0x9f, 0xbc, 0x07, 0x00, 0x00, } // Reference imports to suppress errors if they are not otherwise used. @@ -467,6 +655,8 @@ type MsgClient interface { DestroyIssuer(ctx context.Context, in *MsgDestroyIssuer, opts ...grpc.CallOption) (*MsgDestroyIssuerResponse, error) SetGasPrices(ctx context.Context, in *MsgSetGasPrices, opts ...grpc.CallOption) (*MsgSetGasPricesResponse, error) ReplaceAuthority(ctx context.Context, in *MsgReplaceAuthority, opts ...grpc.CallOption) (*MsgReplaceAuthorityResponse, error) + ScheduleUpgrade(ctx context.Context, in *MsgScheduleUpgrade, opts ...grpc.CallOption) (*MsgScheduleUpgradeResponse, error) + ApplyUpgrade(ctx context.Context, in *MsgApplyUpgrade, opts ...grpc.CallOption) (*MsgApplyUpgradeResponse, error) } type msgClient struct { @@ -513,12 +703,32 @@ func (c *msgClient) ReplaceAuthority(ctx context.Context, in *MsgReplaceAuthorit return out, nil } +func (c *msgClient) ScheduleUpgrade(ctx context.Context, in *MsgScheduleUpgrade, opts ...grpc.CallOption) (*MsgScheduleUpgradeResponse, error) { + out := new(MsgScheduleUpgradeResponse) + err := c.cc.Invoke(ctx, "/em.authority.v1.Msg/ScheduleUpgrade", in, out, opts...) + if err != nil { + return nil, err + } + return out, nil +} + +func (c *msgClient) ApplyUpgrade(ctx context.Context, in *MsgApplyUpgrade, opts ...grpc.CallOption) (*MsgApplyUpgradeResponse, error) { + out := new(MsgApplyUpgradeResponse) + err := c.cc.Invoke(ctx, "/em.authority.v1.Msg/ApplyUpgrade", in, out, opts...) + if err != nil { + return nil, err + } + return out, nil +} + // MsgServer is the server API for Msg service. type MsgServer interface { CreateIssuer(context.Context, *MsgCreateIssuer) (*MsgCreateIssuerResponse, error) DestroyIssuer(context.Context, *MsgDestroyIssuer) (*MsgDestroyIssuerResponse, error) SetGasPrices(context.Context, *MsgSetGasPrices) (*MsgSetGasPricesResponse, error) ReplaceAuthority(context.Context, *MsgReplaceAuthority) (*MsgReplaceAuthorityResponse, error) + ScheduleUpgrade(context.Context, *MsgScheduleUpgrade) (*MsgScheduleUpgradeResponse, error) + ApplyUpgrade(context.Context, *MsgApplyUpgrade) (*MsgApplyUpgradeResponse, error) } // UnimplementedMsgServer can be embedded to have forward compatible implementations. @@ -537,6 +747,12 @@ func (*UnimplementedMsgServer) SetGasPrices(ctx context.Context, req *MsgSetGasP func (*UnimplementedMsgServer) ReplaceAuthority(ctx context.Context, req *MsgReplaceAuthority) (*MsgReplaceAuthorityResponse, error) { return nil, status.Errorf(codes.Unimplemented, "method ReplaceAuthority not implemented") } +func (*UnimplementedMsgServer) ScheduleUpgrade(ctx context.Context, req *MsgScheduleUpgrade) (*MsgScheduleUpgradeResponse, error) { + return nil, status.Errorf(codes.Unimplemented, "method ScheduleUpgrade not implemented") +} +func (*UnimplementedMsgServer) ApplyUpgrade(ctx context.Context, req *MsgApplyUpgrade) (*MsgApplyUpgradeResponse, error) { + return nil, status.Errorf(codes.Unimplemented, "method ApplyUpgrade not implemented") +} func RegisterMsgServer(s grpc1.Server, srv MsgServer) { s.RegisterService(&_Msg_serviceDesc, srv) @@ -614,6 +830,42 @@ func _Msg_ReplaceAuthority_Handler(srv interface{}, ctx context.Context, dec fun return interceptor(ctx, in, info, handler) } +func _Msg_ScheduleUpgrade_Handler(srv interface{}, ctx context.Context, dec func(interface{}) error, interceptor grpc.UnaryServerInterceptor) (interface{}, error) { + in := new(MsgScheduleUpgrade) + if err := dec(in); err != nil { + return nil, err + } + if interceptor == nil { + return srv.(MsgServer).ScheduleUpgrade(ctx, in) + } + info := &grpc.UnaryServerInfo{ + Server: srv, + FullMethod: "/em.authority.v1.Msg/ScheduleUpgrade", + } + handler := func(ctx context.Context, req interface{}) (interface{}, error) { + return srv.(MsgServer).ScheduleUpgrade(ctx, req.(*MsgScheduleUpgrade)) + } + return interceptor(ctx, in, info, handler) +} + +func _Msg_ApplyUpgrade_Handler(srv interface{}, ctx context.Context, dec func(interface{}) error, interceptor grpc.UnaryServerInterceptor) (interface{}, error) { + in := new(MsgApplyUpgrade) + if err := dec(in); err != nil { + return nil, err + } + if interceptor == nil { + return srv.(MsgServer).ApplyUpgrade(ctx, in) + } + info := &grpc.UnaryServerInfo{ + Server: srv, + FullMethod: "/em.authority.v1.Msg/ApplyUpgrade", + } + handler := func(ctx context.Context, req interface{}) (interface{}, error) { + return srv.(MsgServer).ApplyUpgrade(ctx, req.(*MsgApplyUpgrade)) + } + return interceptor(ctx, in, info, handler) +} + var _Msg_serviceDesc = grpc.ServiceDesc{ ServiceName: "em.authority.v1.Msg", HandlerType: (*MsgServer)(nil), @@ -634,6 +886,14 @@ var _Msg_serviceDesc = grpc.ServiceDesc{ MethodName: "ReplaceAuthority", Handler: _Msg_ReplaceAuthority_Handler, }, + { + MethodName: "ScheduleUpgrade", + Handler: _Msg_ScheduleUpgrade_Handler, + }, + { + MethodName: "ApplyUpgrade", + Handler: _Msg_ApplyUpgrade_Handler, + }, }, Streams: []grpc.StreamDesc{}, Metadata: "em/authority/v1/tx.proto", @@ -902,6 +1162,132 @@ func (m *MsgReplaceAuthorityResponse) MarshalToSizedBuffer(dAtA []byte) (int, er return len(dAtA) - i, nil } +func (m *MsgScheduleUpgrade) 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 *MsgScheduleUpgrade) MarshalTo(dAtA []byte) (int, error) { + size := m.Size() + return m.MarshalToSizedBuffer(dAtA[:size]) +} + +func (m *MsgScheduleUpgrade) MarshalToSizedBuffer(dAtA []byte) (int, error) { + i := len(dAtA) + _ = i + var l int + _ = l + { + size, err := m.Plan.MarshalToSizedBuffer(dAtA[:i]) + if err != nil { + return 0, err + } + i -= size + i = encodeVarintTx(dAtA, i, uint64(size)) + } + i-- + dAtA[i] = 0x12 + if len(m.Authority) > 0 { + i -= len(m.Authority) + copy(dAtA[i:], m.Authority) + i = encodeVarintTx(dAtA, i, uint64(len(m.Authority))) + i-- + dAtA[i] = 0xa + } + return len(dAtA) - i, nil +} + +func (m *MsgScheduleUpgradeResponse) 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 *MsgScheduleUpgradeResponse) MarshalTo(dAtA []byte) (int, error) { + size := m.Size() + return m.MarshalToSizedBuffer(dAtA[:size]) +} + +func (m *MsgScheduleUpgradeResponse) MarshalToSizedBuffer(dAtA []byte) (int, error) { + i := len(dAtA) + _ = i + var l int + _ = l + return len(dAtA) - i, nil +} + +func (m *MsgApplyUpgrade) 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 *MsgApplyUpgrade) MarshalTo(dAtA []byte) (int, error) { + size := m.Size() + return m.MarshalToSizedBuffer(dAtA[:size]) +} + +func (m *MsgApplyUpgrade) MarshalToSizedBuffer(dAtA []byte) (int, error) { + i := len(dAtA) + _ = i + var l int + _ = l + { + size, err := m.Plan.MarshalToSizedBuffer(dAtA[:i]) + if err != nil { + return 0, err + } + i -= size + i = encodeVarintTx(dAtA, i, uint64(size)) + } + i-- + dAtA[i] = 0x12 + if len(m.Authority) > 0 { + i -= len(m.Authority) + copy(dAtA[i:], m.Authority) + i = encodeVarintTx(dAtA, i, uint64(len(m.Authority))) + i-- + dAtA[i] = 0xa + } + return len(dAtA) - i, nil +} + +func (m *MsgApplyUpgradeResponse) 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 *MsgApplyUpgradeResponse) MarshalTo(dAtA []byte) (int, error) { + size := m.Size() + return m.MarshalToSizedBuffer(dAtA[:size]) +} + +func (m *MsgApplyUpgradeResponse) MarshalToSizedBuffer(dAtA []byte) (int, error) { + i := len(dAtA) + _ = i + var l int + _ = l + return len(dAtA) - i, nil +} + func encodeVarintTx(dAtA []byte, offset int, v uint64) int { offset -= sovTx(v) base := offset @@ -1029,6 +1415,54 @@ func (m *MsgReplaceAuthorityResponse) Size() (n int) { return n } +func (m *MsgScheduleUpgrade) Size() (n int) { + if m == nil { + return 0 + } + var l int + _ = l + l = len(m.Authority) + if l > 0 { + n += 1 + l + sovTx(uint64(l)) + } + l = m.Plan.Size() + n += 1 + l + sovTx(uint64(l)) + return n +} + +func (m *MsgScheduleUpgradeResponse) Size() (n int) { + if m == nil { + return 0 + } + var l int + _ = l + return n +} + +func (m *MsgApplyUpgrade) Size() (n int) { + if m == nil { + return 0 + } + var l int + _ = l + l = len(m.Authority) + if l > 0 { + n += 1 + l + sovTx(uint64(l)) + } + l = m.Plan.Size() + n += 1 + l + sovTx(uint64(l)) + return n +} + +func (m *MsgApplyUpgradeResponse) Size() (n int) { + if m == nil { + return 0 + } + var l int + _ = l + return n +} + func sovTx(x uint64) (n int) { return (math_bits.Len64(x|1) + 6) / 7 } @@ -1061,7 +1495,203 @@ func (m *MsgCreateIssuer) Unmarshal(dAtA []byte) error { return fmt.Errorf("proto: MsgCreateIssuer: wiretype end group for non-group") } if fieldNum <= 0 { - return fmt.Errorf("proto: MsgCreateIssuer: illegal tag %d (wire type %d)", fieldNum, wire) + return fmt.Errorf("proto: MsgCreateIssuer: illegal tag %d (wire type %d)", fieldNum, wire) + } + switch fieldNum { + case 1: + if wireType != 2 { + return fmt.Errorf("proto: wrong wireType = %d for field Authority", wireType) + } + var stringLen uint64 + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowTx + } + 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 ErrInvalidLengthTx + } + postIndex := iNdEx + intStringLen + if postIndex < 0 { + return ErrInvalidLengthTx + } + if postIndex > l { + return io.ErrUnexpectedEOF + } + m.Authority = string(dAtA[iNdEx:postIndex]) + iNdEx = postIndex + case 2: + if wireType != 2 { + return fmt.Errorf("proto: wrong wireType = %d for field Issuer", wireType) + } + var stringLen uint64 + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowTx + } + 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 ErrInvalidLengthTx + } + postIndex := iNdEx + intStringLen + if postIndex < 0 { + return ErrInvalidLengthTx + } + if postIndex > l { + return io.ErrUnexpectedEOF + } + m.Issuer = string(dAtA[iNdEx:postIndex]) + iNdEx = postIndex + case 3: + if wireType != 2 { + return fmt.Errorf("proto: wrong wireType = %d for field Denominations", wireType) + } + var stringLen uint64 + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowTx + } + 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 ErrInvalidLengthTx + } + postIndex := iNdEx + intStringLen + if postIndex < 0 { + return ErrInvalidLengthTx + } + if postIndex > l { + return io.ErrUnexpectedEOF + } + m.Denominations = append(m.Denominations, string(dAtA[iNdEx:postIndex])) + iNdEx = postIndex + default: + iNdEx = preIndex + skippy, err := skipTx(dAtA[iNdEx:]) + if err != nil { + return err + } + if (skippy < 0) || (iNdEx+skippy) < 0 { + return ErrInvalidLengthTx + } + if (iNdEx + skippy) > l { + return io.ErrUnexpectedEOF + } + iNdEx += skippy + } + } + + if iNdEx > l { + return io.ErrUnexpectedEOF + } + return nil +} +func (m *MsgCreateIssuerResponse) 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 ErrIntOverflowTx + } + 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: MsgCreateIssuerResponse: wiretype end group for non-group") + } + if fieldNum <= 0 { + return fmt.Errorf("proto: MsgCreateIssuerResponse: illegal tag %d (wire type %d)", fieldNum, wire) + } + switch fieldNum { + default: + iNdEx = preIndex + skippy, err := skipTx(dAtA[iNdEx:]) + if err != nil { + return err + } + if (skippy < 0) || (iNdEx+skippy) < 0 { + return ErrInvalidLengthTx + } + if (iNdEx + skippy) > l { + return io.ErrUnexpectedEOF + } + iNdEx += skippy + } + } + + if iNdEx > l { + return io.ErrUnexpectedEOF + } + return nil +} +func (m *MsgDestroyIssuer) 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 ErrIntOverflowTx + } + 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: MsgDestroyIssuer: wiretype end group for non-group") + } + if fieldNum <= 0 { + return fmt.Errorf("proto: MsgDestroyIssuer: illegal tag %d (wire type %d)", fieldNum, wire) } switch fieldNum { case 1: @@ -1128,9 +1758,109 @@ func (m *MsgCreateIssuer) Unmarshal(dAtA []byte) error { } m.Issuer = string(dAtA[iNdEx:postIndex]) iNdEx = postIndex - case 3: + default: + iNdEx = preIndex + skippy, err := skipTx(dAtA[iNdEx:]) + if err != nil { + return err + } + if (skippy < 0) || (iNdEx+skippy) < 0 { + return ErrInvalidLengthTx + } + if (iNdEx + skippy) > l { + return io.ErrUnexpectedEOF + } + iNdEx += skippy + } + } + + if iNdEx > l { + return io.ErrUnexpectedEOF + } + return nil +} +func (m *MsgDestroyIssuerResponse) 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 ErrIntOverflowTx + } + 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: MsgDestroyIssuerResponse: wiretype end group for non-group") + } + if fieldNum <= 0 { + return fmt.Errorf("proto: MsgDestroyIssuerResponse: illegal tag %d (wire type %d)", fieldNum, wire) + } + switch fieldNum { + default: + iNdEx = preIndex + skippy, err := skipTx(dAtA[iNdEx:]) + if err != nil { + return err + } + if (skippy < 0) || (iNdEx+skippy) < 0 { + return ErrInvalidLengthTx + } + if (iNdEx + skippy) > l { + return io.ErrUnexpectedEOF + } + iNdEx += skippy + } + } + + if iNdEx > l { + return io.ErrUnexpectedEOF + } + return nil +} +func (m *MsgSetGasPrices) 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 ErrIntOverflowTx + } + 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: MsgSetGasPrices: wiretype end group for non-group") + } + if fieldNum <= 0 { + return fmt.Errorf("proto: MsgSetGasPrices: illegal tag %d (wire type %d)", fieldNum, wire) + } + switch fieldNum { + case 1: if wireType != 2 { - return fmt.Errorf("proto: wrong wireType = %d for field Denominations", wireType) + return fmt.Errorf("proto: wrong wireType = %d for field Authority", wireType) } var stringLen uint64 for shift := uint(0); ; shift += 7 { @@ -1158,7 +1888,41 @@ func (m *MsgCreateIssuer) Unmarshal(dAtA []byte) error { if postIndex > l { return io.ErrUnexpectedEOF } - m.Denominations = append(m.Denominations, string(dAtA[iNdEx:postIndex])) + m.Authority = string(dAtA[iNdEx:postIndex]) + iNdEx = postIndex + case 2: + if wireType != 2 { + return fmt.Errorf("proto: wrong wireType = %d for field GasPrices", wireType) + } + var msglen int + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowTx + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + msglen |= int(b&0x7F) << shift + if b < 0x80 { + break + } + } + if msglen < 0 { + return ErrInvalidLengthTx + } + postIndex := iNdEx + msglen + if postIndex < 0 { + return ErrInvalidLengthTx + } + if postIndex > l { + return io.ErrUnexpectedEOF + } + m.GasPrices = append(m.GasPrices, types.DecCoin{}) + if err := m.GasPrices[len(m.GasPrices)-1].Unmarshal(dAtA[iNdEx:postIndex]); err != nil { + return err + } iNdEx = postIndex default: iNdEx = preIndex @@ -1181,7 +1945,7 @@ func (m *MsgCreateIssuer) Unmarshal(dAtA []byte) error { } return nil } -func (m *MsgCreateIssuerResponse) Unmarshal(dAtA []byte) error { +func (m *MsgSetGasPricesResponse) Unmarshal(dAtA []byte) error { l := len(dAtA) iNdEx := 0 for iNdEx < l { @@ -1204,10 +1968,10 @@ func (m *MsgCreateIssuerResponse) Unmarshal(dAtA []byte) error { fieldNum := int32(wire >> 3) wireType := int(wire & 0x7) if wireType == 4 { - return fmt.Errorf("proto: MsgCreateIssuerResponse: wiretype end group for non-group") + return fmt.Errorf("proto: MsgSetGasPricesResponse: wiretype end group for non-group") } if fieldNum <= 0 { - return fmt.Errorf("proto: MsgCreateIssuerResponse: illegal tag %d (wire type %d)", fieldNum, wire) + return fmt.Errorf("proto: MsgSetGasPricesResponse: illegal tag %d (wire type %d)", fieldNum, wire) } switch fieldNum { default: @@ -1231,7 +1995,7 @@ func (m *MsgCreateIssuerResponse) Unmarshal(dAtA []byte) error { } return nil } -func (m *MsgDestroyIssuer) Unmarshal(dAtA []byte) error { +func (m *MsgReplaceAuthority) Unmarshal(dAtA []byte) error { l := len(dAtA) iNdEx := 0 for iNdEx < l { @@ -1254,10 +2018,10 @@ func (m *MsgDestroyIssuer) Unmarshal(dAtA []byte) error { fieldNum := int32(wire >> 3) wireType := int(wire & 0x7) if wireType == 4 { - return fmt.Errorf("proto: MsgDestroyIssuer: wiretype end group for non-group") + return fmt.Errorf("proto: MsgReplaceAuthority: wiretype end group for non-group") } if fieldNum <= 0 { - return fmt.Errorf("proto: MsgDestroyIssuer: illegal tag %d (wire type %d)", fieldNum, wire) + return fmt.Errorf("proto: MsgReplaceAuthority: illegal tag %d (wire type %d)", fieldNum, wire) } switch fieldNum { case 1: @@ -1294,7 +2058,7 @@ func (m *MsgDestroyIssuer) Unmarshal(dAtA []byte) error { iNdEx = postIndex case 2: if wireType != 2 { - return fmt.Errorf("proto: wrong wireType = %d for field Issuer", wireType) + return fmt.Errorf("proto: wrong wireType = %d for field NewAuthority", wireType) } var stringLen uint64 for shift := uint(0); ; shift += 7 { @@ -1322,7 +2086,7 @@ func (m *MsgDestroyIssuer) Unmarshal(dAtA []byte) error { if postIndex > l { return io.ErrUnexpectedEOF } - m.Issuer = string(dAtA[iNdEx:postIndex]) + m.NewAuthority = string(dAtA[iNdEx:postIndex]) iNdEx = postIndex default: iNdEx = preIndex @@ -1345,7 +2109,7 @@ func (m *MsgDestroyIssuer) Unmarshal(dAtA []byte) error { } return nil } -func (m *MsgDestroyIssuerResponse) Unmarshal(dAtA []byte) error { +func (m *MsgReplaceAuthorityResponse) Unmarshal(dAtA []byte) error { l := len(dAtA) iNdEx := 0 for iNdEx < l { @@ -1368,12 +2132,44 @@ func (m *MsgDestroyIssuerResponse) Unmarshal(dAtA []byte) error { fieldNum := int32(wire >> 3) wireType := int(wire & 0x7) if wireType == 4 { - return fmt.Errorf("proto: MsgDestroyIssuerResponse: wiretype end group for non-group") + return fmt.Errorf("proto: MsgReplaceAuthorityResponse: wiretype end group for non-group") } if fieldNum <= 0 { - return fmt.Errorf("proto: MsgDestroyIssuerResponse: illegal tag %d (wire type %d)", fieldNum, wire) + return fmt.Errorf("proto: MsgReplaceAuthorityResponse: illegal tag %d (wire type %d)", fieldNum, wire) } switch fieldNum { + case 1: + if wireType != 2 { + return fmt.Errorf("proto: wrong wireType = %d for field NewAuthorityAddress", wireType) + } + var stringLen uint64 + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowTx + } + 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 ErrInvalidLengthTx + } + postIndex := iNdEx + intStringLen + if postIndex < 0 { + return ErrInvalidLengthTx + } + if postIndex > l { + return io.ErrUnexpectedEOF + } + m.NewAuthorityAddress = string(dAtA[iNdEx:postIndex]) + iNdEx = postIndex default: iNdEx = preIndex skippy, err := skipTx(dAtA[iNdEx:]) @@ -1395,7 +2191,7 @@ func (m *MsgDestroyIssuerResponse) Unmarshal(dAtA []byte) error { } return nil } -func (m *MsgSetGasPrices) Unmarshal(dAtA []byte) error { +func (m *MsgScheduleUpgrade) Unmarshal(dAtA []byte) error { l := len(dAtA) iNdEx := 0 for iNdEx < l { @@ -1418,10 +2214,10 @@ func (m *MsgSetGasPrices) Unmarshal(dAtA []byte) error { fieldNum := int32(wire >> 3) wireType := int(wire & 0x7) if wireType == 4 { - return fmt.Errorf("proto: MsgSetGasPrices: wiretype end group for non-group") + return fmt.Errorf("proto: MsgScheduleUpgrade: wiretype end group for non-group") } if fieldNum <= 0 { - return fmt.Errorf("proto: MsgSetGasPrices: illegal tag %d (wire type %d)", fieldNum, wire) + return fmt.Errorf("proto: MsgScheduleUpgrade: illegal tag %d (wire type %d)", fieldNum, wire) } switch fieldNum { case 1: @@ -1458,7 +2254,7 @@ func (m *MsgSetGasPrices) Unmarshal(dAtA []byte) error { iNdEx = postIndex case 2: if wireType != 2 { - return fmt.Errorf("proto: wrong wireType = %d for field GasPrices", wireType) + return fmt.Errorf("proto: wrong wireType = %d for field Plan", wireType) } var msglen int for shift := uint(0); ; shift += 7 { @@ -1485,8 +2281,7 @@ func (m *MsgSetGasPrices) Unmarshal(dAtA []byte) error { if postIndex > l { return io.ErrUnexpectedEOF } - m.GasPrices = append(m.GasPrices, types.DecCoin{}) - if err := m.GasPrices[len(m.GasPrices)-1].Unmarshal(dAtA[iNdEx:postIndex]); err != nil { + if err := m.Plan.Unmarshal(dAtA[iNdEx:postIndex]); err != nil { return err } iNdEx = postIndex @@ -1511,7 +2306,7 @@ func (m *MsgSetGasPrices) Unmarshal(dAtA []byte) error { } return nil } -func (m *MsgSetGasPricesResponse) Unmarshal(dAtA []byte) error { +func (m *MsgScheduleUpgradeResponse) Unmarshal(dAtA []byte) error { l := len(dAtA) iNdEx := 0 for iNdEx < l { @@ -1534,10 +2329,10 @@ func (m *MsgSetGasPricesResponse) Unmarshal(dAtA []byte) error { fieldNum := int32(wire >> 3) wireType := int(wire & 0x7) if wireType == 4 { - return fmt.Errorf("proto: MsgSetGasPricesResponse: wiretype end group for non-group") + return fmt.Errorf("proto: MsgScheduleUpgradeResponse: wiretype end group for non-group") } if fieldNum <= 0 { - return fmt.Errorf("proto: MsgSetGasPricesResponse: illegal tag %d (wire type %d)", fieldNum, wire) + return fmt.Errorf("proto: MsgScheduleUpgradeResponse: illegal tag %d (wire type %d)", fieldNum, wire) } switch fieldNum { default: @@ -1561,7 +2356,7 @@ func (m *MsgSetGasPricesResponse) Unmarshal(dAtA []byte) error { } return nil } -func (m *MsgReplaceAuthority) Unmarshal(dAtA []byte) error { +func (m *MsgApplyUpgrade) Unmarshal(dAtA []byte) error { l := len(dAtA) iNdEx := 0 for iNdEx < l { @@ -1584,10 +2379,10 @@ func (m *MsgReplaceAuthority) Unmarshal(dAtA []byte) error { fieldNum := int32(wire >> 3) wireType := int(wire & 0x7) if wireType == 4 { - return fmt.Errorf("proto: MsgReplaceAuthority: wiretype end group for non-group") + return fmt.Errorf("proto: MsgApplyUpgrade: wiretype end group for non-group") } if fieldNum <= 0 { - return fmt.Errorf("proto: MsgReplaceAuthority: illegal tag %d (wire type %d)", fieldNum, wire) + return fmt.Errorf("proto: MsgApplyUpgrade: illegal tag %d (wire type %d)", fieldNum, wire) } switch fieldNum { case 1: @@ -1624,9 +2419,9 @@ func (m *MsgReplaceAuthority) Unmarshal(dAtA []byte) error { iNdEx = postIndex case 2: if wireType != 2 { - return fmt.Errorf("proto: wrong wireType = %d for field NewAuthority", wireType) + return fmt.Errorf("proto: wrong wireType = %d for field Plan", wireType) } - var stringLen uint64 + var msglen int for shift := uint(0); ; shift += 7 { if shift >= 64 { return ErrIntOverflowTx @@ -1636,23 +2431,24 @@ func (m *MsgReplaceAuthority) Unmarshal(dAtA []byte) error { } b := dAtA[iNdEx] iNdEx++ - stringLen |= uint64(b&0x7F) << shift + msglen |= int(b&0x7F) << shift if b < 0x80 { break } } - intStringLen := int(stringLen) - if intStringLen < 0 { + if msglen < 0 { return ErrInvalidLengthTx } - postIndex := iNdEx + intStringLen + postIndex := iNdEx + msglen if postIndex < 0 { return ErrInvalidLengthTx } if postIndex > l { return io.ErrUnexpectedEOF } - m.NewAuthority = string(dAtA[iNdEx:postIndex]) + if err := m.Plan.Unmarshal(dAtA[iNdEx:postIndex]); err != nil { + return err + } iNdEx = postIndex default: iNdEx = preIndex @@ -1675,7 +2471,7 @@ func (m *MsgReplaceAuthority) Unmarshal(dAtA []byte) error { } return nil } -func (m *MsgReplaceAuthorityResponse) Unmarshal(dAtA []byte) error { +func (m *MsgApplyUpgradeResponse) Unmarshal(dAtA []byte) error { l := len(dAtA) iNdEx := 0 for iNdEx < l { @@ -1698,44 +2494,12 @@ func (m *MsgReplaceAuthorityResponse) Unmarshal(dAtA []byte) error { fieldNum := int32(wire >> 3) wireType := int(wire & 0x7) if wireType == 4 { - return fmt.Errorf("proto: MsgReplaceAuthorityResponse: wiretype end group for non-group") + return fmt.Errorf("proto: MsgApplyUpgradeResponse: wiretype end group for non-group") } if fieldNum <= 0 { - return fmt.Errorf("proto: MsgReplaceAuthorityResponse: illegal tag %d (wire type %d)", fieldNum, wire) + return fmt.Errorf("proto: MsgApplyUpgradeResponse: illegal tag %d (wire type %d)", fieldNum, wire) } switch fieldNum { - case 1: - if wireType != 2 { - return fmt.Errorf("proto: wrong wireType = %d for field NewAuthorityAddress", wireType) - } - var stringLen uint64 - for shift := uint(0); ; shift += 7 { - if shift >= 64 { - return ErrIntOverflowTx - } - 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 ErrInvalidLengthTx - } - postIndex := iNdEx + intStringLen - if postIndex < 0 { - return ErrInvalidLengthTx - } - if postIndex > l { - return io.ErrUnexpectedEOF - } - m.NewAuthorityAddress = string(dAtA[iNdEx:postIndex]) - iNdEx = postIndex default: iNdEx = preIndex skippy, err := skipTx(dAtA[iNdEx:]) From 6e8964b9a524e2ddd949c4afab5e1dfdcb9d588e Mon Sep 17 00:00:00 2001 From: Mario Karagiorgas Date: Thu, 22 Jul 2021 15:10:23 +0300 Subject: [PATCH 02/49] Add schedule/apply upgrade message + methods --- x/authority/client/cli/tx.go | 71 +++++++++++++++++++++++---- x/authority/handler.go | 4 ++ x/authority/keeper/keeper.go | 14 ++++++ x/authority/keeper/msg_server.go | 18 +++++++ x/authority/keeper/msg_server_test.go | 20 ++++++++ x/authority/types/msgs.go | 58 ++++++++++++++++++++++ 6 files changed, 175 insertions(+), 10 deletions(-) diff --git a/x/authority/client/cli/tx.go b/x/authority/client/cli/tx.go index e7e8ebec..51799848 100644 --- a/x/authority/client/cli/tx.go +++ b/x/authority/client/cli/tx.go @@ -5,13 +5,16 @@ package cli import ( + "fmt" "time" + sdkerrors "github.com/cosmos/cosmos-sdk/types/errors" + "github.com/cosmos/cosmos-sdk/client" "github.com/cosmos/cosmos-sdk/client/flags" "github.com/cosmos/cosmos-sdk/client/tx" sdk "github.com/cosmos/cosmos-sdk/types" - types1 "github.com/cosmos/cosmos-sdk/x/upgrade/types" + upgtypes "github.com/cosmos/cosmos-sdk/x/upgrade/types" "github.com/e-money/em-ledger/util" "github.com/e-money/em-ledger/x/authority/types" "github.com/spf13/cobra" @@ -29,6 +32,7 @@ func GetTxCmd() *cobra.Command { getCmdDestroyIssuer(), getCmdSetGasPrices(), GetCmdReplaceAuthority(), + GetCmdScheduleUpgrade(), ) return authorityCmds @@ -177,39 +181,86 @@ For a 24-hour grace period the former authority key is equivalent to the new one func GetCmdScheduleUpgrade() *cobra.Command { cmd := &cobra.Command{ + //Use: "schedule-upg [authority_key_or_address] plan_name [upg_height] [upg_time] [upg_commit_hash]", Use: "schedule-upg [authority_key_or_address] plan_name", Short: "Schedule a software upgrade.", - Example: "emd tx schedule-upg emoney1n5ggspeff4fxc87dvmg0ematr3qzw5l4v20mdv 0-43", + Example: "emd tx schedule-upg emoney1n5ggspeff4fxc87dvmg0ematr3qzw5l4v20mdv 0.43 --upg_height 2001", Long: `Schedule a software upgrade.`, Args: cobra.ExactArgs(2), RunE: func(cmd *cobra.Command, args []string) error { + const ( + upgHeight = "upg-upgHeightVal" + upgTime = "upg-timeVal" + upgCommitHash = "upg_commit_hash" + ) + + var ( + upgHeightVal, timeVal int64 + upgCommitVal string + ) + f := cmd.Flags() + f.Int64VarP(&upgHeightVal, upgHeight, "h", 0, "upgrade block upgHeightVal") + f.Int64VarP(&timeVal, upgTime, "t", 0, "upgrade block timeVal (in Unix seconds) to upgrade") + f.StringVarP(&upgCommitVal, upgCommitHash, "g", "", "upgrade git upgCommitVal hash") + err := f.Set(flags.FlagFrom, args[0]) if err != nil { return err } + if upgHeightVal == 0 && timeVal == 0 && upgCommitVal == "" { + return sdkerrors.Wrapf( + sdkerrors.ErrInvalidRequest, + "need to specify --%s or --%s or --%s", upgHeight, upgTime, + upgCommitHash, + ) + } + + flagsSet := 0 + if upgHeightVal != 0 { + flagsSet++ + } + if timeVal != 0 { + flagsSet++ + } + if upgCommitVal != "" { + flagsSet++ + } + if flagsSet != 1 { + return sdkerrors.Wrapf( + sdkerrors.ErrInvalidRequest, + "specify only one of the flags: --%s or --%s or --%s", upgHeight, upgTime, + upgCommitHash, + ) + } + + upgTimeVal := time.Unix(timeVal, 0) + clientCtx, err := client.GetClientTxContext(cmd) if err != nil { return err } - plan := types1.Plan{ - Name: args[1], - Time: time.Now(), - } - - _ = &types.MsgScheduleUpgrade{ + msg := &types.MsgScheduleUpgrade{ Authority: clientCtx.GetFromAddress().String(), - Plan: plan, + Plan: upgtypes.Plan{ + Name: args[1], + Time: upgTimeVal, + Height: upgHeightVal, + Info: upgCommitVal, + }, } if err := msg.ValidateBasic(); err != nil { return err } - return tx.GenerateOrBroadcastTxCLI(clientCtx, cmd.Flags(), msg) + fmt.Println(msg) + + //return tx.GenerateOrBroadcastTxCLI(clientCtx, cmd.Flags(), msg) + return nil }, } flags.AddTxFlagsToCmd(cmd) diff --git a/x/authority/handler.go b/x/authority/handler.go index e86827dd..f39a0f92 100644 --- a/x/authority/handler.go +++ b/x/authority/handler.go @@ -36,6 +36,10 @@ func newHandler(k Keeper) sdk.Handler { res, err := msgServer.ReplaceAuthority(sdk.WrapSDKContext(ctx), msg) return sdk.WrapServiceResult(ctx, res, err) + case *types.MsgScheduleUpgrade: + res, err := msgServer.ScheduleUpgrade(sdk.WrapSDKContext(ctx), msg) + return sdk.WrapServiceResult(ctx, res, err) + default: return nil, sdkerrors.Wrapf(sdkerrors.ErrUnknownRequest, "unrecognized %s message type: %T", ModuleName, msg) } diff --git a/x/authority/keeper/keeper.go b/x/authority/keeper/keeper.go index 1c106066..4a2f3a57 100644 --- a/x/authority/keeper/keeper.go +++ b/x/authority/keeper/keeper.go @@ -8,6 +8,8 @@ import ( "errors" "sync" + upgradetypes "github.com/cosmos/cosmos-sdk/x/upgrade/types" + "github.com/cosmos/cosmos-sdk/codec" sdkerrors "github.com/cosmos/cosmos-sdk/types/errors" "github.com/e-money/em-ledger/x/authority/types" @@ -207,3 +209,15 @@ func (k Keeper) replaceAuthority(ctx sdk.Context, authority, newAuthority sdk.Ac return &sdk.Result{Events: ctx.EventManager().ABCIEvents()}, nil } + +func (k Keeper) scheduleUpgrade( + ctx sdk.Context, authority sdk.AccAddress, plan upgradetypes.Plan, +) (*sdk.Result, error) { + panic("implement me") +} + +func (k Keeper) applyUpgrade( + ctx sdk.Context, authority sdk.AccAddress, plan upgradetypes.Plan, +) (*sdk.Result, error) { + panic("implement me") +} diff --git a/x/authority/keeper/msg_server.go b/x/authority/keeper/msg_server.go index a3a6ebb4..0013b944 100644 --- a/x/authority/keeper/msg_server.go +++ b/x/authority/keeper/msg_server.go @@ -3,6 +3,8 @@ package keeper import ( "context" + upgradetypes "github.com/cosmos/cosmos-sdk/x/upgrade/types" + sdk "github.com/cosmos/cosmos-sdk/types" sdkerrors "github.com/cosmos/cosmos-sdk/types/errors" "github.com/e-money/em-ledger/x/authority/types" @@ -15,6 +17,8 @@ type authorityKeeper interface { destroyIssuer(ctx sdk.Context, authority sdk.AccAddress, issuerAddress sdk.AccAddress) (*sdk.Result, error) replaceAuthority(ctx sdk.Context, authority, newAuthority sdk.AccAddress) (*sdk.Result, error) SetGasPrices(ctx sdk.Context, authority sdk.AccAddress, gasprices sdk.DecCoins) (*sdk.Result, error) + scheduleUpgrade(ctx sdk.Context, authority sdk.AccAddress, plan upgradetypes.Plan) (*sdk.Result, error) + applyUpgrade(ctx sdk.Context, authority sdk.AccAddress, plan upgradetypes.Plan) (*sdk.Result, error) } type msgServer struct { k authorityKeeper @@ -108,3 +112,17 @@ func (m msgServer) ReplaceAuthority(goCtx context.Context, msg *types.MsgReplace return &types.MsgReplaceAuthorityResponse{}, nil } + +func (m msgServer) ScheduleUpgrade( + ctx context.Context, upgrade *types.MsgScheduleUpgrade, +) (*types.MsgScheduleUpgradeResponse, error) { + + return &types.MsgScheduleUpgradeResponse{}, nil +} + +func (m msgServer) ApplyUpgrade( + ctx context.Context, upgrade *types.MsgApplyUpgrade, +) (*types.MsgApplyUpgradeResponse, error) { + + return &types.MsgApplyUpgradeResponse{}, nil +} diff --git a/x/authority/keeper/msg_server_test.go b/x/authority/keeper/msg_server_test.go index 399ec124..b7e4d6d9 100644 --- a/x/authority/keeper/msg_server_test.go +++ b/x/authority/keeper/msg_server_test.go @@ -5,6 +5,8 @@ import ( "errors" "testing" + upgradetypes "github.com/cosmos/cosmos-sdk/x/upgrade/types" + sdk "github.com/cosmos/cosmos-sdk/types" "github.com/e-money/em-ledger/x/authority/types" "github.com/stretchr/testify/assert" @@ -400,6 +402,8 @@ type authorityKeeperMock struct { destroyIssuerfn func(ctx sdk.Context, authority sdk.AccAddress, issuerAddress sdk.AccAddress) (*sdk.Result, error) SetGasPricesfn func(ctx sdk.Context, authority sdk.AccAddress, gasprices sdk.DecCoins) (*sdk.Result, error) replaceAuthorityfn func(ctx sdk.Context, authority, newAuthority sdk.AccAddress) (*sdk.Result, error) + scheduleUpgradefn func(ctx sdk.Context, authority sdk.AccAddress, plan upgradetypes.Plan) (*sdk.Result, error) + applyUpgradefn func(ctx sdk.Context, authority sdk.AccAddress, plan upgradetypes.Plan) (*sdk.Result, error) } func (a authorityKeeperMock) createIssuer(ctx sdk.Context, authority sdk.AccAddress, issuerAddress sdk.AccAddress, denoms []string) (*sdk.Result, error) { @@ -430,3 +434,19 @@ func (a authorityKeeperMock) replaceAuthority(ctx sdk.Context, authority, newAut return a.replaceAuthorityfn(ctx, authority, newAuthority) } + +func (a authorityKeeperMock) scheduleUpgrade(ctx sdk.Context, authority sdk.AccAddress, plan upgradetypes.Plan) (*sdk.Result, error) { + if a.scheduleUpgradefn == nil { + panic("not expected to be called") + } + + return a.scheduleUpgradefn(ctx, authority, plan) +} + +func (a authorityKeeperMock) applyUpgrade(ctx sdk.Context, authority sdk.AccAddress, plan upgradetypes.Plan) (*sdk.Result, error) { + if a.applyUpgradefn == nil { + panic("not expected to be called") + } + + return a.applyUpgradefn(ctx, authority, plan) +} diff --git a/x/authority/types/msgs.go b/x/authority/types/msgs.go index fe61de93..b77c0243 100644 --- a/x/authority/types/msgs.go +++ b/x/authority/types/msgs.go @@ -14,6 +14,8 @@ var ( _ sdk.Msg = &MsgDestroyIssuer{} _ sdk.Msg = &MsgSetGasPrices{} _ sdk.Msg = &MsgReplaceAuthority{} + _ sdk.Msg = &MsgScheduleUpgrade{} + _ sdk.Msg = &MsgApplyUpgrade{} ) func (msg MsgDestroyIssuer) Type() string { return "destroy_issuer" } @@ -24,6 +26,10 @@ func (msg MsgSetGasPrices) Type() string { return "set_gas_prices" } func (msg MsgReplaceAuthority) Type() string { return "replace_authority" } +func (msg MsgScheduleUpgrade) Type() string { return "schedule_upgrade" } + +func (msg MsgApplyUpgrade) Type() string { return "apply_upgrade" } + func (msg MsgDestroyIssuer) ValidateBasic() error { if _, err := sdk.AccAddressFromBech32(msg.Issuer); err != nil { return sdkerrors.Wrapf(sdkerrors.ErrInvalidAddress, "invalid issuer address (%s)", err) @@ -76,6 +82,30 @@ func (msg MsgReplaceAuthority) ValidateBasic() error { return nil } +func (msg MsgScheduleUpgrade) ValidateBasic() error { + if _, err := sdk.AccAddressFromBech32(msg.Authority); err != nil { + return sdkerrors.Wrapf(sdkerrors.ErrInvalidAddress, "invalid authority address (%s)", err) + } + + if err := msg.Plan.ValidateBasic(); err != nil { + return err + } + + return nil +} + +func (msg MsgApplyUpgrade) ValidateBasic() error { + if _, err := sdk.AccAddressFromBech32(msg.Authority); err != nil { + return sdkerrors.Wrapf(sdkerrors.ErrInvalidAddress, "invalid authority address (%s)", err) + } + + if err := msg.Plan.ValidateBasic(); err != nil { + return err + } + + return nil +} + func (msg MsgDestroyIssuer) GetSigners() []sdk.AccAddress { from, err := sdk.AccAddressFromBech32(msg.Authority) if err != nil { @@ -108,6 +138,22 @@ func (msg MsgReplaceAuthority) GetSigners() []sdk.AccAddress { return []sdk.AccAddress{from} } +func (msg MsgScheduleUpgrade) GetSigners() []sdk.AccAddress { + from, err := sdk.AccAddressFromBech32(msg.Authority) + if err != nil { + panic(err) + } + return []sdk.AccAddress{from} +} + +func (msg MsgApplyUpgrade) GetSigners() []sdk.AccAddress { + from, err := sdk.AccAddressFromBech32(msg.Authority) + if err != nil { + panic(err) + } + return []sdk.AccAddress{from} +} + func (msg MsgDestroyIssuer) GetSignBytes() []byte { return sdk.MustSortJSON(ModuleCdc.MustMarshalJSON(&msg)) } @@ -124,6 +170,14 @@ func (msg MsgReplaceAuthority) GetSignBytes() []byte { return sdk.MustSortJSON(ModuleCdc.MustMarshalJSON(&msg)) } +func (msg MsgScheduleUpgrade) GetSignBytes() []byte { + return sdk.MustSortJSON(ModuleCdc.MustMarshalJSON(&msg)) +} + +func (msg MsgApplyUpgrade) GetSignBytes() []byte { + return sdk.MustSortJSON(ModuleCdc.MustMarshalJSON(&msg)) +} + func (msg MsgDestroyIssuer) Route() string { return ModuleName } func (msg MsgCreateIssuer) Route() string { return ModuleName } @@ -131,3 +185,7 @@ func (msg MsgCreateIssuer) Route() string { return ModuleName } func (msg MsgSetGasPrices) Route() string { return ModuleName } func (msg MsgReplaceAuthority) Route() string { return ModuleName } + +func (msg MsgScheduleUpgrade) Route() string { return ModuleName } + +func (msg MsgApplyUpgrade) Route() string { return ModuleName } From 5b1f8243647d1dd8f6dea90dcfba7a3571b9e12a Mon Sep 17 00:00:00 2001 From: Mario Karagiorgas Date: Thu, 22 Jul 2021 16:13:24 +0300 Subject: [PATCH 03/49] Cli schedule-upgrade --- x/authority/client/cli/tx.go | 121 ++++++++++++++++++++--------------- x/authority/types/errors.go | 14 ++-- 2 files changed, 75 insertions(+), 60 deletions(-) diff --git a/x/authority/client/cli/tx.go b/x/authority/client/cli/tx.go index 51799848..29f37728 100644 --- a/x/authority/client/cli/tx.go +++ b/x/authority/client/cli/tx.go @@ -5,7 +5,6 @@ package cli import ( - "fmt" "time" sdkerrors "github.com/cosmos/cosmos-sdk/types/errors" @@ -180,60 +179,36 @@ For a 24-hour grace period the former authority key is equivalent to the new one } func GetCmdScheduleUpgrade() *cobra.Command { - cmd := &cobra.Command{ - //Use: "schedule-upg [authority_key_or_address] plan_name [upg_height] [upg_time] [upg_commit_hash]", - Use: "schedule-upg [authority_key_or_address] plan_name", - Short: "Schedule a software upgrade.", - Example: "emd tx schedule-upg emoney1n5ggspeff4fxc87dvmg0ematr3qzw5l4v20mdv 0.43 --upg_height 2001", - Long: `Schedule a software upgrade.`, - Args: cobra.ExactArgs(2), - RunE: func(cmd *cobra.Command, args []string) error { - const ( - upgHeight = "upg-upgHeightVal" - upgTime = "upg-timeVal" - upgCommitHash = "upg_commit_hash" - ) - - var ( - upgHeightVal, timeVal int64 - upgCommitVal string - ) - - f := cmd.Flags() + const ( + upgHeight = "upg-height" + upgTime = "upg-time" + upgCommitHash = "upg-commit-hash" + ) - f.Int64VarP(&upgHeightVal, upgHeight, "h", 0, "upgrade block upgHeightVal") - f.Int64VarP(&timeVal, upgTime, "t", 0, "upgrade block timeVal (in Unix seconds) to upgrade") - f.StringVarP(&upgCommitVal, upgCommitHash, "g", "", "upgrade git upgCommitVal hash") + var ( + upgHeightVal, timeVal int64 + upgCommitVal string + ) - err := f.Set(flags.FlagFrom, args[0]) + cmd := &cobra.Command{ + Use: "schedule-upg [authority_key_or_address] plan_name", + Short: "Schedule a software upgrade.", + Example: `emd tx schedule-upg emoney1n5ggspeff4fxc87dvmg0ematr3qzw5l4v20mdv 0.43 --upg_height 2001 +emd tx schedule-upg emoney1n5ggspeff4fxc87dvmg0ematr3qzw5l4v20mdv 'New Staking Rewards 36%' --upg_time 1628956125 # Unix seconds for 2021-08-14 15:48:45 +0000 UTC +emd tx schedule-upg emoney1n5ggspeff4fxc87dvmg0ematr3qzw5l4v20mdv sdk-v0.43.0 --upg_commit 6e8964b9a524e2ddd949c4afab5e1dfdcb9d588e`, + Long: `Schedule a software upgrade.`, + Args: cobra.ExactArgs(2), + RunE: func(cmd *cobra.Command, args []string) error { + err := cmd.Flags().Set(flags.FlagFrom, args[0]) if err != nil { return err } - if upgHeightVal == 0 && timeVal == 0 && upgCommitVal == "" { - return sdkerrors.Wrapf( - sdkerrors.ErrInvalidRequest, - "need to specify --%s or --%s or --%s", upgHeight, upgTime, - upgCommitHash, - ) - } - - flagsSet := 0 - if upgHeightVal != 0 { - flagsSet++ - } - if timeVal != 0 { - flagsSet++ - } - if upgCommitVal != "" { - flagsSet++ - } - if flagsSet != 1 { - return sdkerrors.Wrapf( - sdkerrors.ErrInvalidRequest, - "specify only one of the flags: --%s or --%s or --%s", upgHeight, upgTime, - upgCommitHash, - ) + if err := validateUpgFlags( + upgHeightVal, timeVal, upgCommitVal, upgHeight, upgTime, + upgCommitHash, + ); err != nil { + return err } upgTimeVal := time.Unix(timeVal, 0) @@ -257,12 +232,52 @@ func GetCmdScheduleUpgrade() *cobra.Command { return err } - fmt.Println(msg) - - //return tx.GenerateOrBroadcastTxCLI(clientCtx, cmd.Flags(), msg) - return nil + return tx.GenerateOrBroadcastTxCLI(clientCtx, cmd.Flags(), msg) }, } + f := cmd.Flags() + f.Int64VarP(&upgHeightVal, upgHeight, "n", 0, "upgrade block height number") + f.Int64VarP( + &timeVal, upgTime, "t", 0, "upgrade block time (in Unix seconds)", + ) + f.StringVarP( + &upgCommitVal, upgCommitHash, "g", "", "upgrade git commit hash", + ) + flags.AddTxFlagsToCmd(cmd) return cmd } + +func validateUpgFlags( + upgHeightVal int64, timeVal int64, upgCommitVal string, upgHeight string, + upgTime string, upgCommitHash string, +) error { + if upgHeightVal == 0 && timeVal == 0 && upgCommitVal == "" { + return sdkerrors.Wrapf( + types.ErrMissingFlag, + "need to specify --%s or --%s or --%s", upgHeight, upgTime, + upgCommitHash, + ) + } + + flagsSet := 0 + if upgHeightVal != 0 { + flagsSet++ + } + if timeVal != 0 { + flagsSet++ + } + if upgCommitVal != "" { + flagsSet++ + } + if flagsSet != 1 { + return sdkerrors.Wrapf( + sdkerrors.ErrInvalidRequest, + "specify only one of the flags: --%s or --%s or --%s", upgHeight, + upgTime, + upgCommitHash, + ) + } + + return nil +} diff --git a/x/authority/types/errors.go b/x/authority/types/errors.go index 17df36a5..e44a5acf 100644 --- a/x/authority/types/errors.go +++ b/x/authority/types/errors.go @@ -9,11 +9,11 @@ import ( ) var ( - ErrNotAuthority = sdkerrors.Register(ModuleName, 1, "not an authority") - ErrNoDenomsSpecified = sdkerrors.Register(ModuleName, 2, "No denominations specified in authority call") - ErrInvalidDenom = sdkerrors.Register(ModuleName, 3, "Invalid denomination found") - ErrNoAuthorityConfigured = sdkerrors.Register(ModuleName, 4, "No authority configured") - ErrInvalidGasPrices = sdkerrors.Register(ModuleName, 5, "Invalid gas prices") - ErrUnknownDenom = sdkerrors.Register(ModuleName, 6, "Unknown denomination specified") - ErrSameAuthorityConfigured = sdkerrors.Register(ModuleName, 7, "Authority already configured") + ErrNotAuthority = sdkerrors.Register(ModuleName, 1, "not an authority") + ErrNoDenomsSpecified = sdkerrors.Register(ModuleName, 2, "No denominations specified in authority call") + ErrInvalidDenom = sdkerrors.Register(ModuleName, 3, "Invalid denomination found") + ErrNoAuthorityConfigured = sdkerrors.Register(ModuleName, 4, "No authority configured") + ErrInvalidGasPrices = sdkerrors.Register(ModuleName, 5, "Invalid gas prices") + ErrUnknownDenom = sdkerrors.Register(ModuleName, 6, "Unknown denomination specified") + ErrMissingFlag = sdkerrors.Register(ModuleName, 7, "missing flag") ) From df48fe99964005826d269b391e6d1fedf3c84244 Mon Sep 17 00:00:00 2001 From: Mario Karagiorgas Date: Thu, 22 Jul 2021 18:16:06 +0300 Subject: [PATCH 04/49] Add upgrade keeper --- app.go | 13 ++++---- x/authority/keeper/keeper.go | 45 +++++++++++++++++++-------- x/authority/keeper/keeper_test.go | 9 +++++- x/authority/types/expected_keepers.go | 9 ++++++ 4 files changed, 56 insertions(+), 20 deletions(-) diff --git a/app.go b/app.go index d7f0aab5..c85d2ebd 100644 --- a/app.go +++ b/app.go @@ -7,6 +7,12 @@ package emoney import ( "encoding/json" "fmt" + "io" + "net/http" + "os" + "path/filepath" + "time" + "github.com/cosmos/cosmos-sdk/client" "github.com/cosmos/cosmos-sdk/client/grpc/tmservice" "github.com/cosmos/cosmos-sdk/client/rpc" @@ -65,11 +71,6 @@ import ( tmos "github.com/tendermint/tendermint/libs/os" tmproto "github.com/tendermint/tendermint/proto/tendermint/types" dbm "github.com/tendermint/tm-db" - "io" - "net/http" - "os" - "path/filepath" - "time" "github.com/cosmos/cosmos-sdk/baseapp" "github.com/cosmos/cosmos-sdk/codec" @@ -342,7 +343,7 @@ func NewApp( app.inflationKeeper = inflation.NewKeeper(app.appCodec, keys[inflation.StoreKey], app.bankKeeper, app.accountKeeper, app.stakingKeeper, buyback.AccountName, authtypes.FeeCollectorName) app.lpKeeper = liquidityprovider.NewKeeper(app.appCodec, keys[lptypes.StoreKey], app.bankKeeper) app.issuerKeeper = issuer.NewKeeper(app.appCodec, keys[issuer.StoreKey], app.lpKeeper, app.inflationKeeper) - app.authorityKeeper = authority.NewKeeper(app.appCodec, keys[authority.StoreKey], app.issuerKeeper, app.bankKeeper, app) + app.authorityKeeper = authority.NewKeeper(app.appCodec, keys[authority.StoreKey], app.issuerKeeper, app.bankKeeper, app, app.upgradeKeeper) app.marketKeeper = market.NewKeeper(app.appCodec, keys[market.StoreKey], memKeys[market.StoreKeyIdx], app.accountKeeper, app.bankKeeper) app.buybackKeeper = buyback.NewKeeper(app.appCodec, keys[buyback.StoreKey], app.marketKeeper, app.accountKeeper, app.stakingKeeper, app.bankKeeper) app.bep3Keeper = bep3.NewKeeper(app.appCodec, keys[bep3.StoreKey], app.bankKeeper, app.accountKeeper, app.paramsKeeper.Subspace(bep3.ModuleName), GetMaccs()) diff --git a/x/authority/keeper/keeper.go b/x/authority/keeper/keeper.go index 4a2f3a57..b53441db 100644 --- a/x/authority/keeper/keeper.go +++ b/x/authority/keeper/keeper.go @@ -26,22 +26,28 @@ const ( var _ authorityKeeper = Keeper{} type Keeper struct { - cdc codec.BinaryMarshaler - storeKey sdk.StoreKey - ik issuer.Keeper - bankKeeper types.BankKeeper - gpk types.GasPricesKeeper + cdc codec.BinaryMarshaler + storeKey sdk.StoreKey + ik issuer.Keeper + bankKeeper types.BankKeeper + upgradeKeeper types.UpgradeKeeper + gpk types.GasPricesKeeper gasPricesInit *sync.Once } -func NewKeeper(cdc codec.BinaryMarshaler, storeKey sdk.StoreKey, issuerKeeper issuer.Keeper, bankKeeper types.BankKeeper, gasPricesKeeper types.GasPricesKeeper) Keeper { +func NewKeeper( + cdc codec.BinaryMarshaler, storeKey sdk.StoreKey, + issuerKeeper issuer.Keeper, bankKeeper types.BankKeeper, + gasPricesKeeper types.GasPricesKeeper, upgradeKeeper types.UpgradeKeeper, +) Keeper { return Keeper{ - cdc: cdc, - ik: issuerKeeper, - bankKeeper: bankKeeper, - gpk: gasPricesKeeper, - storeKey: storeKey, + cdc: cdc, + ik: issuerKeeper, + bankKeeper: bankKeeper, + gpk: gasPricesKeeper, + storeKey: storeKey, + upgradeKeeper: upgradeKeeper, gasPricesInit: new(sync.Once), } @@ -213,11 +219,24 @@ func (k Keeper) replaceAuthority(ctx sdk.Context, authority, newAuthority sdk.Ac func (k Keeper) scheduleUpgrade( ctx sdk.Context, authority sdk.AccAddress, plan upgradetypes.Plan, ) (*sdk.Result, error) { - panic("implement me") + + // create a no-op handler if one does not exist + if k.upgradeKeeper.HasHandler(plan.Name) { + k.upgradeKeeper.SetUpgradeHandler(plan.Name, func(ctx sdk.Context, plan upgradetypes.Plan) {}) + } + + if err := k.upgradeKeeper.ScheduleUpgrade(ctx, plan); err != nil { + return nil, err + } + + return &sdk.Result{Events: ctx.EventManager().ABCIEvents()}, nil } func (k Keeper) applyUpgrade( ctx sdk.Context, authority sdk.AccAddress, plan upgradetypes.Plan, ) (*sdk.Result, error) { - panic("implement me") + + k.upgradeKeeper.ApplyUpgrade(ctx, plan) + + return &sdk.Result{Events: ctx.EventManager().ABCIEvents()}, nil } diff --git a/x/authority/keeper/keeper_test.go b/x/authority/keeper/keeper_test.go index e75737f8..0d04dd83 100644 --- a/x/authority/keeper/keeper_test.go +++ b/x/authority/keeper/keeper_test.go @@ -7,6 +7,10 @@ package keeper import ( "testing" + upgradetypes "github.com/cosmos/cosmos-sdk/x/upgrade/types" + + upgradekeeper "github.com/cosmos/cosmos-sdk/x/upgrade/keeper" + "github.com/cosmos/cosmos-sdk/codec" codectypes "github.com/cosmos/cosmos-sdk/codec/types" simappparams "github.com/cosmos/cosmos-sdk/simapp/params" @@ -392,6 +396,7 @@ func createTestComponentWithEncodingConfig(t *testing.T, encConfig simappparams. tkeyParams = sdk.NewTransientStoreKey("transient_params") keyIssuer = sdk.NewKVStoreKey(issuer.ModuleName) keyLp = sdk.NewKVStoreKey(liquidityprovider.ModuleName) + keyUpg = sdk.NewKVStoreKey(upgradetypes.StoreKey) blockedAddr = make(map[string]bool) ) @@ -422,6 +427,8 @@ func createTestComponentWithEncodingConfig(t *testing.T, encConfig simappparams. ) lpk = liquidityprovider.NewKeeper(encConfig.Marshaler, keyLp, bk) ik = issuer.NewKeeper(encConfig.Marshaler, keyIssuer, lpk, mockInflationKeeper{}) + + upgK = upgradekeeper.NewKeeper(map[int64]bool{}, keyUpg, encConfig.Marshaler, t.TempDir()) ) bk.SetSupply(ctx, banktypes.NewSupply( @@ -431,7 +438,7 @@ func createTestComponentWithEncodingConfig(t *testing.T, encConfig simappparams. ))) gpk := new(mockGasPricesKeeper) - keeper := NewKeeper(encConfig.Marshaler, authKey, ik, bk, gpk) + keeper := NewKeeper(encConfig.Marshaler, authKey, ik, bk, gpk, upgK) return ctx, keeper, ik, gpk } diff --git a/x/authority/types/expected_keepers.go b/x/authority/types/expected_keepers.go index 79c34c7e..cc5103b6 100644 --- a/x/authority/types/expected_keepers.go +++ b/x/authority/types/expected_keepers.go @@ -7,6 +7,7 @@ package types import ( sdk "github.com/cosmos/cosmos-sdk/types" "github.com/cosmos/cosmos-sdk/x/bank/exported" + "github.com/cosmos/cosmos-sdk/x/upgrade/types" ) type ( @@ -17,4 +18,12 @@ type ( BankKeeper interface { GetSupply(ctx sdk.Context) exported.SupplyI } + + UpgradeKeeper interface { + ApplyUpgrade(ctx sdk.Context, plan types.Plan) + GetUpgradePlan(ctx sdk.Context) (plan types.Plan, havePlan bool) + HasHandler(name string) bool + ScheduleUpgrade(ctx sdk.Context, plan types.Plan) error + SetUpgradeHandler(name string, upgradeHandler types.UpgradeHandler) + } ) From e45615dfb91dd09329dfde25a1e78d03ba48ada5 Mon Sep 17 00:00:00 2001 From: Mario Karagiorgas Date: Thu, 22 Jul 2021 19:01:25 +0300 Subject: [PATCH 05/49] Upgrade v0.42.7 --- go.mod | 2 +- go.sum | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/go.mod b/go.mod index e6e0cfe5..5236074b 100644 --- a/go.mod +++ b/go.mod @@ -3,7 +3,7 @@ module github.com/e-money/em-ledger go 1.15 require ( - github.com/cosmos/cosmos-sdk v0.42.6 + github.com/cosmos/cosmos-sdk v0.42.7 github.com/e-money/bep3 v0.3.4 github.com/gogo/protobuf v1.3.3 github.com/golang/protobuf v1.5.2 diff --git a/go.sum b/go.sum index 61692096..03bd66e2 100644 --- a/go.sum +++ b/go.sum @@ -101,8 +101,8 @@ github.com/coreos/go-systemd v0.0.0-20190321100706-95778dfbb74e/go.mod h1:F5haX7 github.com/coreos/pkg v0.0.0-20160727233714-3ac0863d7acf/go.mod h1:E3G3o1h8I7cfcXa63jLwjI0eiQQMgzzUDFVpN/nH/eA= github.com/coreos/pkg v0.0.0-20180928190104-399ea9e2e55f/go.mod h1:E3G3o1h8I7cfcXa63jLwjI0eiQQMgzzUDFVpN/nH/eA= github.com/cosmos/cosmos-sdk v0.42.4/go.mod h1:I1Zw1zmU4rA/NITaakTb71pXQnQrWyFBhqo3WSeg0vA= -github.com/cosmos/cosmos-sdk v0.42.6 h1:ps1QWfvaX6VLNcykA7wzfii/5IwBfYgTIik6NOVDq/c= -github.com/cosmos/cosmos-sdk v0.42.6/go.mod h1:kh37gwYQoWdgR7N/9zeqW2rJ7cnP2W4A7nqIaf6m3zg= +github.com/cosmos/cosmos-sdk v0.42.7 h1:f+ZUjao2y93I37RZ7P2d94JdcEsS7Vq64SBLcNITAVc= +github.com/cosmos/cosmos-sdk v0.42.7/go.mod h1:SrclJP9lMXxz2fCbngxb0brsPNuZXqoQQ9VHuQ3Tpf4= github.com/cosmos/go-bip39 v0.0.0-20180819234021-555e2067c45d/go.mod h1:tSxLoYXyBmiFeKpvmq4dzayMdCjCnu8uqmCysIGBT2Y= github.com/cosmos/go-bip39 v1.0.0 h1:pcomnQdrdH22njcAatO0yWojsUnCO3y2tNoV1cb6hHY= github.com/cosmos/go-bip39 v1.0.0/go.mod h1:RNJv0H/pOIVgxw6KS7QeX2a0Uo0aKUlfhZ4xuwvCdJw= From 16fcb0217f93fd8a74ceaa45857fb9a62efd1b18 Mon Sep 17 00:00:00 2001 From: Mario Karagiorgas Date: Fri, 23 Jul 2021 13:03:31 +0300 Subject: [PATCH 06/49] Add startemd --- networks/.gitignore | 1 + networks/utils/startemd | 29 +++++++++++++++++++++++++++++ 2 files changed, 30 insertions(+) create mode 100644 networks/.gitignore create mode 100755 networks/utils/startemd diff --git a/networks/.gitignore b/networks/.gitignore new file mode 100644 index 00000000..0763333a --- /dev/null +++ b/networks/.gitignore @@ -0,0 +1 @@ +.emd/ \ No newline at end of file diff --git a/networks/utils/startemd b/networks/utils/startemd new file mode 100755 index 00000000..aeddb34d --- /dev/null +++ b/networks/utils/startemd @@ -0,0 +1,29 @@ +#!/bin/bash + +set -ev + +EMD=../../build/emd +EMD_HOME=$PWD/.. +EMD_NODE=$EMD_HOME/.emd + +# do not do this in production +rm -rf "$EMD_NODE"/config +rm -rf "$EMD_NODE"/data +rm -rf "$EMD_NODE"/keyring-test +# do not delete cosmovisor if it exists + +$EMD init test --chain-id=test --home="$EMD_NODE" --overwrite +$EMD keys add validator --keyring-backend=test --home="$EMD_NODE" +$EMD add-genesis-account "$($EMD keys show validator -a --keyring-backend=test --home="$EMD_NODE")" 1000000000stake,1000000000ungm --home=$EMD_NODE +$EMD gentx validator 500000000stake --keyring-backend=test --home="$EMD_NODE" --chain-id=test +$EMD collect-gentxs --home="$EMD_NODE" + +# establish authority emoney1xue7fm6es84jze49grm4slhlmr4ffz8a3u7g3t +AUTH_SEED="fuel public electric luxury short upper quit edge ginger need olive gesture time useful stadium exhaust since team pond wool type flat focus narrow" +(echo "$AUTH_SEED"; echo "$AUTH_SEED") | $EMD keys add authoritykey --recover --keyring-backend=test --home="$EMD_NODE" +AUTHORITY_ADDR=$($EMD keys show authoritykey -a --keyring-backend=test --home="$EMD_NODE") +AUTHORITY_ADDR_VAL=".app_state.authority.key=\"$AUTHORITY_ADDR\"" +jq $AUTHORITY_ADDR_VAL < "$EMD_NODE"/config/genesis.json > "$EMD_NODE"/config/tmp_genesis.json +mv "$EMD_NODE"/config/tmp_genesis.json "$EMD_NODE"/config/genesis.json + +$EMD start --home="$EMD_NODE" \ No newline at end of file From a7900c9bc21a0730ae48c34b927412c4a474a0a0 Mon Sep 17 00:00:00 2001 From: Mario Karagiorgas Date: Fri, 23 Jul 2021 15:08:57 +0300 Subject: [PATCH 07/49] Add cpemd --- networks/upg/cpemd | 34 ++++++++++++++++++++++++++++++++++ 1 file changed, 34 insertions(+) create mode 100755 networks/upg/cpemd diff --git a/networks/upg/cpemd b/networks/upg/cpemd new file mode 100755 index 00000000..ec26914f --- /dev/null +++ b/networks/upg/cpemd @@ -0,0 +1,34 @@ +#!/bin/zsh + +set -e + +# cosmovisor constants +export DAEMON_NAME=emd +export DAEMON_ALLOW_DOWNLOAD_BINARIES=true +export DAEMON_RESTART_AFTER_UPGRADE=true + +if [[ -d $PWD/.emd ]]; then + export DAEMON_HOME=$PWD/.emd +elif [[ -d ../.emd ]]; then + pushd -q ../ + export DAEMON_HOME=$PWD/.emd + popd -q +else + echo ".emd folder not found neither in $PWD nor in parent. run startemd.sh to create node" + exit 1 +fi + +echo "node home: $DAEMON_HOME" + +EMD=$DAEMON_HOME/../../build/emd + +if [[ ! -f $DAEMON_HOME/cosmovisor/genesis/bin/emd ]]; then + + mkdir -p "$DAEMON_HOME"/cosmovisor/genesis/bin + cp "$EMD" "$DAEMON_HOME"/cosmovisor/genesis/bin + +fi + +echo "legacy or current binary in "$DAEMON_HOME"/cosmovisor/genesis/bin" + +echo "current version: $(cosmovisor version)" \ No newline at end of file From 3c3bba602fc9d2a5e61286108af107d26beecf19 Mon Sep 17 00:00:00 2001 From: Mario Karagiorgas Date: Fri, 23 Jul 2021 17:09:34 +0300 Subject: [PATCH 08/49] Modify schedule-upg info param for cosmovisor compatibility --- x/authority/client/cli/tx.go | 37 +++++++++++++++--------------------- 1 file changed, 15 insertions(+), 22 deletions(-) diff --git a/x/authority/client/cli/tx.go b/x/authority/client/cli/tx.go index 29f37728..cde8ef69 100644 --- a/x/authority/client/cli/tx.go +++ b/x/authority/client/cli/tx.go @@ -180,14 +180,14 @@ For a 24-hour grace period the former authority key is equivalent to the new one func GetCmdScheduleUpgrade() *cobra.Command { const ( - upgHeight = "upg-height" - upgTime = "upg-time" - upgCommitHash = "upg-commit-hash" + upgHeight = "upg-height" + upgTime = "upg-time" + upgInfo = "upg-info" ) var ( - upgHeightVal, timeVal int64 - upgCommitVal string + upgHeightVal, upgTimeSecsVal int64 + upgInfoVal string ) cmd := &cobra.Command{ @@ -195,7 +195,7 @@ func GetCmdScheduleUpgrade() *cobra.Command { Short: "Schedule a software upgrade.", Example: `emd tx schedule-upg emoney1n5ggspeff4fxc87dvmg0ematr3qzw5l4v20mdv 0.43 --upg_height 2001 emd tx schedule-upg emoney1n5ggspeff4fxc87dvmg0ematr3qzw5l4v20mdv 'New Staking Rewards 36%' --upg_time 1628956125 # Unix seconds for 2021-08-14 15:48:45 +0000 UTC -emd tx schedule-upg emoney1n5ggspeff4fxc87dvmg0ematr3qzw5l4v20mdv sdk-v0.43.0 --upg_commit 6e8964b9a524e2ddd949c4afab5e1dfdcb9d588e`, +emd tx schedule-upg emoney1n5ggspeff4fxc87dvmg0ematr3qzw5l4v20mdv sdk-v0.43.0 --upg_height 2001 --upg_info "https://e-money.com/mainnet-099-info.json?checksum=sha256:deaaa99fda9407c4dbe1d04bd49bab0cc3c1dd76fa392cd55a9425be074af01e"`, Long: `Schedule a software upgrade.`, Args: cobra.ExactArgs(2), RunE: func(cmd *cobra.Command, args []string) error { @@ -205,13 +205,12 @@ emd tx schedule-upg emoney1n5ggspeff4fxc87dvmg0ematr3qzw5l4v20mdv sdk-v0.43.0 -- } if err := validateUpgFlags( - upgHeightVal, timeVal, upgCommitVal, upgHeight, upgTime, - upgCommitHash, + upgHeight, upgHeightVal, upgTime, upgTimeSecsVal, ); err != nil { return err } - upgTimeVal := time.Unix(timeVal, 0) + upgTimeVal := time.Unix(upgTimeSecsVal, 0) clientCtx, err := client.GetClientTxContext(cmd) if err != nil { @@ -224,7 +223,7 @@ emd tx schedule-upg emoney1n5ggspeff4fxc87dvmg0ematr3qzw5l4v20mdv sdk-v0.43.0 -- Name: args[1], Time: upgTimeVal, Height: upgHeightVal, - Info: upgCommitVal, + Info: upgInfoVal, }, } @@ -238,10 +237,10 @@ emd tx schedule-upg emoney1n5ggspeff4fxc87dvmg0ematr3qzw5l4v20mdv sdk-v0.43.0 -- f := cmd.Flags() f.Int64VarP(&upgHeightVal, upgHeight, "n", 0, "upgrade block height number") f.Int64VarP( - &timeVal, upgTime, "t", 0, "upgrade block time (in Unix seconds)", + &upgTimeSecsVal, upgTime, "t", 0, "upgrade block time (in Unix seconds)", ) f.StringVarP( - &upgCommitVal, upgCommitHash, "g", "", "upgrade git commit hash", + &upgInfoVal, upgInfo, "i", "", "upgrade info", ) flags.AddTxFlagsToCmd(cmd) @@ -249,14 +248,12 @@ emd tx schedule-upg emoney1n5ggspeff4fxc87dvmg0ematr3qzw5l4v20mdv sdk-v0.43.0 -- } func validateUpgFlags( - upgHeightVal int64, timeVal int64, upgCommitVal string, upgHeight string, - upgTime string, upgCommitHash string, + upgHeight string, upgHeightVal int64, upgTime string, timeVal int64, ) error { - if upgHeightVal == 0 && timeVal == 0 && upgCommitVal == "" { + if upgHeightVal == 0 && timeVal == 0 { return sdkerrors.Wrapf( types.ErrMissingFlag, - "need to specify --%s or --%s or --%s", upgHeight, upgTime, - upgCommitHash, + "need to specify --%s or --%s", upgHeight, upgTime, ) } @@ -267,15 +264,11 @@ func validateUpgFlags( if timeVal != 0 { flagsSet++ } - if upgCommitVal != "" { - flagsSet++ - } if flagsSet != 1 { return sdkerrors.Wrapf( sdkerrors.ErrInvalidRequest, - "specify only one of the flags: --%s or --%s or --%s", upgHeight, + "specify only one of the flags: --%s or --%s", upgHeight, upgTime, - upgCommitHash, ) } From 3b05ded1b505340919898c1a79ebf3370d310779 Mon Sep 17 00:00:00 2001 From: Mario Karagiorgas Date: Fri, 23 Jul 2021 17:51:26 +0300 Subject: [PATCH 09/49] Remove authority param --- x/authority/keeper/keeper.go | 8 ++------ x/authority/keeper/msg_server.go | 17 ++++++++++++++--- x/authority/keeper/msg_server_test.go | 12 ++++++------ 3 files changed, 22 insertions(+), 15 deletions(-) diff --git a/x/authority/keeper/keeper.go b/x/authority/keeper/keeper.go index b53441db..d3b34195 100644 --- a/x/authority/keeper/keeper.go +++ b/x/authority/keeper/keeper.go @@ -216,9 +216,7 @@ func (k Keeper) replaceAuthority(ctx sdk.Context, authority, newAuthority sdk.Ac return &sdk.Result{Events: ctx.EventManager().ABCIEvents()}, nil } -func (k Keeper) scheduleUpgrade( - ctx sdk.Context, authority sdk.AccAddress, plan upgradetypes.Plan, -) (*sdk.Result, error) { +func (k Keeper) scheduleUpgrade(ctx sdk.Context, plan upgradetypes.Plan) (*sdk.Result, error) { // create a no-op handler if one does not exist if k.upgradeKeeper.HasHandler(plan.Name) { @@ -232,9 +230,7 @@ func (k Keeper) scheduleUpgrade( return &sdk.Result{Events: ctx.EventManager().ABCIEvents()}, nil } -func (k Keeper) applyUpgrade( - ctx sdk.Context, authority sdk.AccAddress, plan upgradetypes.Plan, -) (*sdk.Result, error) { +func (k Keeper) applyUpgrade(ctx sdk.Context, plan upgradetypes.Plan) (*sdk.Result, error) { k.upgradeKeeper.ApplyUpgrade(ctx, plan) diff --git a/x/authority/keeper/msg_server.go b/x/authority/keeper/msg_server.go index 0013b944..d32cf641 100644 --- a/x/authority/keeper/msg_server.go +++ b/x/authority/keeper/msg_server.go @@ -17,8 +17,8 @@ type authorityKeeper interface { destroyIssuer(ctx sdk.Context, authority sdk.AccAddress, issuerAddress sdk.AccAddress) (*sdk.Result, error) replaceAuthority(ctx sdk.Context, authority, newAuthority sdk.AccAddress) (*sdk.Result, error) SetGasPrices(ctx sdk.Context, authority sdk.AccAddress, gasprices sdk.DecCoins) (*sdk.Result, error) - scheduleUpgrade(ctx sdk.Context, authority sdk.AccAddress, plan upgradetypes.Plan) (*sdk.Result, error) - applyUpgrade(ctx sdk.Context, authority sdk.AccAddress, plan upgradetypes.Plan) (*sdk.Result, error) + scheduleUpgrade(ctx sdk.Context, plan upgradetypes.Plan) (*sdk.Result, error) + applyUpgrade(ctx sdk.Context, plan upgradetypes.Plan) (*sdk.Result, error) } type msgServer struct { k authorityKeeper @@ -114,9 +114,20 @@ func (m msgServer) ReplaceAuthority(goCtx context.Context, msg *types.MsgReplace } func (m msgServer) ScheduleUpgrade( - ctx context.Context, upgrade *types.MsgScheduleUpgrade, + goCtx context.Context, upgrade *types.MsgScheduleUpgrade, ) (*types.MsgScheduleUpgradeResponse, error) { + ctx := sdk.UnwrapSDKContext(goCtx) + + result, err := m.k.scheduleUpgrade(ctx, upgrade.Plan) + if err != nil { + return nil, err + } + + for _, e := range result.Events { + ctx.EventManager().EmitEvent(sdk.Event(e)) + } + return &types.MsgScheduleUpgradeResponse{}, nil } diff --git a/x/authority/keeper/msg_server_test.go b/x/authority/keeper/msg_server_test.go index b7e4d6d9..b3e123a4 100644 --- a/x/authority/keeper/msg_server_test.go +++ b/x/authority/keeper/msg_server_test.go @@ -402,8 +402,8 @@ type authorityKeeperMock struct { destroyIssuerfn func(ctx sdk.Context, authority sdk.AccAddress, issuerAddress sdk.AccAddress) (*sdk.Result, error) SetGasPricesfn func(ctx sdk.Context, authority sdk.AccAddress, gasprices sdk.DecCoins) (*sdk.Result, error) replaceAuthorityfn func(ctx sdk.Context, authority, newAuthority sdk.AccAddress) (*sdk.Result, error) - scheduleUpgradefn func(ctx sdk.Context, authority sdk.AccAddress, plan upgradetypes.Plan) (*sdk.Result, error) - applyUpgradefn func(ctx sdk.Context, authority sdk.AccAddress, plan upgradetypes.Plan) (*sdk.Result, error) + scheduleUpgradefn func(ctx sdk.Context, plan upgradetypes.Plan) (*sdk.Result, error) + applyUpgradefn func(ctx sdk.Context, plan upgradetypes.Plan) (*sdk.Result, error) } func (a authorityKeeperMock) createIssuer(ctx sdk.Context, authority sdk.AccAddress, issuerAddress sdk.AccAddress, denoms []string) (*sdk.Result, error) { @@ -435,18 +435,18 @@ func (a authorityKeeperMock) replaceAuthority(ctx sdk.Context, authority, newAut return a.replaceAuthorityfn(ctx, authority, newAuthority) } -func (a authorityKeeperMock) scheduleUpgrade(ctx sdk.Context, authority sdk.AccAddress, plan upgradetypes.Plan) (*sdk.Result, error) { +func (a authorityKeeperMock) scheduleUpgrade(ctx sdk.Context, plan upgradetypes.Plan) (*sdk.Result, error) { if a.scheduleUpgradefn == nil { panic("not expected to be called") } - return a.scheduleUpgradefn(ctx, authority, plan) + return a.scheduleUpgradefn(ctx, plan) } -func (a authorityKeeperMock) applyUpgrade(ctx sdk.Context, authority sdk.AccAddress, plan upgradetypes.Plan) (*sdk.Result, error) { +func (a authorityKeeperMock) applyUpgrade(ctx sdk.Context, plan upgradetypes.Plan) (*sdk.Result, error) { if a.applyUpgradefn == nil { panic("not expected to be called") } - return a.applyUpgradefn(ctx, authority, plan) + return a.applyUpgradefn(ctx, plan) } From 3e384e820b25bfb5ab98b736208b9e8e70786eab Mon Sep 17 00:00:00 2001 From: Mario Karagiorgas Date: Fri, 23 Jul 2021 17:57:24 +0300 Subject: [PATCH 10/49] Remove setting handler --- x/authority/keeper/keeper.go | 6 ------ 1 file changed, 6 deletions(-) diff --git a/x/authority/keeper/keeper.go b/x/authority/keeper/keeper.go index d3b34195..4e2c3357 100644 --- a/x/authority/keeper/keeper.go +++ b/x/authority/keeper/keeper.go @@ -217,12 +217,6 @@ func (k Keeper) replaceAuthority(ctx sdk.Context, authority, newAuthority sdk.Ac } func (k Keeper) scheduleUpgrade(ctx sdk.Context, plan upgradetypes.Plan) (*sdk.Result, error) { - - // create a no-op handler if one does not exist - if k.upgradeKeeper.HasHandler(plan.Name) { - k.upgradeKeeper.SetUpgradeHandler(plan.Name, func(ctx sdk.Context, plan upgradetypes.Plan) {}) - } - if err := k.upgradeKeeper.ScheduleUpgrade(ctx, plan); err != nil { return nil, err } From 8215b8de78062b284829d3550a4fdd020ab1fb21 Mon Sep 17 00:00:00 2001 From: Mario Karagiorgas Date: Sat, 24 Jul 2021 13:46:09 +0300 Subject: [PATCH 11/49] Add upgrade tests to e-Money Sim App --- app_test.go | 246 +++++++++++++++++++++++++++++++++++++++++++++++++--- 1 file changed, 233 insertions(+), 13 deletions(-) diff --git a/app_test.go b/app_test.go index 9c09df51..57d019c5 100644 --- a/app_test.go +++ b/app_test.go @@ -2,23 +2,48 @@ package emoney import ( "encoding/json" - sdk "github.com/cosmos/cosmos-sdk/types" - "github.com/e-money/em-ledger/x/authority" - "github.com/tendermint/tendermint/libs/rand" "os" + "path/filepath" "testing" + "time" + + upgradekeeper "github.com/cosmos/cosmos-sdk/x/upgrade/keeper" + + apptypes "github.com/e-money/em-ledger/types" + sdk "github.com/cosmos/cosmos-sdk/types" + upgradetypes "github.com/cosmos/cosmos-sdk/x/upgrade/types" + authtypes "github.com/e-money/em-ledger/x/authority/types" "github.com/stretchr/testify/require" + abci "github.com/tendermint/tendermint/abci/types" "github.com/tendermint/tendermint/libs/log" + "github.com/tendermint/tendermint/libs/rand" + tmproto "github.com/tendermint/tendermint/proto/tendermint/types" dbm "github.com/tendermint/tm-db" - - abci "github.com/tendermint/tendermint/abci/types" ) func TestSimAppExportAndBlockedAddrs(t *testing.T) { + encCfg, db, app := getEmSimApp(t, rand.Bytes(sdk.AddrLen)) + app.Commit() + + // Making a new app object with the db, so that initchain hasn't been called + app2 := NewApp( + log.NewTMLogger(log.NewSyncWriter(os.Stdout)), db, nil, true, + map[int64]bool{}, t.TempDir(), 0, encCfg, EmptyAppOptions{}, + ) + _, err := app2.ExportAppStateAndValidators(false, []string{}) + require.NoError( + t, err, "ExportAppStateAndValidators should not have an error", + ) +} + +func getEmSimApp(t *testing.T, authorityAcc sdk.AccAddress) (EncodingConfig, *dbm.MemDB, *EMoneyApp) { encCfg := MakeEncodingConfig() db := dbm.NewMemDB() - app := NewApp(log.NewTMLogger(log.NewSyncWriter(os.Stdout)), db, nil, true, map[int64]bool{}, t.TempDir(), 0, encCfg, EmptyAppOptions{}) + app := NewApp( + log.NewTMLogger(log.NewSyncWriter(os.Stdout)), db, nil, true, + map[int64]bool{}, t.TempDir(), 0, encCfg, EmptyAppOptions{}, + ) for acc := range maccPerms { require.True( @@ -29,8 +54,10 @@ func TestSimAppExportAndBlockedAddrs(t *testing.T) { } genesisState := ModuleBasics.DefaultGenesis(encCfg.Marshaler) - authorityState := authority.NewGenesisState(rand.Bytes(sdk.AddrLen), sdk.NewDecCoins()) - genesisState[authority.ModuleName] = encCfg.Marshaler.MustMarshalJSON(&authorityState) + //authorityState := authority.NewGenesisState(rand.Bytes(sdk.AddrLen), sdk.NewDecCoins()) + authorityState := authtypes.GenesisState{AuthorityKey: authorityAcc.String(), MinGasPrices: sdk.NewDecCoins()} + + genesisState["authority"] = encCfg.Marshaler.MustMarshalJSON(&authorityState) stateBytes, err := json.MarshalIndent(genesisState, "", " ") require.NoError(t, err) @@ -42,12 +69,8 @@ func TestSimAppExportAndBlockedAddrs(t *testing.T) { AppStateBytes: stateBytes, }, ) - app.Commit() - // Making a new app object with the db, so that initchain hasn't been called - app2 := NewApp(log.NewTMLogger(log.NewSyncWriter(os.Stdout)), db, nil, true, map[int64]bool{}, t.TempDir(), 0, encCfg, EmptyAppOptions{}) - _, err = app2.ExportAppStateAndValidators(false, []string{}) - require.NoError(t, err, "ExportAppStateAndValidators should not have an error") + return encCfg, db, app } // EmptyAppOptions is a stub implementing AppOptions @@ -57,3 +80,200 @@ type EmptyAppOptions struct{} func (ao EmptyAppOptions) Get(o string) interface{} { return nil } + +type upgTests struct { + ctx sdk.Context + homeDir string + app *EMoneyApp +} + +func (ut *upgTests) initApp(t *testing.T) { + homeDir := filepath.Join(t.TempDir(), "x_upgrade_keeper_test") + + authorityAddr, err := sdk.AccAddressFromBech32("emoney1kt0vh0ttget0xx77g6d3ttnvq2lnxx6vp3uyl0") + require.NoError(t, err) + + _, _, app := getEmSimApp(t, authorityAddr) + app.upgradeKeeper = upgradekeeper.NewKeeper( // recreate keeper in order to use a custom home path + make(map[int64]bool), app.GetKey(upgradetypes.StoreKey), app.AppCodec(), homeDir, + ) + t.Log("home dir:", homeDir) + + ut.homeDir = homeDir + ut.app = app + ut.ctx = app.BaseApp.NewContext(false, tmproto.Header{ + Time: time.Now(), + Height: 10, + }) +} + +func Test_ScheduleUpgrade(t *testing.T) { + apptypes.ConfigureSDK() + + tests := []struct { + suite upgTests + name string + plan upgradetypes.Plan + setupUpgCond func(simApp upgTests, plan *upgradetypes.Plan) + expPass bool + }{ + { + suite: upgTests{}, + name: "successful time schedule", + plan: upgradetypes.Plan{ + Name: "all-good", + Info: "some text here", + }, + setupUpgCond: func(simApp upgTests, plan *upgradetypes.Plan) { + plan.Time = simApp.ctx.BlockTime().Add(time.Hour) + }, + expPass: true, + }, + { + suite: upgTests{}, + name: "successful height schedule", + plan: upgradetypes.Plan{ + Name: "all-good", + Info: "some text here", + Height: 123450000, + }, + setupUpgCond: func(simApp upgTests, plan *upgradetypes.Plan) {}, + expPass: true, + }, + { + suite: upgTests{}, + name: "successful schedule", + plan: upgradetypes.Plan{ + Name: "all-good", + Info: "some text here", + Height: 123450000, + }, + setupUpgCond: func(simApp upgTests, plan *upgradetypes.Plan) {}, + expPass: true, + }, + { + suite: upgTests{}, + name: "successful overwrite", + plan: upgradetypes.Plan{ + Name: "all-good", + Info: "some text here", + Height: 123450000, + }, + setupUpgCond: func(simApp upgTests, plan *upgradetypes.Plan) { + + err := simApp.app.upgradeKeeper.ScheduleUpgrade(simApp.ctx, upgradetypes.Plan{ + Name: "alt-good", + Info: "new text here", + Height: 543210000, + }) + require.NoError(t, err) + }, + expPass: true, + }, + { + suite: upgTests{}, + name: "successful overwrite", + plan: upgradetypes.Plan{ + Name: "all-good", + Info: "some text here", + Height: 123450000, + }, + setupUpgCond: func(simApp upgTests, plan *upgradetypes.Plan) { + err := simApp.app.upgradeKeeper.ScheduleUpgrade(simApp.ctx, upgradetypes.Plan{ + Name: "alt-good", + Info: "new text here", + Height: 543210000, + }) + require.NoError(t, err) + }, + expPass: true, + }, + { + suite: upgTests{}, + name: "successful IBC overwrite with non IBC plan", + plan: upgradetypes.Plan{ + Name: "all-good", + Info: "some text here", + Height: 123450000, + }, + setupUpgCond: func(simApp upgTests, plan *upgradetypes.Plan) { + err := simApp.app.upgradeKeeper.ScheduleUpgrade(simApp.ctx, upgradetypes.Plan{ + Name: "alt-good", + Info: "new text here", + Height: 543210000, + }) + require.NoError(t, err) + }, + expPass: true, + }, + { + suite: upgTests{}, + name: "unsuccessful schedule: invalid plan", + plan: upgradetypes.Plan{ + Height: 123450000, + }, + setupUpgCond: func(simApp upgTests, plan *upgradetypes.Plan) {}, + expPass: false, + }, + { + suite: upgTests{}, + name: "unsuccessful time schedule: due date in past", + plan: upgradetypes.Plan{ + Name: "all-good", + Info: "some text here", + }, + setupUpgCond: func(simApp upgTests, plan *upgradetypes.Plan) { + plan.Time = simApp.ctx.BlockTime() + }, + expPass: false, + }, + { + suite: upgTests{}, + name: "unsuccessful height schedule: due date in past", + plan: upgradetypes.Plan{ + Name: "all-good", + Info: "some text here", + Height: 1, + }, + setupUpgCond: func(simApp upgTests, plan *upgradetypes.Plan) {}, + expPass: false, + }, + { + suite: upgTests{}, + name: "unsuccessful schedule: schedule already executed", + plan: upgradetypes.Plan{ + Name: "all-good", + Info: "some text here", + Height: 123450000, + }, + setupUpgCond: func(simApp upgTests, plan *upgradetypes.Plan) { + simApp.app.upgradeKeeper.SetUpgradeHandler("all-good", func(_ sdk.Context, _ upgradetypes.Plan) {}) + simApp.app.upgradeKeeper.ApplyUpgrade(simApp.ctx, upgradetypes.Plan{ + Name: "all-good", + Info: "some text here", + Height: 123450000, + }) + }, + expPass: false, + }, + } + for _, tt := range tests { + t.Run( + tt.name, func(t *testing.T) { + tt.suite.initApp(t) + + // setupUpgCond test case + tt.setupUpgCond(tt.suite, &tt.plan) + + err := tt.suite.app.upgradeKeeper.ScheduleUpgrade(tt.suite.ctx, tt.plan) + + if (err != nil) == tt.expPass { + t.Errorf( + "scheduleUpgrade() error = %v, expPass %v", err, tt.expPass, + ) + return + } + }, + ) + } +} From 297f897366b85c927c8566fea45ff0ef1bf4d76c Mon Sep 17 00:00:00 2001 From: Mario Karagiorgas Date: Mon, 26 Jul 2021 13:02:13 +0300 Subject: [PATCH 12/49] Complete emSimApp upgrade keeper tests --- app.go | 2 +- app_test.go | 128 +++++++++++++++----------- x/authority/keeper/keeper.go | 9 +- x/authority/keeper/msg_server.go | 7 +- x/authority/keeper/msg_server_test.go | 13 ++- 5 files changed, 97 insertions(+), 62 deletions(-) diff --git a/app.go b/app.go index c85d2ebd..28b3f23c 100644 --- a/app.go +++ b/app.go @@ -343,7 +343,7 @@ func NewApp( app.inflationKeeper = inflation.NewKeeper(app.appCodec, keys[inflation.StoreKey], app.bankKeeper, app.accountKeeper, app.stakingKeeper, buyback.AccountName, authtypes.FeeCollectorName) app.lpKeeper = liquidityprovider.NewKeeper(app.appCodec, keys[lptypes.StoreKey], app.bankKeeper) app.issuerKeeper = issuer.NewKeeper(app.appCodec, keys[issuer.StoreKey], app.lpKeeper, app.inflationKeeper) - app.authorityKeeper = authority.NewKeeper(app.appCodec, keys[authority.StoreKey], app.issuerKeeper, app.bankKeeper, app, app.upgradeKeeper) + app.authorityKeeper = authority.NewKeeper(app.appCodec, keys[authority.StoreKey], app.issuerKeeper, app.bankKeeper, app, &app.upgradeKeeper) app.marketKeeper = market.NewKeeper(app.appCodec, keys[market.StoreKey], memKeys[market.StoreKeyIdx], app.accountKeeper, app.bankKeeper) app.buybackKeeper = buyback.NewKeeper(app.appCodec, keys[buyback.StoreKey], app.marketKeeper, app.accountKeeper, app.stakingKeeper, app.bankKeeper) app.bep3Keeper = bep3.NewKeeper(app.appCodec, keys[bep3.StoreKey], app.bankKeeper, app.accountKeeper, app.paramsKeeper.Subspace(bep3.ModuleName), GetMaccs()) diff --git a/app_test.go b/app_test.go index 57d019c5..072879e7 100644 --- a/app_test.go +++ b/app_test.go @@ -81,13 +81,13 @@ func (ao EmptyAppOptions) Get(o string) interface{} { return nil } -type upgTests struct { +type emAppTests struct { ctx sdk.Context homeDir string app *EMoneyApp } -func (ut *upgTests) initApp(t *testing.T) { +func (et *emAppTests) initEmApp(t *testing.T) { homeDir := filepath.Join(t.TempDir(), "x_upgrade_keeper_test") authorityAddr, err := sdk.AccAddressFromBech32("emoney1kt0vh0ttget0xx77g6d3ttnvq2lnxx6vp3uyl0") @@ -99,69 +99,69 @@ func (ut *upgTests) initApp(t *testing.T) { ) t.Log("home dir:", homeDir) - ut.homeDir = homeDir - ut.app = app - ut.ctx = app.BaseApp.NewContext(false, tmproto.Header{ + et.homeDir = homeDir + et.app = app + et.ctx = app.BaseApp.NewContext(false, tmproto.Header{ Time: time.Now(), Height: 10, }) } -func Test_ScheduleUpgrade(t *testing.T) { +func Test_Upgrade(t *testing.T) { apptypes.ConfigureSDK() tests := []struct { - suite upgTests + suite emAppTests name string plan upgradetypes.Plan - setupUpgCond func(simApp upgTests, plan *upgradetypes.Plan) + setupUpgCond func(simApp emAppTests, plan *upgradetypes.Plan) expPass bool + qrySched bool + qryApply bool }{ { - suite: upgTests{}, - name: "successful time schedule", + name: "successful time schedule", plan: upgradetypes.Plan{ Name: "all-good", Info: "some text here", }, - setupUpgCond: func(simApp upgTests, plan *upgradetypes.Plan) { + setupUpgCond: func(simApp emAppTests, plan *upgradetypes.Plan) { plan.Time = simApp.ctx.BlockTime().Add(time.Hour) }, expPass: true, }, { - suite: upgTests{}, - name: "successful height schedule", + name: "successful height schedule", plan: upgradetypes.Plan{ Name: "all-good", Info: "some text here", Height: 123450000, }, - setupUpgCond: func(simApp upgTests, plan *upgradetypes.Plan) {}, + setupUpgCond: func(simApp emAppTests, plan *upgradetypes.Plan) {}, expPass: true, }, { - suite: upgTests{}, - name: "successful schedule", + name: "setting both time and height schedule", plan: upgradetypes.Plan{ Name: "all-good", Info: "some text here", Height: 123450000, }, - setupUpgCond: func(simApp upgTests, plan *upgradetypes.Plan) {}, - expPass: true, + setupUpgCond: func(simApp emAppTests, plan *upgradetypes.Plan) { + plan.Time = simApp.ctx.BlockTime().Add(time.Hour) + }, + expPass: false, }, { - suite: upgTests{}, - name: "successful overwrite", + name: "successful overwrite", plan: upgradetypes.Plan{ Name: "all-good", Info: "some text here", Height: 123450000, }, - setupUpgCond: func(simApp upgTests, plan *upgradetypes.Plan) { + setupUpgCond: func(simApp emAppTests, plan *upgradetypes.Plan) { - err := simApp.app.upgradeKeeper.ScheduleUpgrade(simApp.ctx, upgradetypes.Plan{ + _, err := simApp.app.authorityKeeper.ScheduleUpgrade(simApp.ctx, upgradetypes.Plan{ Name: "alt-good", Info: "new text here", Height: 543210000, @@ -171,15 +171,14 @@ func Test_ScheduleUpgrade(t *testing.T) { expPass: true, }, { - suite: upgTests{}, - name: "successful overwrite", + name: "successful overwrite future with earlier date", plan: upgradetypes.Plan{ Name: "all-good", Info: "some text here", Height: 123450000, }, - setupUpgCond: func(simApp upgTests, plan *upgradetypes.Plan) { - err := simApp.app.upgradeKeeper.ScheduleUpgrade(simApp.ctx, upgradetypes.Plan{ + setupUpgCond: func(simApp emAppTests, plan *upgradetypes.Plan) { + _, err := simApp.app.authorityKeeper.ScheduleUpgrade(simApp.ctx, upgradetypes.Plan{ Name: "alt-good", Info: "new text here", Height: 543210000, @@ -189,70 +188,69 @@ func Test_ScheduleUpgrade(t *testing.T) { expPass: true, }, { - suite: upgTests{}, - name: "successful IBC overwrite with non IBC plan", + name: "successful overwrite earlier with future date", plan: upgradetypes.Plan{ Name: "all-good", Info: "some text here", - Height: 123450000, + Height: 543210000, }, - setupUpgCond: func(simApp upgTests, plan *upgradetypes.Plan) { - err := simApp.app.upgradeKeeper.ScheduleUpgrade(simApp.ctx, upgradetypes.Plan{ + setupUpgCond: func(simApp emAppTests, plan *upgradetypes.Plan) { + _, err := simApp.app.authorityKeeper.ScheduleUpgrade(simApp.ctx, upgradetypes.Plan{ Name: "alt-good", Info: "new text here", - Height: 543210000, + Height: 123450000, }) require.NoError(t, err) }, expPass: true, }, { - suite: upgTests{}, - name: "unsuccessful schedule: invalid plan", + name: "unsuccessful schedule: missing plan name", plan: upgradetypes.Plan{ Height: 123450000, }, - setupUpgCond: func(simApp upgTests, plan *upgradetypes.Plan) {}, + setupUpgCond: func(simApp emAppTests, plan *upgradetypes.Plan) {}, expPass: false, }, { - suite: upgTests{}, - name: "unsuccessful time schedule: due date in past", + name: "unsuccessful time schedule: initialized, uninitialized due date in past", plan: upgradetypes.Plan{ Name: "all-good", Info: "some text here", }, - setupUpgCond: func(simApp upgTests, plan *upgradetypes.Plan) { + setupUpgCond: func(simApp emAppTests, plan *upgradetypes.Plan) { plan.Time = simApp.ctx.BlockTime() }, expPass: false, }, { - suite: upgTests{}, - name: "unsuccessful height schedule: due date in past", + name: "unsuccessful height schedule: due date in past", plan: upgradetypes.Plan{ Name: "all-good", Info: "some text here", Height: 1, }, - setupUpgCond: func(simApp upgTests, plan *upgradetypes.Plan) {}, + setupUpgCond: func(simApp emAppTests, plan *upgradetypes.Plan) {}, expPass: false, }, { - suite: upgTests{}, - name: "unsuccessful schedule: schedule already executed", + name: "unsuccessful schedule: schedule already executed", plan: upgradetypes.Plan{ Name: "all-good", Info: "some text here", Height: 123450000, }, - setupUpgCond: func(simApp upgTests, plan *upgradetypes.Plan) { - simApp.app.upgradeKeeper.SetUpgradeHandler("all-good", func(_ sdk.Context, _ upgradetypes.Plan) {}) - simApp.app.upgradeKeeper.ApplyUpgrade(simApp.ctx, upgradetypes.Plan{ - Name: "all-good", - Info: "some text here", - Height: 123450000, - }) + setupUpgCond: func(simEmApp emAppTests, plan *upgradetypes.Plan) { + simEmApp.app.upgradeKeeper.SetUpgradeHandler("all-good", func(_ sdk.Context, _ upgradetypes.Plan) {}) + _, err := simEmApp.app.authorityKeeper.ApplyUpgrade( + simEmApp.ctx, upgradetypes.Plan{ + Name: "all-good", + Info: "some text here", + Height: 123450000, + }) + if err != nil { + panic(err) + } }, expPass: false, }, @@ -260,16 +258,38 @@ func Test_ScheduleUpgrade(t *testing.T) { for _, tt := range tests { t.Run( tt.name, func(t *testing.T) { - tt.suite.initApp(t) + tt.suite = emAppTests{} + tt.suite.initEmApp(t) - // setupUpgCond test case + // setup test case tt.setupUpgCond(tt.suite, &tt.plan) - err := tt.suite.app.upgradeKeeper.ScheduleUpgrade(tt.suite.ctx, tt.plan) + // schedule upgrade plan + var err error + _, err = tt.suite.app.authorityKeeper.ScheduleUpgrade(tt.suite.ctx, tt.plan) + schedPlan, hasPlan := tt.suite.app.authorityKeeper.GetUpgradePlan(tt.suite.ctx) + + // validate plan side-effect + if tt.expPass { + require.Truef(t, hasPlan, "hasPlan: %t there should be a plan", hasPlan) + require.Equalf(t, schedPlan, tt.plan, "queried %v != %v", schedPlan, tt.plan) + } else { + require.Falsef(t, hasPlan, "hasPlan: %t plan should not exist", hasPlan) + require.NotEqualf(t, schedPlan, tt.plan, "queried %v == %v", schedPlan, tt.plan) + } + + // apply and confirm plan deletion + if err == nil { + tt.suite.app.upgradeKeeper.SetUpgradeHandler(tt.plan.Name, func(_ sdk.Context, _ upgradetypes.Plan) {}) + _, err = tt.suite.app.authorityKeeper.ApplyUpgrade(tt.suite.ctx, tt.plan) + schedPlan, hasPlan = tt.suite.app.authorityKeeper.GetUpgradePlan(tt.suite.ctx) + require.Falsef(t, hasPlan, "hasPlan: %t plan should not exist", hasPlan) + require.NotEqualf(t, schedPlan, tt.plan, "queried %v == %v", schedPlan, tt.plan) + } if (err != nil) == tt.expPass { t.Errorf( - "scheduleUpgrade() error = %v, expPass %v", err, tt.expPass, + "Upgrade() error = %v, expPass %v", err, tt.expPass, ) return } diff --git a/x/authority/keeper/keeper.go b/x/authority/keeper/keeper.go index 4e2c3357..3cdad7d3 100644 --- a/x/authority/keeper/keeper.go +++ b/x/authority/keeper/keeper.go @@ -216,7 +216,7 @@ func (k Keeper) replaceAuthority(ctx sdk.Context, authority, newAuthority sdk.Ac return &sdk.Result{Events: ctx.EventManager().ABCIEvents()}, nil } -func (k Keeper) scheduleUpgrade(ctx sdk.Context, plan upgradetypes.Plan) (*sdk.Result, error) { +func (k Keeper) ScheduleUpgrade(ctx sdk.Context, plan upgradetypes.Plan) (*sdk.Result, error) { if err := k.upgradeKeeper.ScheduleUpgrade(ctx, plan); err != nil { return nil, err } @@ -224,9 +224,14 @@ func (k Keeper) scheduleUpgrade(ctx sdk.Context, plan upgradetypes.Plan) (*sdk.R return &sdk.Result{Events: ctx.EventManager().ABCIEvents()}, nil } -func (k Keeper) applyUpgrade(ctx sdk.Context, plan upgradetypes.Plan) (*sdk.Result, error) { +func (k Keeper) ApplyUpgrade(ctx sdk.Context, plan upgradetypes.Plan) (*sdk.Result, error) { k.upgradeKeeper.ApplyUpgrade(ctx, plan) return &sdk.Result{Events: ctx.EventManager().ABCIEvents()}, nil } + +func (k Keeper) GetUpgradePlan(ctx sdk.Context) (plan upgradetypes.Plan, havePlan bool) { + + return k.upgradeKeeper.GetUpgradePlan(ctx) +} diff --git a/x/authority/keeper/msg_server.go b/x/authority/keeper/msg_server.go index d32cf641..cd8c03bd 100644 --- a/x/authority/keeper/msg_server.go +++ b/x/authority/keeper/msg_server.go @@ -17,8 +17,9 @@ type authorityKeeper interface { destroyIssuer(ctx sdk.Context, authority sdk.AccAddress, issuerAddress sdk.AccAddress) (*sdk.Result, error) replaceAuthority(ctx sdk.Context, authority, newAuthority sdk.AccAddress) (*sdk.Result, error) SetGasPrices(ctx sdk.Context, authority sdk.AccAddress, gasprices sdk.DecCoins) (*sdk.Result, error) - scheduleUpgrade(ctx sdk.Context, plan upgradetypes.Plan) (*sdk.Result, error) - applyUpgrade(ctx sdk.Context, plan upgradetypes.Plan) (*sdk.Result, error) + ScheduleUpgrade(ctx sdk.Context, plan upgradetypes.Plan) (*sdk.Result, error) + ApplyUpgrade(ctx sdk.Context, plan upgradetypes.Plan) (*sdk.Result, error) + GetUpgradePlan(ctx sdk.Context) (plan upgradetypes.Plan, havePlan bool) } type msgServer struct { k authorityKeeper @@ -119,7 +120,7 @@ func (m msgServer) ScheduleUpgrade( ctx := sdk.UnwrapSDKContext(goCtx) - result, err := m.k.scheduleUpgrade(ctx, upgrade.Plan) + result, err := m.k.ScheduleUpgrade(ctx, upgrade.Plan) if err != nil { return nil, err } diff --git a/x/authority/keeper/msg_server_test.go b/x/authority/keeper/msg_server_test.go index b3e123a4..4b4ecb1d 100644 --- a/x/authority/keeper/msg_server_test.go +++ b/x/authority/keeper/msg_server_test.go @@ -403,6 +403,7 @@ type authorityKeeperMock struct { SetGasPricesfn func(ctx sdk.Context, authority sdk.AccAddress, gasprices sdk.DecCoins) (*sdk.Result, error) replaceAuthorityfn func(ctx sdk.Context, authority, newAuthority sdk.AccAddress) (*sdk.Result, error) scheduleUpgradefn func(ctx sdk.Context, plan upgradetypes.Plan) (*sdk.Result, error) + getUpgradePlanfn func(ctx sdk.Context) (plan upgradetypes.Plan, havePlan bool) applyUpgradefn func(ctx sdk.Context, plan upgradetypes.Plan) (*sdk.Result, error) } @@ -435,7 +436,7 @@ func (a authorityKeeperMock) replaceAuthority(ctx sdk.Context, authority, newAut return a.replaceAuthorityfn(ctx, authority, newAuthority) } -func (a authorityKeeperMock) scheduleUpgrade(ctx sdk.Context, plan upgradetypes.Plan) (*sdk.Result, error) { +func (a authorityKeeperMock) ScheduleUpgrade(ctx sdk.Context, plan upgradetypes.Plan) (*sdk.Result, error) { if a.scheduleUpgradefn == nil { panic("not expected to be called") } @@ -443,7 +444,15 @@ func (a authorityKeeperMock) scheduleUpgrade(ctx sdk.Context, plan upgradetypes. return a.scheduleUpgradefn(ctx, plan) } -func (a authorityKeeperMock) applyUpgrade(ctx sdk.Context, plan upgradetypes.Plan) (*sdk.Result, error) { +func (a authorityKeeperMock) GetUpgradePlan(ctx sdk.Context) (plan upgradetypes.Plan, havePlan bool) { + if a.getUpgradePlanfn == nil { + panic("not expected to be called") + } + + return a.getUpgradePlanfn(ctx) +} + +func (a authorityKeeperMock) ApplyUpgrade(ctx sdk.Context, plan upgradetypes.Plan) (*sdk.Result, error) { if a.applyUpgradefn == nil { panic("not expected to be called") } From 35a2d737c3abf90a23796bd4e95fb40df74bff4f Mon Sep 17 00:00:00 2001 From: Mario Karagiorgas Date: Mon, 26 Jul 2021 17:48:41 +0300 Subject: [PATCH 13/49] Complete the API --- app_test.go | 65 +++-- docs/proto/em/proto-docs.md | 28 ++ proto/em/authority/v1/query.proto | 14 + x/authority/client/cli/query.go | 25 ++ x/authority/client/cli/tx.go | 75 ++++- x/authority/keeper/grpc_query.go | 12 + x/authority/keeper/grpc_query_test.go | 38 +++ x/authority/keeper/keeper.go | 15 +- x/authority/keeper/keeper_test.go | 1 + x/authority/keeper/msg_server.go | 30 +- x/authority/keeper/msg_server_test.go | 16 +- x/authority/types/query.pb.go | 384 ++++++++++++++++++++++++-- x/authority/types/query.pb.gw.go | 65 +++++ 13 files changed, 702 insertions(+), 66 deletions(-) diff --git a/app_test.go b/app_test.go index 072879e7..053be116 100644 --- a/app_test.go +++ b/app_test.go @@ -82,18 +82,20 @@ func (ao EmptyAppOptions) Get(o string) interface{} { } type emAppTests struct { - ctx sdk.Context - homeDir string - app *EMoneyApp + ctx sdk.Context + homeDir string + app *EMoneyApp + authority sdk.AccAddress } func (et *emAppTests) initEmApp(t *testing.T) { homeDir := filepath.Join(t.TempDir(), "x_upgrade_keeper_test") - authorityAddr, err := sdk.AccAddressFromBech32("emoney1kt0vh0ttget0xx77g6d3ttnvq2lnxx6vp3uyl0") + var err error + et.authority, err = sdk.AccAddressFromBech32("emoney1kt0vh0ttget0xx77g6d3ttnvq2lnxx6vp3uyl0") require.NoError(t, err) - _, _, app := getEmSimApp(t, authorityAddr) + _, _, app := getEmSimApp(t, et.authority) app.upgradeKeeper = upgradekeeper.NewKeeper( // recreate keeper in order to use a custom home path make(map[int64]bool), app.GetKey(upgradetypes.StoreKey), app.AppCodec(), homeDir, ) @@ -161,11 +163,13 @@ func Test_Upgrade(t *testing.T) { }, setupUpgCond: func(simApp emAppTests, plan *upgradetypes.Plan) { - _, err := simApp.app.authorityKeeper.ScheduleUpgrade(simApp.ctx, upgradetypes.Plan{ - Name: "alt-good", - Info: "new text here", - Height: 543210000, - }) + _, err := simApp.app.authorityKeeper.ScheduleUpgrade( + simApp.ctx, simApp.authority, upgradetypes.Plan{ + Name: "alt-good", + Info: "new text here", + Height: 543210000, + }, + ) require.NoError(t, err) }, expPass: true, @@ -178,11 +182,13 @@ func Test_Upgrade(t *testing.T) { Height: 123450000, }, setupUpgCond: func(simApp emAppTests, plan *upgradetypes.Plan) { - _, err := simApp.app.authorityKeeper.ScheduleUpgrade(simApp.ctx, upgradetypes.Plan{ - Name: "alt-good", - Info: "new text here", - Height: 543210000, - }) + _, err := simApp.app.authorityKeeper.ScheduleUpgrade( + simApp.ctx, simApp.authority, upgradetypes.Plan{ + Name: "alt-good", + Info: "new text here", + Height: 543210000, + }, + ) require.NoError(t, err) }, expPass: true, @@ -195,11 +201,13 @@ func Test_Upgrade(t *testing.T) { Height: 543210000, }, setupUpgCond: func(simApp emAppTests, plan *upgradetypes.Plan) { - _, err := simApp.app.authorityKeeper.ScheduleUpgrade(simApp.ctx, upgradetypes.Plan{ - Name: "alt-good", - Info: "new text here", - Height: 123450000, - }) + _, err := simApp.app.authorityKeeper.ScheduleUpgrade( + simApp.ctx, simApp.authority, upgradetypes.Plan{ + Name: "alt-good", + Info: "new text here", + Height: 123450000, + }, + ) require.NoError(t, err) }, expPass: true, @@ -243,14 +251,13 @@ func Test_Upgrade(t *testing.T) { setupUpgCond: func(simEmApp emAppTests, plan *upgradetypes.Plan) { simEmApp.app.upgradeKeeper.SetUpgradeHandler("all-good", func(_ sdk.Context, _ upgradetypes.Plan) {}) _, err := simEmApp.app.authorityKeeper.ApplyUpgrade( - simEmApp.ctx, upgradetypes.Plan{ + simEmApp.ctx, simEmApp.authority, upgradetypes.Plan{ Name: "all-good", Info: "some text here", Height: 123450000, - }) - if err != nil { - panic(err) - } + }, + ) + require.NoError(t, err) }, expPass: false, }, @@ -266,7 +273,9 @@ func Test_Upgrade(t *testing.T) { // schedule upgrade plan var err error - _, err = tt.suite.app.authorityKeeper.ScheduleUpgrade(tt.suite.ctx, tt.plan) + _, err = tt.suite.app.authorityKeeper.ScheduleUpgrade( + tt.suite.ctx, tt.suite.authority, tt.plan, + ) schedPlan, hasPlan := tt.suite.app.authorityKeeper.GetUpgradePlan(tt.suite.ctx) // validate plan side-effect @@ -281,7 +290,9 @@ func Test_Upgrade(t *testing.T) { // apply and confirm plan deletion if err == nil { tt.suite.app.upgradeKeeper.SetUpgradeHandler(tt.plan.Name, func(_ sdk.Context, _ upgradetypes.Plan) {}) - _, err = tt.suite.app.authorityKeeper.ApplyUpgrade(tt.suite.ctx, tt.plan) + _, err = tt.suite.app.authorityKeeper.ApplyUpgrade( + tt.suite.ctx, tt.suite.authority, tt.plan, + ) schedPlan, hasPlan = tt.suite.app.authorityKeeper.GetUpgradePlan(tt.suite.ctx) require.Falsef(t, hasPlan, "hasPlan: %t plan should not exist", hasPlan) require.NotEqualf(t, schedPlan, tt.plan, "queried %v == %v", schedPlan, tt.plan) diff --git a/docs/proto/em/proto-docs.md b/docs/proto/em/proto-docs.md index f18a9229..58c031cd 100644 --- a/docs/proto/em/proto-docs.md +++ b/docs/proto/em/proto-docs.md @@ -14,6 +14,8 @@ - [em/authority/v1/query.proto](#em/authority/v1/query.proto) - [QueryGasPricesRequest](#em.authority.v1.QueryGasPricesRequest) - [QueryGasPricesResponse](#em.authority.v1.QueryGasPricesResponse) + - [QueryUpgradePlanRequest](#em.authority.v1.QueryUpgradePlanRequest) + - [QueryUpgradePlanResponse](#em.authority.v1.QueryUpgradePlanResponse) - [Query](#em.authority.v1.Query) @@ -260,6 +262,31 @@ + + + +### QueryUpgradePlanRequest + + + + + + + + + +### QueryUpgradePlanResponse + + + +| Field | Type | Label | Description | +| ----- | ---- | ----- | ----------- | +| `plan` | [cosmos.upgrade.v1beta1.Plan](#cosmos.upgrade.v1beta1.Plan) | | | + + + + + @@ -275,6 +302,7 @@ | Method Name | Request Type | Response Type | Description | HTTP Verb | Endpoint | | ----------- | ------------ | ------------- | ------------| ------- | -------- | | `GasPrices` | [QueryGasPricesRequest](#em.authority.v1.QueryGasPricesRequest) | [QueryGasPricesResponse](#em.authority.v1.QueryGasPricesResponse) | | GET|/e-money/authority/v1/gasprices| +| `UpgradePlan` | [QueryUpgradePlanRequest](#em.authority.v1.QueryUpgradePlanRequest) | [QueryUpgradePlanResponse](#em.authority.v1.QueryUpgradePlanResponse) | | GET|/e-money/authority/v1/upgrade_plan| diff --git a/proto/em/authority/v1/query.proto b/proto/em/authority/v1/query.proto index e942eddf..9bacb134 100644 --- a/proto/em/authority/v1/query.proto +++ b/proto/em/authority/v1/query.proto @@ -4,6 +4,7 @@ package em.authority.v1; import "gogoproto/gogo.proto"; import "cosmos/base/v1beta1/coin.proto"; import "google/api/annotations.proto"; +import "cosmos/upgrade/v1beta1/upgrade.proto"; option go_package = "github.com/e-money/em-ledger/x/authority/types"; @@ -11,6 +12,10 @@ service Query { rpc GasPrices(QueryGasPricesRequest) returns (QueryGasPricesResponse) { option (google.api.http).get = "/e-money/authority/v1/gasprices"; }; + + rpc UpgradePlan(QueryUpgradePlanRequest) returns (QueryUpgradePlanResponse){ + option (google.api.http).get = "/e-money/authority/v1/upgrade_plan"; + } } message QueryGasPricesRequest {} @@ -24,3 +29,12 @@ message QueryGasPricesResponse { (gogoproto.nullable) = false ]; } + +message QueryUpgradePlanRequest {} + +message QueryUpgradePlanResponse { + cosmos.upgrade.v1beta1.Plan plan = 1 [ + (gogoproto.moretags) = "yaml:\"plan\"", + (gogoproto.nullable) = false + ]; +} \ No newline at end of file diff --git a/x/authority/client/cli/query.go b/x/authority/client/cli/query.go index b31faf9b..faeb6237 100644 --- a/x/authority/client/cli/query.go +++ b/x/authority/client/cli/query.go @@ -22,6 +22,7 @@ func GetQueryCmd() *cobra.Command { cmd.AddCommand( GetGasPricesCmd(), + GetUpgradePlanCmd(), ) return cmd @@ -50,3 +51,27 @@ func GetGasPricesCmd() *cobra.Command { flags.AddQueryFlagsToCmd(cmd) return cmd } + +func GetUpgradePlanCmd() *cobra.Command { + cmd := &cobra.Command{ + Use: "upg-plan", + Short: "Query the current upgrade plan", + Args: cobra.NoArgs, + RunE: func(cmd *cobra.Command, _ []string) error { + clientCtx, err := client.GetClientQueryContext(cmd) + if err != nil { + return err + } + + queryClient := types.NewQueryClient(clientCtx) + res, err := queryClient.UpgradePlan(cmd.Context(), &types.QueryUpgradePlanRequest{}) + if err != nil { + return err + } + + return clientCtx.PrintProto(res) + }, + } + flags.AddQueryFlagsToCmd(cmd) + return cmd +} diff --git a/x/authority/client/cli/tx.go b/x/authority/client/cli/tx.go index cde8ef69..f55cf833 100644 --- a/x/authority/client/cli/tx.go +++ b/x/authority/client/cli/tx.go @@ -32,6 +32,7 @@ func GetTxCmd() *cobra.Command { getCmdSetGasPrices(), GetCmdReplaceAuthority(), GetCmdScheduleUpgrade(), + GetCmdApplyUpgrade(), ) return authorityCmds @@ -196,7 +197,10 @@ func GetCmdScheduleUpgrade() *cobra.Command { Example: `emd tx schedule-upg emoney1n5ggspeff4fxc87dvmg0ematr3qzw5l4v20mdv 0.43 --upg_height 2001 emd tx schedule-upg emoney1n5ggspeff4fxc87dvmg0ematr3qzw5l4v20mdv 'New Staking Rewards 36%' --upg_time 1628956125 # Unix seconds for 2021-08-14 15:48:45 +0000 UTC emd tx schedule-upg emoney1n5ggspeff4fxc87dvmg0ematr3qzw5l4v20mdv sdk-v0.43.0 --upg_height 2001 --upg_info "https://e-money.com/mainnet-099-info.json?checksum=sha256:deaaa99fda9407c4dbe1d04bd49bab0cc3c1dd76fa392cd55a9425be074af01e"`, - Long: `Schedule a software upgrade.`, + Long: `Schedule a software upgrade by submitting a unique plan name that + has been used before with either an absolute block height or block time. An +upgrade handler should be defined at the upgraded binary. Optionally If you set DAEMON_ALLOW_DOWNLOAD_BINARIES=on pass +the upgraded binary download url with the --upg-info flag i.e., --upg-info 'https://example.com/testnet-1001-info.json?checksum=sha256:deaaa99fda9407c4dbe1d04bd49bab0cc3c1dd76fa392cd55a9425be074af01e'`, Args: cobra.ExactArgs(2), RunE: func(cmd *cobra.Command, args []string) error { err := cmd.Flags().Set(flags.FlagFrom, args[0]) @@ -247,6 +251,75 @@ emd tx schedule-upg emoney1n5ggspeff4fxc87dvmg0ematr3qzw5l4v20mdv sdk-v0.43.0 -- return cmd } +func GetCmdApplyUpgrade() *cobra.Command { + const ( + upgHeight = "upg-height" + upgTime = "upg-time" + upgInfo = "upg-info" + ) + + var ( + upgHeightVal, upgTimeSecsVal int64 + upgInfoVal string + ) + + cmd := &cobra.Command{ + Use: "upg-apply [authority_key_or_address] plan_name", + Short: "Apply a software upgrade.", + Example: `emd tx upg-apply emoney1n5ggspeff4fxc87dvmg0ematr3qzw5l4v20mdv 0.43 --upg_height 2001 +emd tx upg-apply emoney1n5ggspeff4fxc87dvmg0ematr3qzw5l4v20mdv 'New Staking Rewards 36%' --upg_time 1628956125 # Unix seconds for 2021-08-14 15:48:45 +0000 UTC +emd tx upg-apply emoney1n5ggspeff4fxc87dvmg0ematr3qzw5l4v20mdv sdk-v0.43.0 --upg_height 2001 --upg_info "https://e-money.com/mainnet-099-info.json?checksum=sha256:deaaa99fda9407c4dbe1d04bd49bab0cc3c1dd76fa392cd55a9425be074af01e"`, + Long: `Apply a software upgrade by submitting an already scheduled plan. An upgrade handler should have been submitted already.`, + Args: cobra.ExactArgs(2), + RunE: func(cmd *cobra.Command, args []string) error { + err := cmd.Flags().Set(flags.FlagFrom, args[0]) + if err != nil { + return err + } + + if err := validateUpgFlags( + upgHeight, upgHeightVal, upgTime, upgTimeSecsVal, + ); err != nil { + return err + } + + upgTimeVal := time.Unix(upgTimeSecsVal, 0) + + clientCtx, err := client.GetClientTxContext(cmd) + if err != nil { + return err + } + + msg := &types.MsgApplyUpgrade{ + Authority: clientCtx.GetFromAddress().String(), + Plan: upgtypes.Plan{ + Name: args[1], + Time: upgTimeVal, + Height: upgHeightVal, + Info: upgInfoVal, + }, + } + + if err := msg.ValidateBasic(); err != nil { + return err + } + + return tx.GenerateOrBroadcastTxCLI(clientCtx, cmd.Flags(), msg) + }, + } + f := cmd.Flags() + f.Int64VarP(&upgHeightVal, upgHeight, "n", 0, "upgrade block height number") + f.Int64VarP( + &upgTimeSecsVal, upgTime, "t", 0, "upgrade block time (in Unix seconds)", + ) + f.StringVarP( + &upgInfoVal, upgInfo, "i", "", "upgrade info", + ) + + flags.AddTxFlagsToCmd(cmd) + return cmd +} + func validateUpgFlags( upgHeight string, upgHeightVal int64, upgTime string, timeVal int64, ) error { diff --git a/x/authority/keeper/grpc_query.go b/x/authority/keeper/grpc_query.go index fb1823b9..541de1cb 100644 --- a/x/authority/keeper/grpc_query.go +++ b/x/authority/keeper/grpc_query.go @@ -2,6 +2,7 @@ package keeper import ( "context" + sdk "github.com/cosmos/cosmos-sdk/types" "github.com/e-money/em-ledger/x/authority/types" "google.golang.org/grpc/codes" @@ -18,3 +19,14 @@ func (k Keeper) GasPrices(c context.Context, req *types.QueryGasPricesRequest) ( gasPrices := k.GetGasPrices(ctx) return &types.QueryGasPricesResponse{MinGasPrices: gasPrices}, nil } + +func (k Keeper) UpgradePlan(c context.Context, req *types.QueryUpgradePlanRequest) (*types.QueryUpgradePlanResponse, error) { + if req == nil { + return nil, status.Error(codes.InvalidArgument, "empty request") + } + + ctx := sdk.UnwrapSDKContext(c) + plan, _ := k.GetUpgradePlan(ctx) + + return &types.QueryUpgradePlanResponse{Plan: plan}, nil +} diff --git a/x/authority/keeper/grpc_query_test.go b/x/authority/keeper/grpc_query_test.go index 4acd1267..4981718f 100644 --- a/x/authority/keeper/grpc_query_test.go +++ b/x/authority/keeper/grpc_query_test.go @@ -3,6 +3,8 @@ package keeper import ( "testing" + upgradetypes "github.com/cosmos/cosmos-sdk/x/upgrade/types" + "github.com/cosmos/cosmos-sdk/baseapp" sdk "github.com/cosmos/cosmos-sdk/types" "github.com/e-money/em-ledger/x/authority/types" @@ -41,3 +43,39 @@ func TestQueryGasPrices(t *testing.T) { }) } } + +func TestQueryUpgradePlan(t *testing.T) { + encConfig := MakeTestEncodingConfig() + ctx, keeper, _, _ := createTestComponentWithEncodingConfig(t, encConfig) + + authority := mustParseAddress("emoney1kt0vh0ttget0xx77g6d3ttnvq2lnxx6vp3uyl0") + keeper.BootstrapAuthority(ctx, authority) + + expPlan := upgradetypes.Plan{ + Name: "expPlan 8", + Height: 1000, + } + _, err := keeper.ScheduleUpgrade(ctx, authority, expPlan) + require.NoError(t, err) + + queryHelper := baseapp.NewQueryServerTestHelper(ctx, encConfig.InterfaceRegistry) + types.RegisterQueryServer(queryHelper, keeper) + queryClient := types.NewQueryClient(queryHelper) + + specs := map[string]struct { + req *types.QueryUpgradePlanRequest + }{ + "all good": { + req: &types.QueryUpgradePlanRequest{}, + }, + "nil param": {}, + } + for name, spec := range specs { + t.Run(name, func(t *testing.T) { + gotRsp, gotErr := queryClient.UpgradePlan(sdk.WrapSDKContext(ctx), spec.req) + require.NoError(t, gotErr) + require.NotNil(t, gotRsp) + assert.Equal(t, expPlan, gotRsp.Plan) + }) + } +} diff --git a/x/authority/keeper/keeper.go b/x/authority/keeper/keeper.go index 3cdad7d3..0dca9c87 100644 --- a/x/authority/keeper/keeper.go +++ b/x/authority/keeper/keeper.go @@ -216,7 +216,13 @@ func (k Keeper) replaceAuthority(ctx sdk.Context, authority, newAuthority sdk.Ac return &sdk.Result{Events: ctx.EventManager().ABCIEvents()}, nil } -func (k Keeper) ScheduleUpgrade(ctx sdk.Context, plan upgradetypes.Plan) (*sdk.Result, error) { +func (k Keeper) ScheduleUpgrade( + ctx sdk.Context, authority sdk.AccAddress, plan upgradetypes.Plan, +) (*sdk.Result, error) { + if err := k.ValidateAuthority(ctx, authority); err != nil { + return nil, err + } + if err := k.upgradeKeeper.ScheduleUpgrade(ctx, plan); err != nil { return nil, err } @@ -224,7 +230,12 @@ func (k Keeper) ScheduleUpgrade(ctx sdk.Context, plan upgradetypes.Plan) (*sdk.R return &sdk.Result{Events: ctx.EventManager().ABCIEvents()}, nil } -func (k Keeper) ApplyUpgrade(ctx sdk.Context, plan upgradetypes.Plan) (*sdk.Result, error) { +func (k Keeper) ApplyUpgrade( + ctx sdk.Context, authority sdk.AccAddress, plan upgradetypes.Plan, +) (*sdk.Result, error) { + if err := k.ValidateAuthority(ctx, authority); err != nil { + return nil, err + } k.upgradeKeeper.ApplyUpgrade(ctx, plan) diff --git a/x/authority/keeper/keeper_test.go b/x/authority/keeper/keeper_test.go index 0d04dd83..ac4250df 100644 --- a/x/authority/keeper/keeper_test.go +++ b/x/authority/keeper/keeper_test.go @@ -408,6 +408,7 @@ func createTestComponentWithEncodingConfig(t *testing.T, encConfig simappparams. ms.MountStoreWithDB(bankKey, sdk.StoreTypeIAVL, db) ms.MountStoreWithDB(keyIssuer, sdk.StoreTypeIAVL, db) ms.MountStoreWithDB(keyLp, sdk.StoreTypeIAVL, db) + ms.MountStoreWithDB(keyUpg, sdk.StoreTypeIAVL, db) err := ms.LoadLatestVersion() require.NoError(t, err) diff --git a/x/authority/keeper/msg_server.go b/x/authority/keeper/msg_server.go index cd8c03bd..212e1a2e 100644 --- a/x/authority/keeper/msg_server.go +++ b/x/authority/keeper/msg_server.go @@ -17,8 +17,8 @@ type authorityKeeper interface { destroyIssuer(ctx sdk.Context, authority sdk.AccAddress, issuerAddress sdk.AccAddress) (*sdk.Result, error) replaceAuthority(ctx sdk.Context, authority, newAuthority sdk.AccAddress) (*sdk.Result, error) SetGasPrices(ctx sdk.Context, authority sdk.AccAddress, gasprices sdk.DecCoins) (*sdk.Result, error) - ScheduleUpgrade(ctx sdk.Context, plan upgradetypes.Plan) (*sdk.Result, error) - ApplyUpgrade(ctx sdk.Context, plan upgradetypes.Plan) (*sdk.Result, error) + ScheduleUpgrade(ctx sdk.Context, authority sdk.AccAddress, plan upgradetypes.Plan) (*sdk.Result, error) + ApplyUpgrade(ctx sdk.Context, authority sdk.AccAddress, plan upgradetypes.Plan) (*sdk.Result, error) GetUpgradePlan(ctx sdk.Context) (plan upgradetypes.Plan, havePlan bool) } type msgServer struct { @@ -115,12 +115,17 @@ func (m msgServer) ReplaceAuthority(goCtx context.Context, msg *types.MsgReplace } func (m msgServer) ScheduleUpgrade( - goCtx context.Context, upgrade *types.MsgScheduleUpgrade, + goCtx context.Context, msg *types.MsgScheduleUpgrade, ) (*types.MsgScheduleUpgradeResponse, error) { ctx := sdk.UnwrapSDKContext(goCtx) - result, err := m.k.ScheduleUpgrade(ctx, upgrade.Plan) + authority, err := sdk.AccAddressFromBech32(msg.Authority) + if err != nil { + return nil, sdkerrors.Wrap(sdkerrors.ErrInvalidAddress, "authority") + } + + result, err := m.k.ScheduleUpgrade(ctx, authority, msg.Plan) if err != nil { return nil, err } @@ -133,8 +138,23 @@ func (m msgServer) ScheduleUpgrade( } func (m msgServer) ApplyUpgrade( - ctx context.Context, upgrade *types.MsgApplyUpgrade, + goCtx context.Context, msg *types.MsgApplyUpgrade, ) (*types.MsgApplyUpgradeResponse, error) { + ctx := sdk.UnwrapSDKContext(goCtx) + + authority, err := sdk.AccAddressFromBech32(msg.Authority) + if err != nil { + return nil, sdkerrors.Wrap(sdkerrors.ErrInvalidAddress, "authority") + } + + result, err := m.k.ApplyUpgrade(ctx, authority, msg.Plan) + if err != nil { + return nil, err + } + + for _, e := range result.Events { + ctx.EventManager().EmitEvent(sdk.Event(e)) + } return &types.MsgApplyUpgradeResponse{}, nil } diff --git a/x/authority/keeper/msg_server_test.go b/x/authority/keeper/msg_server_test.go index 4b4ecb1d..8bbc6d1b 100644 --- a/x/authority/keeper/msg_server_test.go +++ b/x/authority/keeper/msg_server_test.go @@ -402,9 +402,9 @@ type authorityKeeperMock struct { destroyIssuerfn func(ctx sdk.Context, authority sdk.AccAddress, issuerAddress sdk.AccAddress) (*sdk.Result, error) SetGasPricesfn func(ctx sdk.Context, authority sdk.AccAddress, gasprices sdk.DecCoins) (*sdk.Result, error) replaceAuthorityfn func(ctx sdk.Context, authority, newAuthority sdk.AccAddress) (*sdk.Result, error) - scheduleUpgradefn func(ctx sdk.Context, plan upgradetypes.Plan) (*sdk.Result, error) + scheduleUpgradefn func(ctx sdk.Context, authority sdk.AccAddress, plan upgradetypes.Plan) (*sdk.Result, error) getUpgradePlanfn func(ctx sdk.Context) (plan upgradetypes.Plan, havePlan bool) - applyUpgradefn func(ctx sdk.Context, plan upgradetypes.Plan) (*sdk.Result, error) + applyUpgradefn func(ctx sdk.Context, authority sdk.AccAddress, plan upgradetypes.Plan) (*sdk.Result, error) } func (a authorityKeeperMock) createIssuer(ctx sdk.Context, authority sdk.AccAddress, issuerAddress sdk.AccAddress, denoms []string) (*sdk.Result, error) { @@ -436,12 +436,14 @@ func (a authorityKeeperMock) replaceAuthority(ctx sdk.Context, authority, newAut return a.replaceAuthorityfn(ctx, authority, newAuthority) } -func (a authorityKeeperMock) ScheduleUpgrade(ctx sdk.Context, plan upgradetypes.Plan) (*sdk.Result, error) { +func (a authorityKeeperMock) ScheduleUpgrade( + ctx sdk.Context, authority sdk.AccAddress, plan upgradetypes.Plan, +) (*sdk.Result, error) { if a.scheduleUpgradefn == nil { panic("not expected to be called") } - return a.scheduleUpgradefn(ctx, plan) + return a.scheduleUpgradefn(ctx, authority, plan) } func (a authorityKeeperMock) GetUpgradePlan(ctx sdk.Context) (plan upgradetypes.Plan, havePlan bool) { @@ -452,10 +454,12 @@ func (a authorityKeeperMock) GetUpgradePlan(ctx sdk.Context) (plan upgradetypes. return a.getUpgradePlanfn(ctx) } -func (a authorityKeeperMock) ApplyUpgrade(ctx sdk.Context, plan upgradetypes.Plan) (*sdk.Result, error) { +func (a authorityKeeperMock) ApplyUpgrade( + ctx sdk.Context, authority sdk.AccAddress, plan upgradetypes.Plan, +) (*sdk.Result, error) { if a.applyUpgradefn == nil { panic("not expected to be called") } - return a.applyUpgradefn(ctx, plan) + return a.applyUpgradefn(ctx, authority, plan) } diff --git a/x/authority/types/query.pb.go b/x/authority/types/query.pb.go index a2c00546..0c7c15e3 100644 --- a/x/authority/types/query.pb.go +++ b/x/authority/types/query.pb.go @@ -8,6 +8,7 @@ import ( fmt "fmt" github_com_cosmos_cosmos_sdk_types "github.com/cosmos/cosmos-sdk/types" types "github.com/cosmos/cosmos-sdk/types" + types1 "github.com/cosmos/cosmos-sdk/x/upgrade/types" _ "github.com/gogo/protobuf/gogoproto" grpc1 "github.com/gogo/protobuf/grpc" proto "github.com/gogo/protobuf/proto" @@ -110,39 +111,127 @@ func (m *QueryGasPricesResponse) GetMinGasPrices() github_com_cosmos_cosmos_sdk_ return nil } +type QueryUpgradePlanRequest struct { +} + +func (m *QueryUpgradePlanRequest) Reset() { *m = QueryUpgradePlanRequest{} } +func (m *QueryUpgradePlanRequest) String() string { return proto.CompactTextString(m) } +func (*QueryUpgradePlanRequest) ProtoMessage() {} +func (*QueryUpgradePlanRequest) Descriptor() ([]byte, []int) { + return fileDescriptor_d766145e8bc7b365, []int{2} +} +func (m *QueryUpgradePlanRequest) XXX_Unmarshal(b []byte) error { + return m.Unmarshal(b) +} +func (m *QueryUpgradePlanRequest) XXX_Marshal(b []byte, deterministic bool) ([]byte, error) { + if deterministic { + return xxx_messageInfo_QueryUpgradePlanRequest.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 *QueryUpgradePlanRequest) XXX_Merge(src proto.Message) { + xxx_messageInfo_QueryUpgradePlanRequest.Merge(m, src) +} +func (m *QueryUpgradePlanRequest) XXX_Size() int { + return m.Size() +} +func (m *QueryUpgradePlanRequest) XXX_DiscardUnknown() { + xxx_messageInfo_QueryUpgradePlanRequest.DiscardUnknown(m) +} + +var xxx_messageInfo_QueryUpgradePlanRequest proto.InternalMessageInfo + +type QueryUpgradePlanResponse struct { + Plan types1.Plan `protobuf:"bytes,1,opt,name=plan,proto3" json:"plan" yaml:"plan"` +} + +func (m *QueryUpgradePlanResponse) Reset() { *m = QueryUpgradePlanResponse{} } +func (m *QueryUpgradePlanResponse) String() string { return proto.CompactTextString(m) } +func (*QueryUpgradePlanResponse) ProtoMessage() {} +func (*QueryUpgradePlanResponse) Descriptor() ([]byte, []int) { + return fileDescriptor_d766145e8bc7b365, []int{3} +} +func (m *QueryUpgradePlanResponse) XXX_Unmarshal(b []byte) error { + return m.Unmarshal(b) +} +func (m *QueryUpgradePlanResponse) XXX_Marshal(b []byte, deterministic bool) ([]byte, error) { + if deterministic { + return xxx_messageInfo_QueryUpgradePlanResponse.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 *QueryUpgradePlanResponse) XXX_Merge(src proto.Message) { + xxx_messageInfo_QueryUpgradePlanResponse.Merge(m, src) +} +func (m *QueryUpgradePlanResponse) XXX_Size() int { + return m.Size() +} +func (m *QueryUpgradePlanResponse) XXX_DiscardUnknown() { + xxx_messageInfo_QueryUpgradePlanResponse.DiscardUnknown(m) +} + +var xxx_messageInfo_QueryUpgradePlanResponse proto.InternalMessageInfo + +func (m *QueryUpgradePlanResponse) GetPlan() types1.Plan { + if m != nil { + return m.Plan + } + return types1.Plan{} +} + func init() { proto.RegisterType((*QueryGasPricesRequest)(nil), "em.authority.v1.QueryGasPricesRequest") proto.RegisterType((*QueryGasPricesResponse)(nil), "em.authority.v1.QueryGasPricesResponse") + proto.RegisterType((*QueryUpgradePlanRequest)(nil), "em.authority.v1.QueryUpgradePlanRequest") + proto.RegisterType((*QueryUpgradePlanResponse)(nil), "em.authority.v1.QueryUpgradePlanResponse") } func init() { proto.RegisterFile("em/authority/v1/query.proto", fileDescriptor_d766145e8bc7b365) } var fileDescriptor_d766145e8bc7b365 = []byte{ - // 379 bytes of a gzipped FileDescriptorProto - 0x1f, 0x8b, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0xff, 0x84, 0x91, 0xbf, 0x8b, 0x13, 0x41, - 0x14, 0xc7, 0x77, 0xfc, 0x05, 0xae, 0xa2, 0xb0, 0x18, 0x95, 0x18, 0x76, 0x75, 0x0b, 0x23, 0x48, - 0x66, 0xd8, 0xd8, 0xa5, 0x8c, 0x82, 0x16, 0x16, 0x9a, 0xd2, 0x26, 0xcc, 0x6e, 0x1e, 0x93, 0xc1, - 0xcc, 0xbc, 0xcd, 0xce, 0x6c, 0x70, 0x5b, 0xc1, 0xda, 0x80, 0x8d, 0xa5, 0xb5, 0x9d, 0xff, 0x45, - 0xca, 0x80, 0xcd, 0x55, 0xb9, 0x23, 0xb9, 0xbf, 0xe0, 0xfe, 0x82, 0x23, 0xbb, 0x49, 0x48, 0xc2, - 0xc1, 0x55, 0xbb, 0xf0, 0x79, 0x7c, 0xe7, 0xfb, 0x79, 0xcf, 0x7d, 0x06, 0x8a, 0xf1, 0xdc, 0x0e, - 0x31, 0x93, 0xb6, 0x60, 0x93, 0x88, 0x8d, 0x73, 0xc8, 0x0a, 0x9a, 0x66, 0x68, 0xd1, 0x7b, 0x08, - 0x8a, 0xee, 0x20, 0x9d, 0x44, 0xf5, 0x47, 0x02, 0x05, 0x96, 0x8c, 0xad, 0xff, 0xaa, 0xb1, 0xba, - 0x9f, 0xa0, 0x51, 0x68, 0x58, 0xcc, 0x0d, 0xb0, 0x49, 0x14, 0x83, 0xe5, 0x11, 0x4b, 0x50, 0xea, - 0x0d, 0x6f, 0x08, 0x44, 0x31, 0x02, 0xc6, 0x53, 0xc9, 0xb8, 0xd6, 0x68, 0xb9, 0x95, 0xa8, 0x4d, - 0x45, 0xc3, 0x27, 0x6e, 0xed, 0xf3, 0xfa, 0xcd, 0xf7, 0xdc, 0x7c, 0xca, 0x64, 0x02, 0xa6, 0x07, - 0xe3, 0x1c, 0x8c, 0x0d, 0xff, 0x11, 0xf7, 0xf1, 0x31, 0x31, 0x29, 0x6a, 0x03, 0xde, 0x94, 0xb8, - 0x0f, 0x94, 0xd4, 0x7d, 0xc1, 0x4d, 0x3f, 0x2d, 0xd1, 0x53, 0xf2, 0xfc, 0xe6, 0xab, 0x7b, 0xed, - 0x06, 0xad, 0xba, 0xd0, 0x75, 0x17, 0xba, 0xe9, 0x42, 0xdf, 0x41, 0xf2, 0x16, 0xa5, 0xee, 0x7e, - 0x9c, 0x2d, 0x02, 0xe7, 0x62, 0x11, 0xd4, 0x0a, 0xae, 0x46, 0x9d, 0xf0, 0x30, 0x21, 0xfc, 0x7b, - 0x1a, 0xbc, 0x16, 0xd2, 0x0e, 0xf3, 0x98, 0x26, 0xa8, 0xd8, 0x46, 0xaa, 0xfa, 0xb4, 0xcc, 0xe0, - 0x2b, 0xb3, 0x45, 0x0a, 0x66, 0x1b, 0x66, 0x7a, 0xf7, 0x95, 0xd4, 0xbb, 0x6a, 0x9d, 0x5b, 0xbf, - 0xff, 0x04, 0x4e, 0xfb, 0x27, 0x71, 0x6f, 0x97, 0x9d, 0xbd, 0x1f, 0xc4, 0xbd, 0xbb, 0xa3, 0xde, - 0x4b, 0x7a, 0xb4, 0x4a, 0x7a, 0xa5, 0x73, 0xbd, 0x79, 0xed, 0x5c, 0xb5, 0x81, 0xb0, 0xf9, 0xfd, - 0xff, 0xf9, 0xaf, 0x1b, 0x2f, 0xbc, 0x80, 0x41, 0x4b, 0xa1, 0x86, 0xe2, 0xf0, 0x8a, 0x82, 0x9b, - 0xca, 0xaa, 0xfb, 0x61, 0xb6, 0xf4, 0xc9, 0x7c, 0xe9, 0x93, 0xb3, 0xa5, 0x4f, 0xa6, 0x2b, 0xdf, - 0x99, 0xaf, 0x7c, 0xe7, 0x64, 0xe5, 0x3b, 0x5f, 0xe8, 0x9e, 0xec, 0x36, 0x04, 0x54, 0x6b, 0x04, - 0x03, 0x01, 0x19, 0xfb, 0xb6, 0x17, 0x58, 0x8a, 0xc7, 0x77, 0xca, 0x7b, 0xbd, 0xb9, 0x0c, 0x00, - 0x00, 0xff, 0xff, 0x25, 0x0c, 0xa6, 0x7e, 0x33, 0x02, 0x00, 0x00, + // 478 bytes of a gzipped FileDescriptorProto + 0x1f, 0x8b, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0xff, 0x8c, 0x92, 0x3f, 0x6f, 0xd3, 0x40, + 0x18, 0xc6, 0x7d, 0xa5, 0x20, 0x71, 0x45, 0x20, 0x19, 0x4a, 0x43, 0xa8, 0xec, 0x62, 0x55, 0xb4, + 0x80, 0x72, 0xa7, 0x94, 0xad, 0x63, 0x00, 0xc1, 0xc0, 0x50, 0x22, 0xb1, 0xb0, 0x44, 0x17, 0xe7, + 0xd5, 0xf5, 0x84, 0xef, 0xce, 0xf5, 0x9d, 0x23, 0xbc, 0x22, 0xb1, 0xa2, 0x4a, 0x2c, 0x8c, 0x9d, + 0xd9, 0xf8, 0x16, 0x1d, 0x2b, 0xb1, 0x30, 0x15, 0x94, 0xf0, 0x09, 0xf8, 0x04, 0xc8, 0xf6, 0x39, + 0xa4, 0x6d, 0x24, 0x98, 0x12, 0xeb, 0x79, 0xff, 0xfc, 0x9e, 0xe7, 0x5e, 0x7c, 0x17, 0x24, 0x65, + 0xb9, 0xdd, 0xd7, 0x99, 0xb0, 0x05, 0x1d, 0x77, 0xe9, 0x41, 0x0e, 0x59, 0x41, 0xd2, 0x4c, 0x5b, + 0xed, 0xdf, 0x00, 0x49, 0x66, 0x22, 0x19, 0x77, 0xdb, 0xb7, 0xb8, 0xe6, 0xba, 0xd2, 0x68, 0xf9, + 0xaf, 0x2e, 0x6b, 0x07, 0xb1, 0x36, 0x52, 0x1b, 0x3a, 0x64, 0x06, 0xe8, 0xb8, 0x3b, 0x04, 0xcb, + 0xba, 0x34, 0xd6, 0x42, 0x39, 0x7d, 0x9d, 0x6b, 0xcd, 0x13, 0xa0, 0x2c, 0x15, 0x94, 0x29, 0xa5, + 0x2d, 0xb3, 0x42, 0x2b, 0xe3, 0xd4, 0x4d, 0xd7, 0x9d, 0xa7, 0x3c, 0x63, 0xa3, 0xbf, 0x03, 0xdc, + 0x77, 0x5d, 0x15, 0xad, 0xe1, 0xd5, 0x57, 0x25, 0xd9, 0x73, 0x66, 0xf6, 0x32, 0x11, 0x83, 0xe9, + 0xc3, 0x41, 0x0e, 0xc6, 0x46, 0x5f, 0x11, 0xbe, 0x7d, 0x5e, 0x31, 0xa9, 0x56, 0x06, 0xfc, 0x43, + 0x84, 0xaf, 0x4b, 0xa1, 0x06, 0x9c, 0x99, 0x41, 0x5a, 0x49, 0x2d, 0xb4, 0x71, 0x69, 0x7b, 0x65, + 0x67, 0x9d, 0xd4, 0x3b, 0x49, 0x49, 0x4c, 0xdc, 0x42, 0xf2, 0x14, 0xe2, 0x27, 0x5a, 0xa8, 0xde, + 0xcb, 0xe3, 0xd3, 0xd0, 0xfb, 0x7d, 0x1a, 0xae, 0x16, 0x4c, 0x26, 0xbb, 0xd1, 0xd9, 0x09, 0xd1, + 0x97, 0x1f, 0xe1, 0x23, 0x2e, 0xec, 0x7e, 0x3e, 0x24, 0xb1, 0x96, 0xd4, 0xc1, 0xd7, 0x3f, 0x1d, + 0x33, 0x7a, 0x4b, 0x6d, 0x91, 0x82, 0x69, 0x86, 0x99, 0xfe, 0x35, 0x29, 0xd4, 0x0c, 0x6d, 0x77, + 0xf9, 0xf3, 0x51, 0xe8, 0x45, 0x77, 0xf0, 0x5a, 0x85, 0xfc, 0xba, 0xb6, 0xb8, 0x97, 0x30, 0xd5, + 0xd8, 0x61, 0xb8, 0x75, 0x51, 0x72, 0x7e, 0x9e, 0xe1, 0xe5, 0x34, 0x61, 0xaa, 0x85, 0x36, 0xd0, + 0xbc, 0x89, 0x26, 0xa8, 0xc6, 0x47, 0xd9, 0xd3, 0xbb, 0xe9, 0x4c, 0xac, 0xd4, 0x26, 0xca, 0xbe, + 0xa8, 0x5f, 0xb5, 0xef, 0x1c, 0x2d, 0xe1, 0xcb, 0xd5, 0x0e, 0xff, 0x03, 0xc2, 0x57, 0x67, 0x6c, + 0xfe, 0x7d, 0x72, 0xee, 0xb9, 0xc9, 0xc2, 0xc4, 0xdb, 0x5b, 0xff, 0xac, 0xab, 0x79, 0xa3, 0xad, + 0xf7, 0xdf, 0x7e, 0x7d, 0x5a, 0xba, 0xe7, 0x87, 0x14, 0x3a, 0x52, 0x2b, 0x28, 0xce, 0x5e, 0x1a, + 0x67, 0xa6, 0xce, 0xd4, 0xff, 0x88, 0xf0, 0xca, 0x9c, 0x61, 0x7f, 0x7b, 0xf1, 0x86, 0x8b, 0x71, + 0xb5, 0x1f, 0xfc, 0x47, 0xa5, 0xa3, 0x79, 0x58, 0xd1, 0x6c, 0xfa, 0xd1, 0x62, 0x1a, 0x97, 0xe2, + 0xa0, 0x8c, 0xa8, 0xf7, 0xe2, 0x78, 0x12, 0xa0, 0x93, 0x49, 0x80, 0x7e, 0x4e, 0x02, 0x74, 0x38, + 0x0d, 0xbc, 0x93, 0x69, 0xe0, 0x7d, 0x9f, 0x06, 0xde, 0x1b, 0x32, 0xf7, 0xf6, 0xcd, 0x1c, 0x90, + 0x9d, 0x04, 0x46, 0x1c, 0x32, 0xfa, 0x6e, 0x6e, 0x66, 0x75, 0x07, 0xc3, 0x2b, 0xd5, 0xf9, 0x3e, + 0xfe, 0x13, 0x00, 0x00, 0xff, 0xff, 0x6b, 0x52, 0x20, 0x32, 0x68, 0x03, 0x00, 0x00, } // Reference imports to suppress errors if they are not otherwise used. @@ -158,6 +247,7 @@ const _ = grpc.SupportPackageIsVersion4 // For semantics around ctx use and closing/ending streaming RPCs, please refer to https://godoc.org/google.golang.org/grpc#ClientConn.NewStream. type QueryClient interface { GasPrices(ctx context.Context, in *QueryGasPricesRequest, opts ...grpc.CallOption) (*QueryGasPricesResponse, error) + UpgradePlan(ctx context.Context, in *QueryUpgradePlanRequest, opts ...grpc.CallOption) (*QueryUpgradePlanResponse, error) } type queryClient struct { @@ -177,9 +267,19 @@ func (c *queryClient) GasPrices(ctx context.Context, in *QueryGasPricesRequest, return out, nil } +func (c *queryClient) UpgradePlan(ctx context.Context, in *QueryUpgradePlanRequest, opts ...grpc.CallOption) (*QueryUpgradePlanResponse, error) { + out := new(QueryUpgradePlanResponse) + err := c.cc.Invoke(ctx, "/em.authority.v1.Query/UpgradePlan", in, out, opts...) + if err != nil { + return nil, err + } + return out, nil +} + // QueryServer is the server API for Query service. type QueryServer interface { GasPrices(context.Context, *QueryGasPricesRequest) (*QueryGasPricesResponse, error) + UpgradePlan(context.Context, *QueryUpgradePlanRequest) (*QueryUpgradePlanResponse, error) } // UnimplementedQueryServer can be embedded to have forward compatible implementations. @@ -189,6 +289,9 @@ type UnimplementedQueryServer struct { func (*UnimplementedQueryServer) GasPrices(ctx context.Context, req *QueryGasPricesRequest) (*QueryGasPricesResponse, error) { return nil, status.Errorf(codes.Unimplemented, "method GasPrices not implemented") } +func (*UnimplementedQueryServer) UpgradePlan(ctx context.Context, req *QueryUpgradePlanRequest) (*QueryUpgradePlanResponse, error) { + return nil, status.Errorf(codes.Unimplemented, "method UpgradePlan not implemented") +} func RegisterQueryServer(s grpc1.Server, srv QueryServer) { s.RegisterService(&_Query_serviceDesc, srv) @@ -212,6 +315,24 @@ func _Query_GasPrices_Handler(srv interface{}, ctx context.Context, dec func(int return interceptor(ctx, in, info, handler) } +func _Query_UpgradePlan_Handler(srv interface{}, ctx context.Context, dec func(interface{}) error, interceptor grpc.UnaryServerInterceptor) (interface{}, error) { + in := new(QueryUpgradePlanRequest) + if err := dec(in); err != nil { + return nil, err + } + if interceptor == nil { + return srv.(QueryServer).UpgradePlan(ctx, in) + } + info := &grpc.UnaryServerInfo{ + Server: srv, + FullMethod: "/em.authority.v1.Query/UpgradePlan", + } + handler := func(ctx context.Context, req interface{}) (interface{}, error) { + return srv.(QueryServer).UpgradePlan(ctx, req.(*QueryUpgradePlanRequest)) + } + return interceptor(ctx, in, info, handler) +} + var _Query_serviceDesc = grpc.ServiceDesc{ ServiceName: "em.authority.v1.Query", HandlerType: (*QueryServer)(nil), @@ -220,6 +341,10 @@ var _Query_serviceDesc = grpc.ServiceDesc{ MethodName: "GasPrices", Handler: _Query_GasPrices_Handler, }, + { + MethodName: "UpgradePlan", + Handler: _Query_UpgradePlan_Handler, + }, }, Streams: []grpc.StreamDesc{}, Metadata: "em/authority/v1/query.proto", @@ -285,6 +410,62 @@ func (m *QueryGasPricesResponse) MarshalToSizedBuffer(dAtA []byte) (int, error) return len(dAtA) - i, nil } +func (m *QueryUpgradePlanRequest) 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 *QueryUpgradePlanRequest) MarshalTo(dAtA []byte) (int, error) { + size := m.Size() + return m.MarshalToSizedBuffer(dAtA[:size]) +} + +func (m *QueryUpgradePlanRequest) MarshalToSizedBuffer(dAtA []byte) (int, error) { + i := len(dAtA) + _ = i + var l int + _ = l + return len(dAtA) - i, nil +} + +func (m *QueryUpgradePlanResponse) 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 *QueryUpgradePlanResponse) MarshalTo(dAtA []byte) (int, error) { + size := m.Size() + return m.MarshalToSizedBuffer(dAtA[:size]) +} + +func (m *QueryUpgradePlanResponse) MarshalToSizedBuffer(dAtA []byte) (int, error) { + i := len(dAtA) + _ = i + var l int + _ = l + { + size, err := m.Plan.MarshalToSizedBuffer(dAtA[:i]) + if err != nil { + return 0, err + } + i -= size + i = encodeVarintQuery(dAtA, i, uint64(size)) + } + i-- + dAtA[i] = 0xa + return len(dAtA) - i, nil +} + func encodeVarintQuery(dAtA []byte, offset int, v uint64) int { offset -= sovQuery(v) base := offset @@ -320,6 +501,26 @@ func (m *QueryGasPricesResponse) Size() (n int) { return n } +func (m *QueryUpgradePlanRequest) Size() (n int) { + if m == nil { + return 0 + } + var l int + _ = l + return n +} + +func (m *QueryUpgradePlanResponse) Size() (n int) { + if m == nil { + return 0 + } + var l int + _ = l + l = m.Plan.Size() + n += 1 + l + sovQuery(uint64(l)) + return n +} + func sovQuery(x uint64) (n int) { return (math_bits.Len64(x|1) + 6) / 7 } @@ -460,6 +661,139 @@ func (m *QueryGasPricesResponse) Unmarshal(dAtA []byte) error { } return nil } +func (m *QueryUpgradePlanRequest) 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 ErrIntOverflowQuery + } + 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: QueryUpgradePlanRequest: wiretype end group for non-group") + } + if fieldNum <= 0 { + return fmt.Errorf("proto: QueryUpgradePlanRequest: illegal tag %d (wire type %d)", fieldNum, wire) + } + switch fieldNum { + default: + iNdEx = preIndex + skippy, err := skipQuery(dAtA[iNdEx:]) + if err != nil { + return err + } + if (skippy < 0) || (iNdEx+skippy) < 0 { + return ErrInvalidLengthQuery + } + if (iNdEx + skippy) > l { + return io.ErrUnexpectedEOF + } + iNdEx += skippy + } + } + + if iNdEx > l { + return io.ErrUnexpectedEOF + } + return nil +} +func (m *QueryUpgradePlanResponse) 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 ErrIntOverflowQuery + } + 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: QueryUpgradePlanResponse: wiretype end group for non-group") + } + if fieldNum <= 0 { + return fmt.Errorf("proto: QueryUpgradePlanResponse: illegal tag %d (wire type %d)", fieldNum, wire) + } + switch fieldNum { + case 1: + if wireType != 2 { + return fmt.Errorf("proto: wrong wireType = %d for field Plan", wireType) + } + var msglen int + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowQuery + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + msglen |= int(b&0x7F) << shift + if b < 0x80 { + break + } + } + if msglen < 0 { + return ErrInvalidLengthQuery + } + postIndex := iNdEx + msglen + if postIndex < 0 { + return ErrInvalidLengthQuery + } + if postIndex > l { + return io.ErrUnexpectedEOF + } + if err := m.Plan.Unmarshal(dAtA[iNdEx:postIndex]); err != nil { + return err + } + iNdEx = postIndex + default: + iNdEx = preIndex + skippy, err := skipQuery(dAtA[iNdEx:]) + if err != nil { + return err + } + if (skippy < 0) || (iNdEx+skippy) < 0 { + return ErrInvalidLengthQuery + } + if (iNdEx + skippy) > l { + return io.ErrUnexpectedEOF + } + iNdEx += skippy + } + } + + if iNdEx > l { + return io.ErrUnexpectedEOF + } + return nil +} func skipQuery(dAtA []byte) (n int, err error) { l := len(dAtA) iNdEx := 0 diff --git a/x/authority/types/query.pb.gw.go b/x/authority/types/query.pb.gw.go index d0945e5a..56e60801 100644 --- a/x/authority/types/query.pb.gw.go +++ b/x/authority/types/query.pb.gw.go @@ -51,6 +51,24 @@ func local_request_Query_GasPrices_0(ctx context.Context, marshaler runtime.Mars } +func request_Query_UpgradePlan_0(ctx context.Context, marshaler runtime.Marshaler, client QueryClient, req *http.Request, pathParams map[string]string) (proto.Message, runtime.ServerMetadata, error) { + var protoReq QueryUpgradePlanRequest + var metadata runtime.ServerMetadata + + msg, err := client.UpgradePlan(ctx, &protoReq, grpc.Header(&metadata.HeaderMD), grpc.Trailer(&metadata.TrailerMD)) + return msg, metadata, err + +} + +func local_request_Query_UpgradePlan_0(ctx context.Context, marshaler runtime.Marshaler, server QueryServer, req *http.Request, pathParams map[string]string) (proto.Message, runtime.ServerMetadata, error) { + var protoReq QueryUpgradePlanRequest + var metadata runtime.ServerMetadata + + msg, err := server.UpgradePlan(ctx, &protoReq) + return msg, metadata, err + +} + // RegisterQueryHandlerServer registers the http handlers for service Query to "mux". // UnaryRPC :call QueryServer directly. // StreamingRPC :currently unsupported pending https://github.com/grpc/grpc-go/issues/906. @@ -80,6 +98,29 @@ func RegisterQueryHandlerServer(ctx context.Context, mux *runtime.ServeMux, serv }) + mux.Handle("GET", pattern_Query_UpgradePlan_0, func(w http.ResponseWriter, req *http.Request, pathParams map[string]string) { + ctx, cancel := context.WithCancel(req.Context()) + defer cancel() + var stream runtime.ServerTransportStream + ctx = grpc.NewContextWithServerTransportStream(ctx, &stream) + inboundMarshaler, outboundMarshaler := runtime.MarshalerForRequest(mux, req) + rctx, err := runtime.AnnotateIncomingContext(ctx, mux, req) + if err != nil { + runtime.HTTPError(ctx, mux, outboundMarshaler, w, req, err) + return + } + resp, md, err := local_request_Query_UpgradePlan_0(rctx, inboundMarshaler, server, req, pathParams) + md.HeaderMD, md.TrailerMD = metadata.Join(md.HeaderMD, stream.Header()), metadata.Join(md.TrailerMD, stream.Trailer()) + ctx = runtime.NewServerMetadataContext(ctx, md) + if err != nil { + runtime.HTTPError(ctx, mux, outboundMarshaler, w, req, err) + return + } + + forward_Query_UpgradePlan_0(ctx, mux, outboundMarshaler, w, req, resp, mux.GetForwardResponseOptions()...) + + }) + return nil } @@ -141,13 +182,37 @@ func RegisterQueryHandlerClient(ctx context.Context, mux *runtime.ServeMux, clie }) + mux.Handle("GET", pattern_Query_UpgradePlan_0, func(w http.ResponseWriter, req *http.Request, pathParams map[string]string) { + ctx, cancel := context.WithCancel(req.Context()) + defer cancel() + inboundMarshaler, outboundMarshaler := runtime.MarshalerForRequest(mux, req) + rctx, err := runtime.AnnotateContext(ctx, mux, req) + if err != nil { + runtime.HTTPError(ctx, mux, outboundMarshaler, w, req, err) + return + } + resp, md, err := request_Query_UpgradePlan_0(rctx, inboundMarshaler, client, req, pathParams) + ctx = runtime.NewServerMetadataContext(ctx, md) + if err != nil { + runtime.HTTPError(ctx, mux, outboundMarshaler, w, req, err) + return + } + + forward_Query_UpgradePlan_0(ctx, mux, outboundMarshaler, w, req, resp, mux.GetForwardResponseOptions()...) + + }) + return nil } var ( pattern_Query_GasPrices_0 = runtime.MustPattern(runtime.NewPattern(1, []int{2, 0, 2, 1, 2, 2, 2, 3}, []string{"e-money", "authority", "v1", "gasprices"}, "", runtime.AssumeColonVerbOpt(true))) + + pattern_Query_UpgradePlan_0 = runtime.MustPattern(runtime.NewPattern(1, []int{2, 0, 2, 1, 2, 2, 2, 3}, []string{"e-money", "authority", "v1", "upgrade_plan"}, "", runtime.AssumeColonVerbOpt(true))) ) var ( forward_Query_GasPrices_0 = runtime.ForwardResponseMessage + + forward_Query_UpgradePlan_0 = runtime.ForwardResponseMessage ) From d3b95e676a61de6d9bf5a26b8b6108c0dd1d0e37 Mon Sep 17 00:00:00 2001 From: Mario Karagiorgas Date: Mon, 26 Jul 2021 19:06:38 +0300 Subject: [PATCH 14/49] Fix app test and remove 2nd upg keeper creation --- app_test.go | 28 ++++++++++++++-------------- 1 file changed, 14 insertions(+), 14 deletions(-) diff --git a/app_test.go b/app_test.go index 053be116..693645c4 100644 --- a/app_test.go +++ b/app_test.go @@ -3,12 +3,9 @@ package emoney import ( "encoding/json" "os" - "path/filepath" "testing" "time" - upgradekeeper "github.com/cosmos/cosmos-sdk/x/upgrade/keeper" - apptypes "github.com/e-money/em-ledger/types" sdk "github.com/cosmos/cosmos-sdk/types" @@ -23,7 +20,7 @@ import ( ) func TestSimAppExportAndBlockedAddrs(t *testing.T) { - encCfg, db, app := getEmSimApp(t, rand.Bytes(sdk.AddrLen)) + encCfg, db, app, _ := getEmSimApp(t, rand.Bytes(sdk.AddrLen)) app.Commit() // Making a new app object with the db, so that initchain hasn't been called @@ -37,12 +34,19 @@ func TestSimAppExportAndBlockedAddrs(t *testing.T) { ) } -func getEmSimApp(t *testing.T, authorityAcc sdk.AccAddress) (EncodingConfig, *dbm.MemDB, *EMoneyApp) { - encCfg := MakeEncodingConfig() +func getEmSimApp( + t *testing.T, authorityAcc sdk.AccAddress, +) (encCfg EncodingConfig, memDB *dbm.MemDB, eMoneyApp *EMoneyApp, homeFolder string) { + t.Helper() + + encCfg = MakeEncodingConfig() db := dbm.NewMemDB() + homeDir := t.TempDir() + t.Log("home dir:", homeDir) + app := NewApp( log.NewTMLogger(log.NewSyncWriter(os.Stdout)), db, nil, true, - map[int64]bool{}, t.TempDir(), 0, encCfg, EmptyAppOptions{}, + map[int64]bool{}, homeDir, 0, encCfg, EmptyAppOptions{}, ) for acc := range maccPerms { @@ -70,7 +74,7 @@ func getEmSimApp(t *testing.T, authorityAcc sdk.AccAddress) (EncodingConfig, *db }, ) - return encCfg, db, app + return encCfg, db, app, homeFolder } // EmptyAppOptions is a stub implementing AppOptions @@ -89,17 +93,13 @@ type emAppTests struct { } func (et *emAppTests) initEmApp(t *testing.T) { - homeDir := filepath.Join(t.TempDir(), "x_upgrade_keeper_test") + t.Helper() var err error et.authority, err = sdk.AccAddressFromBech32("emoney1kt0vh0ttget0xx77g6d3ttnvq2lnxx6vp3uyl0") require.NoError(t, err) - _, _, app := getEmSimApp(t, et.authority) - app.upgradeKeeper = upgradekeeper.NewKeeper( // recreate keeper in order to use a custom home path - make(map[int64]bool), app.GetKey(upgradetypes.StoreKey), app.AppCodec(), homeDir, - ) - t.Log("home dir:", homeDir) + _, _, app, homeDir := getEmSimApp(t, et.authority) et.homeDir = homeDir et.app = app From 134a25e4e4b34d1835242860d08dbd0bac7e4ec1 Mon Sep 17 00:00:00 2001 From: Mario Karagiorgas Date: Tue, 27 Jul 2021 13:10:30 +0300 Subject: [PATCH 15/49] Link RPC-to-gPRC Apis, cmd documentation touches --- app.go | 1 - x/authority/client/cli/tx.go | 38 ++++++++++++++++++------------------ x/authority/handler.go | 4 ++++ x/authority/types/codec.go | 4 ++++ 4 files changed, 27 insertions(+), 20 deletions(-) diff --git a/app.go b/app.go index 28b3f23c..28bffa31 100644 --- a/app.go +++ b/app.go @@ -105,7 +105,6 @@ const ( var ( DefaultNodeHome = os.ExpandEnv("$HOME/.emd") - // todo (reviewer) : please check the listed modules carefully. This are the defaults + em modules ModuleBasics = module.NewBasicManager( auth.AppModuleBasic{}, genutil.AppModuleBasic{}, diff --git a/x/authority/client/cli/tx.go b/x/authority/client/cli/tx.go index f55cf833..38f44026 100644 --- a/x/authority/client/cli/tx.go +++ b/x/authority/client/cli/tx.go @@ -179,29 +179,29 @@ For a 24-hour grace period the former authority key is equivalent to the new one return cmd } -func GetCmdScheduleUpgrade() *cobra.Command { - const ( - upgHeight = "upg-height" - upgTime = "upg-time" - upgInfo = "upg-info" - ) +const ( + UpgHeight = "upg-height" + UpgTime = "upg-time" + UpgInfo = "upg-info" +) +func GetCmdScheduleUpgrade() *cobra.Command { var ( upgHeightVal, upgTimeSecsVal int64 upgInfoVal string ) cmd := &cobra.Command{ - Use: "schedule-upg [authority_key_or_address] plan_name", + Use: "upg-schedule [authority_key_or_address] plan_name", Short: "Schedule a software upgrade.", - Example: `emd tx schedule-upg emoney1n5ggspeff4fxc87dvmg0ematr3qzw5l4v20mdv 0.43 --upg_height 2001 -emd tx schedule-upg emoney1n5ggspeff4fxc87dvmg0ematr3qzw5l4v20mdv 'New Staking Rewards 36%' --upg_time 1628956125 # Unix seconds for 2021-08-14 15:48:45 +0000 UTC -emd tx schedule-upg emoney1n5ggspeff4fxc87dvmg0ematr3qzw5l4v20mdv sdk-v0.43.0 --upg_height 2001 --upg_info "https://e-money.com/mainnet-099-info.json?checksum=sha256:deaaa99fda9407c4dbe1d04bd49bab0cc3c1dd76fa392cd55a9425be074af01e"`, + Example: `emd tx authority upg-schedule --upg_height 2001 --from emoney1xue7fm6es84jze49grm4slhlmr4ffz8a3u7g3t 0.43 +emd tx upg-schedule 'New Staking Rewards 36%' --upg_time 1628956125 --from emoney1xue7fm6es84jze49grm4slhlmr4ffz8a3u7g3t # Unix seconds for 2021-08-14 15:48:45 +0000 UTC +emd tx upg-schedule sdk-v0.43.0 --upg_height 2001 --from emoney1xue7fm6es84jze49grm4slhlmr4ffz8a3u7g3t --upg_info "https://e-money.com/mainnet-099-info.json?checksum=sha256:deaaa99fda9407c4dbe1d04bd49bab0cc3c1dd76fa392cd55a9425be074af01e"`, Long: `Schedule a software upgrade by submitting a unique plan name that has been used before with either an absolute block height or block time. An upgrade handler should be defined at the upgraded binary. Optionally If you set DAEMON_ALLOW_DOWNLOAD_BINARIES=on pass the upgraded binary download url with the --upg-info flag i.e., --upg-info 'https://example.com/testnet-1001-info.json?checksum=sha256:deaaa99fda9407c4dbe1d04bd49bab0cc3c1dd76fa392cd55a9425be074af01e'`, - Args: cobra.ExactArgs(2), + Args: cobra.RangeArgs(1, 2), RunE: func(cmd *cobra.Command, args []string) error { err := cmd.Flags().Set(flags.FlagFrom, args[0]) if err != nil { @@ -209,7 +209,7 @@ the upgraded binary download url with the --upg-info flag i.e., --upg-info 'http } if err := validateUpgFlags( - upgHeight, upgHeightVal, upgTime, upgTimeSecsVal, + UpgHeight, upgHeightVal, UpgTime, upgTimeSecsVal, ); err != nil { return err } @@ -239,12 +239,12 @@ the upgraded binary download url with the --upg-info flag i.e., --upg-info 'http }, } f := cmd.Flags() - f.Int64VarP(&upgHeightVal, upgHeight, "n", 0, "upgrade block height number") + f.Int64VarP(&upgHeightVal, UpgHeight, "n", 0, "upgrade block height number") f.Int64VarP( - &upgTimeSecsVal, upgTime, "t", 0, "upgrade block time (in Unix seconds)", + &upgTimeSecsVal, UpgTime, "t", 0, "upgrade block time (in Unix seconds)", ) f.StringVarP( - &upgInfoVal, upgInfo, "i", "", "upgrade info", + &upgInfoVal, UpgInfo, "i", "", "upgrade info", ) flags.AddTxFlagsToCmd(cmd) @@ -266,11 +266,11 @@ func GetCmdApplyUpgrade() *cobra.Command { cmd := &cobra.Command{ Use: "upg-apply [authority_key_or_address] plan_name", Short: "Apply a software upgrade.", - Example: `emd tx upg-apply emoney1n5ggspeff4fxc87dvmg0ematr3qzw5l4v20mdv 0.43 --upg_height 2001 -emd tx upg-apply emoney1n5ggspeff4fxc87dvmg0ematr3qzw5l4v20mdv 'New Staking Rewards 36%' --upg_time 1628956125 # Unix seconds for 2021-08-14 15:48:45 +0000 UTC -emd tx upg-apply emoney1n5ggspeff4fxc87dvmg0ematr3qzw5l4v20mdv sdk-v0.43.0 --upg_height 2001 --upg_info "https://e-money.com/mainnet-099-info.json?checksum=sha256:deaaa99fda9407c4dbe1d04bd49bab0cc3c1dd76fa392cd55a9425be074af01e"`, + Example: `emd tx authority upg-apply 0.43 --upg_height 2001 --from emoney1xue7fm6es84jze49grm4slhlmr4ffz8a3u7g3t +emd tx upg-apply 'New Staking Rewards 36%' --upg_time 1628956125 --from emoney1xue7fm6es84jze49grm4slhlmr4ffz8a3u7g3t # Unix seconds for 2021-08-14 15:48:45 +0000 UTC +emd tx upg-apply sdk-v0.43.0 --upg_height 2001 --from emoney1xue7fm6es84jze49grm4slhlmr4ffz8a3u7g3t --upg_info "https://e-money.com/mainnet-099-info.json?checksum=sha256:deaaa99fda9407c4dbe1d04bd49bab0cc3c1dd76fa392cd55a9425be074af01e"`, Long: `Apply a software upgrade by submitting an already scheduled plan. An upgrade handler should have been submitted already.`, - Args: cobra.ExactArgs(2), + Args: cobra.RangeArgs(1, 2), RunE: func(cmd *cobra.Command, args []string) error { err := cmd.Flags().Set(flags.FlagFrom, args[0]) if err != nil { diff --git a/x/authority/handler.go b/x/authority/handler.go index f39a0f92..d70eb213 100644 --- a/x/authority/handler.go +++ b/x/authority/handler.go @@ -40,6 +40,10 @@ func newHandler(k Keeper) sdk.Handler { res, err := msgServer.ScheduleUpgrade(sdk.WrapSDKContext(ctx), msg) return sdk.WrapServiceResult(ctx, res, err) + case *types.MsgApplyUpgrade: + res, err := msgServer.ApplyUpgrade(sdk.WrapSDKContext(ctx), msg) + return sdk.WrapServiceResult(ctx, res, err) + default: return nil, sdkerrors.Wrapf(sdkerrors.ErrUnknownRequest, "unrecognized %s message type: %T", ModuleName, msg) } diff --git a/x/authority/types/codec.go b/x/authority/types/codec.go index b3633d6f..0bec4b5a 100644 --- a/x/authority/types/codec.go +++ b/x/authority/types/codec.go @@ -26,6 +26,8 @@ func RegisterLegacyAminoCodec(cdc *codec.LegacyAmino) { cdc.RegisterConcrete(&MsgDestroyIssuer{}, "e-money/MsgDestroyIssuer", nil) cdc.RegisterConcrete(&MsgSetGasPrices{}, "e-money/MsgSetGasPrices", nil) cdc.RegisterConcrete(&MsgReplaceAuthority{}, "e-money/MsgReplaceAuthority", nil) + cdc.RegisterConcrete(&MsgScheduleUpgrade{}, "e-money/MsgScheduleUpgrade", nil) + cdc.RegisterConcrete(&MsgApplyUpgrade{}, "e-money/MsgApplyUpgrade", nil) } func RegisterInterfaces(registry types.InterfaceRegistry) { @@ -34,6 +36,8 @@ func RegisterInterfaces(registry types.InterfaceRegistry) { &MsgDestroyIssuer{}, &MsgSetGasPrices{}, &MsgReplaceAuthority{}, + &MsgScheduleUpgrade{}, + &MsgApplyUpgrade{}, ) msgservice.RegisterMsgServiceDesc(registry, &_Msg_serviceDesc) } From 46ed6ac7a50154977b216b976ee55811bb0e4232 Mon Sep 17 00:00:00 2001 From: Mario Karagiorgas Date: Tue, 27 Jul 2021 15:12:57 +0300 Subject: [PATCH 16/49] Add msg server tests --- x/authority/keeper/msg_server_test.go | 130 ++++++++++++++++++++++++++ 1 file changed, 130 insertions(+) diff --git a/x/authority/keeper/msg_server_test.go b/x/authority/keeper/msg_server_test.go index 8bbc6d1b..28d8cebb 100644 --- a/x/authority/keeper/msg_server_test.go +++ b/x/authority/keeper/msg_server_test.go @@ -4,6 +4,7 @@ import ( "context" "errors" "testing" + "time" upgradetypes "github.com/cosmos/cosmos-sdk/x/upgrade/types" @@ -286,6 +287,135 @@ func TestSetGasPrices(t *testing.T) { }) } } + +func TestScheduleUpgrade(t *testing.T) { + var ( + authorityAddr = mustParseAddress("emoney1kt0vh0ttget0xx77g6d3ttnvq2lnxx6vp3uyl0") + gotAuthority sdk.AccAddress + gotPlan upgradetypes.Plan + ) + + keeper := authorityKeeperMock{} + svr := NewMsgServerImpl(&keeper) + + specs := map[string]struct { + req *types.MsgScheduleUpgrade + mockFn func(ctx sdk.Context, authority sdk.AccAddress, plan upgradetypes.Plan) (*sdk.Result, error) + expErr bool + expEvents sdk.Events + }{ + "all good": { + req: &types.MsgScheduleUpgrade{ + Authority: authorityAddr.String(), + Plan: upgradetypes.Plan{ + Name: "plan8", + Height: 100, + }, + }, + mockFn: func(ctx sdk.Context, authority sdk.AccAddress, plan upgradetypes.Plan) (*sdk.Result, error) { + gotAuthority, gotPlan = authority, plan + return &sdk.Result{ + Events: []abcitypes.Event{{ + Type: "testing", + Attributes: []abcitypes.EventAttribute{{Key: []byte("foo"), Value: []byte("bar")}}, + }}, + }, nil + }, + expEvents: sdk.Events{{ + Type: "testing", + Attributes: []abcitypes.EventAttribute{{Key: []byte("foo"), Value: []byte("bar")}}, + }}, + }, + "authority missing": { + req: &types.MsgScheduleUpgrade{ + Plan: upgradetypes.Plan{ + Name: "test1", + Height: 100, + }, + }, + expErr: true, + }, + "authority invalid": { + req: &types.MsgScheduleUpgrade{ + Authority: "invalid", + Plan: upgradetypes.Plan{ + Name: "test1", + Height: 100, + }, + }, + expErr: true, + }, + "invalid height value": { + req: &types.MsgScheduleUpgrade{ + Authority: authorityAddr.String(), + Plan: upgradetypes.Plan{ + Name: "test1", + Height: -100, + }, + }, + mockFn: func(ctx sdk.Context, authority sdk.AccAddress, plan upgradetypes.Plan) (*sdk.Result, error) { + return nil, errors.New("testing") + }, + expErr: true, + }, + "missing time or height": { + req: &types.MsgScheduleUpgrade{ + Authority: authorityAddr.String(), + Plan: upgradetypes.Plan{ + Name: "test1", + }, + }, + mockFn: func(ctx sdk.Context, authority sdk.AccAddress, plan upgradetypes.Plan) (*sdk.Result, error) { + return nil, errors.New("testing") + }, + expErr: true, + }, + "missing plan name": { + req: &types.MsgScheduleUpgrade{ + Authority: authorityAddr.String(), + Plan: upgradetypes.Plan{ + Height: 1, + }, + }, + mockFn: func(ctx sdk.Context, authority sdk.AccAddress, plan upgradetypes.Plan) (*sdk.Result, error) { + return nil, errors.New("testing") + }, + expErr: true, + }, + "featuring both time and height": { + req: &types.MsgScheduleUpgrade{ + Authority: authorityAddr.String(), + Plan: upgradetypes.Plan{ + Name: "test1", + Time: time.Now(), + Height: 1, + }, + }, + mockFn: func(ctx sdk.Context, authority sdk.AccAddress, plan upgradetypes.Plan) (*sdk.Result, error) { + return nil, errors.New("testing") + }, + expErr: true, + }, + } + + for name, spec := range specs { + t.Run(name, func(t *testing.T) { + keeper.scheduleUpgradefn = spec.mockFn + eventManager := sdk.NewEventManager() + ctx := sdk.Context{}.WithContext(context.Background()).WithEventManager(eventManager) + _, gotErr := svr.ScheduleUpgrade(sdk.WrapSDKContext(ctx), spec.req) + if spec.expErr { + require.Error(t, gotErr) + return + } + require.NoError(t, gotErr) + assert.Equal(t, spec.expEvents, eventManager.Events()) + assert.Equal(t, spec.req.Authority, gotAuthority.String()) + assert.Equal(t, spec.req.Plan, gotPlan) + }) + } +} + func TestReplaceAuth(t *testing.T) { var ( authorityAddr = mustParseAddress("emoney1kt0vh0ttget0xx77g6d3ttnvq2lnxx6vp3uyl0") From 274e3154d4c9649dc95b49ca9e9757abb2dae4c6 Mon Sep 17 00:00:00 2001 From: Mario Karagiorgas Date: Tue, 27 Jul 2021 18:17:17 +0300 Subject: [PATCH 17/49] Add cmd integration test --- .../cli/{tx_test.go => tx_replace_test.go} | 30 +-- x/authority/client/cli/tx_upg_test.go | 172 ++++++++++++++++++ 2 files changed, 188 insertions(+), 14 deletions(-) rename x/authority/client/cli/{tx_test.go => tx_replace_test.go} (93%) create mode 100644 x/authority/client/cli/tx_upg_test.go diff --git a/x/authority/client/cli/tx_test.go b/x/authority/client/cli/tx_replace_test.go similarity index 93% rename from x/authority/client/cli/tx_test.go rename to x/authority/client/cli/tx_replace_test.go index 5c54424e..974209ed 100644 --- a/x/authority/client/cli/tx_test.go +++ b/x/authority/client/cli/tx_replace_test.go @@ -3,11 +3,14 @@ package cli_test import ( "bytes" "fmt" + "sort" + "strings" + bankcli "github.com/cosmos/cosmos-sdk/x/bank/client/testutil" "github.com/e-money/em-ledger/x/authority/client/cli" "github.com/e-money/em-ledger/x/authority/types" - "sort" - "strings" + + "testing" "github.com/cosmos/cosmos-sdk/client/flags" "github.com/cosmos/cosmos-sdk/crypto/hd" @@ -20,22 +23,21 @@ import ( sdk "github.com/cosmos/cosmos-sdk/types" authtest "github.com/cosmos/cosmos-sdk/x/auth/client/testutil" "github.com/stretchr/testify/suite" - "testing" ) -type IntegrationTestSuite struct { +type ReplacementTestSuite struct { suite.Suite cfg network.Config network *network.Network } -func (s *IntegrationTestSuite) SetupSuite() { +func (s *ReplacementTestSuite) SetupSuite() { s.T().Log("setting up integration test suite") cfg := network.DefaultConfig() cfg.LegacyAmino.RegisterConcrete(&types.MsgReplaceAuthority{}, "MsgReplaceAuthority", nil) - cfg.InterfaceRegistry.RegisterImplementations((*sdk.Msg)(nil),&types.MsgReplaceAuthority{}) + cfg.InterfaceRegistry.RegisterImplementations((*sdk.Msg)(nil), &types.MsgReplaceAuthority{}) cfg.NumValidators = 2 s.cfg = cfg @@ -59,12 +61,12 @@ func (s *IntegrationTestSuite) SetupSuite() { s.Require().NoError(err) } -func (s *IntegrationTestSuite) TearDownSuite() { +func (s *ReplacementTestSuite) TearDownSuite() { s.T().Log("tearing down integration test suite") s.network.Cleanup() } -func (s *IntegrationTestSuite) TestReplaceAuth() { +func (s *ReplacementTestSuite) TestReplaceAuth() { val1 := *s.network.Validators[0] // Generate 2 accounts and a multisig. @@ -109,7 +111,7 @@ func (s *IntegrationTestSuite) TestReplaceAuth() { authkeys := []string{acc1UID, acc2UID, acc3UID} multisigThreshold := len(authkeys) - 1 // generate new multisig authority key - for _, keyname := range authkeys{ + for _, keyname := range authkeys { k, err := kb.Key(keyname) s.Require().NoError(err) @@ -130,7 +132,7 @@ func (s *IntegrationTestSuite) TestReplaceAuth() { fmt.Println("New authority multisig key:", newAuthMultiSigAcc.GetAddress().String()) - // set the multisig acount in the state + // set the multisig account in the state sendTokens := sdk.NewInt64Coin(s.cfg.BondDenom, 10) _, err = bankcli.MsgSendExec( val1.ClientCtx, @@ -153,7 +155,7 @@ func (s *IntegrationTestSuite) TestReplaceAuth() { fmt.Sprintf("--%s=true", flags.FlagGenerateOnly), } - multiGeneratedTx, err := sdkcli.ExecTestCLICmd(val1.ClientCtx, cli.GetCmdReplaceAuthority(),args) + multiGeneratedTx, err := sdkcli.ExecTestCLICmd(val1.ClientCtx, cli.GetCmdReplaceAuthority(), args) s.Require().NoError(err) // Save tx to file @@ -208,6 +210,6 @@ func (s *IntegrationTestSuite) TestReplaceAuth() { s.Require().NoError(s.network.WaitForNextBlock()) } -func TestIntegrationTestSuite(t *testing.T) { - suite.Run(t, new(IntegrationTestSuite)) -} \ No newline at end of file +func TestReplacementTestSuite(t *testing.T) { + suite.Run(t, new(ReplacementTestSuite)) +} diff --git a/x/authority/client/cli/tx_upg_test.go b/x/authority/client/cli/tx_upg_test.go new file mode 100644 index 00000000..205b546c --- /dev/null +++ b/x/authority/client/cli/tx_upg_test.go @@ -0,0 +1,172 @@ +package cli_test + +import ( + "fmt" + "strings" + + bankcli "github.com/cosmos/cosmos-sdk/x/bank/client/testutil" + "github.com/e-money/em-ledger/x/authority/client/cli" + "github.com/e-money/em-ledger/x/authority/types" + + "testing" + + "github.com/cosmos/cosmos-sdk/client/flags" + "github.com/cosmos/cosmos-sdk/crypto/hd" + "github.com/cosmos/cosmos-sdk/crypto/keyring" + kmultisig "github.com/cosmos/cosmos-sdk/crypto/keys/multisig" + cryptotypes "github.com/cosmos/cosmos-sdk/crypto/types" + "github.com/cosmos/cosmos-sdk/testutil" + sdkcli "github.com/cosmos/cosmos-sdk/testutil/cli" + "github.com/cosmos/cosmos-sdk/testutil/network" + sdk "github.com/cosmos/cosmos-sdk/types" + authtest "github.com/cosmos/cosmos-sdk/x/auth/client/testutil" + "github.com/stretchr/testify/suite" +) + +type UpgTestSuite struct { + suite.Suite + + cfg network.Config + network *network.Network +} + +func (s *UpgTestSuite) SetupSuite() { + s.T().Log("setting up integration test suite") + + cfg := network.DefaultConfig() + cfg.LegacyAmino.RegisterConcrete(&types.MsgScheduleUpgrade{}, "MsgScheduleUpgrade", nil) + cfg.InterfaceRegistry.RegisterImplementations((*sdk.Msg)(nil), &types.MsgScheduleUpgrade{}) + cfg.NumValidators = 2 + + s.cfg = cfg + s.network = network.New(s.T(), cfg) + + kb := s.network.Validators[0].ClientCtx.Keyring + _, _, err := kb.NewMnemonic("newAccount", keyring.English, sdk.FullFundraiserPath, hd.Secp256k1) + s.Require().NoError(err) + + account1, _, err := kb.NewMnemonic("newAccount1", keyring.English, sdk.FullFundraiserPath, hd.Secp256k1) + s.Require().NoError(err) + + account2, _, err := kb.NewMnemonic("newAccount2", keyring.English, sdk.FullFundraiserPath, hd.Secp256k1) + s.Require().NoError(err) + + // Create multisig authority key + multi := kmultisig.NewLegacyAminoPubKey(2, []cryptotypes.PubKey{account1.GetPubKey(), account2.GetPubKey()}) + _, err = kb.SaveMultisig("multi", multi) + s.Require().NoError(err) + + _, err = s.network.WaitForHeight(1) + s.Require().NoError(err) +} + +func (s *UpgTestSuite) TearDownSuite() { + s.T().Log("tearing down integration test suite") + s.network.Cleanup() +} + +func (s *UpgTestSuite) TestScheduleUpgrade() { + val1 := *s.network.Validators[0] + + // Generate 2 accounts and a multisig. + const ( + acc1UID = "newAccount1" + acc2UID = "newAccount2" + msigUID = "multi" + ) + + account1, err := val1.ClientCtx.Keyring.Key(acc1UID) + s.Require().NoError(err) + fmt.Println("acc 1:", account1.GetAddress().String()) + + account2, err := val1.ClientCtx.Keyring.Key(acc2UID) + s.Require().NoError(err) + fmt.Println("acc 2:", account2.GetAddress().String()) + + authMultiSigAcc, err := val1.ClientCtx.Keyring.Key(msigUID) + s.Require().NoError(err) + s.Require().Equal(keyring.TypeMulti, authMultiSigAcc.GetType()) + fmt.Println("multi:", authMultiSigAcc.GetAddress().String()) + + // set the multisig account in the state + sendTokens := sdk.NewInt64Coin(s.cfg.BondDenom, 10) + _, err = bankcli.MsgSendExec( + val1.ClientCtx, + val1.Address, + authMultiSigAcc.GetAddress(), + sdk.NewCoins(sendTokens), + fmt.Sprintf("--%s=true", flags.FlagSkipConfirmation), + fmt.Sprintf("--%s=%s", flags.FlagBroadcastMode, flags.BroadcastBlock), + fmt.Sprintf("--%s=%s", flags.FlagFees, sdk.NewCoins(sdk.NewCoin(s.cfg.BondDenom, sdk.NewInt(10))).String()), + fmt.Sprintf("--gas=%d", flags.DefaultGasLimit), + ) + + // Generate the unsigned multisig transaction json with the existing authority key. + args := []string{ + authMultiSigAcc.GetAddress().String(), + "test1", + fmt.Sprintf("--%s=100", cli.UpgHeight), + fmt.Sprintf("--%s=true", flags.FlagSkipConfirmation), + fmt.Sprintf("--%s=%s", flags.FlagBroadcastMode, flags.BroadcastBlock), + fmt.Sprintf("--%s=%s", flags.FlagFees, sdk.NewCoins(sdk.NewCoin(s.cfg.BondDenom, sdk.NewInt(10))).String()), + fmt.Sprintf("--%s=true", flags.FlagGenerateOnly), + } + + multiGeneratedTx, err := sdkcli.ExecTestCLICmd(val1.ClientCtx, cli.GetCmdScheduleUpgrade(), args) + s.Require().NoError(err) + + // Save tx to file + multiGeneratedTxFile := testutil.WriteToNewTempFile(s.T(), multiGeneratedTx.String()) + + // Sign with account1 + val1.ClientCtx.HomeDir = strings.Replace(val1.ClientCtx.HomeDir, "simd", "simcli", 1) + account1Signature, err := authtest.TxSignExec( + val1.ClientCtx, account1.GetAddress(), multiGeneratedTxFile.Name(), + "--multisig", authMultiSigAcc.GetAddress().String(), + ) + s.Require().NoError(err) + + sign1File := testutil.WriteToNewTempFile(s.T(), account1Signature.String()) + + // Sign with account2 + account2Signature, err := authtest.TxSignExec( + val1.ClientCtx, account2.GetAddress(), multiGeneratedTxFile.Name(), + "--multisig", authMultiSigAcc.GetAddress().String(), + ) + s.Require().NoError(err) + + sign2File := testutil.WriteToNewTempFile(s.T(), account2Signature.String()) + + // Does not work in offline mode. + _, err = authtest.TxMultiSignExec( + val1.ClientCtx, authMultiSigAcc.GetName(), multiGeneratedTxFile.Name(), + "--offline", sign1File.Name(), sign2File.Name(), + ) + s.Require().EqualError( + err, + "couldn't verify signature: unable to verify single signer signature", + ) + + val1.ClientCtx.Offline = false + multiSigWith2Signatures, err := authtest.TxMultiSignExec( + val1.ClientCtx, authMultiSigAcc.GetName(), multiGeneratedTxFile.Name(), + sign1File.Name(), sign2File.Name(), + ) + s.Require().NoError(err) + + // Write the output to disk + signedTxFile := testutil.WriteToNewTempFile(s.T(), multiSigWith2Signatures.String()) + + _, err = authtest.TxValidateSignaturesExec(val1.ClientCtx, signedTxFile.Name()) + s.Require().NoError(err) + + val1.ClientCtx.BroadcastMode = flags.BroadcastBlock + _, err = authtest.TxBroadcastExec(val1.ClientCtx, signedTxFile.Name()) + s.Require().NoError(err) + + s.Require().NoError(s.network.WaitForNextBlock()) +} + +func TestUpgTestSuite(t *testing.T) { + suite.Run(t, new(UpgTestSuite)) +} From 15b03b83667cad7b114943aa59dd3a4e2b190607 Mon Sep 17 00:00:00 2001 From: Mario Karagiorgas Date: Tue, 27 Jul 2021 23:50:15 +0300 Subject: [PATCH 18/49] Add cosmovisor testing script --- networks/upg/cpemd | 20 ++++++++------ networks/upg/startcv | 61 +++++++++++++++++++++++++++++++++++++++++ networks/utils/startemd | 33 ++++++++++++++++++---- 3 files changed, 99 insertions(+), 15 deletions(-) create mode 100755 networks/upg/startcv diff --git a/networks/upg/cpemd b/networks/upg/cpemd index ec26914f..52acfe48 100755 --- a/networks/upg/cpemd +++ b/networks/upg/cpemd @@ -7,11 +7,18 @@ export DAEMON_NAME=emd export DAEMON_ALLOW_DOWNLOAD_BINARIES=true export DAEMON_RESTART_AFTER_UPGRADE=true +# locate .emd home folder starting either in em-ledger/networks or em-ledger/networks/upg if [[ -d $PWD/.emd ]]; then export DAEMON_HOME=$PWD/.emd + pushd -q ../ + EM_LEDGER_LOC=$PWD + popd -q elif [[ -d ../.emd ]]; then pushd -q ../ export DAEMON_HOME=$PWD/.emd + pushd -q ../ + EM_LEDGER_LOC=$PWD + popd -q popd -q else echo ".emd folder not found neither in $PWD nor in parent. run startemd.sh to create node" @@ -20,15 +27,10 @@ fi echo "node home: $DAEMON_HOME" -EMD=$DAEMON_HOME/../../build/emd - -if [[ ! -f $DAEMON_HOME/cosmovisor/genesis/bin/emd ]]; then - - mkdir -p "$DAEMON_HOME"/cosmovisor/genesis/bin - cp "$EMD" "$DAEMON_HOME"/cosmovisor/genesis/bin - -fi +# copy soon to be the legacy binary +mkdir -p "$EM_LEDGER_LOC"/networks/.emd/cosmovisor/genesis/bin +cp "$EM_LEDGER_LOC"/build/emd "$EM_LEDGER_LOC"/networks/.emd/cosmovisor/genesis/bin -echo "legacy or current binary in "$DAEMON_HOME"/cosmovisor/genesis/bin" +echo "legacy or current binary in $EM_LEDGER_LOC/networks/.emd/cosmovisor/genesis/bin" echo "current version: $(cosmovisor version)" \ No newline at end of file diff --git a/networks/upg/startcv b/networks/upg/startcv new file mode 100755 index 00000000..bda58f2f --- /dev/null +++ b/networks/upg/startcv @@ -0,0 +1,61 @@ +#!/bin/zsh + +set -ev + +##### em-ledger single node genesis setup + +# locate emd binary starting either in em-ledger/networks or em-ledger/networks/utils +if [[ -f $PWD/../../build/emd ]]; then + pushd ../ + EMD_NODE=$PWD/.emd + pushd -q ../build + EMD=$PWD/emd + # return to networks + popd -q +elif [[ -f $PWD/../build/emd ]]; then + EMD_NODE=$PWD/.emd + pushd -q ../build + EMD=$PWD/emd + popd -q +else + echo "emd binary not found neither in $PWD nor in parent. run make to create binary" + exit 1 +fi + +# destructive +# do not do this in production +rm -rf "$EMD_NODE"/config +rm -rf "$EMD_NODE"/data +rm -rf "$EMD_NODE"/keyring-test +# do not delete cosmovisor if it exists + +$EMD unsafe-reset-all --home=$EMD_NODE + +$EMD init test --chain-id=test --home="$EMD_NODE" --overwrite +$EMD keys add validator --keyring-backend=test --home="$EMD_NODE" +$EMD add-genesis-account "$($EMD keys show validator -a --keyring-backend=test --home="$EMD_NODE")" 1000000000stake,1000000000ungm --home=$EMD_NODE +$EMD gentx validator 500000000stake --keyring-backend=test --home="$EMD_NODE" --chain-id=test + +# create genesis emoney1xue7fm6es84jze49grm4slhlmr4ffz8a3u7g3t to set the authority later +AUTH_SEED="fuel public electric luxury short upper quit edge ginger need olive gesture time useful stadium exhaust since team pond wool type flat focus narrow" +(echo "$AUTH_SEED"; echo "$AUTH_SEED") | $EMD keys add authoritykey --recover --keyring-backend=test --home="$EMD_NODE" +AUTHORITY_ADDR=$($EMD keys show authoritykey -a --keyring-backend=test --home="$EMD_NODE") +$EMD add-genesis-account "$AUTHORITY_ADDR" 1000000000000ungm --home=$EMD_NODE + +$EMD collect-gentxs --home="$EMD_NODE" + +# set the auth address as the chain authority +AUTHORITY_ADDR_VAL=".app_state.authority.key=\"$AUTHORITY_ADDR\"" +jq $AUTHORITY_ADDR_VAL < "$EMD_NODE"/config/genesis.json > "$EMD_NODE"/config/tmp_genesis.json +mv "$EMD_NODE"/config/tmp_genesis.json "$EMD_NODE"/config/genesis.json + +##### Cosmovisor setup + +export DAEMON_NAME=emd +export DAEMON_ALLOW_DOWNLOAD_BINARIES=true +export DAEMON_RESTART_AFTER_UPGRADE=true +export DAEMON_HOME=$EMD_NODE + +echo "node home: $DAEMON_HOME" + +cosmovisor start --home="$DAEMON_HOME" \ No newline at end of file diff --git a/networks/utils/startemd b/networks/utils/startemd index aeddb34d..a747f5b9 100755 --- a/networks/utils/startemd +++ b/networks/utils/startemd @@ -1,27 +1,48 @@ -#!/bin/bash +#!/bin/zsh set -ev -EMD=../../build/emd -EMD_HOME=$PWD/.. -EMD_NODE=$EMD_HOME/.emd +# locate emd binary starting either in em-ledger/networks or em-ledger/networks/utils +if [[ -f $PWD/../../build/emd ]]; then + pushd ../ + EMD_NODE=$PWD/.emd + pushd -q ../build + EMD=$PWD/emd + # return to networks + popd -q +elif [[ -f $PWD/../build/emd ]]; then + EMD_NODE=$PWD/.emd + pushd -q ../build + EMD=$PWD/emd + popd -q +else + echo "emd binary not found neither in $PWD nor in parent. run make to create binary" + exit 1 +fi +# destructive # do not do this in production rm -rf "$EMD_NODE"/config rm -rf "$EMD_NODE"/data rm -rf "$EMD_NODE"/keyring-test # do not delete cosmovisor if it exists +$EMD unsafe-reset-all --home=$EMD_NODE + $EMD init test --chain-id=test --home="$EMD_NODE" --overwrite $EMD keys add validator --keyring-backend=test --home="$EMD_NODE" $EMD add-genesis-account "$($EMD keys show validator -a --keyring-backend=test --home="$EMD_NODE")" 1000000000stake,1000000000ungm --home=$EMD_NODE $EMD gentx validator 500000000stake --keyring-backend=test --home="$EMD_NODE" --chain-id=test -$EMD collect-gentxs --home="$EMD_NODE" -# establish authority emoney1xue7fm6es84jze49grm4slhlmr4ffz8a3u7g3t +# create genesis emoney1xue7fm6es84jze49grm4slhlmr4ffz8a3u7g3t to set the authority later AUTH_SEED="fuel public electric luxury short upper quit edge ginger need olive gesture time useful stadium exhaust since team pond wool type flat focus narrow" (echo "$AUTH_SEED"; echo "$AUTH_SEED") | $EMD keys add authoritykey --recover --keyring-backend=test --home="$EMD_NODE" AUTHORITY_ADDR=$($EMD keys show authoritykey -a --keyring-backend=test --home="$EMD_NODE") +$EMD add-genesis-account "$AUTHORITY_ADDR" 1000000000000ungm --home=$EMD_NODE + +$EMD collect-gentxs --home="$EMD_NODE" + +# set the auth address as the chain authority AUTHORITY_ADDR_VAL=".app_state.authority.key=\"$AUTHORITY_ADDR\"" jq $AUTHORITY_ADDR_VAL < "$EMD_NODE"/config/genesis.json > "$EMD_NODE"/config/tmp_genesis.json mv "$EMD_NODE"/config/tmp_genesis.json "$EMD_NODE"/config/genesis.json From 57b9cd7488fd7b7b86299976346a5fd4b10c4b23 Mon Sep 17 00:00:00 2001 From: Mario Karagiorgas Date: Wed, 28 Jul 2021 22:25:35 +0300 Subject: [PATCH 19/49] Add testing scripts for auto-download option Add documentation --- networks/upg/cpemd | 17 ++++++++++++--- networks/upg/cpupgemd | 48 ++++++++++++++++++++++++++++++++++++++++++ networks/upg/setcvenv | 29 +++++++++++++++++++++++++ networks/upg/startcv | 33 +++++++++++++++++++++++------ networks/upg/upg-sched | 21 ++++++++++++++++++ 5 files changed, 139 insertions(+), 9 deletions(-) create mode 100755 networks/upg/cpupgemd create mode 100755 networks/upg/setcvenv create mode 100755 networks/upg/upg-sched diff --git a/networks/upg/cpemd b/networks/upg/cpemd index 52acfe48..9b4bf51e 100755 --- a/networks/upg/cpemd +++ b/networks/upg/cpemd @@ -1,11 +1,21 @@ #!/bin/zsh +# Copying the present/soon to be legacy binary in the cosmovisor genesis folder +# Note the cosmovisor folder structure before the upgrade +# em-ledger/networks/.emd/cosmovisor +# ├── current -> /home/user/go/src/github.com/e-money/em-ledger/networks/.emd/cosmovisor/genesis/bin/emd +# ├── genesis +# │ └── bin +# │ └── emd +# └── upgrades +# └── test-upg-0.1.0 +# └── bin +# └── emd + set -e -# cosmovisor constants +# cosmovisor constant export DAEMON_NAME=emd -export DAEMON_ALLOW_DOWNLOAD_BINARIES=true -export DAEMON_RESTART_AFTER_UPGRADE=true # locate .emd home folder starting either in em-ledger/networks or em-ledger/networks/upg if [[ -d $PWD/.emd ]]; then @@ -30,6 +40,7 @@ echo "node home: $DAEMON_HOME" # copy soon to be the legacy binary mkdir -p "$EM_LEDGER_LOC"/networks/.emd/cosmovisor/genesis/bin cp "$EM_LEDGER_LOC"/build/emd "$EM_LEDGER_LOC"/networks/.emd/cosmovisor/genesis/bin +mkdir -p "$EM_LEDGER_LOC"/networks/.emd/cosmovisor/upgrades echo "legacy or current binary in $EM_LEDGER_LOC/networks/.emd/cosmovisor/genesis/bin" diff --git a/networks/upg/cpupgemd b/networks/upg/cpupgemd new file mode 100755 index 00000000..41e1e02b --- /dev/null +++ b/networks/upg/cpupgemd @@ -0,0 +1,48 @@ +#!/bin/zsh + +# Copying test upgrade binary in cosmovisor upgrade folder +# This script is optional and not-needed if exercising the auto +# download option with DAEMON_RESTART_AFTER_UPGRADE=true +# -- or using the http download option as a backup option. + +# em-ledger/networks/.emd/cosmovisor +# ├── current -> /home/user/go/src/github.com/e-money/em-ledger/networks/.emd/cosmovisor/genesis/bin/emd +# ├── genesis +# │ └── bin +# │ └── emd +# └── upgrades +# └── test-upg-0.1.0 +# └── bin +# └── emd + +set -e + +UPG_EMD_LOC=/srv/ftp/test-upg-0.1.0 + +# cosmovisor constants +export DAEMON_NAME=emd + +# locate .emd home folder starting either in em-ledger/networks or em-ledger/networks/upg +if [[ -d $PWD/.emd ]]; then + export DAEMON_HOME=$PWD/.emd +elif [[ -d ../.emd ]]; then + pushd -q ../ + export DAEMON_HOME=$PWD/.emd + popd -q +else + echo ".emd folder not found neither in $PWD nor in parent. run startemd.sh to create node" + exit 1 +fi + +echo "node home: $DAEMON_HOME" + +COSMOVISOR_UPG_LOC="$DAEMON_HOME"/networks/.emd/cosmovisor/upgrades/test-upg-0.1.0/bin +echo "copying $UPG_EMD_LOC/emd -> $COSMOVISOR_UPG_LOC" + +# copy the upgrade binary +mkdir -p "$COSMOVISOR_UPG_LOC" +cp $UPG_EMD_LOC/emd "$COSMOVISOR_UPG_LOC" + +echo "copied upgrade binary in $COSMOVISOR_UPG_LOC" + +echo "current version: $(cosmovisor version)" \ No newline at end of file diff --git a/networks/upg/setcvenv b/networks/upg/setcvenv new file mode 100755 index 00000000..9cdf900b --- /dev/null +++ b/networks/upg/setcvenv @@ -0,0 +1,29 @@ +#!/bin/zsh + +set -e + +##### cosmovisor env vars setup + +export DAEMON_NAME=emd +export DAEMON_ALLOW_DOWNLOAD_BINARIES=true +export DAEMON_RESTART_AFTER_UPGRADE=true + +# locate emd binary starting either in em-ledger/networks or em-ledger/networks/utils +if [[ -f $PWD/../../build/emd ]]; then + pushd ../ # to get absolute value + export DAEMON_HOME=$PWD/.emd + # return to networks + popd -q +elif [[ -f $PWD/../build/emd ]]; then + export DAEMON_HOME=$PWD/.emd +else + echo "emd binary not found neither in $PWD nor in parent. run make to create binary" + exit 1 +fi + +export EMD="$DAEMON_HOME"/cosmovisor/current/bin/emd + +echo "\$EMD: $(ls "$EMD")" +echo "node home: $DAEMON_HOME" + +echo "cosmovisor version: $(cosmovisor version)" \ No newline at end of file diff --git a/networks/upg/startcv b/networks/upg/startcv index bda58f2f..4f9e0065 100755 --- a/networks/upg/startcv +++ b/networks/upg/startcv @@ -2,7 +2,31 @@ set -ev -##### em-ledger single node genesis setup +##### em-ledger single node cosmovisor setup +export DAEMON_NAME=emd +export DAEMON_ALLOW_DOWNLOAD_BINARIES=true +export DAEMON_RESTART_AFTER_UPGRADE=true +# The following is setup at the end of this script +# export DAEMON_HOME= + +# +if [[ -f ./cpemd ]]; then + ./cpemd + set +e + rm ../.emd/cosmovisor/current + set +e +else + upg/cpemd + set +e + rm .emd/cosmovisor/current + set -e +fi + +# optionally uncomment to copy future upgrade binary in location if +# auto-downloading is not available as a primary or none at all +# by default we assume it is on and the upgrade binary is not available +# locally: DAEMON_RESTART_AFTER_UPGRADE=true +#./cpupgemd # locate emd binary starting either in em-ledger/networks or em-ledger/networks/utils if [[ -f $PWD/../../build/emd ]]; then @@ -49,13 +73,10 @@ AUTHORITY_ADDR_VAL=".app_state.authority.key=\"$AUTHORITY_ADDR\"" jq $AUTHORITY_ADDR_VAL < "$EMD_NODE"/config/genesis.json > "$EMD_NODE"/config/tmp_genesis.json mv "$EMD_NODE"/config/tmp_genesis.json "$EMD_NODE"/config/genesis.json -##### Cosmovisor setup - -export DAEMON_NAME=emd -export DAEMON_ALLOW_DOWNLOAD_BINARIES=true -export DAEMON_RESTART_AFTER_UPGRADE=true export DAEMON_HOME=$EMD_NODE echo "node home: $DAEMON_HOME" +cosmovisor version + cosmovisor start --home="$DAEMON_HOME" \ No newline at end of file diff --git a/networks/upg/upg-sched b/networks/upg/upg-sched new file mode 100755 index 00000000..f52c60a2 --- /dev/null +++ b/networks/upg/upg-sched @@ -0,0 +1,21 @@ +#!/bin/zsh + +set -e + +# Preconditions: +# git checkout upgrade-emd-test +# make +# copy to a convenient location +# mkdir -p /srv/upgemd/test-upg-0.1.0 +# cp build/emd /srv/upgemd/test-upg-0.1.0 +# zip /srv/upgemd/test-upg-0.1.0/emd.zip /srv/upgemd/test-upg-0.1.0/emd +# save sha value to clipboard +# sha256sum /srv/upgemd/test-upg-0.1.0/emd.zip | xsel -i -b +# cd /srv/upgemd +# start a web server in the +# python3 -m http.server 8765 + +EMD="$DAEMON_HOME"/cosmovisor/current/bin/emd + +# choose a future nearby +$EMD tx authority upg-schedule authoritykey test-upg-0.1.0 --upg-height 4 --upg-info '{"binaries":{"linux/amd64":"http://localhost:8765/test-upg-0.1.0/emd.zip?checksum=sha256:cadd5b52fe90a04e20b2cbb93291b0d1d0204f17b64b2215eb09f5dc78a127f1"}}' --yes --from authoritykey --home="$DAEMON_HOME" --node tcp://localhost:26657 --chain-id test --keyring-backend test \ No newline at end of file From 83f2b6538442935220825e1afe8b1b0a062e6235 Mon Sep 17 00:00:00 2001 From: Mario Karagiorgas Date: Thu, 29 Jul 2021 12:27:34 +0300 Subject: [PATCH 20/49] Remove linux prefix --- Makefile | 2 +- networks/docker/emdnode/wrapper.sh | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/Makefile b/Makefile index 3cad273e..582be5e6 100644 --- a/Makefile +++ b/Makefile @@ -66,7 +66,7 @@ install: build-linux: # Linux images for docker-compose # CGO_ENABLED=0 added to solve this issue: https://stackoverflow.com/a/36308464 - BIN_PREFIX=-linux LEDGER_ENABLED=false GOOS=linux CGO_ENABLED=0 GOARCH=amd64 $(MAKE) build + LEDGER_ENABLED=false GOOS=linux GOARCH=amd64 $(MAKE) build build-all: build-linux $(MAKE) build diff --git a/networks/docker/emdnode/wrapper.sh b/networks/docker/emdnode/wrapper.sh index da42ae87..7cf846eb 100755 --- a/networks/docker/emdnode/wrapper.sh +++ b/networks/docker/emdnode/wrapper.sh @@ -7,7 +7,7 @@ ## ## Input parameters ## -BINARY=/emoney/${BINARY:-emd-linux} +BINARY=/emoney/${BINARY:-emd} ID=${ID:-0} LOG=${LOG:-emd.log} # LOGLEVEL=${LOGLEVEL:-emz:info,x/inflation:info,x/liquidityprovider:info,main:info,state:info,*:error} From b7fb20561e9ab9bd2bd688ea2e9cb3345eca5017 Mon Sep 17 00:00:00 2001 From: Mario Karagiorgas Date: Thu, 29 Jul 2021 18:29:43 +0300 Subject: [PATCH 21/49] Add cosmovisor docker build --- Makefile | 2 ++ networks/docker/Makefile | 5 ++++- networks/docker/cosmovisor/Dockerfile | 7 +++++++ 3 files changed, 13 insertions(+), 1 deletion(-) create mode 100644 networks/docker/cosmovisor/Dockerfile diff --git a/Makefile b/Makefile index 582be5e6..19982b7f 100644 --- a/Makefile +++ b/Makefile @@ -67,6 +67,8 @@ build-linux: # Linux images for docker-compose # CGO_ENABLED=0 added to solve this issue: https://stackoverflow.com/a/36308464 LEDGER_ENABLED=false GOOS=linux GOARCH=amd64 $(MAKE) build + docker run --rm --entrypoint cat emoney/cosmovisor /go/bin/cosmovisor > build/cosmovisor + chmod +x build/cosmovisor build-all: build-linux $(MAKE) build diff --git a/networks/docker/Makefile b/networks/docker/Makefile index 4389323c..54c89c58 100644 --- a/networks/docker/Makefile +++ b/networks/docker/Makefile @@ -5,7 +5,10 @@ all: emdnode emdnode: docker build --tag emoney/emdnode emdnode +cosmovisor: + docker build cosmovisor --tag emoney/cosmovisor + # todo (reviewer): please note the rest-server is not a command anymore. Please enable `api` section in `app.toml` instead -.PHONY: all emdnode +.PHONY: all emdnode cosmovisor diff --git a/networks/docker/cosmovisor/Dockerfile b/networks/docker/cosmovisor/Dockerfile new file mode 100644 index 00000000..d72cac76 --- /dev/null +++ b/networks/docker/cosmovisor/Dockerfile @@ -0,0 +1,7 @@ +# This software is Copyright (c) 2019-2021 e-Money A/S. It is not offered under an open source license. +# +# Please contact partners@e-money.com for licensing related questions. + +FROM golang:1.16-buster AS build-env + +RUN go install github.com/cosmos/cosmos-sdk/cosmovisor/cmd/cosmovisor@latest \ No newline at end of file From 78b3383b73f1bcfc8d3f20445c149a6241986689 Mon Sep 17 00:00:00 2001 From: Mario Karagiorgas Date: Thu, 29 Jul 2021 19:31:22 +0300 Subject: [PATCH 22/49] Add cosmovisor variables --- networks/docker/emdnode/wrapper.sh | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/networks/docker/emdnode/wrapper.sh b/networks/docker/emdnode/wrapper.sh index 7cf846eb..416f7ed4 100755 --- a/networks/docker/emdnode/wrapper.sh +++ b/networks/docker/emdnode/wrapper.sh @@ -33,9 +33,12 @@ export EMDHOME="/emoney/node${ID}" if [ -d "`dirname ${EMDHOME}/${LOG}`" ]; then "$BINARY" --home "$EMDHOME" "$@" --log_level ${LOGLEVEL} --trace --pruning=nothing | tee "${EMDHOME}/${LOG}" +export DAEMON_RESTART_AFTER_UPGRADE=true +export DAEMON_HOME=$EMDHOME +# link chain launcher to cosmovisor with linux emd binary +export DAEMON_NAME=emd else "$BINARY" --home "$EMDHOME" "$@" --log_level ${LOGLEVEL} --trace --pruning=nothing fi -chmod 777 -R /emoney - +chmod 777 -R /emoney \ No newline at end of file From d2535368e459f6cc6a3feff25101dd08b6cfe8bf Mon Sep 17 00:00:00 2001 From: Mario Karagiorgas Date: Thu, 29 Jul 2021 22:33:48 +0300 Subject: [PATCH 23/49] Replace Alpine with Ubuntu and sync with Gaia --- networks/docker/emdnode/Dockerfile | 11 +++++------ networks/docker/emdnode/wrapper.sh | 11 +++++------ 2 files changed, 10 insertions(+), 12 deletions(-) diff --git a/networks/docker/emdnode/Dockerfile b/networks/docker/emdnode/Dockerfile index 59ffbe7a..75486c1c 100644 --- a/networks/docker/emdnode/Dockerfile +++ b/networks/docker/emdnode/Dockerfile @@ -2,11 +2,11 @@ # # Please contact partners@e-money.com for licensing related questions. -FROM alpine:3.7 +FROM ubuntu:18.04 -RUN apk update && \ - apk upgrade && \ - apk --no-cache add curl jq file +RUN apt-get update && \ + apt-get -y upgrade && \ + apt-get -y install curl jq file VOLUME /emoney WORKDIR /emoney @@ -15,5 +15,4 @@ ENTRYPOINT ["/usr/bin/wrapper.sh"] CMD ["start"] STOPSIGNAL SIGTERM -COPY wrapper.sh /usr/bin/wrapper.sh - +COPY wrapper.sh /usr/bin/wrapper.sh \ No newline at end of file diff --git a/networks/docker/emdnode/wrapper.sh b/networks/docker/emdnode/wrapper.sh index 416f7ed4..f7b49e97 100755 --- a/networks/docker/emdnode/wrapper.sh +++ b/networks/docker/emdnode/wrapper.sh @@ -10,9 +10,6 @@ BINARY=/emoney/${BINARY:-emd} ID=${ID:-0} LOG=${LOG:-emd.log} -# LOGLEVEL=${LOGLEVEL:-emz:info,x/inflation:info,x/liquidityprovider:info,main:info,state:info,*:error} -# TODO (reviewer) : the SDK uses the zap logger now. without fine grained configuration options. There should be an open issue in the repo already -LOGLEVEL=info ## ## Assert linux binary ## @@ -31,14 +28,16 @@ fi ## export EMDHOME="/emoney/node${ID}" -if [ -d "`dirname ${EMDHOME}/${LOG}`" ]; then - "$BINARY" --home "$EMDHOME" "$@" --log_level ${LOGLEVEL} --trace --pruning=nothing | tee "${EMDHOME}/${LOG}" +# Cosmovisor values +export DAEMON_ALLOW_DOWNLOAD_BINARIES=true export DAEMON_RESTART_AFTER_UPGRADE=true export DAEMON_HOME=$EMDHOME # link chain launcher to cosmovisor with linux emd binary export DAEMON_NAME=emd +if [ -d "$(dirname "${EMDHOME}"/"${LOG}")" ]; then + "$BINARY" --home "$EMDHOME" "$@" | tee "${EMDHOME}/${LOG}" else - "$BINARY" --home "$EMDHOME" "$@" --log_level ${LOGLEVEL} --trace --pruning=nothing + "$BINARY" --home "$EMDHOME" "$@" fi chmod 777 -R /emoney \ No newline at end of file From 7348309fa082017b2d718ef4c2c12b688fbdb065 Mon Sep 17 00:00:00 2001 From: Mario Karagiorgas Date: Fri, 30 Jul 2021 12:36:30 +0300 Subject: [PATCH 24/49] Start testnet chain with cosmovisor --- networks/docker/emdnode/wrapper.sh | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/networks/docker/emdnode/wrapper.sh b/networks/docker/emdnode/wrapper.sh index f7b49e97..364520d5 100755 --- a/networks/docker/emdnode/wrapper.sh +++ b/networks/docker/emdnode/wrapper.sh @@ -28,12 +28,18 @@ fi ## export EMDHOME="/emoney/node${ID}" -# Cosmovisor values +# setup cosmovisor +mkdir -p "$EMDHOME/cosmovisor/genesis/bin" +cp /emoney/emd "$EMDHOME/cosmovisor/genesis/bin" +mkdir -p "$EMDHOME/cosmovisor/upgrades" + export DAEMON_ALLOW_DOWNLOAD_BINARIES=true export DAEMON_RESTART_AFTER_UPGRADE=true export DAEMON_HOME=$EMDHOME # link chain launcher to cosmovisor with linux emd binary export DAEMON_NAME=emd +BINARY=/emoney/cosmovisor + if [ -d "$(dirname "${EMDHOME}"/"${LOG}")" ]; then "$BINARY" --home "$EMDHOME" "$@" | tee "${EMDHOME}/${LOG}" else From 031968a5ac5e93310ac8ff9233ef7e325b4a5c9b Mon Sep 17 00:00:00 2001 From: Mario Karagiorgas Date: Fri, 30 Jul 2021 20:09:56 +0300 Subject: [PATCH 25/49] Add nodes upgrade BDD test --- Makefile | 6 +++ networks/docker/emdnode/wrapper.sh | 4 +- networks/docker/test-upg/Dockerfile | 10 +++++ networktest/emcli.go | 11 +++++ upgrade_test.go | 67 +++++++++++++++++++++++++++++ 5 files changed, 97 insertions(+), 1 deletion(-) create mode 100644 networks/docker/test-upg/Dockerfile create mode 100644 upgrade_test.go diff --git a/Makefile b/Makefile index 19982b7f..f2b9f304 100644 --- a/Makefile +++ b/Makefile @@ -69,6 +69,12 @@ build-linux: LEDGER_ENABLED=false GOOS=linux GOARCH=amd64 $(MAKE) build docker run --rm --entrypoint cat emoney/cosmovisor /go/bin/cosmovisor > build/cosmovisor chmod +x build/cosmovisor + $(MAKE) build-test-upg + +build-test-upg: + # linux upgrade binary for testing cosmovisor upgrade + docker run --rm --entrypoint cat emoney/test-upg /go/src/em-ledger/build/emd > "build/emdupg" + chmod +x "build/emdupg" build-all: build-linux $(MAKE) build diff --git a/networks/docker/emdnode/wrapper.sh b/networks/docker/emdnode/wrapper.sh index 364520d5..042aa644 100755 --- a/networks/docker/emdnode/wrapper.sh +++ b/networks/docker/emdnode/wrapper.sh @@ -31,7 +31,6 @@ export EMDHOME="/emoney/node${ID}" # setup cosmovisor mkdir -p "$EMDHOME/cosmovisor/genesis/bin" cp /emoney/emd "$EMDHOME/cosmovisor/genesis/bin" -mkdir -p "$EMDHOME/cosmovisor/upgrades" export DAEMON_ALLOW_DOWNLOAD_BINARIES=true export DAEMON_RESTART_AFTER_UPGRADE=true @@ -39,6 +38,9 @@ export DAEMON_HOME=$EMDHOME # link chain launcher to cosmovisor with linux emd binary export DAEMON_NAME=emd BINARY=/emoney/cosmovisor +UPG_LOC="$EMDHOME"/cosmovisor/upgrades/test-upg-0.1.0/bin +mkdir -p "$UPG_LOC" +cp /emoney/emdupg "$UPG_LOC"/emd if [ -d "$(dirname "${EMDHOME}"/"${LOG}")" ]; then "$BINARY" --home "$EMDHOME" "$@" | tee "${EMDHOME}/${LOG}" diff --git a/networks/docker/test-upg/Dockerfile b/networks/docker/test-upg/Dockerfile new file mode 100644 index 00000000..76d9369f --- /dev/null +++ b/networks/docker/test-upg/Dockerfile @@ -0,0 +1,10 @@ +FROM golang:1.16-buster + +RUN cd /go/src && \ + git clone https://github.com/e-money/em-ledger.git && \ + cd em-ledger && \ + git checkout upgrade-emd-test && \ + make + + + diff --git a/networktest/emcli.go b/networktest/emcli.go index 76671dc3..6217c0d3 100644 --- a/networktest/emcli.go +++ b/networktest/emcli.go @@ -51,6 +51,12 @@ func (cli Emcli) AuthorityCreateIssuer(authority, issuer Key, denoms ...string) return execCmdWithInput(args, KeyPwd) } +func (cli Emcli) AuthorityUpgSched(authority Key, planName string, height int64) (string, bool, error) { + args := cli.addTransactionFlags("tx", "authority", "upg-schedule", + authority.name, planName, "--upg-height", strconv.FormatInt(height, 10)) + return execCmdWithInput(args, KeyPwd) +} + func (cli Emcli) AuthorityDestroyIssuer(authority, issuer Key) (string, bool, error) { args := cli.addTransactionFlags("tx", "authority", "destroy-issuer", authority.name, issuer.GetAddress()) return execCmdWithInput(args, KeyPwd) @@ -81,6 +87,11 @@ func (cli Emcli) AuthoritySetMinGasPrices(authority Key, minGasPrices string, pa return execCmdWithInput(args, KeyPwd) } +func (cli Emcli) QueryUpgSched() ([]byte, error) { + args := cli.addQueryFlags("query", "authority", "upg-plan") + return execCmdAndCollectResponse(args) +} + func (cli Emcli) QueryBuybackBalance() ([]byte, error) { args := cli.addQueryFlags("query", "buyback", "balance") return execCmdAndCollectResponse(args) diff --git a/upgrade_test.go b/upgrade_test.go new file mode 100644 index 00000000..a823a7a0 --- /dev/null +++ b/upgrade_test.go @@ -0,0 +1,67 @@ +// This software is Copyright (c) 2019-2020 e-Money A/S. It is not offered under an open source license. +// +// Please contact partners@e-money.com for licensing related questions. + +// +build bdd + +package emoney_test + +import ( + nt "github.com/e-money/em-ledger/networktest" + . "github.com/onsi/ginkgo" + . "github.com/onsi/gomega" + "github.com/tidwall/gjson" +) + +var _ = Describe("Upgrade", func() { + emcli := testnet.NewEmcli() + + var Authority = testnet.Keystore.Authority + + Describe("Authority manages issuers", func() { + It("creates a new testnet", createNewTestnet) + + It("upgrade nodes and confirm", func() { + const ( + name = "test-upg-0.1.0" + ) + + chainHeight, err := nt.GetHeight() + Expect(err).ToNot(HaveOccurred()) + + const upgDelta = 5 + upgHeight := chainHeight + upgDelta + + _, success, err := emcli.AuthorityUpgSched(Authority, name, + upgHeight, + ) + Expect(err).ToNot(HaveOccurred()) + Expect(success).To(BeTrue()) + + bz, err := emcli.QueryUpgSched() + Expect(err).ToNot(HaveOccurred()) + + upgPlan := gjson.ParseBytes(bz).Get("plan") + + resName := upgPlan.Get("name").Str + Expect(resName).To(Equal(name)) + resUpgHeight := upgPlan.Get("height").Int() + Expect(resUpgHeight).To(BeEquivalentTo(upgHeight)) + + // wait till the upgrade + newHeight, err := nt.IncChain(upgDelta + 1) + Expect(err).ToNot(HaveOccurred()) + Expect(newHeight > chainHeight+upgDelta).To(BeTrue()) + + // if we made it here, the upgrade succeeded + bz, err = emcli.QueryUpgSched() + Expect(err).ToNot(HaveOccurred()) + + // assert that the upgrade plan zeroed out + upgPlan = gjson.ParseBytes(bz).Get("plan") + + resName = upgPlan.Get("name").Str + Expect(resName).To(HaveLen(0)) + }) + }) +}) From d506684b7a7d6d0bf5dc3926ad93df8c41c18afc Mon Sep 17 00:00:00 2001 From: Mario Karagiorgas Date: Mon, 2 Aug 2021 10:13:45 +0300 Subject: [PATCH 26/49] Include upgrade in bdd tests list --- Makefile | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Makefile b/Makefile index f2b9f304..84c79a1a 100644 --- a/Makefile +++ b/Makefile @@ -90,7 +90,7 @@ test: go test -mod=readonly ./... bdd-test: - go test -mod=readonly -v -p 1 -timeout 1h --tags="bdd" bdd_test.go multisigauthority_test.go authority_test.go market_test.go buyback_test.go capacity_test.go staking_test.go bep3swap_test.go + go test -mod=readonly -v -p 1 -timeout 1h --tags="bdd" bdd_test.go multisigauthority_test.go authority_test.go market_test.go buyback_test.go capacity_test.go staking_test.go bep3swap_test.go upgrade_test.go github-ci: build-linux $(MAKE) test From ae65df21639b88da820ae30b4af2f1e335164d6a Mon Sep 17 00:00:00 2001 From: Mario Karagiorgas Date: Mon, 2 Aug 2021 13:14:02 +0300 Subject: [PATCH 27/49] Github workflow: Add 1.16, Macos, for go tests --- .github/workflows/ci.yml | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index d10be7f1..e866a20b 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -4,8 +4,8 @@ jobs: test: strategy: matrix: - go-version: [1.15.x] - os: [ubuntu-latest] + go-version: [1.15.x, 1.16.x] + os: [ubuntu-latest, macos-latest] runs-on: ${{ matrix.os }} steps: - name: Install Go @@ -14,5 +14,5 @@ jobs: go-version: ${{ matrix.go-version }} - name: Checkout code uses: actions/checkout@v2 - - name: Run Makefile Tests - run: make github-ci \ No newline at end of file + - name: Run Go Tests + run: go test ./... \ No newline at end of file From d19ffd441ba47ad3ef55906ad884099b20cd8dea Mon Sep 17 00:00:00 2001 From: Mario Karagiorgas Date: Mon, 2 Aug 2021 15:18:38 +0300 Subject: [PATCH 28/49] Complete docker makefile --- networks/docker/Makefile | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/networks/docker/Makefile b/networks/docker/Makefile index 54c89c58..30b0ae95 100644 --- a/networks/docker/Makefile +++ b/networks/docker/Makefile @@ -1,6 +1,6 @@ # Makefile for the "emdnode" docker image. -all: emdnode +all: emdnode cosmovisor test-upg emdnode: docker build --tag emoney/emdnode emdnode @@ -8,7 +8,10 @@ emdnode: cosmovisor: docker build cosmovisor --tag emoney/cosmovisor +test-upg: + docker build test-upg --tag emoney/test-upg + # todo (reviewer): please note the rest-server is not a command anymore. Please enable `api` section in `app.toml` instead -.PHONY: all emdnode cosmovisor +.PHONY: all emdnode cosmovisor test-upg From 3f786ac17b61ec549bf6eee66d5a1a093de237a1 Mon Sep 17 00:00:00 2001 From: Mario Karagiorgas Date: Mon, 2 Aug 2021 20:02:52 +0300 Subject: [PATCH 29/49] Authority bdd test fix --- Makefile | 2 +- multisigauthority_test.go | 8 -------- networktest/emcli.go | 1 + 3 files changed, 2 insertions(+), 9 deletions(-) diff --git a/Makefile b/Makefile index 84c79a1a..be2f61b8 100644 --- a/Makefile +++ b/Makefile @@ -90,7 +90,7 @@ test: go test -mod=readonly ./... bdd-test: - go test -mod=readonly -v -p 1 -timeout 1h --tags="bdd" bdd_test.go multisigauthority_test.go authority_test.go market_test.go buyback_test.go capacity_test.go staking_test.go bep3swap_test.go upgrade_test.go + go test -mod=readonly -v -p 1 -timeout 1h --tags="bdd" bdd_test.go multisigauthority_test.go authority_test.go market_test.go buyback_test.go capacity_test.go staking_test.go bep3swap_test.go upgrade_test.go github-ci: build-linux $(MAKE) test diff --git a/multisigauthority_test.go b/multisigauthority_test.go index ae35a723..3b14cd75 100644 --- a/multisigauthority_test.go +++ b/multisigauthority_test.go @@ -101,14 +101,6 @@ var _ = Describe("Authority", func() { ) Expect(err).To(BeNil()) - // create/revoke issuer with both the former and the new authority - // former singlesig first - ok = nt.AuthCreatesIssuer(emcli, keystore.Authority, key1) - Expect(ok).To(BeTrue()) - _, success, err = emcli.AuthorityDestroyIssuer(keystore.Authority, key1) - Expect(success).To(BeTrue()) - Expect(err).ToNot(HaveOccurred()) - // current multisig authority now // create-issuer execAuthMSigTx( diff --git a/networktest/emcli.go b/networktest/emcli.go index 6217c0d3..2fc51d53 100644 --- a/networktest/emcli.go +++ b/networktest/emcli.go @@ -69,6 +69,7 @@ func (cli Emcli) CustomCommand(params ...string) (string, error) { for _, param := range params { if re.MatchString(param) { checkTxRes = false + break } } args := cli.addTransactionFlags(params...) From 7be58577ad63db4e09441004f239c3c9cfe5149f Mon Sep 17 00:00:00 2001 From: Mario Karagiorgas Date: Mon, 2 Aug 2021 23:07:29 +0300 Subject: [PATCH 30/49] Fix Macos Docker linux prefix --- Makefile | 2 +- networks/docker/emdnode/wrapper.sh | 8 ++++---- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/Makefile b/Makefile index be2f61b8..8eddc8c5 100644 --- a/Makefile +++ b/Makefile @@ -66,7 +66,7 @@ install: build-linux: # Linux images for docker-compose # CGO_ENABLED=0 added to solve this issue: https://stackoverflow.com/a/36308464 - LEDGER_ENABLED=false GOOS=linux GOARCH=amd64 $(MAKE) build + BIN_PREFIX=-linux LEDGER_ENABLED=false GOOS=linux GOARCH=amd64 $(MAKE) build docker run --rm --entrypoint cat emoney/cosmovisor /go/bin/cosmovisor > build/cosmovisor chmod +x build/cosmovisor $(MAKE) build-test-upg diff --git a/networks/docker/emdnode/wrapper.sh b/networks/docker/emdnode/wrapper.sh index 042aa644..b88c8699 100755 --- a/networks/docker/emdnode/wrapper.sh +++ b/networks/docker/emdnode/wrapper.sh @@ -7,7 +7,7 @@ ## ## Input parameters ## -BINARY=/emoney/${BINARY:-emd} +BINARY=/emoney/${BINARY:-emd-linux} ID=${ID:-0} LOG=${LOG:-emd.log} ## @@ -30,17 +30,17 @@ export EMDHOME="/emoney/node${ID}" # setup cosmovisor mkdir -p "$EMDHOME/cosmovisor/genesis/bin" -cp /emoney/emd "$EMDHOME/cosmovisor/genesis/bin" +cp /emoney/emd-linux "$EMDHOME/cosmovisor/genesis/bin" export DAEMON_ALLOW_DOWNLOAD_BINARIES=true export DAEMON_RESTART_AFTER_UPGRADE=true export DAEMON_HOME=$EMDHOME # link chain launcher to cosmovisor with linux emd binary -export DAEMON_NAME=emd +export DAEMON_NAME=emd-linux BINARY=/emoney/cosmovisor UPG_LOC="$EMDHOME"/cosmovisor/upgrades/test-upg-0.1.0/bin mkdir -p "$UPG_LOC" -cp /emoney/emdupg "$UPG_LOC"/emd +cp /emoney/emdupg "$UPG_LOC"/emd-linux if [ -d "$(dirname "${EMDHOME}"/"${LOG}")" ]; then "$BINARY" --home "$EMDHOME" "$@" | tee "${EMDHOME}/${LOG}" From 120c14f7e07f379eb519c61e58fe7ab15fad7523 Mon Sep 17 00:00:00 2001 From: Mario Karagiorgas Date: Tue, 3 Aug 2021 22:19:30 +0300 Subject: [PATCH 31/49] Macos and overall fixes for single node test --- Makefile | 24 ++++++++------- networks/docker/emdnode/wrapper.sh | 2 +- networks/docker/test-upg/Dockerfile | 9 ++++-- networks/upg/cpemd | 45 ++++++++++++--------------- networks/upg/cpupgemd | 48 ----------------------------- networks/upg/setcvenv | 29 ----------------- networks/upg/startcv | 37 +++------------------- networks/upg/upg-sched | 33 ++++++++++---------- networks/upg/upg-sched-srv | 20 ++++++++++++ networks/utils/startemd | 14 +++------ 10 files changed, 84 insertions(+), 177 deletions(-) delete mode 100755 networks/upg/cpupgemd delete mode 100755 networks/upg/setcvenv create mode 100755 networks/upg/upg-sched-srv diff --git a/Makefile b/Makefile index 8eddc8c5..b9b59b0f 100644 --- a/Makefile +++ b/Makefile @@ -48,6 +48,14 @@ BUILD_FLAGS := -tags "$(build_tags)" -ldflags '$(ldflags)' build: go build -mod=readonly $(BUILD_FLAGS) -o build/emd$(BIN_PREFIX) ./cmd/emd + +emdupg: + docker run --rm --entrypoint cat emoney/test-upg /go/src/em-ledger/build/emd > "build/emdupg" + chmod +x "build/emdupg" + +cosmovisor: + go install github.com/cosmos/cosmos-sdk/cosmovisor/cmd/cosmovisor@latest + lint: golangci-lint run @@ -69,14 +77,10 @@ build-linux: BIN_PREFIX=-linux LEDGER_ENABLED=false GOOS=linux GOARCH=amd64 $(MAKE) build docker run --rm --entrypoint cat emoney/cosmovisor /go/bin/cosmovisor > build/cosmovisor chmod +x build/cosmovisor - $(MAKE) build-test-upg + docker run --rm --entrypoint cat emoney/test-upg /go/src/em-ledger/build/emd-linux > "build/emdupg-linux" + chmod +x "build/emdupg-linux" -build-test-upg: - # linux upgrade binary for testing cosmovisor upgrade - docker run --rm --entrypoint cat emoney/test-upg /go/src/em-ledger/build/emd > "build/emdupg" - chmod +x "build/emdupg" - -build-all: build-linux +build-all: build-linux emdupg $(MAKE) build build-docker: @@ -112,7 +116,7 @@ license: GO111MODULE=off go get github.com/google/addlicense/ addlicense -f LICENSE . -.PHONY: build build-linux clean test bdd-test build-docker license +.PHONY: build build-linux emdupg cosmovisor clean test bdd-test build-docker license ############################################################################### ### Protobuf ### @@ -141,6 +145,4 @@ proto-lint: proto-check-breaking: @$(DOCKER_BUF) breaking --against-input $(HTTPS_GIT)#branch=master -.PHONY: proto-all proto-gen proto-swagger-gen proto-format proto-lint proto-check-breaking - - +.PHONY: proto-all proto-gen proto-swagger-gen proto-format proto-lint proto-check-breaking \ No newline at end of file diff --git a/networks/docker/emdnode/wrapper.sh b/networks/docker/emdnode/wrapper.sh index b88c8699..0e771f12 100755 --- a/networks/docker/emdnode/wrapper.sh +++ b/networks/docker/emdnode/wrapper.sh @@ -40,7 +40,7 @@ export DAEMON_NAME=emd-linux BINARY=/emoney/cosmovisor UPG_LOC="$EMDHOME"/cosmovisor/upgrades/test-upg-0.1.0/bin mkdir -p "$UPG_LOC" -cp /emoney/emdupg "$UPG_LOC"/emd-linux +cp /emoney/emdupg-linux "$UPG_LOC"/emd-linux if [ -d "$(dirname "${EMDHOME}"/"${LOG}")" ]; then "$BINARY" --home "$EMDHOME" "$@" | tee "${EMDHOME}/${LOG}" diff --git a/networks/docker/test-upg/Dockerfile b/networks/docker/test-upg/Dockerfile index 76d9369f..6b0c8085 100644 --- a/networks/docker/test-upg/Dockerfile +++ b/networks/docker/test-upg/Dockerfile @@ -1,10 +1,13 @@ FROM golang:1.16-buster +ARG OS + RUN cd /go/src && \ git clone https://github.com/e-money/em-ledger.git && \ cd em-ledger && \ git checkout upgrade-emd-test && \ - make - - + make build-linux +# build native binary +WORKDIR /go/src/em-ledger +RUN GOOS='darwin' go build -tags "netgo ledger" -ldflags '-X github.com/cosmos/cosmos-sdk/version.Name=e-money -X github.com/cosmos/cosmos-sdk/version.AppName=emd -X github.com/cosmos/cosmos-sdk/version.Version=test-upg-0.0.1 -X "github.com/cosmos/cosmos-sdk/version.BuildTags=netgo,ledger"' -o build/emd ./cmd/emd \ No newline at end of file diff --git a/networks/upg/cpemd b/networks/upg/cpemd index 9b4bf51e..cfadabf7 100755 --- a/networks/upg/cpemd +++ b/networks/upg/cpemd @@ -1,9 +1,9 @@ #!/bin/zsh -# Copying the present/soon to be legacy binary in the cosmovisor genesis folder +# Copying the upgrade and present/soon to be legacy binary in the cosmovisor genesis folder # Note the cosmovisor folder structure before the upgrade -# em-ledger/networks/.emd/cosmovisor -# ├── current -> /home/user/go/src/github.com/e-money/em-ledger/networks/.emd/cosmovisor/genesis/bin/emd +# em-ledger/networks/upg/.emd/cosmovisor +# ├── current -> /Users/user/go/src/github.com/e-money/em-ledger/networks/upg/.emd/cosmovisor/genesis/bin/emd # ├── genesis # │ └── bin # │ └── emd @@ -17,31 +17,24 @@ set -e # cosmovisor constant export DAEMON_NAME=emd -# locate .emd home folder starting either in em-ledger/networks or em-ledger/networks/upg -if [[ -d $PWD/.emd ]]; then - export DAEMON_HOME=$PWD/.emd - pushd -q ../ - EM_LEDGER_LOC=$PWD - popd -q -elif [[ -d ../.emd ]]; then - pushd -q ../ - export DAEMON_HOME=$PWD/.emd - pushd -q ../ - EM_LEDGER_LOC=$PWD - popd -q - popd -q -else - echo ".emd folder not found neither in $PWD nor in parent. run startemd.sh to create node" - exit 1 -fi +mkdir -p .emd +export DAEMON_HOME=$PWD/.emd +pushd -q ../../ +EM_LEDGER_LOC=$PWD +popd -q echo "node home: $DAEMON_HOME" # copy soon to be the legacy binary -mkdir -p "$EM_LEDGER_LOC"/networks/.emd/cosmovisor/genesis/bin -cp "$EM_LEDGER_LOC"/build/emd "$EM_LEDGER_LOC"/networks/.emd/cosmovisor/genesis/bin -mkdir -p "$EM_LEDGER_LOC"/networks/.emd/cosmovisor/upgrades - -echo "legacy or current binary in $EM_LEDGER_LOC/networks/.emd/cosmovisor/genesis/bin" - +COSMOVISOR_HOME="$EM_LEDGER_LOC"/networks/upg/.emd/cosmovisor +mkdir -p "$COSMOVISOR_HOME"/genesis/bin +cp "$EM_LEDGER_LOC"/build/emd "$COSMOVISOR_HOME"/genesis/bin +UPG_LOC="$COSMOVISOR_HOME"/upgrades/test-upg-0.1.0/bin +mkdir -p "$UPG_LOC" +cp "$EM_LEDGER_LOC"/build/emdupg "$UPG_LOC"/emd + +echo "legacy or current binary:" +ls "$COSMOVISOR_HOME"/genesis/bin/emd +echo "upgrade binary:" +ls "$UPG_LOC"/emd echo "current version: $(cosmovisor version)" \ No newline at end of file diff --git a/networks/upg/cpupgemd b/networks/upg/cpupgemd deleted file mode 100755 index 41e1e02b..00000000 --- a/networks/upg/cpupgemd +++ /dev/null @@ -1,48 +0,0 @@ -#!/bin/zsh - -# Copying test upgrade binary in cosmovisor upgrade folder -# This script is optional and not-needed if exercising the auto -# download option with DAEMON_RESTART_AFTER_UPGRADE=true -# -- or using the http download option as a backup option. - -# em-ledger/networks/.emd/cosmovisor -# ├── current -> /home/user/go/src/github.com/e-money/em-ledger/networks/.emd/cosmovisor/genesis/bin/emd -# ├── genesis -# │ └── bin -# │ └── emd -# └── upgrades -# └── test-upg-0.1.0 -# └── bin -# └── emd - -set -e - -UPG_EMD_LOC=/srv/ftp/test-upg-0.1.0 - -# cosmovisor constants -export DAEMON_NAME=emd - -# locate .emd home folder starting either in em-ledger/networks or em-ledger/networks/upg -if [[ -d $PWD/.emd ]]; then - export DAEMON_HOME=$PWD/.emd -elif [[ -d ../.emd ]]; then - pushd -q ../ - export DAEMON_HOME=$PWD/.emd - popd -q -else - echo ".emd folder not found neither in $PWD nor in parent. run startemd.sh to create node" - exit 1 -fi - -echo "node home: $DAEMON_HOME" - -COSMOVISOR_UPG_LOC="$DAEMON_HOME"/networks/.emd/cosmovisor/upgrades/test-upg-0.1.0/bin -echo "copying $UPG_EMD_LOC/emd -> $COSMOVISOR_UPG_LOC" - -# copy the upgrade binary -mkdir -p "$COSMOVISOR_UPG_LOC" -cp $UPG_EMD_LOC/emd "$COSMOVISOR_UPG_LOC" - -echo "copied upgrade binary in $COSMOVISOR_UPG_LOC" - -echo "current version: $(cosmovisor version)" \ No newline at end of file diff --git a/networks/upg/setcvenv b/networks/upg/setcvenv deleted file mode 100755 index 9cdf900b..00000000 --- a/networks/upg/setcvenv +++ /dev/null @@ -1,29 +0,0 @@ -#!/bin/zsh - -set -e - -##### cosmovisor env vars setup - -export DAEMON_NAME=emd -export DAEMON_ALLOW_DOWNLOAD_BINARIES=true -export DAEMON_RESTART_AFTER_UPGRADE=true - -# locate emd binary starting either in em-ledger/networks or em-ledger/networks/utils -if [[ -f $PWD/../../build/emd ]]; then - pushd ../ # to get absolute value - export DAEMON_HOME=$PWD/.emd - # return to networks - popd -q -elif [[ -f $PWD/../build/emd ]]; then - export DAEMON_HOME=$PWD/.emd -else - echo "emd binary not found neither in $PWD nor in parent. run make to create binary" - exit 1 -fi - -export EMD="$DAEMON_HOME"/cosmovisor/current/bin/emd - -echo "\$EMD: $(ls "$EMD")" -echo "node home: $DAEMON_HOME" - -echo "cosmovisor version: $(cosmovisor version)" \ No newline at end of file diff --git a/networks/upg/startcv b/networks/upg/startcv index 4f9e0065..79c336f1 100755 --- a/networks/upg/startcv +++ b/networks/upg/startcv @@ -6,21 +6,8 @@ set -ev export DAEMON_NAME=emd export DAEMON_ALLOW_DOWNLOAD_BINARIES=true export DAEMON_RESTART_AFTER_UPGRADE=true -# The following is setup at the end of this script -# export DAEMON_HOME= -# -if [[ -f ./cpemd ]]; then - ./cpemd - set +e - rm ../.emd/cosmovisor/current - set +e -else - upg/cpemd - set +e - rm .emd/cosmovisor/current - set -e -fi +./cpemd # optionally uncomment to copy future upgrade binary in location if # auto-downloading is not available as a primary or none at all @@ -28,30 +15,14 @@ fi # locally: DAEMON_RESTART_AFTER_UPGRADE=true #./cpupgemd -# locate emd binary starting either in em-ledger/networks or em-ledger/networks/utils -if [[ -f $PWD/../../build/emd ]]; then - pushd ../ - EMD_NODE=$PWD/.emd - pushd -q ../build - EMD=$PWD/emd - # return to networks - popd -q -elif [[ -f $PWD/../build/emd ]]; then - EMD_NODE=$PWD/.emd - pushd -q ../build - EMD=$PWD/emd - popd -q -else - echo "emd binary not found neither in $PWD nor in parent. run make to create binary" - exit 1 -fi +EMD_NODE=$PWD/.emd +EMD=../../build/emd -# destructive # do not do this in production +# do not delete cosmovisor if it exists rm -rf "$EMD_NODE"/config rm -rf "$EMD_NODE"/data rm -rf "$EMD_NODE"/keyring-test -# do not delete cosmovisor if it exists $EMD unsafe-reset-all --home=$EMD_NODE diff --git a/networks/upg/upg-sched b/networks/upg/upg-sched index f52c60a2..802e91f4 100755 --- a/networks/upg/upg-sched +++ b/networks/upg/upg-sched @@ -1,21 +1,22 @@ -#!/bin/zsh +#!/bin/bash + +# $1 : choose a future block height to upgrade set -e -# Preconditions: -# git checkout upgrade-emd-test -# make -# copy to a convenient location -# mkdir -p /srv/upgemd/test-upg-0.1.0 -# cp build/emd /srv/upgemd/test-upg-0.1.0 -# zip /srv/upgemd/test-upg-0.1.0/emd.zip /srv/upgemd/test-upg-0.1.0/emd -# save sha value to clipboard -# sha256sum /srv/upgemd/test-upg-0.1.0/emd.zip | xsel -i -b -# cd /srv/upgemd -# start a web server in the -# python3 -m http.server 8765 +EMD=.emd/cosmovisor/current/bin/emd + +$EMD version +$EMD q authority gas-prices --home=.emd --node tcp://localhost:26657 --chain-id test +$EMD q authority upg-plan --home=.emd --node tcp://localhost:26657 --chain-id test + +# schedule upgrade +$EMD tx authority upg-schedule authoritykey test-upg-0.1.0 --upg-height "$1" --yes --from authoritykey --home=".emd" --node tcp://localhost:26657 --chain-id test --keyring-backend test -EMD="$DAEMON_HOME"/cosmovisor/current/bin/emd +# confirm upg plan +$EMD q authority upg-plan --home=.emd --node tcp://localhost:26657 --chain-id test -# choose a future nearby -$EMD tx authority upg-schedule authoritykey test-upg-0.1.0 --upg-height 4 --upg-info '{"binaries":{"linux/amd64":"http://localhost:8765/test-upg-0.1.0/emd.zip?checksum=sha256:cadd5b52fe90a04e20b2cbb93291b0d1d0204f17b64b2215eb09f5dc78a127f1"}}' --yes --from authoritykey --home="$DAEMON_HOME" --node tcp://localhost:26657 --chain-id test --keyring-backend test \ No newline at end of file +# ---------- after upgrade ---------> +$EMD q authority gas-prices --home=.emd --node tcp://localhost:26657 --chain-id test +#$EMD q authority upg-plan --home=.emd --node tcp://localhost:26657 --chain-id test # is nil again +$EMD version # test-upg-0.0.1 diff --git a/networks/upg/upg-sched-srv b/networks/upg/upg-sched-srv new file mode 100755 index 00000000..ee8020b4 --- /dev/null +++ b/networks/upg/upg-sched-srv @@ -0,0 +1,20 @@ +#!/bin/bash + +set -ev + +# Preconditions server auto download: +# export DAEMON_ALLOW_DOWNLOAD_BINARIES=true +# make emdupg +# mkdir -p /srv/upgemd/test-upg-0.1.0 +# cp build/emdupg /srv/upgemd/test-upg-0.1.0 +# zip /srv/upgemd/test-upg-0.1.0/emd.zip /srv/upgemd/test-upg-0.1.0/emd +# save sha value to clipboard +# sha256sum /srv/upgemd/test-upg-0.1.0/emd.zip | xsel -i -b +# cd /srv/upgemd +# start a web server in the +# python3 -m http.server 8765 + +EMD=.emd/cosmovisor/current/bin/emd + +# choose a future height +$EMD tx authority upg-schedule authoritykey test-upg-0.1.0 --upg-height 6 --upg-info '{"binaries":{"linux/amd64":"http://localhost:8765/test-upg-0.1.0/emd.zip?checksum=sha256:cadd5b52fe90a04e20b2cbb93291b0d1d0204f17b64b2215eb09f5dc78a127f1"}}' --yes --from authoritykey --home="$DAEMON_HOME" --node tcp://localhost:26657 --chain-id test --keyring-backend test \ No newline at end of file diff --git a/networks/utils/startemd b/networks/utils/startemd index a747f5b9..3c10687e 100755 --- a/networks/utils/startemd +++ b/networks/utils/startemd @@ -2,21 +2,15 @@ set -ev -# locate emd binary starting either in em-ledger/networks or em-ledger/networks/utils +# locate emd binary if [[ -f $PWD/../../build/emd ]]; then - pushd ../ EMD_NODE=$PWD/.emd - pushd -q ../build - EMD=$PWD/emd - # return to networks - popd -q -elif [[ -f $PWD/../build/emd ]]; then - EMD_NODE=$PWD/.emd - pushd -q ../build + pushd -q ../../build + # save absolute path of emd required by cosmovisor EMD=$PWD/emd popd -q else - echo "emd binary not found neither in $PWD nor in parent. run make to create binary" + echo "emd binary not found in $PWD. Please run make to create the emd binary" exit 1 fi From 3c917cf1aa9989b13564a1652ac3d24b3cd0e217 Mon Sep 17 00:00:00 2001 From: Mario Karagiorgas Date: Wed, 4 Aug 2021 10:03:17 +0300 Subject: [PATCH 32/49] Add Readme.md --- networks/upg/Readme.md | 75 ++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 75 insertions(+) create mode 100644 networks/upg/Readme.md diff --git a/networks/upg/Readme.md b/networks/upg/Readme.md new file mode 100644 index 00000000..246e0816 --- /dev/null +++ b/networks/upg/Readme.md @@ -0,0 +1,75 @@ +## Guide for testing the upgrade module +#### Overview +This document is an interactive guide for testing the upgrade module with a single docker-less e-money node. + +Please note if you'd rather test the upgrade module within the **e-money local-testnet** run: + +```shell +cd em-ledger +make build-docker +make build-linux +go test -v --tags="bdd" bdd_test.go upgrade_test.go +``` + +Two new docker images defined in em-ledger/networks/docker: + +1. `emoney/cosmovisor` which builds a linux cosmovisor binary for use within the e-money local-testnet. + +2. `emoney/test-upg` which builds a test upgrade mode with a trivial upgrade module handler changing the gas-fees as part of the upgrade migration process. + +Note these scripts at **em-ledger/networks/upg**: +* `Readme.md` (this doc) +* `startcv` (starts a single e-money node with cosmovisor) +* `upg-sched` schedule an upgrade by passing the upgrade block height +* `upg-sched-srv` optional documentation setup and schedule command for upgrading with server downloaded binary + +### Components installation +Build the revamped Docker, Linux artifacts +```shell +make build-docker +make build-all +``` +As a result these artifacts generate within the build folder +```shell +.rwxrwxr-x 1 15M usr 3 Aug 13:06 cosmovisor +.rwxrwxr-x 1 60M usr 3 Aug 13:06 emd +.rwxrwxr-x 1 61M usr 3 Aug 13:06 emd-linux +.rwxrwxr-x 1 60M usr 3 Aug 13:06 emdupg +.rwxrwxr-x 1 60M usr 3 Aug 13:06 emdupg-linux +``` +`emdupg` is the *upgrade* emd binary* with the migration handler setting the gas-prices upon the chain upgrade. + +**The code for the upgrade handler is checked-in the *`upgrade-emd-test`* branch.* +### Install cosmovisor + +#### For interactive testing and general use +Please note, the cosmovisor binary built above is a `linux` binary for use within the *local-testnet* +```shell +go install github.com/cosmos/cosmos-sdk/cosmovisor/cmd/cosmovisor@latest + +# test installation success +cosmovisor version +DAEMON_NAME is not set +``` + +### Launch network to upgrade +```shell +# Optionally in a separate pane or terminal tab +cd networks/upg +./startcv + +cd networks/upg +# schedule upgrade at future block height 6 +# if you overshoot retry with lower block height +./upg-sched 6 + +# wait for the upgrade +# check version, upgraded gas-prices +.emd/cosmovisor/current/bin/emd verion # test-upg-0.0.1 +.emd/cosmovisor/current/bin/emd q authority gas-prices +min_gas_prices: +- amount: "1.000000000000000000" + denom: ungm + +#success! +``` \ No newline at end of file From 5c1bc10f411dd121df32ca1b24755858e38f6fcf Mon Sep 17 00:00:00 2001 From: Martin Dyring-Andersen Date: Thu, 5 Aug 2021 11:34:59 +0200 Subject: [PATCH 33/49] Use uppercase README convention --- networks/upg/{Readme.md => README.md} | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) rename networks/upg/{Readme.md => README.md} (98%) diff --git a/networks/upg/Readme.md b/networks/upg/README.md similarity index 98% rename from networks/upg/Readme.md rename to networks/upg/README.md index 246e0816..7b5f03ea 100644 --- a/networks/upg/Readme.md +++ b/networks/upg/README.md @@ -18,7 +18,7 @@ Two new docker images defined in em-ledger/networks/docker: 2. `emoney/test-upg` which builds a test upgrade mode with a trivial upgrade module handler changing the gas-fees as part of the upgrade migration process. Note these scripts at **em-ledger/networks/upg**: -* `Readme.md` (this doc) +* `README.md` (this doc) * `startcv` (starts a single e-money node with cosmovisor) * `upg-sched` schedule an upgrade by passing the upgrade block height * `upg-sched-srv` optional documentation setup and schedule command for upgrading with server downloaded binary From 6aca12f9c4fe685c2801bfe2a0ddbb1462d7cbf4 Mon Sep 17 00:00:00 2001 From: Martin Dyring-Andersen Date: Thu, 5 Aug 2021 11:59:37 +0200 Subject: [PATCH 34/49] Minor naming convention changes --- networks/upg/upg-sched | 8 +++---- networks/upg/upg-sched-srv | 2 +- networktest/emcli.go | 6 ++--- x/authority/client/cli/query.go | 2 +- x/authority/client/cli/tx.go | 40 ++++++++++++++++----------------- 5 files changed, 29 insertions(+), 29 deletions(-) diff --git a/networks/upg/upg-sched b/networks/upg/upg-sched index 802e91f4..501815ae 100755 --- a/networks/upg/upg-sched +++ b/networks/upg/upg-sched @@ -8,15 +8,15 @@ EMD=.emd/cosmovisor/current/bin/emd $EMD version $EMD q authority gas-prices --home=.emd --node tcp://localhost:26657 --chain-id test -$EMD q authority upg-plan --home=.emd --node tcp://localhost:26657 --chain-id test +$EMD q authority upgrade-plan --home=.emd --node tcp://localhost:26657 --chain-id test # schedule upgrade -$EMD tx authority upg-schedule authoritykey test-upg-0.1.0 --upg-height "$1" --yes --from authoritykey --home=".emd" --node tcp://localhost:26657 --chain-id test --keyring-backend test +$EMD tx authority schedule-upgrade authoritykey test-upg-0.1.0 --upgrade-height "$1" --yes --from authoritykey --home=".emd" --node tcp://localhost:26657 --chain-id test --keyring-backend test # confirm upg plan -$EMD q authority upg-plan --home=.emd --node tcp://localhost:26657 --chain-id test +$EMD q authority upgrade-plan --home=.emd --node tcp://localhost:26657 --chain-id test # ---------- after upgrade ---------> $EMD q authority gas-prices --home=.emd --node tcp://localhost:26657 --chain-id test -#$EMD q authority upg-plan --home=.emd --node tcp://localhost:26657 --chain-id test # is nil again +#$EMD q authority upgrade-plan --home=.emd --node tcp://localhost:26657 --chain-id test # is nil again $EMD version # test-upg-0.0.1 diff --git a/networks/upg/upg-sched-srv b/networks/upg/upg-sched-srv index ee8020b4..f5979927 100755 --- a/networks/upg/upg-sched-srv +++ b/networks/upg/upg-sched-srv @@ -17,4 +17,4 @@ set -ev EMD=.emd/cosmovisor/current/bin/emd # choose a future height -$EMD tx authority upg-schedule authoritykey test-upg-0.1.0 --upg-height 6 --upg-info '{"binaries":{"linux/amd64":"http://localhost:8765/test-upg-0.1.0/emd.zip?checksum=sha256:cadd5b52fe90a04e20b2cbb93291b0d1d0204f17b64b2215eb09f5dc78a127f1"}}' --yes --from authoritykey --home="$DAEMON_HOME" --node tcp://localhost:26657 --chain-id test --keyring-backend test \ No newline at end of file +$EMD tx authority schedule-upgrade authoritykey test-upg-0.1.0 --upgrade-height 6 --upgrade-info '{"binaries":{"linux/amd64":"http://localhost:8765/test-upg-0.1.0/emd.zip?checksum=sha256:cadd5b52fe90a04e20b2cbb93291b0d1d0204f17b64b2215eb09f5dc78a127f1"}}' --yes --from authoritykey --home="$DAEMON_HOME" --node tcp://localhost:26657 --chain-id test --keyring-backend test \ No newline at end of file diff --git a/networktest/emcli.go b/networktest/emcli.go index 2fc51d53..412c4e46 100644 --- a/networktest/emcli.go +++ b/networktest/emcli.go @@ -52,8 +52,8 @@ func (cli Emcli) AuthorityCreateIssuer(authority, issuer Key, denoms ...string) } func (cli Emcli) AuthorityUpgSched(authority Key, planName string, height int64) (string, bool, error) { - args := cli.addTransactionFlags("tx", "authority", "upg-schedule", - authority.name, planName, "--upg-height", strconv.FormatInt(height, 10)) + args := cli.addTransactionFlags("tx", "authority", "schedule-upgrade", + authority.name, planName, "--upgrade-height", strconv.FormatInt(height, 10)) return execCmdWithInput(args, KeyPwd) } @@ -89,7 +89,7 @@ func (cli Emcli) AuthoritySetMinGasPrices(authority Key, minGasPrices string, pa } func (cli Emcli) QueryUpgSched() ([]byte, error) { - args := cli.addQueryFlags("query", "authority", "upg-plan") + args := cli.addQueryFlags("query", "authority", "upgrade-plan") return execCmdAndCollectResponse(args) } diff --git a/x/authority/client/cli/query.go b/x/authority/client/cli/query.go index faeb6237..6aacfccf 100644 --- a/x/authority/client/cli/query.go +++ b/x/authority/client/cli/query.go @@ -54,7 +54,7 @@ func GetGasPricesCmd() *cobra.Command { func GetUpgradePlanCmd() *cobra.Command { cmd := &cobra.Command{ - Use: "upg-plan", + Use: "upgrade-plan", Short: "Query the current upgrade plan", Args: cobra.NoArgs, RunE: func(cmd *cobra.Command, _ []string) error { diff --git a/x/authority/client/cli/tx.go b/x/authority/client/cli/tx.go index 38f44026..ce4815fa 100644 --- a/x/authority/client/cli/tx.go +++ b/x/authority/client/cli/tx.go @@ -180,9 +180,9 @@ For a 24-hour grace period the former authority key is equivalent to the new one } const ( - UpgHeight = "upg-height" - UpgTime = "upg-time" - UpgInfo = "upg-info" + UpgHeight = "upgrade-height" + UpgTime = "upgrade-time" + UpgInfo = "upgrade-info" ) func GetCmdScheduleUpgrade() *cobra.Command { @@ -192,15 +192,15 @@ func GetCmdScheduleUpgrade() *cobra.Command { ) cmd := &cobra.Command{ - Use: "upg-schedule [authority_key_or_address] plan_name", - Short: "Schedule a software upgrade.", - Example: `emd tx authority upg-schedule --upg_height 2001 --from emoney1xue7fm6es84jze49grm4slhlmr4ffz8a3u7g3t 0.43 -emd tx upg-schedule 'New Staking Rewards 36%' --upg_time 1628956125 --from emoney1xue7fm6es84jze49grm4slhlmr4ffz8a3u7g3t # Unix seconds for 2021-08-14 15:48:45 +0000 UTC -emd tx upg-schedule sdk-v0.43.0 --upg_height 2001 --from emoney1xue7fm6es84jze49grm4slhlmr4ffz8a3u7g3t --upg_info "https://e-money.com/mainnet-099-info.json?checksum=sha256:deaaa99fda9407c4dbe1d04bd49bab0cc3c1dd76fa392cd55a9425be074af01e"`, + Use: "schedule-upgrade [authority_key_or_address] plan_name", + Short: "Schedule a software upgrade", + Example: `emd tx authority schedule-upgrade someplan --upgrade-height 2001 --from emoney1xue7fm6es84jze49grm4slhlmr4ffz8a3u7g3t 0.43 +emd tx authority schedule-upgrade 'New Staking Rewards 36%' --upgrade-time 1628956125 --from emoney1xue7fm6es84jze49grm4slhlmr4ffz8a3u7g3t # Unix seconds for 2021-08-14 15:48:45 +0000 UTC +emd tx authority schedule-upgrade sdk-v0.43.0 --upgrade-height 2001 --from emoney1xue7fm6es84jze49grm4slhlmr4ffz8a3u7g3t --upgrade-info '{"binaries":{"linux/amd64":"http://localhost:8765/test-upg-0.1.0/emd.zip?checksum=sha256:cadd5b52fe90a04e20b2cbb93291b0d1d0204f17b64b2215eb09f5dc78a127f1"}}'`, Long: `Schedule a software upgrade by submitting a unique plan name that - has been used before with either an absolute block height or block time. An + has not been used before with either an absolute block height or block time. An upgrade handler should be defined at the upgraded binary. Optionally If you set DAEMON_ALLOW_DOWNLOAD_BINARIES=on pass -the upgraded binary download url with the --upg-info flag i.e., --upg-info 'https://example.com/testnet-1001-info.json?checksum=sha256:deaaa99fda9407c4dbe1d04bd49bab0cc3c1dd76fa392cd55a9425be074af01e'`, +the upgraded binary download url with the --upgrade-info flag i.e., --upgrade-info '{"binaries":{"linux/amd64":"http://localhost:8765/test-upg-0.1.0/emd.zip?checksum=sha256:cadd5b52fe90a04e20b2cbb93291b0d1d0204f17b64b2215eb09f5dc78a127f1"}}'`, Args: cobra.RangeArgs(1, 2), RunE: func(cmd *cobra.Command, args []string) error { err := cmd.Flags().Set(flags.FlagFrom, args[0]) @@ -239,12 +239,12 @@ the upgraded binary download url with the --upg-info flag i.e., --upg-info 'http }, } f := cmd.Flags() - f.Int64VarP(&upgHeightVal, UpgHeight, "n", 0, "upgrade block height number") + f.Int64VarP(&upgHeightVal, UpgHeight, "n", 0, "Upgrade block height number") f.Int64VarP( &upgTimeSecsVal, UpgTime, "t", 0, "upgrade block time (in Unix seconds)", ) f.StringVarP( - &upgInfoVal, UpgInfo, "i", "", "upgrade info", + &upgInfoVal, UpgInfo, "i", "", "Upgrade info", ) flags.AddTxFlagsToCmd(cmd) @@ -253,9 +253,9 @@ the upgraded binary download url with the --upg-info flag i.e., --upg-info 'http func GetCmdApplyUpgrade() *cobra.Command { const ( - upgHeight = "upg-height" - upgTime = "upg-time" - upgInfo = "upg-info" + upgHeight = "upgrade-height" + upgTime = "upgrade-time" + upgInfo = "upgrade-info" ) var ( @@ -264,11 +264,11 @@ func GetCmdApplyUpgrade() *cobra.Command { ) cmd := &cobra.Command{ - Use: "upg-apply [authority_key_or_address] plan_name", - Short: "Apply a software upgrade.", - Example: `emd tx authority upg-apply 0.43 --upg_height 2001 --from emoney1xue7fm6es84jze49grm4slhlmr4ffz8a3u7g3t -emd tx upg-apply 'New Staking Rewards 36%' --upg_time 1628956125 --from emoney1xue7fm6es84jze49grm4slhlmr4ffz8a3u7g3t # Unix seconds for 2021-08-14 15:48:45 +0000 UTC -emd tx upg-apply sdk-v0.43.0 --upg_height 2001 --from emoney1xue7fm6es84jze49grm4slhlmr4ffz8a3u7g3t --upg_info "https://e-money.com/mainnet-099-info.json?checksum=sha256:deaaa99fda9407c4dbe1d04bd49bab0cc3c1dd76fa392cd55a9425be074af01e"`, + Use: "apply-upgrade [authority_key_or_address] plan_name", + Short: "Apply a software upgrade", + Example: `emd tx authority apply-upgrade 0.43 --upgrade-height 2001 --from emoney1xue7fm6es84jze49grm4slhlmr4ffz8a3u7g3t +emd tx authority apply-upgrade 'New Staking Rewards 36%' --upgrade-time 1628956125 --from emoney1xue7fm6es84jze49grm4slhlmr4ffz8a3u7g3t # Unix seconds for 2021-08-14 15:48:45 +0000 UTC +emd tx authority apply-upgrade sdk-v0.43.0 --upgrade-height 2001 --from emoney1xue7fm6es84jze49grm4slhlmr4ffz8a3u7g3t --upgrade-info "https://e-money.com/mainnet-099-info.json?checksum=sha256:deaaa99fda9407c4dbe1d04bd49bab0cc3c1dd76fa392cd55a9425be074af01e"`, Long: `Apply a software upgrade by submitting an already scheduled plan. An upgrade handler should have been submitted already.`, Args: cobra.RangeArgs(1, 2), RunE: func(cmd *cobra.Command, args []string) error { From 430144f2b8f66a53469b6d1af3182c5e907d00a3 Mon Sep 17 00:00:00 2001 From: Mario Karagiorgas Date: Thu, 5 Aug 2021 15:03:56 +0300 Subject: [PATCH 35/49] Remove ApplyUpgrade() from cli, gRPC --- docs/proto/em/proto-docs.md | 29 -- proto/em/authority/v1/tx.proto | 14 +- x/authority/client/cli/tx.go | 70 ----- x/authority/handler.go | 4 - x/authority/keeper/msg_server.go | 23 -- x/authority/types/codec.go | 2 - x/authority/types/msgs.go | 29 -- x/authority/types/tx.pb.go | 464 +++---------------------------- 8 files changed, 43 insertions(+), 592 deletions(-) diff --git a/docs/proto/em/proto-docs.md b/docs/proto/em/proto-docs.md index 58c031cd..a2f746b1 100644 --- a/docs/proto/em/proto-docs.md +++ b/docs/proto/em/proto-docs.md @@ -20,8 +20,6 @@ - [Query](#em.authority.v1.Query) - [em/authority/v1/tx.proto](#em/authority/v1/tx.proto) - - [MsgApplyUpgrade](#em.authority.v1.MsgApplyUpgrade) - - [MsgApplyUpgradeResponse](#em.authority.v1.MsgApplyUpgradeResponse) - [MsgCreateIssuer](#em.authority.v1.MsgCreateIssuer) - [MsgCreateIssuerResponse](#em.authority.v1.MsgCreateIssuerResponse) - [MsgDestroyIssuer](#em.authority.v1.MsgDestroyIssuer) @@ -315,32 +313,6 @@ - - -### MsgApplyUpgrade - - - -| Field | Type | Label | Description | -| ----- | ---- | ----- | ----------- | -| `authority` | [string](#string) | | | -| `plan` | [cosmos.upgrade.v1beta1.Plan](#cosmos.upgrade.v1beta1.Plan) | | | - - - - - - - - -### MsgApplyUpgradeResponse - - - - - - - ### MsgCreateIssuer @@ -495,7 +467,6 @@ | `SetGasPrices` | [MsgSetGasPrices](#em.authority.v1.MsgSetGasPrices) | [MsgSetGasPricesResponse](#em.authority.v1.MsgSetGasPricesResponse) | | | | `ReplaceAuthority` | [MsgReplaceAuthority](#em.authority.v1.MsgReplaceAuthority) | [MsgReplaceAuthorityResponse](#em.authority.v1.MsgReplaceAuthorityResponse) | | | | `ScheduleUpgrade` | [MsgScheduleUpgrade](#em.authority.v1.MsgScheduleUpgrade) | [MsgScheduleUpgradeResponse](#em.authority.v1.MsgScheduleUpgradeResponse) | | | -| `ApplyUpgrade` | [MsgApplyUpgrade](#em.authority.v1.MsgApplyUpgrade) | [MsgApplyUpgradeResponse](#em.authority.v1.MsgApplyUpgradeResponse) | | | diff --git a/proto/em/authority/v1/tx.proto b/proto/em/authority/v1/tx.proto index a52598d6..1dd46a20 100644 --- a/proto/em/authority/v1/tx.proto +++ b/proto/em/authority/v1/tx.proto @@ -18,8 +18,6 @@ service Msg { rpc ReplaceAuthority(MsgReplaceAuthority) returns (MsgReplaceAuthorityResponse); rpc ScheduleUpgrade(MsgScheduleUpgrade) returns (MsgScheduleUpgradeResponse); - - rpc ApplyUpgrade(MsgApplyUpgrade) returns (MsgApplyUpgradeResponse); } message MsgCreateIssuer { @@ -66,14 +64,4 @@ message MsgScheduleUpgrade { ]; } -message MsgScheduleUpgradeResponse {} - -message MsgApplyUpgrade { - string authority = 1 [ (gogoproto.moretags) = "yaml:\"authority\"" ]; - cosmos.upgrade.v1beta1.Plan plan = 2 [ - (gogoproto.moretags) = "yaml:\"plan\"", - (gogoproto.nullable) = false - ]; -} - -message MsgApplyUpgradeResponse {} \ No newline at end of file +message MsgScheduleUpgradeResponse {} \ No newline at end of file diff --git a/x/authority/client/cli/tx.go b/x/authority/client/cli/tx.go index ce4815fa..eff521df 100644 --- a/x/authority/client/cli/tx.go +++ b/x/authority/client/cli/tx.go @@ -32,7 +32,6 @@ func GetTxCmd() *cobra.Command { getCmdSetGasPrices(), GetCmdReplaceAuthority(), GetCmdScheduleUpgrade(), - GetCmdApplyUpgrade(), ) return authorityCmds @@ -251,75 +250,6 @@ the upgraded binary download url with the --upgrade-info flag i.e., --upgrade-in return cmd } -func GetCmdApplyUpgrade() *cobra.Command { - const ( - upgHeight = "upgrade-height" - upgTime = "upgrade-time" - upgInfo = "upgrade-info" - ) - - var ( - upgHeightVal, upgTimeSecsVal int64 - upgInfoVal string - ) - - cmd := &cobra.Command{ - Use: "apply-upgrade [authority_key_or_address] plan_name", - Short: "Apply a software upgrade", - Example: `emd tx authority apply-upgrade 0.43 --upgrade-height 2001 --from emoney1xue7fm6es84jze49grm4slhlmr4ffz8a3u7g3t -emd tx authority apply-upgrade 'New Staking Rewards 36%' --upgrade-time 1628956125 --from emoney1xue7fm6es84jze49grm4slhlmr4ffz8a3u7g3t # Unix seconds for 2021-08-14 15:48:45 +0000 UTC -emd tx authority apply-upgrade sdk-v0.43.0 --upgrade-height 2001 --from emoney1xue7fm6es84jze49grm4slhlmr4ffz8a3u7g3t --upgrade-info "https://e-money.com/mainnet-099-info.json?checksum=sha256:deaaa99fda9407c4dbe1d04bd49bab0cc3c1dd76fa392cd55a9425be074af01e"`, - Long: `Apply a software upgrade by submitting an already scheduled plan. An upgrade handler should have been submitted already.`, - Args: cobra.RangeArgs(1, 2), - RunE: func(cmd *cobra.Command, args []string) error { - err := cmd.Flags().Set(flags.FlagFrom, args[0]) - if err != nil { - return err - } - - if err := validateUpgFlags( - upgHeight, upgHeightVal, upgTime, upgTimeSecsVal, - ); err != nil { - return err - } - - upgTimeVal := time.Unix(upgTimeSecsVal, 0) - - clientCtx, err := client.GetClientTxContext(cmd) - if err != nil { - return err - } - - msg := &types.MsgApplyUpgrade{ - Authority: clientCtx.GetFromAddress().String(), - Plan: upgtypes.Plan{ - Name: args[1], - Time: upgTimeVal, - Height: upgHeightVal, - Info: upgInfoVal, - }, - } - - if err := msg.ValidateBasic(); err != nil { - return err - } - - return tx.GenerateOrBroadcastTxCLI(clientCtx, cmd.Flags(), msg) - }, - } - f := cmd.Flags() - f.Int64VarP(&upgHeightVal, upgHeight, "n", 0, "upgrade block height number") - f.Int64VarP( - &upgTimeSecsVal, upgTime, "t", 0, "upgrade block time (in Unix seconds)", - ) - f.StringVarP( - &upgInfoVal, upgInfo, "i", "", "upgrade info", - ) - - flags.AddTxFlagsToCmd(cmd) - return cmd -} - func validateUpgFlags( upgHeight string, upgHeightVal int64, upgTime string, timeVal int64, ) error { diff --git a/x/authority/handler.go b/x/authority/handler.go index d70eb213..f39a0f92 100644 --- a/x/authority/handler.go +++ b/x/authority/handler.go @@ -40,10 +40,6 @@ func newHandler(k Keeper) sdk.Handler { res, err := msgServer.ScheduleUpgrade(sdk.WrapSDKContext(ctx), msg) return sdk.WrapServiceResult(ctx, res, err) - case *types.MsgApplyUpgrade: - res, err := msgServer.ApplyUpgrade(sdk.WrapSDKContext(ctx), msg) - return sdk.WrapServiceResult(ctx, res, err) - default: return nil, sdkerrors.Wrapf(sdkerrors.ErrUnknownRequest, "unrecognized %s message type: %T", ModuleName, msg) } diff --git a/x/authority/keeper/msg_server.go b/x/authority/keeper/msg_server.go index 212e1a2e..740d1342 100644 --- a/x/authority/keeper/msg_server.go +++ b/x/authority/keeper/msg_server.go @@ -18,7 +18,6 @@ type authorityKeeper interface { replaceAuthority(ctx sdk.Context, authority, newAuthority sdk.AccAddress) (*sdk.Result, error) SetGasPrices(ctx sdk.Context, authority sdk.AccAddress, gasprices sdk.DecCoins) (*sdk.Result, error) ScheduleUpgrade(ctx sdk.Context, authority sdk.AccAddress, plan upgradetypes.Plan) (*sdk.Result, error) - ApplyUpgrade(ctx sdk.Context, authority sdk.AccAddress, plan upgradetypes.Plan) (*sdk.Result, error) GetUpgradePlan(ctx sdk.Context) (plan upgradetypes.Plan, havePlan bool) } type msgServer struct { @@ -136,25 +135,3 @@ func (m msgServer) ScheduleUpgrade( return &types.MsgScheduleUpgradeResponse{}, nil } - -func (m msgServer) ApplyUpgrade( - goCtx context.Context, msg *types.MsgApplyUpgrade, -) (*types.MsgApplyUpgradeResponse, error) { - ctx := sdk.UnwrapSDKContext(goCtx) - - authority, err := sdk.AccAddressFromBech32(msg.Authority) - if err != nil { - return nil, sdkerrors.Wrap(sdkerrors.ErrInvalidAddress, "authority") - } - - result, err := m.k.ApplyUpgrade(ctx, authority, msg.Plan) - if err != nil { - return nil, err - } - - for _, e := range result.Events { - ctx.EventManager().EmitEvent(sdk.Event(e)) - } - - return &types.MsgApplyUpgradeResponse{}, nil -} diff --git a/x/authority/types/codec.go b/x/authority/types/codec.go index 0bec4b5a..14d21e74 100644 --- a/x/authority/types/codec.go +++ b/x/authority/types/codec.go @@ -27,7 +27,6 @@ func RegisterLegacyAminoCodec(cdc *codec.LegacyAmino) { cdc.RegisterConcrete(&MsgSetGasPrices{}, "e-money/MsgSetGasPrices", nil) cdc.RegisterConcrete(&MsgReplaceAuthority{}, "e-money/MsgReplaceAuthority", nil) cdc.RegisterConcrete(&MsgScheduleUpgrade{}, "e-money/MsgScheduleUpgrade", nil) - cdc.RegisterConcrete(&MsgApplyUpgrade{}, "e-money/MsgApplyUpgrade", nil) } func RegisterInterfaces(registry types.InterfaceRegistry) { @@ -37,7 +36,6 @@ func RegisterInterfaces(registry types.InterfaceRegistry) { &MsgSetGasPrices{}, &MsgReplaceAuthority{}, &MsgScheduleUpgrade{}, - &MsgApplyUpgrade{}, ) msgservice.RegisterMsgServiceDesc(registry, &_Msg_serviceDesc) } diff --git a/x/authority/types/msgs.go b/x/authority/types/msgs.go index b77c0243..832942c7 100644 --- a/x/authority/types/msgs.go +++ b/x/authority/types/msgs.go @@ -15,7 +15,6 @@ var ( _ sdk.Msg = &MsgSetGasPrices{} _ sdk.Msg = &MsgReplaceAuthority{} _ sdk.Msg = &MsgScheduleUpgrade{} - _ sdk.Msg = &MsgApplyUpgrade{} ) func (msg MsgDestroyIssuer) Type() string { return "destroy_issuer" } @@ -28,8 +27,6 @@ func (msg MsgReplaceAuthority) Type() string { return "replace_authority" } func (msg MsgScheduleUpgrade) Type() string { return "schedule_upgrade" } -func (msg MsgApplyUpgrade) Type() string { return "apply_upgrade" } - func (msg MsgDestroyIssuer) ValidateBasic() error { if _, err := sdk.AccAddressFromBech32(msg.Issuer); err != nil { return sdkerrors.Wrapf(sdkerrors.ErrInvalidAddress, "invalid issuer address (%s)", err) @@ -94,18 +91,6 @@ func (msg MsgScheduleUpgrade) ValidateBasic() error { return nil } -func (msg MsgApplyUpgrade) ValidateBasic() error { - if _, err := sdk.AccAddressFromBech32(msg.Authority); err != nil { - return sdkerrors.Wrapf(sdkerrors.ErrInvalidAddress, "invalid authority address (%s)", err) - } - - if err := msg.Plan.ValidateBasic(); err != nil { - return err - } - - return nil -} - func (msg MsgDestroyIssuer) GetSigners() []sdk.AccAddress { from, err := sdk.AccAddressFromBech32(msg.Authority) if err != nil { @@ -146,14 +131,6 @@ func (msg MsgScheduleUpgrade) GetSigners() []sdk.AccAddress { return []sdk.AccAddress{from} } -func (msg MsgApplyUpgrade) GetSigners() []sdk.AccAddress { - from, err := sdk.AccAddressFromBech32(msg.Authority) - if err != nil { - panic(err) - } - return []sdk.AccAddress{from} -} - func (msg MsgDestroyIssuer) GetSignBytes() []byte { return sdk.MustSortJSON(ModuleCdc.MustMarshalJSON(&msg)) } @@ -174,10 +151,6 @@ func (msg MsgScheduleUpgrade) GetSignBytes() []byte { return sdk.MustSortJSON(ModuleCdc.MustMarshalJSON(&msg)) } -func (msg MsgApplyUpgrade) GetSignBytes() []byte { - return sdk.MustSortJSON(ModuleCdc.MustMarshalJSON(&msg)) -} - func (msg MsgDestroyIssuer) Route() string { return ModuleName } func (msg MsgCreateIssuer) Route() string { return ModuleName } @@ -187,5 +160,3 @@ func (msg MsgSetGasPrices) Route() string { return ModuleName } func (msg MsgReplaceAuthority) Route() string { return ModuleName } func (msg MsgScheduleUpgrade) Route() string { return ModuleName } - -func (msg MsgApplyUpgrade) Route() string { return ModuleName } diff --git a/x/authority/types/tx.pb.go b/x/authority/types/tx.pb.go index 235f5649..ac06bf9f 100644 --- a/x/authority/types/tx.pb.go +++ b/x/authority/types/tx.pb.go @@ -487,94 +487,6 @@ func (m *MsgScheduleUpgradeResponse) XXX_DiscardUnknown() { var xxx_messageInfo_MsgScheduleUpgradeResponse proto.InternalMessageInfo -type MsgApplyUpgrade struct { - Authority string `protobuf:"bytes,1,opt,name=authority,proto3" json:"authority,omitempty" yaml:"authority"` - Plan types1.Plan `protobuf:"bytes,2,opt,name=plan,proto3" json:"plan" yaml:"plan"` -} - -func (m *MsgApplyUpgrade) Reset() { *m = MsgApplyUpgrade{} } -func (m *MsgApplyUpgrade) String() string { return proto.CompactTextString(m) } -func (*MsgApplyUpgrade) ProtoMessage() {} -func (*MsgApplyUpgrade) Descriptor() ([]byte, []int) { - return fileDescriptor_1601f633ca5d263c, []int{10} -} -func (m *MsgApplyUpgrade) XXX_Unmarshal(b []byte) error { - return m.Unmarshal(b) -} -func (m *MsgApplyUpgrade) XXX_Marshal(b []byte, deterministic bool) ([]byte, error) { - if deterministic { - return xxx_messageInfo_MsgApplyUpgrade.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 *MsgApplyUpgrade) XXX_Merge(src proto.Message) { - xxx_messageInfo_MsgApplyUpgrade.Merge(m, src) -} -func (m *MsgApplyUpgrade) XXX_Size() int { - return m.Size() -} -func (m *MsgApplyUpgrade) XXX_DiscardUnknown() { - xxx_messageInfo_MsgApplyUpgrade.DiscardUnknown(m) -} - -var xxx_messageInfo_MsgApplyUpgrade proto.InternalMessageInfo - -func (m *MsgApplyUpgrade) GetAuthority() string { - if m != nil { - return m.Authority - } - return "" -} - -func (m *MsgApplyUpgrade) GetPlan() types1.Plan { - if m != nil { - return m.Plan - } - return types1.Plan{} -} - -type MsgApplyUpgradeResponse struct { -} - -func (m *MsgApplyUpgradeResponse) Reset() { *m = MsgApplyUpgradeResponse{} } -func (m *MsgApplyUpgradeResponse) String() string { return proto.CompactTextString(m) } -func (*MsgApplyUpgradeResponse) ProtoMessage() {} -func (*MsgApplyUpgradeResponse) Descriptor() ([]byte, []int) { - return fileDescriptor_1601f633ca5d263c, []int{11} -} -func (m *MsgApplyUpgradeResponse) XXX_Unmarshal(b []byte) error { - return m.Unmarshal(b) -} -func (m *MsgApplyUpgradeResponse) XXX_Marshal(b []byte, deterministic bool) ([]byte, error) { - if deterministic { - return xxx_messageInfo_MsgApplyUpgradeResponse.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 *MsgApplyUpgradeResponse) XXX_Merge(src proto.Message) { - xxx_messageInfo_MsgApplyUpgradeResponse.Merge(m, src) -} -func (m *MsgApplyUpgradeResponse) XXX_Size() int { - return m.Size() -} -func (m *MsgApplyUpgradeResponse) XXX_DiscardUnknown() { - xxx_messageInfo_MsgApplyUpgradeResponse.DiscardUnknown(m) -} - -var xxx_messageInfo_MsgApplyUpgradeResponse proto.InternalMessageInfo - func init() { proto.RegisterType((*MsgCreateIssuer)(nil), "em.authority.v1.MsgCreateIssuer") proto.RegisterType((*MsgCreateIssuerResponse)(nil), "em.authority.v1.MsgCreateIssuerResponse") @@ -586,57 +498,53 @@ func init() { proto.RegisterType((*MsgReplaceAuthorityResponse)(nil), "em.authority.v1.MsgReplaceAuthorityResponse") proto.RegisterType((*MsgScheduleUpgrade)(nil), "em.authority.v1.MsgScheduleUpgrade") proto.RegisterType((*MsgScheduleUpgradeResponse)(nil), "em.authority.v1.MsgScheduleUpgradeResponse") - proto.RegisterType((*MsgApplyUpgrade)(nil), "em.authority.v1.MsgApplyUpgrade") - proto.RegisterType((*MsgApplyUpgradeResponse)(nil), "em.authority.v1.MsgApplyUpgradeResponse") } func init() { proto.RegisterFile("em/authority/v1/tx.proto", fileDescriptor_1601f633ca5d263c) } var fileDescriptor_1601f633ca5d263c = []byte{ - // 685 bytes of a gzipped FileDescriptorProto - 0x1f, 0x8b, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0xff, 0xcc, 0x55, 0xcd, 0x4e, 0xd4, 0x50, - 0x14, 0x9e, 0x32, 0x84, 0x84, 0x0b, 0x13, 0xa0, 0x60, 0xac, 0x95, 0xb4, 0xe3, 0x95, 0x05, 0x04, - 0x69, 0x33, 0xb8, 0x30, 0x31, 0x71, 0xc1, 0x80, 0x11, 0x17, 0x93, 0x90, 0xaa, 0x1b, 0x12, 0x43, - 0xee, 0xb4, 0xc7, 0xd2, 0xd8, 0xf6, 0xd6, 0xde, 0x0e, 0x30, 0x0f, 0x60, 0xe2, 0xc2, 0x44, 0x5f, - 0x43, 0xdf, 0xc3, 0x84, 0x8d, 0x09, 0x4b, 0x57, 0xa3, 0x81, 0x37, 0x98, 0x27, 0x30, 0xd3, 0xdb, - 0x76, 0xda, 0xd2, 0x04, 0x32, 0x0b, 0xe3, 0x6a, 0xa6, 0x3d, 0xdf, 0x77, 0xce, 0x77, 0x7e, 0x8b, - 0x24, 0xf0, 0x74, 0xd2, 0x8b, 0x8e, 0x69, 0xe8, 0x44, 0x7d, 0xfd, 0xa4, 0xa5, 0x47, 0x67, 0x5a, - 0x10, 0xd2, 0x88, 0x8a, 0x0b, 0xe0, 0x69, 0x99, 0x45, 0x3b, 0x69, 0xc9, 0x2b, 0x36, 0xb5, 0x69, - 0x6c, 0xd3, 0x47, 0xff, 0x38, 0x4c, 0x56, 0x4c, 0xca, 0x3c, 0xca, 0xf4, 0x2e, 0x61, 0xa0, 0x9f, - 0xb4, 0xba, 0x10, 0x91, 0x96, 0x6e, 0x52, 0xc7, 0x4f, 0xec, 0x6b, 0x89, 0xbd, 0x17, 0xd8, 0x21, - 0xb1, 0xc6, 0x90, 0xe4, 0x99, 0xa3, 0xf0, 0x37, 0x01, 0x2d, 0x74, 0x98, 0xbd, 0x1b, 0x02, 0x89, - 0xe0, 0x25, 0x63, 0x3d, 0x08, 0xc5, 0x6d, 0x34, 0x9b, 0xc5, 0x97, 0x84, 0xa6, 0xb0, 0x3e, 0xdb, - 0x5e, 0x19, 0x0e, 0xd4, 0xc5, 0x3e, 0xf1, 0xdc, 0xa7, 0x38, 0x33, 0x61, 0x63, 0x0c, 0x13, 0x37, - 0xd0, 0x8c, 0x13, 0xb3, 0xa5, 0xa9, 0x98, 0xb0, 0x34, 0x1c, 0xa8, 0x0d, 0x4e, 0xe0, 0xef, 0xb1, - 0x91, 0x00, 0xc4, 0x27, 0xa8, 0x61, 0x81, 0x4f, 0x3d, 0xc7, 0x27, 0x91, 0x43, 0x7d, 0x26, 0xd5, - 0x9b, 0xf5, 0x22, 0x23, 0x36, 0x33, 0x6c, 0x14, 0x71, 0xf8, 0x1e, 0xba, 0x5b, 0x92, 0x6a, 0x00, - 0x0b, 0xa8, 0xcf, 0x00, 0x7f, 0x40, 0x8b, 0x1d, 0x66, 0xef, 0x01, 0x8b, 0x42, 0xda, 0xff, 0x27, - 0x69, 0x60, 0x19, 0x49, 0xe5, 0x90, 0x99, 0x9c, 0x9f, 0xbc, 0xaa, 0xaf, 0x20, 0x7a, 0x41, 0xd8, - 0x41, 0xe8, 0x98, 0xc0, 0x26, 0x92, 0xf3, 0x51, 0x40, 0xc8, 0x26, 0xec, 0x28, 0x88, 0x5d, 0x48, - 0x53, 0xcd, 0xfa, 0xfa, 0xdc, 0xf6, 0xaa, 0xc6, 0x3b, 0xab, 0x8d, 0x3a, 0xaf, 0x25, 0x6d, 0xd5, - 0xf6, 0xc0, 0xdc, 0xa5, 0x8e, 0xdf, 0xde, 0x3f, 0x1f, 0xa8, 0xb5, 0xe1, 0x40, 0x5d, 0xe2, 0x7e, - 0xc7, 0x6c, 0xfc, 0xfd, 0xb7, 0xba, 0x69, 0x3b, 0xd1, 0x71, 0xaf, 0xab, 0x99, 0xd4, 0xd3, 0x93, - 0xf1, 0xe0, 0x3f, 0x5b, 0xcc, 0x7a, 0xaf, 0x47, 0xfd, 0x00, 0x58, 0xea, 0x88, 0x19, 0xb3, 0x76, - 0xaa, 0x3d, 0xa9, 0x7c, 0x3e, 0x9d, 0x2c, 0xd5, 0x4f, 0x02, 0x5a, 0xee, 0x30, 0xdb, 0x80, 0xc0, - 0x25, 0x26, 0xec, 0x64, 0xd2, 0x27, 0x49, 0xf7, 0x19, 0x6a, 0xf8, 0x70, 0x7a, 0x34, 0xe6, 0xf1, - 0x26, 0x48, 0xc3, 0x81, 0xba, 0xc2, 0x79, 0x05, 0x33, 0x36, 0xe6, 0x7d, 0x38, 0xcd, 0x42, 0x62, - 0x86, 0xee, 0x57, 0x28, 0x49, 0x95, 0x8a, 0xaf, 0xd1, 0x9d, 0x02, 0xfd, 0x88, 0x58, 0x56, 0x08, - 0x8c, 0x25, 0xea, 0x9a, 0xc3, 0x81, 0xba, 0x5a, 0x11, 0x25, 0x85, 0x61, 0x63, 0x39, 0x1f, 0x6d, - 0x27, 0x79, 0xfb, 0x45, 0x40, 0xe2, 0xa8, 0x36, 0xe6, 0x31, 0x58, 0x3d, 0x17, 0xde, 0xf0, 0xed, - 0x9a, 0x28, 0xfd, 0xe7, 0x68, 0x3a, 0x70, 0x89, 0x1f, 0x67, 0x9d, 0x6b, 0x73, 0xba, 0xb0, 0x69, - 0xa7, 0x0f, 0x5c, 0xe2, 0xb7, 0x97, 0x93, 0x36, 0xcf, 0x71, 0x87, 0x23, 0x1e, 0x36, 0x62, 0x3a, - 0x5e, 0x45, 0xf2, 0x75, 0x41, 0x59, 0xbf, 0x3e, 0xf3, 0xd1, 0xdc, 0x09, 0x02, 0xb7, 0xff, 0x1f, - 0x88, 0xe5, 0x93, 0x95, 0x57, 0x93, 0x2a, 0xdd, 0xfe, 0x31, 0x8d, 0xea, 0x1d, 0x66, 0x8b, 0x87, - 0x68, 0xbe, 0x70, 0x9e, 0x9a, 0x5a, 0xe9, 0x40, 0x6a, 0xa5, 0xab, 0x20, 0xaf, 0xdf, 0x84, 0xc8, - 0x66, 0xe2, 0x2d, 0x6a, 0x14, 0x8f, 0xc6, 0x83, 0x2a, 0x6a, 0x01, 0x22, 0x6f, 0xdc, 0x08, 0xc9, - 0xdc, 0x1f, 0xa2, 0xf9, 0xc2, 0x0d, 0xa8, 0x94, 0x9e, 0x47, 0x54, 0x4b, 0xaf, 0x5a, 0x3c, 0xf1, - 0x1d, 0x5a, 0xbc, 0xb6, 0x74, 0x6b, 0x55, 0xec, 0x32, 0x4a, 0x7e, 0x74, 0x1b, 0x54, 0x16, 0xc7, - 0x44, 0x0b, 0xe5, 0xe1, 0x7e, 0x58, 0x29, 0xb2, 0x08, 0x92, 0x37, 0x6f, 0x01, 0xca, 0x17, 0xaa, - 0x30, 0x91, 0x95, 0x85, 0xca, 0x23, 0xaa, 0x0b, 0x55, 0x35, 0x47, 0xed, 0xfd, 0xf3, 0x4b, 0x45, - 0xb8, 0xb8, 0x54, 0x84, 0x3f, 0x97, 0x8a, 0xf0, 0xf5, 0x4a, 0xa9, 0x5d, 0x5c, 0x29, 0xb5, 0x5f, - 0x57, 0x4a, 0xed, 0x50, 0xcb, 0x9d, 0x43, 0xd8, 0xf2, 0xa8, 0x0f, 0x7d, 0x1d, 0xbc, 0x2d, 0x17, - 0x2c, 0x1b, 0x42, 0xfd, 0x2c, 0xf7, 0x7d, 0x8e, 0x4f, 0x63, 0x77, 0x26, 0xfe, 0x66, 0x3e, 0xfe, - 0x1b, 0x00, 0x00, 0xff, 0xff, 0xa1, 0x45, 0xee, 0x9f, 0xbc, 0x07, 0x00, 0x00, + // 656 bytes of a gzipped FileDescriptorProto + 0x1f, 0x8b, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0xff, 0xbc, 0x55, 0x4f, 0x4f, 0xd4, 0x4e, + 0x18, 0xde, 0xb2, 0xbf, 0x90, 0x30, 0xb0, 0x01, 0x0a, 0xbf, 0x58, 0x2b, 0x69, 0xd7, 0x91, 0x03, + 0x04, 0x69, 0xb3, 0x78, 0x30, 0x31, 0xf1, 0xc0, 0x82, 0x11, 0x0f, 0x9b, 0x90, 0xaa, 0x17, 0x12, + 0x43, 0x66, 0xdb, 0xd7, 0xd2, 0xd8, 0x76, 0x6a, 0xa7, 0x0b, 0xec, 0x07, 0x30, 0xf1, 0xa6, 0x5f, + 0x43, 0x3f, 0x09, 0x17, 0x13, 0x8e, 0x9e, 0xaa, 0x81, 0x93, 0xd7, 0xfd, 0x04, 0x66, 0x3b, 0x6d, + 0xb7, 0x2d, 0x4d, 0x20, 0x7b, 0xf0, 0xb4, 0xdb, 0x79, 0x9f, 0xe7, 0x7d, 0x9f, 0xf7, 0xdf, 0x0c, + 0x92, 0xc0, 0xd3, 0xc9, 0x20, 0x3a, 0xa1, 0xa1, 0x13, 0x0d, 0xf5, 0xd3, 0x8e, 0x1e, 0x9d, 0x6b, + 0x41, 0x48, 0x23, 0x2a, 0x2e, 0x82, 0xa7, 0xe5, 0x16, 0xed, 0xb4, 0x23, 0xaf, 0xda, 0xd4, 0xa6, + 0x89, 0x4d, 0x1f, 0xff, 0xe3, 0x30, 0x59, 0x31, 0x29, 0xf3, 0x28, 0xd3, 0xfb, 0x84, 0x81, 0x7e, + 0xda, 0xe9, 0x43, 0x44, 0x3a, 0xba, 0x49, 0x1d, 0x3f, 0xb5, 0xaf, 0xa7, 0xf6, 0x41, 0x60, 0x87, + 0xc4, 0x9a, 0x40, 0xd2, 0x6f, 0x8e, 0xc2, 0xdf, 0x04, 0xb4, 0xd8, 0x63, 0xf6, 0x5e, 0x08, 0x24, + 0x82, 0x57, 0x8c, 0x0d, 0x20, 0x14, 0x77, 0xd0, 0x5c, 0x1e, 0x5f, 0x12, 0xda, 0xc2, 0xc6, 0x5c, + 0x77, 0x75, 0x14, 0xab, 0x4b, 0x43, 0xe2, 0xb9, 0xcf, 0x70, 0x6e, 0xc2, 0xc6, 0x04, 0x26, 0x6e, + 0xa2, 0x59, 0x27, 0x61, 0x4b, 0x33, 0x09, 0x61, 0x79, 0x14, 0xab, 0x2d, 0x4e, 0xe0, 0xe7, 0xd8, + 0x48, 0x01, 0xe2, 0x53, 0xd4, 0xb2, 0xc0, 0xa7, 0x9e, 0xe3, 0x93, 0xc8, 0xa1, 0x3e, 0x93, 0x9a, + 0xed, 0x66, 0x99, 0x91, 0x98, 0x19, 0x36, 0xca, 0x38, 0x7c, 0x1f, 0xdd, 0xab, 0x48, 0x35, 0x80, + 0x05, 0xd4, 0x67, 0x80, 0x3f, 0xa2, 0xa5, 0x1e, 0xb3, 0xf7, 0x81, 0x45, 0x21, 0x1d, 0xfe, 0x93, + 0x34, 0xb0, 0x8c, 0xa4, 0x6a, 0xc8, 0x5c, 0xce, 0x0f, 0x5e, 0xd5, 0xd7, 0x10, 0xbd, 0x24, 0xec, + 0x30, 0x74, 0x4c, 0x60, 0x53, 0xc9, 0xf9, 0x24, 0x20, 0x64, 0x13, 0x76, 0x1c, 0x24, 0x2e, 0xa4, + 0x99, 0x76, 0x73, 0x63, 0x7e, 0x67, 0x4d, 0xe3, 0x9d, 0xd5, 0xc6, 0x9d, 0xd7, 0xd2, 0xb6, 0x6a, + 0xfb, 0x60, 0xee, 0x51, 0xc7, 0xef, 0x1e, 0x5c, 0xc4, 0x6a, 0x63, 0x14, 0xab, 0xcb, 0xdc, 0xef, + 0x84, 0x8d, 0xbf, 0xff, 0x52, 0xb7, 0x6c, 0x27, 0x3a, 0x19, 0xf4, 0x35, 0x93, 0x7a, 0x7a, 0x3a, + 0x1e, 0xfc, 0x67, 0x9b, 0x59, 0x1f, 0xf4, 0x68, 0x18, 0x00, 0xcb, 0x1c, 0x31, 0x63, 0xce, 0xce, + 0xb4, 0xa7, 0x95, 0x2f, 0xa6, 0x93, 0xa7, 0xfa, 0x59, 0x40, 0x2b, 0x3d, 0x66, 0x1b, 0x10, 0xb8, + 0xc4, 0x84, 0xdd, 0x5c, 0xfa, 0x34, 0xe9, 0x3e, 0x47, 0x2d, 0x1f, 0xce, 0x8e, 0x27, 0x3c, 0xde, + 0x04, 0x69, 0x14, 0xab, 0xab, 0x9c, 0x57, 0x32, 0x63, 0x63, 0xc1, 0x87, 0xb3, 0x3c, 0x24, 0x66, + 0xe8, 0x41, 0x8d, 0x92, 0x4c, 0xa9, 0xf8, 0x06, 0xfd, 0x5f, 0xa2, 0x1f, 0x13, 0xcb, 0x0a, 0x81, + 0xb1, 0x54, 0x5d, 0x7b, 0x14, 0xab, 0x6b, 0x35, 0x51, 0x32, 0x18, 0x36, 0x56, 0x8a, 0xd1, 0x76, + 0xd3, 0xd3, 0x2f, 0x02, 0x12, 0xc7, 0xb5, 0x31, 0x4f, 0xc0, 0x1a, 0xb8, 0xf0, 0x96, 0x6f, 0xd7, + 0x54, 0xe9, 0xbf, 0x40, 0xff, 0x05, 0x2e, 0xf1, 0x93, 0xac, 0x0b, 0x6d, 0xce, 0x16, 0x36, 0xeb, + 0xf4, 0xa1, 0x4b, 0xfc, 0xee, 0x4a, 0xda, 0xe6, 0x79, 0xee, 0x70, 0xcc, 0xc3, 0x46, 0x42, 0xc7, + 0x6b, 0x48, 0xbe, 0x29, 0x28, 0xab, 0xc2, 0xce, 0x9f, 0x26, 0x6a, 0xf6, 0x98, 0x2d, 0x1e, 0xa1, + 0x85, 0xd2, 0xd2, 0xb7, 0xb5, 0xca, 0xb5, 0xa3, 0x55, 0x76, 0x4d, 0xde, 0xb8, 0x0d, 0x91, 0x57, + 0xfa, 0x1d, 0x6a, 0x95, 0x57, 0xf1, 0x61, 0x1d, 0xb5, 0x04, 0x91, 0x37, 0x6f, 0x85, 0xe4, 0xee, + 0x8f, 0xd0, 0x42, 0x69, 0xb3, 0x6a, 0xa5, 0x17, 0x11, 0xf5, 0xd2, 0xeb, 0xc6, 0x59, 0x7c, 0x8f, + 0x96, 0x6e, 0x8c, 0xf2, 0x7a, 0x1d, 0xbb, 0x8a, 0x92, 0x1f, 0xdf, 0x05, 0x95, 0xc7, 0x31, 0xd1, + 0x62, 0x75, 0x64, 0x1e, 0xd5, 0x8a, 0x2c, 0x83, 0xe4, 0xad, 0x3b, 0x80, 0xb2, 0x20, 0xdd, 0x83, + 0x8b, 0x2b, 0x45, 0xb8, 0xbc, 0x52, 0x84, 0xdf, 0x57, 0x8a, 0xf0, 0xf5, 0x5a, 0x69, 0x5c, 0x5e, + 0x2b, 0x8d, 0x9f, 0xd7, 0x4a, 0xe3, 0x48, 0x2b, 0x5c, 0x04, 0xb0, 0xed, 0x51, 0x1f, 0x86, 0x3a, + 0x78, 0xdb, 0x2e, 0x58, 0x36, 0x84, 0xfa, 0x79, 0xe1, 0x65, 0x4a, 0x2e, 0x85, 0xfe, 0x6c, 0xf2, + 0x5a, 0x3c, 0xf9, 0x1b, 0x00, 0x00, 0xff, 0xff, 0x82, 0x0d, 0xef, 0xdc, 0xb6, 0x06, 0x00, 0x00, } // Reference imports to suppress errors if they are not otherwise used. @@ -656,7 +564,6 @@ type MsgClient interface { SetGasPrices(ctx context.Context, in *MsgSetGasPrices, opts ...grpc.CallOption) (*MsgSetGasPricesResponse, error) ReplaceAuthority(ctx context.Context, in *MsgReplaceAuthority, opts ...grpc.CallOption) (*MsgReplaceAuthorityResponse, error) ScheduleUpgrade(ctx context.Context, in *MsgScheduleUpgrade, opts ...grpc.CallOption) (*MsgScheduleUpgradeResponse, error) - ApplyUpgrade(ctx context.Context, in *MsgApplyUpgrade, opts ...grpc.CallOption) (*MsgApplyUpgradeResponse, error) } type msgClient struct { @@ -712,15 +619,6 @@ func (c *msgClient) ScheduleUpgrade(ctx context.Context, in *MsgScheduleUpgrade, return out, nil } -func (c *msgClient) ApplyUpgrade(ctx context.Context, in *MsgApplyUpgrade, opts ...grpc.CallOption) (*MsgApplyUpgradeResponse, error) { - out := new(MsgApplyUpgradeResponse) - err := c.cc.Invoke(ctx, "/em.authority.v1.Msg/ApplyUpgrade", in, out, opts...) - if err != nil { - return nil, err - } - return out, nil -} - // MsgServer is the server API for Msg service. type MsgServer interface { CreateIssuer(context.Context, *MsgCreateIssuer) (*MsgCreateIssuerResponse, error) @@ -728,7 +626,6 @@ type MsgServer interface { SetGasPrices(context.Context, *MsgSetGasPrices) (*MsgSetGasPricesResponse, error) ReplaceAuthority(context.Context, *MsgReplaceAuthority) (*MsgReplaceAuthorityResponse, error) ScheduleUpgrade(context.Context, *MsgScheduleUpgrade) (*MsgScheduleUpgradeResponse, error) - ApplyUpgrade(context.Context, *MsgApplyUpgrade) (*MsgApplyUpgradeResponse, error) } // UnimplementedMsgServer can be embedded to have forward compatible implementations. @@ -750,9 +647,6 @@ func (*UnimplementedMsgServer) ReplaceAuthority(ctx context.Context, req *MsgRep func (*UnimplementedMsgServer) ScheduleUpgrade(ctx context.Context, req *MsgScheduleUpgrade) (*MsgScheduleUpgradeResponse, error) { return nil, status.Errorf(codes.Unimplemented, "method ScheduleUpgrade not implemented") } -func (*UnimplementedMsgServer) ApplyUpgrade(ctx context.Context, req *MsgApplyUpgrade) (*MsgApplyUpgradeResponse, error) { - return nil, status.Errorf(codes.Unimplemented, "method ApplyUpgrade not implemented") -} func RegisterMsgServer(s grpc1.Server, srv MsgServer) { s.RegisterService(&_Msg_serviceDesc, srv) @@ -848,24 +742,6 @@ func _Msg_ScheduleUpgrade_Handler(srv interface{}, ctx context.Context, dec func return interceptor(ctx, in, info, handler) } -func _Msg_ApplyUpgrade_Handler(srv interface{}, ctx context.Context, dec func(interface{}) error, interceptor grpc.UnaryServerInterceptor) (interface{}, error) { - in := new(MsgApplyUpgrade) - if err := dec(in); err != nil { - return nil, err - } - if interceptor == nil { - return srv.(MsgServer).ApplyUpgrade(ctx, in) - } - info := &grpc.UnaryServerInfo{ - Server: srv, - FullMethod: "/em.authority.v1.Msg/ApplyUpgrade", - } - handler := func(ctx context.Context, req interface{}) (interface{}, error) { - return srv.(MsgServer).ApplyUpgrade(ctx, req.(*MsgApplyUpgrade)) - } - return interceptor(ctx, in, info, handler) -} - var _Msg_serviceDesc = grpc.ServiceDesc{ ServiceName: "em.authority.v1.Msg", HandlerType: (*MsgServer)(nil), @@ -890,10 +766,6 @@ var _Msg_serviceDesc = grpc.ServiceDesc{ MethodName: "ScheduleUpgrade", Handler: _Msg_ScheduleUpgrade_Handler, }, - { - MethodName: "ApplyUpgrade", - Handler: _Msg_ApplyUpgrade_Handler, - }, }, Streams: []grpc.StreamDesc{}, Metadata: "em/authority/v1/tx.proto", @@ -1225,69 +1097,6 @@ func (m *MsgScheduleUpgradeResponse) MarshalToSizedBuffer(dAtA []byte) (int, err return len(dAtA) - i, nil } -func (m *MsgApplyUpgrade) 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 *MsgApplyUpgrade) MarshalTo(dAtA []byte) (int, error) { - size := m.Size() - return m.MarshalToSizedBuffer(dAtA[:size]) -} - -func (m *MsgApplyUpgrade) MarshalToSizedBuffer(dAtA []byte) (int, error) { - i := len(dAtA) - _ = i - var l int - _ = l - { - size, err := m.Plan.MarshalToSizedBuffer(dAtA[:i]) - if err != nil { - return 0, err - } - i -= size - i = encodeVarintTx(dAtA, i, uint64(size)) - } - i-- - dAtA[i] = 0x12 - if len(m.Authority) > 0 { - i -= len(m.Authority) - copy(dAtA[i:], m.Authority) - i = encodeVarintTx(dAtA, i, uint64(len(m.Authority))) - i-- - dAtA[i] = 0xa - } - return len(dAtA) - i, nil -} - -func (m *MsgApplyUpgradeResponse) 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 *MsgApplyUpgradeResponse) MarshalTo(dAtA []byte) (int, error) { - size := m.Size() - return m.MarshalToSizedBuffer(dAtA[:size]) -} - -func (m *MsgApplyUpgradeResponse) MarshalToSizedBuffer(dAtA []byte) (int, error) { - i := len(dAtA) - _ = i - var l int - _ = l - return len(dAtA) - i, nil -} - func encodeVarintTx(dAtA []byte, offset int, v uint64) int { offset -= sovTx(v) base := offset @@ -1439,30 +1248,6 @@ func (m *MsgScheduleUpgradeResponse) Size() (n int) { return n } -func (m *MsgApplyUpgrade) Size() (n int) { - if m == nil { - return 0 - } - var l int - _ = l - l = len(m.Authority) - if l > 0 { - n += 1 + l + sovTx(uint64(l)) - } - l = m.Plan.Size() - n += 1 + l + sovTx(uint64(l)) - return n -} - -func (m *MsgApplyUpgradeResponse) Size() (n int) { - if m == nil { - return 0 - } - var l int - _ = l - return n -} - func sovTx(x uint64) (n int) { return (math_bits.Len64(x|1) + 6) / 7 } @@ -2356,171 +2141,6 @@ func (m *MsgScheduleUpgradeResponse) Unmarshal(dAtA []byte) error { } return nil } -func (m *MsgApplyUpgrade) 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 ErrIntOverflowTx - } - 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: MsgApplyUpgrade: wiretype end group for non-group") - } - if fieldNum <= 0 { - return fmt.Errorf("proto: MsgApplyUpgrade: illegal tag %d (wire type %d)", fieldNum, wire) - } - switch fieldNum { - case 1: - if wireType != 2 { - return fmt.Errorf("proto: wrong wireType = %d for field Authority", wireType) - } - var stringLen uint64 - for shift := uint(0); ; shift += 7 { - if shift >= 64 { - return ErrIntOverflowTx - } - 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 ErrInvalidLengthTx - } - postIndex := iNdEx + intStringLen - if postIndex < 0 { - return ErrInvalidLengthTx - } - if postIndex > l { - return io.ErrUnexpectedEOF - } - m.Authority = string(dAtA[iNdEx:postIndex]) - iNdEx = postIndex - case 2: - if wireType != 2 { - return fmt.Errorf("proto: wrong wireType = %d for field Plan", wireType) - } - var msglen int - for shift := uint(0); ; shift += 7 { - if shift >= 64 { - return ErrIntOverflowTx - } - if iNdEx >= l { - return io.ErrUnexpectedEOF - } - b := dAtA[iNdEx] - iNdEx++ - msglen |= int(b&0x7F) << shift - if b < 0x80 { - break - } - } - if msglen < 0 { - return ErrInvalidLengthTx - } - postIndex := iNdEx + msglen - if postIndex < 0 { - return ErrInvalidLengthTx - } - if postIndex > l { - return io.ErrUnexpectedEOF - } - if err := m.Plan.Unmarshal(dAtA[iNdEx:postIndex]); err != nil { - return err - } - iNdEx = postIndex - default: - iNdEx = preIndex - skippy, err := skipTx(dAtA[iNdEx:]) - if err != nil { - return err - } - if (skippy < 0) || (iNdEx+skippy) < 0 { - return ErrInvalidLengthTx - } - if (iNdEx + skippy) > l { - return io.ErrUnexpectedEOF - } - iNdEx += skippy - } - } - - if iNdEx > l { - return io.ErrUnexpectedEOF - } - return nil -} -func (m *MsgApplyUpgradeResponse) 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 ErrIntOverflowTx - } - 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: MsgApplyUpgradeResponse: wiretype end group for non-group") - } - if fieldNum <= 0 { - return fmt.Errorf("proto: MsgApplyUpgradeResponse: illegal tag %d (wire type %d)", fieldNum, wire) - } - switch fieldNum { - default: - iNdEx = preIndex - skippy, err := skipTx(dAtA[iNdEx:]) - if err != nil { - return err - } - if (skippy < 0) || (iNdEx+skippy) < 0 { - return ErrInvalidLengthTx - } - if (iNdEx + skippy) > l { - return io.ErrUnexpectedEOF - } - iNdEx += skippy - } - } - - if iNdEx > l { - return io.ErrUnexpectedEOF - } - return nil -} func skipTx(dAtA []byte) (n int, err error) { l := len(dAtA) iNdEx := 0 From 913659d4250b2d53fbb7ab605325c653b5044dd5 Mon Sep 17 00:00:00 2001 From: Mario Karagiorgas Date: Thu, 5 Aug 2021 15:46:43 +0300 Subject: [PATCH 36/49] Fix copy the OS upg binary --- networks/upg/cpemd | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/networks/upg/cpemd b/networks/upg/cpemd index cfadabf7..86fa4bd8 100755 --- a/networks/upg/cpemd +++ b/networks/upg/cpemd @@ -31,7 +31,11 @@ mkdir -p "$COSMOVISOR_HOME"/genesis/bin cp "$EM_LEDGER_LOC"/build/emd "$COSMOVISOR_HOME"/genesis/bin UPG_LOC="$COSMOVISOR_HOME"/upgrades/test-upg-0.1.0/bin mkdir -p "$UPG_LOC" -cp "$EM_LEDGER_LOC"/build/emdupg "$UPG_LOC"/emd +if [ "$(uname)" = "Linux" ]; then + cp "$EM_LEDGER_LOC"/build/emdupg-linux "$UPG_LOC"/emd +else + cp "$EM_LEDGER_LOC"/build/emdupg "$UPG_LOC"/emd +fi echo "legacy or current binary:" ls "$COSMOVISOR_HOME"/genesis/bin/emd From 3844027870f1239d271b714017deb5ae610bee56 Mon Sep 17 00:00:00 2001 From: Mario Karagiorgas Date: Thu, 5 Aug 2021 17:06:44 +0300 Subject: [PATCH 37/49] Recover from a failed upgrade Add test-upg-0.2.0 --- networks/docker/emdnode/wrapper.sh | 2 +- networks/docker/test-upg/Dockerfile | 6 +++--- networks/upg/cpemd | 9 +++++++-- networks/upg/startcv | 4 ++-- networks/upg/upg-sched | 4 ++-- networks/upg/upg-sched-srv | 10 +++++----- upgrade_test.go | 2 +- x/authority/client/cli/tx.go | 4 ++-- 8 files changed, 23 insertions(+), 18 deletions(-) diff --git a/networks/docker/emdnode/wrapper.sh b/networks/docker/emdnode/wrapper.sh index 0e771f12..6e87dd6e 100755 --- a/networks/docker/emdnode/wrapper.sh +++ b/networks/docker/emdnode/wrapper.sh @@ -38,7 +38,7 @@ export DAEMON_HOME=$EMDHOME # link chain launcher to cosmovisor with linux emd binary export DAEMON_NAME=emd-linux BINARY=/emoney/cosmovisor -UPG_LOC="$EMDHOME"/cosmovisor/upgrades/test-upg-0.1.0/bin +UPG_LOC="$EMDHOME"/cosmovisor/upgrades/test-upg-0.2.0/bin mkdir -p "$UPG_LOC" cp /emoney/emdupg-linux "$UPG_LOC"/emd-linux diff --git a/networks/docker/test-upg/Dockerfile b/networks/docker/test-upg/Dockerfile index 6b0c8085..2dde4ed9 100644 --- a/networks/docker/test-upg/Dockerfile +++ b/networks/docker/test-upg/Dockerfile @@ -5,9 +5,9 @@ ARG OS RUN cd /go/src && \ git clone https://github.com/e-money/em-ledger.git && \ cd em-ledger && \ - git checkout upgrade-emd-test && \ - make build-linux + git checkout test-upg-0.2.0 && \ + BIN_PREFIX=-linux LEDGER_ENABLED=false GOOS=linux GOARCH=amd64 make build # build native binary WORKDIR /go/src/em-ledger -RUN GOOS='darwin' go build -tags "netgo ledger" -ldflags '-X github.com/cosmos/cosmos-sdk/version.Name=e-money -X github.com/cosmos/cosmos-sdk/version.AppName=emd -X github.com/cosmos/cosmos-sdk/version.Version=test-upg-0.0.1 -X "github.com/cosmos/cosmos-sdk/version.BuildTags=netgo,ledger"' -o build/emd ./cmd/emd \ No newline at end of file +RUN LEDGER_ENABLED=false GOARCH=amd64 make build \ No newline at end of file diff --git a/networks/upg/cpemd b/networks/upg/cpemd index 86fa4bd8..0ef42631 100755 --- a/networks/upg/cpemd +++ b/networks/upg/cpemd @@ -8,7 +8,7 @@ # │ └── bin # │ └── emd # └── upgrades -# └── test-upg-0.1.0 +# └── test-upg-0.2.0 # └── bin # └── emd @@ -27,9 +27,14 @@ echo "node home: $DAEMON_HOME" # copy soon to be the legacy binary COSMOVISOR_HOME="$EM_LEDGER_LOC"/networks/upg/.emd/cosmovisor + +# clean up previous sticky upgrade +rm "$COSMOVISOR_HOME"/current + mkdir -p "$COSMOVISOR_HOME"/genesis/bin cp "$EM_LEDGER_LOC"/build/emd "$COSMOVISOR_HOME"/genesis/bin -UPG_LOC="$COSMOVISOR_HOME"/upgrades/test-upg-0.1.0/bin +UPG_LOC="$COSMOVISOR_HOME"/upgrades/test-upg-0.2.0/bin + mkdir -p "$UPG_LOC" if [ "$(uname)" = "Linux" ]; then cp "$EM_LEDGER_LOC"/build/emdupg-linux "$UPG_LOC"/emd diff --git a/networks/upg/startcv b/networks/upg/startcv index 79c336f1..3a070e80 100755 --- a/networks/upg/startcv +++ b/networks/upg/startcv @@ -7,8 +7,6 @@ export DAEMON_NAME=emd export DAEMON_ALLOW_DOWNLOAD_BINARIES=true export DAEMON_RESTART_AFTER_UPGRADE=true -./cpemd - # optionally uncomment to copy future upgrade binary in location if # auto-downloading is not available as a primary or none at all # by default we assume it is on and the upgrade binary is not available @@ -24,6 +22,8 @@ rm -rf "$EMD_NODE"/config rm -rf "$EMD_NODE"/data rm -rf "$EMD_NODE"/keyring-test +./cpemd + $EMD unsafe-reset-all --home=$EMD_NODE $EMD init test --chain-id=test --home="$EMD_NODE" --overwrite diff --git a/networks/upg/upg-sched b/networks/upg/upg-sched index 501815ae..7ac23143 100755 --- a/networks/upg/upg-sched +++ b/networks/upg/upg-sched @@ -11,7 +11,7 @@ $EMD q authority gas-prices --home=.emd --node tcp://localhost:26657 --chain-id $EMD q authority upgrade-plan --home=.emd --node tcp://localhost:26657 --chain-id test # schedule upgrade -$EMD tx authority schedule-upgrade authoritykey test-upg-0.1.0 --upgrade-height "$1" --yes --from authoritykey --home=".emd" --node tcp://localhost:26657 --chain-id test --keyring-backend test +$EMD tx authority schedule-upgrade authoritykey test-upg-0.2.0 --upgrade-height "$1" --yes --from authoritykey --home=".emd" --node tcp://localhost:26657 --chain-id test --keyring-backend test # confirm upg plan $EMD q authority upgrade-plan --home=.emd --node tcp://localhost:26657 --chain-id test @@ -19,4 +19,4 @@ $EMD q authority upgrade-plan --home=.emd --node tcp://localhost:26657 --chain-i # ---------- after upgrade ---------> $EMD q authority gas-prices --home=.emd --node tcp://localhost:26657 --chain-id test #$EMD q authority upgrade-plan --home=.emd --node tcp://localhost:26657 --chain-id test # is nil again -$EMD version # test-upg-0.0.1 +$EMD version # test-upg-0.2.0 diff --git a/networks/upg/upg-sched-srv b/networks/upg/upg-sched-srv index f5979927..e50be5ea 100755 --- a/networks/upg/upg-sched-srv +++ b/networks/upg/upg-sched-srv @@ -5,11 +5,11 @@ set -ev # Preconditions server auto download: # export DAEMON_ALLOW_DOWNLOAD_BINARIES=true # make emdupg -# mkdir -p /srv/upgemd/test-upg-0.1.0 -# cp build/emdupg /srv/upgemd/test-upg-0.1.0 -# zip /srv/upgemd/test-upg-0.1.0/emd.zip /srv/upgemd/test-upg-0.1.0/emd +# mkdir -p /srv/upgemd/test-upg-0.2.0 +# cp build/emdupg /srv/upgemd/test-upg-0.2.0 +# zip /srv/upgemd/test-upg-0.2.0/emd.zip /srv/upgemd/test-upg-0.2.0/emd # save sha value to clipboard -# sha256sum /srv/upgemd/test-upg-0.1.0/emd.zip | xsel -i -b +# sha256sum /srv/upgemd/test-upg-0.2.0/emd.zip | xsel -i -b # cd /srv/upgemd # start a web server in the # python3 -m http.server 8765 @@ -17,4 +17,4 @@ set -ev EMD=.emd/cosmovisor/current/bin/emd # choose a future height -$EMD tx authority schedule-upgrade authoritykey test-upg-0.1.0 --upgrade-height 6 --upgrade-info '{"binaries":{"linux/amd64":"http://localhost:8765/test-upg-0.1.0/emd.zip?checksum=sha256:cadd5b52fe90a04e20b2cbb93291b0d1d0204f17b64b2215eb09f5dc78a127f1"}}' --yes --from authoritykey --home="$DAEMON_HOME" --node tcp://localhost:26657 --chain-id test --keyring-backend test \ No newline at end of file +$EMD tx authority schedule-upgrade authoritykey test-upg-0.2.0 --upgrade-height 6 --upgrade-info '{"binaries":{"linux/amd64":"http://localhost:8765/test-upg-0.2.0/emd.zip?checksum=sha256:cadd5b52fe90a04e20b2cbb93291b0d1d0204f17b64b2215eb09f5dc78a127f1"}}' --yes --from authoritykey --home="$DAEMON_HOME" --node tcp://localhost:26657 --chain-id test --keyring-backend test \ No newline at end of file diff --git a/upgrade_test.go b/upgrade_test.go index a823a7a0..fb4e0c0e 100644 --- a/upgrade_test.go +++ b/upgrade_test.go @@ -23,7 +23,7 @@ var _ = Describe("Upgrade", func() { It("upgrade nodes and confirm", func() { const ( - name = "test-upg-0.1.0" + name = "test-upg-0.2.0" ) chainHeight, err := nt.GetHeight() diff --git a/x/authority/client/cli/tx.go b/x/authority/client/cli/tx.go index eff521df..0b4aa3bf 100644 --- a/x/authority/client/cli/tx.go +++ b/x/authority/client/cli/tx.go @@ -195,11 +195,11 @@ func GetCmdScheduleUpgrade() *cobra.Command { Short: "Schedule a software upgrade", Example: `emd tx authority schedule-upgrade someplan --upgrade-height 2001 --from emoney1xue7fm6es84jze49grm4slhlmr4ffz8a3u7g3t 0.43 emd tx authority schedule-upgrade 'New Staking Rewards 36%' --upgrade-time 1628956125 --from emoney1xue7fm6es84jze49grm4slhlmr4ffz8a3u7g3t # Unix seconds for 2021-08-14 15:48:45 +0000 UTC -emd tx authority schedule-upgrade sdk-v0.43.0 --upgrade-height 2001 --from emoney1xue7fm6es84jze49grm4slhlmr4ffz8a3u7g3t --upgrade-info '{"binaries":{"linux/amd64":"http://localhost:8765/test-upg-0.1.0/emd.zip?checksum=sha256:cadd5b52fe90a04e20b2cbb93291b0d1d0204f17b64b2215eb09f5dc78a127f1"}}'`, +emd tx authority schedule-upgrade sdk-v0.43.0 --upgrade-height 2001 --from emoney1xue7fm6es84jze49grm4slhlmr4ffz8a3u7g3t --upgrade-info '{"binaries":{"linux/amd64":"http://localhost:8765/test-upg-0.2.0/emd.zip?checksum=sha256:cadd5b52fe90a04e20b2cbb93291b0d1d0204f17b64b2215eb09f5dc78a127f1"}}'`, Long: `Schedule a software upgrade by submitting a unique plan name that has not been used before with either an absolute block height or block time. An upgrade handler should be defined at the upgraded binary. Optionally If you set DAEMON_ALLOW_DOWNLOAD_BINARIES=on pass -the upgraded binary download url with the --upgrade-info flag i.e., --upgrade-info '{"binaries":{"linux/amd64":"http://localhost:8765/test-upg-0.1.0/emd.zip?checksum=sha256:cadd5b52fe90a04e20b2cbb93291b0d1d0204f17b64b2215eb09f5dc78a127f1"}}'`, +the upgraded binary download url with the --upgrade-info flag i.e., --upgrade-info '{"binaries":{"linux/amd64":"http://localhost:8765/test-upg-0.2.0/emd.zip?checksum=sha256:cadd5b52fe90a04e20b2cbb93291b0d1d0204f17b64b2215eb09f5dc78a127f1"}}'`, Args: cobra.RangeArgs(1, 2), RunE: func(cmd *cobra.Command, args []string) error { err := cmd.Flags().Set(flags.FlagFrom, args[0]) From 0857a3774a635b9de2fcefcea5210f1ad5ffaf7d Mon Sep 17 00:00:00 2001 From: Mario Karagiorgas Date: Thu, 5 Aug 2021 17:07:10 +0300 Subject: [PATCH 38/49] Upgrade SDK to 0.42.9 --- go.mod | 2 +- go.sum | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/go.mod b/go.mod index f5f1f0e2..89923031 100644 --- a/go.mod +++ b/go.mod @@ -3,7 +3,7 @@ module github.com/e-money/em-ledger go 1.15 require ( - github.com/cosmos/cosmos-sdk v0.42.7 + github.com/cosmos/cosmos-sdk v0.42.9 github.com/e-money/bep3 v0.3.4 github.com/gogo/protobuf v1.3.3 github.com/golang/protobuf v1.5.2 diff --git a/go.sum b/go.sum index 0dc4b685..fa49232f 100644 --- a/go.sum +++ b/go.sum @@ -101,8 +101,8 @@ github.com/coreos/go-systemd v0.0.0-20190321100706-95778dfbb74e/go.mod h1:F5haX7 github.com/coreos/pkg v0.0.0-20160727233714-3ac0863d7acf/go.mod h1:E3G3o1h8I7cfcXa63jLwjI0eiQQMgzzUDFVpN/nH/eA= github.com/coreos/pkg v0.0.0-20180928190104-399ea9e2e55f/go.mod h1:E3G3o1h8I7cfcXa63jLwjI0eiQQMgzzUDFVpN/nH/eA= github.com/cosmos/cosmos-sdk v0.42.4/go.mod h1:I1Zw1zmU4rA/NITaakTb71pXQnQrWyFBhqo3WSeg0vA= -github.com/cosmos/cosmos-sdk v0.42.7 h1:f+ZUjao2y93I37RZ7P2d94JdcEsS7Vq64SBLcNITAVc= -github.com/cosmos/cosmos-sdk v0.42.7/go.mod h1:SrclJP9lMXxz2fCbngxb0brsPNuZXqoQQ9VHuQ3Tpf4= +github.com/cosmos/cosmos-sdk v0.42.9 h1:FvF9lkWZz22Xf9K/KEfJvj+g1nFjLpU8GGTt6xkkJPU= +github.com/cosmos/cosmos-sdk v0.42.9/go.mod h1:SrclJP9lMXxz2fCbngxb0brsPNuZXqoQQ9VHuQ3Tpf4= github.com/cosmos/go-bip39 v0.0.0-20180819234021-555e2067c45d/go.mod h1:tSxLoYXyBmiFeKpvmq4dzayMdCjCnu8uqmCysIGBT2Y= github.com/cosmos/go-bip39 v1.0.0 h1:pcomnQdrdH22njcAatO0yWojsUnCO3y2tNoV1cb6hHY= github.com/cosmos/go-bip39 v1.0.0/go.mod h1:RNJv0H/pOIVgxw6KS7QeX2a0Uo0aKUlfhZ4xuwvCdJw= From e53045825904886138746a033ff5a80e440dbcaf Mon Sep 17 00:00:00 2001 From: Mario Karagiorgas Date: Thu, 5 Aug 2021 18:10:30 +0300 Subject: [PATCH 39/49] Force removal of current, fix typo --- networks/upg/README.md | 2 +- networks/upg/cpemd | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/networks/upg/README.md b/networks/upg/README.md index 7b5f03ea..1af33533 100644 --- a/networks/upg/README.md +++ b/networks/upg/README.md @@ -65,7 +65,7 @@ cd networks/upg # wait for the upgrade # check version, upgraded gas-prices -.emd/cosmovisor/current/bin/emd verion # test-upg-0.0.1 +.emd/cosmovisor/current/bin/emd version # test-upg-0.0.1 .emd/cosmovisor/current/bin/emd q authority gas-prices min_gas_prices: - amount: "1.000000000000000000" diff --git a/networks/upg/cpemd b/networks/upg/cpemd index 0ef42631..48ef406a 100755 --- a/networks/upg/cpemd +++ b/networks/upg/cpemd @@ -29,7 +29,7 @@ echo "node home: $DAEMON_HOME" COSMOVISOR_HOME="$EM_LEDGER_LOC"/networks/upg/.emd/cosmovisor # clean up previous sticky upgrade -rm "$COSMOVISOR_HOME"/current +rm -f "$COSMOVISOR_HOME"/current mkdir -p "$COSMOVISOR_HOME"/genesis/bin cp "$EM_LEDGER_LOC"/build/emd "$COSMOVISOR_HOME"/genesis/bin From 05e85b27bf717c408b9331362516ce7bb3c70f0a Mon Sep 17 00:00:00 2001 From: Mario Karagiorgas Date: Thu, 5 Aug 2021 19:17:01 +0300 Subject: [PATCH 40/49] Optimize Upgrade docker image --- networks/docker/test-upg/Dockerfile | 14 ++++++++------ 1 file changed, 8 insertions(+), 6 deletions(-) diff --git a/networks/docker/test-upg/Dockerfile b/networks/docker/test-upg/Dockerfile index 2dde4ed9..15cb7983 100644 --- a/networks/docker/test-upg/Dockerfile +++ b/networks/docker/test-upg/Dockerfile @@ -1,13 +1,15 @@ -FROM golang:1.16-buster +FROM golang:1.16-alpine -ARG OS - -RUN cd /go/src && \ +# checkout and build linux binary +RUN apk update && \ + apk add --update make && \ + apk add git && \ + cd /go/src && \ git clone https://github.com/e-money/em-ledger.git && \ cd em-ledger && \ git checkout test-upg-0.2.0 && \ BIN_PREFIX=-linux LEDGER_ENABLED=false GOOS=linux GOARCH=amd64 make build -# build native binary +# build MacOS binary WORKDIR /go/src/em-ledger -RUN LEDGER_ENABLED=false GOARCH=amd64 make build \ No newline at end of file +RUN LEDGER_ENABLED=false GOOS=darwin GOARCH=amd64 make build \ No newline at end of file From fee455b723599f82ae48f184df96fb33ca630392 Mon Sep 17 00:00:00 2001 From: Mario Karagiorgas Date: Thu, 5 Aug 2021 19:47:04 +0300 Subject: [PATCH 41/49] Revert to buster image for linux compatibility --- networks/docker/test-upg/Dockerfile | 7 ++----- 1 file changed, 2 insertions(+), 5 deletions(-) diff --git a/networks/docker/test-upg/Dockerfile b/networks/docker/test-upg/Dockerfile index 15cb7983..d70b47c0 100644 --- a/networks/docker/test-upg/Dockerfile +++ b/networks/docker/test-upg/Dockerfile @@ -1,10 +1,7 @@ -FROM golang:1.16-alpine +FROM golang:1.16-buster # checkout and build linux binary -RUN apk update && \ - apk add --update make && \ - apk add git && \ - cd /go/src && \ +RUN cd /go/src && \ git clone https://github.com/e-money/em-ledger.git && \ cd em-ledger && \ git checkout test-upg-0.2.0 && \ From 41949121ebf37488548053f351850e680116a26b Mon Sep 17 00:00:00 2001 From: Mario Karagiorgas Date: Fri, 6 Aug 2021 10:24:07 +0300 Subject: [PATCH 42/49] Fix comment --- networks/upg/README.md | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/networks/upg/README.md b/networks/upg/README.md index 1af33533..519941dd 100644 --- a/networks/upg/README.md +++ b/networks/upg/README.md @@ -65,11 +65,11 @@ cd networks/upg # wait for the upgrade # check version, upgraded gas-prices -.emd/cosmovisor/current/bin/emd version # test-upg-0.0.1 +.emd/cosmovisor/current/bin/emd version # test-upg-0.2.0 .emd/cosmovisor/current/bin/emd q authority gas-prices min_gas_prices: - amount: "1.000000000000000000" denom: ungm #success! -``` \ No newline at end of file +``` From e92913ecb3747b4080bc7f27d6e9e35dcc2a94cd Mon Sep 17 00:00:00 2001 From: Mario Karagiorgas Date: Fri, 6 Aug 2021 19:59:21 +0300 Subject: [PATCH 43/49] Add upgrade tests by time --- app_test.go | 156 ++++++++++++++++++++++++++++++++++--------- networktest/emcli.go | 9 ++- upgrade_test.go | 2 +- 3 files changed, 135 insertions(+), 32 deletions(-) diff --git a/app_test.go b/app_test.go index 693645c4..3ef8e7dd 100644 --- a/app_test.go +++ b/app_test.go @@ -3,9 +3,13 @@ package emoney import ( "encoding/json" "os" + "sync" "testing" "time" + upgradekeeper "github.com/cosmos/cosmos-sdk/x/upgrade/keeper" + "github.com/e-money/em-ledger/x/authority" + apptypes "github.com/e-money/em-ledger/types" sdk "github.com/cosmos/cosmos-sdk/types" @@ -19,6 +23,8 @@ import ( dbm "github.com/tendermint/tm-db" ) +var configOnce sync.Once + func TestSimAppExportAndBlockedAddrs(t *testing.T) { encCfg, db, app, _ := getEmSimApp(t, rand.Bytes(sdk.AddrLen)) app.Commit() @@ -58,7 +64,6 @@ func getEmSimApp( } genesisState := ModuleBasics.DefaultGenesis(encCfg.Marshaler) - //authorityState := authority.NewGenesisState(rand.Bytes(sdk.AddrLen), sdk.NewDecCoins()) authorityState := authtypes.GenesisState{AuthorityKey: authorityAcc.String(), MinGasPrices: sdk.NewDecCoins()} genesisState["authority"] = encCfg.Marshaler.MustMarshalJSON(&authorityState) @@ -92,7 +97,7 @@ type emAppTests struct { authority sdk.AccAddress } -func (et *emAppTests) initEmApp(t *testing.T) { +func (et emAppTests) initEmApp(t *testing.T) emAppTests { t.Helper() var err error @@ -107,17 +112,19 @@ func (et *emAppTests) initEmApp(t *testing.T) { Time: time.Now(), Height: 10, }) + + return et } func Test_Upgrade(t *testing.T) { - apptypes.ConfigureSDK() + configOnce.Do(apptypes.ConfigureSDK) tests := []struct { suite emAppTests name string plan upgradetypes.Plan setupUpgCond func(simApp emAppTests, plan *upgradetypes.Plan) - expPass bool + expSchedPass bool qrySched bool qryApply bool }{ @@ -130,7 +137,7 @@ func Test_Upgrade(t *testing.T) { setupUpgCond: func(simApp emAppTests, plan *upgradetypes.Plan) { plan.Time = simApp.ctx.BlockTime().Add(time.Hour) }, - expPass: true, + expSchedPass: true, }, { name: "successful height schedule", @@ -140,7 +147,7 @@ func Test_Upgrade(t *testing.T) { Height: 123450000, }, setupUpgCond: func(simApp emAppTests, plan *upgradetypes.Plan) {}, - expPass: true, + expSchedPass: true, }, { name: "setting both time and height schedule", @@ -152,7 +159,7 @@ func Test_Upgrade(t *testing.T) { setupUpgCond: func(simApp emAppTests, plan *upgradetypes.Plan) { plan.Time = simApp.ctx.BlockTime().Add(time.Hour) }, - expPass: false, + expSchedPass: false, }, { name: "successful overwrite", @@ -172,7 +179,7 @@ func Test_Upgrade(t *testing.T) { ) require.NoError(t, err) }, - expPass: true, + expSchedPass: true, }, { name: "successful overwrite future with earlier date", @@ -191,7 +198,7 @@ func Test_Upgrade(t *testing.T) { ) require.NoError(t, err) }, - expPass: true, + expSchedPass: true, }, { name: "successful overwrite earlier with future date", @@ -210,7 +217,7 @@ func Test_Upgrade(t *testing.T) { ) require.NoError(t, err) }, - expPass: true, + expSchedPass: true, }, { name: "unsuccessful schedule: missing plan name", @@ -218,7 +225,7 @@ func Test_Upgrade(t *testing.T) { Height: 123450000, }, setupUpgCond: func(simApp emAppTests, plan *upgradetypes.Plan) {}, - expPass: false, + expSchedPass: false, }, { name: "unsuccessful time schedule: initialized, uninitialized due date in past", @@ -229,7 +236,7 @@ func Test_Upgrade(t *testing.T) { setupUpgCond: func(simApp emAppTests, plan *upgradetypes.Plan) { plan.Time = simApp.ctx.BlockTime() }, - expPass: false, + expSchedPass: false, }, { name: "unsuccessful height schedule: due date in past", @@ -239,7 +246,7 @@ func Test_Upgrade(t *testing.T) { Height: 1, }, setupUpgCond: func(simApp emAppTests, plan *upgradetypes.Plan) {}, - expPass: false, + expSchedPass: false, }, { name: "unsuccessful schedule: schedule already executed", @@ -259,14 +266,13 @@ func Test_Upgrade(t *testing.T) { ) require.NoError(t, err) }, - expPass: false, + expSchedPass: false, }, } for _, tt := range tests { t.Run( tt.name, func(t *testing.T) { - tt.suite = emAppTests{} - tt.suite.initEmApp(t) + tt.suite = emAppTests{}.initEmApp(t) // setup test case tt.setupUpgCond(tt.suite, &tt.plan) @@ -278,8 +284,9 @@ func Test_Upgrade(t *testing.T) { ) schedPlan, hasPlan := tt.suite.app.authorityKeeper.GetUpgradePlan(tt.suite.ctx) - // validate plan side-effect - if tt.expPass { + // validate plan side effect + if tt.expSchedPass { + require.NoError(t, err, "Upgrade() error = %v, expSchedPass %v", err, tt.expSchedPass) require.Truef(t, hasPlan, "hasPlan: %t there should be a plan", hasPlan) require.Equalf(t, schedPlan, tt.plan, "queried %v != %v", schedPlan, tt.plan) } else { @@ -288,23 +295,112 @@ func Test_Upgrade(t *testing.T) { } // apply and confirm plan deletion - if err == nil { - tt.suite.app.upgradeKeeper.SetUpgradeHandler(tt.plan.Name, func(_ sdk.Context, _ upgradetypes.Plan) {}) - _, err = tt.suite.app.authorityKeeper.ApplyUpgrade( - tt.suite.ctx, tt.suite.authority, tt.plan, - ) - schedPlan, hasPlan = tt.suite.app.authorityKeeper.GetUpgradePlan(tt.suite.ctx) - require.Falsef(t, hasPlan, "hasPlan: %t plan should not exist", hasPlan) - require.NotEqualf(t, schedPlan, tt.plan, "queried %v == %v", schedPlan, tt.plan) + if tt.expSchedPass { + executePlan(tt.suite.ctx, t, tt.suite.app.upgradeKeeper, tt.suite.app.authorityKeeper, tt.suite.authority, tt.plan) } + }, + ) + } +} - if (err != nil) == tt.expPass { - t.Errorf( - "Upgrade() error = %v, expPass %v", err, tt.expPass, +func Test_UpgradeByTime(t *testing.T) { + + configOnce.Do(apptypes.ConfigureSDK) + + tests := []struct { + suite emAppTests + name string + plan upgradetypes.Plan + blockTimes []time.Time + setupUpgCond func(simApp emAppTests, blockTimes []time.Time, plan *upgradetypes.Plan) + expPass bool + qrySched bool + qryApply bool + }{ + { + name: "successful time plan + 1minute", + plan: upgradetypes.Plan{ + Name: "all-good", + Info: "some text here", + }, + setupUpgCond: func(simApp emAppTests, blockTimes []time.Time, plan *upgradetypes.Plan) { + const duration = 10 * time.Minute + plan.Time = simApp.ctx.BlockTime().Add(duration) + blockTimes = []time.Time{ + simApp.ctx.BlockTime(), + simApp.ctx.BlockTime().Add(time.Minute), + plan.Time.Add(-time.Nanosecond), + } + }, + expPass: true, + }, + } + for _, tt := range tests { + t.Run( + tt.name, func(t *testing.T) { + tt.suite = emAppTests{}.initEmApp(t) + + // setup test case + tt.setupUpgCond(tt.suite, tt.blockTimes, &tt.plan) + + // schedule upgrade plan + var err error + _, err = tt.suite.app.authorityKeeper.ScheduleUpgrade( + tt.suite.ctx, tt.suite.authority, tt.plan, + ) + schedPlan, hasPlan := tt.suite.app.authorityKeeper.GetUpgradePlan(tt.suite.ctx) + + // validate plan side effect + if tt.expPass { + require.NoError(t, err, "Upgrade() error = %v, expSchedPass %v", err, tt.expPass) + require.Truef( + t, hasPlan, "hasPlan: %t there should be a plan", + hasPlan, + ) + require.Equalf( + t, schedPlan, tt.plan, "queried %v != %v", schedPlan, + tt.plan, + ) + } else { + require.Falsef( + t, hasPlan, "hasPlan: %t plan should not exist", hasPlan, + ) + require.NotEqualf( + t, schedPlan, tt.plan, "queried %v == %v", schedPlan, + tt.plan, ) - return } + + // advance chain and confirm plan execution + tt.suite.app.authorityKeeper.GetUpgradePlan(tt.suite.ctx) + for _, blockTime := range tt.blockTimes { + tt.suite.ctx = tt.suite.ctx.WithBlockTime(blockTime) + require.Falsef(t, schedPlan.ShouldExecute(tt.suite.ctx), "premature timing for executing plan") + } + // move forward to execution time + tt.suite.ctx = tt.suite.ctx.WithBlockTime(schedPlan.Time) + require.Truef(t, schedPlan.ShouldExecute(tt.suite.ctx), "plan should be ripe for execution") + + executePlan( + tt.suite.ctx, t, tt.suite.app.upgradeKeeper, + tt.suite.app.authorityKeeper, tt.suite.authority, tt.plan, + ) }, ) } } + +func executePlan( + ctx sdk.Context, t *testing.T, uk upgradekeeper.Keeper, ak authority.Keeper, + authority sdk.AccAddress, plan upgradetypes.Plan, +) { + uk.SetUpgradeHandler(plan.Name, func(_ sdk.Context, _ upgradetypes.Plan) {}) + + _, err := ak.ApplyUpgrade(ctx, authority, plan) + require.NoError(t, err) + + schedPlan, hasPlan := ak.GetUpgradePlan(ctx) + require.Falsef(t, hasPlan, "hasPlan: %t plan should not exist", hasPlan) + require.NotEqualf(t, schedPlan, plan, "queried %v == %v", schedPlan, plan) + require.NoError(t, err, "ApplyUpgrade() error = %v", err) +} diff --git a/networktest/emcli.go b/networktest/emcli.go index 412c4e46..fd6385bd 100644 --- a/networktest/emcli.go +++ b/networktest/emcli.go @@ -13,6 +13,7 @@ import ( "regexp" "strconv" "strings" + "time" sdk "github.com/cosmos/cosmos-sdk/types" "github.com/tidwall/gjson" @@ -51,12 +52,18 @@ func (cli Emcli) AuthorityCreateIssuer(authority, issuer Key, denoms ...string) return execCmdWithInput(args, KeyPwd) } -func (cli Emcli) AuthorityUpgSched(authority Key, planName string, height int64) (string, bool, error) { +func (cli Emcli) UpgSchedByHeight(authority Key, planName string, height int64) (string, bool, error) { args := cli.addTransactionFlags("tx", "authority", "schedule-upgrade", authority.name, planName, "--upgrade-height", strconv.FormatInt(height, 10)) return execCmdWithInput(args, KeyPwd) } +func (cli Emcli) UpgSchedByTime(authority Key, planName string, time time.Time) (string, bool, error) { + args := cli.addTransactionFlags("tx", "authority", "schedule-upgrade", + authority.name, planName, "--upgrade-height", strconv.FormatInt(time.Unix(), 10)) + return execCmdWithInput(args, KeyPwd) +} + func (cli Emcli) AuthorityDestroyIssuer(authority, issuer Key) (string, bool, error) { args := cli.addTransactionFlags("tx", "authority", "destroy-issuer", authority.name, issuer.GetAddress()) return execCmdWithInput(args, KeyPwd) diff --git a/upgrade_test.go b/upgrade_test.go index fb4e0c0e..3d9b4061 100644 --- a/upgrade_test.go +++ b/upgrade_test.go @@ -32,7 +32,7 @@ var _ = Describe("Upgrade", func() { const upgDelta = 5 upgHeight := chainHeight + upgDelta - _, success, err := emcli.AuthorityUpgSched(Authority, name, + _, success, err := emcli.UpgSchedByHeight(Authority, name, upgHeight, ) Expect(err).ToNot(HaveOccurred()) From 94cc6d9580ddaf1e093fbb6d84d343b764f74a07 Mon Sep 17 00:00:00 2001 From: Mario Karagiorgas Date: Sat, 7 Aug 2021 18:58:16 +0300 Subject: [PATCH 44/49] CapabilityKeeper Init Change per Cosmos #9800 --- app.go | 2 ++ 1 file changed, 2 insertions(+) diff --git a/app.go b/app.go index 28bffa31..4fe826b3 100644 --- a/app.go +++ b/app.go @@ -386,6 +386,8 @@ func NewApp( app.mm.SetOrderBeginBlockers( // todo (reviewer): check which modules make sense and which order upgradetypes.ModuleName, + // Cosmos #9800: capability module's begin blocker must come before any modules using capabilities (e.g. IBC) + capabilitytypes.ModuleName, evidencetypes.ModuleName, stakingtypes.ModuleName, ibchost.ModuleName, authority.ModuleName, market.ModuleName, inflation.ModuleName, emslashing.ModuleName, emdistr.ModuleName, buyback.ModuleName, bep3.ModuleName, From aea0c589c5743f6ce2121d6846053e3272992fcf Mon Sep 17 00:00:00 2001 From: Mario Karagiorgas Date: Tue, 10 Aug 2021 18:36:12 +0300 Subject: [PATCH 45/49] #111 Remove time based upgrade --- networktest/emcli.go | 7 ------- x/authority/client/cli/tx.go | 23 +++++------------------ x/authority/keeper/msg_server.go | 8 ++++++++ x/authority/keeper/msg_server_test.go | 2 +- x/authority/types/errors.go | 1 + 5 files changed, 15 insertions(+), 26 deletions(-) diff --git a/networktest/emcli.go b/networktest/emcli.go index fd6385bd..a5a7e830 100644 --- a/networktest/emcli.go +++ b/networktest/emcli.go @@ -13,7 +13,6 @@ import ( "regexp" "strconv" "strings" - "time" sdk "github.com/cosmos/cosmos-sdk/types" "github.com/tidwall/gjson" @@ -58,12 +57,6 @@ func (cli Emcli) UpgSchedByHeight(authority Key, planName string, height int64) return execCmdWithInput(args, KeyPwd) } -func (cli Emcli) UpgSchedByTime(authority Key, planName string, time time.Time) (string, bool, error) { - args := cli.addTransactionFlags("tx", "authority", "schedule-upgrade", - authority.name, planName, "--upgrade-height", strconv.FormatInt(time.Unix(), 10)) - return execCmdWithInput(args, KeyPwd) -} - func (cli Emcli) AuthorityDestroyIssuer(authority, issuer Key) (string, bool, error) { args := cli.addTransactionFlags("tx", "authority", "destroy-issuer", authority.name, issuer.GetAddress()) return execCmdWithInput(args, KeyPwd) diff --git a/x/authority/client/cli/tx.go b/x/authority/client/cli/tx.go index 0b4aa3bf..26078d72 100644 --- a/x/authority/client/cli/tx.go +++ b/x/authority/client/cli/tx.go @@ -194,7 +194,6 @@ func GetCmdScheduleUpgrade() *cobra.Command { Use: "schedule-upgrade [authority_key_or_address] plan_name", Short: "Schedule a software upgrade", Example: `emd tx authority schedule-upgrade someplan --upgrade-height 2001 --from emoney1xue7fm6es84jze49grm4slhlmr4ffz8a3u7g3t 0.43 -emd tx authority schedule-upgrade 'New Staking Rewards 36%' --upgrade-time 1628956125 --from emoney1xue7fm6es84jze49grm4slhlmr4ffz8a3u7g3t # Unix seconds for 2021-08-14 15:48:45 +0000 UTC emd tx authority schedule-upgrade sdk-v0.43.0 --upgrade-height 2001 --from emoney1xue7fm6es84jze49grm4slhlmr4ffz8a3u7g3t --upgrade-info '{"binaries":{"linux/amd64":"http://localhost:8765/test-upg-0.2.0/emd.zip?checksum=sha256:cadd5b52fe90a04e20b2cbb93291b0d1d0204f17b64b2215eb09f5dc78a127f1"}}'`, Long: `Schedule a software upgrade by submitting a unique plan name that has not been used before with either an absolute block height or block time. An @@ -207,9 +206,7 @@ the upgraded binary download url with the --upgrade-info flag i.e., --upgrade-in return err } - if err := validateUpgFlags( - UpgHeight, upgHeightVal, UpgTime, upgTimeSecsVal, - ); err != nil { + if err := validateUpgFlags(UpgHeight, upgHeightVal); err != nil { return err } @@ -239,9 +236,6 @@ the upgraded binary download url with the --upgrade-info flag i.e., --upgrade-in } f := cmd.Flags() f.Int64VarP(&upgHeightVal, UpgHeight, "n", 0, "Upgrade block height number") - f.Int64VarP( - &upgTimeSecsVal, UpgTime, "t", 0, "upgrade block time (in Unix seconds)", - ) f.StringVarP( &upgInfoVal, UpgInfo, "i", "", "Upgrade info", ) @@ -250,13 +244,11 @@ the upgraded binary download url with the --upgrade-info flag i.e., --upgrade-in return cmd } -func validateUpgFlags( - upgHeight string, upgHeightVal int64, upgTime string, timeVal int64, -) error { - if upgHeightVal == 0 && timeVal == 0 { +func validateUpgFlags(upgHeight string, upgHeightVal int64) error { + if upgHeightVal == 0 { return sdkerrors.Wrapf( types.ErrMissingFlag, - "need to specify --%s or --%s", upgHeight, upgTime, + "need to specify --%s", upgHeight, ) } @@ -264,15 +256,10 @@ func validateUpgFlags( if upgHeightVal != 0 { flagsSet++ } - if timeVal != 0 { - flagsSet++ - } if flagsSet != 1 { return sdkerrors.Wrapf( sdkerrors.ErrInvalidRequest, - "specify only one of the flags: --%s or --%s", upgHeight, - upgTime, - ) + "specify only one of the flags: --%s", upgHeight) } return nil diff --git a/x/authority/keeper/msg_server.go b/x/authority/keeper/msg_server.go index 740d1342..36f11943 100644 --- a/x/authority/keeper/msg_server.go +++ b/x/authority/keeper/msg_server.go @@ -2,6 +2,7 @@ package keeper import ( "context" + "fmt" upgradetypes "github.com/cosmos/cosmos-sdk/x/upgrade/types" @@ -124,6 +125,13 @@ func (m msgServer) ScheduleUpgrade( return nil, sdkerrors.Wrap(sdkerrors.ErrInvalidAddress, "authority") } + if msg.Plan.Time.Unix() != 0 { + return nil, sdkerrors.Wrap( + types.ErrPlanTimeIsSet, + fmt.Sprintf("Plan time: %s", msg.Plan.Time.String()), + ) + } + result, err := m.k.ScheduleUpgrade(ctx, authority, msg.Plan) if err != nil { return nil, err diff --git a/x/authority/keeper/msg_server_test.go b/x/authority/keeper/msg_server_test.go index 28d8cebb..3dc63284 100644 --- a/x/authority/keeper/msg_server_test.go +++ b/x/authority/keeper/msg_server_test.go @@ -358,7 +358,7 @@ func TestScheduleUpgrade(t *testing.T) { }, expErr: true, }, - "missing time or height": { + "missing height": { req: &types.MsgScheduleUpgrade{ Authority: authorityAddr.String(), Plan: upgradetypes.Plan{ diff --git a/x/authority/types/errors.go b/x/authority/types/errors.go index e44a5acf..622cc3b6 100644 --- a/x/authority/types/errors.go +++ b/x/authority/types/errors.go @@ -16,4 +16,5 @@ var ( ErrInvalidGasPrices = sdkerrors.Register(ModuleName, 5, "Invalid gas prices") ErrUnknownDenom = sdkerrors.Register(ModuleName, 6, "Unknown denomination specified") ErrMissingFlag = sdkerrors.Register(ModuleName, 7, "missing flag") + ErrPlanTimeIsSet = sdkerrors.Register(ModuleName, 8, "upgrade plan cannot set time") ) From 7923a5f5e3ac98a09d71211ab00f737ecded2d22 Mon Sep 17 00:00:00 2001 From: Mario Karagiorgas Date: Tue, 10 Aug 2021 19:58:18 +0300 Subject: [PATCH 46/49] Init time to zero --- x/authority/client/cli/tx.go | 8 +++----- x/authority/keeper/msg_server_test.go | 1 + 2 files changed, 4 insertions(+), 5 deletions(-) diff --git a/x/authority/client/cli/tx.go b/x/authority/client/cli/tx.go index 26078d72..6022a5b6 100644 --- a/x/authority/client/cli/tx.go +++ b/x/authority/client/cli/tx.go @@ -186,8 +186,8 @@ const ( func GetCmdScheduleUpgrade() *cobra.Command { var ( - upgHeightVal, upgTimeSecsVal int64 - upgInfoVal string + upgHeightVal int64 + upgInfoVal string ) cmd := &cobra.Command{ @@ -210,8 +210,6 @@ the upgraded binary download url with the --upgrade-info flag i.e., --upgrade-in return err } - upgTimeVal := time.Unix(upgTimeSecsVal, 0) - clientCtx, err := client.GetClientTxContext(cmd) if err != nil { return err @@ -221,7 +219,7 @@ the upgraded binary download url with the --upgrade-info flag i.e., --upgrade-in Authority: clientCtx.GetFromAddress().String(), Plan: upgtypes.Plan{ Name: args[1], - Time: upgTimeVal, + Time: time.Unix(0, 0), Height: upgHeightVal, Info: upgInfoVal, }, diff --git a/x/authority/keeper/msg_server_test.go b/x/authority/keeper/msg_server_test.go index 3dc63284..b06a8833 100644 --- a/x/authority/keeper/msg_server_test.go +++ b/x/authority/keeper/msg_server_test.go @@ -310,6 +310,7 @@ func TestScheduleUpgrade(t *testing.T) { Plan: upgradetypes.Plan{ Name: "plan8", Height: 100, + Time: time.Unix(0, 0), }, }, mockFn: func(ctx sdk.Context, authority sdk.AccAddress, plan upgradetypes.Plan) (*sdk.Result, error) { From 1f33422fd536a7a4000503b00d45bf09c58901a0 Mon Sep 17 00:00:00 2001 From: Mario Karagiorgas Date: Wed, 11 Aug 2021 12:00:20 +0300 Subject: [PATCH 47/49] Add text sed repl upgrade handler --- Makefile | 12 +++++++----- networks/upg/upgfunc.txt | 31 +++++++++++++++++++++++++++++++ 2 files changed, 38 insertions(+), 5 deletions(-) create mode 100644 networks/upg/upgfunc.txt diff --git a/Makefile b/Makefile index b9b59b0f..71392560 100644 --- a/Makefile +++ b/Makefile @@ -67,18 +67,20 @@ fmt: imp: gci -w **/*.go - install: go install -mod=readonly $(BUILD_FLAGS) ./cmd/emd -build-linux: - # Linux images for docker-compose - # CGO_ENABLED=0 added to solve this issue: https://stackoverflow.com/a/36308464 - BIN_PREFIX=-linux LEDGER_ENABLED=false GOOS=linux GOARCH=amd64 $(MAKE) build +build-test-upg: docker run --rm --entrypoint cat emoney/cosmovisor /go/bin/cosmovisor > build/cosmovisor chmod +x build/cosmovisor docker run --rm --entrypoint cat emoney/test-upg /go/src/em-ledger/build/emd-linux > "build/emdupg-linux" chmod +x "build/emdupg-linux" + sed -i -e '/bep3.NewKeeper/r networks/upg/upgfunc.txt' app.go + +build-linux: + # Linux images for docker-compose + # CGO_ENABLED=0 added to solve this issue: https://stackoverflow.com/a/36308464 + BIN_PREFIX=-linux LEDGER_ENABLED=false GOOS=linux GOARCH=amd64 $(MAKE) build build-all: build-linux emdupg $(MAKE) build diff --git a/networks/upg/upgfunc.txt b/networks/upg/upgfunc.txt new file mode 100644 index 00000000..1830bbda --- /dev/null +++ b/networks/upg/upgfunc.txt @@ -0,0 +1,31 @@ + + /* + * This is a test handler for trying out cosmovisor + * Setting gas to One ungm + **/ + const testUpgradeHandler = "test-upg-0.2.0" + app.upgradeKeeper.SetUpgradeHandler(testUpgradeHandler, func(ctx sdk.Context, plan upgradetypes.Plan) { + genesisAuth := app.authorityKeeper.GetAuthoritySet(ctx) + if genesisAuth.Address == "" { + panic("authority should be set in genesis") + } + + authAcc, err := sdk.AccAddressFromBech32(genesisAuth.Address) + if err != nil { + panic(err) + } + + newGas := sdk.DecCoins{ + sdk.NewDecCoin("ungm", sdk.OneInt()), + } + + _, err = app.authorityKeeper.SetGasPrices(ctx, authAcc, newGas) + if err != nil { + panic(err) + } + + gasPrices := app.authorityKeeper.GetGasPrices(ctx) + if gasPrices.Empty() || !gasPrices.IsEqual(newGas) { + panic(fmt.Sprintf("expected Gas: %+v != store Gas: %+v", newGas, gasPrices)) + } + }) From 9f8be7a91e2c49cb9c697c802ccd74287113c057 Mon Sep 17 00:00:00 2001 From: Mario Karagiorgas Date: Wed, 11 Aug 2021 14:32:15 +0300 Subject: [PATCH 48/49] Remove test ApplyUpgrade --- app_test.go | 18 +++++++++--------- x/authority/keeper/keeper.go | 12 ------------ 2 files changed, 9 insertions(+), 21 deletions(-) diff --git a/app_test.go b/app_test.go index 3ef8e7dd..a15e83e9 100644 --- a/app_test.go +++ b/app_test.go @@ -257,14 +257,13 @@ func Test_Upgrade(t *testing.T) { }, setupUpgCond: func(simEmApp emAppTests, plan *upgradetypes.Plan) { simEmApp.app.upgradeKeeper.SetUpgradeHandler("all-good", func(_ sdk.Context, _ upgradetypes.Plan) {}) - _, err := simEmApp.app.authorityKeeper.ApplyUpgrade( - simEmApp.ctx, simEmApp.authority, upgradetypes.Plan{ + simEmApp.app.upgradeKeeper.ApplyUpgrade( + simEmApp.ctx, upgradetypes.Plan{ Name: "all-good", Info: "some text here", Height: 123450000, }, ) - require.NoError(t, err) }, expSchedPass: false, }, @@ -296,7 +295,10 @@ func Test_Upgrade(t *testing.T) { // apply and confirm plan deletion if tt.expSchedPass { - executePlan(tt.suite.ctx, t, tt.suite.app.upgradeKeeper, tt.suite.app.authorityKeeper, tt.suite.authority, tt.plan) + executePlan( + tt.suite.ctx, t, tt.suite.app.upgradeKeeper, + tt.suite.app.authorityKeeper, tt.plan, + ) } }, ) @@ -383,7 +385,7 @@ func Test_UpgradeByTime(t *testing.T) { executePlan( tt.suite.ctx, t, tt.suite.app.upgradeKeeper, - tt.suite.app.authorityKeeper, tt.suite.authority, tt.plan, + tt.suite.app.authorityKeeper, tt.plan, ) }, ) @@ -392,15 +394,13 @@ func Test_UpgradeByTime(t *testing.T) { func executePlan( ctx sdk.Context, t *testing.T, uk upgradekeeper.Keeper, ak authority.Keeper, - authority sdk.AccAddress, plan upgradetypes.Plan, + plan upgradetypes.Plan, ) { uk.SetUpgradeHandler(plan.Name, func(_ sdk.Context, _ upgradetypes.Plan) {}) - _, err := ak.ApplyUpgrade(ctx, authority, plan) - require.NoError(t, err) + uk.ApplyUpgrade(ctx, plan) schedPlan, hasPlan := ak.GetUpgradePlan(ctx) require.Falsef(t, hasPlan, "hasPlan: %t plan should not exist", hasPlan) require.NotEqualf(t, schedPlan, plan, "queried %v == %v", schedPlan, plan) - require.NoError(t, err, "ApplyUpgrade() error = %v", err) } diff --git a/x/authority/keeper/keeper.go b/x/authority/keeper/keeper.go index 0dca9c87..ba4958f9 100644 --- a/x/authority/keeper/keeper.go +++ b/x/authority/keeper/keeper.go @@ -230,18 +230,6 @@ func (k Keeper) ScheduleUpgrade( return &sdk.Result{Events: ctx.EventManager().ABCIEvents()}, nil } -func (k Keeper) ApplyUpgrade( - ctx sdk.Context, authority sdk.AccAddress, plan upgradetypes.Plan, -) (*sdk.Result, error) { - if err := k.ValidateAuthority(ctx, authority); err != nil { - return nil, err - } - - k.upgradeKeeper.ApplyUpgrade(ctx, plan) - - return &sdk.Result{Events: ctx.EventManager().ABCIEvents()}, nil -} - func (k Keeper) GetUpgradePlan(ctx sdk.Context) (plan upgradetypes.Plan, havePlan bool) { return k.upgradeKeeper.GetUpgradePlan(ctx) From 8f5857fa303da435a6cda3e41f81928ba30dc27b Mon Sep 17 00:00:00 2001 From: Mario Karagiorgas Date: Wed, 11 Aug 2021 16:10:34 +0300 Subject: [PATCH 49/49] Remove upg branch dependency Makefile: separate testupg binary from build-linux Update README.md --- Makefile | 11 ++++------- networks/docker/Makefile | 2 +- networks/docker/test-upg/Dockerfile | 7 ++++++- networks/upg/README.md | 3 ++- 4 files changed, 13 insertions(+), 10 deletions(-) diff --git a/Makefile b/Makefile index 71392560..82b382fd 100644 --- a/Makefile +++ b/Makefile @@ -49,10 +49,6 @@ BUILD_FLAGS := -tags "$(build_tags)" -ldflags '$(ldflags)' build: go build -mod=readonly $(BUILD_FLAGS) -o build/emd$(BIN_PREFIX) ./cmd/emd -emdupg: - docker run --rm --entrypoint cat emoney/test-upg /go/src/em-ledger/build/emd > "build/emdupg" - chmod +x "build/emdupg" - cosmovisor: go install github.com/cosmos/cosmos-sdk/cosmovisor/cmd/cosmovisor@latest @@ -73,16 +69,17 @@ install: build-test-upg: docker run --rm --entrypoint cat emoney/cosmovisor /go/bin/cosmovisor > build/cosmovisor chmod +x build/cosmovisor + docker run --rm --entrypoint cat emoney/test-upg /go/src/em-ledger/build/emd > "build/emdupg" + chmod +x "build/emdupg" docker run --rm --entrypoint cat emoney/test-upg /go/src/em-ledger/build/emd-linux > "build/emdupg-linux" chmod +x "build/emdupg-linux" - sed -i -e '/bep3.NewKeeper/r networks/upg/upgfunc.txt' app.go build-linux: # Linux images for docker-compose # CGO_ENABLED=0 added to solve this issue: https://stackoverflow.com/a/36308464 BIN_PREFIX=-linux LEDGER_ENABLED=false GOOS=linux GOARCH=amd64 $(MAKE) build -build-all: build-linux emdupg +build-all: build-linux build-test-upg $(MAKE) build build-docker: @@ -118,7 +115,7 @@ license: GO111MODULE=off go get github.com/google/addlicense/ addlicense -f LICENSE . -.PHONY: build build-linux emdupg cosmovisor clean test bdd-test build-docker license +.PHONY: build build-linux build-test-upg cosmovisor clean test bdd-test build-docker license ############################################################################### ### Protobuf ### diff --git a/networks/docker/Makefile b/networks/docker/Makefile index c6493f13..459c7d14 100644 --- a/networks/docker/Makefile +++ b/networks/docker/Makefile @@ -9,7 +9,7 @@ cosmovisor: docker build cosmovisor --tag emoney/cosmovisor test-upg: - docker build test-upg --tag emoney/test-upg + docker build test-upg --build-arg branch=$$(git rev-parse --abbrev-ref HEAD) --build-arg version=test-upg-0.2.0 --tag emoney/test-upg # todo (reviewer): please note the rest-server is not a command anymore. Please enable `api` section in `app.toml` instead diff --git a/networks/docker/test-upg/Dockerfile b/networks/docker/test-upg/Dockerfile index d70b47c0..d8cb6108 100644 --- a/networks/docker/test-upg/Dockerfile +++ b/networks/docker/test-upg/Dockerfile @@ -1,10 +1,15 @@ FROM golang:1.16-buster +ARG branch +ARG version + # checkout and build linux binary RUN cd /go/src && \ git clone https://github.com/e-money/em-ledger.git && \ cd em-ledger && \ - git checkout test-upg-0.2.0 && \ + git checkout $branch && \ + sed -i -e '/bep3.NewKeeper/r networks/upg/upgfunc.txt' app.go && \ + git tag $version && \ BIN_PREFIX=-linux LEDGER_ENABLED=false GOOS=linux GOARCH=amd64 make build # build MacOS binary diff --git a/networks/upg/README.md b/networks/upg/README.md index 519941dd..58a04c70 100644 --- a/networks/upg/README.md +++ b/networks/upg/README.md @@ -7,7 +7,7 @@ Please note if you'd rather test the upgrade module within the **e-money local-t ```shell cd em-ledger make build-docker -make build-linux +make build-all go test -v --tags="bdd" bdd_test.go upgrade_test.go ``` @@ -22,6 +22,7 @@ Note these scripts at **em-ledger/networks/upg**: * `startcv` (starts a single e-money node with cosmovisor) * `upg-sched` schedule an upgrade by passing the upgrade block height * `upg-sched-srv` optional documentation setup and schedule command for upgrading with server downloaded binary +* `upgfunc.txt` Go snippet to be inserted as the upgrade module handler in the *upgrade* binary. ### Components installation Build the revamped Docker, Linux artifacts