From a9225765fea436d8bc70a3c8104ac879e94f69e4 Mon Sep 17 00:00:00 2001 From: lumtis Date: Tue, 5 Mar 2024 14:00:02 +0100 Subject: [PATCH] rename policy address --- contrib/localnet/scripts/start-zetacored.sh | 4 +- docs/openapi/openapi.swagger.yaml | 6 +- proto/authority/policies.proto | 4 +- testutil/sample/authority.go | 2 +- typescript/authority/policies_pb.d.ts | 20 ++-- x/authority/keeper/policies.go | 2 +- x/authority/keeper/policies_test.go | 2 +- x/authority/module.go | 8 +- x/authority/types/client_ctx.go | 14 --- x/authority/types/genesis_test.go | 2 +- .../types/message_update_policies_test.go | 2 +- x/authority/types/policies.go | 4 +- x/authority/types/policies.pb.go | 105 +++++++++--------- x/authority/types/policies_test.go | 8 +- .../msg_server_update_crosschain_flags.go | 2 +- x/observer/migrations/v7/migrate.go | 2 +- x/observer/migrations/v7/migrate_test.go | 32 +++--- x/observer/types/message_crosschain_flags.go | 6 +- .../types/message_crosschain_flags_test.go | 4 +- 19 files changed, 104 insertions(+), 125 deletions(-) delete mode 100644 x/authority/types/client_ctx.go diff --git a/contrib/localnet/scripts/start-zetacored.sh b/contrib/localnet/scripts/start-zetacored.sh index fb5d8a1255..713627171b 100755 --- a/contrib/localnet/scripts/start-zetacored.sh +++ b/contrib/localnet/scripts/start-zetacored.sh @@ -118,8 +118,8 @@ then # set admin account zetacored add-genesis-account zeta1srsq755t654agc0grpxj4y3w0znktrpr9tcdgk 100000000000000000000000000azeta zetacored add-genesis-account zeta1n0rn6sne54hv7w2uu93fl48ncyqz97d3kty6sh 100000000000000000000000000azeta # Funds the localnet_gov_admin account - cat $HOME/.zetacored/config/genesis.json | jq '.app_state["authority"]["policies"]["policy_addresses"][0]["address"]="zeta1srsq755t654agc0grpxj4y3w0znktrpr9tcdgk"' > $HOME/.zetacored/config/tmp_genesis.json && mv $HOME/.zetacored/config/tmp_genesis.json $HOME/.zetacored/config/genesis.json - cat $HOME/.zetacored/config/genesis.json | jq '.app_state["authority"]["policies"]["policy_addresses"][1]["address"]="zeta1srsq755t654agc0grpxj4y3w0znktrpr9tcdgk"' > $HOME/.zetacored/config/tmp_genesis.json && mv $HOME/.zetacored/config/tmp_genesis.json $HOME/.zetacored/config/genesis.json + cat $HOME/.zetacored/config/genesis.json | jq '.app_state["authority"]["policies"]["items"][0]["address"]="zeta1srsq755t654agc0grpxj4y3w0znktrpr9tcdgk"' > $HOME/.zetacored/config/tmp_genesis.json && mv $HOME/.zetacored/config/tmp_genesis.json $HOME/.zetacored/config/genesis.json + cat $HOME/.zetacored/config/genesis.json | jq '.app_state["authority"]["policies"]["items"][1]["address"]="zeta1srsq755t654agc0grpxj4y3w0znktrpr9tcdgk"' > $HOME/.zetacored/config/tmp_genesis.json && mv $HOME/.zetacored/config/tmp_genesis.json $HOME/.zetacored/config/genesis.json cat $HOME/.zetacored/config/genesis.json | jq '.app_state["observer"]["params"]["admin_policy"][0]["address"]="zeta1srsq755t654agc0grpxj4y3w0znktrpr9tcdgk"' > $HOME/.zetacored/config/tmp_genesis.json && mv $HOME/.zetacored/config/tmp_genesis.json $HOME/.zetacored/config/genesis.json cat $HOME/.zetacored/config/genesis.json | jq '.app_state["observer"]["params"]["admin_policy"][1]["address"]="zeta1srsq755t654agc0grpxj4y3w0znktrpr9tcdgk"' > $HOME/.zetacored/config/tmp_genesis.json && mv $HOME/.zetacored/config/tmp_genesis.json $HOME/.zetacored/config/genesis.json diff --git a/docs/openapi/openapi.swagger.yaml b/docs/openapi/openapi.swagger.yaml index 8dc17721a4..3ee890602d 100644 --- a/docs/openapi/openapi.swagger.yaml +++ b/docs/openapi/openapi.swagger.yaml @@ -53483,13 +53483,13 @@ definitions: authorityPolicies: type: object properties: - policy_addresses: + items: type: array items: type: object - $ref: '#/definitions/authorityPolicyAddress' + $ref: '#/definitions/authorityPolicy' title: Policy contains info about authority policies - authorityPolicyAddress: + authorityPolicy: type: object properties: policy_type: diff --git a/proto/authority/policies.proto b/proto/authority/policies.proto index 3dc9b65343..85916c165a 100644 --- a/proto/authority/policies.proto +++ b/proto/authority/policies.proto @@ -12,12 +12,12 @@ enum PolicyType { groupAdmin = 1; } -message PolicyAddress { +message Policy { PolicyType policy_type = 1; string address = 2; } // Policy contains info about authority policies message Policies { - repeated PolicyAddress policy_addresses = 1; + repeated Policy items = 1; } diff --git a/testutil/sample/authority.go b/testutil/sample/authority.go index 56325ccb02..1e65b735e7 100644 --- a/testutil/sample/authority.go +++ b/testutil/sample/authority.go @@ -4,7 +4,7 @@ import authoritytypes "github.com/zeta-chain/zetacore/x/authority/types" func Policies() authoritytypes.Policies { return authoritytypes.Policies{ - PolicyAddresses: []*authoritytypes.PolicyAddress{ + Items: []*authoritytypes.Policy{ { Address: AccAddress(), PolicyType: authoritytypes.PolicyType_groupEmergency, diff --git a/typescript/authority/policies_pb.d.ts b/typescript/authority/policies_pb.d.ts index 9fa25a7866..b6835f08a5 100644 --- a/typescript/authority/policies_pb.d.ts +++ b/typescript/authority/policies_pb.d.ts @@ -24,9 +24,9 @@ export declare enum PolicyType { } /** - * @generated from message zetachain.zetacore.authority.PolicyAddress + * @generated from message zetachain.zetacore.authority.Policy */ -export declare class PolicyAddress extends Message { +export declare class Policy extends Message { /** * @generated from field: zetachain.zetacore.authority.PolicyType policy_type = 1; */ @@ -37,19 +37,19 @@ export declare class PolicyAddress extends Message { */ address: string; - constructor(data?: PartialMessage); + constructor(data?: PartialMessage); static readonly runtime: typeof proto3; - static readonly typeName = "zetachain.zetacore.authority.PolicyAddress"; + static readonly typeName = "zetachain.zetacore.authority.Policy"; static readonly fields: FieldList; - static fromBinary(bytes: Uint8Array, options?: Partial): PolicyAddress; + static fromBinary(bytes: Uint8Array, options?: Partial): Policy; - static fromJson(jsonValue: JsonValue, options?: Partial): PolicyAddress; + static fromJson(jsonValue: JsonValue, options?: Partial): Policy; - static fromJsonString(jsonString: string, options?: Partial): PolicyAddress; + static fromJsonString(jsonString: string, options?: Partial): Policy; - static equals(a: PolicyAddress | PlainMessage | undefined, b: PolicyAddress | PlainMessage | undefined): boolean; + static equals(a: Policy | PlainMessage | undefined, b: Policy | PlainMessage | undefined): boolean; } /** @@ -59,9 +59,9 @@ export declare class PolicyAddress extends Message { */ export declare class Policies extends Message { /** - * @generated from field: repeated zetachain.zetacore.authority.PolicyAddress policy_addresses = 1; + * @generated from field: repeated zetachain.zetacore.authority.Policy items = 1; */ - policyAddresses: PolicyAddress[]; + items: Policy[]; constructor(data?: PartialMessage); diff --git a/x/authority/keeper/policies.go b/x/authority/keeper/policies.go index 1a00a08190..93f0086e7a 100644 --- a/x/authority/keeper/policies.go +++ b/x/authority/keeper/policies.go @@ -30,7 +30,7 @@ func (k Keeper) IsAuthorized(ctx sdk.Context, address string, policyType types.P if !found { return false } - for _, policy := range policies.PolicyAddresses { + for _, policy := range policies.Items { if policy.Address == address && policy.PolicyType == policyType { return true } diff --git a/x/authority/keeper/policies_test.go b/x/authority/keeper/policies_test.go index d18c2f2da4..527278435c 100644 --- a/x/authority/keeper/policies_test.go +++ b/x/authority/keeper/policies_test.go @@ -44,7 +44,7 @@ func TestKeeper_IsAuthorized(t *testing.T) { require.Equal(t, policies, got) // Check policy is authorized - for _, policy := range policies.PolicyAddresses { + for _, policy := range policies.Items { require.True(t, k.IsAuthorized(ctx, policy.Address, policy.PolicyType)) } diff --git a/x/authority/module.go b/x/authority/module.go index a64f0ddbcb..6c7d535ec5 100644 --- a/x/authority/module.go +++ b/x/authority/module.go @@ -75,13 +75,7 @@ func (AppModuleBasic) RegisterRESTRoutes(_ client.Context, _ *mux.Router) { // RegisterGRPCGatewayRoutes registers the gRPC Gateway routes for the module. func (AppModuleBasic) RegisterGRPCGatewayRoutes(clientCtx client.Context, mux *runtime.ServeMux) { - err := types.RegisterClientCtx(clientCtx) - if err != nil { - fmt.Println("RegisterQueryHandlerClient err: %w", err) - } - - err = types.RegisterQueryHandlerClient(context.Background(), mux, types.NewQueryClient(clientCtx)) - if err != nil { + if err := types.RegisterQueryHandlerClient(context.Background(), mux, types.NewQueryClient(clientCtx)); err != nil { fmt.Println("RegisterQueryHandlerClient err: %w", err) } } diff --git a/x/authority/types/client_ctx.go b/x/authority/types/client_ctx.go deleted file mode 100644 index b4622e1a61..0000000000 --- a/x/authority/types/client_ctx.go +++ /dev/null @@ -1,14 +0,0 @@ -package types - -import ( - "github.com/cosmos/cosmos-sdk/client" -) - -var ( - ClientCtx client.Context -) - -func RegisterClientCtx(clientCtx client.Context) error { - ClientCtx = clientCtx - return nil -} diff --git a/x/authority/types/genesis_test.go b/x/authority/types/genesis_test.go index 690e343791..ec53fc1fad 100644 --- a/x/authority/types/genesis_test.go +++ b/x/authority/types/genesis_test.go @@ -32,7 +32,7 @@ func TestGenesisState_Validate(t *testing.T) { name: "invalid if policies is invalid", gs: &types.GenesisState{ Policies: types.Policies{ - PolicyAddresses: []*types.PolicyAddress{ + Items: []*types.Policy{ { Address: "invalid", PolicyType: types.PolicyType_groupEmergency, diff --git a/x/authority/types/message_update_policies_test.go b/x/authority/types/message_update_policies_test.go index 82fa23fab7..011d1e5d2c 100644 --- a/x/authority/types/message_update_policies_test.go +++ b/x/authority/types/message_update_policies_test.go @@ -29,7 +29,7 @@ func TestMsgUpdatePolicies_ValidateBasic(t *testing.T) { { name: "invalid policies", msg: types.NewMsgUpdatePolicies(sample.AccAddress(), types.Policies{ - PolicyAddresses: []*types.PolicyAddress{ + Items: []*types.Policy{ { Address: "invalid", PolicyType: types.PolicyType_groupEmergency, diff --git a/x/authority/types/policies.go b/x/authority/types/policies.go index 28698fbf02..5526ea98f1 100644 --- a/x/authority/types/policies.go +++ b/x/authority/types/policies.go @@ -14,7 +14,7 @@ const ( // DefaultPolicies returns the default value for policies func DefaultPolicies() Policies { return Policies{ - PolicyAddresses: []*PolicyAddress{ + Items: []*Policy{ { Address: DefaultPolicyAddress, PolicyType: PolicyType_groupEmergency, @@ -32,7 +32,7 @@ func (p Policies) Validate() error { policyTypeMap := make(map[PolicyType]bool) // for each policy, check address, policy type, and ensure no duplicate policy types - for _, policy := range p.PolicyAddresses { + for _, policy := range p.Items { _, err := sdk.AccAddressFromBech32(policy.Address) if err != nil { return fmt.Errorf("invalid address: %s", err) diff --git a/x/authority/types/policies.pb.go b/x/authority/types/policies.pb.go index a2a31b3827..bf14e65f12 100644 --- a/x/authority/types/policies.pb.go +++ b/x/authority/types/policies.pb.go @@ -50,23 +50,23 @@ func (PolicyType) EnumDescriptor() ([]byte, []int) { return fileDescriptor_cf39aa57ca0776f1, []int{0} } -type PolicyAddress struct { +type Policy struct { PolicyType PolicyType `protobuf:"varint,1,opt,name=policy_type,json=policyType,proto3,enum=zetachain.zetacore.authority.PolicyType" json:"policy_type,omitempty"` Address string `protobuf:"bytes,2,opt,name=address,proto3" json:"address,omitempty"` } -func (m *PolicyAddress) Reset() { *m = PolicyAddress{} } -func (m *PolicyAddress) String() string { return proto.CompactTextString(m) } -func (*PolicyAddress) ProtoMessage() {} -func (*PolicyAddress) Descriptor() ([]byte, []int) { +func (m *Policy) Reset() { *m = Policy{} } +func (m *Policy) String() string { return proto.CompactTextString(m) } +func (*Policy) ProtoMessage() {} +func (*Policy) Descriptor() ([]byte, []int) { return fileDescriptor_cf39aa57ca0776f1, []int{0} } -func (m *PolicyAddress) XXX_Unmarshal(b []byte) error { +func (m *Policy) XXX_Unmarshal(b []byte) error { return m.Unmarshal(b) } -func (m *PolicyAddress) XXX_Marshal(b []byte, deterministic bool) ([]byte, error) { +func (m *Policy) XXX_Marshal(b []byte, deterministic bool) ([]byte, error) { if deterministic { - return xxx_messageInfo_PolicyAddress.Marshal(b, m, deterministic) + return xxx_messageInfo_Policy.Marshal(b, m, deterministic) } else { b = b[:cap(b)] n, err := m.MarshalToSizedBuffer(b) @@ -76,26 +76,26 @@ func (m *PolicyAddress) XXX_Marshal(b []byte, deterministic bool) ([]byte, error return b[:n], nil } } -func (m *PolicyAddress) XXX_Merge(src proto.Message) { - xxx_messageInfo_PolicyAddress.Merge(m, src) +func (m *Policy) XXX_Merge(src proto.Message) { + xxx_messageInfo_Policy.Merge(m, src) } -func (m *PolicyAddress) XXX_Size() int { +func (m *Policy) XXX_Size() int { return m.Size() } -func (m *PolicyAddress) XXX_DiscardUnknown() { - xxx_messageInfo_PolicyAddress.DiscardUnknown(m) +func (m *Policy) XXX_DiscardUnknown() { + xxx_messageInfo_Policy.DiscardUnknown(m) } -var xxx_messageInfo_PolicyAddress proto.InternalMessageInfo +var xxx_messageInfo_Policy proto.InternalMessageInfo -func (m *PolicyAddress) GetPolicyType() PolicyType { +func (m *Policy) GetPolicyType() PolicyType { if m != nil { return m.PolicyType } return PolicyType_groupEmergency } -func (m *PolicyAddress) GetAddress() string { +func (m *Policy) GetAddress() string { if m != nil { return m.Address } @@ -104,7 +104,7 @@ func (m *PolicyAddress) GetAddress() string { // Policy contains info about authority policies type Policies struct { - PolicyAddresses []*PolicyAddress `protobuf:"bytes,1,rep,name=policy_addresses,json=policyAddresses,proto3" json:"policy_addresses,omitempty"` + Items []*Policy `protobuf:"bytes,1,rep,name=items,proto3" json:"items,omitempty"` } func (m *Policies) Reset() { *m = Policies{} } @@ -140,45 +140,44 @@ func (m *Policies) XXX_DiscardUnknown() { var xxx_messageInfo_Policies proto.InternalMessageInfo -func (m *Policies) GetPolicyAddresses() []*PolicyAddress { +func (m *Policies) GetItems() []*Policy { if m != nil { - return m.PolicyAddresses + return m.Items } return nil } func init() { proto.RegisterEnum("zetachain.zetacore.authority.PolicyType", PolicyType_name, PolicyType_value) - proto.RegisterType((*PolicyAddress)(nil), "zetachain.zetacore.authority.PolicyAddress") + proto.RegisterType((*Policy)(nil), "zetachain.zetacore.authority.Policy") proto.RegisterType((*Policies)(nil), "zetachain.zetacore.authority.Policies") } func init() { proto.RegisterFile("authority/policies.proto", fileDescriptor_cf39aa57ca0776f1) } var fileDescriptor_cf39aa57ca0776f1 = []byte{ - // 295 bytes of a gzipped FileDescriptorProto + // 284 bytes of a gzipped FileDescriptorProto 0x1f, 0x8b, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0xff, 0xe2, 0x92, 0x48, 0x2c, 0x2d, 0xc9, 0xc8, 0x2f, 0xca, 0x2c, 0xa9, 0xd4, 0x2f, 0xc8, 0xcf, 0xc9, 0x4c, 0xce, 0x4c, 0x2d, 0xd6, 0x2b, 0x28, 0xca, 0x2f, 0xc9, 0x17, 0x92, 0xa9, 0x4a, 0x2d, 0x49, 0x4c, 0xce, 0x48, 0xcc, 0xcc, 0xd3, 0x03, 0xb3, 0xf2, 0x8b, 0x52, 0xf5, 0xe0, 0x8a, 0xa5, 0x44, 0xd2, 0xf3, 0xd3, 0xf3, 0xc1, 0x0a, - 0xf5, 0x41, 0x2c, 0x88, 0x1e, 0xa5, 0x12, 0x2e, 0xde, 0x00, 0x90, 0x29, 0x95, 0x8e, 0x29, 0x29, - 0x45, 0xa9, 0xc5, 0xc5, 0x42, 0x9e, 0x5c, 0xdc, 0x60, 0x63, 0x2b, 0xe3, 0x4b, 0x2a, 0x0b, 0x52, - 0x25, 0x18, 0x15, 0x18, 0x35, 0xf8, 0x8c, 0x34, 0xf4, 0xf0, 0x19, 0xad, 0x07, 0x31, 0x21, 0xa4, - 0xb2, 0x20, 0x35, 0x88, 0xab, 0x00, 0xce, 0x16, 0x92, 0xe0, 0x62, 0x4f, 0x84, 0x98, 0x2a, 0xc1, - 0xa4, 0xc0, 0xa8, 0xc1, 0x19, 0x04, 0xe3, 0x2a, 0x25, 0x71, 0x71, 0x04, 0x40, 0xdd, 0x2e, 0x14, - 0xc6, 0x25, 0x00, 0xb5, 0x10, 0x2a, 0x9b, 0x5a, 0x2c, 0xc1, 0xa8, 0xc0, 0xac, 0xc1, 0x6d, 0xa4, - 0x4d, 0x8c, 0xad, 0x50, 0x77, 0x07, 0xf1, 0x17, 0x20, 0x73, 0x53, 0x8b, 0xb5, 0xcc, 0xb8, 0xb8, - 0x10, 0xee, 0x12, 0x12, 0xe2, 0xe2, 0x4b, 0x2f, 0xca, 0x2f, 0x2d, 0x70, 0xcd, 0x4d, 0x2d, 0x4a, - 0x4f, 0xcd, 0x4b, 0xae, 0x14, 0x60, 0x10, 0xe2, 0xe3, 0xe2, 0x02, 0x8b, 0x39, 0xa6, 0xe4, 0x66, - 0xe6, 0x09, 0x30, 0x4a, 0xb1, 0xac, 0x58, 0x22, 0xc7, 0xe8, 0xe4, 0x75, 0xe2, 0x91, 0x1c, 0xe3, - 0x85, 0x47, 0x72, 0x8c, 0x0f, 0x1e, 0xc9, 0x31, 0x4e, 0x78, 0x2c, 0xc7, 0x70, 0xe1, 0xb1, 0x1c, - 0xc3, 0x8d, 0xc7, 0x72, 0x0c, 0x51, 0x06, 0xe9, 0x99, 0x25, 0x19, 0xa5, 0x49, 0x7a, 0xc9, 0xf9, - 0xb9, 0xfa, 0x20, 0xf7, 0xe8, 0x82, 0x9d, 0xa6, 0x0f, 0x73, 0x9a, 0x7e, 0x85, 0x3e, 0x22, 0x6a, - 0x40, 0x81, 0x57, 0x9c, 0xc4, 0x06, 0x0e, 0x64, 0x63, 0x40, 0x00, 0x00, 0x00, 0xff, 0xff, 0x2a, - 0xef, 0xf4, 0x31, 0xb4, 0x01, 0x00, 0x00, -} - -func (m *PolicyAddress) Marshal() (dAtA []byte, err error) { + 0xf5, 0x41, 0x2c, 0x88, 0x1e, 0xa5, 0x5c, 0x2e, 0xb6, 0x00, 0x90, 0x29, 0x95, 0x42, 0x9e, 0x5c, + 0xdc, 0x60, 0xf3, 0x2a, 0xe3, 0x4b, 0x2a, 0x0b, 0x52, 0x25, 0x18, 0x15, 0x18, 0x35, 0xf8, 0x8c, + 0x34, 0xf4, 0xf0, 0x99, 0xa9, 0x07, 0xd1, 0x1a, 0x52, 0x59, 0x90, 0x1a, 0xc4, 0x55, 0x00, 0x67, + 0x0b, 0x49, 0x70, 0xb1, 0x27, 0xa6, 0xa4, 0x14, 0xa5, 0x16, 0x17, 0x4b, 0x30, 0x29, 0x30, 0x6a, + 0x70, 0x06, 0xc1, 0xb8, 0x4a, 0x6e, 0x5c, 0x1c, 0x01, 0x50, 0x47, 0x0b, 0x59, 0x71, 0xb1, 0x66, + 0x96, 0xa4, 0xe6, 0x16, 0x4b, 0x30, 0x2a, 0x30, 0x6b, 0x70, 0x1b, 0xa9, 0x10, 0x63, 0x55, 0x10, + 0x44, 0x8b, 0x96, 0x19, 0x17, 0x17, 0xc2, 0x6e, 0x21, 0x21, 0x2e, 0xbe, 0xf4, 0xa2, 0xfc, 0xd2, + 0x02, 0xd7, 0xdc, 0xd4, 0xa2, 0xf4, 0xd4, 0xbc, 0xe4, 0x4a, 0x01, 0x06, 0x21, 0x3e, 0x2e, 0x2e, + 0xb0, 0x98, 0x63, 0x4a, 0x6e, 0x66, 0x9e, 0x00, 0xa3, 0x14, 0xcb, 0x8a, 0x25, 0x72, 0x8c, 0x4e, + 0x5e, 0x27, 0x1e, 0xc9, 0x31, 0x5e, 0x78, 0x24, 0xc7, 0xf8, 0xe0, 0x91, 0x1c, 0xe3, 0x84, 0xc7, + 0x72, 0x0c, 0x17, 0x1e, 0xcb, 0x31, 0xdc, 0x78, 0x2c, 0xc7, 0x10, 0x65, 0x90, 0x9e, 0x59, 0x92, + 0x51, 0x9a, 0xa4, 0x97, 0x9c, 0x9f, 0xab, 0x0f, 0xb2, 0x5e, 0x17, 0xec, 0x12, 0x7d, 0x98, 0x4b, + 0xf4, 0x2b, 0xf4, 0x11, 0xe1, 0x0e, 0x0a, 0xa0, 0xe2, 0x24, 0x36, 0x70, 0x08, 0x1a, 0x03, 0x02, + 0x00, 0x00, 0xff, 0xff, 0x08, 0x31, 0x60, 0x2c, 0x91, 0x01, 0x00, 0x00, +} + +func (m *Policy) Marshal() (dAtA []byte, err error) { size := m.Size() dAtA = make([]byte, size) n, err := m.MarshalToSizedBuffer(dAtA[:size]) @@ -188,12 +187,12 @@ func (m *PolicyAddress) Marshal() (dAtA []byte, err error) { return dAtA[:n], nil } -func (m *PolicyAddress) MarshalTo(dAtA []byte) (int, error) { +func (m *Policy) MarshalTo(dAtA []byte) (int, error) { size := m.Size() return m.MarshalToSizedBuffer(dAtA[:size]) } -func (m *PolicyAddress) MarshalToSizedBuffer(dAtA []byte) (int, error) { +func (m *Policy) MarshalToSizedBuffer(dAtA []byte) (int, error) { i := len(dAtA) _ = i var l int @@ -233,10 +232,10 @@ func (m *Policies) MarshalToSizedBuffer(dAtA []byte) (int, error) { _ = i var l int _ = l - if len(m.PolicyAddresses) > 0 { - for iNdEx := len(m.PolicyAddresses) - 1; iNdEx >= 0; iNdEx-- { + if len(m.Items) > 0 { + for iNdEx := len(m.Items) - 1; iNdEx >= 0; iNdEx-- { { - size, err := m.PolicyAddresses[iNdEx].MarshalToSizedBuffer(dAtA[:i]) + size, err := m.Items[iNdEx].MarshalToSizedBuffer(dAtA[:i]) if err != nil { return 0, err } @@ -261,7 +260,7 @@ func encodeVarintPolicies(dAtA []byte, offset int, v uint64) int { dAtA[offset] = uint8(v) return base } -func (m *PolicyAddress) Size() (n int) { +func (m *Policy) Size() (n int) { if m == nil { return 0 } @@ -283,8 +282,8 @@ func (m *Policies) Size() (n int) { } var l int _ = l - if len(m.PolicyAddresses) > 0 { - for _, e := range m.PolicyAddresses { + if len(m.Items) > 0 { + for _, e := range m.Items { l = e.Size() n += 1 + l + sovPolicies(uint64(l)) } @@ -298,7 +297,7 @@ func sovPolicies(x uint64) (n int) { func sozPolicies(x uint64) (n int) { return sovPolicies(uint64((x << 1) ^ uint64((int64(x) >> 63)))) } -func (m *PolicyAddress) Unmarshal(dAtA []byte) error { +func (m *Policy) Unmarshal(dAtA []byte) error { l := len(dAtA) iNdEx := 0 for iNdEx < l { @@ -321,10 +320,10 @@ func (m *PolicyAddress) Unmarshal(dAtA []byte) error { fieldNum := int32(wire >> 3) wireType := int(wire & 0x7) if wireType == 4 { - return fmt.Errorf("proto: PolicyAddress: wiretype end group for non-group") + return fmt.Errorf("proto: Policy: wiretype end group for non-group") } if fieldNum <= 0 { - return fmt.Errorf("proto: PolicyAddress: illegal tag %d (wire type %d)", fieldNum, wire) + return fmt.Errorf("proto: Policy: illegal tag %d (wire type %d)", fieldNum, wire) } switch fieldNum { case 1: @@ -430,7 +429,7 @@ func (m *Policies) Unmarshal(dAtA []byte) error { switch fieldNum { case 1: if wireType != 2 { - return fmt.Errorf("proto: wrong wireType = %d for field PolicyAddresses", wireType) + return fmt.Errorf("proto: wrong wireType = %d for field Items", wireType) } var msglen int for shift := uint(0); ; shift += 7 { @@ -457,8 +456,8 @@ func (m *Policies) Unmarshal(dAtA []byte) error { if postIndex > l { return io.ErrUnexpectedEOF } - m.PolicyAddresses = append(m.PolicyAddresses, &PolicyAddress{}) - if err := m.PolicyAddresses[len(m.PolicyAddresses)-1].Unmarshal(dAtA[iNdEx:postIndex]); err != nil { + m.Items = append(m.Items, &Policy{}) + if err := m.Items[len(m.Items)-1].Unmarshal(dAtA[iNdEx:postIndex]); err != nil { return err } iNdEx = postIndex diff --git a/x/authority/types/policies_test.go b/x/authority/types/policies_test.go index d8113bf80b..8d609d377c 100644 --- a/x/authority/types/policies_test.go +++ b/x/authority/types/policies_test.go @@ -44,7 +44,7 @@ func TestPolicies_Validate(t *testing.T) { { name: "valid if a policy type is not existing", policies: types.Policies{ - PolicyAddresses: []*types.PolicyAddress{ + Items: []*types.Policy{ { Address: sample.AccAddress(), PolicyType: types.PolicyType_groupEmergency, @@ -56,7 +56,7 @@ func TestPolicies_Validate(t *testing.T) { { name: "invalid if address is invalid", policies: types.Policies{ - PolicyAddresses: []*types.PolicyAddress{ + Items: []*types.Policy{ { Address: "invalid", PolicyType: types.PolicyType_groupEmergency, @@ -68,7 +68,7 @@ func TestPolicies_Validate(t *testing.T) { { name: "invalid if policy type is invalid", policies: types.Policies{ - PolicyAddresses: []*types.PolicyAddress{ + Items: []*types.Policy{ { Address: sample.AccAddress(), PolicyType: types.PolicyType(1000), @@ -80,7 +80,7 @@ func TestPolicies_Validate(t *testing.T) { { name: "invalid if duplicated policy type", policies: types.Policies{ - PolicyAddresses: []*types.PolicyAddress{ + Items: []*types.Policy{ { Address: sample.AccAddress(), PolicyType: types.PolicyType_groupEmergency, diff --git a/x/observer/keeper/msg_server_update_crosschain_flags.go b/x/observer/keeper/msg_server_update_crosschain_flags.go index 94cf507043..42be93a3a8 100644 --- a/x/observer/keeper/msg_server_update_crosschain_flags.go +++ b/x/observer/keeper/msg_server_update_crosschain_flags.go @@ -15,7 +15,7 @@ func (k msgServer) UpdateCrosschainFlags(goCtx context.Context, msg *types.MsgUp ctx := sdk.UnwrapSDKContext(goCtx) // check permission - if !k.GetAuthorityKeeper().IsAuthorized(ctx, msg.Creator, msg.GetRequiredGroup()) { + if !k.GetAuthorityKeeper().IsAuthorized(ctx, msg.Creator, msg.GetRequiredPolicyType()) { return &types.MsgUpdateCrosschainFlagsResponse{}, types.ErrNotAuthorizedPolicy } diff --git a/x/observer/migrations/v7/migrate.go b/x/observer/migrations/v7/migrate.go index 71490adfab..2d69977f55 100644 --- a/x/observer/migrations/v7/migrate.go +++ b/x/observer/migrations/v7/migrate.go @@ -34,7 +34,7 @@ func MigratePolicies(ctx sdk.Context, observerKeeper observerKeeper) error { policyType = authoritytypes.PolicyType_groupEmergency } - policies.PolicyAddresses = append(policies.PolicyAddresses, &authoritytypes.PolicyAddress{ + policies.Items = append(policies.Items, &authoritytypes.Policy{ Address: adminPolicy.Address, PolicyType: policyType, }) diff --git a/x/observer/migrations/v7/migrate_test.go b/x/observer/migrations/v7/migrate_test.go index d0a068ba9c..39b56bcf22 100644 --- a/x/observer/migrations/v7/migrate_test.go +++ b/x/observer/migrations/v7/migrate_test.go @@ -38,12 +38,12 @@ func TestMigratePolicies(t *testing.T) { require.NoError(t, err) policies, found := zk.AuthorityKeeper.GetPolicies(ctx) require.True(t, found) - policyAddresses := policies.PolicyAddresses - require.Len(t, policyAddresses, 2) - require.EqualValues(t, addr1, policyAddresses[0].Address) - require.EqualValues(t, addr2, policyAddresses[1].Address) - require.EqualValues(t, authoritytypes.PolicyType_groupEmergency, policyAddresses[0].PolicyType) - require.EqualValues(t, authoritytypes.PolicyType_groupAdmin, policyAddresses[1].PolicyType) + items := policies.Items + require.Len(t, items, 2) + require.EqualValues(t, addr1, items[0].Address) + require.EqualValues(t, addr2, items[1].Address) + require.EqualValues(t, authoritytypes.PolicyType_groupEmergency, items[0].PolicyType) + require.EqualValues(t, authoritytypes.PolicyType_groupAdmin, items[1].PolicyType) }) t.Run("Can migrate with just emergency policy", func(t *testing.T) { @@ -67,10 +67,10 @@ func TestMigratePolicies(t *testing.T) { require.NoError(t, err) policies, found := zk.AuthorityKeeper.GetPolicies(ctx) require.True(t, found) - policyAddresses := policies.PolicyAddresses - require.Len(t, policyAddresses, 1) - require.EqualValues(t, addr, policyAddresses[0].Address) - require.EqualValues(t, authoritytypes.PolicyType_groupEmergency, policyAddresses[0].PolicyType) + items := policies.Items + require.Len(t, items, 1) + require.EqualValues(t, addr, items[0].Address) + require.EqualValues(t, authoritytypes.PolicyType_groupEmergency, items[0].PolicyType) }) t.Run("Can migrate with just admin policy", func(t *testing.T) { @@ -94,10 +94,10 @@ func TestMigratePolicies(t *testing.T) { require.NoError(t, err) policies, found := zk.AuthorityKeeper.GetPolicies(ctx) require.True(t, found) - policyAddresses := policies.PolicyAddresses - require.Len(t, policyAddresses, 1) - require.EqualValues(t, addr, policyAddresses[0].Address) - require.EqualValues(t, authoritytypes.PolicyType_groupAdmin, policyAddresses[0].PolicyType) + items := policies.Items + require.Len(t, items, 1) + require.EqualValues(t, addr, items[0].Address) + require.EqualValues(t, authoritytypes.PolicyType_groupAdmin, items[0].PolicyType) }) t.Run("Can migrate with no policies", func(t *testing.T) { @@ -112,8 +112,8 @@ func TestMigratePolicies(t *testing.T) { require.NoError(t, err) policies, found := zk.AuthorityKeeper.GetPolicies(ctx) require.True(t, found) - policyAddresses := policies.PolicyAddresses - require.Len(t, policyAddresses, 0) + items := policies.Items + require.Len(t, items, 0) }) t.Run("Fail to migrate if invalid policy", func(t *testing.T) { diff --git a/x/observer/types/message_crosschain_flags.go b/x/observer/types/message_crosschain_flags.go index ad2dbdfa70..05ee4d331e 100644 --- a/x/observer/types/message_crosschain_flags.go +++ b/x/observer/types/message_crosschain_flags.go @@ -70,13 +70,13 @@ func (gpf GasPriceIncreaseFlags) Validate() error { return nil } -// GetRequiredGroup returns the required group policy for the message to execute the message -// Group emergency should only be able to stop or disable functiunalities in case of emergency +// GetRequiredPolicyType returns the required policy type for the message to execute the message +// Group emergency should only be able to stop or disable functionalities in case of emergency // this concerns disabling inbound and outbound txs or block header verification // every other action requires group admin // TODO: add separate message for each group // https://github.com/zeta-chain/node/issues/1562 -func (msg *MsgUpdateCrosschainFlags) GetRequiredGroup() authoritytypes.PolicyType { +func (msg *MsgUpdateCrosschainFlags) GetRequiredPolicyType() authoritytypes.PolicyType { if msg.IsInboundEnabled || msg.IsOutboundEnabled { return authoritytypes.PolicyType_groupAdmin } diff --git a/x/observer/types/message_crosschain_flags_test.go b/x/observer/types/message_crosschain_flags_test.go index 80778a8610..1ccd1d7040 100644 --- a/x/observer/types/message_crosschain_flags_test.go +++ b/x/observer/types/message_crosschain_flags_test.go @@ -118,7 +118,7 @@ func TestGasPriceIncreaseFlags_Validate(t *testing.T) { } } -func TestMsgUpdateCrosschainFlags_GetRequiredGroup(t *testing.T) { +func TestMsgUpdateCrosschainFlags_GetRequiredPolicyType(t *testing.T) { tests := []struct { name string msg types.MsgUpdateCrosschainFlags @@ -228,7 +228,7 @@ func TestMsgUpdateCrosschainFlags_GetRequiredGroup(t *testing.T) { for _, tt := range tests { t.Run(tt.name, func(t *testing.T) { - require.EqualValues(t, tt.want, tt.msg.GetRequiredGroup()) + require.EqualValues(t, tt.want, tt.msg.GetRequiredPolicyType()) }) } }