From d93374631fa9373f57320f8d4adb5031b1e0441f Mon Sep 17 00:00:00 2001 From: Yusuf Date: Wed, 8 Apr 2026 17:52:55 +0300 Subject: [PATCH 01/62] feat: add keyregistry --- .../keyregistry/v1/address_pair.proto | 11 + .../pulsarchain/keyregistry/v1/genesis.proto | 7 +- .../{key_pair.proto => public_key_pair.proto} | 2 +- proto/pulsarchain/keyregistry/v1/query.proto | 66 +- proto/pulsarchain/keyregistry/v1/tx.proto | 5 +- x/keyregistry/keeper/genesis.go | 131 +- x/keyregistry/keeper/genesis_test.go | 10 +- x/keyregistry/keeper/keeper.go | 69 +- x/keyregistry/keeper/keeper_test.go | 12 +- .../keeper/msg_server_register_keys.go | 89 +- .../keeper/msg_server_register_user_keys.go | 63 + .../msg_server_register_validator_keys.go | 64 + x/keyregistry/keeper/query.go | 4 +- .../keeper/query_get_user_cosmos_address.go | 39 + ..._key.go => query_get_user_mina_address.go} | 12 +- ... => query_get_validator_cosmos_pub_key.go} | 13 +- .../query_get_validator_mina_pub_key.go | 39 + ...rs_test.go => query_user_keypairs_test.go} | 52 +- .../keeper/query_validator_keypairs_test.go | 135 ++ ...eys_test.go => user_register_keys_test.go} | 128 +- .../keeper/validator_register_keys_test.go | 189 +++ x/keyregistry/module/autocli.go | 32 +- x/keyregistry/types/address_pair.pb.go | 374 +++++ x/keyregistry/types/address_pairs.go | 35 + x/keyregistry/types/errors.go | 12 +- x/keyregistry/types/genesis.go | 16 +- x/keyregistry/types/genesis.pb.go | 117 +- x/keyregistry/types/keypairs.go | 30 - x/keyregistry/types/keys.go | 7 +- .../{key_pair.pb.go => public_key_pair.pb.go} | 139 +- x/keyregistry/types/public_key_pairs.go | 34 + x/keyregistry/types/query.pb.go | 1201 ++++++++++++++--- x/keyregistry/types/query.pb.gw.go | 290 +++- x/keyregistry/types/tx.pb.go | 156 ++- 34 files changed, 2894 insertions(+), 689 deletions(-) create mode 100644 proto/pulsarchain/keyregistry/v1/address_pair.proto rename proto/pulsarchain/keyregistry/v1/{key_pair.proto => public_key_pair.proto} (90%) create mode 100644 x/keyregistry/keeper/msg_server_register_user_keys.go create mode 100644 x/keyregistry/keeper/msg_server_register_validator_keys.go create mode 100644 x/keyregistry/keeper/query_get_user_cosmos_address.go rename x/keyregistry/keeper/{query_get_mina_pub_key.go => query_get_user_mina_address.go} (61%) rename x/keyregistry/keeper/{query_get_cosmos_pub_key.go => query_get_validator_cosmos_pub_key.go} (58%) create mode 100644 x/keyregistry/keeper/query_get_validator_mina_pub_key.go rename x/keyregistry/keeper/{query_keypairs_test.go => query_user_keypairs_test.go} (64%) create mode 100644 x/keyregistry/keeper/query_validator_keypairs_test.go rename x/keyregistry/keeper/{register_keys_test.go => user_register_keys_test.go} (50%) create mode 100644 x/keyregistry/keeper/validator_register_keys_test.go create mode 100644 x/keyregistry/types/address_pair.pb.go create mode 100644 x/keyregistry/types/address_pairs.go delete mode 100644 x/keyregistry/types/keypairs.go rename x/keyregistry/types/{key_pair.pb.go => public_key_pair.pb.go} (55%) create mode 100644 x/keyregistry/types/public_key_pairs.go diff --git a/proto/pulsarchain/keyregistry/v1/address_pair.proto b/proto/pulsarchain/keyregistry/v1/address_pair.proto new file mode 100644 index 00000000..6d13c957 --- /dev/null +++ b/proto/pulsarchain/keyregistry/v1/address_pair.proto @@ -0,0 +1,11 @@ +syntax = "proto3"; +package pulsarchain.keyregistry.v1; + +option go_package = "github.com/node101-io/pulsar-chain/x/keyregistry/types"; + +// KeyPair defines the KeyPair message. + +message AddressPair { + bytes mina_addr = 1; + bytes cosmos_addr = 2; +} diff --git a/proto/pulsarchain/keyregistry/v1/genesis.proto b/proto/pulsarchain/keyregistry/v1/genesis.proto index 0f0a5554..25d1bc37 100644 --- a/proto/pulsarchain/keyregistry/v1/genesis.proto +++ b/proto/pulsarchain/keyregistry/v1/genesis.proto @@ -3,12 +3,12 @@ package pulsarchain.keyregistry.v1; import "amino/amino.proto"; import "gogoproto/gogo.proto"; +import "pulsarchain/keyregistry/v1/address_pair.proto"; import "pulsarchain/keyregistry/v1/params.proto"; -import "pulsarchain/keyregistry/v1/key_pair.proto"; +import "pulsarchain/keyregistry/v1/public_key_pair.proto"; option go_package = "github.com/node101-io/pulsar-chain/x/keyregistry/types"; - // GenesisState defines the keyregistry module's genesis state. message GenesisState { // params defines all the parameters of the module. @@ -16,5 +16,6 @@ message GenesisState { (gogoproto.nullable) = false, (amino.dont_omitempty) = true ]; - repeated KeyPair key_pairs = 2; + repeated AddressPair user_key_pairs = 2; + repeated PublicKeyPair validator_key_pairs = 3; } diff --git a/proto/pulsarchain/keyregistry/v1/key_pair.proto b/proto/pulsarchain/keyregistry/v1/public_key_pair.proto similarity index 90% rename from proto/pulsarchain/keyregistry/v1/key_pair.proto rename to proto/pulsarchain/keyregistry/v1/public_key_pair.proto index ed7d22e6..b6e3810f 100644 --- a/proto/pulsarchain/keyregistry/v1/key_pair.proto +++ b/proto/pulsarchain/keyregistry/v1/public_key_pair.proto @@ -4,7 +4,7 @@ package pulsarchain.keyregistry.v1; option go_package = "github.com/node101-io/pulsar-chain/x/keyregistry/types"; // KeyPair defines the KeyPair message. -message KeyPair { +message PublicKeyPair { bytes mina_key = 1; bytes cosmos_key = 2; } diff --git a/proto/pulsarchain/keyregistry/v1/query.proto b/proto/pulsarchain/keyregistry/v1/query.proto index b1fd2c73..9dda46ad 100644 --- a/proto/pulsarchain/keyregistry/v1/query.proto +++ b/proto/pulsarchain/keyregistry/v1/query.proto @@ -17,14 +17,24 @@ service Query { option (google.api.http).get = "/node101-io/pulsar-chain/keyregistry/v1/params"; } - // GetMinaPubKey Queries a list of GetMinaPubKey items. - rpc GetMinaPubKey(QueryGetMinaPubKeyRequest) returns (QueryGetMinaPubKeyResponse) { - option (google.api.http).get = "/node101-io/pulsar-chain/keyregistry/v1/get_mina_pub_key/{cosmos_pub_key}"; + // GetUserMinaAddress Queries a list of GetUserMinaAddress items. + rpc GetUserMinaAddress(QueryGetUserMinaAddressRequest) returns (QueryGetUserMinaAddressResponse) { + option (google.api.http).get = "/node101-io/pulsar-chain/keyregistry/v1/get_user_mina_address/{user_cosmos_address}"; } - // GetCosmosPubKey Queries a list of GetCosmosPubKey items. - rpc GetCosmosPubKey(QueryGetCosmosPubKeyRequest) returns (QueryGetCosmosPubKeyResponse) { - option (google.api.http).get = "/node101-io/pulsar-chain/keyregistry/v1/get_cosmos_pub_key/{mina_pub_key}"; + // GetUserCosmosAddress Queries a list of GetUserCosmosAddress items. + rpc GetUserCosmosAddress(QueryGetUserCosmosAddressRequest) returns (QueryGetUserCosmosAddressResponse) { + option (google.api.http).get = "/node101-io/pulsar-chain/keyregistry/v1/get_user_cosmos_address/{user_mina_address}"; + } + + // GetValidatorMinaAddress Queries a list of GetValidatorMinaAddress items. + rpc GetValidatorMinaPubKey(QueryGetValidatorMinaPubKeyRequest) returns (QueryGetValidatorMinaPubKeyResponse) { + option (google.api.http).get = "/node101-io/pulsar-chain/keyregistry/v1/get_validator_mina_pub_key/{validator_cosmos_pub_key}"; + } + + // GetValidatorCosmosAddress Queries a list of GetValidatorCosmosAddress items. + rpc GetValidatorCosmosPubKey(QueryGetValidatorCosmosPubKeyRequest) returns (QueryGetValidatorCosmosPubKeyResponse) { + option (google.api.http).get = "/node101-io/pulsar-chain/keyregistry/v1/get_validator_cosmos_pub_key/{validator_mina_pub_key}"; } } @@ -40,22 +50,42 @@ message QueryParamsResponse { ]; } -// QueryGetMinaPubKeyRequest defines the QueryGetMinaPubKeyRequest message. -message QueryGetMinaPubKeyRequest { - bytes cosmos_pub_key = 1; +// QueryGetUserMinaAddressRequest defines the QueryGetUserMinaAddressRequest message. +message QueryGetUserMinaAddressRequest { + bytes user_cosmos_address = 1; +} + +// QueryGetUserMinaAddressResponse defines the QueryGetUserMinaAddressResponse message. +message QueryGetUserMinaAddressResponse { + bytes user_mina_address = 1; +} + +// QueryGetUserCosmosAddressRequest defines the QueryGetUserCosmosAddressRequest message. +message QueryGetUserCosmosAddressRequest { + bytes user_mina_address = 1; +} + +// QueryGetUserCosmosAddressResponse defines the QueryGetUserCosmosAddressResponse message. +message QueryGetUserCosmosAddressResponse { + bytes user_cosmos_address = 1; +} + +// QueryGetValidatorMinaAddressRequest defines the QueryGetValidatorMinaAddressRequest message. +message QueryGetValidatorMinaPubKeyRequest { + bytes validator_cosmos_pub_key = 1; } -// QueryGetMinaPubKeyResponse defines the QueryGetMinaPubKeyResponse message. -message QueryGetMinaPubKeyResponse { - bytes mina_pub_key = 1; +// QueryGetValidatorMinaAddressResponse defines the QueryGetValidatorMinaAddressResponse message. +message QueryGetValidatorMinaPubKeyResponse { + bytes validator_mina_pub_key = 1; } -// QueryGetCosmosPubKeyRequest defines the QueryGetCosmosPubKeyRequest message. -message QueryGetCosmosPubKeyRequest { - bytes mina_pub_key = 1; +// QueryGetValidatorCosmosAddressRequest defines the QueryGetValidatorCosmosAddressRequest message. +message QueryGetValidatorCosmosPubKeyRequest { + bytes validator_mina_pub_key = 1; } -// QueryGetCosmosPubKeyResponse defines the QueryGetCosmosPubKeyResponse message. -message QueryGetCosmosPubKeyResponse { - bytes cosmos_pub_key = 1; +// QueryGetValidatorCosmosAddressResponse defines the QueryGetValidatorCosmosAddressResponse message. +message QueryGetValidatorCosmosPubKeyResponse { + bytes validator_cosmos_pub_key = 1; } diff --git a/proto/pulsarchain/keyregistry/v1/tx.proto b/proto/pulsarchain/keyregistry/v1/tx.proto index 1841b99d..6a8826bf 100644 --- a/proto/pulsarchain/keyregistry/v1/tx.proto +++ b/proto/pulsarchain/keyregistry/v1/tx.proto @@ -49,8 +49,9 @@ message MsgRegisterKeys { string creator = 1 [(cosmos_proto.scalar) = "cosmos.AddressString"]; string cosmos_signature = 2; string mina_signature = 3; - bytes cosmos_public_key = 4; - bytes mina_public_key = 5; + bytes cosmos_address = 4; + bytes mina_address = 5; + bool is_user = 6; } // MsgRegisterKeysResponse defines the MsgRegisterKeysResponse message. diff --git a/x/keyregistry/keeper/genesis.go b/x/keyregistry/keeper/genesis.go index 8bbcbd8a..d8163ed5 100644 --- a/x/keyregistry/keeper/genesis.go +++ b/x/keyregistry/keeper/genesis.go @@ -9,16 +9,31 @@ import ( // InitGenesis initializes the module's state from a provided genesis state. func (k Keeper) InitGenesis(ctx context.Context, genState types.GenesisState) error { - keyPairs := genState.KeyPairs + userKeyPairs := genState.UserKeyPairs // Insert genesis key pairs. - for _, keyPair := range keyPairs { + for _, keyPair := range userKeyPairs { - err := k.cosmosToMina.Set(ctx, keyPair.CosmosKey, keyPair.MinaKey) + err := k.userCosmosToMina.Set(ctx, keyPair.CosmosAddr, keyPair.MinaAddr) if err != nil { return err } - err = k.minaToCosmos.Set(ctx, keyPair.MinaKey, keyPair.CosmosKey) + err = k.userMinaToCosmos.Set(ctx, keyPair.MinaAddr, keyPair.CosmosAddr) + if err != nil { + return err + } + } + + validatorKeyPairs := genState.ValidatorKeyPairs + + // Insert genesis key pairs. + for _, keyPair := range validatorKeyPairs { + + err := k.validatorCosmosToMina.Set(ctx, keyPair.CosmosKey, keyPair.MinaKey) + if err != nil { + return err + } + err = k.validatorMinaToCosmos.Set(ctx, keyPair.MinaKey, keyPair.CosmosKey) if err != nil { return err } @@ -37,36 +52,36 @@ func (k Keeper) ExportGenesis(ctx context.Context) (*types.GenesisState, error) return nil, err } - var keyPairs []*types.KeyPair + var userKeyPairs []*types.AddressPair - var existenceMap = make(map[string]bool) + var userKeypairExistenceMap = make(map[string]bool) // Iterate over CosmosToMina map first and collect all key pairs. - cosmosIterator, err := k.cosmosToMina.Iterate(ctx, nil) + userCosmosIterator, err := k.userCosmosToMina.Iterate(ctx, nil) if err != nil { return nil, err } - defer cosmosIterator.Close() + defer userCosmosIterator.Close() - for cosmosIterator.Valid() { - cosmosKey, err := cosmosIterator.Key() + for userCosmosIterator.Valid() { + cosmosKey, err := userCosmosIterator.Key() if err != nil { return genesis, err } - minaKey, err := cosmosIterator.Value() + minaKey, err := userCosmosIterator.Value() if err != nil { return genesis, err } - keyPair := &types.KeyPair{ - MinaKey: minaKey, - CosmosKey: cosmosKey, + keyPair := &types.AddressPair{ + MinaAddr: minaKey, + CosmosAddr: cosmosKey, } - keyPairs = append(keyPairs, keyPair) - existenceMap[keyPair.String()] = true - cosmosIterator.Next() + userKeyPairs = append(userKeyPairs, keyPair) + userKeypairExistenceMap[keyPair.String()] = true + userCosmosIterator.Next() } - // Iterate over MinaToCosmos map and collect any key pairs that are not + // Iterate over inaToCosmos map and collect any key pairs that are not // already present in the CosmosToMina map. Although both maps are expected // to be in sync, this ensures no key pairs are lost in case of any inconsistency // between the two maps during export. @@ -75,34 +90,92 @@ func (k Keeper) ExportGenesis(ctx context.Context) (*types.GenesisState, error) // Returning an error here could prevent the state from being exported and lead // to potential state loss. Consistency checks should instead be handled at the // message implementation level where the mappings are created or updated. - minaIterator, err := k.minaToCosmos.Iterate(ctx, nil) + userMinaIterator, err := k.userMinaToCosmos.Iterate(ctx, nil) + if err != nil { + return nil, err + } + defer userMinaIterator.Close() + + for userMinaIterator.Valid() { + minaKey, err := userMinaIterator.Key() + if err != nil { + return genesis, err + } + cosmosKey, err := userMinaIterator.Value() + if err != nil { + return genesis, err + } + keyPair := &types.AddressPair{ + MinaAddr: minaKey, + CosmosAddr: cosmosKey, + } + if userKeypairExistenceMap[keyPair.String()] { + userMinaIterator.Next() + continue + } + userKeyPairs = append(userKeyPairs, keyPair) + userMinaIterator.Next() + } + + genesis.UserKeyPairs = userKeyPairs + + var validatorKeyPairs []*types.PublicKeyPair + + var validatorKeypairExistenceMap = make(map[string]bool) + + // Iterate over CosmosToMina map first and collect all key pairs. + validatorCosmosIterator, err := k.validatorCosmosToMina.Iterate(ctx, nil) + if err != nil { + return nil, err + } + defer validatorCosmosIterator.Close() + + for validatorCosmosIterator.Valid() { + cosmosKey, err := validatorCosmosIterator.Key() + if err != nil { + return genesis, err + } + minaKey, err := validatorCosmosIterator.Value() + if err != nil { + return genesis, err + } + keyPair := &types.PublicKeyPair{ + MinaKey: minaKey, + CosmosKey: cosmosKey, + } + validatorKeyPairs = append(validatorKeyPairs, keyPair) + validatorKeypairExistenceMap[keyPair.String()] = true + validatorCosmosIterator.Next() + } + + validatorMinaIterator, err := k.validatorMinaToCosmos.Iterate(ctx, nil) if err != nil { return nil, err } - defer minaIterator.Close() + defer validatorMinaIterator.Close() - for minaIterator.Valid() { - minaKey, err := minaIterator.Key() + for validatorMinaIterator.Valid() { + minaKey, err := validatorMinaIterator.Key() if err != nil { return genesis, err } - cosmosKey, err := minaIterator.Value() + cosmosKey, err := validatorMinaIterator.Value() if err != nil { return genesis, err } - keyPair := &types.KeyPair{ + keyPair := &types.PublicKeyPair{ MinaKey: minaKey, CosmosKey: cosmosKey, } - if existenceMap[keyPair.String()] { - minaIterator.Next() + if validatorKeypairExistenceMap[keyPair.String()] { + validatorMinaIterator.Next() continue } - keyPairs = append(keyPairs, keyPair) - minaIterator.Next() + validatorKeyPairs = append(validatorKeyPairs, keyPair) + validatorMinaIterator.Next() } - genesis.KeyPairs = keyPairs + genesis.ValidatorKeyPairs = validatorKeyPairs return genesis, nil } diff --git a/x/keyregistry/keeper/genesis_test.go b/x/keyregistry/keeper/genesis_test.go index 26bc0bc0..dc1dfce7 100644 --- a/x/keyregistry/keeper/genesis_test.go +++ b/x/keyregistry/keeper/genesis_test.go @@ -43,7 +43,13 @@ func TestInitAndExportGenesis(t *testing.T) { genesisState := types.GenesisState{ Params: types.DefaultParams(), - KeyPairs: []*types.KeyPair{ + UserKeyPairs: []*types.AddressPair{ + { + MinaAddr: minaPubKey, + CosmosAddr: cosmosPubKey.Bytes(), + }, + }, + ValidatorKeyPairs: []*types.PublicKeyPair{ { MinaKey: minaPubKey, CosmosKey: cosmosPubKey.Bytes(), @@ -57,6 +63,6 @@ func TestInitAndExportGenesis(t *testing.T) { require.NoError(t, err) require.NotNil(t, got) - require.EqualExportedValues(t, genesisState.KeyPairs, got.KeyPairs) + require.EqualExportedValues(t, genesisState.UserKeyPairs, got.UserKeyPairs) } diff --git a/x/keyregistry/keeper/keeper.go b/x/keyregistry/keeper/keeper.go index 2097b0f3..851d23f8 100644 --- a/x/keyregistry/keeper/keeper.go +++ b/x/keyregistry/keeper/keeper.go @@ -11,8 +11,11 @@ import ( "github.com/node101-io/pulsar-chain/x/keyregistry/types" ) -const CosmosToMinaMapName string = "cosmos_to_mina" -const MinaToCosmosMapName string = "mina_to_cosmos" +const UserCosmosToMinaMapName string = "user_cosmos_to_mina" +const UserMinaToCosmosMapName string = "user_mina_to_cosmos" + +const ValidatorCosmosToMinaMapName string = "validator_cosmos_to_mina" +const ValidatorMinaToCosmosMapName string = "validator_mina_to_cosmos" type Keeper struct { storeService corestore.KVStoreService @@ -25,8 +28,11 @@ type Keeper struct { Schema collections.Schema Params collections.Item[types.Params] - cosmosToMina collections.Map[[]byte, []byte] // Cosmos PubKey --> Mina PubKey - minaToCosmos collections.Map[[]byte, []byte] // Mina PubKey --> Cosmos PubKey + userCosmosToMina collections.Map[[]byte, []byte] // Cosmos Address --> Mina Address + userMinaToCosmos collections.Map[[]byte, []byte] // Mina Address --> Cosmos Address + + validatorCosmosToMina collections.Map[[]byte, []byte] // Validator Cosmos Address --> Validator Mina Address + validatorMinaToCosmos collections.Map[[]byte, []byte] // Validator Mina Address --> Validator Cosmos Address } func NewKeeper( @@ -50,8 +56,11 @@ func NewKeeper( Params: collections.NewItem(sb, types.ParamsKey, "params", codec.CollValue[types.Params](cdc)), - cosmosToMina: collections.NewMap(sb, types.CosmosToMinaPrefix, CosmosToMinaMapName, collections.BytesKey, collections.BytesValue), - minaToCosmos: collections.NewMap(sb, types.MinaToCosmosPrefix, MinaToCosmosMapName, collections.BytesKey, collections.BytesValue), + userCosmosToMina: collections.NewMap(sb, types.UserCosmosToMinaPrefix, UserCosmosToMinaMapName, collections.BytesKey, collections.BytesValue), + userMinaToCosmos: collections.NewMap(sb, types.UserMinaToCosmosPrefix, UserMinaToCosmosMapName, collections.BytesKey, collections.BytesValue), + + validatorCosmosToMina: collections.NewMap(sb, types.ValidatorCosmosToMinaPrefix, ValidatorCosmosToMinaMapName, collections.BytesKey, collections.BytesValue), + validatorMinaToCosmos: collections.NewMap(sb, types.ValidatorMinaToCosmosPrefix, ValidatorMinaToCosmosMapName, collections.BytesKey, collections.BytesValue), } schema, err := sb.Build() if err != nil { @@ -67,26 +76,50 @@ func (k Keeper) GetAuthority() []byte { return k.authority } -func (k Keeper) SetCosmosToMina(ctx context.Context, cosmosPublicKey, minaPublicKey []byte) error { - return k.cosmosToMina.Set(ctx, cosmosPublicKey, minaPublicKey) +func (k Keeper) UserSetCosmosToMina(ctx context.Context, cosmosAddress, minaAddress []byte) error { + return k.userCosmosToMina.Set(ctx, cosmosAddress, minaAddress) +} + +func (k Keeper) UserGetCosmosToMina(ctx context.Context, cosmosAddress []byte) ([]byte, error) { + return k.userCosmosToMina.Get(ctx, cosmosAddress) +} + +func (k Keeper) UserSetMinaToCosmos(ctx context.Context, minaAddress, cosmosAddress []byte) error { + return k.userMinaToCosmos.Set(ctx, minaAddress, cosmosAddress) +} + +func (k Keeper) UserGetMinaToCosmos(ctx context.Context, minaAddress []byte) ([]byte, error) { + return k.userMinaToCosmos.Get(ctx, minaAddress) +} + +func (k Keeper) UserCosmosToMinaHas(ctx context.Context, cosmosAddress []byte) (bool, error) { + return k.userCosmosToMina.Has(ctx, cosmosAddress) +} + +func (k Keeper) UserMinaToCosmosHas(ctx context.Context, minaAddress []byte) (bool, error) { + return k.userMinaToCosmos.Has(ctx, minaAddress) +} + +func (k Keeper) ValidatorSetCosmosToMina(ctx context.Context, cosmosAddress, minaAddress []byte) error { + return k.validatorCosmosToMina.Set(ctx, cosmosAddress, minaAddress) } -func (k Keeper) GetCosmosToMina(ctx context.Context, cosmosPublicKey []byte) ([]byte, error) { - return k.cosmosToMina.Get(ctx, cosmosPublicKey) +func (k Keeper) ValidatorGetCosmosToMina(ctx context.Context, cosmosAddress []byte) ([]byte, error) { + return k.validatorCosmosToMina.Get(ctx, cosmosAddress) } -func (k Keeper) SetMinaToCosmos(ctx context.Context, minaPublicKey, cosmosPublicKey []byte) error { - return k.minaToCosmos.Set(ctx, minaPublicKey, cosmosPublicKey) +func (k Keeper) ValidatorSetMinaToCosmos(ctx context.Context, minaAddress, cosmosAddress []byte) error { + return k.validatorMinaToCosmos.Set(ctx, minaAddress, cosmosAddress) } -func (k Keeper) GetMinaToCosmos(ctx context.Context, minaPublicKey []byte) ([]byte, error) { - return k.minaToCosmos.Get(ctx, minaPublicKey) +func (k Keeper) ValidatorGetMinaToCosmos(ctx context.Context, minaAddress []byte) ([]byte, error) { + return k.validatorMinaToCosmos.Get(ctx, minaAddress) } -func (k Keeper) CosmosToMinaHas(ctx context.Context, cosmosPublicKey []byte) (bool, error) { - return k.cosmosToMina.Has(ctx, cosmosPublicKey) +func (k Keeper) ValidatorCosmosToMinaHas(ctx context.Context, cosmosAddress []byte) (bool, error) { + return k.validatorCosmosToMina.Has(ctx, cosmosAddress) } -func (k Keeper) MinaToCosmosHas(ctx context.Context, minaPublicKey []byte) (bool, error) { - return k.minaToCosmos.Has(ctx, minaPublicKey) +func (k Keeper) ValidatorMinaToCosmosHas(ctx context.Context, minaAddress []byte) (bool, error) { + return k.validatorMinaToCosmos.Has(ctx, minaAddress) } diff --git a/x/keyregistry/keeper/keeper_test.go b/x/keyregistry/keeper/keeper_test.go index e00bb4a5..92679d98 100644 --- a/x/keyregistry/keeper/keeper_test.go +++ b/x/keyregistry/keeper/keeper_test.go @@ -62,13 +62,13 @@ var MinaPubKey = []byte("mina") // TestCosmosToMina verifies that a cosmos public key can be stored in the // CosmosToMina map and correctly retrieved using the same cosmos public key. -func TestCosmosToMina(t *testing.T) { +func TestUserCosmosToMina(t *testing.T) { f := initFixture(t) - err := f.keeper.SetCosmosToMina(f.ctx, CosmosPubKey, MinaPubKey) + err := f.keeper.UserSetCosmosToMina(f.ctx, CosmosPubKey, MinaPubKey) require.NoError(t, err) - pubKey, err := f.keeper.GetCosmosToMina(f.ctx, CosmosPubKey) + pubKey, err := f.keeper.UserGetCosmosToMina(f.ctx, CosmosPubKey) require.NoError(t, err) require.Equal(t, MinaPubKey, pubKey) @@ -76,13 +76,13 @@ func TestCosmosToMina(t *testing.T) { // TestMinaToCosmos verifies that a mina public key can be stored in the // MinaToCosmos map and correctly retrieved using the same mina public key. -func TestMinaToCosmos(t *testing.T) { +func TestUserMinaToCosmos(t *testing.T) { f := initFixture(t) - err := f.keeper.SetMinaToCosmos(f.ctx, MinaPubKey, CosmosPubKey) + err := f.keeper.UserSetMinaToCosmos(f.ctx, MinaPubKey, CosmosPubKey) require.NoError(t, err) - pubKey, err := f.keeper.GetMinaToCosmos(f.ctx, MinaPubKey) + pubKey, err := f.keeper.UserGetMinaToCosmos(f.ctx, MinaPubKey) require.NoError(t, err) require.Equal(t, CosmosPubKey, pubKey) diff --git a/x/keyregistry/keeper/msg_server_register_keys.go b/x/keyregistry/keeper/msg_server_register_keys.go index 321dfc44..cfbd328d 100644 --- a/x/keyregistry/keeper/msg_server_register_keys.go +++ b/x/keyregistry/keeper/msg_server_register_keys.go @@ -3,27 +3,48 @@ package keeper import ( "context" - errorsmod "cosmossdk.io/errors" + "github.com/cosmos/cosmos-sdk/crypto/keys/ed25519" "github.com/cosmos/cosmos-sdk/crypto/keys/secp256k1" sdk "github.com/cosmos/cosmos-sdk/types" "github.com/node101-io/pulsar-chain/x/keyregistry/types" ) -// TODO: Implement Mina signature verification -func VerifyMinaSig(sig string, msg, minaPublicKey []byte) bool { +// TODO: Implement Mina signature verification for users +func VerifyUserMinaSig(sig string, msg, minaAddress []byte) bool { return true } -// TODO: Implement Cosmos signature verification -func VerifyCosmosSig(sig string, msg, cosmosPublicKey []byte) bool { +// TODO: Implement Cosmos signature verification for users +func VerifyUserCosmosSig(sig string, msg, mosmosAddress []byte) bool { return true } -// deriveAddressFromPubkey derives a bech32 cosmos address from a compressed secp256k1 public key. -func deriveAddressFromPubkey(cosmosPublicKey []byte) string { +// TODO: Implement Mina signature verification for users +func VerifyValidatorMinaSig(sig string, msg, minaAddress []byte) bool { + return true +} + +// TODO: Implement Cosmos signature verification for users +func VerifyValidatorCosmosSig(sig string, msg, cosmosAddress []byte) bool { + return true +} + +// deriveAddressFromPubkey derives the expected signer address from the provided +// key material. Users provide secp256k1 account public keys, while validators +// provide consensus public keys. +func deriveAddressFromPubkey(cosmosAddress []byte, isUser bool) string { + if !isUser { + pubKey := ed25519.PubKey{ + Key: cosmosAddress, + } + validatorAddr := sdk.ConsAddress(pubKey.Address()) + return validatorAddr.String() + } + pubKey := secp256k1.PubKey{ - Key: cosmosPublicKey, + Key: cosmosAddress, } + addr := sdk.AccAddress(pubKey.Address()) return addr.String() } @@ -38,56 +59,14 @@ func deriveAddressFromPubkey(cosmosPublicKey []byte) string { // // If all checks pass, the key pair is stored in both the CosmosToMina and MinaToCosmos maps. func (k msgServer) RegisterKeys(ctx context.Context, msg *types.MsgRegisterKeys) (*types.MsgRegisterKeysResponse, error) { - // Validate the creator address. - if _, err := k.addressCodec.StringToBytes(msg.Creator); err != nil { - return nil, errorsmod.Wrap(types.ErrInvalidCreatorAddres, "") - } - - // Ensure the cosmos and mina public keys are valid. - err := types.ValidateKeyPair(types.KeyPair{ - MinaKey: msg.MinaPublicKey, - CosmosKey: msg.CosmosPublicKey, - }) - if err != nil { - return nil, errorsmod.Wrap(types.ErrInvalidPublicKey, "pubkeys must be valid") - } - - // Ensure the creator address matches the provided cosmos public key - // to prevent someone from registering a key pair on behalf of another address. - derivedAddress := deriveAddressFromPubkey(msg.CosmosPublicKey) - if derivedAddress != msg.Creator { - return nil, errorsmod.Wrap(types.ErrInvalidSigner, "creator does not match provided cosmos public key") - } - - // Check if either key is already registered to prevent duplicate registrations. - cosmosKeyExists, err := k.Keeper.cosmosToMina.Has(ctx, msg.CosmosPublicKey) - if err != nil { - return nil, err - } - minaKeyExists, err := k.Keeper.minaToCosmos.Has(ctx, msg.MinaPublicKey) - if err != nil { - return nil, err - } - if cosmosKeyExists || minaKeyExists { - return nil, errorsmod.Wrap(types.ErrSecondaryKeyExists, "") - } + var err error - // Verify that the mina key signed the cosmos public key and vice versa. - // This proves ownership of both keys. - minaSigValidity := VerifyMinaSig(msg.MinaSignature, msg.CosmosPublicKey, msg.MinaPublicKey) - cosmosSigValidity := VerifyCosmosSig(msg.CosmosSignature, msg.MinaPublicKey, msg.CosmosPublicKey) - - if !minaSigValidity || !cosmosSigValidity { - return nil, errorsmod.Wrap(types.ErrInvalidSignature, "invalid cosmos or mina signature") - } - - // Store the key pair in both directions to allow lookups by either key. - err = k.Keeper.cosmosToMina.Set(ctx, msg.CosmosPublicKey, msg.MinaPublicKey) - if err != nil { - return nil, err + if msg.IsUser { + err = k.handleUserRegistration(ctx, msg) + } else { + err = k.handleValidatorRegistration(ctx, msg) } - err = k.Keeper.minaToCosmos.Set(ctx, msg.MinaPublicKey, msg.CosmosPublicKey) if err != nil { return nil, err } diff --git a/x/keyregistry/keeper/msg_server_register_user_keys.go b/x/keyregistry/keeper/msg_server_register_user_keys.go new file mode 100644 index 00000000..6bef940e --- /dev/null +++ b/x/keyregistry/keeper/msg_server_register_user_keys.go @@ -0,0 +1,63 @@ +package keeper + +import ( + "bytes" + "context" + + errorsmod "cosmossdk.io/errors" + "github.com/node101-io/pulsar-chain/x/keyregistry/types" +) + +// handleUserRegistration encapsulates the user registration flow where both +// sides of the mapping are addresses, not public keys. +func (k msgServer) handleUserRegistration(ctx context.Context, msg *types.MsgRegisterKeys) error { + creatorAddress, err := k.addressCodec.StringToBytes(msg.Creator) + if err != nil { + return errorsmod.Wrap(types.ErrInvalidCreatorAddres, "") + } + + err = types.ValidateAddressPair(types.AddressPair{ + MinaAddr: msg.MinaAddress, + CosmosAddr: msg.CosmosAddress, + }) + if err != nil { + return errorsmod.Wrap(types.ErrInvalidAddress, "address must be valid") + } + + if !bytes.Equal(creatorAddress, msg.CosmosAddress) { + return errorsmod.Wrap(types.ErrInvalidSigner, "creator does not match provided cosmos address") + } + + return k.persistUserRegistration(ctx, msg) +} + +func (k msgServer) persistUserRegistration(ctx context.Context, msg *types.MsgRegisterKeys) error { + cosmosKeyExists, err := k.Keeper.userCosmosToMina.Has(ctx, msg.CosmosAddress) + if err != nil { + return err + } + minaKeyExists, err := k.Keeper.userMinaToCosmos.Has(ctx, msg.MinaAddress) + if err != nil { + return err + } + if cosmosKeyExists || minaKeyExists { + return errorsmod.Wrap(types.ErrUserSecondaryKeyExists, "") + } + + minaSigValidity := VerifyUserMinaSig(msg.MinaSignature, msg.CosmosAddress, msg.MinaAddress) + cosmosSigValidity := VerifyUserCosmosSig(msg.CosmosSignature, msg.MinaAddress, msg.CosmosAddress) + if !minaSigValidity || !cosmosSigValidity { + return errorsmod.Wrap(types.ErrInvalidSignature, "invalid cosmos or mina signature") + } + + err = k.Keeper.userCosmosToMina.Set(ctx, msg.CosmosAddress, msg.MinaAddress) + if err != nil { + return err + } + err = k.Keeper.userMinaToCosmos.Set(ctx, msg.MinaAddress, msg.CosmosAddress) + if err != nil { + return err + } + + return nil +} diff --git a/x/keyregistry/keeper/msg_server_register_validator_keys.go b/x/keyregistry/keeper/msg_server_register_validator_keys.go new file mode 100644 index 00000000..59e3f6e1 --- /dev/null +++ b/x/keyregistry/keeper/msg_server_register_validator_keys.go @@ -0,0 +1,64 @@ +package keeper + +import ( + "context" + + errorsmod "cosmossdk.io/errors" + sdk "github.com/cosmos/cosmos-sdk/types" + "github.com/node101-io/pulsar-chain/x/keyregistry/types" +) + +// handleValidatorRegistration encapsulates the validator registration flow +// where the Cosmos-side key is the validator consensus public key. +func (k msgServer) handleValidatorRegistration(ctx context.Context, msg *types.MsgRegisterKeys) error { + _, err := sdk.ConsAddressFromBech32(msg.Creator) + if err != nil { + return errorsmod.Wrap(types.ErrInvalidCreatorAddres, "") + } + + err = types.ValidatePublicKeyPair(types.PublicKeyPair{ + MinaKey: msg.MinaAddress, + CosmosKey: msg.CosmosAddress, + }) + if err != nil { + return errorsmod.Wrap(types.ErrInvalidPublicKey, "pubkeys must be valid") + } + + derivedAddress := deriveAddressFromPubkey(msg.CosmosAddress, false) + if derivedAddress != msg.Creator { + return errorsmod.Wrap(types.ErrInvalidSigner, "creator does not match provided cosmos consensus public key") + } + + return k.persistValidatorRegistration(ctx, msg) +} + +func (k msgServer) persistValidatorRegistration(ctx context.Context, msg *types.MsgRegisterKeys) error { + cosmosKeyExists, err := k.Keeper.validatorCosmosToMina.Has(ctx, msg.CosmosAddress) + if err != nil { + return err + } + minaKeyExists, err := k.Keeper.validatorMinaToCosmos.Has(ctx, msg.MinaAddress) + if err != nil { + return err + } + if cosmosKeyExists || minaKeyExists { + return errorsmod.Wrap(types.ErrValidatorSecondaryKeyExists, "") + } + + minaSigValidity := VerifyValidatorMinaSig(msg.MinaSignature, msg.CosmosAddress, msg.MinaAddress) + cosmosSigValidity := VerifyValidatorCosmosSig(msg.CosmosSignature, msg.MinaAddress, msg.CosmosAddress) + if !minaSigValidity || !cosmosSigValidity { + return errorsmod.Wrap(types.ErrInvalidSignature, "invalid cosmos or mina signature") + } + + err = k.Keeper.validatorCosmosToMina.Set(ctx, msg.CosmosAddress, msg.MinaAddress) + if err != nil { + return err + } + err = k.Keeper.validatorMinaToCosmos.Set(ctx, msg.MinaAddress, msg.CosmosAddress) + if err != nil { + return err + } + + return nil +} diff --git a/x/keyregistry/keeper/query.go b/x/keyregistry/keeper/query.go index 5b8c8317..7f90e455 100644 --- a/x/keyregistry/keeper/query.go +++ b/x/keyregistry/keeper/query.go @@ -1,8 +1,6 @@ package keeper -import ( - "github.com/node101-io/pulsar-chain/x/keyregistry/types" -) +import "github.com/node101-io/pulsar-chain/x/keyregistry/types" var _ types.QueryServer = queryServer{} diff --git a/x/keyregistry/keeper/query_get_user_cosmos_address.go b/x/keyregistry/keeper/query_get_user_cosmos_address.go new file mode 100644 index 00000000..c8ed261a --- /dev/null +++ b/x/keyregistry/keeper/query_get_user_cosmos_address.go @@ -0,0 +1,39 @@ +package keeper + +import ( + "context" + + sdk "github.com/cosmos/cosmos-sdk/types" + "github.com/node101-io/pulsar-chain/x/keyregistry/types" + "google.golang.org/grpc/codes" + "google.golang.org/grpc/status" +) + +// GetCosmosPubKey returns the user's cosmos public key associated with the given mina public key. +// Returns NotFound if no mapping exists for the provided mina public key. +func (q queryServer) GetUserCosmosAddress(ctx context.Context, req *types.QueryGetUserCosmosAddressRequest) (*types.QueryGetUserCosmosAddressResponse, error) { + if req == nil { + return nil, status.Error(codes.InvalidArgument, "invalid request") + } + + sdkCtx := sdk.UnwrapSDKContext(ctx) + + // Check if the mina address exists in the MinaToCosmos map. + exists, err := q.k.userMinaToCosmos.Has(sdkCtx, req.UserMinaAddress) + if err != nil { + return nil, status.Error(codes.Internal, "internal error") + } + + if !exists { + return nil, status.Error(codes.NotFound, "cosmos key not found for given mina key") + } + + cosmosKey, err := q.k.userMinaToCosmos.Get(sdkCtx, req.UserMinaAddress) + if err != nil { + return nil, status.Error(codes.Internal, err.Error()) + } + + return &types.QueryGetUserCosmosAddressResponse{ + UserCosmosAddress: cosmosKey, + }, nil +} diff --git a/x/keyregistry/keeper/query_get_mina_pub_key.go b/x/keyregistry/keeper/query_get_user_mina_address.go similarity index 61% rename from x/keyregistry/keeper/query_get_mina_pub_key.go rename to x/keyregistry/keeper/query_get_user_mina_address.go index 301a62c0..421b9b89 100644 --- a/x/keyregistry/keeper/query_get_mina_pub_key.go +++ b/x/keyregistry/keeper/query_get_user_mina_address.go @@ -9,9 +9,9 @@ import ( "google.golang.org/grpc/status" ) -// GetMinaPubKey returns the mina public key associated with the given cosmos public key. +// GetMinaPubKey returns the user's mina public key associated with the given cosmos public key. // Returns NotFound if no mapping exists for the provided cosmos public key. -func (q queryServer) GetMinaPubKey(ctx context.Context, req *types.QueryGetMinaPubKeyRequest) (*types.QueryGetMinaPubKeyResponse, error) { +func (q queryServer) GetUserMinaAddress(ctx context.Context, req *types.QueryGetUserMinaAddressRequest) (*types.QueryGetUserMinaAddressResponse, error) { if req == nil { return nil, status.Error(codes.InvalidArgument, "invalid request") } @@ -19,7 +19,7 @@ func (q queryServer) GetMinaPubKey(ctx context.Context, req *types.QueryGetMinaP sdkCtx := sdk.UnwrapSDKContext(ctx) // Check if the cosmos key exists in the CosmosToMina map. - exists, err := q.k.cosmosToMina.Has(sdkCtx, req.CosmosPubKey) + exists, err := q.k.userCosmosToMina.Has(sdkCtx, req.UserCosmosAddress) if err != nil { return nil, status.Error(codes.Internal, "internal Error") } @@ -28,12 +28,12 @@ func (q queryServer) GetMinaPubKey(ctx context.Context, req *types.QueryGetMinaP return nil, status.Error(codes.NotFound, "mina key not found for given cosmos key") } - minaKey, err := q.k.cosmosToMina.Get(sdkCtx, req.CosmosPubKey) + minaKey, err := q.k.userCosmosToMina.Get(sdkCtx, req.UserCosmosAddress) if err != nil { return nil, status.Error(codes.Internal, err.Error()) } - return &types.QueryGetMinaPubKeyResponse{ - MinaPubKey: minaKey, + return &types.QueryGetUserMinaAddressResponse{ + UserMinaAddress: minaKey, }, nil } diff --git a/x/keyregistry/keeper/query_get_cosmos_pub_key.go b/x/keyregistry/keeper/query_get_validator_cosmos_pub_key.go similarity index 58% rename from x/keyregistry/keeper/query_get_cosmos_pub_key.go rename to x/keyregistry/keeper/query_get_validator_cosmos_pub_key.go index 241233a3..69e19fa9 100644 --- a/x/keyregistry/keeper/query_get_cosmos_pub_key.go +++ b/x/keyregistry/keeper/query_get_validator_cosmos_pub_key.go @@ -9,9 +9,10 @@ import ( "google.golang.org/grpc/status" ) -// GetCosmosPubKey returns the cosmos public key associated with the given mina public key. +// GetCosmosPubKey returns the Validator's cosmos public key associated with the given mina public key. // Returns NotFound if no mapping exists for the provided mina public key. -func (q queryServer) GetCosmosPubKey(ctx context.Context, req *types.QueryGetCosmosPubKeyRequest) (*types.QueryGetCosmosPubKeyResponse, error) { + +func (q queryServer) GetValidatorCosmosPubKey(ctx context.Context, req *types.QueryGetValidatorCosmosPubKeyRequest) (*types.QueryGetValidatorCosmosPubKeyResponse, error) { if req == nil { return nil, status.Error(codes.InvalidArgument, "invalid request") } @@ -19,7 +20,7 @@ func (q queryServer) GetCosmosPubKey(ctx context.Context, req *types.QueryGetCos sdkCtx := sdk.UnwrapSDKContext(ctx) // Check if the mina key exists in the MinaToCosmos map. - exists, err := q.k.minaToCosmos.Has(sdkCtx, req.MinaPubKey) + exists, err := q.k.validatorMinaToCosmos.Has(sdkCtx, req.ValidatorMinaPubKey) if err != nil { return nil, status.Error(codes.Internal, "internal error") } @@ -28,12 +29,12 @@ func (q queryServer) GetCosmosPubKey(ctx context.Context, req *types.QueryGetCos return nil, status.Error(codes.NotFound, "cosmos key not found for given mina key") } - cosmosKey, err := q.k.minaToCosmos.Get(sdkCtx, req.MinaPubKey) + cosmosKey, err := q.k.validatorMinaToCosmos.Get(sdkCtx, req.ValidatorMinaPubKey) if err != nil { return nil, status.Error(codes.Internal, err.Error()) } - return &types.QueryGetCosmosPubKeyResponse{ - CosmosPubKey: cosmosKey, + return &types.QueryGetValidatorCosmosPubKeyResponse{ + ValidatorCosmosPubKey: cosmosKey, }, nil } diff --git a/x/keyregistry/keeper/query_get_validator_mina_pub_key.go b/x/keyregistry/keeper/query_get_validator_mina_pub_key.go new file mode 100644 index 00000000..2f0ce656 --- /dev/null +++ b/x/keyregistry/keeper/query_get_validator_mina_pub_key.go @@ -0,0 +1,39 @@ +package keeper + +import ( + "context" + + sdk "github.com/cosmos/cosmos-sdk/types" + "github.com/node101-io/pulsar-chain/x/keyregistry/types" + "google.golang.org/grpc/codes" + "google.golang.org/grpc/status" +) + +// GetMinaPubKey returns the validator's mina public key associated with the given cosmos public key. +// Returns NotFound if no mapping exists for the provided cosmos public key. +func (q queryServer) GetValidatorMinaPubKey(ctx context.Context, req *types.QueryGetValidatorMinaPubKeyRequest) (*types.QueryGetValidatorMinaPubKeyResponse, error) { + if req == nil { + return nil, status.Error(codes.InvalidArgument, "invalid request") + } + + sdkCtx := sdk.UnwrapSDKContext(ctx) + + // Check if the cosmos key exists in the CosmosToMina map. + exists, err := q.k.validatorCosmosToMina.Has(sdkCtx, req.ValidatorCosmosPubKey) + if err != nil { + return nil, status.Error(codes.Internal, "internal Error") + } + + if !exists { + return nil, status.Error(codes.NotFound, "mina key not found for given cosmos key") + } + + minaKey, err := q.k.validatorCosmosToMina.Get(sdkCtx, req.ValidatorCosmosPubKey) + if err != nil { + return nil, status.Error(codes.Internal, err.Error()) + } + + return &types.QueryGetValidatorMinaPubKeyResponse{ + ValidatorMinaPubKey: minaKey, + }, nil +} diff --git a/x/keyregistry/keeper/query_keypairs_test.go b/x/keyregistry/keeper/query_user_keypairs_test.go similarity index 64% rename from x/keyregistry/keeper/query_keypairs_test.go rename to x/keyregistry/keeper/query_user_keypairs_test.go index b29c52cb..d0e24013 100644 --- a/x/keyregistry/keeper/query_keypairs_test.go +++ b/x/keyregistry/keeper/query_user_keypairs_test.go @@ -13,25 +13,25 @@ import ( "google.golang.org/grpc/status" ) -// TestCosmosMapInvalidArgumentFail verifies that GetCosmosPubKey returns +// TestUserCosmosMapInvalidArgumentFail verifies that GetCosmosPubKey returns // an InvalidArgument error when called with a nil request. -func TestCosmosMapInvalidArgumentFail(t *testing.T) { +func TestUserCosmosMapInvalidArgumentFail(t *testing.T) { f := initFixture(t) qs := keeper.NewQueryServerImpl(f.keeper) params := types.DefaultParams() require.NoError(t, f.keeper.Params.Set(f.ctx, params)) - _, err := qs.GetCosmosPubKey(f.ctx, nil) + _, err := qs.GetUserCosmosAddress(f.ctx, nil) require.Error(t, err) st, _ := status.FromError(err) require.Equal(t, codes.InvalidArgument, st.Code()) } -// TestCosmosMapSuccess verifies that a mina public key can be retrieved +// TestUserCosmosMapSuccess verifies that a mina public key can be retrieved // by its associated cosmos public key after being stored in the CosmosToMina map. -func TestCosmosMapSuccess(t *testing.T) { +func TestUserCosmosMapSuccess(t *testing.T) { f := initFixture(t) qs := keeper.NewQueryServerImpl(f.keeper) @@ -48,22 +48,22 @@ func TestCosmosMapSuccess(t *testing.T) { } require.NoError(t, err) - err = f.keeper.SetCosmosToMina(f.ctx, cosmosPubKey.Bytes(), minaPubKey) + err = f.keeper.UserSetCosmosToMina(f.ctx, cosmosPubKey.Bytes(), minaPubKey) require.NoError(t, err) - resp, err := qs.GetMinaPubKey(f.ctx, &types.QueryGetMinaPubKeyRequest{ - CosmosPubKey: cosmosPubKey.Bytes(), + resp, err := qs.GetUserMinaAddress(f.ctx, &types.QueryGetUserMinaAddressRequest{ + UserCosmosAddress: cosmosPubKey.Bytes(), }) require.NotNil(t, resp) require.NoError(t, err) - require.Equal(t, resp.MinaPubKey, []byte(minaPubKey)) + require.Equal(t, resp.UserMinaAddress, []byte(minaPubKey)) } -// TestMinaMapSuccess verifies that a cosmos public key can be retrieved +// TestUserMinaMapSuccess verifies that a cosmos public key can be retrieved // by its associated mina public key after being stored in the MinaToCosmos map. -func TestMinaMapSuccess(t *testing.T) { +func TestUserMinaMapSuccess(t *testing.T) { f := initFixture(t) qs := keeper.NewQueryServerImpl(f.keeper) @@ -80,38 +80,38 @@ func TestMinaMapSuccess(t *testing.T) { } require.NoError(t, err) - err = f.keeper.SetMinaToCosmos(f.ctx, minaPubKey, cosmosPubKey.Bytes()) + err = f.keeper.UserSetMinaToCosmos(f.ctx, minaPubKey, cosmosPubKey.Bytes()) require.NoError(t, err) - resp, err := qs.GetCosmosPubKey(f.ctx, &types.QueryGetCosmosPubKeyRequest{ - MinaPubKey: minaPubKey, + resp, err := qs.GetUserCosmosAddress(f.ctx, &types.QueryGetUserCosmosAddressRequest{ + UserMinaAddress: minaPubKey, }) require.NotNil(t, resp) require.NoError(t, err) - require.Equal(t, resp.CosmosPubKey, cosmosPubKey.Bytes()) + require.Equal(t, resp.UserCosmosAddress, cosmosPubKey.Bytes()) } -// TestMinaMapInvalidArgumentFail verifies that GetMinaPubKey returns +// TestUserMinaMapInvalidArgumentFail verifies that GetMinaPubKey returns // an InvalidArgument error when called with a nil request. -func TestMinaMapInvalidArgumentFail(t *testing.T) { +func TestUserMinaMapInvalidArgumentFail(t *testing.T) { f := initFixture(t) qs := keeper.NewQueryServerImpl(f.keeper) params := types.DefaultParams() require.NoError(t, f.keeper.Params.Set(f.ctx, params)) - _, err := qs.GetMinaPubKey(f.ctx, nil) + _, err := qs.GetUserMinaAddress(f.ctx, nil) require.Error(t, err) st, _ := status.FromError(err) require.Equal(t, codes.InvalidArgument, st.Code()) } -// TestCosmosMapPubkeyNotFound verifies that GetCosmosPubKey returns +// TestUserCosmosMapPubkeyNotFound verifies that GetCosmosPubKey returns // a NotFound error when the provided mina public key has no associated cosmos key. -func TestCosmosMapPubkeyNotFound(t *testing.T) { +func TestUserCosmosMapPubkeyNotFound(t *testing.T) { f := initFixture(t) qs := keeper.NewQueryServerImpl(f.keeper) @@ -123,17 +123,17 @@ func TestCosmosMapPubkeyNotFound(t *testing.T) { panic(err) } - _, err = qs.GetCosmosPubKey(f.ctx, &types.QueryGetCosmosPubKeyRequest{ - MinaPubKey: pub, + _, err = qs.GetUserCosmosAddress(f.ctx, &types.QueryGetUserCosmosAddressRequest{ + UserMinaAddress: pub, }) st, _ := status.FromError(err) require.Equal(t, codes.NotFound, st.Code()) } -// TestMinaMapPubkeyNotFound verifies that GetMinaPubKey returns +// TestUserMinaMapPubkeyNotFound verifies that GetMinaPubKey returns // a NotFound error when the provided cosmos public key has no associated mina key. -func TestMinaMapPubkeyNotFound(t *testing.T) { +func TestUserMinaMapPubkeyNotFound(t *testing.T) { f := initFixture(t) qs := keeper.NewQueryServerImpl(f.keeper) @@ -144,8 +144,8 @@ func TestMinaMapPubkeyNotFound(t *testing.T) { pub := priv.PubKey() - _, err := qs.GetMinaPubKey(f.ctx, &types.QueryGetMinaPubKeyRequest{ - CosmosPubKey: pub.Bytes(), + _, err := qs.GetUserMinaAddress(f.ctx, &types.QueryGetUserMinaAddressRequest{ + UserCosmosAddress: pub.Bytes(), }) st, _ := status.FromError(err) diff --git a/x/keyregistry/keeper/query_validator_keypairs_test.go b/x/keyregistry/keeper/query_validator_keypairs_test.go new file mode 100644 index 00000000..a9e40862 --- /dev/null +++ b/x/keyregistry/keeper/query_validator_keypairs_test.go @@ -0,0 +1,135 @@ +package keeper_test + +import ( + "testing" + + "github.com/node101-io/pulsar-chain/x/keyregistry/keeper" + "github.com/node101-io/pulsar-chain/x/keyregistry/types" + "github.com/stretchr/testify/require" + "google.golang.org/grpc/codes" + "google.golang.org/grpc/status" +) + +// TestValidatorCosmosMapInvalidArgumentFail verifies that GetCosmosPubKey returns +// an InvalidArgument error when called with a nil request. +func TestValidatorCosmosMapInvalidArgumentFail(t *testing.T) { + f := initFixture(t) + + qs := keeper.NewQueryServerImpl(f.keeper) + params := types.DefaultParams() + require.NoError(t, f.keeper.Params.Set(f.ctx, params)) + + _, err := qs.GetValidatorCosmosPubKey(f.ctx, nil) + require.Error(t, err) + + st, _ := status.FromError(err) + require.Equal(t, codes.InvalidArgument, st.Code()) +} + +// TestValidatorCosmosMapSuccess verifies that a mina public key can be retrieved +// by its associated cosmos public key after being stored in the CosmosToMina map. +func TestValidatorCosmosMapSuccess(t *testing.T) { + f := initFixture(t) + + qs := keeper.NewQueryServerImpl(f.keeper) + params := types.DefaultParams() + require.NoError(t, f.keeper.Params.Set(f.ctx, params)) + + cosmosPubKey, minaPubKey, err := generateValidatorPublicKeys() + require.NoError(t, err) + + err = f.keeper.ValidatorSetCosmosToMina(f.ctx, cosmosPubKey.Bytes(), minaPubKey) + require.NoError(t, err) + + resp, err := qs.GetValidatorMinaPubKey(f.ctx, &types.QueryGetValidatorMinaPubKeyRequest{ + ValidatorCosmosPubKey: cosmosPubKey.Bytes(), + }) + + require.NotNil(t, resp) + require.NoError(t, err) + + require.Equal(t, resp.ValidatorMinaPubKey, minaPubKey) +} + +// TestValidatorMinaMapSuccess verifies that a cosmos public key can be retrieved +// by its associated mina public key after being stored in the MinaToCosmos map. +func TestValidatorMinaMapSuccess(t *testing.T) { + f := initFixture(t) + + qs := keeper.NewQueryServerImpl(f.keeper) + params := types.DefaultParams() + require.NoError(t, f.keeper.Params.Set(f.ctx, params)) + + cosmosPubKey, minaPubKey, err := generateValidatorPublicKeys() + require.NoError(t, err) + + err = f.keeper.ValidatorSetMinaToCosmos(f.ctx, minaPubKey, cosmosPubKey.Bytes()) + require.NoError(t, err) + + resp, err := qs.GetValidatorCosmosPubKey(f.ctx, &types.QueryGetValidatorCosmosPubKeyRequest{ + ValidatorMinaPubKey: minaPubKey, + }) + require.NotNil(t, resp) + require.NoError(t, err) + + require.Equal(t, resp.ValidatorCosmosPubKey, cosmosPubKey.Bytes()) +} + +// TestValidatorMinaMapInvalidArgumentFail verifies that GetMinaPubKey returns +// an InvalidArgument error when called with a nil request. +func TestValidatorMinaMapInvalidArgumentFail(t *testing.T) { + f := initFixture(t) + + qs := keeper.NewQueryServerImpl(f.keeper) + params := types.DefaultParams() + require.NoError(t, f.keeper.Params.Set(f.ctx, params)) + + _, err := qs.GetValidatorMinaPubKey(f.ctx, nil) + require.Error(t, err) + + st, _ := status.FromError(err) + require.Equal(t, codes.InvalidArgument, st.Code()) +} + +// TestValidatorCosmosMapPubkeyNotFound verifies that GetCosmosPubKey returns +// a NotFound error when the provided mina public key has no associated cosmos key. +func TestValidatorCosmosMapPubkeyNotFound(t *testing.T) { + f := initFixture(t) + + qs := keeper.NewQueryServerImpl(f.keeper) + params := types.DefaultParams() + require.NoError(t, f.keeper.Params.Set(f.ctx, params)) + + _, minaPubKey, err := generateValidatorPublicKeys() + require.NotNil(t, minaPubKey) + require.NoError(t, err) + + _, err = qs.GetValidatorCosmosPubKey(f.ctx, &types.QueryGetValidatorCosmosPubKeyRequest{ + ValidatorMinaPubKey: minaPubKey, + }) + + st, _ := status.FromError(err) + require.Equal(t, codes.NotFound, st.Code()) +} + +// TestValidatorMinaMapPubkeyNotFound verifies that GetMinaPubKey returns +// a NotFound error when the provided cosmos public key has no associated mina key. +func TestValidatorMinaMapPubkeyNotFound(t *testing.T) { + f := initFixture(t) + + qs := keeper.NewQueryServerImpl(f.keeper) + params := types.DefaultParams() + require.NoError(t, f.keeper.Params.Set(f.ctx, params)) + + cosmosPubKey, minaPubKey, err := generateValidatorPublicKeys() + require.NotNil(t, cosmosPubKey) + require.NotNil(t, minaPubKey) + require.NoError(t, err) + + _, err = qs.GetValidatorMinaPubKey(f.ctx, &types.QueryGetValidatorMinaPubKeyRequest{ + ValidatorCosmosPubKey: CosmosPubKey, + }) + + st, _ := status.FromError(err) + require.Equal(t, codes.NotFound, st.Code()) +} diff --git a/x/keyregistry/keeper/register_keys_test.go b/x/keyregistry/keeper/user_register_keys_test.go similarity index 50% rename from x/keyregistry/keeper/register_keys_test.go rename to x/keyregistry/keeper/user_register_keys_test.go index 3ad930d1..6520b4ab 100644 --- a/x/keyregistry/keeper/register_keys_test.go +++ b/x/keyregistry/keeper/user_register_keys_test.go @@ -5,6 +5,7 @@ import ( "github.com/cometbft/cometbft/crypto/secp256k1" sdk "github.com/cosmos/cosmos-sdk/types" + "github.com/node101-io/mina-signer-go/keys" "github.com/node101-io/pulsar-chain/x/keyregistry/keeper" "github.com/node101-io/pulsar-chain/x/keyregistry/types" "github.com/stretchr/testify/require" @@ -15,9 +16,25 @@ import ( var mockCosmosSignature = "cosmosSig" var mockMinaSignature = "minaSig" -// TestRegisterKeysFail verifies that RegisterKeys fails with ErrInvalidPublicKey +var MinaPriv = []byte("7olA5Knafb5E2hJoWFzD+oamtyXIXXUZmYG9+pBMjTGIjqZTVLNGbE7DQ3Zq5YL5NMW31UMMMGgNCeEk+gyzRA==") + +func generateAddress() (sdk.AccAddress, []byte, error) { + cosmosPrivKey := secp256k1.GenPrivKey() + + cosmosPubKey := cosmosPrivKey.PubKey() + + cosmosAddr := sdk.AccAddress(cosmosPubKey.Address()) + + minaPrivKey := keys.NewPrivateKeyFromBytes([32]byte(MinaPriv)) + + minaAddress, err := minaPrivKey.ToPublicKey().ToAddress() + + return cosmosAddr, []byte(minaAddress), err +} + +// TestUserRegisterKeysFail verifies that RegisterKeys fails with ErrInvalidPublicKey // when the provided cosmos public key is not a valid compressed secp256k1 key (33 bytes). -func TestRegisterKeysFail(t *testing.T) { +func TestUserRegisterKeysFail(t *testing.T) { f := initFixture(t) ms := keeper.NewMsgServerImpl(f.keeper) @@ -27,73 +44,71 @@ func TestRegisterKeysFail(t *testing.T) { Creator: creatorAddr.String(), CosmosSignature: mockCosmosSignature, MinaSignature: mockMinaSignature, - CosmosPublicKey: CosmosPubKey, - MinaPublicKey: MinaPubKey, + CosmosAddress: CosmosPubKey, + MinaAddress: MinaPubKey, + IsUser: true, }) - require.ErrorIs(t, err, types.ErrInvalidPublicKey) + require.ErrorIs(t, err, types.ErrInvalidAddress) } -// TestRegisterKeysSuccess verifies that RegisterKeys succeeds with valid inputs +// TestUserRegisterKeysSuccess verifies that RegisterKeys succeeds with valid inputs // and ensures that both CosmosToMina and MinaToCosmos mappings are correctly stored. -func TestRegisterKeysSuccess(t *testing.T) { - - priv := secp256k1.GenPrivKey() +func TestUserRegisterKeysSuccess(t *testing.T) { - pub := priv.PubKey() - - addr := sdk.AccAddress(pub.Address()) + cosmosAddr, minaAddr, err := generateAddress() + require.NoError(t, err) f := initFixture(t) ms := keeper.NewMsgServerImpl(f.keeper) resp, err := ms.RegisterKeys(f.ctx, &types.MsgRegisterKeys{ - Creator: addr.String(), + Creator: cosmosAddr.String(), CosmosSignature: mockCosmosSignature, MinaSignature: mockMinaSignature, - CosmosPublicKey: pub.Bytes(), - MinaPublicKey: MinaPubKey, + CosmosAddress: cosmosAddr.Bytes(), + MinaAddress: minaAddr, + IsUser: true, }) require.NoError(t, err) require.NotNil(t, resp) - exists, err := f.keeper.CosmosToMinaHas(f.ctx, pub.Bytes()) + exists, err := f.keeper.UserCosmosToMinaHas(f.ctx, cosmosAddr.Bytes()) require.NoError(t, err) require.Equal(t, exists, true) - exists, err = f.keeper.MinaToCosmosHas(f.ctx, MinaPubKey) + exists, err = f.keeper.UserMinaToCosmosHas(f.ctx, minaAddr) require.NoError(t, err) require.Equal(t, exists, true) } -// TestInvalidCreatorAddress verifies that RegisterKeys fails with ErrInvalidCreatorAddres +// TestUserInvalidCreatorAddress verifies that RegisterKeys fails with ErrInvalidCreatorAddres // when the creator field is not a valid bech32 address. -func TestInvalidCreatorAddress(t *testing.T) { - - priv := secp256k1.GenPrivKey() +func TestUserInvalidCreatorAddress(t *testing.T) { - pub := priv.PubKey() + cosmosAddr, minaAddr, err := generateAddress() + require.NoError(t, err) f := initFixture(t) ms := keeper.NewMsgServerImpl(f.keeper) - _, err := ms.RegisterKeys(f.ctx, &types.MsgRegisterKeys{ + _, err = ms.RegisterKeys(f.ctx, &types.MsgRegisterKeys{ Creator: "creator", CosmosSignature: mockCosmosSignature, MinaSignature: mockMinaSignature, - CosmosPublicKey: pub.Bytes(), - MinaPublicKey: MinaPubKey, + CosmosAddress: cosmosAddr.Bytes(), + MinaAddress: minaAddr, + IsUser: true, }) require.ErrorIs(t, err, types.ErrInvalidCreatorAddres) } -// TestInvalidSigner verifies that RegisterKeys fails with ErrInvalidSigner +// TestUserInvalidSigner verifies that RegisterKeys fails with ErrInvalidSigner // when the creator address does not match the address derived from the provided cosmos public key. -func TestInvalidSigner(t *testing.T) { - - priv := secp256k1.GenPrivKey() +func TestUserInvalidSigner(t *testing.T) { - pub := priv.PubKey() + cosmosAddr, minaAddr, err := generateAddress() + require.NoError(t, err) secondaryPriv := secp256k1.GenPrivKey() @@ -104,12 +119,13 @@ func TestInvalidSigner(t *testing.T) { f := initFixture(t) ms := keeper.NewMsgServerImpl(f.keeper) - _, err := ms.RegisterKeys(f.ctx, &types.MsgRegisterKeys{ + _, err = ms.RegisterKeys(f.ctx, &types.MsgRegisterKeys{ Creator: addr.String(), CosmosSignature: mockCosmosSignature, MinaSignature: mockMinaSignature, - CosmosPublicKey: pub.Bytes(), - MinaPublicKey: MinaPubKey, + CosmosAddress: cosmosAddr.Bytes(), + MinaAddress: minaAddr, + IsUser: true, }) require.ErrorIs(t, err, types.ErrInvalidSigner) @@ -117,64 +133,62 @@ func TestInvalidSigner(t *testing.T) { } // TODO: Update require.NoError to require.ErrorIs once the VerifyCosmosSig and VerifyMinaSig is implemented -// TestInvalidSignature currently expects no error since signature verification is not yet implemented. -func TestInvalidSignature(t *testing.T) { +// TestUserInvalidSignature currently expects no error since signature verification is not yet implemented. +func TestUserInvalidSignature(t *testing.T) { - priv := secp256k1.GenPrivKey() + cosmosAddr, minaAddr, err := generateAddress() - pub := priv.PubKey() - - addr := sdk.AccAddress(pub.Address()) + require.NoError(t, err) f := initFixture(t) ms := keeper.NewMsgServerImpl(f.keeper) invalidSig := "cosmosSig" - _, err := ms.RegisterKeys(f.ctx, &types.MsgRegisterKeys{ - Creator: addr.String(), + _, err = ms.RegisterKeys(f.ctx, &types.MsgRegisterKeys{ + Creator: cosmosAddr.String(), CosmosSignature: invalidSig, MinaSignature: mockMinaSignature, - CosmosPublicKey: pub.Bytes(), - MinaPublicKey: MinaPubKey, + CosmosAddress: cosmosAddr.Bytes(), + MinaAddress: minaAddr, + IsUser: true, }) require.NoError(t, err) } -// TestInsertSecondaryKeysFail verifies that registering the same key pair twice +// TestUserInsertSecondaryKeysFail verifies that registering the same key pair twice // fails with ErrSecondaryKeyExists on the second attempt. -func TestInsertSecondaryKeysFail(t *testing.T) { +func TestUserInsertSecondaryKeysFail(t *testing.T) { f := initFixture(t) - priv := secp256k1.GenPrivKey() - - pub := priv.PubKey() - - addr := sdk.AccAddress(pub.Address()) + cosmosAddr, minaAddr, err := generateAddress() + require.NoError(t, err) ms := keeper.NewMsgServerImpl(f.keeper) // First registration should succeed. resp, err := ms.RegisterKeys(f.ctx, &types.MsgRegisterKeys{ - Creator: addr.String(), + Creator: cosmosAddr.String(), CosmosSignature: mockCosmosSignature, MinaSignature: mockMinaSignature, - CosmosPublicKey: pub.Bytes(), - MinaPublicKey: MinaPubKey, + CosmosAddress: cosmosAddr.Bytes(), + MinaAddress: minaAddr, + IsUser: true, }) require.NoError(t, err) require.NotNil(t, resp) // Second registration with the same keys should fail. resp, err = ms.RegisterKeys(f.ctx, &types.MsgRegisterKeys{ - Creator: addr.String(), + Creator: cosmosAddr.String(), CosmosSignature: mockCosmosSignature, MinaSignature: mockMinaSignature, - CosmosPublicKey: pub.Bytes(), - MinaPublicKey: MinaPubKey, + CosmosAddress: cosmosAddr.Bytes(), + MinaAddress: minaAddr, + IsUser: true, }) - require.ErrorIs(t, err, types.ErrSecondaryKeyExists) + require.ErrorIs(t, err, types.ErrUserSecondaryKeyExists) } diff --git a/x/keyregistry/keeper/validator_register_keys_test.go b/x/keyregistry/keeper/validator_register_keys_test.go new file mode 100644 index 00000000..7139e68e --- /dev/null +++ b/x/keyregistry/keeper/validator_register_keys_test.go @@ -0,0 +1,189 @@ +package keeper_test + +import ( + "testing" + + "github.com/cosmos/cosmos-sdk/crypto/keys/ed25519" + cryptotypes "github.com/cosmos/cosmos-sdk/crypto/types" + sdk "github.com/cosmos/cosmos-sdk/types" + "github.com/node101-io/mina-signer-go/keys" + "github.com/node101-io/pulsar-chain/x/keyregistry/keeper" + "github.com/node101-io/pulsar-chain/x/keyregistry/types" + "github.com/stretchr/testify/require" +) + +func generateValidatorPublicKeys() (cryptotypes.PubKey, []byte, error) { + cosmosPrivKey := ed25519.GenPrivKey() + + cosmosPubKey := cosmosPrivKey.PubKey() + + minaPrivKey := keys.NewPrivateKeyFromBytes([32]byte(MinaPriv)) + + minaAddress, err := minaPrivKey.ToPublicKey().Marshal() + + return cosmosPubKey, minaAddress, err +} + +// TestValidatorRegisterKeysFail verifies that RegisterKeys fails with ErrInvalidPublicKey +// when the provided cosmos consensus public key is invalid. +func TestValidatorRegisterKeysFail(t *testing.T) { + + f := initFixture(t) + ms := keeper.NewMsgServerImpl(f.keeper) + + creatorAddr := sdk.ConsAddress([]byte("pulsar")) + _, err := ms.RegisterKeys(f.ctx, &types.MsgRegisterKeys{ + Creator: creatorAddr.String(), + CosmosSignature: mockCosmosSignature, + MinaSignature: mockMinaSignature, + CosmosAddress: CosmosPubKey, + MinaAddress: MinaPubKey, + IsUser: false, + }) + require.ErrorIs(t, err, types.ErrInvalidPublicKey) +} + +// TestValidatorRegisterKeysSuccess verifies that RegisterKeys succeeds with valid inputs +// and ensures that both CosmosToMina and MinaToCosmos mappings are correctly stored. +func TestValidatorRegisterKeysSuccess(t *testing.T) { + + cosmosPubKey, minaPubKey, err := generateValidatorPublicKeys() + require.NoError(t, err) + + addr := sdk.ConsAddress(cosmosPubKey.Address()) + + f := initFixture(t) + ms := keeper.NewMsgServerImpl(f.keeper) + + resp, err := ms.RegisterKeys(f.ctx, &types.MsgRegisterKeys{ + Creator: addr.String(), + CosmosSignature: mockCosmosSignature, + MinaSignature: mockMinaSignature, + CosmosAddress: cosmosPubKey.Bytes(), + MinaAddress: minaPubKey, + IsUser: false, + }) + require.NoError(t, err) + require.NotNil(t, resp) + + exists, err := f.keeper.ValidatorCosmosToMinaHas(f.ctx, cosmosPubKey.Bytes()) + require.NoError(t, err) + require.Equal(t, exists, true) + + exists, err = f.keeper.ValidatorMinaToCosmosHas(f.ctx, minaPubKey) + require.NoError(t, err) + require.Equal(t, exists, true) +} + +// TestValidatorInvalidCreatorAddress verifies that RegisterKeys fails with ErrInvalidCreatorAddres +// when the creator field is not a valid bech32 address. +func TestValidatorInvalidCreatorAddress(t *testing.T) { + + cosmosPubKey, minaPubKey, err := generateValidatorPublicKeys() + require.NoError(t, err) + + f := initFixture(t) + ms := keeper.NewMsgServerImpl(f.keeper) + + _, err = ms.RegisterKeys(f.ctx, &types.MsgRegisterKeys{ + Creator: "creator", + CosmosSignature: mockCosmosSignature, + MinaSignature: mockMinaSignature, + CosmosAddress: cosmosPubKey.Bytes(), + MinaAddress: minaPubKey, + IsUser: false, + }) + require.ErrorIs(t, err, types.ErrInvalidCreatorAddres) +} + +// TestValidatorInvalidSigner verifies that RegisterKeys fails with ErrInvalidSigner +// when the creator address does not match the address derived from the provided consensus public key. +func TestValidatorInvalidSigner(t *testing.T) { + + cosmosPubKey, minaPubKey, err := generateValidatorPublicKeys() + require.NoError(t, err) + + secondaryPriv := ed25519.GenPrivKey() + + secondaryPublic := secondaryPriv.PubKey() + + addr := sdk.ConsAddress(secondaryPublic.Address()) + + f := initFixture(t) + ms := keeper.NewMsgServerImpl(f.keeper) + + _, err = ms.RegisterKeys(f.ctx, &types.MsgRegisterKeys{ + Creator: addr.String(), + CosmosSignature: mockCosmosSignature, + MinaSignature: mockMinaSignature, + CosmosAddress: cosmosPubKey.Bytes(), + MinaAddress: minaPubKey, + IsUser: false, + }) + + require.ErrorIs(t, err, types.ErrInvalidSigner) +} + +// TODO: Update require.NoError to require.ErrorIs once the VerifyCosmosSig and VerifyMinaSig is implemented +// TestValidatorInvalidSignature currently expects no error since signature verification is not yet implemented. +func TestValidatorInvalidSignature(t *testing.T) { + + cosmosPubKey, minaPubKey, err := generateValidatorPublicKeys() + addr := sdk.ConsAddress(cosmosPubKey.Address()) + + require.NoError(t, err) + + f := initFixture(t) + ms := keeper.NewMsgServerImpl(f.keeper) + + invalidSig := "cosmosSig" + + _, err = ms.RegisterKeys(f.ctx, &types.MsgRegisterKeys{ + Creator: addr.String(), + CosmosSignature: invalidSig, + MinaSignature: mockMinaSignature, + CosmosAddress: cosmosPubKey.Bytes(), + MinaAddress: minaPubKey, + IsUser: false, + }) + + require.NoError(t, err) + +} + +// TestValidatorInsertSecondaryKeysFail verifies that registering the same key pair twice +// fails with ErrSecondaryKeyExists on the second attempt. +func TestValidatorInsertSecondaryKeysFail(t *testing.T) { + f := initFixture(t) + + cosmosPubKey, minaPubKey, err := generateValidatorPublicKeys() + require.NoError(t, err) + + addr := sdk.ConsAddress(cosmosPubKey.Address()) + + ms := keeper.NewMsgServerImpl(f.keeper) + + // First registration should succeed. + resp, err := ms.RegisterKeys(f.ctx, &types.MsgRegisterKeys{ + Creator: addr.String(), + CosmosSignature: mockCosmosSignature, + MinaSignature: mockMinaSignature, + CosmosAddress: cosmosPubKey.Bytes(), + MinaAddress: minaPubKey, + IsUser: false, + }) + require.NoError(t, err) + require.NotNil(t, resp) + + // Second registration with the same keys should fail. + resp, err = ms.RegisterKeys(f.ctx, &types.MsgRegisterKeys{ + Creator: addr.String(), + CosmosSignature: mockCosmosSignature, + MinaSignature: mockMinaSignature, + CosmosAddress: cosmosPubKey.Bytes(), + MinaAddress: minaPubKey, + IsUser: false, + }) + + require.ErrorIs(t, err, types.ErrValidatorSecondaryKeyExists) +} diff --git a/x/keyregistry/module/autocli.go b/x/keyregistry/module/autocli.go index 70bfd25b..206950c9 100644 --- a/x/keyregistry/module/autocli.go +++ b/x/keyregistry/module/autocli.go @@ -18,17 +18,31 @@ func (am AppModule) AutoCLIOptions() *autocliv1.ModuleOptions { Short: "Shows the parameters of the module", }, { - RpcMethod: "GetMinaPubKey", - Use: "get-mina-pub-key [cosmos-pub-key]", - Short: "Query GetMinaPubKey", - PositionalArgs: []*autocliv1.PositionalArgDescriptor{{ProtoField: "cosmos_pub_key", Varargs: true}}, + RpcMethod: "GetUserMinaAddress", + Use: "get-user-mina-address [user-cosmos-address]", + Short: "Query GetUserMinaAddress", + PositionalArgs: []*autocliv1.PositionalArgDescriptor{{ProtoField: "user_cosmos_address", Varargs: true}}, }, { - RpcMethod: "GetCosmosPubKey", - Use: "get-cosmos-pub-key [mina-pub-key]", - Short: "Query GetCosmosPubKey", - PositionalArgs: []*autocliv1.PositionalArgDescriptor{{ProtoField: "mina_pub_key", Varargs: true}}, + RpcMethod: "GetUserCosmosAddress", + Use: "get-user-cosmos-address [user-mina-address]", + Short: "Query GetUserCosmosAddress", + PositionalArgs: []*autocliv1.PositionalArgDescriptor{{ProtoField: "user_mina_address", Varargs: true}}, + }, + + { + RpcMethod: "GetValidatorMinaPubKey", + Use: "get-validator-mina-pub-key [validator-cosmos-address]", + Short: "Query GetValidatorMinaAddress", + PositionalArgs: []*autocliv1.PositionalArgDescriptor{{ProtoField: "validator_cosmos_pub_key", Varargs: true}}, + }, + + { + RpcMethod: "GetValidatorCosmosPubKey", + Use: "get-validator-cosmos-address [validator-mina-pub-key]", + Short: "Query GetValidatorCosmosAddress", + PositionalArgs: []*autocliv1.PositionalArgDescriptor{{ProtoField: "validator_mina_pub_key", Varargs: true}}, }, // this line is used by ignite scaffolding # autocli/query @@ -46,7 +60,7 @@ func (am AppModule) AutoCLIOptions() *autocliv1.ModuleOptions { RpcMethod: "RegisterKeys", Use: "register-keys [cosmos-signature] [mina-signature] [cosmos-public-key] [mina-public-key]", Short: "Send a registerKeys tx", - PositionalArgs: []*autocliv1.PositionalArgDescriptor{{ProtoField: "cosmos_signature"}, {ProtoField: "mina_signature"}, {ProtoField: "cosmos_public_key"}, {ProtoField: "mina_public_key", Varargs: true}}, + PositionalArgs: []*autocliv1.PositionalArgDescriptor{{ProtoField: "cosmos_signature"}, {ProtoField: "mina_signature"}, {ProtoField: "cosmos_address"}, {ProtoField: "mina_address", Varargs: true}}, }, // this line is used by ignite scaffolding # autocli/tx }, diff --git a/x/keyregistry/types/address_pair.pb.go b/x/keyregistry/types/address_pair.pb.go new file mode 100644 index 00000000..3f5b82ab --- /dev/null +++ b/x/keyregistry/types/address_pair.pb.go @@ -0,0 +1,374 @@ +// Code generated by protoc-gen-gogo. DO NOT EDIT. +// source: pulsarchain/keyregistry/v1/address_pair.proto + +package types + +import ( + fmt "fmt" + proto "github.com/cosmos/gogoproto/proto" + io "io" + math "math" + math_bits "math/bits" +) + +// Reference imports to suppress errors if they are not otherwise used. +var _ = proto.Marshal +var _ = fmt.Errorf +var _ = math.Inf + +// This is a compile-time assertion to ensure that this generated file +// is compatible with the proto package it is being compiled against. +// A compilation error at this line likely means your copy of the +// proto package needs to be updated. +const _ = proto.GoGoProtoPackageIsVersion3 // please upgrade the proto package + +type AddressPair struct { + MinaAddr []byte `protobuf:"bytes,1,opt,name=mina_addr,json=minaAddr,proto3" json:"mina_addr,omitempty"` + CosmosAddr []byte `protobuf:"bytes,2,opt,name=cosmos_addr,json=cosmosAddr,proto3" json:"cosmos_addr,omitempty"` +} + +func (m *AddressPair) Reset() { *m = AddressPair{} } +func (m *AddressPair) String() string { return proto.CompactTextString(m) } +func (*AddressPair) ProtoMessage() {} +func (*AddressPair) Descriptor() ([]byte, []int) { + return fileDescriptor_eb9cea5d1b988cd3, []int{0} +} +func (m *AddressPair) XXX_Unmarshal(b []byte) error { + return m.Unmarshal(b) +} +func (m *AddressPair) XXX_Marshal(b []byte, deterministic bool) ([]byte, error) { + if deterministic { + return xxx_messageInfo_AddressPair.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 *AddressPair) XXX_Merge(src proto.Message) { + xxx_messageInfo_AddressPair.Merge(m, src) +} +func (m *AddressPair) XXX_Size() int { + return m.Size() +} +func (m *AddressPair) XXX_DiscardUnknown() { + xxx_messageInfo_AddressPair.DiscardUnknown(m) +} + +var xxx_messageInfo_AddressPair proto.InternalMessageInfo + +func (m *AddressPair) GetMinaAddr() []byte { + if m != nil { + return m.MinaAddr + } + return nil +} + +func (m *AddressPair) GetCosmosAddr() []byte { + if m != nil { + return m.CosmosAddr + } + return nil +} + +func init() { + proto.RegisterType((*AddressPair)(nil), "pulsarchain.keyregistry.v1.AddressPair") +} + +func init() { + proto.RegisterFile("pulsarchain/keyregistry/v1/address_pair.proto", fileDescriptor_eb9cea5d1b988cd3) +} + +var fileDescriptor_eb9cea5d1b988cd3 = []byte{ + // 206 bytes of a gzipped FileDescriptorProto + 0x1f, 0x8b, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0xff, 0xe2, 0xd2, 0x2d, 0x28, 0xcd, 0x29, + 0x4e, 0x2c, 0x4a, 0xce, 0x48, 0xcc, 0xcc, 0xd3, 0xcf, 0x4e, 0xad, 0x2c, 0x4a, 0x4d, 0xcf, 0x2c, + 0x2e, 0x29, 0xaa, 0xd4, 0x2f, 0x33, 0xd4, 0x4f, 0x4c, 0x49, 0x29, 0x4a, 0x2d, 0x2e, 0x8e, 0x2f, + 0x48, 0xcc, 0x2c, 0xd2, 0x2b, 0x28, 0xca, 0x2f, 0xc9, 0x17, 0x92, 0x42, 0x52, 0xae, 0x87, 0xa4, + 0x5c, 0xaf, 0xcc, 0x50, 0xc9, 0x9b, 0x8b, 0xdb, 0x11, 0xa2, 0x23, 0x20, 0x31, 0xb3, 0x48, 0x48, + 0x9a, 0x8b, 0x33, 0x37, 0x33, 0x2f, 0x31, 0x1e, 0x64, 0x8a, 0x04, 0xa3, 0x02, 0xa3, 0x06, 0x4f, + 0x10, 0x07, 0x48, 0x00, 0xa4, 0x46, 0x48, 0x9e, 0x8b, 0x3b, 0x39, 0xbf, 0x38, 0x37, 0xbf, 0x18, + 0x22, 0xcd, 0x04, 0x96, 0xe6, 0x82, 0x08, 0x81, 0x14, 0x38, 0x05, 0x9c, 0x78, 0x24, 0xc7, 0x78, + 0xe1, 0x91, 0x1c, 0xe3, 0x83, 0x47, 0x72, 0x8c, 0x13, 0x1e, 0xcb, 0x31, 0x5c, 0x78, 0x2c, 0xc7, + 0x70, 0xe3, 0xb1, 0x1c, 0x43, 0x94, 0x59, 0x7a, 0x66, 0x49, 0x46, 0x69, 0x92, 0x5e, 0x72, 0x7e, + 0xae, 0x7e, 0x5e, 0x7e, 0x4a, 0xaa, 0xa1, 0x81, 0xa1, 0x6e, 0x66, 0xbe, 0x3e, 0xc4, 0x61, 0xba, + 0x10, 0x8f, 0x54, 0xa0, 0x78, 0xa5, 0xa4, 0xb2, 0x20, 0xb5, 0x38, 0x89, 0x0d, 0xec, 0x03, 0x63, + 0x40, 0x00, 0x00, 0x00, 0xff, 0xff, 0x32, 0x26, 0x7c, 0xb2, 0xf2, 0x00, 0x00, 0x00, +} + +func (m *AddressPair) 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 *AddressPair) MarshalTo(dAtA []byte) (int, error) { + size := m.Size() + return m.MarshalToSizedBuffer(dAtA[:size]) +} + +func (m *AddressPair) MarshalToSizedBuffer(dAtA []byte) (int, error) { + i := len(dAtA) + _ = i + var l int + _ = l + if len(m.CosmosAddr) > 0 { + i -= len(m.CosmosAddr) + copy(dAtA[i:], m.CosmosAddr) + i = encodeVarintAddressPair(dAtA, i, uint64(len(m.CosmosAddr))) + i-- + dAtA[i] = 0x12 + } + if len(m.MinaAddr) > 0 { + i -= len(m.MinaAddr) + copy(dAtA[i:], m.MinaAddr) + i = encodeVarintAddressPair(dAtA, i, uint64(len(m.MinaAddr))) + i-- + dAtA[i] = 0xa + } + return len(dAtA) - i, nil +} + +func encodeVarintAddressPair(dAtA []byte, offset int, v uint64) int { + offset -= sovAddressPair(v) + base := offset + for v >= 1<<7 { + dAtA[offset] = uint8(v&0x7f | 0x80) + v >>= 7 + offset++ + } + dAtA[offset] = uint8(v) + return base +} +func (m *AddressPair) Size() (n int) { + if m == nil { + return 0 + } + var l int + _ = l + l = len(m.MinaAddr) + if l > 0 { + n += 1 + l + sovAddressPair(uint64(l)) + } + l = len(m.CosmosAddr) + if l > 0 { + n += 1 + l + sovAddressPair(uint64(l)) + } + return n +} + +func sovAddressPair(x uint64) (n int) { + return (math_bits.Len64(x|1) + 6) / 7 +} +func sozAddressPair(x uint64) (n int) { + return sovAddressPair(uint64((x << 1) ^ uint64((int64(x) >> 63)))) +} +func (m *AddressPair) 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 ErrIntOverflowAddressPair + } + 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: AddressPair: wiretype end group for non-group") + } + if fieldNum <= 0 { + return fmt.Errorf("proto: AddressPair: illegal tag %d (wire type %d)", fieldNum, wire) + } + switch fieldNum { + case 1: + if wireType != 2 { + return fmt.Errorf("proto: wrong wireType = %d for field MinaAddr", wireType) + } + var byteLen int + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowAddressPair + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + byteLen |= int(b&0x7F) << shift + if b < 0x80 { + break + } + } + if byteLen < 0 { + return ErrInvalidLengthAddressPair + } + postIndex := iNdEx + byteLen + if postIndex < 0 { + return ErrInvalidLengthAddressPair + } + if postIndex > l { + return io.ErrUnexpectedEOF + } + m.MinaAddr = append(m.MinaAddr[:0], dAtA[iNdEx:postIndex]...) + if m.MinaAddr == nil { + m.MinaAddr = []byte{} + } + iNdEx = postIndex + case 2: + if wireType != 2 { + return fmt.Errorf("proto: wrong wireType = %d for field CosmosAddr", wireType) + } + var byteLen int + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowAddressPair + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + byteLen |= int(b&0x7F) << shift + if b < 0x80 { + break + } + } + if byteLen < 0 { + return ErrInvalidLengthAddressPair + } + postIndex := iNdEx + byteLen + if postIndex < 0 { + return ErrInvalidLengthAddressPair + } + if postIndex > l { + return io.ErrUnexpectedEOF + } + m.CosmosAddr = append(m.CosmosAddr[:0], dAtA[iNdEx:postIndex]...) + if m.CosmosAddr == nil { + m.CosmosAddr = []byte{} + } + iNdEx = postIndex + default: + iNdEx = preIndex + skippy, err := skipAddressPair(dAtA[iNdEx:]) + if err != nil { + return err + } + if (skippy < 0) || (iNdEx+skippy) < 0 { + return ErrInvalidLengthAddressPair + } + if (iNdEx + skippy) > l { + return io.ErrUnexpectedEOF + } + iNdEx += skippy + } + } + + if iNdEx > l { + return io.ErrUnexpectedEOF + } + return nil +} +func skipAddressPair(dAtA []byte) (n int, err error) { + l := len(dAtA) + iNdEx := 0 + depth := 0 + for iNdEx < l { + var wire uint64 + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return 0, ErrIntOverflowAddressPair + } + if iNdEx >= l { + return 0, io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + wire |= (uint64(b) & 0x7F) << shift + if b < 0x80 { + break + } + } + wireType := int(wire & 0x7) + switch wireType { + case 0: + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return 0, ErrIntOverflowAddressPair + } + if iNdEx >= l { + return 0, io.ErrUnexpectedEOF + } + iNdEx++ + if dAtA[iNdEx-1] < 0x80 { + break + } + } + case 1: + iNdEx += 8 + case 2: + var length int + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return 0, ErrIntOverflowAddressPair + } + if iNdEx >= l { + return 0, io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + length |= (int(b) & 0x7F) << shift + if b < 0x80 { + break + } + } + if length < 0 { + return 0, ErrInvalidLengthAddressPair + } + iNdEx += length + case 3: + depth++ + case 4: + if depth == 0 { + return 0, ErrUnexpectedEndOfGroupAddressPair + } + depth-- + case 5: + iNdEx += 4 + default: + return 0, fmt.Errorf("proto: illegal wireType %d", wireType) + } + if iNdEx < 0 { + return 0, ErrInvalidLengthAddressPair + } + if depth == 0 { + return iNdEx, nil + } + } + return 0, io.ErrUnexpectedEOF +} + +var ( + ErrInvalidLengthAddressPair = fmt.Errorf("proto: negative length found during unmarshaling") + ErrIntOverflowAddressPair = fmt.Errorf("proto: integer overflow") + ErrUnexpectedEndOfGroupAddressPair = fmt.Errorf("proto: unexpected end of group") +) diff --git a/x/keyregistry/types/address_pairs.go b/x/keyregistry/types/address_pairs.go new file mode 100644 index 00000000..9d2edca8 --- /dev/null +++ b/x/keyregistry/types/address_pairs.go @@ -0,0 +1,35 @@ +package types + +import ( + "cosmossdk.io/errors" +) + +const CosmosAddrLen = 20 +const MinaAddrLen = 45 + +func NewAddressPairs() []*AddressPair { + return []*AddressPair{} +} +func DefaultUserAddressPairs() []*AddressPair { + return NewAddressPairs() +} + +func DefaultValidatorKeyPairs() []*AddressPair { + return NewAddressPairs() +} + +func ValidateAddressPair(k AddressPair) error { + if len(k.CosmosAddr) != CosmosAddrLen { + return errors.Wrap(ErrInvalidAddress, "cosmos address must be valid (20 bytes)") + } + + if len(k.MinaAddr) != MinaAddrLen { + return errors.Wrap(ErrInvalidAddress, "mina address must be valid") + } + return nil +} + +// Validate validates the set of params. +func (k AddressPair) Validate() error { + return ValidateAddressPair(k) +} diff --git a/x/keyregistry/types/errors.go b/x/keyregistry/types/errors.go index 202d20f0..8a8fd513 100644 --- a/x/keyregistry/types/errors.go +++ b/x/keyregistry/types/errors.go @@ -8,9 +8,11 @@ import ( // x/keyregistry module sentinel errors var ( - ErrInvalidSigner = errors.Register(ModuleName, 1100, "expected gov account as only signer for proposal message") - ErrInvalidSignature = errors.Register(ModuleName, 1101, "invalid signature") - ErrSecondaryKeyExists = errors.Register(ModuleName, 1102, "secondary key already exists") - ErrInvalidCreatorAddres = errors.Register(ModuleName, 1103, "invalid creator address") - ErrInvalidPublicKey = errors.Register(ModuleName, 1104, "invalid public key") + ErrInvalidSigner = errors.Register(ModuleName, 1100, "expected gov account as only signer for proposal message") + ErrInvalidSignature = errors.Register(ModuleName, 1101, "invalid signature") + ErrUserSecondaryKeyExists = errors.Register(ModuleName, 1102, "user's secondary key already exists") + ErrValidatorSecondaryKeyExists = errors.Register(ModuleName, 1103, "validator's secondary key already exists") + ErrInvalidCreatorAddres = errors.Register(ModuleName, 1104, "invalid creator address") + ErrInvalidPublicKey = errors.Register(ModuleName, 1105, "invalid public key") + ErrInvalidAddress = errors.Register(ModuleName, 1106, "invalid address") ) diff --git a/x/keyregistry/types/genesis.go b/x/keyregistry/types/genesis.go index b2e8fb0f..4cda9d3d 100644 --- a/x/keyregistry/types/genesis.go +++ b/x/keyregistry/types/genesis.go @@ -3,8 +3,9 @@ package types // DefaultGenesis returns the default genesis state func DefaultGenesis() *GenesisState { return &GenesisState{ - Params: DefaultParams(), - KeyPairs: DefaultKeyPairs(), + Params: DefaultParams(), + UserKeyPairs: DefaultUserAddressPairs(), + ValidatorKeyPairs: DefaultPublicKeyPair(), } } @@ -12,8 +13,15 @@ func DefaultGenesis() *GenesisState { // failure. func (gs GenesisState) Validate() error { - for _, keyPair := range gs.KeyPairs { - err := ValidateKeyPair(*keyPair) + for _, keyPair := range gs.UserKeyPairs { + err := ValidateAddressPair(*keyPair) + if err != nil { + return err + } + } + + for _, keyPair := range gs.ValidatorKeyPairs { + err := ValidatePublicKeyPair(*keyPair) if err != nil { return err } diff --git a/x/keyregistry/types/genesis.pb.go b/x/keyregistry/types/genesis.pb.go index 86964336..10beefbe 100644 --- a/x/keyregistry/types/genesis.pb.go +++ b/x/keyregistry/types/genesis.pb.go @@ -27,8 +27,9 @@ const _ = proto.GoGoProtoPackageIsVersion3 // please upgrade the proto package // GenesisState defines the keyregistry module's genesis state. type GenesisState struct { // params defines all the parameters of the module. - Params Params `protobuf:"bytes,1,opt,name=params,proto3" json:"params"` - KeyPairs []*KeyPair `protobuf:"bytes,2,rep,name=key_pairs,json=keyPairs,proto3" json:"key_pairs,omitempty"` + Params Params `protobuf:"bytes,1,opt,name=params,proto3" json:"params"` + UserKeyPairs []*AddressPair `protobuf:"bytes,2,rep,name=user_key_pairs,json=userKeyPairs,proto3" json:"user_key_pairs,omitempty"` + ValidatorKeyPairs []*PublicKeyPair `protobuf:"bytes,3,rep,name=validator_key_pairs,json=validatorKeyPairs,proto3" json:"validator_key_pairs,omitempty"` } func (m *GenesisState) Reset() { *m = GenesisState{} } @@ -71,9 +72,16 @@ func (m *GenesisState) GetParams() Params { return Params{} } -func (m *GenesisState) GetKeyPairs() []*KeyPair { +func (m *GenesisState) GetUserKeyPairs() []*AddressPair { if m != nil { - return m.KeyPairs + return m.UserKeyPairs + } + return nil +} + +func (m *GenesisState) GetValidatorKeyPairs() []*PublicKeyPair { + if m != nil { + return m.ValidatorKeyPairs } return nil } @@ -87,25 +95,28 @@ func init() { } var fileDescriptor_dbaeb2ea35536f14 = []byte{ - // 275 bytes of a gzipped FileDescriptorProto + // 334 bytes of a gzipped FileDescriptorProto 0x1f, 0x8b, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0xff, 0xe2, 0xd2, 0x28, 0x28, 0xcd, 0x29, 0x4e, 0x2c, 0x4a, 0xce, 0x48, 0xcc, 0xcc, 0xd3, 0xcf, 0x4e, 0xad, 0x2c, 0x4a, 0x4d, 0xcf, 0x2c, 0x2e, 0x29, 0xaa, 0xd4, 0x2f, 0x33, 0xd4, 0x4f, 0x4f, 0xcd, 0x4b, 0x2d, 0xce, 0x2c, 0xd6, 0x2b, 0x28, 0xca, 0x2f, 0xc9, 0x17, 0x92, 0x42, 0x52, 0xa9, 0x87, 0xa4, 0x52, 0xaf, 0xcc, 0x50, 0x4a, 0x30, 0x31, 0x37, 0x33, 0x2f, 0x5f, 0x1f, 0x4c, 0x42, 0x94, 0x4b, 0x89, 0xa4, 0xe7, 0xa7, 0xe7, - 0x83, 0x99, 0xfa, 0x20, 0x16, 0x54, 0x54, 0x1d, 0x8f, 0x75, 0x05, 0x89, 0x45, 0x89, 0xb9, 0x50, - 0xdb, 0xa4, 0x34, 0xf1, 0x28, 0xcc, 0x4e, 0xad, 0x8c, 0x2f, 0x48, 0xcc, 0x2c, 0x82, 0x28, 0x55, - 0x9a, 0xce, 0xc8, 0xc5, 0xe3, 0x0e, 0x71, 0x6a, 0x70, 0x49, 0x62, 0x49, 0xaa, 0x90, 0x2b, 0x17, - 0x1b, 0xc4, 0x2c, 0x09, 0x46, 0x05, 0x46, 0x0d, 0x6e, 0x23, 0x25, 0x3d, 0xdc, 0x4e, 0xd7, 0x0b, - 0x00, 0xab, 0x74, 0xe2, 0x3c, 0x71, 0x4f, 0x9e, 0x61, 0xc5, 0xf3, 0x0d, 0x5a, 0x8c, 0x41, 0x50, - 0xcd, 0x42, 0x0e, 0x5c, 0x9c, 0x30, 0x9b, 0x8a, 0x25, 0x98, 0x14, 0x98, 0x35, 0xb8, 0x8d, 0x94, - 0xf1, 0x99, 0xe4, 0x9d, 0x5a, 0x19, 0x90, 0x98, 0x59, 0x14, 0xc4, 0x91, 0x0d, 0x61, 0x14, 0x3b, - 0x05, 0x9c, 0x78, 0x24, 0xc7, 0x78, 0xe1, 0x91, 0x1c, 0xe3, 0x83, 0x47, 0x72, 0x8c, 0x13, 0x1e, - 0xcb, 0x31, 0x5c, 0x78, 0x2c, 0xc7, 0x70, 0xe3, 0xb1, 0x1c, 0x43, 0x94, 0x59, 0x7a, 0x66, 0x49, - 0x46, 0x69, 0x92, 0x5e, 0x72, 0x7e, 0xae, 0x7e, 0x5e, 0x7e, 0x4a, 0xaa, 0xa1, 0x81, 0xa1, 0x6e, - 0x66, 0xbe, 0x3e, 0xc4, 0x74, 0x5d, 0x88, 0xaf, 0x2b, 0x50, 0xfc, 0x5d, 0x52, 0x59, 0x90, 0x5a, - 0x9c, 0xc4, 0x06, 0xf6, 0xb2, 0x31, 0x20, 0x00, 0x00, 0xff, 0xff, 0xa5, 0xaa, 0xf8, 0xf1, 0xb7, - 0x01, 0x00, 0x00, + 0x83, 0x99, 0xfa, 0x20, 0x16, 0x54, 0x54, 0x17, 0x8f, 0x75, 0x89, 0x29, 0x29, 0x45, 0xa9, 0xc5, + 0xc5, 0xf1, 0x05, 0x89, 0x99, 0x45, 0x50, 0xe5, 0xea, 0x78, 0x94, 0x17, 0x24, 0x16, 0x25, 0xe6, + 0x42, 0x1d, 0x27, 0x65, 0x80, 0x4f, 0x61, 0x69, 0x52, 0x4e, 0x66, 0x72, 0x7c, 0x76, 0x6a, 0x25, + 0x92, 0xd1, 0x4a, 0xff, 0x19, 0xb9, 0x78, 0xdc, 0x21, 0x1e, 0x0c, 0x2e, 0x49, 0x2c, 0x49, 0x15, + 0x72, 0xe5, 0x62, 0x83, 0x18, 0x29, 0xc1, 0xa8, 0xc0, 0xa8, 0xc1, 0x6d, 0xa4, 0xa4, 0x87, 0xdb, + 0xc3, 0x7a, 0x01, 0x60, 0x95, 0x4e, 0x9c, 0x27, 0xee, 0xc9, 0x33, 0xac, 0x78, 0xbe, 0x41, 0x8b, + 0x31, 0x08, 0xaa, 0x59, 0xc8, 0x97, 0x8b, 0xaf, 0xb4, 0x38, 0xb5, 0x08, 0x6e, 0x5d, 0xb1, 0x04, + 0x93, 0x02, 0xb3, 0x06, 0xb7, 0x91, 0x3a, 0x3e, 0xe3, 0x1c, 0x21, 0x5e, 0x0f, 0x48, 0xcc, 0x2c, + 0x0a, 0xe2, 0x01, 0x69, 0xf7, 0x4e, 0xad, 0x04, 0x71, 0x8a, 0x85, 0x22, 0xb9, 0x84, 0xcb, 0x12, + 0x73, 0x32, 0x53, 0x12, 0x4b, 0xf2, 0x91, 0xcd, 0x64, 0x06, 0x9b, 0xa9, 0x89, 0xd7, 0x89, 0x60, + 0x6f, 0x43, 0x0d, 0x0a, 0x12, 0x84, 0x9b, 0x02, 0x33, 0xda, 0x29, 0xe0, 0xc4, 0x23, 0x39, 0xc6, + 0x0b, 0x8f, 0xe4, 0x18, 0x1f, 0x3c, 0x92, 0x63, 0x9c, 0xf0, 0x58, 0x8e, 0xe1, 0xc2, 0x63, 0x39, + 0x86, 0x1b, 0x8f, 0xe5, 0x18, 0xa2, 0xcc, 0xd2, 0x33, 0x4b, 0x32, 0x4a, 0x93, 0xf4, 0x92, 0xf3, + 0x73, 0xf5, 0xf3, 0xf2, 0x53, 0x52, 0x0d, 0x0d, 0x0c, 0x75, 0x33, 0xf3, 0xf5, 0x21, 0x96, 0xe9, + 0x42, 0x02, 0xb9, 0x02, 0x25, 0x98, 0x4b, 0x2a, 0x0b, 0x52, 0x8b, 0x93, 0xd8, 0xc0, 0x41, 0x6b, + 0x0c, 0x08, 0x00, 0x00, 0xff, 0xff, 0x10, 0xe9, 0xe3, 0x9b, 0x55, 0x02, 0x00, 0x00, } func (m *GenesisState) Marshal() (dAtA []byte, err error) { @@ -128,10 +139,24 @@ func (m *GenesisState) MarshalToSizedBuffer(dAtA []byte) (int, error) { _ = i var l int _ = l - if len(m.KeyPairs) > 0 { - for iNdEx := len(m.KeyPairs) - 1; iNdEx >= 0; iNdEx-- { + if len(m.ValidatorKeyPairs) > 0 { + for iNdEx := len(m.ValidatorKeyPairs) - 1; iNdEx >= 0; iNdEx-- { { - size, err := m.KeyPairs[iNdEx].MarshalToSizedBuffer(dAtA[:i]) + size, err := m.ValidatorKeyPairs[iNdEx].MarshalToSizedBuffer(dAtA[:i]) + if err != nil { + return 0, err + } + i -= size + i = encodeVarintGenesis(dAtA, i, uint64(size)) + } + i-- + dAtA[i] = 0x1a + } + } + if len(m.UserKeyPairs) > 0 { + for iNdEx := len(m.UserKeyPairs) - 1; iNdEx >= 0; iNdEx-- { + { + size, err := m.UserKeyPairs[iNdEx].MarshalToSizedBuffer(dAtA[:i]) if err != nil { return 0, err } @@ -174,8 +199,14 @@ func (m *GenesisState) Size() (n int) { _ = l l = m.Params.Size() n += 1 + l + sovGenesis(uint64(l)) - if len(m.KeyPairs) > 0 { - for _, e := range m.KeyPairs { + if len(m.UserKeyPairs) > 0 { + for _, e := range m.UserKeyPairs { + l = e.Size() + n += 1 + l + sovGenesis(uint64(l)) + } + } + if len(m.ValidatorKeyPairs) > 0 { + for _, e := range m.ValidatorKeyPairs { l = e.Size() n += 1 + l + sovGenesis(uint64(l)) } @@ -253,7 +284,41 @@ func (m *GenesisState) Unmarshal(dAtA []byte) error { iNdEx = postIndex case 2: if wireType != 2 { - return fmt.Errorf("proto: wrong wireType = %d for field KeyPairs", wireType) + return fmt.Errorf("proto: wrong wireType = %d for field UserKeyPairs", wireType) + } + var msglen int + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowGenesis + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + msglen |= int(b&0x7F) << shift + if b < 0x80 { + break + } + } + if msglen < 0 { + return ErrInvalidLengthGenesis + } + postIndex := iNdEx + msglen + if postIndex < 0 { + return ErrInvalidLengthGenesis + } + if postIndex > l { + return io.ErrUnexpectedEOF + } + m.UserKeyPairs = append(m.UserKeyPairs, &AddressPair{}) + if err := m.UserKeyPairs[len(m.UserKeyPairs)-1].Unmarshal(dAtA[iNdEx:postIndex]); err != nil { + return err + } + iNdEx = postIndex + case 3: + if wireType != 2 { + return fmt.Errorf("proto: wrong wireType = %d for field ValidatorKeyPairs", wireType) } var msglen int for shift := uint(0); ; shift += 7 { @@ -280,8 +345,8 @@ func (m *GenesisState) Unmarshal(dAtA []byte) error { if postIndex > l { return io.ErrUnexpectedEOF } - m.KeyPairs = append(m.KeyPairs, &KeyPair{}) - if err := m.KeyPairs[len(m.KeyPairs)-1].Unmarshal(dAtA[iNdEx:postIndex]); err != nil { + m.ValidatorKeyPairs = append(m.ValidatorKeyPairs, &PublicKeyPair{}) + if err := m.ValidatorKeyPairs[len(m.ValidatorKeyPairs)-1].Unmarshal(dAtA[iNdEx:postIndex]); err != nil { return err } iNdEx = postIndex diff --git a/x/keyregistry/types/keypairs.go b/x/keyregistry/types/keypairs.go deleted file mode 100644 index f3c372dd..00000000 --- a/x/keyregistry/types/keypairs.go +++ /dev/null @@ -1,30 +0,0 @@ -package types - -import ( - "cosmossdk.io/errors" - "github.com/cosmos/cosmos-sdk/crypto/keys/secp256k1" - "github.com/node101-io/mina-signer-go/keys" -) - -func NewKeyPairs() []*KeyPair { - return []*KeyPair{} -} -func DefaultKeyPairs() []*KeyPair { - return NewKeyPairs() -} - -func ValidateKeyPair(k KeyPair) error { - if len(k.CosmosKey) != secp256k1.PubKeySize { - return errors.Wrap(ErrInvalidPublicKey, "cosmos public key must be compressed (33 bytes)") - } - - if len(k.MinaKey) != keys.PublicKeyTotalByteSize { - return errors.Wrap(ErrInvalidPublicKey, "mina public key must be compressed (33 bytes)") - } - return nil -} - -// Validate validates the set of params. -func (k KeyPair) Validate() error { - return ValidateKeyPair(k) -} diff --git a/x/keyregistry/types/keys.go b/x/keyregistry/types/keys.go index 5dcbbf70..9e6fb4e6 100644 --- a/x/keyregistry/types/keys.go +++ b/x/keyregistry/types/keys.go @@ -17,5 +17,8 @@ const ( // ParamsKey is the prefix to retrieve all Params var ParamsKey = collections.NewPrefix("p_keyregistry") -var CosmosToMinaPrefix = collections.NewPrefix("cosmos_map") -var MinaToCosmosPrefix = collections.NewPrefix("mina_map") +var UserCosmosToMinaPrefix = collections.NewPrefix("user_cosmos_map") +var UserMinaToCosmosPrefix = collections.NewPrefix("user_mina_map") + +var ValidatorCosmosToMinaPrefix = collections.NewPrefix("validator_cosmos_map") +var ValidatorMinaToCosmosPrefix = collections.NewPrefix("validator_mina_map") diff --git a/x/keyregistry/types/key_pair.pb.go b/x/keyregistry/types/public_key_pair.pb.go similarity index 55% rename from x/keyregistry/types/key_pair.pb.go rename to x/keyregistry/types/public_key_pair.pb.go index 94a30630..a5554363 100644 --- a/x/keyregistry/types/key_pair.pb.go +++ b/x/keyregistry/types/public_key_pair.pb.go @@ -1,5 +1,5 @@ // Code generated by protoc-gen-gogo. DO NOT EDIT. -// source: pulsarchain/keyregistry/v1/key_pair.proto +// source: pulsarchain/keyregistry/v1/public_key_pair.proto package types @@ -23,23 +23,23 @@ var _ = math.Inf const _ = proto.GoGoProtoPackageIsVersion3 // please upgrade the proto package // KeyPair defines the KeyPair message. -type KeyPair struct { +type PublicKeyPair struct { MinaKey []byte `protobuf:"bytes,1,opt,name=mina_key,json=minaKey,proto3" json:"mina_key,omitempty"` CosmosKey []byte `protobuf:"bytes,2,opt,name=cosmos_key,json=cosmosKey,proto3" json:"cosmos_key,omitempty"` } -func (m *KeyPair) Reset() { *m = KeyPair{} } -func (m *KeyPair) String() string { return proto.CompactTextString(m) } -func (*KeyPair) ProtoMessage() {} -func (*KeyPair) Descriptor() ([]byte, []int) { - return fileDescriptor_7125759d37e49a74, []int{0} +func (m *PublicKeyPair) Reset() { *m = PublicKeyPair{} } +func (m *PublicKeyPair) String() string { return proto.CompactTextString(m) } +func (*PublicKeyPair) ProtoMessage() {} +func (*PublicKeyPair) Descriptor() ([]byte, []int) { + return fileDescriptor_e897d11daaf50b90, []int{0} } -func (m *KeyPair) XXX_Unmarshal(b []byte) error { +func (m *PublicKeyPair) XXX_Unmarshal(b []byte) error { return m.Unmarshal(b) } -func (m *KeyPair) XXX_Marshal(b []byte, deterministic bool) ([]byte, error) { +func (m *PublicKeyPair) XXX_Marshal(b []byte, deterministic bool) ([]byte, error) { if deterministic { - return xxx_messageInfo_KeyPair.Marshal(b, m, deterministic) + return xxx_messageInfo_PublicKeyPair.Marshal(b, m, deterministic) } else { b = b[:cap(b)] n, err := m.MarshalToSizedBuffer(b) @@ -49,26 +49,26 @@ func (m *KeyPair) XXX_Marshal(b []byte, deterministic bool) ([]byte, error) { return b[:n], nil } } -func (m *KeyPair) XXX_Merge(src proto.Message) { - xxx_messageInfo_KeyPair.Merge(m, src) +func (m *PublicKeyPair) XXX_Merge(src proto.Message) { + xxx_messageInfo_PublicKeyPair.Merge(m, src) } -func (m *KeyPair) XXX_Size() int { +func (m *PublicKeyPair) XXX_Size() int { return m.Size() } -func (m *KeyPair) XXX_DiscardUnknown() { - xxx_messageInfo_KeyPair.DiscardUnknown(m) +func (m *PublicKeyPair) XXX_DiscardUnknown() { + xxx_messageInfo_PublicKeyPair.DiscardUnknown(m) } -var xxx_messageInfo_KeyPair proto.InternalMessageInfo +var xxx_messageInfo_PublicKeyPair proto.InternalMessageInfo -func (m *KeyPair) GetMinaKey() []byte { +func (m *PublicKeyPair) GetMinaKey() []byte { if m != nil { return m.MinaKey } return nil } -func (m *KeyPair) GetCosmosKey() []byte { +func (m *PublicKeyPair) GetCosmosKey() []byte { if m != nil { return m.CosmosKey } @@ -76,31 +76,32 @@ func (m *KeyPair) GetCosmosKey() []byte { } func init() { - proto.RegisterType((*KeyPair)(nil), "pulsarchain.keyregistry.v1.KeyPair") + proto.RegisterType((*PublicKeyPair)(nil), "pulsarchain.keyregistry.v1.PublicKeyPair") } func init() { - proto.RegisterFile("pulsarchain/keyregistry/v1/key_pair.proto", fileDescriptor_7125759d37e49a74) + proto.RegisterFile("pulsarchain/keyregistry/v1/public_key_pair.proto", fileDescriptor_e897d11daaf50b90) } -var fileDescriptor_7125759d37e49a74 = []byte{ - // 202 bytes of a gzipped FileDescriptorProto - 0x1f, 0x8b, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0xff, 0xe2, 0xd2, 0x2c, 0x28, 0xcd, 0x29, +var fileDescriptor_e897d11daaf50b90 = []byte{ + // 212 bytes of a gzipped FileDescriptorProto + 0x1f, 0x8b, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0xff, 0xe2, 0x32, 0x28, 0x28, 0xcd, 0x29, 0x4e, 0x2c, 0x4a, 0xce, 0x48, 0xcc, 0xcc, 0xd3, 0xcf, 0x4e, 0xad, 0x2c, 0x4a, 0x4d, 0xcf, 0x2c, - 0x2e, 0x29, 0xaa, 0xd4, 0x2f, 0x33, 0x04, 0x71, 0xe3, 0x0b, 0x12, 0x33, 0x8b, 0xf4, 0x0a, 0x8a, - 0xf2, 0x4b, 0xf2, 0x85, 0xa4, 0x90, 0x94, 0xea, 0x21, 0x29, 0xd5, 0x2b, 0x33, 0x54, 0x72, 0xe6, - 0x62, 0xf7, 0x4e, 0xad, 0x0c, 0x48, 0xcc, 0x2c, 0x12, 0x92, 0xe4, 0xe2, 0xc8, 0xcd, 0xcc, 0x4b, - 0x8c, 0xcf, 0x4e, 0xad, 0x94, 0x60, 0x54, 0x60, 0xd4, 0xe0, 0x09, 0x62, 0x07, 0xf1, 0xbd, 0x53, - 0x2b, 0x85, 0x64, 0xb9, 0xb8, 0x92, 0xf3, 0x8b, 0x73, 0xf3, 0x8b, 0xc1, 0x92, 0x4c, 0x60, 0x49, - 0x4e, 0x88, 0x88, 0x77, 0x6a, 0xa5, 0x53, 0xc0, 0x89, 0x47, 0x72, 0x8c, 0x17, 0x1e, 0xc9, 0x31, - 0x3e, 0x78, 0x24, 0xc7, 0x38, 0xe1, 0xb1, 0x1c, 0xc3, 0x85, 0xc7, 0x72, 0x0c, 0x37, 0x1e, 0xcb, - 0x31, 0x44, 0x99, 0xa5, 0x67, 0x96, 0x64, 0x94, 0x26, 0xe9, 0x25, 0xe7, 0xe7, 0xea, 0xe7, 0xe5, - 0xa7, 0xa4, 0x1a, 0x1a, 0x18, 0xea, 0x66, 0xe6, 0xeb, 0x43, 0x1c, 0xa4, 0x0b, 0x71, 0x7c, 0x05, - 0x8a, 0xf3, 0x4b, 0x2a, 0x0b, 0x52, 0x8b, 0x93, 0xd8, 0xc0, 0x2e, 0x37, 0x06, 0x04, 0x00, 0x00, - 0xff, 0xff, 0x61, 0x07, 0x29, 0xd9, 0xe6, 0x00, 0x00, 0x00, + 0x2e, 0x29, 0xaa, 0xd4, 0x2f, 0x33, 0xd4, 0x2f, 0x28, 0x4d, 0xca, 0xc9, 0x4c, 0x8e, 0xcf, 0x4e, + 0xad, 0x8c, 0x2f, 0x48, 0xcc, 0x2c, 0xd2, 0x2b, 0x28, 0xca, 0x2f, 0xc9, 0x17, 0x92, 0x42, 0xd2, + 0xa1, 0x87, 0xa4, 0x43, 0xaf, 0xcc, 0x50, 0xc9, 0x93, 0x8b, 0x37, 0x00, 0xac, 0xc9, 0x3b, 0xb5, + 0x32, 0x20, 0x31, 0xb3, 0x48, 0x48, 0x92, 0x8b, 0x23, 0x37, 0x33, 0x2f, 0x11, 0x64, 0x86, 0x04, + 0xa3, 0x02, 0xa3, 0x06, 0x4f, 0x10, 0x3b, 0x88, 0xef, 0x9d, 0x5a, 0x29, 0x24, 0xcb, 0xc5, 0x95, + 0x9c, 0x5f, 0x9c, 0x9b, 0x5f, 0x0c, 0x96, 0x64, 0x02, 0x4b, 0x72, 0x42, 0x44, 0xbc, 0x53, 0x2b, + 0x9d, 0x02, 0x4e, 0x3c, 0x92, 0x63, 0xbc, 0xf0, 0x48, 0x8e, 0xf1, 0xc1, 0x23, 0x39, 0xc6, 0x09, + 0x8f, 0xe5, 0x18, 0x2e, 0x3c, 0x96, 0x63, 0xb8, 0xf1, 0x58, 0x8e, 0x21, 0xca, 0x2c, 0x3d, 0xb3, + 0x24, 0xa3, 0x34, 0x49, 0x2f, 0x39, 0x3f, 0x57, 0x3f, 0x2f, 0x3f, 0x25, 0xd5, 0xd0, 0xc0, 0x50, + 0x37, 0x33, 0x5f, 0x1f, 0xe2, 0x2c, 0x5d, 0x88, 0x4f, 0x2a, 0x50, 0xfc, 0x52, 0x52, 0x59, 0x90, + 0x5a, 0x9c, 0xc4, 0x06, 0x76, 0xbf, 0x31, 0x20, 0x00, 0x00, 0xff, 0xff, 0x5f, 0x86, 0xc7, 0xaa, + 0xf3, 0x00, 0x00, 0x00, } -func (m *KeyPair) Marshal() (dAtA []byte, err error) { +func (m *PublicKeyPair) Marshal() (dAtA []byte, err error) { size := m.Size() dAtA = make([]byte, size) n, err := m.MarshalToSizedBuffer(dAtA[:size]) @@ -110,12 +111,12 @@ func (m *KeyPair) Marshal() (dAtA []byte, err error) { return dAtA[:n], nil } -func (m *KeyPair) MarshalTo(dAtA []byte) (int, error) { +func (m *PublicKeyPair) MarshalTo(dAtA []byte) (int, error) { size := m.Size() return m.MarshalToSizedBuffer(dAtA[:size]) } -func (m *KeyPair) MarshalToSizedBuffer(dAtA []byte) (int, error) { +func (m *PublicKeyPair) MarshalToSizedBuffer(dAtA []byte) (int, error) { i := len(dAtA) _ = i var l int @@ -123,22 +124,22 @@ func (m *KeyPair) MarshalToSizedBuffer(dAtA []byte) (int, error) { if len(m.CosmosKey) > 0 { i -= len(m.CosmosKey) copy(dAtA[i:], m.CosmosKey) - i = encodeVarintKeyPair(dAtA, i, uint64(len(m.CosmosKey))) + i = encodeVarintPublicKeyPair(dAtA, i, uint64(len(m.CosmosKey))) i-- dAtA[i] = 0x12 } if len(m.MinaKey) > 0 { i -= len(m.MinaKey) copy(dAtA[i:], m.MinaKey) - i = encodeVarintKeyPair(dAtA, i, uint64(len(m.MinaKey))) + i = encodeVarintPublicKeyPair(dAtA, i, uint64(len(m.MinaKey))) i-- dAtA[i] = 0xa } return len(dAtA) - i, nil } -func encodeVarintKeyPair(dAtA []byte, offset int, v uint64) int { - offset -= sovKeyPair(v) +func encodeVarintPublicKeyPair(dAtA []byte, offset int, v uint64) int { + offset -= sovPublicKeyPair(v) base := offset for v >= 1<<7 { dAtA[offset] = uint8(v&0x7f | 0x80) @@ -148,7 +149,7 @@ func encodeVarintKeyPair(dAtA []byte, offset int, v uint64) int { dAtA[offset] = uint8(v) return base } -func (m *KeyPair) Size() (n int) { +func (m *PublicKeyPair) Size() (n int) { if m == nil { return 0 } @@ -156,22 +157,22 @@ func (m *KeyPair) Size() (n int) { _ = l l = len(m.MinaKey) if l > 0 { - n += 1 + l + sovKeyPair(uint64(l)) + n += 1 + l + sovPublicKeyPair(uint64(l)) } l = len(m.CosmosKey) if l > 0 { - n += 1 + l + sovKeyPair(uint64(l)) + n += 1 + l + sovPublicKeyPair(uint64(l)) } return n } -func sovKeyPair(x uint64) (n int) { +func sovPublicKeyPair(x uint64) (n int) { return (math_bits.Len64(x|1) + 6) / 7 } -func sozKeyPair(x uint64) (n int) { - return sovKeyPair(uint64((x << 1) ^ uint64((int64(x) >> 63)))) +func sozPublicKeyPair(x uint64) (n int) { + return sovPublicKeyPair(uint64((x << 1) ^ uint64((int64(x) >> 63)))) } -func (m *KeyPair) Unmarshal(dAtA []byte) error { +func (m *PublicKeyPair) Unmarshal(dAtA []byte) error { l := len(dAtA) iNdEx := 0 for iNdEx < l { @@ -179,7 +180,7 @@ func (m *KeyPair) Unmarshal(dAtA []byte) error { var wire uint64 for shift := uint(0); ; shift += 7 { if shift >= 64 { - return ErrIntOverflowKeyPair + return ErrIntOverflowPublicKeyPair } if iNdEx >= l { return io.ErrUnexpectedEOF @@ -194,10 +195,10 @@ func (m *KeyPair) Unmarshal(dAtA []byte) error { fieldNum := int32(wire >> 3) wireType := int(wire & 0x7) if wireType == 4 { - return fmt.Errorf("proto: KeyPair: wiretype end group for non-group") + return fmt.Errorf("proto: PublicKeyPair: wiretype end group for non-group") } if fieldNum <= 0 { - return fmt.Errorf("proto: KeyPair: illegal tag %d (wire type %d)", fieldNum, wire) + return fmt.Errorf("proto: PublicKeyPair: illegal tag %d (wire type %d)", fieldNum, wire) } switch fieldNum { case 1: @@ -207,7 +208,7 @@ func (m *KeyPair) Unmarshal(dAtA []byte) error { var byteLen int for shift := uint(0); ; shift += 7 { if shift >= 64 { - return ErrIntOverflowKeyPair + return ErrIntOverflowPublicKeyPair } if iNdEx >= l { return io.ErrUnexpectedEOF @@ -220,11 +221,11 @@ func (m *KeyPair) Unmarshal(dAtA []byte) error { } } if byteLen < 0 { - return ErrInvalidLengthKeyPair + return ErrInvalidLengthPublicKeyPair } postIndex := iNdEx + byteLen if postIndex < 0 { - return ErrInvalidLengthKeyPair + return ErrInvalidLengthPublicKeyPair } if postIndex > l { return io.ErrUnexpectedEOF @@ -241,7 +242,7 @@ func (m *KeyPair) Unmarshal(dAtA []byte) error { var byteLen int for shift := uint(0); ; shift += 7 { if shift >= 64 { - return ErrIntOverflowKeyPair + return ErrIntOverflowPublicKeyPair } if iNdEx >= l { return io.ErrUnexpectedEOF @@ -254,11 +255,11 @@ func (m *KeyPair) Unmarshal(dAtA []byte) error { } } if byteLen < 0 { - return ErrInvalidLengthKeyPair + return ErrInvalidLengthPublicKeyPair } postIndex := iNdEx + byteLen if postIndex < 0 { - return ErrInvalidLengthKeyPair + return ErrInvalidLengthPublicKeyPair } if postIndex > l { return io.ErrUnexpectedEOF @@ -270,12 +271,12 @@ func (m *KeyPair) Unmarshal(dAtA []byte) error { iNdEx = postIndex default: iNdEx = preIndex - skippy, err := skipKeyPair(dAtA[iNdEx:]) + skippy, err := skipPublicKeyPair(dAtA[iNdEx:]) if err != nil { return err } if (skippy < 0) || (iNdEx+skippy) < 0 { - return ErrInvalidLengthKeyPair + return ErrInvalidLengthPublicKeyPair } if (iNdEx + skippy) > l { return io.ErrUnexpectedEOF @@ -289,7 +290,7 @@ func (m *KeyPair) Unmarshal(dAtA []byte) error { } return nil } -func skipKeyPair(dAtA []byte) (n int, err error) { +func skipPublicKeyPair(dAtA []byte) (n int, err error) { l := len(dAtA) iNdEx := 0 depth := 0 @@ -297,7 +298,7 @@ func skipKeyPair(dAtA []byte) (n int, err error) { var wire uint64 for shift := uint(0); ; shift += 7 { if shift >= 64 { - return 0, ErrIntOverflowKeyPair + return 0, ErrIntOverflowPublicKeyPair } if iNdEx >= l { return 0, io.ErrUnexpectedEOF @@ -314,7 +315,7 @@ func skipKeyPair(dAtA []byte) (n int, err error) { case 0: for shift := uint(0); ; shift += 7 { if shift >= 64 { - return 0, ErrIntOverflowKeyPair + return 0, ErrIntOverflowPublicKeyPair } if iNdEx >= l { return 0, io.ErrUnexpectedEOF @@ -330,7 +331,7 @@ func skipKeyPair(dAtA []byte) (n int, err error) { var length int for shift := uint(0); ; shift += 7 { if shift >= 64 { - return 0, ErrIntOverflowKeyPair + return 0, ErrIntOverflowPublicKeyPair } if iNdEx >= l { return 0, io.ErrUnexpectedEOF @@ -343,14 +344,14 @@ func skipKeyPair(dAtA []byte) (n int, err error) { } } if length < 0 { - return 0, ErrInvalidLengthKeyPair + return 0, ErrInvalidLengthPublicKeyPair } iNdEx += length case 3: depth++ case 4: if depth == 0 { - return 0, ErrUnexpectedEndOfGroupKeyPair + return 0, ErrUnexpectedEndOfGroupPublicKeyPair } depth-- case 5: @@ -359,7 +360,7 @@ func skipKeyPair(dAtA []byte) (n int, err error) { return 0, fmt.Errorf("proto: illegal wireType %d", wireType) } if iNdEx < 0 { - return 0, ErrInvalidLengthKeyPair + return 0, ErrInvalidLengthPublicKeyPair } if depth == 0 { return iNdEx, nil @@ -369,7 +370,7 @@ func skipKeyPair(dAtA []byte) (n int, err error) { } var ( - ErrInvalidLengthKeyPair = fmt.Errorf("proto: negative length found during unmarshaling") - ErrIntOverflowKeyPair = fmt.Errorf("proto: integer overflow") - ErrUnexpectedEndOfGroupKeyPair = fmt.Errorf("proto: unexpected end of group") + ErrInvalidLengthPublicKeyPair = fmt.Errorf("proto: negative length found during unmarshaling") + ErrIntOverflowPublicKeyPair = fmt.Errorf("proto: integer overflow") + ErrUnexpectedEndOfGroupPublicKeyPair = fmt.Errorf("proto: unexpected end of group") ) diff --git a/x/keyregistry/types/public_key_pairs.go b/x/keyregistry/types/public_key_pairs.go new file mode 100644 index 00000000..1d1998dd --- /dev/null +++ b/x/keyregistry/types/public_key_pairs.go @@ -0,0 +1,34 @@ +package types + +import ( + "cosmossdk.io/errors" + "github.com/cosmos/cosmos-sdk/crypto/keys/ed25519" + "github.com/node101-io/mina-signer-go/keys" +) + +func NewPublicKeyPairs() []*PublicKeyPair { + return []*PublicKeyPair{} +} +func DefaultUserPublicKeyPairs() []*PublicKeyPair { + return NewPublicKeyPairs() +} + +func DefaultPublicKeyPair() []*PublicKeyPair { + return NewPublicKeyPairs() +} + +func ValidatePublicKeyPair(k PublicKeyPair) error { + if len(k.CosmosKey) != ed25519.PubKeySize { + return errors.Wrap(ErrInvalidPublicKey, "cosmos consensus public key must be ed25519 (32 bytes)") + } + + if len(k.MinaKey) != keys.PublicKeyTotalByteSize { + return errors.Wrap(ErrInvalidPublicKey, "mina public key must be compressed (33 bytes)") + } + return nil +} + +// Validate validates the set of params. +func (k PublicKeyPair) Validate() error { + return ValidatePublicKeyPair(k) +} diff --git a/x/keyregistry/types/query.pb.go b/x/keyregistry/types/query.pb.go index 09839626..8fd3aa83 100644 --- a/x/keyregistry/types/query.pb.go +++ b/x/keyregistry/types/query.pb.go @@ -114,23 +114,23 @@ func (m *QueryParamsResponse) GetParams() Params { return Params{} } -// QueryGetMinaPubKeyRequest defines the QueryGetMinaPubKeyRequest message. -type QueryGetMinaPubKeyRequest struct { - CosmosPubKey []byte `protobuf:"bytes,1,opt,name=cosmos_pub_key,json=cosmosPubKey,proto3" json:"cosmos_pub_key,omitempty"` +// QueryGetUserMinaAddressRequest defines the QueryGetUserMinaAddressRequest message. +type QueryGetUserMinaAddressRequest struct { + UserCosmosAddress []byte `protobuf:"bytes,1,opt,name=user_cosmos_address,json=userCosmosAddress,proto3" json:"user_cosmos_address,omitempty"` } -func (m *QueryGetMinaPubKeyRequest) Reset() { *m = QueryGetMinaPubKeyRequest{} } -func (m *QueryGetMinaPubKeyRequest) String() string { return proto.CompactTextString(m) } -func (*QueryGetMinaPubKeyRequest) ProtoMessage() {} -func (*QueryGetMinaPubKeyRequest) Descriptor() ([]byte, []int) { +func (m *QueryGetUserMinaAddressRequest) Reset() { *m = QueryGetUserMinaAddressRequest{} } +func (m *QueryGetUserMinaAddressRequest) String() string { return proto.CompactTextString(m) } +func (*QueryGetUserMinaAddressRequest) ProtoMessage() {} +func (*QueryGetUserMinaAddressRequest) Descriptor() ([]byte, []int) { return fileDescriptor_d580bfce910e0ca3, []int{2} } -func (m *QueryGetMinaPubKeyRequest) XXX_Unmarshal(b []byte) error { +func (m *QueryGetUserMinaAddressRequest) XXX_Unmarshal(b []byte) error { return m.Unmarshal(b) } -func (m *QueryGetMinaPubKeyRequest) XXX_Marshal(b []byte, deterministic bool) ([]byte, error) { +func (m *QueryGetUserMinaAddressRequest) XXX_Marshal(b []byte, deterministic bool) ([]byte, error) { if deterministic { - return xxx_messageInfo_QueryGetMinaPubKeyRequest.Marshal(b, m, deterministic) + return xxx_messageInfo_QueryGetUserMinaAddressRequest.Marshal(b, m, deterministic) } else { b = b[:cap(b)] n, err := m.MarshalToSizedBuffer(b) @@ -140,42 +140,42 @@ func (m *QueryGetMinaPubKeyRequest) XXX_Marshal(b []byte, deterministic bool) ([ return b[:n], nil } } -func (m *QueryGetMinaPubKeyRequest) XXX_Merge(src proto.Message) { - xxx_messageInfo_QueryGetMinaPubKeyRequest.Merge(m, src) +func (m *QueryGetUserMinaAddressRequest) XXX_Merge(src proto.Message) { + xxx_messageInfo_QueryGetUserMinaAddressRequest.Merge(m, src) } -func (m *QueryGetMinaPubKeyRequest) XXX_Size() int { +func (m *QueryGetUserMinaAddressRequest) XXX_Size() int { return m.Size() } -func (m *QueryGetMinaPubKeyRequest) XXX_DiscardUnknown() { - xxx_messageInfo_QueryGetMinaPubKeyRequest.DiscardUnknown(m) +func (m *QueryGetUserMinaAddressRequest) XXX_DiscardUnknown() { + xxx_messageInfo_QueryGetUserMinaAddressRequest.DiscardUnknown(m) } -var xxx_messageInfo_QueryGetMinaPubKeyRequest proto.InternalMessageInfo +var xxx_messageInfo_QueryGetUserMinaAddressRequest proto.InternalMessageInfo -func (m *QueryGetMinaPubKeyRequest) GetCosmosPubKey() []byte { +func (m *QueryGetUserMinaAddressRequest) GetUserCosmosAddress() []byte { if m != nil { - return m.CosmosPubKey + return m.UserCosmosAddress } return nil } -// QueryGetMinaPubKeyResponse defines the QueryGetMinaPubKeyResponse message. -type QueryGetMinaPubKeyResponse struct { - MinaPubKey []byte `protobuf:"bytes,1,opt,name=mina_pub_key,json=minaPubKey,proto3" json:"mina_pub_key,omitempty"` +// QueryGetUserMinaAddressResponse defines the QueryGetUserMinaAddressResponse message. +type QueryGetUserMinaAddressResponse struct { + UserMinaAddress []byte `protobuf:"bytes,1,opt,name=user_mina_address,json=userMinaAddress,proto3" json:"user_mina_address,omitempty"` } -func (m *QueryGetMinaPubKeyResponse) Reset() { *m = QueryGetMinaPubKeyResponse{} } -func (m *QueryGetMinaPubKeyResponse) String() string { return proto.CompactTextString(m) } -func (*QueryGetMinaPubKeyResponse) ProtoMessage() {} -func (*QueryGetMinaPubKeyResponse) Descriptor() ([]byte, []int) { +func (m *QueryGetUserMinaAddressResponse) Reset() { *m = QueryGetUserMinaAddressResponse{} } +func (m *QueryGetUserMinaAddressResponse) String() string { return proto.CompactTextString(m) } +func (*QueryGetUserMinaAddressResponse) ProtoMessage() {} +func (*QueryGetUserMinaAddressResponse) Descriptor() ([]byte, []int) { return fileDescriptor_d580bfce910e0ca3, []int{3} } -func (m *QueryGetMinaPubKeyResponse) XXX_Unmarshal(b []byte) error { +func (m *QueryGetUserMinaAddressResponse) XXX_Unmarshal(b []byte) error { return m.Unmarshal(b) } -func (m *QueryGetMinaPubKeyResponse) XXX_Marshal(b []byte, deterministic bool) ([]byte, error) { +func (m *QueryGetUserMinaAddressResponse) XXX_Marshal(b []byte, deterministic bool) ([]byte, error) { if deterministic { - return xxx_messageInfo_QueryGetMinaPubKeyResponse.Marshal(b, m, deterministic) + return xxx_messageInfo_QueryGetUserMinaAddressResponse.Marshal(b, m, deterministic) } else { b = b[:cap(b)] n, err := m.MarshalToSizedBuffer(b) @@ -185,42 +185,42 @@ func (m *QueryGetMinaPubKeyResponse) XXX_Marshal(b []byte, deterministic bool) ( return b[:n], nil } } -func (m *QueryGetMinaPubKeyResponse) XXX_Merge(src proto.Message) { - xxx_messageInfo_QueryGetMinaPubKeyResponse.Merge(m, src) +func (m *QueryGetUserMinaAddressResponse) XXX_Merge(src proto.Message) { + xxx_messageInfo_QueryGetUserMinaAddressResponse.Merge(m, src) } -func (m *QueryGetMinaPubKeyResponse) XXX_Size() int { +func (m *QueryGetUserMinaAddressResponse) XXX_Size() int { return m.Size() } -func (m *QueryGetMinaPubKeyResponse) XXX_DiscardUnknown() { - xxx_messageInfo_QueryGetMinaPubKeyResponse.DiscardUnknown(m) +func (m *QueryGetUserMinaAddressResponse) XXX_DiscardUnknown() { + xxx_messageInfo_QueryGetUserMinaAddressResponse.DiscardUnknown(m) } -var xxx_messageInfo_QueryGetMinaPubKeyResponse proto.InternalMessageInfo +var xxx_messageInfo_QueryGetUserMinaAddressResponse proto.InternalMessageInfo -func (m *QueryGetMinaPubKeyResponse) GetMinaPubKey() []byte { +func (m *QueryGetUserMinaAddressResponse) GetUserMinaAddress() []byte { if m != nil { - return m.MinaPubKey + return m.UserMinaAddress } return nil } -// QueryGetCosmosPubKeyRequest defines the QueryGetCosmosPubKeyRequest message. -type QueryGetCosmosPubKeyRequest struct { - MinaPubKey []byte `protobuf:"bytes,1,opt,name=mina_pub_key,json=minaPubKey,proto3" json:"mina_pub_key,omitempty"` +// QueryGetUserCosmosAddressRequest defines the QueryGetUserCosmosAddressRequest message. +type QueryGetUserCosmosAddressRequest struct { + UserMinaAddress []byte `protobuf:"bytes,1,opt,name=user_mina_address,json=userMinaAddress,proto3" json:"user_mina_address,omitempty"` } -func (m *QueryGetCosmosPubKeyRequest) Reset() { *m = QueryGetCosmosPubKeyRequest{} } -func (m *QueryGetCosmosPubKeyRequest) String() string { return proto.CompactTextString(m) } -func (*QueryGetCosmosPubKeyRequest) ProtoMessage() {} -func (*QueryGetCosmosPubKeyRequest) Descriptor() ([]byte, []int) { +func (m *QueryGetUserCosmosAddressRequest) Reset() { *m = QueryGetUserCosmosAddressRequest{} } +func (m *QueryGetUserCosmosAddressRequest) String() string { return proto.CompactTextString(m) } +func (*QueryGetUserCosmosAddressRequest) ProtoMessage() {} +func (*QueryGetUserCosmosAddressRequest) Descriptor() ([]byte, []int) { return fileDescriptor_d580bfce910e0ca3, []int{4} } -func (m *QueryGetCosmosPubKeyRequest) XXX_Unmarshal(b []byte) error { +func (m *QueryGetUserCosmosAddressRequest) XXX_Unmarshal(b []byte) error { return m.Unmarshal(b) } -func (m *QueryGetCosmosPubKeyRequest) XXX_Marshal(b []byte, deterministic bool) ([]byte, error) { +func (m *QueryGetUserCosmosAddressRequest) XXX_Marshal(b []byte, deterministic bool) ([]byte, error) { if deterministic { - return xxx_messageInfo_QueryGetCosmosPubKeyRequest.Marshal(b, m, deterministic) + return xxx_messageInfo_QueryGetUserCosmosAddressRequest.Marshal(b, m, deterministic) } else { b = b[:cap(b)] n, err := m.MarshalToSizedBuffer(b) @@ -230,42 +230,42 @@ func (m *QueryGetCosmosPubKeyRequest) XXX_Marshal(b []byte, deterministic bool) return b[:n], nil } } -func (m *QueryGetCosmosPubKeyRequest) XXX_Merge(src proto.Message) { - xxx_messageInfo_QueryGetCosmosPubKeyRequest.Merge(m, src) +func (m *QueryGetUserCosmosAddressRequest) XXX_Merge(src proto.Message) { + xxx_messageInfo_QueryGetUserCosmosAddressRequest.Merge(m, src) } -func (m *QueryGetCosmosPubKeyRequest) XXX_Size() int { +func (m *QueryGetUserCosmosAddressRequest) XXX_Size() int { return m.Size() } -func (m *QueryGetCosmosPubKeyRequest) XXX_DiscardUnknown() { - xxx_messageInfo_QueryGetCosmosPubKeyRequest.DiscardUnknown(m) +func (m *QueryGetUserCosmosAddressRequest) XXX_DiscardUnknown() { + xxx_messageInfo_QueryGetUserCosmosAddressRequest.DiscardUnknown(m) } -var xxx_messageInfo_QueryGetCosmosPubKeyRequest proto.InternalMessageInfo +var xxx_messageInfo_QueryGetUserCosmosAddressRequest proto.InternalMessageInfo -func (m *QueryGetCosmosPubKeyRequest) GetMinaPubKey() []byte { +func (m *QueryGetUserCosmosAddressRequest) GetUserMinaAddress() []byte { if m != nil { - return m.MinaPubKey + return m.UserMinaAddress } return nil } -// QueryGetCosmosPubKeyResponse defines the QueryGetCosmosPubKeyResponse message. -type QueryGetCosmosPubKeyResponse struct { - CosmosPubKey []byte `protobuf:"bytes,1,opt,name=cosmos_pub_key,json=cosmosPubKey,proto3" json:"cosmos_pub_key,omitempty"` +// QueryGetUserCosmosAddressResponse defines the QueryGetUserCosmosAddressResponse message. +type QueryGetUserCosmosAddressResponse struct { + UserCosmosAddress []byte `protobuf:"bytes,1,opt,name=user_cosmos_address,json=userCosmosAddress,proto3" json:"user_cosmos_address,omitempty"` } -func (m *QueryGetCosmosPubKeyResponse) Reset() { *m = QueryGetCosmosPubKeyResponse{} } -func (m *QueryGetCosmosPubKeyResponse) String() string { return proto.CompactTextString(m) } -func (*QueryGetCosmosPubKeyResponse) ProtoMessage() {} -func (*QueryGetCosmosPubKeyResponse) Descriptor() ([]byte, []int) { +func (m *QueryGetUserCosmosAddressResponse) Reset() { *m = QueryGetUserCosmosAddressResponse{} } +func (m *QueryGetUserCosmosAddressResponse) String() string { return proto.CompactTextString(m) } +func (*QueryGetUserCosmosAddressResponse) ProtoMessage() {} +func (*QueryGetUserCosmosAddressResponse) Descriptor() ([]byte, []int) { return fileDescriptor_d580bfce910e0ca3, []int{5} } -func (m *QueryGetCosmosPubKeyResponse) XXX_Unmarshal(b []byte) error { +func (m *QueryGetUserCosmosAddressResponse) XXX_Unmarshal(b []byte) error { return m.Unmarshal(b) } -func (m *QueryGetCosmosPubKeyResponse) XXX_Marshal(b []byte, deterministic bool) ([]byte, error) { +func (m *QueryGetUserCosmosAddressResponse) XXX_Marshal(b []byte, deterministic bool) ([]byte, error) { if deterministic { - return xxx_messageInfo_QueryGetCosmosPubKeyResponse.Marshal(b, m, deterministic) + return xxx_messageInfo_QueryGetUserCosmosAddressResponse.Marshal(b, m, deterministic) } else { b = b[:cap(b)] n, err := m.MarshalToSizedBuffer(b) @@ -275,21 +275,201 @@ func (m *QueryGetCosmosPubKeyResponse) XXX_Marshal(b []byte, deterministic bool) return b[:n], nil } } -func (m *QueryGetCosmosPubKeyResponse) XXX_Merge(src proto.Message) { - xxx_messageInfo_QueryGetCosmosPubKeyResponse.Merge(m, src) +func (m *QueryGetUserCosmosAddressResponse) XXX_Merge(src proto.Message) { + xxx_messageInfo_QueryGetUserCosmosAddressResponse.Merge(m, src) } -func (m *QueryGetCosmosPubKeyResponse) XXX_Size() int { +func (m *QueryGetUserCosmosAddressResponse) XXX_Size() int { return m.Size() } -func (m *QueryGetCosmosPubKeyResponse) XXX_DiscardUnknown() { - xxx_messageInfo_QueryGetCosmosPubKeyResponse.DiscardUnknown(m) +func (m *QueryGetUserCosmosAddressResponse) XXX_DiscardUnknown() { + xxx_messageInfo_QueryGetUserCosmosAddressResponse.DiscardUnknown(m) } -var xxx_messageInfo_QueryGetCosmosPubKeyResponse proto.InternalMessageInfo +var xxx_messageInfo_QueryGetUserCosmosAddressResponse proto.InternalMessageInfo -func (m *QueryGetCosmosPubKeyResponse) GetCosmosPubKey() []byte { +func (m *QueryGetUserCosmosAddressResponse) GetUserCosmosAddress() []byte { if m != nil { - return m.CosmosPubKey + return m.UserCosmosAddress + } + return nil +} + +// QueryGetValidatorMinaAddressRequest defines the QueryGetValidatorMinaAddressRequest message. +type QueryGetValidatorMinaPubKeyRequest struct { + ValidatorCosmosPubKey []byte `protobuf:"bytes,1,opt,name=validator_cosmos_pub_key,json=validatorCosmosPubKey,proto3" json:"validator_cosmos_pub_key,omitempty"` +} + +func (m *QueryGetValidatorMinaPubKeyRequest) Reset() { *m = QueryGetValidatorMinaPubKeyRequest{} } +func (m *QueryGetValidatorMinaPubKeyRequest) String() string { return proto.CompactTextString(m) } +func (*QueryGetValidatorMinaPubKeyRequest) ProtoMessage() {} +func (*QueryGetValidatorMinaPubKeyRequest) Descriptor() ([]byte, []int) { + return fileDescriptor_d580bfce910e0ca3, []int{6} +} +func (m *QueryGetValidatorMinaPubKeyRequest) XXX_Unmarshal(b []byte) error { + return m.Unmarshal(b) +} +func (m *QueryGetValidatorMinaPubKeyRequest) XXX_Marshal(b []byte, deterministic bool) ([]byte, error) { + if deterministic { + return xxx_messageInfo_QueryGetValidatorMinaPubKeyRequest.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 *QueryGetValidatorMinaPubKeyRequest) XXX_Merge(src proto.Message) { + xxx_messageInfo_QueryGetValidatorMinaPubKeyRequest.Merge(m, src) +} +func (m *QueryGetValidatorMinaPubKeyRequest) XXX_Size() int { + return m.Size() +} +func (m *QueryGetValidatorMinaPubKeyRequest) XXX_DiscardUnknown() { + xxx_messageInfo_QueryGetValidatorMinaPubKeyRequest.DiscardUnknown(m) +} + +var xxx_messageInfo_QueryGetValidatorMinaPubKeyRequest proto.InternalMessageInfo + +func (m *QueryGetValidatorMinaPubKeyRequest) GetValidatorCosmosPubKey() []byte { + if m != nil { + return m.ValidatorCosmosPubKey + } + return nil +} + +// QueryGetValidatorMinaAddressResponse defines the QueryGetValidatorMinaAddressResponse message. +type QueryGetValidatorMinaPubKeyResponse struct { + ValidatorMinaPubKey []byte `protobuf:"bytes,1,opt,name=validator_mina_pub_key,json=validatorMinaPubKey,proto3" json:"validator_mina_pub_key,omitempty"` +} + +func (m *QueryGetValidatorMinaPubKeyResponse) Reset() { *m = QueryGetValidatorMinaPubKeyResponse{} } +func (m *QueryGetValidatorMinaPubKeyResponse) String() string { return proto.CompactTextString(m) } +func (*QueryGetValidatorMinaPubKeyResponse) ProtoMessage() {} +func (*QueryGetValidatorMinaPubKeyResponse) Descriptor() ([]byte, []int) { + return fileDescriptor_d580bfce910e0ca3, []int{7} +} +func (m *QueryGetValidatorMinaPubKeyResponse) XXX_Unmarshal(b []byte) error { + return m.Unmarshal(b) +} +func (m *QueryGetValidatorMinaPubKeyResponse) XXX_Marshal(b []byte, deterministic bool) ([]byte, error) { + if deterministic { + return xxx_messageInfo_QueryGetValidatorMinaPubKeyResponse.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 *QueryGetValidatorMinaPubKeyResponse) XXX_Merge(src proto.Message) { + xxx_messageInfo_QueryGetValidatorMinaPubKeyResponse.Merge(m, src) +} +func (m *QueryGetValidatorMinaPubKeyResponse) XXX_Size() int { + return m.Size() +} +func (m *QueryGetValidatorMinaPubKeyResponse) XXX_DiscardUnknown() { + xxx_messageInfo_QueryGetValidatorMinaPubKeyResponse.DiscardUnknown(m) +} + +var xxx_messageInfo_QueryGetValidatorMinaPubKeyResponse proto.InternalMessageInfo + +func (m *QueryGetValidatorMinaPubKeyResponse) GetValidatorMinaPubKey() []byte { + if m != nil { + return m.ValidatorMinaPubKey + } + return nil +} + +// QueryGetValidatorCosmosAddressRequest defines the QueryGetValidatorCosmosAddressRequest message. +type QueryGetValidatorCosmosPubKeyRequest struct { + ValidatorMinaPubKey []byte `protobuf:"bytes,1,opt,name=validator_mina_pub_key,json=validatorMinaPubKey,proto3" json:"validator_mina_pub_key,omitempty"` +} + +func (m *QueryGetValidatorCosmosPubKeyRequest) Reset() { *m = QueryGetValidatorCosmosPubKeyRequest{} } +func (m *QueryGetValidatorCosmosPubKeyRequest) String() string { return proto.CompactTextString(m) } +func (*QueryGetValidatorCosmosPubKeyRequest) ProtoMessage() {} +func (*QueryGetValidatorCosmosPubKeyRequest) Descriptor() ([]byte, []int) { + return fileDescriptor_d580bfce910e0ca3, []int{8} +} +func (m *QueryGetValidatorCosmosPubKeyRequest) XXX_Unmarshal(b []byte) error { + return m.Unmarshal(b) +} +func (m *QueryGetValidatorCosmosPubKeyRequest) XXX_Marshal(b []byte, deterministic bool) ([]byte, error) { + if deterministic { + return xxx_messageInfo_QueryGetValidatorCosmosPubKeyRequest.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 *QueryGetValidatorCosmosPubKeyRequest) XXX_Merge(src proto.Message) { + xxx_messageInfo_QueryGetValidatorCosmosPubKeyRequest.Merge(m, src) +} +func (m *QueryGetValidatorCosmosPubKeyRequest) XXX_Size() int { + return m.Size() +} +func (m *QueryGetValidatorCosmosPubKeyRequest) XXX_DiscardUnknown() { + xxx_messageInfo_QueryGetValidatorCosmosPubKeyRequest.DiscardUnknown(m) +} + +var xxx_messageInfo_QueryGetValidatorCosmosPubKeyRequest proto.InternalMessageInfo + +func (m *QueryGetValidatorCosmosPubKeyRequest) GetValidatorMinaPubKey() []byte { + if m != nil { + return m.ValidatorMinaPubKey + } + return nil +} + +// QueryGetValidatorCosmosAddressResponse defines the QueryGetValidatorCosmosAddressResponse message. +type QueryGetValidatorCosmosPubKeyResponse struct { + ValidatorCosmosPubKey []byte `protobuf:"bytes,1,opt,name=validator_cosmos_pub_key,json=validatorCosmosPubKey,proto3" json:"validator_cosmos_pub_key,omitempty"` +} + +func (m *QueryGetValidatorCosmosPubKeyResponse) Reset() { *m = QueryGetValidatorCosmosPubKeyResponse{} } +func (m *QueryGetValidatorCosmosPubKeyResponse) String() string { return proto.CompactTextString(m) } +func (*QueryGetValidatorCosmosPubKeyResponse) ProtoMessage() {} +func (*QueryGetValidatorCosmosPubKeyResponse) Descriptor() ([]byte, []int) { + return fileDescriptor_d580bfce910e0ca3, []int{9} +} +func (m *QueryGetValidatorCosmosPubKeyResponse) XXX_Unmarshal(b []byte) error { + return m.Unmarshal(b) +} +func (m *QueryGetValidatorCosmosPubKeyResponse) XXX_Marshal(b []byte, deterministic bool) ([]byte, error) { + if deterministic { + return xxx_messageInfo_QueryGetValidatorCosmosPubKeyResponse.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 *QueryGetValidatorCosmosPubKeyResponse) XXX_Merge(src proto.Message) { + xxx_messageInfo_QueryGetValidatorCosmosPubKeyResponse.Merge(m, src) +} +func (m *QueryGetValidatorCosmosPubKeyResponse) XXX_Size() int { + return m.Size() +} +func (m *QueryGetValidatorCosmosPubKeyResponse) XXX_DiscardUnknown() { + xxx_messageInfo_QueryGetValidatorCosmosPubKeyResponse.DiscardUnknown(m) +} + +var xxx_messageInfo_QueryGetValidatorCosmosPubKeyResponse proto.InternalMessageInfo + +func (m *QueryGetValidatorCosmosPubKeyResponse) GetValidatorCosmosPubKey() []byte { + if m != nil { + return m.ValidatorCosmosPubKey } return nil } @@ -297,10 +477,14 @@ func (m *QueryGetCosmosPubKeyResponse) GetCosmosPubKey() []byte { func init() { proto.RegisterType((*QueryParamsRequest)(nil), "pulsarchain.keyregistry.v1.QueryParamsRequest") proto.RegisterType((*QueryParamsResponse)(nil), "pulsarchain.keyregistry.v1.QueryParamsResponse") - proto.RegisterType((*QueryGetMinaPubKeyRequest)(nil), "pulsarchain.keyregistry.v1.QueryGetMinaPubKeyRequest") - proto.RegisterType((*QueryGetMinaPubKeyResponse)(nil), "pulsarchain.keyregistry.v1.QueryGetMinaPubKeyResponse") - proto.RegisterType((*QueryGetCosmosPubKeyRequest)(nil), "pulsarchain.keyregistry.v1.QueryGetCosmosPubKeyRequest") - proto.RegisterType((*QueryGetCosmosPubKeyResponse)(nil), "pulsarchain.keyregistry.v1.QueryGetCosmosPubKeyResponse") + proto.RegisterType((*QueryGetUserMinaAddressRequest)(nil), "pulsarchain.keyregistry.v1.QueryGetUserMinaAddressRequest") + proto.RegisterType((*QueryGetUserMinaAddressResponse)(nil), "pulsarchain.keyregistry.v1.QueryGetUserMinaAddressResponse") + proto.RegisterType((*QueryGetUserCosmosAddressRequest)(nil), "pulsarchain.keyregistry.v1.QueryGetUserCosmosAddressRequest") + proto.RegisterType((*QueryGetUserCosmosAddressResponse)(nil), "pulsarchain.keyregistry.v1.QueryGetUserCosmosAddressResponse") + proto.RegisterType((*QueryGetValidatorMinaPubKeyRequest)(nil), "pulsarchain.keyregistry.v1.QueryGetValidatorMinaPubKeyRequest") + proto.RegisterType((*QueryGetValidatorMinaPubKeyResponse)(nil), "pulsarchain.keyregistry.v1.QueryGetValidatorMinaPubKeyResponse") + proto.RegisterType((*QueryGetValidatorCosmosPubKeyRequest)(nil), "pulsarchain.keyregistry.v1.QueryGetValidatorCosmosPubKeyRequest") + proto.RegisterType((*QueryGetValidatorCosmosPubKeyResponse)(nil), "pulsarchain.keyregistry.v1.QueryGetValidatorCosmosPubKeyResponse") } func init() { @@ -308,38 +492,49 @@ func init() { } var fileDescriptor_d580bfce910e0ca3 = []byte{ - // 495 bytes of a gzipped FileDescriptorProto - 0x1f, 0x8b, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0xff, 0xa4, 0x54, 0xcf, 0x6a, 0x14, 0x31, - 0x18, 0xdf, 0x88, 0x2e, 0x18, 0x57, 0xc5, 0xd8, 0x83, 0x8e, 0x65, 0x2c, 0x83, 0xa8, 0x14, 0x3a, - 0xe9, 0x54, 0x5c, 0x3d, 0x29, 0x56, 0x45, 0xa4, 0x08, 0xdb, 0x3d, 0x8a, 0xb0, 0x64, 0xd6, 0x90, - 0x86, 0x76, 0x92, 0x74, 0x92, 0x59, 0x1c, 0x4a, 0x2f, 0x3e, 0x81, 0xe0, 0x13, 0x78, 0xf3, 0xe8, - 0x63, 0xf4, 0x58, 0xf1, 0xa0, 0x5e, 0x44, 0x76, 0x05, 0x5f, 0x43, 0x9a, 0xa4, 0x32, 0x53, 0xb7, - 0xdb, 0x5d, 0xbc, 0x0c, 0xe1, 0x9b, 0xdf, 0xbf, 0xef, 0xfb, 0x42, 0xe0, 0x4d, 0x55, 0x6c, 0x69, - 0x92, 0xf7, 0x37, 0x08, 0x17, 0x78, 0x93, 0x96, 0x39, 0x65, 0x5c, 0x9b, 0xbc, 0xc4, 0x83, 0x04, - 0x6f, 0x17, 0x34, 0x2f, 0x63, 0x95, 0x4b, 0x23, 0x51, 0x50, 0xc1, 0xc5, 0x15, 0x5c, 0x3c, 0x48, - 0x82, 0x4b, 0x24, 0xe3, 0x42, 0x62, 0xfb, 0x75, 0xf0, 0x60, 0xb1, 0x2f, 0x75, 0x26, 0x35, 0x4e, - 0x89, 0xa6, 0x4e, 0x07, 0x0f, 0x92, 0x94, 0x1a, 0x92, 0x60, 0x45, 0x18, 0x17, 0xc4, 0x70, 0x29, - 0x3c, 0x76, 0x8e, 0x49, 0x26, 0xed, 0x11, 0x1f, 0x9c, 0x7c, 0x75, 0x9e, 0x49, 0xc9, 0xb6, 0x28, - 0x26, 0x8a, 0x63, 0x22, 0x84, 0x34, 0x96, 0xa2, 0xfd, 0xdf, 0x5b, 0x13, 0x62, 0x2b, 0x92, 0x93, - 0xcc, 0x03, 0xa3, 0x39, 0x88, 0xd6, 0x0f, 0xec, 0x3b, 0xb6, 0xd8, 0xa5, 0xdb, 0x05, 0xd5, 0x26, - 0x7a, 0x05, 0x2f, 0xd7, 0xaa, 0x5a, 0x49, 0xa1, 0x29, 0x7a, 0x0a, 0x9b, 0x8e, 0x7c, 0x05, 0x2c, - 0x80, 0xdb, 0xe7, 0x56, 0xa2, 0xf8, 0xf8, 0xae, 0x63, 0xc7, 0x5d, 0x3d, 0xbb, 0xf7, 0xe3, 0x7a, - 0xe3, 0xe3, 0xef, 0x4f, 0x8b, 0xa0, 0xeb, 0xc9, 0xd1, 0x23, 0x78, 0xd5, 0xaa, 0x3f, 0xa3, 0xe6, - 0x05, 0x17, 0xa4, 0x53, 0xa4, 0x6b, 0xb4, 0xf4, 0xd6, 0xe8, 0x06, 0xbc, 0xe0, 0x66, 0xd3, 0x53, - 0x45, 0xda, 0xdb, 0xa4, 0xa5, 0xf5, 0x6a, 0x75, 0x5b, 0xae, 0xea, 0xc0, 0xd1, 0x03, 0x18, 0x8c, - 0x93, 0xf0, 0x39, 0x17, 0x60, 0x2b, 0xe3, 0x82, 0x1c, 0x51, 0x80, 0xd9, 0x5f, 0x64, 0xf4, 0x10, - 0x5e, 0x3b, 0xe4, 0x3f, 0xae, 0xe8, 0x1e, 0x86, 0x38, 0x59, 0xe0, 0x09, 0x9c, 0x1f, 0x2f, 0xe0, - 0x23, 0x4c, 0xd5, 0xc6, 0xca, 0xf7, 0xd3, 0xf0, 0x8c, 0x95, 0x41, 0x1f, 0x00, 0x6c, 0xba, 0x89, - 0xa1, 0x78, 0xd2, 0x54, 0xff, 0x5d, 0x56, 0x80, 0xa7, 0xc6, 0xbb, 0x6c, 0x51, 0xfb, 0xed, 0x97, - 0x5f, 0xef, 0x4f, 0x2d, 0xa3, 0x18, 0x0b, 0xf9, 0x9a, 0x26, 0xcb, 0xc9, 0x12, 0x97, 0xd8, 0x69, - 0x2c, 0x4d, 0xb8, 0x31, 0xe8, 0x33, 0x80, 0xe7, 0x6b, 0x03, 0x47, 0x77, 0x4f, 0xb4, 0x1e, 0xb7, - 0xe3, 0xa0, 0x3d, 0x2b, 0xcd, 0x07, 0x5f, 0xb7, 0xc1, 0xd7, 0xd0, 0xf3, 0x69, 0x83, 0x33, 0x6a, - 0x7a, 0xd5, 0x45, 0xe2, 0x9d, 0xfa, 0x52, 0x76, 0xd1, 0x57, 0x00, 0x2f, 0x1e, 0xd9, 0x21, 0xba, - 0x37, 0x4d, 0xbc, 0x31, 0xd7, 0x26, 0xb8, 0x3f, 0x3b, 0xf1, 0x7f, 0x3a, 0xab, 0xf7, 0x82, 0x77, - 0xaa, 0x9d, 0xee, 0xae, 0x76, 0xf6, 0x86, 0x21, 0xd8, 0x1f, 0x86, 0xe0, 0xe7, 0x30, 0x04, 0xef, - 0x46, 0x61, 0x63, 0x7f, 0x14, 0x36, 0xbe, 0x8d, 0xc2, 0xc6, 0xcb, 0x36, 0xe3, 0x66, 0xa3, 0x48, - 0xe3, 0xbe, 0xcc, 0x8e, 0xb5, 0x7b, 0x53, 0x33, 0x34, 0xa5, 0xa2, 0x3a, 0x6d, 0xda, 0x27, 0xe3, - 0xce, 0x9f, 0x00, 0x00, 0x00, 0xff, 0xff, 0xd9, 0x53, 0x57, 0x8b, 0x14, 0x05, 0x00, 0x00, + // 659 bytes of a gzipped FileDescriptorProto + 0x1f, 0x8b, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0xff, 0xac, 0x56, 0x4f, 0x6b, 0x13, 0x4f, + 0x18, 0xce, 0x16, 0x7e, 0x85, 0xce, 0x4f, 0x90, 0x4e, 0x62, 0x09, 0x8b, 0x6c, 0xeb, 0xfa, 0x97, + 0x40, 0x77, 0xba, 0x2d, 0x54, 0xf0, 0x7f, 0x2b, 0xe2, 0x41, 0x2a, 0x31, 0xa5, 0x1e, 0x5a, 0xcb, + 0x3a, 0x9b, 0x0c, 0xdb, 0xa5, 0xc9, 0xce, 0x76, 0x67, 0x37, 0xb8, 0x94, 0x80, 0x78, 0xf0, 0x2c, + 0x78, 0xf0, 0xec, 0xcd, 0xa3, 0x1f, 0xa3, 0xc7, 0x82, 0x17, 0x4f, 0x22, 0x89, 0x20, 0x78, 0xf2, + 0x23, 0x48, 0x66, 0x67, 0x75, 0xd7, 0xec, 0xa6, 0x49, 0xea, 0x25, 0x0c, 0xf3, 0xbe, 0xcf, 0xf3, + 0x3e, 0xcf, 0x4b, 0x9e, 0x61, 0xc1, 0x15, 0x37, 0x68, 0x32, 0xec, 0xd5, 0xf7, 0xb0, 0xed, 0xa0, + 0x7d, 0x12, 0x7a, 0xc4, 0xb2, 0x99, 0xef, 0x85, 0xa8, 0xad, 0xa3, 0x83, 0x80, 0x78, 0xa1, 0xe6, + 0x7a, 0xd4, 0xa7, 0x50, 0x4e, 0xf4, 0x69, 0x89, 0x3e, 0xad, 0xad, 0xcb, 0xb3, 0xb8, 0x65, 0x3b, + 0x14, 0xf1, 0xdf, 0xa8, 0x5d, 0xae, 0xd4, 0x29, 0x6b, 0x51, 0x86, 0x4c, 0xcc, 0x48, 0xc4, 0x83, + 0xda, 0xba, 0x49, 0x7c, 0xac, 0x23, 0x17, 0x5b, 0xb6, 0x83, 0x7d, 0x9b, 0x3a, 0xa2, 0xb7, 0x64, + 0x51, 0x8b, 0xf2, 0x23, 0xea, 0x9f, 0xc4, 0xed, 0x79, 0x8b, 0x52, 0xab, 0x49, 0x10, 0x76, 0x6d, + 0x84, 0x1d, 0x87, 0xfa, 0x1c, 0xc2, 0x44, 0xf5, 0xea, 0x10, 0xd9, 0x2e, 0xf6, 0x70, 0x4b, 0x34, + 0xaa, 0x25, 0x00, 0x9f, 0xf4, 0xc7, 0x57, 0xf9, 0x65, 0x8d, 0x1c, 0x04, 0x84, 0xf9, 0xea, 0x33, + 0x50, 0x4c, 0xdd, 0x32, 0x97, 0x3a, 0x8c, 0xc0, 0x07, 0x60, 0x3a, 0x02, 0x97, 0xa5, 0x05, 0xe9, + 0xda, 0xff, 0xcb, 0xaa, 0x96, 0xef, 0x5a, 0x8b, 0xb0, 0xeb, 0x33, 0x47, 0x5f, 0xe6, 0x0b, 0x1f, + 0xbe, 0x7f, 0xac, 0x48, 0x35, 0x01, 0x56, 0xab, 0x40, 0xe1, 0xec, 0x0f, 0x89, 0xbf, 0xc5, 0x88, + 0xb7, 0x61, 0x3b, 0x78, 0xad, 0xd1, 0xf0, 0x08, 0x8b, 0xe7, 0x43, 0x0d, 0x14, 0x03, 0x46, 0x3c, + 0x23, 0xda, 0x92, 0x81, 0xa3, 0x2a, 0x9f, 0x7a, 0xa6, 0x36, 0xdb, 0x2f, 0xdd, 0xe7, 0x15, 0x01, + 0x53, 0x37, 0xc0, 0x7c, 0x2e, 0xa3, 0xd0, 0x5e, 0x01, 0x1c, 0x67, 0xb4, 0x6c, 0x07, 0xff, 0x45, + 0x78, 0x36, 0x48, 0x63, 0xd4, 0xc7, 0x60, 0x21, 0x49, 0x97, 0x9a, 0x15, 0x4b, 0x1c, 0x87, 0x6f, + 0x13, 0x5c, 0x18, 0xc2, 0x27, 0x04, 0x8e, 0xeb, 0x79, 0x17, 0xa8, 0x31, 0xe9, 0x53, 0xdc, 0xb4, + 0x1b, 0xd8, 0xa7, 0x7c, 0x68, 0x35, 0x30, 0x1f, 0x91, 0x30, 0x96, 0x79, 0x1d, 0x94, 0xdb, 0x71, + 0x35, 0xa6, 0x76, 0x03, 0xd3, 0xd8, 0x27, 0xa1, 0xa0, 0x3e, 0xf7, 0xbb, 0x1e, 0xf1, 0x47, 0x78, + 0x75, 0x1b, 0x5c, 0x1c, 0x4a, 0x2f, 0x54, 0xaf, 0x80, 0xb9, 0x3f, 0xfc, 0x7c, 0x17, 0x69, 0xf6, + 0x62, 0x7b, 0x10, 0xac, 0xee, 0x80, 0x4b, 0x03, 0xdc, 0xc9, 0xe1, 0xb1, 0xf8, 0x89, 0xc8, 0x9f, + 0x83, 0xcb, 0x27, 0x90, 0x0b, 0xe9, 0x93, 0xae, 0x66, 0xf9, 0xdd, 0x0c, 0xf8, 0x8f, 0x8f, 0x80, + 0xef, 0x25, 0x30, 0x1d, 0xfd, 0xcf, 0xa1, 0x36, 0x2c, 0x0b, 0x83, 0x11, 0x93, 0xd1, 0xc8, 0xfd, + 0x91, 0x5c, 0x75, 0xf5, 0xd5, 0xa7, 0x6f, 0x6f, 0xa7, 0x96, 0xa0, 0x86, 0x1c, 0xda, 0x20, 0xfa, + 0x92, 0xbe, 0x68, 0x53, 0x14, 0x71, 0x2c, 0x0e, 0xc9, 0x39, 0xfc, 0x21, 0x01, 0x38, 0x98, 0x0b, + 0x78, 0xe3, 0xc4, 0xf9, 0xb9, 0xf1, 0x94, 0x6f, 0x4e, 0x84, 0x15, 0x3e, 0x76, 0xb8, 0x8f, 0x2d, + 0xb8, 0x39, 0xaa, 0x0f, 0x8b, 0xf8, 0xc6, 0x40, 0xd4, 0xd0, 0x61, 0x46, 0x58, 0x3a, 0xf0, 0xa7, + 0x04, 0x4a, 0x59, 0x29, 0x83, 0xb7, 0x46, 0x95, 0x9c, 0x15, 0x76, 0xf9, 0xf6, 0x84, 0xe8, 0x53, + 0x5b, 0x4e, 0xfb, 0x13, 0xa6, 0x93, 0x7b, 0xe8, 0xc0, 0x97, 0x53, 0x60, 0x2e, 0x3b, 0xa4, 0xf0, + 0xce, 0x28, 0xb2, 0xf3, 0x1f, 0x0f, 0xf9, 0xee, 0xc4, 0x78, 0x61, 0x9c, 0x70, 0xe3, 0x06, 0xdc, + 0x1d, 0xc7, 0x78, 0x76, 0xe4, 0xd1, 0x61, 0x5e, 0x58, 0x3b, 0xf0, 0xf5, 0x14, 0x28, 0xe7, 0xc5, + 0x1d, 0xde, 0x1b, 0xcb, 0x44, 0xc6, 0x33, 0x24, 0xaf, 0x9d, 0x82, 0xe1, 0xdf, 0x2c, 0x22, 0x6d, + 0x38, 0xb9, 0x8a, 0xe4, 0x8a, 0x3a, 0xeb, 0xd5, 0xa3, 0xae, 0x22, 0x1d, 0x77, 0x15, 0xe9, 0x6b, + 0x57, 0x91, 0xde, 0xf4, 0x94, 0xc2, 0x71, 0x4f, 0x29, 0x7c, 0xee, 0x29, 0x85, 0xed, 0x55, 0xcb, + 0xf6, 0xf7, 0x02, 0x53, 0xab, 0xd3, 0x56, 0xae, 0x84, 0x17, 0x29, 0x11, 0x7e, 0xe8, 0x12, 0x66, + 0x4e, 0xf3, 0xcf, 0x84, 0x95, 0x5f, 0x01, 0x00, 0x00, 0xff, 0xff, 0x7c, 0x80, 0x7a, 0xbc, 0x08, + 0x09, 0x00, 0x00, } // Reference imports to suppress errors if they are not otherwise used. @@ -356,10 +551,14 @@ const _ = grpc.SupportPackageIsVersion4 type QueryClient interface { // Parameters queries the parameters of the module. Params(ctx context.Context, in *QueryParamsRequest, opts ...grpc.CallOption) (*QueryParamsResponse, error) - // GetMinaPubKey Queries a list of GetMinaPubKey items. - GetMinaPubKey(ctx context.Context, in *QueryGetMinaPubKeyRequest, opts ...grpc.CallOption) (*QueryGetMinaPubKeyResponse, error) - // GetCosmosPubKey Queries a list of GetCosmosPubKey items. - GetCosmosPubKey(ctx context.Context, in *QueryGetCosmosPubKeyRequest, opts ...grpc.CallOption) (*QueryGetCosmosPubKeyResponse, error) + // GetUserMinaAddress Queries a list of GetUserMinaAddress items. + GetUserMinaAddress(ctx context.Context, in *QueryGetUserMinaAddressRequest, opts ...grpc.CallOption) (*QueryGetUserMinaAddressResponse, error) + // GetUserCosmosAddress Queries a list of GetUserCosmosAddress items. + GetUserCosmosAddress(ctx context.Context, in *QueryGetUserCosmosAddressRequest, opts ...grpc.CallOption) (*QueryGetUserCosmosAddressResponse, error) + // GetValidatorMinaAddress Queries a list of GetValidatorMinaAddress items. + GetValidatorMinaPubKey(ctx context.Context, in *QueryGetValidatorMinaPubKeyRequest, opts ...grpc.CallOption) (*QueryGetValidatorMinaPubKeyResponse, error) + // GetValidatorCosmosAddress Queries a list of GetValidatorCosmosAddress items. + GetValidatorCosmosPubKey(ctx context.Context, in *QueryGetValidatorCosmosPubKeyRequest, opts ...grpc.CallOption) (*QueryGetValidatorCosmosPubKeyResponse, error) } type queryClient struct { @@ -379,18 +578,36 @@ func (c *queryClient) Params(ctx context.Context, in *QueryParamsRequest, opts . return out, nil } -func (c *queryClient) GetMinaPubKey(ctx context.Context, in *QueryGetMinaPubKeyRequest, opts ...grpc.CallOption) (*QueryGetMinaPubKeyResponse, error) { - out := new(QueryGetMinaPubKeyResponse) - err := c.cc.Invoke(ctx, "/pulsarchain.keyregistry.v1.Query/GetMinaPubKey", in, out, opts...) +func (c *queryClient) GetUserMinaAddress(ctx context.Context, in *QueryGetUserMinaAddressRequest, opts ...grpc.CallOption) (*QueryGetUserMinaAddressResponse, error) { + out := new(QueryGetUserMinaAddressResponse) + err := c.cc.Invoke(ctx, "/pulsarchain.keyregistry.v1.Query/GetUserMinaAddress", in, out, opts...) + if err != nil { + return nil, err + } + return out, nil +} + +func (c *queryClient) GetUserCosmosAddress(ctx context.Context, in *QueryGetUserCosmosAddressRequest, opts ...grpc.CallOption) (*QueryGetUserCosmosAddressResponse, error) { + out := new(QueryGetUserCosmosAddressResponse) + err := c.cc.Invoke(ctx, "/pulsarchain.keyregistry.v1.Query/GetUserCosmosAddress", in, out, opts...) + if err != nil { + return nil, err + } + return out, nil +} + +func (c *queryClient) GetValidatorMinaPubKey(ctx context.Context, in *QueryGetValidatorMinaPubKeyRequest, opts ...grpc.CallOption) (*QueryGetValidatorMinaPubKeyResponse, error) { + out := new(QueryGetValidatorMinaPubKeyResponse) + err := c.cc.Invoke(ctx, "/pulsarchain.keyregistry.v1.Query/GetValidatorMinaPubKey", in, out, opts...) if err != nil { return nil, err } return out, nil } -func (c *queryClient) GetCosmosPubKey(ctx context.Context, in *QueryGetCosmosPubKeyRequest, opts ...grpc.CallOption) (*QueryGetCosmosPubKeyResponse, error) { - out := new(QueryGetCosmosPubKeyResponse) - err := c.cc.Invoke(ctx, "/pulsarchain.keyregistry.v1.Query/GetCosmosPubKey", in, out, opts...) +func (c *queryClient) GetValidatorCosmosPubKey(ctx context.Context, in *QueryGetValidatorCosmosPubKeyRequest, opts ...grpc.CallOption) (*QueryGetValidatorCosmosPubKeyResponse, error) { + out := new(QueryGetValidatorCosmosPubKeyResponse) + err := c.cc.Invoke(ctx, "/pulsarchain.keyregistry.v1.Query/GetValidatorCosmosPubKey", in, out, opts...) if err != nil { return nil, err } @@ -401,10 +618,14 @@ func (c *queryClient) GetCosmosPubKey(ctx context.Context, in *QueryGetCosmosPub type QueryServer interface { // Parameters queries the parameters of the module. Params(context.Context, *QueryParamsRequest) (*QueryParamsResponse, error) - // GetMinaPubKey Queries a list of GetMinaPubKey items. - GetMinaPubKey(context.Context, *QueryGetMinaPubKeyRequest) (*QueryGetMinaPubKeyResponse, error) - // GetCosmosPubKey Queries a list of GetCosmosPubKey items. - GetCosmosPubKey(context.Context, *QueryGetCosmosPubKeyRequest) (*QueryGetCosmosPubKeyResponse, error) + // GetUserMinaAddress Queries a list of GetUserMinaAddress items. + GetUserMinaAddress(context.Context, *QueryGetUserMinaAddressRequest) (*QueryGetUserMinaAddressResponse, error) + // GetUserCosmosAddress Queries a list of GetUserCosmosAddress items. + GetUserCosmosAddress(context.Context, *QueryGetUserCosmosAddressRequest) (*QueryGetUserCosmosAddressResponse, error) + // GetValidatorMinaAddress Queries a list of GetValidatorMinaAddress items. + GetValidatorMinaPubKey(context.Context, *QueryGetValidatorMinaPubKeyRequest) (*QueryGetValidatorMinaPubKeyResponse, error) + // GetValidatorCosmosAddress Queries a list of GetValidatorCosmosAddress items. + GetValidatorCosmosPubKey(context.Context, *QueryGetValidatorCosmosPubKeyRequest) (*QueryGetValidatorCosmosPubKeyResponse, error) } // UnimplementedQueryServer can be embedded to have forward compatible implementations. @@ -414,11 +635,17 @@ type UnimplementedQueryServer struct { func (*UnimplementedQueryServer) Params(ctx context.Context, req *QueryParamsRequest) (*QueryParamsResponse, error) { return nil, status.Errorf(codes.Unimplemented, "method Params not implemented") } -func (*UnimplementedQueryServer) GetMinaPubKey(ctx context.Context, req *QueryGetMinaPubKeyRequest) (*QueryGetMinaPubKeyResponse, error) { - return nil, status.Errorf(codes.Unimplemented, "method GetMinaPubKey not implemented") +func (*UnimplementedQueryServer) GetUserMinaAddress(ctx context.Context, req *QueryGetUserMinaAddressRequest) (*QueryGetUserMinaAddressResponse, error) { + return nil, status.Errorf(codes.Unimplemented, "method GetUserMinaAddress not implemented") } -func (*UnimplementedQueryServer) GetCosmosPubKey(ctx context.Context, req *QueryGetCosmosPubKeyRequest) (*QueryGetCosmosPubKeyResponse, error) { - return nil, status.Errorf(codes.Unimplemented, "method GetCosmosPubKey not implemented") +func (*UnimplementedQueryServer) GetUserCosmosAddress(ctx context.Context, req *QueryGetUserCosmosAddressRequest) (*QueryGetUserCosmosAddressResponse, error) { + return nil, status.Errorf(codes.Unimplemented, "method GetUserCosmosAddress not implemented") +} +func (*UnimplementedQueryServer) GetValidatorMinaPubKey(ctx context.Context, req *QueryGetValidatorMinaPubKeyRequest) (*QueryGetValidatorMinaPubKeyResponse, error) { + return nil, status.Errorf(codes.Unimplemented, "method GetValidatorMinaPubKey not implemented") +} +func (*UnimplementedQueryServer) GetValidatorCosmosPubKey(ctx context.Context, req *QueryGetValidatorCosmosPubKeyRequest) (*QueryGetValidatorCosmosPubKeyResponse, error) { + return nil, status.Errorf(codes.Unimplemented, "method GetValidatorCosmosPubKey not implemented") } func RegisterQueryServer(s grpc1.Server, srv QueryServer) { @@ -443,38 +670,74 @@ func _Query_Params_Handler(srv interface{}, ctx context.Context, dec func(interf return interceptor(ctx, in, info, handler) } -func _Query_GetMinaPubKey_Handler(srv interface{}, ctx context.Context, dec func(interface{}) error, interceptor grpc.UnaryServerInterceptor) (interface{}, error) { - in := new(QueryGetMinaPubKeyRequest) +func _Query_GetUserMinaAddress_Handler(srv interface{}, ctx context.Context, dec func(interface{}) error, interceptor grpc.UnaryServerInterceptor) (interface{}, error) { + in := new(QueryGetUserMinaAddressRequest) + if err := dec(in); err != nil { + return nil, err + } + if interceptor == nil { + return srv.(QueryServer).GetUserMinaAddress(ctx, in) + } + info := &grpc.UnaryServerInfo{ + Server: srv, + FullMethod: "/pulsarchain.keyregistry.v1.Query/GetUserMinaAddress", + } + handler := func(ctx context.Context, req interface{}) (interface{}, error) { + return srv.(QueryServer).GetUserMinaAddress(ctx, req.(*QueryGetUserMinaAddressRequest)) + } + return interceptor(ctx, in, info, handler) +} + +func _Query_GetUserCosmosAddress_Handler(srv interface{}, ctx context.Context, dec func(interface{}) error, interceptor grpc.UnaryServerInterceptor) (interface{}, error) { + in := new(QueryGetUserCosmosAddressRequest) + if err := dec(in); err != nil { + return nil, err + } + if interceptor == nil { + return srv.(QueryServer).GetUserCosmosAddress(ctx, in) + } + info := &grpc.UnaryServerInfo{ + Server: srv, + FullMethod: "/pulsarchain.keyregistry.v1.Query/GetUserCosmosAddress", + } + handler := func(ctx context.Context, req interface{}) (interface{}, error) { + return srv.(QueryServer).GetUserCosmosAddress(ctx, req.(*QueryGetUserCosmosAddressRequest)) + } + return interceptor(ctx, in, info, handler) +} + +func _Query_GetValidatorMinaPubKey_Handler(srv interface{}, ctx context.Context, dec func(interface{}) error, interceptor grpc.UnaryServerInterceptor) (interface{}, error) { + in := new(QueryGetValidatorMinaPubKeyRequest) if err := dec(in); err != nil { return nil, err } if interceptor == nil { - return srv.(QueryServer).GetMinaPubKey(ctx, in) + return srv.(QueryServer).GetValidatorMinaPubKey(ctx, in) } info := &grpc.UnaryServerInfo{ Server: srv, - FullMethod: "/pulsarchain.keyregistry.v1.Query/GetMinaPubKey", + FullMethod: "/pulsarchain.keyregistry.v1.Query/GetValidatorMinaPubKey", } handler := func(ctx context.Context, req interface{}) (interface{}, error) { - return srv.(QueryServer).GetMinaPubKey(ctx, req.(*QueryGetMinaPubKeyRequest)) + return srv.(QueryServer).GetValidatorMinaPubKey(ctx, req.(*QueryGetValidatorMinaPubKeyRequest)) } return interceptor(ctx, in, info, handler) } -func _Query_GetCosmosPubKey_Handler(srv interface{}, ctx context.Context, dec func(interface{}) error, interceptor grpc.UnaryServerInterceptor) (interface{}, error) { - in := new(QueryGetCosmosPubKeyRequest) +func _Query_GetValidatorCosmosPubKey_Handler(srv interface{}, ctx context.Context, dec func(interface{}) error, interceptor grpc.UnaryServerInterceptor) (interface{}, error) { + in := new(QueryGetValidatorCosmosPubKeyRequest) if err := dec(in); err != nil { return nil, err } if interceptor == nil { - return srv.(QueryServer).GetCosmosPubKey(ctx, in) + return srv.(QueryServer).GetValidatorCosmosPubKey(ctx, in) } info := &grpc.UnaryServerInfo{ Server: srv, - FullMethod: "/pulsarchain.keyregistry.v1.Query/GetCosmosPubKey", + FullMethod: "/pulsarchain.keyregistry.v1.Query/GetValidatorCosmosPubKey", } handler := func(ctx context.Context, req interface{}) (interface{}, error) { - return srv.(QueryServer).GetCosmosPubKey(ctx, req.(*QueryGetCosmosPubKeyRequest)) + return srv.(QueryServer).GetValidatorCosmosPubKey(ctx, req.(*QueryGetValidatorCosmosPubKeyRequest)) } return interceptor(ctx, in, info, handler) } @@ -489,12 +752,20 @@ var _Query_serviceDesc = grpc.ServiceDesc{ Handler: _Query_Params_Handler, }, { - MethodName: "GetMinaPubKey", - Handler: _Query_GetMinaPubKey_Handler, + MethodName: "GetUserMinaAddress", + Handler: _Query_GetUserMinaAddress_Handler, }, { - MethodName: "GetCosmosPubKey", - Handler: _Query_GetCosmosPubKey_Handler, + MethodName: "GetUserCosmosAddress", + Handler: _Query_GetUserCosmosAddress_Handler, + }, + { + MethodName: "GetValidatorMinaPubKey", + Handler: _Query_GetValidatorMinaPubKey_Handler, + }, + { + MethodName: "GetValidatorCosmosPubKey", + Handler: _Query_GetValidatorCosmosPubKey_Handler, }, }, Streams: []grpc.StreamDesc{}, @@ -557,7 +828,127 @@ func (m *QueryParamsResponse) MarshalToSizedBuffer(dAtA []byte) (int, error) { return len(dAtA) - i, nil } -func (m *QueryGetMinaPubKeyRequest) Marshal() (dAtA []byte, err error) { +func (m *QueryGetUserMinaAddressRequest) 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 *QueryGetUserMinaAddressRequest) MarshalTo(dAtA []byte) (int, error) { + size := m.Size() + return m.MarshalToSizedBuffer(dAtA[:size]) +} + +func (m *QueryGetUserMinaAddressRequest) MarshalToSizedBuffer(dAtA []byte) (int, error) { + i := len(dAtA) + _ = i + var l int + _ = l + if len(m.UserCosmosAddress) > 0 { + i -= len(m.UserCosmosAddress) + copy(dAtA[i:], m.UserCosmosAddress) + i = encodeVarintQuery(dAtA, i, uint64(len(m.UserCosmosAddress))) + i-- + dAtA[i] = 0xa + } + return len(dAtA) - i, nil +} + +func (m *QueryGetUserMinaAddressResponse) 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 *QueryGetUserMinaAddressResponse) MarshalTo(dAtA []byte) (int, error) { + size := m.Size() + return m.MarshalToSizedBuffer(dAtA[:size]) +} + +func (m *QueryGetUserMinaAddressResponse) MarshalToSizedBuffer(dAtA []byte) (int, error) { + i := len(dAtA) + _ = i + var l int + _ = l + if len(m.UserMinaAddress) > 0 { + i -= len(m.UserMinaAddress) + copy(dAtA[i:], m.UserMinaAddress) + i = encodeVarintQuery(dAtA, i, uint64(len(m.UserMinaAddress))) + i-- + dAtA[i] = 0xa + } + return len(dAtA) - i, nil +} + +func (m *QueryGetUserCosmosAddressRequest) 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 *QueryGetUserCosmosAddressRequest) MarshalTo(dAtA []byte) (int, error) { + size := m.Size() + return m.MarshalToSizedBuffer(dAtA[:size]) +} + +func (m *QueryGetUserCosmosAddressRequest) MarshalToSizedBuffer(dAtA []byte) (int, error) { + i := len(dAtA) + _ = i + var l int + _ = l + if len(m.UserMinaAddress) > 0 { + i -= len(m.UserMinaAddress) + copy(dAtA[i:], m.UserMinaAddress) + i = encodeVarintQuery(dAtA, i, uint64(len(m.UserMinaAddress))) + i-- + dAtA[i] = 0xa + } + return len(dAtA) - i, nil +} + +func (m *QueryGetUserCosmosAddressResponse) 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 *QueryGetUserCosmosAddressResponse) MarshalTo(dAtA []byte) (int, error) { + size := m.Size() + return m.MarshalToSizedBuffer(dAtA[:size]) +} + +func (m *QueryGetUserCosmosAddressResponse) MarshalToSizedBuffer(dAtA []byte) (int, error) { + i := len(dAtA) + _ = i + var l int + _ = l + if len(m.UserCosmosAddress) > 0 { + i -= len(m.UserCosmosAddress) + copy(dAtA[i:], m.UserCosmosAddress) + i = encodeVarintQuery(dAtA, i, uint64(len(m.UserCosmosAddress))) + i-- + dAtA[i] = 0xa + } + return len(dAtA) - i, nil +} + +func (m *QueryGetValidatorMinaPubKeyRequest) Marshal() (dAtA []byte, err error) { size := m.Size() dAtA = make([]byte, size) n, err := m.MarshalToSizedBuffer(dAtA[:size]) @@ -567,27 +958,27 @@ func (m *QueryGetMinaPubKeyRequest) Marshal() (dAtA []byte, err error) { return dAtA[:n], nil } -func (m *QueryGetMinaPubKeyRequest) MarshalTo(dAtA []byte) (int, error) { +func (m *QueryGetValidatorMinaPubKeyRequest) MarshalTo(dAtA []byte) (int, error) { size := m.Size() return m.MarshalToSizedBuffer(dAtA[:size]) } -func (m *QueryGetMinaPubKeyRequest) MarshalToSizedBuffer(dAtA []byte) (int, error) { +func (m *QueryGetValidatorMinaPubKeyRequest) MarshalToSizedBuffer(dAtA []byte) (int, error) { i := len(dAtA) _ = i var l int _ = l - if len(m.CosmosPubKey) > 0 { - i -= len(m.CosmosPubKey) - copy(dAtA[i:], m.CosmosPubKey) - i = encodeVarintQuery(dAtA, i, uint64(len(m.CosmosPubKey))) + if len(m.ValidatorCosmosPubKey) > 0 { + i -= len(m.ValidatorCosmosPubKey) + copy(dAtA[i:], m.ValidatorCosmosPubKey) + i = encodeVarintQuery(dAtA, i, uint64(len(m.ValidatorCosmosPubKey))) i-- dAtA[i] = 0xa } return len(dAtA) - i, nil } -func (m *QueryGetMinaPubKeyResponse) Marshal() (dAtA []byte, err error) { +func (m *QueryGetValidatorMinaPubKeyResponse) Marshal() (dAtA []byte, err error) { size := m.Size() dAtA = make([]byte, size) n, err := m.MarshalToSizedBuffer(dAtA[:size]) @@ -597,27 +988,27 @@ func (m *QueryGetMinaPubKeyResponse) Marshal() (dAtA []byte, err error) { return dAtA[:n], nil } -func (m *QueryGetMinaPubKeyResponse) MarshalTo(dAtA []byte) (int, error) { +func (m *QueryGetValidatorMinaPubKeyResponse) MarshalTo(dAtA []byte) (int, error) { size := m.Size() return m.MarshalToSizedBuffer(dAtA[:size]) } -func (m *QueryGetMinaPubKeyResponse) MarshalToSizedBuffer(dAtA []byte) (int, error) { +func (m *QueryGetValidatorMinaPubKeyResponse) MarshalToSizedBuffer(dAtA []byte) (int, error) { i := len(dAtA) _ = i var l int _ = l - if len(m.MinaPubKey) > 0 { - i -= len(m.MinaPubKey) - copy(dAtA[i:], m.MinaPubKey) - i = encodeVarintQuery(dAtA, i, uint64(len(m.MinaPubKey))) + if len(m.ValidatorMinaPubKey) > 0 { + i -= len(m.ValidatorMinaPubKey) + copy(dAtA[i:], m.ValidatorMinaPubKey) + i = encodeVarintQuery(dAtA, i, uint64(len(m.ValidatorMinaPubKey))) i-- dAtA[i] = 0xa } return len(dAtA) - i, nil } -func (m *QueryGetCosmosPubKeyRequest) Marshal() (dAtA []byte, err error) { +func (m *QueryGetValidatorCosmosPubKeyRequest) Marshal() (dAtA []byte, err error) { size := m.Size() dAtA = make([]byte, size) n, err := m.MarshalToSizedBuffer(dAtA[:size]) @@ -627,27 +1018,27 @@ func (m *QueryGetCosmosPubKeyRequest) Marshal() (dAtA []byte, err error) { return dAtA[:n], nil } -func (m *QueryGetCosmosPubKeyRequest) MarshalTo(dAtA []byte) (int, error) { +func (m *QueryGetValidatorCosmosPubKeyRequest) MarshalTo(dAtA []byte) (int, error) { size := m.Size() return m.MarshalToSizedBuffer(dAtA[:size]) } -func (m *QueryGetCosmosPubKeyRequest) MarshalToSizedBuffer(dAtA []byte) (int, error) { +func (m *QueryGetValidatorCosmosPubKeyRequest) MarshalToSizedBuffer(dAtA []byte) (int, error) { i := len(dAtA) _ = i var l int _ = l - if len(m.MinaPubKey) > 0 { - i -= len(m.MinaPubKey) - copy(dAtA[i:], m.MinaPubKey) - i = encodeVarintQuery(dAtA, i, uint64(len(m.MinaPubKey))) + if len(m.ValidatorMinaPubKey) > 0 { + i -= len(m.ValidatorMinaPubKey) + copy(dAtA[i:], m.ValidatorMinaPubKey) + i = encodeVarintQuery(dAtA, i, uint64(len(m.ValidatorMinaPubKey))) i-- dAtA[i] = 0xa } return len(dAtA) - i, nil } -func (m *QueryGetCosmosPubKeyResponse) Marshal() (dAtA []byte, err error) { +func (m *QueryGetValidatorCosmosPubKeyResponse) Marshal() (dAtA []byte, err error) { size := m.Size() dAtA = make([]byte, size) n, err := m.MarshalToSizedBuffer(dAtA[:size]) @@ -657,20 +1048,20 @@ func (m *QueryGetCosmosPubKeyResponse) Marshal() (dAtA []byte, err error) { return dAtA[:n], nil } -func (m *QueryGetCosmosPubKeyResponse) MarshalTo(dAtA []byte) (int, error) { +func (m *QueryGetValidatorCosmosPubKeyResponse) MarshalTo(dAtA []byte) (int, error) { size := m.Size() return m.MarshalToSizedBuffer(dAtA[:size]) } -func (m *QueryGetCosmosPubKeyResponse) MarshalToSizedBuffer(dAtA []byte) (int, error) { +func (m *QueryGetValidatorCosmosPubKeyResponse) MarshalToSizedBuffer(dAtA []byte) (int, error) { i := len(dAtA) _ = i var l int _ = l - if len(m.CosmosPubKey) > 0 { - i -= len(m.CosmosPubKey) - copy(dAtA[i:], m.CosmosPubKey) - i = encodeVarintQuery(dAtA, i, uint64(len(m.CosmosPubKey))) + if len(m.ValidatorCosmosPubKey) > 0 { + i -= len(m.ValidatorCosmosPubKey) + copy(dAtA[i:], m.ValidatorCosmosPubKey) + i = encodeVarintQuery(dAtA, i, uint64(len(m.ValidatorCosmosPubKey))) i-- dAtA[i] = 0xa } @@ -708,66 +1099,118 @@ func (m *QueryParamsResponse) Size() (n int) { return n } -func (m *QueryGetMinaPubKeyRequest) Size() (n int) { +func (m *QueryGetUserMinaAddressRequest) Size() (n int) { if m == nil { return 0 } var l int _ = l - l = len(m.CosmosPubKey) + l = len(m.UserCosmosAddress) if l > 0 { n += 1 + l + sovQuery(uint64(l)) } return n } -func (m *QueryGetMinaPubKeyResponse) Size() (n int) { +func (m *QueryGetUserMinaAddressResponse) Size() (n int) { if m == nil { return 0 } var l int _ = l - l = len(m.MinaPubKey) + l = len(m.UserMinaAddress) if l > 0 { n += 1 + l + sovQuery(uint64(l)) } return n } -func (m *QueryGetCosmosPubKeyRequest) Size() (n int) { +func (m *QueryGetUserCosmosAddressRequest) Size() (n int) { if m == nil { return 0 } var l int _ = l - l = len(m.MinaPubKey) + l = len(m.UserMinaAddress) if l > 0 { n += 1 + l + sovQuery(uint64(l)) } return n } -func (m *QueryGetCosmosPubKeyResponse) Size() (n int) { +func (m *QueryGetUserCosmosAddressResponse) Size() (n int) { if m == nil { return 0 } var l int _ = l - l = len(m.CosmosPubKey) + l = len(m.UserCosmosAddress) if l > 0 { n += 1 + l + sovQuery(uint64(l)) } return n } -func sovQuery(x uint64) (n int) { - return (math_bits.Len64(x|1) + 6) / 7 -} -func sozQuery(x uint64) (n int) { - return sovQuery(uint64((x << 1) ^ uint64((int64(x) >> 63)))) +func (m *QueryGetValidatorMinaPubKeyRequest) Size() (n int) { + if m == nil { + return 0 + } + var l int + _ = l + l = len(m.ValidatorCosmosPubKey) + if l > 0 { + n += 1 + l + sovQuery(uint64(l)) + } + return n } -func (m *QueryParamsRequest) Unmarshal(dAtA []byte) error { - l := len(dAtA) + +func (m *QueryGetValidatorMinaPubKeyResponse) Size() (n int) { + if m == nil { + return 0 + } + var l int + _ = l + l = len(m.ValidatorMinaPubKey) + if l > 0 { + n += 1 + l + sovQuery(uint64(l)) + } + return n +} + +func (m *QueryGetValidatorCosmosPubKeyRequest) Size() (n int) { + if m == nil { + return 0 + } + var l int + _ = l + l = len(m.ValidatorMinaPubKey) + if l > 0 { + n += 1 + l + sovQuery(uint64(l)) + } + return n +} + +func (m *QueryGetValidatorCosmosPubKeyResponse) Size() (n int) { + if m == nil { + return 0 + } + var l int + _ = l + l = len(m.ValidatorCosmosPubKey) + if l > 0 { + n += 1 + l + sovQuery(uint64(l)) + } + return n +} + +func sovQuery(x uint64) (n int) { + return (math_bits.Len64(x|1) + 6) / 7 +} +func sozQuery(x uint64) (n int) { + return sovQuery(uint64((x << 1) ^ uint64((int64(x) >> 63)))) +} +func (m *QueryParamsRequest) Unmarshal(dAtA []byte) error { + l := len(dAtA) iNdEx := 0 for iNdEx < l { preIndex := iNdEx @@ -899,7 +1342,343 @@ func (m *QueryParamsResponse) Unmarshal(dAtA []byte) error { } return nil } -func (m *QueryGetMinaPubKeyRequest) Unmarshal(dAtA []byte) error { +func (m *QueryGetUserMinaAddressRequest) 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: QueryGetUserMinaAddressRequest: wiretype end group for non-group") + } + if fieldNum <= 0 { + return fmt.Errorf("proto: QueryGetUserMinaAddressRequest: illegal tag %d (wire type %d)", fieldNum, wire) + } + switch fieldNum { + case 1: + if wireType != 2 { + return fmt.Errorf("proto: wrong wireType = %d for field UserCosmosAddress", wireType) + } + var byteLen int + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowQuery + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + byteLen |= int(b&0x7F) << shift + if b < 0x80 { + break + } + } + if byteLen < 0 { + return ErrInvalidLengthQuery + } + postIndex := iNdEx + byteLen + if postIndex < 0 { + return ErrInvalidLengthQuery + } + if postIndex > l { + return io.ErrUnexpectedEOF + } + m.UserCosmosAddress = append(m.UserCosmosAddress[:0], dAtA[iNdEx:postIndex]...) + if m.UserCosmosAddress == nil { + m.UserCosmosAddress = []byte{} + } + 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 (m *QueryGetUserMinaAddressResponse) 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: QueryGetUserMinaAddressResponse: wiretype end group for non-group") + } + if fieldNum <= 0 { + return fmt.Errorf("proto: QueryGetUserMinaAddressResponse: illegal tag %d (wire type %d)", fieldNum, wire) + } + switch fieldNum { + case 1: + if wireType != 2 { + return fmt.Errorf("proto: wrong wireType = %d for field UserMinaAddress", wireType) + } + var byteLen int + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowQuery + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + byteLen |= int(b&0x7F) << shift + if b < 0x80 { + break + } + } + if byteLen < 0 { + return ErrInvalidLengthQuery + } + postIndex := iNdEx + byteLen + if postIndex < 0 { + return ErrInvalidLengthQuery + } + if postIndex > l { + return io.ErrUnexpectedEOF + } + m.UserMinaAddress = append(m.UserMinaAddress[:0], dAtA[iNdEx:postIndex]...) + if m.UserMinaAddress == nil { + m.UserMinaAddress = []byte{} + } + 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 (m *QueryGetUserCosmosAddressRequest) 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: QueryGetUserCosmosAddressRequest: wiretype end group for non-group") + } + if fieldNum <= 0 { + return fmt.Errorf("proto: QueryGetUserCosmosAddressRequest: illegal tag %d (wire type %d)", fieldNum, wire) + } + switch fieldNum { + case 1: + if wireType != 2 { + return fmt.Errorf("proto: wrong wireType = %d for field UserMinaAddress", wireType) + } + var byteLen int + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowQuery + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + byteLen |= int(b&0x7F) << shift + if b < 0x80 { + break + } + } + if byteLen < 0 { + return ErrInvalidLengthQuery + } + postIndex := iNdEx + byteLen + if postIndex < 0 { + return ErrInvalidLengthQuery + } + if postIndex > l { + return io.ErrUnexpectedEOF + } + m.UserMinaAddress = append(m.UserMinaAddress[:0], dAtA[iNdEx:postIndex]...) + if m.UserMinaAddress == nil { + m.UserMinaAddress = []byte{} + } + 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 (m *QueryGetUserCosmosAddressResponse) 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: QueryGetUserCosmosAddressResponse: wiretype end group for non-group") + } + if fieldNum <= 0 { + return fmt.Errorf("proto: QueryGetUserCosmosAddressResponse: illegal tag %d (wire type %d)", fieldNum, wire) + } + switch fieldNum { + case 1: + if wireType != 2 { + return fmt.Errorf("proto: wrong wireType = %d for field UserCosmosAddress", wireType) + } + var byteLen int + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowQuery + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + byteLen |= int(b&0x7F) << shift + if b < 0x80 { + break + } + } + if byteLen < 0 { + return ErrInvalidLengthQuery + } + postIndex := iNdEx + byteLen + if postIndex < 0 { + return ErrInvalidLengthQuery + } + if postIndex > l { + return io.ErrUnexpectedEOF + } + m.UserCosmosAddress = append(m.UserCosmosAddress[:0], dAtA[iNdEx:postIndex]...) + if m.UserCosmosAddress == nil { + m.UserCosmosAddress = []byte{} + } + 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 (m *QueryGetValidatorMinaPubKeyRequest) Unmarshal(dAtA []byte) error { l := len(dAtA) iNdEx := 0 for iNdEx < l { @@ -922,15 +1701,15 @@ func (m *QueryGetMinaPubKeyRequest) Unmarshal(dAtA []byte) error { fieldNum := int32(wire >> 3) wireType := int(wire & 0x7) if wireType == 4 { - return fmt.Errorf("proto: QueryGetMinaPubKeyRequest: wiretype end group for non-group") + return fmt.Errorf("proto: QueryGetValidatorMinaPubKeyRequest: wiretype end group for non-group") } if fieldNum <= 0 { - return fmt.Errorf("proto: QueryGetMinaPubKeyRequest: illegal tag %d (wire type %d)", fieldNum, wire) + return fmt.Errorf("proto: QueryGetValidatorMinaPubKeyRequest: illegal tag %d (wire type %d)", fieldNum, wire) } switch fieldNum { case 1: if wireType != 2 { - return fmt.Errorf("proto: wrong wireType = %d for field CosmosPubKey", wireType) + return fmt.Errorf("proto: wrong wireType = %d for field ValidatorCosmosPubKey", wireType) } var byteLen int for shift := uint(0); ; shift += 7 { @@ -957,9 +1736,9 @@ func (m *QueryGetMinaPubKeyRequest) Unmarshal(dAtA []byte) error { if postIndex > l { return io.ErrUnexpectedEOF } - m.CosmosPubKey = append(m.CosmosPubKey[:0], dAtA[iNdEx:postIndex]...) - if m.CosmosPubKey == nil { - m.CosmosPubKey = []byte{} + m.ValidatorCosmosPubKey = append(m.ValidatorCosmosPubKey[:0], dAtA[iNdEx:postIndex]...) + if m.ValidatorCosmosPubKey == nil { + m.ValidatorCosmosPubKey = []byte{} } iNdEx = postIndex default: @@ -983,7 +1762,7 @@ func (m *QueryGetMinaPubKeyRequest) Unmarshal(dAtA []byte) error { } return nil } -func (m *QueryGetMinaPubKeyResponse) Unmarshal(dAtA []byte) error { +func (m *QueryGetValidatorMinaPubKeyResponse) Unmarshal(dAtA []byte) error { l := len(dAtA) iNdEx := 0 for iNdEx < l { @@ -1006,15 +1785,15 @@ func (m *QueryGetMinaPubKeyResponse) Unmarshal(dAtA []byte) error { fieldNum := int32(wire >> 3) wireType := int(wire & 0x7) if wireType == 4 { - return fmt.Errorf("proto: QueryGetMinaPubKeyResponse: wiretype end group for non-group") + return fmt.Errorf("proto: QueryGetValidatorMinaPubKeyResponse: wiretype end group for non-group") } if fieldNum <= 0 { - return fmt.Errorf("proto: QueryGetMinaPubKeyResponse: illegal tag %d (wire type %d)", fieldNum, wire) + return fmt.Errorf("proto: QueryGetValidatorMinaPubKeyResponse: illegal tag %d (wire type %d)", fieldNum, wire) } switch fieldNum { case 1: if wireType != 2 { - return fmt.Errorf("proto: wrong wireType = %d for field MinaPubKey", wireType) + return fmt.Errorf("proto: wrong wireType = %d for field ValidatorMinaPubKey", wireType) } var byteLen int for shift := uint(0); ; shift += 7 { @@ -1041,9 +1820,9 @@ func (m *QueryGetMinaPubKeyResponse) Unmarshal(dAtA []byte) error { if postIndex > l { return io.ErrUnexpectedEOF } - m.MinaPubKey = append(m.MinaPubKey[:0], dAtA[iNdEx:postIndex]...) - if m.MinaPubKey == nil { - m.MinaPubKey = []byte{} + m.ValidatorMinaPubKey = append(m.ValidatorMinaPubKey[:0], dAtA[iNdEx:postIndex]...) + if m.ValidatorMinaPubKey == nil { + m.ValidatorMinaPubKey = []byte{} } iNdEx = postIndex default: @@ -1067,7 +1846,7 @@ func (m *QueryGetMinaPubKeyResponse) Unmarshal(dAtA []byte) error { } return nil } -func (m *QueryGetCosmosPubKeyRequest) Unmarshal(dAtA []byte) error { +func (m *QueryGetValidatorCosmosPubKeyRequest) Unmarshal(dAtA []byte) error { l := len(dAtA) iNdEx := 0 for iNdEx < l { @@ -1090,15 +1869,15 @@ func (m *QueryGetCosmosPubKeyRequest) Unmarshal(dAtA []byte) error { fieldNum := int32(wire >> 3) wireType := int(wire & 0x7) if wireType == 4 { - return fmt.Errorf("proto: QueryGetCosmosPubKeyRequest: wiretype end group for non-group") + return fmt.Errorf("proto: QueryGetValidatorCosmosPubKeyRequest: wiretype end group for non-group") } if fieldNum <= 0 { - return fmt.Errorf("proto: QueryGetCosmosPubKeyRequest: illegal tag %d (wire type %d)", fieldNum, wire) + return fmt.Errorf("proto: QueryGetValidatorCosmosPubKeyRequest: illegal tag %d (wire type %d)", fieldNum, wire) } switch fieldNum { case 1: if wireType != 2 { - return fmt.Errorf("proto: wrong wireType = %d for field MinaPubKey", wireType) + return fmt.Errorf("proto: wrong wireType = %d for field ValidatorMinaPubKey", wireType) } var byteLen int for shift := uint(0); ; shift += 7 { @@ -1125,9 +1904,9 @@ func (m *QueryGetCosmosPubKeyRequest) Unmarshal(dAtA []byte) error { if postIndex > l { return io.ErrUnexpectedEOF } - m.MinaPubKey = append(m.MinaPubKey[:0], dAtA[iNdEx:postIndex]...) - if m.MinaPubKey == nil { - m.MinaPubKey = []byte{} + m.ValidatorMinaPubKey = append(m.ValidatorMinaPubKey[:0], dAtA[iNdEx:postIndex]...) + if m.ValidatorMinaPubKey == nil { + m.ValidatorMinaPubKey = []byte{} } iNdEx = postIndex default: @@ -1151,7 +1930,7 @@ func (m *QueryGetCosmosPubKeyRequest) Unmarshal(dAtA []byte) error { } return nil } -func (m *QueryGetCosmosPubKeyResponse) Unmarshal(dAtA []byte) error { +func (m *QueryGetValidatorCosmosPubKeyResponse) Unmarshal(dAtA []byte) error { l := len(dAtA) iNdEx := 0 for iNdEx < l { @@ -1174,15 +1953,15 @@ func (m *QueryGetCosmosPubKeyResponse) Unmarshal(dAtA []byte) error { fieldNum := int32(wire >> 3) wireType := int(wire & 0x7) if wireType == 4 { - return fmt.Errorf("proto: QueryGetCosmosPubKeyResponse: wiretype end group for non-group") + return fmt.Errorf("proto: QueryGetValidatorCosmosPubKeyResponse: wiretype end group for non-group") } if fieldNum <= 0 { - return fmt.Errorf("proto: QueryGetCosmosPubKeyResponse: illegal tag %d (wire type %d)", fieldNum, wire) + return fmt.Errorf("proto: QueryGetValidatorCosmosPubKeyResponse: illegal tag %d (wire type %d)", fieldNum, wire) } switch fieldNum { case 1: if wireType != 2 { - return fmt.Errorf("proto: wrong wireType = %d for field CosmosPubKey", wireType) + return fmt.Errorf("proto: wrong wireType = %d for field ValidatorCosmosPubKey", wireType) } var byteLen int for shift := uint(0); ; shift += 7 { @@ -1209,9 +1988,9 @@ func (m *QueryGetCosmosPubKeyResponse) Unmarshal(dAtA []byte) error { if postIndex > l { return io.ErrUnexpectedEOF } - m.CosmosPubKey = append(m.CosmosPubKey[:0], dAtA[iNdEx:postIndex]...) - if m.CosmosPubKey == nil { - m.CosmosPubKey = []byte{} + m.ValidatorCosmosPubKey = append(m.ValidatorCosmosPubKey[:0], dAtA[iNdEx:postIndex]...) + if m.ValidatorCosmosPubKey == nil { + m.ValidatorCosmosPubKey = []byte{} } iNdEx = postIndex default: diff --git a/x/keyregistry/types/query.pb.gw.go b/x/keyregistry/types/query.pb.gw.go index 0ec64544..0de870c2 100644 --- a/x/keyregistry/types/query.pb.gw.go +++ b/x/keyregistry/types/query.pb.gw.go @@ -51,8 +51,8 @@ func local_request_Query_Params_0(ctx context.Context, marshaler runtime.Marshal } -func request_Query_GetMinaPubKey_0(ctx context.Context, marshaler runtime.Marshaler, client QueryClient, req *http.Request, pathParams map[string]string) (proto.Message, runtime.ServerMetadata, error) { - var protoReq QueryGetMinaPubKeyRequest +func request_Query_GetUserMinaAddress_0(ctx context.Context, marshaler runtime.Marshaler, client QueryClient, req *http.Request, pathParams map[string]string) (proto.Message, runtime.ServerMetadata, error) { + var protoReq QueryGetUserMinaAddressRequest var metadata runtime.ServerMetadata var ( @@ -62,24 +62,24 @@ func request_Query_GetMinaPubKey_0(ctx context.Context, marshaler runtime.Marsha _ = err ) - val, ok = pathParams["cosmos_pub_key"] + val, ok = pathParams["user_cosmos_address"] if !ok { - return nil, metadata, status.Errorf(codes.InvalidArgument, "missing parameter %s", "cosmos_pub_key") + return nil, metadata, status.Errorf(codes.InvalidArgument, "missing parameter %s", "user_cosmos_address") } - protoReq.CosmosPubKey, err = runtime.Bytes(val) + protoReq.UserCosmosAddress, err = runtime.Bytes(val) if err != nil { - return nil, metadata, status.Errorf(codes.InvalidArgument, "type mismatch, parameter: %s, error: %v", "cosmos_pub_key", err) + return nil, metadata, status.Errorf(codes.InvalidArgument, "type mismatch, parameter: %s, error: %v", "user_cosmos_address", err) } - msg, err := client.GetMinaPubKey(ctx, &protoReq, grpc.Header(&metadata.HeaderMD), grpc.Trailer(&metadata.TrailerMD)) + msg, err := client.GetUserMinaAddress(ctx, &protoReq, grpc.Header(&metadata.HeaderMD), grpc.Trailer(&metadata.TrailerMD)) return msg, metadata, err } -func local_request_Query_GetMinaPubKey_0(ctx context.Context, marshaler runtime.Marshaler, server QueryServer, req *http.Request, pathParams map[string]string) (proto.Message, runtime.ServerMetadata, error) { - var protoReq QueryGetMinaPubKeyRequest +func local_request_Query_GetUserMinaAddress_0(ctx context.Context, marshaler runtime.Marshaler, server QueryServer, req *http.Request, pathParams map[string]string) (proto.Message, runtime.ServerMetadata, error) { + var protoReq QueryGetUserMinaAddressRequest var metadata runtime.ServerMetadata var ( @@ -89,24 +89,24 @@ func local_request_Query_GetMinaPubKey_0(ctx context.Context, marshaler runtime. _ = err ) - val, ok = pathParams["cosmos_pub_key"] + val, ok = pathParams["user_cosmos_address"] if !ok { - return nil, metadata, status.Errorf(codes.InvalidArgument, "missing parameter %s", "cosmos_pub_key") + return nil, metadata, status.Errorf(codes.InvalidArgument, "missing parameter %s", "user_cosmos_address") } - protoReq.CosmosPubKey, err = runtime.Bytes(val) + protoReq.UserCosmosAddress, err = runtime.Bytes(val) if err != nil { - return nil, metadata, status.Errorf(codes.InvalidArgument, "type mismatch, parameter: %s, error: %v", "cosmos_pub_key", err) + return nil, metadata, status.Errorf(codes.InvalidArgument, "type mismatch, parameter: %s, error: %v", "user_cosmos_address", err) } - msg, err := server.GetMinaPubKey(ctx, &protoReq) + msg, err := server.GetUserMinaAddress(ctx, &protoReq) return msg, metadata, err } -func request_Query_GetCosmosPubKey_0(ctx context.Context, marshaler runtime.Marshaler, client QueryClient, req *http.Request, pathParams map[string]string) (proto.Message, runtime.ServerMetadata, error) { - var protoReq QueryGetCosmosPubKeyRequest +func request_Query_GetUserCosmosAddress_0(ctx context.Context, marshaler runtime.Marshaler, client QueryClient, req *http.Request, pathParams map[string]string) (proto.Message, runtime.ServerMetadata, error) { + var protoReq QueryGetUserCosmosAddressRequest var metadata runtime.ServerMetadata var ( @@ -116,24 +116,24 @@ func request_Query_GetCosmosPubKey_0(ctx context.Context, marshaler runtime.Mars _ = err ) - val, ok = pathParams["mina_pub_key"] + val, ok = pathParams["user_mina_address"] if !ok { - return nil, metadata, status.Errorf(codes.InvalidArgument, "missing parameter %s", "mina_pub_key") + return nil, metadata, status.Errorf(codes.InvalidArgument, "missing parameter %s", "user_mina_address") } - protoReq.MinaPubKey, err = runtime.Bytes(val) + protoReq.UserMinaAddress, err = runtime.Bytes(val) if err != nil { - return nil, metadata, status.Errorf(codes.InvalidArgument, "type mismatch, parameter: %s, error: %v", "mina_pub_key", err) + return nil, metadata, status.Errorf(codes.InvalidArgument, "type mismatch, parameter: %s, error: %v", "user_mina_address", err) } - msg, err := client.GetCosmosPubKey(ctx, &protoReq, grpc.Header(&metadata.HeaderMD), grpc.Trailer(&metadata.TrailerMD)) + msg, err := client.GetUserCosmosAddress(ctx, &protoReq, grpc.Header(&metadata.HeaderMD), grpc.Trailer(&metadata.TrailerMD)) return msg, metadata, err } -func local_request_Query_GetCosmosPubKey_0(ctx context.Context, marshaler runtime.Marshaler, server QueryServer, req *http.Request, pathParams map[string]string) (proto.Message, runtime.ServerMetadata, error) { - var protoReq QueryGetCosmosPubKeyRequest +func local_request_Query_GetUserCosmosAddress_0(ctx context.Context, marshaler runtime.Marshaler, server QueryServer, req *http.Request, pathParams map[string]string) (proto.Message, runtime.ServerMetadata, error) { + var protoReq QueryGetUserCosmosAddressRequest var metadata runtime.ServerMetadata var ( @@ -143,18 +143,126 @@ func local_request_Query_GetCosmosPubKey_0(ctx context.Context, marshaler runtim _ = err ) - val, ok = pathParams["mina_pub_key"] + val, ok = pathParams["user_mina_address"] if !ok { - return nil, metadata, status.Errorf(codes.InvalidArgument, "missing parameter %s", "mina_pub_key") + return nil, metadata, status.Errorf(codes.InvalidArgument, "missing parameter %s", "user_mina_address") } - protoReq.MinaPubKey, err = runtime.Bytes(val) + protoReq.UserMinaAddress, err = runtime.Bytes(val) if err != nil { - return nil, metadata, status.Errorf(codes.InvalidArgument, "type mismatch, parameter: %s, error: %v", "mina_pub_key", err) + return nil, metadata, status.Errorf(codes.InvalidArgument, "type mismatch, parameter: %s, error: %v", "user_mina_address", err) } - msg, err := server.GetCosmosPubKey(ctx, &protoReq) + msg, err := server.GetUserCosmosAddress(ctx, &protoReq) + return msg, metadata, err + +} + +func request_Query_GetValidatorMinaPubKey_0(ctx context.Context, marshaler runtime.Marshaler, client QueryClient, req *http.Request, pathParams map[string]string) (proto.Message, runtime.ServerMetadata, error) { + var protoReq QueryGetValidatorMinaPubKeyRequest + var metadata runtime.ServerMetadata + + var ( + val string + ok bool + err error + _ = err + ) + + val, ok = pathParams["validator_cosmos_pub_key"] + if !ok { + return nil, metadata, status.Errorf(codes.InvalidArgument, "missing parameter %s", "validator_cosmos_pub_key") + } + + protoReq.ValidatorCosmosPubKey, err = runtime.Bytes(val) + + if err != nil { + return nil, metadata, status.Errorf(codes.InvalidArgument, "type mismatch, parameter: %s, error: %v", "validator_cosmos_pub_key", err) + } + + msg, err := client.GetValidatorMinaPubKey(ctx, &protoReq, grpc.Header(&metadata.HeaderMD), grpc.Trailer(&metadata.TrailerMD)) + return msg, metadata, err + +} + +func local_request_Query_GetValidatorMinaPubKey_0(ctx context.Context, marshaler runtime.Marshaler, server QueryServer, req *http.Request, pathParams map[string]string) (proto.Message, runtime.ServerMetadata, error) { + var protoReq QueryGetValidatorMinaPubKeyRequest + var metadata runtime.ServerMetadata + + var ( + val string + ok bool + err error + _ = err + ) + + val, ok = pathParams["validator_cosmos_pub_key"] + if !ok { + return nil, metadata, status.Errorf(codes.InvalidArgument, "missing parameter %s", "validator_cosmos_pub_key") + } + + protoReq.ValidatorCosmosPubKey, err = runtime.Bytes(val) + + if err != nil { + return nil, metadata, status.Errorf(codes.InvalidArgument, "type mismatch, parameter: %s, error: %v", "validator_cosmos_pub_key", err) + } + + msg, err := server.GetValidatorMinaPubKey(ctx, &protoReq) + return msg, metadata, err + +} + +func request_Query_GetValidatorCosmosPubKey_0(ctx context.Context, marshaler runtime.Marshaler, client QueryClient, req *http.Request, pathParams map[string]string) (proto.Message, runtime.ServerMetadata, error) { + var protoReq QueryGetValidatorCosmosPubKeyRequest + var metadata runtime.ServerMetadata + + var ( + val string + ok bool + err error + _ = err + ) + + val, ok = pathParams["validator_mina_pub_key"] + if !ok { + return nil, metadata, status.Errorf(codes.InvalidArgument, "missing parameter %s", "validator_mina_pub_key") + } + + protoReq.ValidatorMinaPubKey, err = runtime.Bytes(val) + + if err != nil { + return nil, metadata, status.Errorf(codes.InvalidArgument, "type mismatch, parameter: %s, error: %v", "validator_mina_pub_key", err) + } + + msg, err := client.GetValidatorCosmosPubKey(ctx, &protoReq, grpc.Header(&metadata.HeaderMD), grpc.Trailer(&metadata.TrailerMD)) + return msg, metadata, err + +} + +func local_request_Query_GetValidatorCosmosPubKey_0(ctx context.Context, marshaler runtime.Marshaler, server QueryServer, req *http.Request, pathParams map[string]string) (proto.Message, runtime.ServerMetadata, error) { + var protoReq QueryGetValidatorCosmosPubKeyRequest + var metadata runtime.ServerMetadata + + var ( + val string + ok bool + err error + _ = err + ) + + val, ok = pathParams["validator_mina_pub_key"] + if !ok { + return nil, metadata, status.Errorf(codes.InvalidArgument, "missing parameter %s", "validator_mina_pub_key") + } + + protoReq.ValidatorMinaPubKey, err = runtime.Bytes(val) + + if err != nil { + return nil, metadata, status.Errorf(codes.InvalidArgument, "type mismatch, parameter: %s, error: %v", "validator_mina_pub_key", err) + } + + msg, err := server.GetValidatorCosmosPubKey(ctx, &protoReq) return msg, metadata, err } @@ -188,7 +296,30 @@ func RegisterQueryHandlerServer(ctx context.Context, mux *runtime.ServeMux, serv }) - mux.Handle("GET", pattern_Query_GetMinaPubKey_0, func(w http.ResponseWriter, req *http.Request, pathParams map[string]string) { + mux.Handle("GET", pattern_Query_GetUserMinaAddress_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_GetUserMinaAddress_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_GetUserMinaAddress_0(ctx, mux, outboundMarshaler, w, req, resp, mux.GetForwardResponseOptions()...) + + }) + + mux.Handle("GET", pattern_Query_GetUserCosmosAddress_0, func(w http.ResponseWriter, req *http.Request, pathParams map[string]string) { ctx, cancel := context.WithCancel(req.Context()) defer cancel() var stream runtime.ServerTransportStream @@ -199,7 +330,7 @@ func RegisterQueryHandlerServer(ctx context.Context, mux *runtime.ServeMux, serv runtime.HTTPError(ctx, mux, outboundMarshaler, w, req, err) return } - resp, md, err := local_request_Query_GetMinaPubKey_0(rctx, inboundMarshaler, server, req, pathParams) + resp, md, err := local_request_Query_GetUserCosmosAddress_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 { @@ -207,11 +338,11 @@ func RegisterQueryHandlerServer(ctx context.Context, mux *runtime.ServeMux, serv return } - forward_Query_GetMinaPubKey_0(ctx, mux, outboundMarshaler, w, req, resp, mux.GetForwardResponseOptions()...) + forward_Query_GetUserCosmosAddress_0(ctx, mux, outboundMarshaler, w, req, resp, mux.GetForwardResponseOptions()...) }) - mux.Handle("GET", pattern_Query_GetCosmosPubKey_0, func(w http.ResponseWriter, req *http.Request, pathParams map[string]string) { + mux.Handle("GET", pattern_Query_GetValidatorMinaPubKey_0, func(w http.ResponseWriter, req *http.Request, pathParams map[string]string) { ctx, cancel := context.WithCancel(req.Context()) defer cancel() var stream runtime.ServerTransportStream @@ -222,7 +353,7 @@ func RegisterQueryHandlerServer(ctx context.Context, mux *runtime.ServeMux, serv runtime.HTTPError(ctx, mux, outboundMarshaler, w, req, err) return } - resp, md, err := local_request_Query_GetCosmosPubKey_0(rctx, inboundMarshaler, server, req, pathParams) + resp, md, err := local_request_Query_GetValidatorMinaPubKey_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 { @@ -230,7 +361,30 @@ func RegisterQueryHandlerServer(ctx context.Context, mux *runtime.ServeMux, serv return } - forward_Query_GetCosmosPubKey_0(ctx, mux, outboundMarshaler, w, req, resp, mux.GetForwardResponseOptions()...) + forward_Query_GetValidatorMinaPubKey_0(ctx, mux, outboundMarshaler, w, req, resp, mux.GetForwardResponseOptions()...) + + }) + + mux.Handle("GET", pattern_Query_GetValidatorCosmosPubKey_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_GetValidatorCosmosPubKey_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_GetValidatorCosmosPubKey_0(ctx, mux, outboundMarshaler, w, req, resp, mux.GetForwardResponseOptions()...) }) @@ -295,7 +449,27 @@ func RegisterQueryHandlerClient(ctx context.Context, mux *runtime.ServeMux, clie }) - mux.Handle("GET", pattern_Query_GetMinaPubKey_0, func(w http.ResponseWriter, req *http.Request, pathParams map[string]string) { + mux.Handle("GET", pattern_Query_GetUserMinaAddress_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_GetUserMinaAddress_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_GetUserMinaAddress_0(ctx, mux, outboundMarshaler, w, req, resp, mux.GetForwardResponseOptions()...) + + }) + + mux.Handle("GET", pattern_Query_GetUserCosmosAddress_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) @@ -304,18 +478,18 @@ func RegisterQueryHandlerClient(ctx context.Context, mux *runtime.ServeMux, clie runtime.HTTPError(ctx, mux, outboundMarshaler, w, req, err) return } - resp, md, err := request_Query_GetMinaPubKey_0(rctx, inboundMarshaler, client, req, pathParams) + resp, md, err := request_Query_GetUserCosmosAddress_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_GetMinaPubKey_0(ctx, mux, outboundMarshaler, w, req, resp, mux.GetForwardResponseOptions()...) + forward_Query_GetUserCosmosAddress_0(ctx, mux, outboundMarshaler, w, req, resp, mux.GetForwardResponseOptions()...) }) - mux.Handle("GET", pattern_Query_GetCosmosPubKey_0, func(w http.ResponseWriter, req *http.Request, pathParams map[string]string) { + mux.Handle("GET", pattern_Query_GetValidatorMinaPubKey_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) @@ -324,14 +498,34 @@ func RegisterQueryHandlerClient(ctx context.Context, mux *runtime.ServeMux, clie runtime.HTTPError(ctx, mux, outboundMarshaler, w, req, err) return } - resp, md, err := request_Query_GetCosmosPubKey_0(rctx, inboundMarshaler, client, req, pathParams) + resp, md, err := request_Query_GetValidatorMinaPubKey_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_GetCosmosPubKey_0(ctx, mux, outboundMarshaler, w, req, resp, mux.GetForwardResponseOptions()...) + forward_Query_GetValidatorMinaPubKey_0(ctx, mux, outboundMarshaler, w, req, resp, mux.GetForwardResponseOptions()...) + + }) + + mux.Handle("GET", pattern_Query_GetValidatorCosmosPubKey_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_GetValidatorCosmosPubKey_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_GetValidatorCosmosPubKey_0(ctx, mux, outboundMarshaler, w, req, resp, mux.GetForwardResponseOptions()...) }) @@ -341,15 +535,23 @@ func RegisterQueryHandlerClient(ctx context.Context, mux *runtime.ServeMux, clie var ( pattern_Query_Params_0 = runtime.MustPattern(runtime.NewPattern(1, []int{2, 0, 2, 1, 2, 2, 2, 3, 2, 4}, []string{"node101-io", "pulsar-chain", "keyregistry", "v1", "params"}, "", runtime.AssumeColonVerbOpt(false))) - pattern_Query_GetMinaPubKey_0 = runtime.MustPattern(runtime.NewPattern(1, []int{2, 0, 2, 1, 2, 2, 2, 3, 2, 4, 1, 0, 4, 1, 5, 5}, []string{"node101-io", "pulsar-chain", "keyregistry", "v1", "get_mina_pub_key", "cosmos_pub_key"}, "", runtime.AssumeColonVerbOpt(false))) + pattern_Query_GetUserMinaAddress_0 = runtime.MustPattern(runtime.NewPattern(1, []int{2, 0, 2, 1, 2, 2, 2, 3, 2, 4, 1, 0, 4, 1, 5, 5}, []string{"node101-io", "pulsar-chain", "keyregistry", "v1", "get_user_mina_address", "user_cosmos_address"}, "", runtime.AssumeColonVerbOpt(false))) - pattern_Query_GetCosmosPubKey_0 = runtime.MustPattern(runtime.NewPattern(1, []int{2, 0, 2, 1, 2, 2, 2, 3, 2, 4, 1, 0, 4, 1, 5, 5}, []string{"node101-io", "pulsar-chain", "keyregistry", "v1", "get_cosmos_pub_key", "mina_pub_key"}, "", runtime.AssumeColonVerbOpt(false))) + pattern_Query_GetUserCosmosAddress_0 = runtime.MustPattern(runtime.NewPattern(1, []int{2, 0, 2, 1, 2, 2, 2, 3, 2, 4, 1, 0, 4, 1, 5, 5}, []string{"node101-io", "pulsar-chain", "keyregistry", "v1", "get_user_cosmos_address", "user_mina_address"}, "", runtime.AssumeColonVerbOpt(false))) + + pattern_Query_GetValidatorMinaPubKey_0 = runtime.MustPattern(runtime.NewPattern(1, []int{2, 0, 2, 1, 2, 2, 2, 3, 2, 4, 1, 0, 4, 1, 5, 5}, []string{"node101-io", "pulsar-chain", "keyregistry", "v1", "get_validator_mina_pub_key", "validator_cosmos_pub_key"}, "", runtime.AssumeColonVerbOpt(false))) + + pattern_Query_GetValidatorCosmosPubKey_0 = runtime.MustPattern(runtime.NewPattern(1, []int{2, 0, 2, 1, 2, 2, 2, 3, 2, 4, 1, 0, 4, 1, 5, 5}, []string{"node101-io", "pulsar-chain", "keyregistry", "v1", "get_validator_cosmos_pub_key", "validator_mina_pub_key"}, "", runtime.AssumeColonVerbOpt(false))) ) var ( forward_Query_Params_0 = runtime.ForwardResponseMessage - forward_Query_GetMinaPubKey_0 = runtime.ForwardResponseMessage + forward_Query_GetUserMinaAddress_0 = runtime.ForwardResponseMessage + + forward_Query_GetUserCosmosAddress_0 = runtime.ForwardResponseMessage + + forward_Query_GetValidatorMinaPubKey_0 = runtime.ForwardResponseMessage - forward_Query_GetCosmosPubKey_0 = runtime.ForwardResponseMessage + forward_Query_GetValidatorCosmosPubKey_0 = runtime.ForwardResponseMessage ) diff --git a/x/keyregistry/types/tx.pb.go b/x/keyregistry/types/tx.pb.go index 42552c4c..b62220a3 100644 --- a/x/keyregistry/types/tx.pb.go +++ b/x/keyregistry/types/tx.pb.go @@ -129,8 +129,9 @@ type MsgRegisterKeys struct { Creator string `protobuf:"bytes,1,opt,name=creator,proto3" json:"creator,omitempty"` CosmosSignature string `protobuf:"bytes,2,opt,name=cosmos_signature,json=cosmosSignature,proto3" json:"cosmos_signature,omitempty"` MinaSignature string `protobuf:"bytes,3,opt,name=mina_signature,json=minaSignature,proto3" json:"mina_signature,omitempty"` - CosmosPublicKey []byte `protobuf:"bytes,4,opt,name=cosmos_public_key,json=cosmosPublicKey,proto3" json:"cosmos_public_key,omitempty"` - MinaPublicKey []byte `protobuf:"bytes,5,opt,name=mina_public_key,json=minaPublicKey,proto3" json:"mina_public_key,omitempty"` + CosmosAddress []byte `protobuf:"bytes,4,opt,name=cosmos_address,json=cosmosAddress,proto3" json:"cosmos_address,omitempty"` + MinaAddress []byte `protobuf:"bytes,5,opt,name=mina_address,json=minaAddress,proto3" json:"mina_address,omitempty"` + IsUser bool `protobuf:"varint,6,opt,name=is_user,json=isUser,proto3" json:"is_user,omitempty"` } func (m *MsgRegisterKeys) Reset() { *m = MsgRegisterKeys{} } @@ -187,20 +188,27 @@ func (m *MsgRegisterKeys) GetMinaSignature() string { return "" } -func (m *MsgRegisterKeys) GetCosmosPublicKey() []byte { +func (m *MsgRegisterKeys) GetCosmosAddress() []byte { if m != nil { - return m.CosmosPublicKey + return m.CosmosAddress } return nil } -func (m *MsgRegisterKeys) GetMinaPublicKey() []byte { +func (m *MsgRegisterKeys) GetMinaAddress() []byte { if m != nil { - return m.MinaPublicKey + return m.MinaAddress } return nil } +func (m *MsgRegisterKeys) GetIsUser() bool { + if m != nil { + return m.IsUser + } + return false +} + // MsgRegisterKeysResponse defines the MsgRegisterKeysResponse message. type MsgRegisterKeysResponse struct { } @@ -250,39 +258,40 @@ func init() { } var fileDescriptor_235f5fb22cc1f8d8 = []byte{ - // 503 bytes of a gzipped FileDescriptorProto - 0x1f, 0x8b, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0xff, 0x94, 0x93, 0xb1, 0x6f, 0x13, 0x31, - 0x14, 0xc6, 0x63, 0x4a, 0x8b, 0x62, 0x02, 0xa1, 0xa7, 0x4a, 0x4d, 0x6f, 0x38, 0xa2, 0x20, 0x20, - 0x0d, 0xca, 0x1d, 0x49, 0xa5, 0x0e, 0x15, 0x0b, 0x91, 0x98, 0xaa, 0x4a, 0xd1, 0x55, 0x2c, 0x2c, - 0x95, 0x73, 0xb1, 0x1c, 0xab, 0xbd, 0xf3, 0xc9, 0xf6, 0x55, 0xbd, 0x0d, 0x31, 0x32, 0xf1, 0x67, - 0x30, 0x66, 0xe0, 0x8f, 0xe8, 0x84, 0x2a, 0x26, 0x26, 0x84, 0x92, 0x21, 0x2b, 0x2b, 0x1b, 0x3a, - 0xdb, 0x47, 0x2e, 0x51, 0x49, 0xc4, 0x12, 0xc5, 0x9f, 0x7f, 0x7e, 0x9f, 0xbf, 0xf7, 0x7c, 0xf0, - 0x49, 0x9c, 0x5c, 0x08, 0xc4, 0x83, 0x11, 0xa2, 0x91, 0x77, 0x8e, 0x53, 0x8e, 0x09, 0x15, 0x92, - 0xa7, 0xde, 0x65, 0xc7, 0x93, 0x57, 0x6e, 0xcc, 0x99, 0x64, 0x96, 0x5d, 0x80, 0xdc, 0x02, 0xe4, - 0x5e, 0x76, 0xec, 0x6d, 0x14, 0xd2, 0x88, 0x79, 0xea, 0x57, 0xe3, 0xf6, 0x6e, 0xc0, 0x44, 0xc8, - 0x84, 0x17, 0x0a, 0x92, 0x95, 0x09, 0x05, 0x31, 0x1b, 0x7b, 0x7a, 0xe3, 0x4c, 0xad, 0x3c, 0xbd, - 0x30, 0x5b, 0x3b, 0x84, 0x11, 0xa6, 0xf5, 0xec, 0x9f, 0x51, 0x9f, 0xaf, 0xb8, 0x5d, 0x8c, 0x38, - 0x0a, 0xcd, 0xf1, 0xc6, 0x57, 0x00, 0xab, 0x27, 0x82, 0xbc, 0x8d, 0x87, 0x48, 0xe2, 0xbe, 0xda, - 0xb1, 0x0e, 0x61, 0x19, 0x25, 0x72, 0xc4, 0x38, 0x95, 0x69, 0x0d, 0xd4, 0x41, 0xb3, 0xdc, 0xab, - 0x7d, 0xfb, 0xd2, 0xde, 0x31, 0xbe, 0xaf, 0x87, 0x43, 0x8e, 0x85, 0x38, 0x95, 0x9c, 0x46, 0xc4, - 0x9f, 0xa3, 0xd6, 0x1b, 0xb8, 0xa5, 0x6b, 0xd7, 0xee, 0xd4, 0x41, 0xf3, 0x7e, 0xb7, 0xe1, 0xfe, - 0x3b, 0xbe, 0xab, 0xbd, 0x7a, 0xe5, 0xeb, 0x1f, 0x8f, 0x4b, 0x9f, 0x67, 0xe3, 0x16, 0xf0, 0xcd, - 0xe1, 0xa3, 0x57, 0x1f, 0x66, 0xe3, 0xd6, 0xbc, 0xec, 0xc7, 0xd9, 0xb8, 0xb5, 0x5f, 0x8c, 0x73, - 0xb5, 0x10, 0x68, 0xe9, 0xf2, 0x8d, 0x3d, 0xb8, 0xbb, 0x24, 0xf9, 0x58, 0xc4, 0x2c, 0x12, 0xb8, - 0xf1, 0x5b, 0x67, 0xf5, 0xd5, 0x51, 0xcc, 0x8f, 0x71, 0x2a, 0xac, 0x2e, 0xbc, 0x17, 0x70, 0x8c, - 0x24, 0xe3, 0x6b, 0x93, 0xe6, 0xa0, 0xb5, 0x0f, 0x1f, 0x99, 0x79, 0x08, 0x4a, 0x22, 0x24, 0x13, - 0x8e, 0x55, 0xe2, 0xb2, 0x5f, 0xd5, 0xfa, 0x69, 0x2e, 0x5b, 0x4f, 0xe1, 0xc3, 0x90, 0x46, 0xa8, - 0x00, 0x6e, 0x28, 0xf0, 0x41, 0xa6, 0xce, 0xb1, 0x16, 0xdc, 0xce, 0x27, 0x9c, 0x0c, 0x2e, 0x68, - 0x70, 0x76, 0x8e, 0xd3, 0xda, 0xdd, 0x3a, 0x68, 0x56, 0xf2, 0x92, 0x7d, 0xa5, 0x1f, 0xe3, 0xd4, - 0x7a, 0x06, 0xab, 0xaa, 0x64, 0x81, 0xdc, 0x54, 0xa4, 0xaa, 0xf9, 0x97, 0x3b, 0xaa, 0x64, 0x6d, - 0xcc, 0xef, 0x6c, 0xda, 0x52, 0x8c, 0x9e, 0xb7, 0xa5, 0xfb, 0x0b, 0xc0, 0x8d, 0x13, 0x41, 0xac, - 0x18, 0x56, 0x16, 0x9e, 0xc1, 0x8b, 0x55, 0xe3, 0x5b, 0xea, 0xb1, 0x7d, 0xf0, 0x1f, 0x70, 0xee, - 0x9c, 0x39, 0x2e, 0x0c, 0x63, 0x9d, 0x63, 0x11, 0x5e, 0xeb, 0x78, 0x5b, 0x56, 0x7b, 0xf3, 0x7d, - 0xf6, 0xd4, 0x7a, 0xfd, 0xeb, 0x89, 0x03, 0x6e, 0x26, 0x0e, 0xf8, 0x39, 0x71, 0xc0, 0xa7, 0xa9, - 0x53, 0xba, 0x99, 0x3a, 0xa5, 0xef, 0x53, 0xa7, 0xf4, 0xee, 0x90, 0x50, 0x39, 0x4a, 0x06, 0x6e, - 0xc0, 0x42, 0x2f, 0x62, 0x43, 0xdc, 0x79, 0xd9, 0x69, 0x53, 0xe6, 0x69, 0xab, 0xf6, 0x6d, 0x0f, - 0x50, 0xa6, 0x31, 0x16, 0x83, 0x2d, 0xf5, 0x39, 0x1d, 0xfc, 0x09, 0x00, 0x00, 0xff, 0xff, 0xfb, - 0xf4, 0xf0, 0x15, 0x17, 0x04, 0x00, 0x00, + // 514 bytes of a gzipped FileDescriptorProto + 0x1f, 0x8b, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0xff, 0x94, 0x93, 0x31, 0x6f, 0x13, 0x31, + 0x14, 0xc7, 0xe3, 0x96, 0xa6, 0xc4, 0x4d, 0x29, 0x9c, 0x2a, 0x25, 0xcd, 0x70, 0x84, 0x20, 0x44, + 0x1a, 0x94, 0x3b, 0x92, 0x4a, 0x1d, 0x2a, 0x16, 0x22, 0x31, 0xa1, 0x4a, 0xd5, 0x55, 0x5d, 0x58, + 0x2a, 0x37, 0xb1, 0x1c, 0x0b, 0xee, 0x7c, 0xf2, 0x73, 0xaa, 0xde, 0x86, 0x98, 0x10, 0x13, 0x1f, + 0x83, 0x31, 0x03, 0x1f, 0xa2, 0x13, 0xaa, 0x98, 0x98, 0x10, 0x4a, 0x86, 0xac, 0x7c, 0x04, 0x74, + 0xb6, 0x4f, 0xbd, 0x44, 0xa5, 0x51, 0x97, 0x28, 0xfe, 0xbf, 0x9f, 0xdf, 0xdf, 0xff, 0x67, 0x1f, + 0x7e, 0x1a, 0x8f, 0x3e, 0x00, 0x91, 0xfd, 0x21, 0xe1, 0x91, 0xff, 0x9e, 0x26, 0x92, 0x32, 0x0e, + 0x4a, 0x26, 0xfe, 0x79, 0xc7, 0x57, 0x17, 0x5e, 0x2c, 0x85, 0x12, 0x4e, 0x2d, 0x07, 0x79, 0x39, + 0xc8, 0x3b, 0xef, 0xd4, 0x1e, 0x91, 0x90, 0x47, 0xc2, 0xd7, 0xbf, 0x06, 0xaf, 0x55, 0xfa, 0x02, + 0x42, 0x01, 0x7e, 0x08, 0x2c, 0x6d, 0x13, 0x02, 0xb3, 0x85, 0x1d, 0x53, 0x38, 0xd5, 0x2b, 0xdf, + 0x2c, 0x6c, 0x69, 0x9b, 0x09, 0x26, 0x8c, 0x9e, 0xfe, 0xb3, 0xea, 0xf3, 0x5b, 0x4e, 0x17, 0x13, + 0x49, 0x42, 0xbb, 0xbd, 0xf1, 0x03, 0xe1, 0xad, 0x43, 0x60, 0x27, 0xf1, 0x80, 0x28, 0x7a, 0xa4, + 0x2b, 0xce, 0x3e, 0x2e, 0x91, 0x91, 0x1a, 0x0a, 0xc9, 0x55, 0x52, 0x45, 0x75, 0xd4, 0x2c, 0xf5, + 0xaa, 0x3f, 0xbf, 0xb7, 0xb7, 0xad, 0xef, 0xeb, 0xc1, 0x40, 0x52, 0x80, 0x63, 0x25, 0x79, 0xc4, + 0x82, 0x6b, 0xd4, 0x79, 0x83, 0x8b, 0xa6, 0x77, 0x75, 0xa5, 0x8e, 0x9a, 0x1b, 0xdd, 0x86, 0xf7, + 0xff, 0xf8, 0x9e, 0xf1, 0xea, 0x95, 0x2e, 0x7f, 0x3f, 0x2e, 0x7c, 0x9b, 0x8d, 0x5b, 0x28, 0xb0, + 0x9b, 0x0f, 0x5e, 0x7d, 0x9a, 0x8d, 0x5b, 0xd7, 0x6d, 0xbf, 0xcc, 0xc6, 0xad, 0xdd, 0x7c, 0x9c, + 0x8b, 0xb9, 0x40, 0x0b, 0x87, 0x6f, 0xec, 0xe0, 0xca, 0x82, 0x14, 0x50, 0x88, 0x45, 0x04, 0xb4, + 0xf1, 0x79, 0x45, 0x67, 0x0d, 0xf4, 0x56, 0x2a, 0xdf, 0xd2, 0x04, 0x9c, 0x2e, 0x5e, 0xef, 0x4b, + 0x4a, 0x94, 0x90, 0x4b, 0x93, 0x66, 0xa0, 0xb3, 0x8b, 0x1f, 0xda, 0xfb, 0x00, 0xce, 0x22, 0xa2, + 0x46, 0x92, 0xea, 0xc4, 0xa5, 0x60, 0xcb, 0xe8, 0xc7, 0x99, 0xec, 0x3c, 0xc3, 0x0f, 0x42, 0x1e, + 0x91, 0x1c, 0xb8, 0xaa, 0xc1, 0xcd, 0x54, 0x9d, 0xc3, 0x6c, 0x47, 0x62, 0x2c, 0xab, 0xf7, 0xea, + 0xa8, 0x59, 0x0e, 0x36, 0x8d, 0x6a, 0xcf, 0xe1, 0x3c, 0xc1, 0x65, 0xdd, 0x2d, 0x83, 0xd6, 0x34, + 0xb4, 0x91, 0x6a, 0x19, 0x52, 0xc1, 0xeb, 0x1c, 0x4e, 0x47, 0x40, 0x65, 0xb5, 0x58, 0x47, 0xcd, + 0xfb, 0x41, 0x91, 0xc3, 0x09, 0x50, 0x79, 0x50, 0x4e, 0xa7, 0x9a, 0x45, 0xb0, 0x53, 0xca, 0x4f, + 0x22, 0x9b, 0x52, 0xf7, 0x2f, 0xc2, 0xab, 0x87, 0xc0, 0x9c, 0x18, 0x97, 0xe7, 0x5e, 0xc5, 0x8b, + 0xdb, 0x6e, 0x73, 0x61, 0xe4, 0xb5, 0xbd, 0x3b, 0xc0, 0x99, 0x73, 0xea, 0x38, 0x77, 0x37, 0xcb, + 0x1c, 0xf3, 0xf0, 0x52, 0xc7, 0x9b, 0xb2, 0xd6, 0xd6, 0x3e, 0xa6, 0x2f, 0xaf, 0x77, 0x74, 0x39, + 0x71, 0xd1, 0xd5, 0xc4, 0x45, 0x7f, 0x26, 0x2e, 0xfa, 0x3a, 0x75, 0x0b, 0x57, 0x53, 0xb7, 0xf0, + 0x6b, 0xea, 0x16, 0xde, 0xed, 0x33, 0xae, 0x86, 0xa3, 0x33, 0xaf, 0x2f, 0x42, 0x3f, 0x12, 0x03, + 0xda, 0x79, 0xd9, 0x69, 0x73, 0xe1, 0x1b, 0xab, 0xf6, 0x4d, 0xef, 0x51, 0x25, 0x31, 0x85, 0xb3, + 0xa2, 0xfe, 0xba, 0xf6, 0xfe, 0x05, 0x00, 0x00, 0xff, 0xff, 0x1b, 0x60, 0xd1, 0xae, 0x26, 0x04, + 0x00, 0x00, } // Reference imports to suppress errors if they are not otherwise used. @@ -491,17 +500,27 @@ func (m *MsgRegisterKeys) MarshalToSizedBuffer(dAtA []byte) (int, error) { _ = i var l int _ = l - if len(m.MinaPublicKey) > 0 { - i -= len(m.MinaPublicKey) - copy(dAtA[i:], m.MinaPublicKey) - i = encodeVarintTx(dAtA, i, uint64(len(m.MinaPublicKey))) + if m.IsUser { + i-- + if m.IsUser { + dAtA[i] = 1 + } else { + dAtA[i] = 0 + } + i-- + dAtA[i] = 0x30 + } + if len(m.MinaAddress) > 0 { + i -= len(m.MinaAddress) + copy(dAtA[i:], m.MinaAddress) + i = encodeVarintTx(dAtA, i, uint64(len(m.MinaAddress))) i-- dAtA[i] = 0x2a } - if len(m.CosmosPublicKey) > 0 { - i -= len(m.CosmosPublicKey) - copy(dAtA[i:], m.CosmosPublicKey) - i = encodeVarintTx(dAtA, i, uint64(len(m.CosmosPublicKey))) + if len(m.CosmosAddress) > 0 { + i -= len(m.CosmosAddress) + copy(dAtA[i:], m.CosmosAddress) + i = encodeVarintTx(dAtA, i, uint64(len(m.CosmosAddress))) i-- dAtA[i] = 0x22 } @@ -605,14 +624,17 @@ func (m *MsgRegisterKeys) Size() (n int) { if l > 0 { n += 1 + l + sovTx(uint64(l)) } - l = len(m.CosmosPublicKey) + l = len(m.CosmosAddress) if l > 0 { n += 1 + l + sovTx(uint64(l)) } - l = len(m.MinaPublicKey) + l = len(m.MinaAddress) if l > 0 { n += 1 + l + sovTx(uint64(l)) } + if m.IsUser { + n += 2 + } return n } @@ -923,7 +945,7 @@ func (m *MsgRegisterKeys) Unmarshal(dAtA []byte) error { iNdEx = postIndex case 4: if wireType != 2 { - return fmt.Errorf("proto: wrong wireType = %d for field CosmosPublicKey", wireType) + return fmt.Errorf("proto: wrong wireType = %d for field CosmosAddress", wireType) } var byteLen int for shift := uint(0); ; shift += 7 { @@ -950,14 +972,14 @@ func (m *MsgRegisterKeys) Unmarshal(dAtA []byte) error { if postIndex > l { return io.ErrUnexpectedEOF } - m.CosmosPublicKey = append(m.CosmosPublicKey[:0], dAtA[iNdEx:postIndex]...) - if m.CosmosPublicKey == nil { - m.CosmosPublicKey = []byte{} + m.CosmosAddress = append(m.CosmosAddress[:0], dAtA[iNdEx:postIndex]...) + if m.CosmosAddress == nil { + m.CosmosAddress = []byte{} } iNdEx = postIndex case 5: if wireType != 2 { - return fmt.Errorf("proto: wrong wireType = %d for field MinaPublicKey", wireType) + return fmt.Errorf("proto: wrong wireType = %d for field MinaAddress", wireType) } var byteLen int for shift := uint(0); ; shift += 7 { @@ -984,11 +1006,31 @@ func (m *MsgRegisterKeys) Unmarshal(dAtA []byte) error { if postIndex > l { return io.ErrUnexpectedEOF } - m.MinaPublicKey = append(m.MinaPublicKey[:0], dAtA[iNdEx:postIndex]...) - if m.MinaPublicKey == nil { - m.MinaPublicKey = []byte{} + m.MinaAddress = append(m.MinaAddress[:0], dAtA[iNdEx:postIndex]...) + if m.MinaAddress == nil { + m.MinaAddress = []byte{} } iNdEx = postIndex + case 6: + if wireType != 0 { + return fmt.Errorf("proto: wrong wireType = %d for field IsUser", wireType) + } + var v int + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowTx + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + v |= int(b&0x7F) << shift + if b < 0x80 { + break + } + } + m.IsUser = bool(v != 0) default: iNdEx = preIndex skippy, err := skipTx(dAtA[iNdEx:]) From 233fc2547dd68b18fece26713574630660f8d978 Mon Sep 17 00:00:00 2001 From: Yusuf Date: Wed, 8 Apr 2026 18:09:19 +0300 Subject: [PATCH 02/62] fix: make config.yml compatible with the new implementation --- config.yml | 9 ++++++--- docs/static/openapi.json | 2 +- 2 files changed, 7 insertions(+), 4 deletions(-) diff --git a/config.yml b/config.yml index 6d7a3ec2..7a327269 100644 --- a/config.yml +++ b/config.yml @@ -30,6 +30,9 @@ genesis: app_state: keyregistry: params: {} - key_pairs: - # - mina_key: "SC/6aqoZ19ObLka8NIQVMs1qPim+uD6epPLuQS4x2n4Z" - # cosmos_key: "UdDr3CCO+4HVrBtbzqLTM3P2xAMNCIrPeCTeVfb5sw1y" + user_key_pairs: + # - mina_key: "SC/6aqoZ19ObLka8NIQVMs1qPim+uD6epPLuQS4x2n4Z" + # cosmos_key: "UdDr3CCO+4HVrBtbzqLTM3P2xAMNCIrPeCTeVfb5sw1y" + validator_key_pairs: + # - mina_key: "3IvK1eWmmcfdlIb+T04+ck9Q5bjbqHqiT0ucGJITzyY=" + # cosmos_key: "A8saw69s1DQWvUjseeOtG8hGavmYiInrQ5M1aOPa4QkP" \ No newline at end of file diff --git a/docs/static/openapi.json b/docs/static/openapi.json index 8340f427..63b795a0 100644 --- a/docs/static/openapi.json +++ b/docs/static/openapi.json @@ -1 +1 @@ -{"id":"github.com/node101-io/pulsar-chain","consumes":["application/json"],"produces":["application/json"],"swagger":"2.0","info":{"description":"Chain github.com/node101-io/pulsar-chain REST API","title":"HTTP API Console","contact":{"name":"github.com/node101-io/pulsar-chain"},"version":"version not set"},"paths":{"/node101-io/pulsar-chain/keyregistry/v1/get_cosmos_pub_key/{mina_pub_key}":{"get":{"tags":["Query"],"summary":"GetCosmosPubKey Queries a list of GetCosmosPubKey items.","operationId":"GithubComnode101IopulsarChainQuery_GetCosmosPubKey","parameters":[{"type":"string","format":"byte","name":"mina_pub_key","in":"path","required":true}],"responses":{"200":{"description":"A successful response.","schema":{"$ref":"#/definitions/pulsarchain.keyregistry.v1.QueryGetCosmosPubKeyResponse"}},"default":{"description":"An unexpected error response.","schema":{"$ref":"#/definitions/google.rpc.Status"}}}}},"/node101-io/pulsar-chain/keyregistry/v1/get_mina_pub_key/{cosmos_pub_key}":{"get":{"tags":["Query"],"summary":"GetMinaPubKey Queries a list of GetMinaPubKey items.","operationId":"GithubComnode101IopulsarChainQuery_GetMinaPubKey","parameters":[{"type":"string","format":"byte","name":"cosmos_pub_key","in":"path","required":true}],"responses":{"200":{"description":"A successful response.","schema":{"$ref":"#/definitions/pulsarchain.keyregistry.v1.QueryGetMinaPubKeyResponse"}},"default":{"description":"An unexpected error response.","schema":{"$ref":"#/definitions/google.rpc.Status"}}}}},"/node101-io/pulsar-chain/keyregistry/v1/params":{"get":{"tags":["Query"],"summary":"Parameters queries the parameters of the module.","operationId":"GithubComnode101IopulsarChainQuery_ParamsMixin7","responses":{"200":{"description":"A successful response.","schema":{"$ref":"#/definitions/pulsarchain.keyregistry.v1.QueryParamsResponse"}},"default":{"description":"An unexpected error response.","schema":{"$ref":"#/definitions/google.rpc.Status"}}}}},"/pulsar/pulsar/v1/params":{"get":{"tags":["Query"],"summary":"Parameters queries the parameters of the module.","operationId":"GithubComnode101IopulsarChainQuery_Params","responses":{"200":{"description":"A successful response.","schema":{"$ref":"#/definitions/pulsar.pulsar.v1.QueryParamsResponse"}},"default":{"description":"An unexpected error response.","schema":{"$ref":"#/definitions/google.rpc.Status"}}}}}},"definitions":{"google.protobuf.Any":{"type":"object","properties":{"@type":{"type":"string"}},"additionalProperties":{}},"google.rpc.Status":{"type":"object","properties":{"code":{"type":"integer","format":"int32"},"details":{"type":"array","items":{"type":"object","$ref":"#/definitions/google.protobuf.Any"}},"message":{"type":"string"}}},"pulsar.pulsar.v1.Params":{"description":"Params defines the parameters for the module.","type":"object"},"pulsar.pulsar.v1.QueryParamsResponse":{"description":"QueryParamsResponse is response type for the Query/Params RPC method.","type":"object","properties":{"params":{"description":"params holds all the parameters of this module.","$ref":"#/definitions/pulsar.pulsar.v1.Params"}}},"pulsarchain.keyregistry.v1.Params":{"description":"Params defines the parameters for the module.","type":"object"},"pulsarchain.keyregistry.v1.QueryGetCosmosPubKeyResponse":{"description":"QueryGetCosmosPubKeyResponse defines the QueryGetCosmosPubKeyResponse message.","type":"object","properties":{"cosmos_pub_key":{"type":"string","format":"byte"}}},"pulsarchain.keyregistry.v1.QueryGetMinaPubKeyResponse":{"description":"QueryGetMinaPubKeyResponse defines the QueryGetMinaPubKeyResponse message.","type":"object","properties":{"mina_pub_key":{"type":"string","format":"byte"}}},"pulsarchain.keyregistry.v1.QueryParamsResponse":{"description":"QueryParamsResponse is response type for the Query/Params RPC method.","type":"object","properties":{"params":{"description":"params holds all the parameters of this module.","$ref":"#/definitions/pulsarchain.keyregistry.v1.Params"}}}},"tags":[{"name":"Query"},{"name":"Msg"}]} \ No newline at end of file +{"id":"github.com/node101-io/pulsar-chain","consumes":["application/json"],"produces":["application/json"],"swagger":"2.0","info":{"description":"Chain github.com/node101-io/pulsar-chain REST API","title":"HTTP API Console","contact":{"name":"github.com/node101-io/pulsar-chain"},"version":"version not set"},"paths":{"/node101-io/pulsar-chain/keyregistry/v1/get_user_cosmos_address/{user_mina_address}":{"get":{"tags":["Query"],"summary":"GetUserCosmosAddress Queries a list of GetUserCosmosAddress items.","operationId":"GithubComnode101IopulsarChainQuery_GetUserCosmosAddress","parameters":[{"type":"string","format":"byte","name":"user_mina_address","in":"path","required":true}],"responses":{"200":{"description":"A successful response.","schema":{"$ref":"#/definitions/pulsarchain.keyregistry.v1.QueryGetUserCosmosAddressResponse"}},"default":{"description":"An unexpected error response.","schema":{"$ref":"#/definitions/google.rpc.Status"}}}}},"/node101-io/pulsar-chain/keyregistry/v1/get_user_mina_address/{user_cosmos_address}":{"get":{"tags":["Query"],"summary":"GetUserMinaAddress Queries a list of GetUserMinaAddress items.","operationId":"GithubComnode101IopulsarChainQuery_GetUserMinaAddress","parameters":[{"type":"string","format":"byte","name":"user_cosmos_address","in":"path","required":true}],"responses":{"200":{"description":"A successful response.","schema":{"$ref":"#/definitions/pulsarchain.keyregistry.v1.QueryGetUserMinaAddressResponse"}},"default":{"description":"An unexpected error response.","schema":{"$ref":"#/definitions/google.rpc.Status"}}}}},"/node101-io/pulsar-chain/keyregistry/v1/get_validator_cosmos_pub_key/{validator_mina_pub_key}":{"get":{"tags":["Query"],"summary":"GetValidatorCosmosAddress Queries a list of GetValidatorCosmosAddress items.","operationId":"GithubComnode101IopulsarChainQuery_GetValidatorCosmosPubKey","parameters":[{"type":"string","format":"byte","name":"validator_mina_pub_key","in":"path","required":true}],"responses":{"200":{"description":"A successful response.","schema":{"$ref":"#/definitions/pulsarchain.keyregistry.v1.QueryGetValidatorCosmosPubKeyResponse"}},"default":{"description":"An unexpected error response.","schema":{"$ref":"#/definitions/google.rpc.Status"}}}}},"/node101-io/pulsar-chain/keyregistry/v1/get_validator_mina_pub_key/{validator_cosmos_pub_key}":{"get":{"tags":["Query"],"summary":"GetValidatorMinaAddress Queries a list of GetValidatorMinaAddress items.","operationId":"GithubComnode101IopulsarChainQuery_GetValidatorMinaPubKey","parameters":[{"type":"string","format":"byte","name":"validator_cosmos_pub_key","in":"path","required":true}],"responses":{"200":{"description":"A successful response.","schema":{"$ref":"#/definitions/pulsarchain.keyregistry.v1.QueryGetValidatorMinaPubKeyResponse"}},"default":{"description":"An unexpected error response.","schema":{"$ref":"#/definitions/google.rpc.Status"}}}}},"/node101-io/pulsar-chain/keyregistry/v1/params":{"get":{"tags":["Query"],"summary":"Parameters queries the parameters of the module.","operationId":"GithubComnode101IopulsarChainQuery_ParamsMixin8","responses":{"200":{"description":"A successful response.","schema":{"$ref":"#/definitions/pulsarchain.keyregistry.v1.QueryParamsResponse"}},"default":{"description":"An unexpected error response.","schema":{"$ref":"#/definitions/google.rpc.Status"}}}}},"/pulsar/pulsar/v1/params":{"get":{"tags":["Query"],"summary":"Parameters queries the parameters of the module.","operationId":"GithubComnode101IopulsarChainQuery_Params","responses":{"200":{"description":"A successful response.","schema":{"$ref":"#/definitions/pulsar.pulsar.v1.QueryParamsResponse"}},"default":{"description":"An unexpected error response.","schema":{"$ref":"#/definitions/google.rpc.Status"}}}}}},"definitions":{"google.protobuf.Any":{"type":"object","properties":{"@type":{"type":"string"}},"additionalProperties":{}},"google.rpc.Status":{"type":"object","properties":{"code":{"type":"integer","format":"int32"},"details":{"type":"array","items":{"type":"object","$ref":"#/definitions/google.protobuf.Any"}},"message":{"type":"string"}}},"pulsar.pulsar.v1.Params":{"description":"Params defines the parameters for the module.","type":"object"},"pulsar.pulsar.v1.QueryParamsResponse":{"description":"QueryParamsResponse is response type for the Query/Params RPC method.","type":"object","properties":{"params":{"description":"params holds all the parameters of this module.","$ref":"#/definitions/pulsar.pulsar.v1.Params"}}},"pulsarchain.keyregistry.v1.Params":{"description":"Params defines the parameters for the module.","type":"object"},"pulsarchain.keyregistry.v1.QueryGetUserCosmosAddressResponse":{"description":"QueryGetUserCosmosAddressResponse defines the QueryGetUserCosmosAddressResponse message.","type":"object","properties":{"user_cosmos_address":{"type":"string","format":"byte"}}},"pulsarchain.keyregistry.v1.QueryGetUserMinaAddressResponse":{"description":"QueryGetUserMinaAddressResponse defines the QueryGetUserMinaAddressResponse message.","type":"object","properties":{"user_mina_address":{"type":"string","format":"byte"}}},"pulsarchain.keyregistry.v1.QueryGetValidatorCosmosPubKeyResponse":{"description":"QueryGetValidatorCosmosAddressResponse defines the QueryGetValidatorCosmosAddressResponse message.","type":"object","properties":{"validator_cosmos_pub_key":{"type":"string","format":"byte"}}},"pulsarchain.keyregistry.v1.QueryGetValidatorMinaPubKeyResponse":{"description":"QueryGetValidatorMinaAddressResponse defines the QueryGetValidatorMinaAddressResponse message.","type":"object","properties":{"validator_mina_pub_key":{"type":"string","format":"byte"}}},"pulsarchain.keyregistry.v1.QueryParamsResponse":{"description":"QueryParamsResponse is response type for the Query/Params RPC method.","type":"object","properties":{"params":{"description":"params holds all the parameters of this module.","$ref":"#/definitions/pulsarchain.keyregistry.v1.Params"}}}},"tags":[{"name":"Query"},{"name":"Msg"}]} \ No newline at end of file From 1507a5fb09b709667bf48fa865e10c01e793d85c Mon Sep 17 00:00:00 2001 From: Yusuf Date: Tue, 14 Apr 2026 23:00:44 +0300 Subject: [PATCH 03/62] feat: update keys msg implementation --- buf.lock | 4 +- .../keyregistry/v1/key_update_type.proto | 9 + proto/pulsarchain/keyregistry/v1/tx.proto | 18 + .../keeper/msg_server_update_keys.go | 97 +++ x/keyregistry/module/autocli.go | 6 + x/keyregistry/module/simulation.go | 15 + x/keyregistry/simulation/update_keys.go | 32 + x/keyregistry/types/codec.go | 4 + x/keyregistry/types/errors.go | 2 + x/keyregistry/types/key_update_type.pb.go | 70 ++ x/keyregistry/types/tx.pb.go | 652 +++++++++++++++++- 11 files changed, 873 insertions(+), 36 deletions(-) create mode 100644 proto/pulsarchain/keyregistry/v1/key_update_type.proto create mode 100644 x/keyregistry/keeper/msg_server_update_keys.go create mode 100644 x/keyregistry/simulation/update_keys.go create mode 100644 x/keyregistry/types/key_update_type.pb.go diff --git a/buf.lock b/buf.lock index ffa7ce8c..2da6522e 100644 --- a/buf.lock +++ b/buf.lock @@ -17,8 +17,8 @@ deps: commit: dc427cb4519143d8996361c045a29ad7 digest: b5:8693e72e230bfaf58a88a47a4093ba99f6252c1957a45582567959b38a8563e2abd11443372283d75f4f2306a7e3cc9bf63604d284a016c11966fca4b74b7a28 - name: buf.build/googleapis/googleapis - commit: 004180b77378443887d3b55cabc00384 - digest: b5:e8f475fe3330f31f5fd86ac689093bcd274e19611a09db91f41d637cb9197881ce89882b94d13a58738e53c91c6e4bae7dc1feba85f590164c975a89e25115dc + commit: 536964a08a534d51b8f30f2d6751f1f9 + digest: b5:3e05d27e797b00c345fadd3c15cf0e16c4cc693036a55059721e66d6ce22a96264a4897658c9243bb0874fa9ca96e437589eb512189d2754604a626c632f6030 - name: buf.build/protocolbuffers/wellknowntypes commit: 9d16d599a978406980f6e2f081331a93 digest: b5:dd06e497a5c52f5ddf6ec02b3c7d289cc6c0432093fc2f6bf7a4fb5fae786c3e4c893e55d2759ffb6833268daf3de0bce303a406fed15725790528f2c27dc219 diff --git a/proto/pulsarchain/keyregistry/v1/key_update_type.proto b/proto/pulsarchain/keyregistry/v1/key_update_type.proto new file mode 100644 index 00000000..1ed9ae04 --- /dev/null +++ b/proto/pulsarchain/keyregistry/v1/key_update_type.proto @@ -0,0 +1,9 @@ +syntax = "proto3"; +package pulsarchain.keyregistry.v1; + +option go_package = "github.com/node101-io/pulsar-chain/x/keyregistry/types"; + +enum KeyUpdateType { + USER = 0; + VALIDATOR = 1; +} diff --git a/proto/pulsarchain/keyregistry/v1/tx.proto b/proto/pulsarchain/keyregistry/v1/tx.proto index 6a8826bf..465ab0fe 100644 --- a/proto/pulsarchain/keyregistry/v1/tx.proto +++ b/proto/pulsarchain/keyregistry/v1/tx.proto @@ -7,6 +7,7 @@ import "cosmos/msg/v1/msg.proto"; import "cosmos_proto/cosmos.proto"; import "gogoproto/gogo.proto"; import "pulsarchain/keyregistry/v1/params.proto"; +import "pulsarchain/keyregistry/v1/key_update_type.proto"; option go_package = "github.com/node101-io/pulsar-chain/x/keyregistry/types"; @@ -20,6 +21,9 @@ service Msg { // RegisterKeys defines the RegisterKeys RPC. rpc RegisterKeys(MsgRegisterKeys) returns (MsgRegisterKeysResponse); + + // UpdateKeys defines the UpdateKeys RPC. + rpc UpdateKeys(MsgUpdateKeys) returns (MsgUpdateKeysResponse); } // MsgUpdateParams is the Msg/UpdateParams request type. @@ -56,3 +60,17 @@ message MsgRegisterKeys { // MsgRegisterKeysResponse defines the MsgRegisterKeysResponse message. message MsgRegisterKeysResponse {} + +// MsgUpdateKeys defines the MsgUpdateKeys message. +message MsgUpdateKeys { + option (cosmos.msg.v1.signer) = "creator"; + string creator = 1 [(cosmos_proto.scalar) = "cosmos.AddressString"]; + bytes prev_mina_public_key = 2; + bytes new_mina_public_key = 3; + bytes cosmos_signature = 4; + bytes new_mina_signature = 5; + KeyUpdateType update_type = 6; +} + +// MsgUpdateKeysResponse defines the MsgUpdateKeysResponse message. +message MsgUpdateKeysResponse {} diff --git a/x/keyregistry/keeper/msg_server_update_keys.go b/x/keyregistry/keeper/msg_server_update_keys.go new file mode 100644 index 00000000..8f75800a --- /dev/null +++ b/x/keyregistry/keeper/msg_server_update_keys.go @@ -0,0 +1,97 @@ +package keeper + +import ( + "context" + + errorsmod "cosmossdk.io/errors" + "github.com/node101-io/pulsar-chain/x/keyregistry/types" +) + +func (k msgServer) UpdateKeys(ctx context.Context, msg *types.MsgUpdateKeys) (*types.MsgUpdateKeysResponse, error) { + if _, err := k.addressCodec.StringToBytes(msg.Creator); err != nil { + return nil, errorsmod.Wrap(err, "invalid authority address") + } + + if msg.UpdateType == types.KeyUpdateType_USER { + + exists, err := k.UserCosmosToMinaHas(ctx, []byte(msg.Creator)) + if err != nil { + return nil, err + } + if !exists { + return nil, types.ErrUserNotRegistered + } + exists, err = k.UserMinaToCosmosHas(ctx, msg.PrevMinaPublicKey) + if err != nil { + return nil, err + } + if !exists { + return nil, types.ErrUserNotRegistered + } + + if !VerifyUserMinaSig(string(msg.NewMinaSignature), []byte(msg.Creator), msg.NewMinaPublicKey) { + return nil, types.ErrInvalidSignature + } + + err = k.userMinaToCosmos.Remove(ctx, msg.PrevMinaPublicKey) + if err != nil { + return nil, err + } + err = k.userCosmosToMina.Remove(ctx, []byte(msg.Creator)) + if err != nil { + return nil, err + } + + err = k.userCosmosToMina.Set(ctx, []byte(msg.Creator), msg.NewMinaPublicKey) + if err != nil { + return nil, err + } + err = k.userMinaToCosmos.Set(ctx, msg.NewMinaPublicKey, []byte(msg.Creator)) + if err != nil { + return nil, err + } + } + + if msg.UpdateType == types.KeyUpdateType_VALIDATOR { + + exists, err := k.ValidatorCosmosToMinaHas(ctx, []byte(msg.Creator)) + if err != nil { + return nil, err + } + if !exists { + return nil, types.ErrValidatorNotRegistered + } + + exists, err = k.ValidatorMinaToCosmosHas(ctx, msg.PrevMinaPublicKey) + if err != nil { + return nil, err + } + if !exists { + return nil, types.ErrValidatorNotRegistered + } + + if !VerifyValidatorMinaSig(string(msg.NewMinaSignature), []byte(msg.Creator), msg.NewMinaPublicKey) { + return nil, types.ErrInvalidSignature + } + + err = k.validatorMinaToCosmos.Remove(ctx, msg.PrevMinaPublicKey) + if err != nil { + return nil, err + } + err = k.validatorCosmosToMina.Remove(ctx, []byte(msg.Creator)) + if err != nil { + return nil, err + } + + err = k.validatorCosmosToMina.Set(ctx, []byte(msg.Creator), msg.NewMinaPublicKey) + if err != nil { + return nil, err + } + err = k.validatorMinaToCosmos.Set(ctx, msg.NewMinaPublicKey, []byte(msg.Creator)) + if err != nil { + return nil, err + } + } + + return &types.MsgUpdateKeysResponse{}, nil +} diff --git a/x/keyregistry/module/autocli.go b/x/keyregistry/module/autocli.go index 206950c9..c74331e3 100644 --- a/x/keyregistry/module/autocli.go +++ b/x/keyregistry/module/autocli.go @@ -62,6 +62,12 @@ func (am AppModule) AutoCLIOptions() *autocliv1.ModuleOptions { Short: "Send a registerKeys tx", PositionalArgs: []*autocliv1.PositionalArgDescriptor{{ProtoField: "cosmos_signature"}, {ProtoField: "mina_signature"}, {ProtoField: "cosmos_address"}, {ProtoField: "mina_address", Varargs: true}}, }, + { + RpcMethod: "UpdateKeys", + Use: "update-keys ", + Short: "Send a UpdateKeys tx", + PositionalArgs: []*autocliv1.PositionalArgDescriptor{}, + }, // this line is used by ignite scaffolding # autocli/tx }, }, diff --git a/x/keyregistry/module/simulation.go b/x/keyregistry/module/simulation.go index e867e489..7c327cda 100644 --- a/x/keyregistry/module/simulation.go +++ b/x/keyregistry/module/simulation.go @@ -44,6 +44,21 @@ func (am AppModule) WeightedOperations(simState module.SimulationState) []simtyp weightMsgRegisterKeys, keyregistrysimulation.SimulateMsgRegisterKeys(am.authKeeper, am.bankKeeper, am.keeper, simState.TxConfig), )) + const ( + opWeightMsgUpdateKeys = "op_weight_msg_keyregistry" + defaultWeightMsgUpdateKeys int = 100 + ) + + var weightMsgUpdateKeys int + simState.AppParams.GetOrGenerate(opWeightMsgUpdateKeys, &weightMsgUpdateKeys, nil, + func(_ *rand.Rand) { + weightMsgUpdateKeys = defaultWeightMsgUpdateKeys + }, + ) + operations = append(operations, simulation.NewWeightedOperation( + weightMsgUpdateKeys, + keyregistrysimulation.SimulateMsgUpdateKeys(am.authKeeper, am.bankKeeper, am.keeper, simState.TxConfig), + )) return operations } diff --git a/x/keyregistry/simulation/update_keys.go b/x/keyregistry/simulation/update_keys.go new file mode 100644 index 00000000..bb4d0608 --- /dev/null +++ b/x/keyregistry/simulation/update_keys.go @@ -0,0 +1,32 @@ +package simulation + +import ( + "math/rand" + + "github.com/cosmos/cosmos-sdk/baseapp" + "github.com/cosmos/cosmos-sdk/client" + sdk "github.com/cosmos/cosmos-sdk/types" + simtypes "github.com/cosmos/cosmos-sdk/types/simulation" + + "github.com/node101-io/pulsar-chain/x/keyregistry/keeper" + "github.com/node101-io/pulsar-chain/x/keyregistry/types" +) + +func SimulateMsgUpdateKeys( + ak types.AuthKeeper, + bk types.BankKeeper, + k keeper.Keeper, + txGen client.TxConfig, +) simtypes.Operation { + return func(r *rand.Rand, app *baseapp.BaseApp, ctx sdk.Context, accs []simtypes.Account, chainID string, + ) (simtypes.OperationMsg, []simtypes.FutureOperation, error) { + simAccount, _ := simtypes.RandomAcc(r, accs) + msg := &types.MsgUpdateKeys{ + Creator: simAccount.Address.String(), + } + + // TODO: Handle the UpdateKeys simulation + + return simtypes.NoOpMsg(types.ModuleName, sdk.MsgTypeURL(msg), "UpdateKeys simulation not implemented"), nil, nil + } +} diff --git a/x/keyregistry/types/codec.go b/x/keyregistry/types/codec.go index 7e1f4224..ee459eb8 100644 --- a/x/keyregistry/types/codec.go +++ b/x/keyregistry/types/codec.go @@ -7,6 +7,10 @@ import ( ) func RegisterInterfaces(registrar codectypes.InterfaceRegistry) { + registrar.RegisterImplementations((*sdk.Msg)(nil), + &MsgUpdateKeys{}, + ) + registrar.RegisterImplementations((*sdk.Msg)(nil), &MsgRegisterKeys{}, ) diff --git a/x/keyregistry/types/errors.go b/x/keyregistry/types/errors.go index 8a8fd513..1750d565 100644 --- a/x/keyregistry/types/errors.go +++ b/x/keyregistry/types/errors.go @@ -15,4 +15,6 @@ var ( ErrInvalidCreatorAddres = errors.Register(ModuleName, 1104, "invalid creator address") ErrInvalidPublicKey = errors.Register(ModuleName, 1105, "invalid public key") ErrInvalidAddress = errors.Register(ModuleName, 1106, "invalid address") + ErrUserNotRegistered = errors.Register(ModuleName, 1107, "user has not been registered") + ErrValidatorNotRegistered = errors.Register(ModuleName, 1108, "validator has not been registered") ) diff --git a/x/keyregistry/types/key_update_type.pb.go b/x/keyregistry/types/key_update_type.pb.go new file mode 100644 index 00000000..582b511e --- /dev/null +++ b/x/keyregistry/types/key_update_type.pb.go @@ -0,0 +1,70 @@ +// Code generated by protoc-gen-gogo. DO NOT EDIT. +// source: pulsarchain/keyregistry/v1/key_update_type.proto + +package types + +import ( + fmt "fmt" + proto "github.com/cosmos/gogoproto/proto" + math "math" +) + +// Reference imports to suppress errors if they are not otherwise used. +var _ = proto.Marshal +var _ = fmt.Errorf +var _ = math.Inf + +// This is a compile-time assertion to ensure that this generated file +// is compatible with the proto package it is being compiled against. +// A compilation error at this line likely means your copy of the +// proto package needs to be updated. +const _ = proto.GoGoProtoPackageIsVersion3 // please upgrade the proto package + +type KeyUpdateType int32 + +const ( + KeyUpdateType_USER KeyUpdateType = 0 + KeyUpdateType_VALIDATOR KeyUpdateType = 1 +) + +var KeyUpdateType_name = map[int32]string{ + 0: "USER", + 1: "VALIDATOR", +} + +var KeyUpdateType_value = map[string]int32{ + "USER": 0, + "VALIDATOR": 1, +} + +func (x KeyUpdateType) String() string { + return proto.EnumName(KeyUpdateType_name, int32(x)) +} + +func (KeyUpdateType) EnumDescriptor() ([]byte, []int) { + return fileDescriptor_ba25ac2a902d16f7, []int{0} +} + +func init() { + proto.RegisterEnum("pulsarchain.keyregistry.v1.KeyUpdateType", KeyUpdateType_name, KeyUpdateType_value) +} + +func init() { + proto.RegisterFile("pulsarchain/keyregistry/v1/key_update_type.proto", fileDescriptor_ba25ac2a902d16f7) +} + +var fileDescriptor_ba25ac2a902d16f7 = []byte{ + // 190 bytes of a gzipped FileDescriptorProto + 0x1f, 0x8b, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0xff, 0xe2, 0x32, 0x28, 0x28, 0xcd, 0x29, + 0x4e, 0x2c, 0x4a, 0xce, 0x48, 0xcc, 0xcc, 0xd3, 0xcf, 0x4e, 0xad, 0x2c, 0x4a, 0x4d, 0xcf, 0x2c, + 0x2e, 0x29, 0xaa, 0xd4, 0x2f, 0x33, 0x04, 0x71, 0xe3, 0x4b, 0x0b, 0x52, 0x12, 0x4b, 0x52, 0xe3, + 0x4b, 0x2a, 0x0b, 0x52, 0xf5, 0x0a, 0x8a, 0xf2, 0x4b, 0xf2, 0x85, 0xa4, 0x90, 0x74, 0xe8, 0x21, + 0xe9, 0xd0, 0x2b, 0x33, 0xd4, 0xd2, 0xe0, 0xe2, 0xf5, 0x4e, 0xad, 0x0c, 0x05, 0xeb, 0x09, 0xa9, + 0x2c, 0x48, 0x15, 0xe2, 0xe0, 0x62, 0x09, 0x0d, 0x76, 0x0d, 0x12, 0x60, 0x10, 0xe2, 0xe5, 0xe2, + 0x0c, 0x73, 0xf4, 0xf1, 0x74, 0x71, 0x0c, 0xf1, 0x0f, 0x12, 0x60, 0x74, 0x0a, 0x38, 0xf1, 0x48, + 0x8e, 0xf1, 0xc2, 0x23, 0x39, 0xc6, 0x07, 0x8f, 0xe4, 0x18, 0x27, 0x3c, 0x96, 0x63, 0xb8, 0xf0, + 0x58, 0x8e, 0xe1, 0xc6, 0x63, 0x39, 0x86, 0x28, 0xb3, 0xf4, 0xcc, 0x92, 0x8c, 0xd2, 0x24, 0xbd, + 0xe4, 0xfc, 0x5c, 0xfd, 0xbc, 0xfc, 0x94, 0x54, 0x43, 0x03, 0x43, 0xdd, 0xcc, 0x7c, 0x7d, 0x88, + 0xad, 0xba, 0x10, 0x87, 0x56, 0xa0, 0x38, 0x15, 0xe4, 0xb8, 0xe2, 0x24, 0x36, 0xb0, 0xf3, 0x8c, + 0x01, 0x01, 0x00, 0x00, 0xff, 0xff, 0xdb, 0x9b, 0x81, 0x4a, 0xd2, 0x00, 0x00, 0x00, +} diff --git a/x/keyregistry/types/tx.pb.go b/x/keyregistry/types/tx.pb.go index b62220a3..ceb0b928 100644 --- a/x/keyregistry/types/tx.pb.go +++ b/x/keyregistry/types/tx.pb.go @@ -246,11 +246,135 @@ func (m *MsgRegisterKeysResponse) XXX_DiscardUnknown() { var xxx_messageInfo_MsgRegisterKeysResponse proto.InternalMessageInfo +// MsgUpdateKeys defines the MsgUpdateKeys message. +type MsgUpdateKeys struct { + Creator string `protobuf:"bytes,1,opt,name=creator,proto3" json:"creator,omitempty"` + PrevMinaPublicKey []byte `protobuf:"bytes,2,opt,name=prev_mina_public_key,json=prevMinaPublicKey,proto3" json:"prev_mina_public_key,omitempty"` + NewMinaPublicKey []byte `protobuf:"bytes,3,opt,name=new_mina_public_key,json=newMinaPublicKey,proto3" json:"new_mina_public_key,omitempty"` + CosmosSignature []byte `protobuf:"bytes,4,opt,name=cosmos_signature,json=cosmosSignature,proto3" json:"cosmos_signature,omitempty"` + NewMinaSignature []byte `protobuf:"bytes,5,opt,name=new_mina_signature,json=newMinaSignature,proto3" json:"new_mina_signature,omitempty"` + UpdateType KeyUpdateType `protobuf:"varint,6,opt,name=update_type,json=updateType,proto3,enum=pulsarchain.keyregistry.v1.KeyUpdateType" json:"update_type,omitempty"` +} + +func (m *MsgUpdateKeys) Reset() { *m = MsgUpdateKeys{} } +func (m *MsgUpdateKeys) String() string { return proto.CompactTextString(m) } +func (*MsgUpdateKeys) ProtoMessage() {} +func (*MsgUpdateKeys) Descriptor() ([]byte, []int) { + return fileDescriptor_235f5fb22cc1f8d8, []int{4} +} +func (m *MsgUpdateKeys) XXX_Unmarshal(b []byte) error { + return m.Unmarshal(b) +} +func (m *MsgUpdateKeys) XXX_Marshal(b []byte, deterministic bool) ([]byte, error) { + if deterministic { + return xxx_messageInfo_MsgUpdateKeys.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 *MsgUpdateKeys) XXX_Merge(src proto.Message) { + xxx_messageInfo_MsgUpdateKeys.Merge(m, src) +} +func (m *MsgUpdateKeys) XXX_Size() int { + return m.Size() +} +func (m *MsgUpdateKeys) XXX_DiscardUnknown() { + xxx_messageInfo_MsgUpdateKeys.DiscardUnknown(m) +} + +var xxx_messageInfo_MsgUpdateKeys proto.InternalMessageInfo + +func (m *MsgUpdateKeys) GetCreator() string { + if m != nil { + return m.Creator + } + return "" +} + +func (m *MsgUpdateKeys) GetPrevMinaPublicKey() []byte { + if m != nil { + return m.PrevMinaPublicKey + } + return nil +} + +func (m *MsgUpdateKeys) GetNewMinaPublicKey() []byte { + if m != nil { + return m.NewMinaPublicKey + } + return nil +} + +func (m *MsgUpdateKeys) GetCosmosSignature() []byte { + if m != nil { + return m.CosmosSignature + } + return nil +} + +func (m *MsgUpdateKeys) GetNewMinaSignature() []byte { + if m != nil { + return m.NewMinaSignature + } + return nil +} + +func (m *MsgUpdateKeys) GetUpdateType() KeyUpdateType { + if m != nil { + return m.UpdateType + } + return KeyUpdateType_USER +} + +// MsgUpdateKeysResponse defines the MsgUpdateKeysResponse message. +type MsgUpdateKeysResponse struct { +} + +func (m *MsgUpdateKeysResponse) Reset() { *m = MsgUpdateKeysResponse{} } +func (m *MsgUpdateKeysResponse) String() string { return proto.CompactTextString(m) } +func (*MsgUpdateKeysResponse) ProtoMessage() {} +func (*MsgUpdateKeysResponse) Descriptor() ([]byte, []int) { + return fileDescriptor_235f5fb22cc1f8d8, []int{5} +} +func (m *MsgUpdateKeysResponse) XXX_Unmarshal(b []byte) error { + return m.Unmarshal(b) +} +func (m *MsgUpdateKeysResponse) XXX_Marshal(b []byte, deterministic bool) ([]byte, error) { + if deterministic { + return xxx_messageInfo_MsgUpdateKeysResponse.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 *MsgUpdateKeysResponse) XXX_Merge(src proto.Message) { + xxx_messageInfo_MsgUpdateKeysResponse.Merge(m, src) +} +func (m *MsgUpdateKeysResponse) XXX_Size() int { + return m.Size() +} +func (m *MsgUpdateKeysResponse) XXX_DiscardUnknown() { + xxx_messageInfo_MsgUpdateKeysResponse.DiscardUnknown(m) +} + +var xxx_messageInfo_MsgUpdateKeysResponse proto.InternalMessageInfo + func init() { proto.RegisterType((*MsgUpdateParams)(nil), "pulsarchain.keyregistry.v1.MsgUpdateParams") proto.RegisterType((*MsgUpdateParamsResponse)(nil), "pulsarchain.keyregistry.v1.MsgUpdateParamsResponse") proto.RegisterType((*MsgRegisterKeys)(nil), "pulsarchain.keyregistry.v1.MsgRegisterKeys") proto.RegisterType((*MsgRegisterKeysResponse)(nil), "pulsarchain.keyregistry.v1.MsgRegisterKeysResponse") + proto.RegisterType((*MsgUpdateKeys)(nil), "pulsarchain.keyregistry.v1.MsgUpdateKeys") + proto.RegisterType((*MsgUpdateKeysResponse)(nil), "pulsarchain.keyregistry.v1.MsgUpdateKeysResponse") } func init() { @@ -258,40 +382,48 @@ func init() { } var fileDescriptor_235f5fb22cc1f8d8 = []byte{ - // 514 bytes of a gzipped FileDescriptorProto - 0x1f, 0x8b, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0xff, 0x94, 0x93, 0x31, 0x6f, 0x13, 0x31, - 0x14, 0xc7, 0xe3, 0x96, 0xa6, 0xc4, 0x4d, 0x29, 0x9c, 0x2a, 0x25, 0xcd, 0x70, 0x84, 0x20, 0x44, - 0x1a, 0x94, 0x3b, 0x92, 0x4a, 0x1d, 0x2a, 0x16, 0x22, 0x31, 0xa1, 0x4a, 0xd5, 0x55, 0x5d, 0x58, - 0x2a, 0x37, 0xb1, 0x1c, 0x0b, 0xee, 0x7c, 0xf2, 0x73, 0xaa, 0xde, 0x86, 0x98, 0x10, 0x13, 0x1f, - 0x83, 0x31, 0x03, 0x1f, 0xa2, 0x13, 0xaa, 0x98, 0x98, 0x10, 0x4a, 0x86, 0xac, 0x7c, 0x04, 0x74, - 0xb6, 0x4f, 0xbd, 0x44, 0xa5, 0x51, 0x97, 0x28, 0xfe, 0xbf, 0x9f, 0xdf, 0xdf, 0xff, 0x67, 0x1f, - 0x7e, 0x1a, 0x8f, 0x3e, 0x00, 0x91, 0xfd, 0x21, 0xe1, 0x91, 0xff, 0x9e, 0x26, 0x92, 0x32, 0x0e, - 0x4a, 0x26, 0xfe, 0x79, 0xc7, 0x57, 0x17, 0x5e, 0x2c, 0x85, 0x12, 0x4e, 0x2d, 0x07, 0x79, 0x39, - 0xc8, 0x3b, 0xef, 0xd4, 0x1e, 0x91, 0x90, 0x47, 0xc2, 0xd7, 0xbf, 0x06, 0xaf, 0x55, 0xfa, 0x02, - 0x42, 0x01, 0x7e, 0x08, 0x2c, 0x6d, 0x13, 0x02, 0xb3, 0x85, 0x1d, 0x53, 0x38, 0xd5, 0x2b, 0xdf, - 0x2c, 0x6c, 0x69, 0x9b, 0x09, 0x26, 0x8c, 0x9e, 0xfe, 0xb3, 0xea, 0xf3, 0x5b, 0x4e, 0x17, 0x13, - 0x49, 0x42, 0xbb, 0xbd, 0xf1, 0x03, 0xe1, 0xad, 0x43, 0x60, 0x27, 0xf1, 0x80, 0x28, 0x7a, 0xa4, - 0x2b, 0xce, 0x3e, 0x2e, 0x91, 0x91, 0x1a, 0x0a, 0xc9, 0x55, 0x52, 0x45, 0x75, 0xd4, 0x2c, 0xf5, - 0xaa, 0x3f, 0xbf, 0xb7, 0xb7, 0xad, 0xef, 0xeb, 0xc1, 0x40, 0x52, 0x80, 0x63, 0x25, 0x79, 0xc4, - 0x82, 0x6b, 0xd4, 0x79, 0x83, 0x8b, 0xa6, 0x77, 0x75, 0xa5, 0x8e, 0x9a, 0x1b, 0xdd, 0x86, 0xf7, - 0xff, 0xf8, 0x9e, 0xf1, 0xea, 0x95, 0x2e, 0x7f, 0x3f, 0x2e, 0x7c, 0x9b, 0x8d, 0x5b, 0x28, 0xb0, - 0x9b, 0x0f, 0x5e, 0x7d, 0x9a, 0x8d, 0x5b, 0xd7, 0x6d, 0xbf, 0xcc, 0xc6, 0xad, 0xdd, 0x7c, 0x9c, - 0x8b, 0xb9, 0x40, 0x0b, 0x87, 0x6f, 0xec, 0xe0, 0xca, 0x82, 0x14, 0x50, 0x88, 0x45, 0x04, 0xb4, - 0xf1, 0x79, 0x45, 0x67, 0x0d, 0xf4, 0x56, 0x2a, 0xdf, 0xd2, 0x04, 0x9c, 0x2e, 0x5e, 0xef, 0x4b, - 0x4a, 0x94, 0x90, 0x4b, 0x93, 0x66, 0xa0, 0xb3, 0x8b, 0x1f, 0xda, 0xfb, 0x00, 0xce, 0x22, 0xa2, - 0x46, 0x92, 0xea, 0xc4, 0xa5, 0x60, 0xcb, 0xe8, 0xc7, 0x99, 0xec, 0x3c, 0xc3, 0x0f, 0x42, 0x1e, - 0x91, 0x1c, 0xb8, 0xaa, 0xc1, 0xcd, 0x54, 0x9d, 0xc3, 0x6c, 0x47, 0x62, 0x2c, 0xab, 0xf7, 0xea, - 0xa8, 0x59, 0x0e, 0x36, 0x8d, 0x6a, 0xcf, 0xe1, 0x3c, 0xc1, 0x65, 0xdd, 0x2d, 0x83, 0xd6, 0x34, - 0xb4, 0x91, 0x6a, 0x19, 0x52, 0xc1, 0xeb, 0x1c, 0x4e, 0x47, 0x40, 0x65, 0xb5, 0x58, 0x47, 0xcd, - 0xfb, 0x41, 0x91, 0xc3, 0x09, 0x50, 0x79, 0x50, 0x4e, 0xa7, 0x9a, 0x45, 0xb0, 0x53, 0xca, 0x4f, - 0x22, 0x9b, 0x52, 0xf7, 0x2f, 0xc2, 0xab, 0x87, 0xc0, 0x9c, 0x18, 0x97, 0xe7, 0x5e, 0xc5, 0x8b, - 0xdb, 0x6e, 0x73, 0x61, 0xe4, 0xb5, 0xbd, 0x3b, 0xc0, 0x99, 0x73, 0xea, 0x38, 0x77, 0x37, 0xcb, - 0x1c, 0xf3, 0xf0, 0x52, 0xc7, 0x9b, 0xb2, 0xd6, 0xd6, 0x3e, 0xa6, 0x2f, 0xaf, 0x77, 0x74, 0x39, - 0x71, 0xd1, 0xd5, 0xc4, 0x45, 0x7f, 0x26, 0x2e, 0xfa, 0x3a, 0x75, 0x0b, 0x57, 0x53, 0xb7, 0xf0, - 0x6b, 0xea, 0x16, 0xde, 0xed, 0x33, 0xae, 0x86, 0xa3, 0x33, 0xaf, 0x2f, 0x42, 0x3f, 0x12, 0x03, - 0xda, 0x79, 0xd9, 0x69, 0x73, 0xe1, 0x1b, 0xab, 0xf6, 0x4d, 0xef, 0x51, 0x25, 0x31, 0x85, 0xb3, - 0xa2, 0xfe, 0xba, 0xf6, 0xfe, 0x05, 0x00, 0x00, 0xff, 0xff, 0x1b, 0x60, 0xd1, 0xae, 0x26, 0x04, - 0x00, 0x00, + // 655 bytes of a gzipped FileDescriptorProto + 0x1f, 0x8b, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0xff, 0x9c, 0x94, 0xbf, 0x6f, 0xd3, 0x40, + 0x14, 0xc7, 0xe3, 0x94, 0xa6, 0xe4, 0x9a, 0xfe, 0x32, 0x45, 0x49, 0x33, 0x98, 0x10, 0x84, 0x48, + 0x0a, 0xb1, 0x9b, 0x54, 0xea, 0x50, 0xb1, 0x50, 0x89, 0x85, 0xaa, 0x52, 0xe5, 0xd2, 0x85, 0xc5, + 0xba, 0x26, 0x27, 0xe7, 0x48, 0xed, 0xb3, 0xee, 0xec, 0xb4, 0xde, 0x10, 0x13, 0x62, 0xe2, 0xcf, + 0x60, 0xcc, 0xc0, 0x1f, 0xd1, 0x09, 0x55, 0x0c, 0x88, 0x01, 0x21, 0x94, 0x0c, 0xf9, 0x37, 0x90, + 0xef, 0xec, 0xc4, 0x4e, 0x43, 0x52, 0x58, 0xa2, 0xf8, 0xbd, 0xcf, 0xbd, 0xef, 0x7b, 0xdf, 0xfb, + 0x01, 0x1e, 0x39, 0xde, 0x39, 0x83, 0xb4, 0xd9, 0x86, 0xd8, 0xd6, 0x3a, 0xc8, 0xa7, 0xc8, 0xc4, + 0xcc, 0xa5, 0xbe, 0xd6, 0xad, 0x6b, 0xee, 0xa5, 0xea, 0x50, 0xe2, 0x12, 0xb9, 0x18, 0x83, 0xd4, + 0x18, 0xa4, 0x76, 0xeb, 0xc5, 0x0d, 0x68, 0x61, 0x9b, 0x68, 0xfc, 0x57, 0xe0, 0xc5, 0x7c, 0x93, + 0x30, 0x8b, 0x30, 0xcd, 0x62, 0x66, 0x50, 0xc6, 0x62, 0x66, 0x98, 0xd8, 0x12, 0x09, 0x83, 0x7f, + 0x69, 0xe2, 0x23, 0x4c, 0x6d, 0x9a, 0xc4, 0x24, 0x22, 0x1e, 0xfc, 0x0b, 0xa3, 0x4f, 0x66, 0x74, + 0xe7, 0x40, 0x0a, 0xad, 0x68, 0xf9, 0xce, 0x0c, 0xb0, 0x83, 0x7c, 0xc3, 0x73, 0x5a, 0xd0, 0x45, + 0x86, 0xeb, 0x3b, 0x48, 0xac, 0x28, 0x7f, 0x95, 0xc0, 0xda, 0x11, 0x33, 0x4f, 0x79, 0xe2, 0x98, + 0xd7, 0x92, 0xf7, 0x40, 0x16, 0x7a, 0x6e, 0x9b, 0x50, 0xec, 0xfa, 0x05, 0xa9, 0x24, 0x55, 0xb2, + 0x07, 0x85, 0x6f, 0x5f, 0x6a, 0x9b, 0x61, 0xa7, 0x2f, 0x5a, 0x2d, 0x8a, 0x18, 0x3b, 0x71, 0x29, + 0xb6, 0x4d, 0x7d, 0x8c, 0xca, 0x2f, 0x41, 0x46, 0x74, 0x53, 0x48, 0x97, 0xa4, 0xca, 0x72, 0xa3, + 0xac, 0xfe, 0xdd, 0x30, 0x55, 0x68, 0x1d, 0x64, 0xaf, 0x7e, 0x3d, 0x48, 0x7d, 0x1e, 0xf6, 0xb6, + 0x25, 0x3d, 0x5c, 0xbc, 0xff, 0xfc, 0xfd, 0xb0, 0xb7, 0x3d, 0x2e, 0xfb, 0x71, 0xd8, 0xdb, 0xae, + 0xc6, 0xe7, 0xba, 0x4c, 0x4c, 0x36, 0xd1, 0x7c, 0x79, 0x0b, 0xe4, 0x27, 0x42, 0x3a, 0x62, 0x0e, + 0xb1, 0x19, 0x2a, 0x7f, 0x48, 0xf3, 0x59, 0x75, 0xbe, 0x14, 0xd1, 0x43, 0xe4, 0x33, 0xb9, 0x01, + 0x96, 0x9a, 0x14, 0x41, 0x97, 0xd0, 0xb9, 0x93, 0x46, 0xa0, 0x5c, 0x05, 0xeb, 0xe1, 0x0e, 0x32, + 0x6c, 0xda, 0xd0, 0xf5, 0x28, 0xe2, 0x13, 0x67, 0xf5, 0x35, 0x11, 0x3f, 0x89, 0xc2, 0xf2, 0x63, + 0xb0, 0x6a, 0x61, 0x1b, 0xc6, 0xc0, 0x05, 0x0e, 0xae, 0x04, 0xd1, 0x04, 0x16, 0x56, 0x84, 0x42, + 0xb2, 0x70, 0xa7, 0x24, 0x55, 0x72, 0xfa, 0x8a, 0x88, 0x86, 0x7d, 0xc8, 0x0f, 0x41, 0x8e, 0x57, + 0x8b, 0xa0, 0x45, 0x0e, 0x2d, 0x07, 0xb1, 0x08, 0xc9, 0x83, 0x25, 0xcc, 0x0c, 0x8f, 0x21, 0x5a, + 0xc8, 0x94, 0xa4, 0xca, 0x5d, 0x3d, 0x83, 0xd9, 0x29, 0x43, 0x74, 0x3f, 0x17, 0xb8, 0x1a, 0x8d, + 0x10, 0xba, 0x14, 0x77, 0x62, 0xe4, 0xd2, 0xf7, 0x34, 0x58, 0x19, 0x39, 0xf8, 0xdf, 0x1e, 0x69, + 0x60, 0xd3, 0xa1, 0xa8, 0x6b, 0xf0, 0x7e, 0x1d, 0xef, 0xec, 0x1c, 0x37, 0x8d, 0x0e, 0xf2, 0xb9, + 0x4f, 0x39, 0x7d, 0x23, 0xc8, 0x1d, 0x61, 0x1b, 0x1e, 0xf3, 0xcc, 0x21, 0xf2, 0xe5, 0x1a, 0xb8, + 0x67, 0xa3, 0x8b, 0x1b, 0xfc, 0x02, 0xe7, 0xd7, 0x6d, 0x74, 0x91, 0xc4, 0xa7, 0xed, 0x81, 0xf0, + 0xec, 0xc6, 0x1e, 0x3c, 0x03, 0xf2, 0xa8, 0xf2, 0x18, 0x5e, 0x4c, 0x14, 0x1e, 0xd3, 0xaf, 0xc0, + 0x72, 0xec, 0x96, 0x70, 0x13, 0x57, 0x1b, 0xd5, 0x59, 0x27, 0xf9, 0x10, 0xf9, 0xc2, 0xac, 0xd7, + 0xbe, 0x83, 0x74, 0xe0, 0x8d, 0xfe, 0x4f, 0x78, 0x9e, 0x07, 0xf7, 0x13, 0xbe, 0x46, 0x8e, 0x37, + 0x7e, 0xa6, 0xc1, 0xc2, 0x11, 0x33, 0x65, 0x07, 0xe4, 0x12, 0xf7, 0xf0, 0xe9, 0x2c, 0xd5, 0x89, + 0x43, 0x5e, 0xdc, 0xfd, 0x07, 0x38, 0x52, 0x0e, 0x14, 0x13, 0xb7, 0x61, 0x9e, 0x62, 0x1c, 0x9e, + 0xab, 0x38, 0xed, 0x74, 0xc9, 0x6f, 0x01, 0x88, 0x9d, 0xac, 0xea, 0xad, 0x9a, 0xe6, 0x6a, 0xf5, + 0x5b, 0xa3, 0x91, 0x56, 0x71, 0xf1, 0x5d, 0xf0, 0xae, 0x1c, 0x1c, 0x5f, 0xf5, 0x15, 0xe9, 0xba, + 0xaf, 0x48, 0xbf, 0xfb, 0x8a, 0xf4, 0x69, 0xa0, 0xa4, 0xae, 0x07, 0x4a, 0xea, 0xc7, 0x40, 0x49, + 0xbd, 0xd9, 0x33, 0xb1, 0xdb, 0xf6, 0xce, 0xd4, 0x26, 0xb1, 0x34, 0x9b, 0xb4, 0x50, 0x7d, 0xa7, + 0x5e, 0xc3, 0x44, 0x13, 0x42, 0xb5, 0x69, 0xaf, 0x4d, 0x70, 0x26, 0xd8, 0x59, 0x86, 0xbf, 0x9d, + 0xbb, 0x7f, 0x02, 0x00, 0x00, 0xff, 0xff, 0x66, 0xc8, 0x3c, 0x88, 0x36, 0x06, 0x00, 0x00, } // Reference imports to suppress errors if they are not otherwise used. @@ -311,6 +443,8 @@ type MsgClient interface { UpdateParams(ctx context.Context, in *MsgUpdateParams, opts ...grpc.CallOption) (*MsgUpdateParamsResponse, error) // RegisterKeys defines the RegisterKeys RPC. RegisterKeys(ctx context.Context, in *MsgRegisterKeys, opts ...grpc.CallOption) (*MsgRegisterKeysResponse, error) + // UpdateKeys defines the UpdateKeys RPC. + UpdateKeys(ctx context.Context, in *MsgUpdateKeys, opts ...grpc.CallOption) (*MsgUpdateKeysResponse, error) } type msgClient struct { @@ -339,6 +473,15 @@ func (c *msgClient) RegisterKeys(ctx context.Context, in *MsgRegisterKeys, opts return out, nil } +func (c *msgClient) UpdateKeys(ctx context.Context, in *MsgUpdateKeys, opts ...grpc.CallOption) (*MsgUpdateKeysResponse, error) { + out := new(MsgUpdateKeysResponse) + err := c.cc.Invoke(ctx, "/pulsarchain.keyregistry.v1.Msg/UpdateKeys", in, out, opts...) + if err != nil { + return nil, err + } + return out, nil +} + // MsgServer is the server API for Msg service. type MsgServer interface { // UpdateParams defines a (governance) operation for updating the module @@ -346,6 +489,8 @@ type MsgServer interface { UpdateParams(context.Context, *MsgUpdateParams) (*MsgUpdateParamsResponse, error) // RegisterKeys defines the RegisterKeys RPC. RegisterKeys(context.Context, *MsgRegisterKeys) (*MsgRegisterKeysResponse, error) + // UpdateKeys defines the UpdateKeys RPC. + UpdateKeys(context.Context, *MsgUpdateKeys) (*MsgUpdateKeysResponse, error) } // UnimplementedMsgServer can be embedded to have forward compatible implementations. @@ -358,6 +503,9 @@ func (*UnimplementedMsgServer) UpdateParams(ctx context.Context, req *MsgUpdateP func (*UnimplementedMsgServer) RegisterKeys(ctx context.Context, req *MsgRegisterKeys) (*MsgRegisterKeysResponse, error) { return nil, status.Errorf(codes.Unimplemented, "method RegisterKeys not implemented") } +func (*UnimplementedMsgServer) UpdateKeys(ctx context.Context, req *MsgUpdateKeys) (*MsgUpdateKeysResponse, error) { + return nil, status.Errorf(codes.Unimplemented, "method UpdateKeys not implemented") +} func RegisterMsgServer(s grpc1.Server, srv MsgServer) { s.RegisterService(&_Msg_serviceDesc, srv) @@ -399,6 +547,24 @@ func _Msg_RegisterKeys_Handler(srv interface{}, ctx context.Context, dec func(in return interceptor(ctx, in, info, handler) } +func _Msg_UpdateKeys_Handler(srv interface{}, ctx context.Context, dec func(interface{}) error, interceptor grpc.UnaryServerInterceptor) (interface{}, error) { + in := new(MsgUpdateKeys) + if err := dec(in); err != nil { + return nil, err + } + if interceptor == nil { + return srv.(MsgServer).UpdateKeys(ctx, in) + } + info := &grpc.UnaryServerInfo{ + Server: srv, + FullMethod: "/pulsarchain.keyregistry.v1.Msg/UpdateKeys", + } + handler := func(ctx context.Context, req interface{}) (interface{}, error) { + return srv.(MsgServer).UpdateKeys(ctx, req.(*MsgUpdateKeys)) + } + return interceptor(ctx, in, info, handler) +} + var Msg_serviceDesc = _Msg_serviceDesc var _Msg_serviceDesc = grpc.ServiceDesc{ ServiceName: "pulsarchain.keyregistry.v1.Msg", @@ -412,6 +578,10 @@ var _Msg_serviceDesc = grpc.ServiceDesc{ MethodName: "RegisterKeys", Handler: _Msg_RegisterKeys_Handler, }, + { + MethodName: "UpdateKeys", + Handler: _Msg_UpdateKeys_Handler, + }, }, Streams: []grpc.StreamDesc{}, Metadata: "pulsarchain/keyregistry/v1/tx.proto", @@ -571,6 +741,92 @@ func (m *MsgRegisterKeysResponse) MarshalToSizedBuffer(dAtA []byte) (int, error) return len(dAtA) - i, nil } +func (m *MsgUpdateKeys) 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 *MsgUpdateKeys) MarshalTo(dAtA []byte) (int, error) { + size := m.Size() + return m.MarshalToSizedBuffer(dAtA[:size]) +} + +func (m *MsgUpdateKeys) MarshalToSizedBuffer(dAtA []byte) (int, error) { + i := len(dAtA) + _ = i + var l int + _ = l + if m.UpdateType != 0 { + i = encodeVarintTx(dAtA, i, uint64(m.UpdateType)) + i-- + dAtA[i] = 0x30 + } + if len(m.NewMinaSignature) > 0 { + i -= len(m.NewMinaSignature) + copy(dAtA[i:], m.NewMinaSignature) + i = encodeVarintTx(dAtA, i, uint64(len(m.NewMinaSignature))) + i-- + dAtA[i] = 0x2a + } + if len(m.CosmosSignature) > 0 { + i -= len(m.CosmosSignature) + copy(dAtA[i:], m.CosmosSignature) + i = encodeVarintTx(dAtA, i, uint64(len(m.CosmosSignature))) + i-- + dAtA[i] = 0x22 + } + if len(m.NewMinaPublicKey) > 0 { + i -= len(m.NewMinaPublicKey) + copy(dAtA[i:], m.NewMinaPublicKey) + i = encodeVarintTx(dAtA, i, uint64(len(m.NewMinaPublicKey))) + i-- + dAtA[i] = 0x1a + } + if len(m.PrevMinaPublicKey) > 0 { + i -= len(m.PrevMinaPublicKey) + copy(dAtA[i:], m.PrevMinaPublicKey) + i = encodeVarintTx(dAtA, i, uint64(len(m.PrevMinaPublicKey))) + i-- + dAtA[i] = 0x12 + } + if len(m.Creator) > 0 { + i -= len(m.Creator) + copy(dAtA[i:], m.Creator) + i = encodeVarintTx(dAtA, i, uint64(len(m.Creator))) + i-- + dAtA[i] = 0xa + } + return len(dAtA) - i, nil +} + +func (m *MsgUpdateKeysResponse) 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 *MsgUpdateKeysResponse) MarshalTo(dAtA []byte) (int, error) { + size := m.Size() + return m.MarshalToSizedBuffer(dAtA[:size]) +} + +func (m *MsgUpdateKeysResponse) 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 @@ -647,6 +903,47 @@ func (m *MsgRegisterKeysResponse) Size() (n int) { return n } +func (m *MsgUpdateKeys) Size() (n int) { + if m == nil { + return 0 + } + var l int + _ = l + l = len(m.Creator) + if l > 0 { + n += 1 + l + sovTx(uint64(l)) + } + l = len(m.PrevMinaPublicKey) + if l > 0 { + n += 1 + l + sovTx(uint64(l)) + } + l = len(m.NewMinaPublicKey) + if l > 0 { + n += 1 + l + sovTx(uint64(l)) + } + l = len(m.CosmosSignature) + if l > 0 { + n += 1 + l + sovTx(uint64(l)) + } + l = len(m.NewMinaSignature) + if l > 0 { + n += 1 + l + sovTx(uint64(l)) + } + if m.UpdateType != 0 { + n += 1 + sovTx(uint64(m.UpdateType)) + } + return n +} + +func (m *MsgUpdateKeysResponse) 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 } @@ -1102,6 +1399,293 @@ func (m *MsgRegisterKeysResponse) Unmarshal(dAtA []byte) error { } return nil } +func (m *MsgUpdateKeys) 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: MsgUpdateKeys: wiretype end group for non-group") + } + if fieldNum <= 0 { + return fmt.Errorf("proto: MsgUpdateKeys: illegal tag %d (wire type %d)", fieldNum, wire) + } + switch fieldNum { + case 1: + if wireType != 2 { + return fmt.Errorf("proto: wrong wireType = %d for field Creator", 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.Creator = string(dAtA[iNdEx:postIndex]) + iNdEx = postIndex + case 2: + if wireType != 2 { + return fmt.Errorf("proto: wrong wireType = %d for field PrevMinaPublicKey", wireType) + } + var byteLen int + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowTx + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + byteLen |= int(b&0x7F) << shift + if b < 0x80 { + break + } + } + if byteLen < 0 { + return ErrInvalidLengthTx + } + postIndex := iNdEx + byteLen + if postIndex < 0 { + return ErrInvalidLengthTx + } + if postIndex > l { + return io.ErrUnexpectedEOF + } + m.PrevMinaPublicKey = append(m.PrevMinaPublicKey[:0], dAtA[iNdEx:postIndex]...) + if m.PrevMinaPublicKey == nil { + m.PrevMinaPublicKey = []byte{} + } + iNdEx = postIndex + case 3: + if wireType != 2 { + return fmt.Errorf("proto: wrong wireType = %d for field NewMinaPublicKey", wireType) + } + var byteLen int + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowTx + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + byteLen |= int(b&0x7F) << shift + if b < 0x80 { + break + } + } + if byteLen < 0 { + return ErrInvalidLengthTx + } + postIndex := iNdEx + byteLen + if postIndex < 0 { + return ErrInvalidLengthTx + } + if postIndex > l { + return io.ErrUnexpectedEOF + } + m.NewMinaPublicKey = append(m.NewMinaPublicKey[:0], dAtA[iNdEx:postIndex]...) + if m.NewMinaPublicKey == nil { + m.NewMinaPublicKey = []byte{} + } + iNdEx = postIndex + case 4: + if wireType != 2 { + return fmt.Errorf("proto: wrong wireType = %d for field CosmosSignature", wireType) + } + var byteLen int + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowTx + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + byteLen |= int(b&0x7F) << shift + if b < 0x80 { + break + } + } + if byteLen < 0 { + return ErrInvalidLengthTx + } + postIndex := iNdEx + byteLen + if postIndex < 0 { + return ErrInvalidLengthTx + } + if postIndex > l { + return io.ErrUnexpectedEOF + } + m.CosmosSignature = append(m.CosmosSignature[:0], dAtA[iNdEx:postIndex]...) + if m.CosmosSignature == nil { + m.CosmosSignature = []byte{} + } + iNdEx = postIndex + case 5: + if wireType != 2 { + return fmt.Errorf("proto: wrong wireType = %d for field NewMinaSignature", wireType) + } + var byteLen int + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowTx + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + byteLen |= int(b&0x7F) << shift + if b < 0x80 { + break + } + } + if byteLen < 0 { + return ErrInvalidLengthTx + } + postIndex := iNdEx + byteLen + if postIndex < 0 { + return ErrInvalidLengthTx + } + if postIndex > l { + return io.ErrUnexpectedEOF + } + m.NewMinaSignature = append(m.NewMinaSignature[:0], dAtA[iNdEx:postIndex]...) + if m.NewMinaSignature == nil { + m.NewMinaSignature = []byte{} + } + iNdEx = postIndex + case 6: + if wireType != 0 { + return fmt.Errorf("proto: wrong wireType = %d for field UpdateType", wireType) + } + m.UpdateType = 0 + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowTx + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + m.UpdateType |= KeyUpdateType(b&0x7F) << shift + if b < 0x80 { + break + } + } + 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 *MsgUpdateKeysResponse) 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: MsgUpdateKeysResponse: wiretype end group for non-group") + } + if fieldNum <= 0 { + return fmt.Errorf("proto: MsgUpdateKeysResponse: 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 4a2ebcd742be56954ac1b3e1643e14f08cf51e93 Mon Sep 17 00:00:00 2001 From: Yusuf Date: Wed, 15 Apr 2026 16:29:29 +0300 Subject: [PATCH 04/62] refactor: rename keyupdatetype to actor type and use enumeration on register keys --- .../keyregistry/v1/key_update_type.proto | 2 +- proto/pulsarchain/keyregistry/v1/tx.proto | 4 +- x/keyregistry/keeper/genesis.go | 2 +- .../keeper/msg_server_register_keys.go | 7 +- .../keeper/msg_server_update_keys.go | 12 +- .../keeper/user_register_keys_test.go | 14 +- .../keeper/validator_register_keys_test.go | 14 +- x/keyregistry/types/key_update_type.pb.go | 36 ++-- x/keyregistry/types/tx.pb.go | 154 +++++++++--------- 9 files changed, 124 insertions(+), 121 deletions(-) diff --git a/proto/pulsarchain/keyregistry/v1/key_update_type.proto b/proto/pulsarchain/keyregistry/v1/key_update_type.proto index 1ed9ae04..dd67defe 100644 --- a/proto/pulsarchain/keyregistry/v1/key_update_type.proto +++ b/proto/pulsarchain/keyregistry/v1/key_update_type.proto @@ -3,7 +3,7 @@ package pulsarchain.keyregistry.v1; option go_package = "github.com/node101-io/pulsar-chain/x/keyregistry/types"; -enum KeyUpdateType { +enum ActorType { USER = 0; VALIDATOR = 1; } diff --git a/proto/pulsarchain/keyregistry/v1/tx.proto b/proto/pulsarchain/keyregistry/v1/tx.proto index 465ab0fe..bddf70c2 100644 --- a/proto/pulsarchain/keyregistry/v1/tx.proto +++ b/proto/pulsarchain/keyregistry/v1/tx.proto @@ -55,7 +55,7 @@ message MsgRegisterKeys { string mina_signature = 3; bytes cosmos_address = 4; bytes mina_address = 5; - bool is_user = 6; + ActorType actor_type = 6; } // MsgRegisterKeysResponse defines the MsgRegisterKeysResponse message. @@ -69,7 +69,7 @@ message MsgUpdateKeys { bytes new_mina_public_key = 3; bytes cosmos_signature = 4; bytes new_mina_signature = 5; - KeyUpdateType update_type = 6; + ActorType actor_type = 6; } // MsgUpdateKeysResponse defines the MsgUpdateKeysResponse message. diff --git a/x/keyregistry/keeper/genesis.go b/x/keyregistry/keeper/genesis.go index d8163ed5..a3646643 100644 --- a/x/keyregistry/keeper/genesis.go +++ b/x/keyregistry/keeper/genesis.go @@ -81,7 +81,7 @@ func (k Keeper) ExportGenesis(ctx context.Context) (*types.GenesisState, error) userCosmosIterator.Next() } - // Iterate over inaToCosmos map and collect any key pairs that are not + // Iterate over MinaToCosmos map and collect any key pairs that are not // already present in the CosmosToMina map. Although both maps are expected // to be in sync, this ensures no key pairs are lost in case of any inconsistency // between the two maps during export. diff --git a/x/keyregistry/keeper/msg_server_register_keys.go b/x/keyregistry/keeper/msg_server_register_keys.go index cfbd328d..a34e6325 100644 --- a/x/keyregistry/keeper/msg_server_register_keys.go +++ b/x/keyregistry/keeper/msg_server_register_keys.go @@ -15,7 +15,7 @@ func VerifyUserMinaSig(sig string, msg, minaAddress []byte) bool { } // TODO: Implement Cosmos signature verification for users -func VerifyUserCosmosSig(sig string, msg, mosmosAddress []byte) bool { +func VerifyUserCosmosSig(sig string, msg, cosmosAddress []byte) bool { return true } @@ -62,9 +62,10 @@ func (k msgServer) RegisterKeys(ctx context.Context, msg *types.MsgRegisterKeys) var err error - if msg.IsUser { + switch msg.ActorType { + case types.ActorType_USER: err = k.handleUserRegistration(ctx, msg) - } else { + case types.ActorType_VALIDATOR: err = k.handleValidatorRegistration(ctx, msg) } if err != nil { diff --git a/x/keyregistry/keeper/msg_server_update_keys.go b/x/keyregistry/keeper/msg_server_update_keys.go index 8f75800a..3b3d65ed 100644 --- a/x/keyregistry/keeper/msg_server_update_keys.go +++ b/x/keyregistry/keeper/msg_server_update_keys.go @@ -12,7 +12,7 @@ func (k msgServer) UpdateKeys(ctx context.Context, msg *types.MsgUpdateKeys) (*t return nil, errorsmod.Wrap(err, "invalid authority address") } - if msg.UpdateType == types.KeyUpdateType_USER { + if msg.ActorType == types.ActorType_USER { exists, err := k.UserCosmosToMinaHas(ctx, []byte(msg.Creator)) if err != nil { @@ -29,6 +29,10 @@ func (k msgServer) UpdateKeys(ctx context.Context, msg *types.MsgUpdateKeys) (*t return nil, types.ErrUserNotRegistered } + if !VerifyUserCosmosSig(string(msg.CosmosSignature), msg.NewMinaPublicKey, []byte(msg.Creator)) { + return nil, types.ErrInvalidSignature + } + if !VerifyUserMinaSig(string(msg.NewMinaSignature), []byte(msg.Creator), msg.NewMinaPublicKey) { return nil, types.ErrInvalidSignature } @@ -52,7 +56,7 @@ func (k msgServer) UpdateKeys(ctx context.Context, msg *types.MsgUpdateKeys) (*t } } - if msg.UpdateType == types.KeyUpdateType_VALIDATOR { + if msg.ActorType == types.ActorType_VALIDATOR { exists, err := k.ValidatorCosmosToMinaHas(ctx, []byte(msg.Creator)) if err != nil { @@ -70,6 +74,10 @@ func (k msgServer) UpdateKeys(ctx context.Context, msg *types.MsgUpdateKeys) (*t return nil, types.ErrValidatorNotRegistered } + if !VerifyUserCosmosSig(string(msg.CosmosSignature), msg.NewMinaPublicKey, []byte(msg.Creator)) { + return nil, types.ErrInvalidSignature + } + if !VerifyValidatorMinaSig(string(msg.NewMinaSignature), []byte(msg.Creator), msg.NewMinaPublicKey) { return nil, types.ErrInvalidSignature } diff --git a/x/keyregistry/keeper/user_register_keys_test.go b/x/keyregistry/keeper/user_register_keys_test.go index 6520b4ab..298956ac 100644 --- a/x/keyregistry/keeper/user_register_keys_test.go +++ b/x/keyregistry/keeper/user_register_keys_test.go @@ -46,7 +46,7 @@ func TestUserRegisterKeysFail(t *testing.T) { MinaSignature: mockMinaSignature, CosmosAddress: CosmosPubKey, MinaAddress: MinaPubKey, - IsUser: true, + ActorType: types.ActorType_USER, }) require.ErrorIs(t, err, types.ErrInvalidAddress) } @@ -67,7 +67,7 @@ func TestUserRegisterKeysSuccess(t *testing.T) { MinaSignature: mockMinaSignature, CosmosAddress: cosmosAddr.Bytes(), MinaAddress: minaAddr, - IsUser: true, + ActorType: types.ActorType_USER, }) require.NoError(t, err) require.NotNil(t, resp) @@ -98,7 +98,7 @@ func TestUserInvalidCreatorAddress(t *testing.T) { MinaSignature: mockMinaSignature, CosmosAddress: cosmosAddr.Bytes(), MinaAddress: minaAddr, - IsUser: true, + ActorType: types.ActorType_USER, }) require.ErrorIs(t, err, types.ErrInvalidCreatorAddres) } @@ -125,7 +125,7 @@ func TestUserInvalidSigner(t *testing.T) { MinaSignature: mockMinaSignature, CosmosAddress: cosmosAddr.Bytes(), MinaAddress: minaAddr, - IsUser: true, + ActorType: types.ActorType_USER, }) require.ErrorIs(t, err, types.ErrInvalidSigner) @@ -151,7 +151,7 @@ func TestUserInvalidSignature(t *testing.T) { MinaSignature: mockMinaSignature, CosmosAddress: cosmosAddr.Bytes(), MinaAddress: minaAddr, - IsUser: true, + ActorType: types.ActorType_USER, }) require.NoError(t, err) @@ -175,7 +175,7 @@ func TestUserInsertSecondaryKeysFail(t *testing.T) { MinaSignature: mockMinaSignature, CosmosAddress: cosmosAddr.Bytes(), MinaAddress: minaAddr, - IsUser: true, + ActorType: types.ActorType_USER, }) require.NoError(t, err) require.NotNil(t, resp) @@ -187,7 +187,7 @@ func TestUserInsertSecondaryKeysFail(t *testing.T) { MinaSignature: mockMinaSignature, CosmosAddress: cosmosAddr.Bytes(), MinaAddress: minaAddr, - IsUser: true, + ActorType: types.ActorType_USER, }) require.ErrorIs(t, err, types.ErrUserSecondaryKeyExists) diff --git a/x/keyregistry/keeper/validator_register_keys_test.go b/x/keyregistry/keeper/validator_register_keys_test.go index 7139e68e..f475a0c8 100644 --- a/x/keyregistry/keeper/validator_register_keys_test.go +++ b/x/keyregistry/keeper/validator_register_keys_test.go @@ -38,7 +38,7 @@ func TestValidatorRegisterKeysFail(t *testing.T) { MinaSignature: mockMinaSignature, CosmosAddress: CosmosPubKey, MinaAddress: MinaPubKey, - IsUser: false, + ActorType: types.ActorType_VALIDATOR, }) require.ErrorIs(t, err, types.ErrInvalidPublicKey) } @@ -61,7 +61,7 @@ func TestValidatorRegisterKeysSuccess(t *testing.T) { MinaSignature: mockMinaSignature, CosmosAddress: cosmosPubKey.Bytes(), MinaAddress: minaPubKey, - IsUser: false, + ActorType: types.ActorType_VALIDATOR, }) require.NoError(t, err) require.NotNil(t, resp) @@ -91,7 +91,7 @@ func TestValidatorInvalidCreatorAddress(t *testing.T) { MinaSignature: mockMinaSignature, CosmosAddress: cosmosPubKey.Bytes(), MinaAddress: minaPubKey, - IsUser: false, + ActorType: types.ActorType_VALIDATOR, }) require.ErrorIs(t, err, types.ErrInvalidCreatorAddres) } @@ -118,7 +118,7 @@ func TestValidatorInvalidSigner(t *testing.T) { MinaSignature: mockMinaSignature, CosmosAddress: cosmosPubKey.Bytes(), MinaAddress: minaPubKey, - IsUser: false, + ActorType: types.ActorType_VALIDATOR, }) require.ErrorIs(t, err, types.ErrInvalidSigner) @@ -144,7 +144,7 @@ func TestValidatorInvalidSignature(t *testing.T) { MinaSignature: mockMinaSignature, CosmosAddress: cosmosPubKey.Bytes(), MinaAddress: minaPubKey, - IsUser: false, + ActorType: types.ActorType_VALIDATOR, }) require.NoError(t, err) @@ -170,7 +170,7 @@ func TestValidatorInsertSecondaryKeysFail(t *testing.T) { MinaSignature: mockMinaSignature, CosmosAddress: cosmosPubKey.Bytes(), MinaAddress: minaPubKey, - IsUser: false, + ActorType: types.ActorType_VALIDATOR, }) require.NoError(t, err) require.NotNil(t, resp) @@ -182,7 +182,7 @@ func TestValidatorInsertSecondaryKeysFail(t *testing.T) { MinaSignature: mockMinaSignature, CosmosAddress: cosmosPubKey.Bytes(), MinaAddress: minaPubKey, - IsUser: false, + ActorType: types.ActorType_VALIDATOR, }) require.ErrorIs(t, err, types.ErrValidatorSecondaryKeyExists) diff --git a/x/keyregistry/types/key_update_type.pb.go b/x/keyregistry/types/key_update_type.pb.go index 582b511e..861effce 100644 --- a/x/keyregistry/types/key_update_type.pb.go +++ b/x/keyregistry/types/key_update_type.pb.go @@ -20,33 +20,33 @@ var _ = math.Inf // proto package needs to be updated. const _ = proto.GoGoProtoPackageIsVersion3 // please upgrade the proto package -type KeyUpdateType int32 +type ActorType int32 const ( - KeyUpdateType_USER KeyUpdateType = 0 - KeyUpdateType_VALIDATOR KeyUpdateType = 1 + ActorType_USER ActorType = 0 + ActorType_VALIDATOR ActorType = 1 ) -var KeyUpdateType_name = map[int32]string{ +var ActorType_name = map[int32]string{ 0: "USER", 1: "VALIDATOR", } -var KeyUpdateType_value = map[string]int32{ +var ActorType_value = map[string]int32{ "USER": 0, "VALIDATOR": 1, } -func (x KeyUpdateType) String() string { - return proto.EnumName(KeyUpdateType_name, int32(x)) +func (x ActorType) String() string { + return proto.EnumName(ActorType_name, int32(x)) } -func (KeyUpdateType) EnumDescriptor() ([]byte, []int) { +func (ActorType) EnumDescriptor() ([]byte, []int) { return fileDescriptor_ba25ac2a902d16f7, []int{0} } func init() { - proto.RegisterEnum("pulsarchain.keyregistry.v1.KeyUpdateType", KeyUpdateType_name, KeyUpdateType_value) + proto.RegisterEnum("pulsarchain.keyregistry.v1.ActorType", ActorType_name, ActorType_value) } func init() { @@ -54,17 +54,17 @@ func init() { } var fileDescriptor_ba25ac2a902d16f7 = []byte{ - // 190 bytes of a gzipped FileDescriptorProto + // 189 bytes of a gzipped FileDescriptorProto 0x1f, 0x8b, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0xff, 0xe2, 0x32, 0x28, 0x28, 0xcd, 0x29, 0x4e, 0x2c, 0x4a, 0xce, 0x48, 0xcc, 0xcc, 0xd3, 0xcf, 0x4e, 0xad, 0x2c, 0x4a, 0x4d, 0xcf, 0x2c, 0x2e, 0x29, 0xaa, 0xd4, 0x2f, 0x33, 0x04, 0x71, 0xe3, 0x4b, 0x0b, 0x52, 0x12, 0x4b, 0x52, 0xe3, 0x4b, 0x2a, 0x0b, 0x52, 0xf5, 0x0a, 0x8a, 0xf2, 0x4b, 0xf2, 0x85, 0xa4, 0x90, 0x74, 0xe8, 0x21, - 0xe9, 0xd0, 0x2b, 0x33, 0xd4, 0xd2, 0xe0, 0xe2, 0xf5, 0x4e, 0xad, 0x0c, 0x05, 0xeb, 0x09, 0xa9, - 0x2c, 0x48, 0x15, 0xe2, 0xe0, 0x62, 0x09, 0x0d, 0x76, 0x0d, 0x12, 0x60, 0x10, 0xe2, 0xe5, 0xe2, - 0x0c, 0x73, 0xf4, 0xf1, 0x74, 0x71, 0x0c, 0xf1, 0x0f, 0x12, 0x60, 0x74, 0x0a, 0x38, 0xf1, 0x48, - 0x8e, 0xf1, 0xc2, 0x23, 0x39, 0xc6, 0x07, 0x8f, 0xe4, 0x18, 0x27, 0x3c, 0x96, 0x63, 0xb8, 0xf0, - 0x58, 0x8e, 0xe1, 0xc6, 0x63, 0x39, 0x86, 0x28, 0xb3, 0xf4, 0xcc, 0x92, 0x8c, 0xd2, 0x24, 0xbd, - 0xe4, 0xfc, 0x5c, 0xfd, 0xbc, 0xfc, 0x94, 0x54, 0x43, 0x03, 0x43, 0xdd, 0xcc, 0x7c, 0x7d, 0x88, - 0xad, 0xba, 0x10, 0x87, 0x56, 0xa0, 0x38, 0x15, 0xe4, 0xb8, 0xe2, 0x24, 0x36, 0xb0, 0xf3, 0x8c, - 0x01, 0x01, 0x00, 0x00, 0xff, 0xff, 0xdb, 0x9b, 0x81, 0x4a, 0xd2, 0x00, 0x00, 0x00, + 0xe9, 0xd0, 0x2b, 0x33, 0xd4, 0x52, 0xe1, 0xe2, 0x74, 0x4c, 0x2e, 0xc9, 0x2f, 0x0a, 0xa9, 0x2c, + 0x48, 0x15, 0xe2, 0xe0, 0x62, 0x09, 0x0d, 0x76, 0x0d, 0x12, 0x60, 0x10, 0xe2, 0xe5, 0xe2, 0x0c, + 0x73, 0xf4, 0xf1, 0x74, 0x71, 0x0c, 0xf1, 0x0f, 0x12, 0x60, 0x74, 0x0a, 0x38, 0xf1, 0x48, 0x8e, + 0xf1, 0xc2, 0x23, 0x39, 0xc6, 0x07, 0x8f, 0xe4, 0x18, 0x27, 0x3c, 0x96, 0x63, 0xb8, 0xf0, 0x58, + 0x8e, 0xe1, 0xc6, 0x63, 0x39, 0x86, 0x28, 0xb3, 0xf4, 0xcc, 0x92, 0x8c, 0xd2, 0x24, 0xbd, 0xe4, + 0xfc, 0x5c, 0xfd, 0xbc, 0xfc, 0x94, 0x54, 0x43, 0x03, 0x43, 0xdd, 0xcc, 0x7c, 0x7d, 0x88, 0x8d, + 0xba, 0x10, 0x47, 0x56, 0xa0, 0x38, 0x13, 0xe4, 0xb0, 0xe2, 0x24, 0x36, 0xb0, 0xd3, 0x8c, 0x01, + 0x01, 0x00, 0x00, 0xff, 0xff, 0x7f, 0x85, 0x42, 0x77, 0xce, 0x00, 0x00, 0x00, } diff --git a/x/keyregistry/types/tx.pb.go b/x/keyregistry/types/tx.pb.go index ceb0b928..b3b2705b 100644 --- a/x/keyregistry/types/tx.pb.go +++ b/x/keyregistry/types/tx.pb.go @@ -126,12 +126,12 @@ var xxx_messageInfo_MsgUpdateParamsResponse proto.InternalMessageInfo // MsgRegisterKeys defines the MsgRegisterKeys message. type MsgRegisterKeys struct { - Creator string `protobuf:"bytes,1,opt,name=creator,proto3" json:"creator,omitempty"` - CosmosSignature string `protobuf:"bytes,2,opt,name=cosmos_signature,json=cosmosSignature,proto3" json:"cosmos_signature,omitempty"` - MinaSignature string `protobuf:"bytes,3,opt,name=mina_signature,json=minaSignature,proto3" json:"mina_signature,omitempty"` - CosmosAddress []byte `protobuf:"bytes,4,opt,name=cosmos_address,json=cosmosAddress,proto3" json:"cosmos_address,omitempty"` - MinaAddress []byte `protobuf:"bytes,5,opt,name=mina_address,json=minaAddress,proto3" json:"mina_address,omitempty"` - IsUser bool `protobuf:"varint,6,opt,name=is_user,json=isUser,proto3" json:"is_user,omitempty"` + Creator string `protobuf:"bytes,1,opt,name=creator,proto3" json:"creator,omitempty"` + CosmosSignature string `protobuf:"bytes,2,opt,name=cosmos_signature,json=cosmosSignature,proto3" json:"cosmos_signature,omitempty"` + MinaSignature string `protobuf:"bytes,3,opt,name=mina_signature,json=minaSignature,proto3" json:"mina_signature,omitempty"` + CosmosAddress []byte `protobuf:"bytes,4,opt,name=cosmos_address,json=cosmosAddress,proto3" json:"cosmos_address,omitempty"` + MinaAddress []byte `protobuf:"bytes,5,opt,name=mina_address,json=minaAddress,proto3" json:"mina_address,omitempty"` + ActorType ActorType `protobuf:"varint,6,opt,name=actor_type,json=actorType,proto3,enum=pulsarchain.keyregistry.v1.ActorType" json:"actor_type,omitempty"` } func (m *MsgRegisterKeys) Reset() { *m = MsgRegisterKeys{} } @@ -202,11 +202,11 @@ func (m *MsgRegisterKeys) GetMinaAddress() []byte { return nil } -func (m *MsgRegisterKeys) GetIsUser() bool { +func (m *MsgRegisterKeys) GetActorType() ActorType { if m != nil { - return m.IsUser + return m.ActorType } - return false + return ActorType_USER } // MsgRegisterKeysResponse defines the MsgRegisterKeysResponse message. @@ -248,12 +248,12 @@ var xxx_messageInfo_MsgRegisterKeysResponse proto.InternalMessageInfo // MsgUpdateKeys defines the MsgUpdateKeys message. type MsgUpdateKeys struct { - Creator string `protobuf:"bytes,1,opt,name=creator,proto3" json:"creator,omitempty"` - PrevMinaPublicKey []byte `protobuf:"bytes,2,opt,name=prev_mina_public_key,json=prevMinaPublicKey,proto3" json:"prev_mina_public_key,omitempty"` - NewMinaPublicKey []byte `protobuf:"bytes,3,opt,name=new_mina_public_key,json=newMinaPublicKey,proto3" json:"new_mina_public_key,omitempty"` - CosmosSignature []byte `protobuf:"bytes,4,opt,name=cosmos_signature,json=cosmosSignature,proto3" json:"cosmos_signature,omitempty"` - NewMinaSignature []byte `protobuf:"bytes,5,opt,name=new_mina_signature,json=newMinaSignature,proto3" json:"new_mina_signature,omitempty"` - UpdateType KeyUpdateType `protobuf:"varint,6,opt,name=update_type,json=updateType,proto3,enum=pulsarchain.keyregistry.v1.KeyUpdateType" json:"update_type,omitempty"` + Creator string `protobuf:"bytes,1,opt,name=creator,proto3" json:"creator,omitempty"` + PrevMinaPublicKey []byte `protobuf:"bytes,2,opt,name=prev_mina_public_key,json=prevMinaPublicKey,proto3" json:"prev_mina_public_key,omitempty"` + NewMinaPublicKey []byte `protobuf:"bytes,3,opt,name=new_mina_public_key,json=newMinaPublicKey,proto3" json:"new_mina_public_key,omitempty"` + CosmosSignature []byte `protobuf:"bytes,4,opt,name=cosmos_signature,json=cosmosSignature,proto3" json:"cosmos_signature,omitempty"` + NewMinaSignature []byte `protobuf:"bytes,5,opt,name=new_mina_signature,json=newMinaSignature,proto3" json:"new_mina_signature,omitempty"` + ActorType ActorType `protobuf:"varint,6,opt,name=actor_type,json=actorType,proto3,enum=pulsarchain.keyregistry.v1.ActorType" json:"actor_type,omitempty"` } func (m *MsgUpdateKeys) Reset() { *m = MsgUpdateKeys{} } @@ -324,11 +324,11 @@ func (m *MsgUpdateKeys) GetNewMinaSignature() []byte { return nil } -func (m *MsgUpdateKeys) GetUpdateType() KeyUpdateType { +func (m *MsgUpdateKeys) GetActorType() ActorType { if m != nil { - return m.UpdateType + return m.ActorType } - return KeyUpdateType_USER + return ActorType_USER } // MsgUpdateKeysResponse defines the MsgUpdateKeysResponse message. @@ -382,48 +382,48 @@ func init() { } var fileDescriptor_235f5fb22cc1f8d8 = []byte{ - // 655 bytes of a gzipped FileDescriptorProto - 0x1f, 0x8b, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0xff, 0x9c, 0x94, 0xbf, 0x6f, 0xd3, 0x40, - 0x14, 0xc7, 0xe3, 0x94, 0xa6, 0xe4, 0x9a, 0xfe, 0x32, 0x45, 0x49, 0x33, 0x98, 0x10, 0x84, 0x48, - 0x0a, 0xb1, 0x9b, 0x54, 0xea, 0x50, 0xb1, 0x50, 0x89, 0x85, 0xaa, 0x52, 0xe5, 0xd2, 0x85, 0xc5, - 0xba, 0x26, 0x27, 0xe7, 0x48, 0xed, 0xb3, 0xee, 0xec, 0xb4, 0xde, 0x10, 0x13, 0x62, 0xe2, 0xcf, - 0x60, 0xcc, 0xc0, 0x1f, 0xd1, 0x09, 0x55, 0x0c, 0x88, 0x01, 0x21, 0x94, 0x0c, 0xf9, 0x37, 0x90, - 0xef, 0xec, 0xc4, 0x4e, 0x43, 0x52, 0x58, 0xa2, 0xf8, 0xbd, 0xcf, 0xbd, 0xef, 0x7b, 0xdf, 0xfb, - 0x01, 0x1e, 0x39, 0xde, 0x39, 0x83, 0xb4, 0xd9, 0x86, 0xd8, 0xd6, 0x3a, 0xc8, 0xa7, 0xc8, 0xc4, - 0xcc, 0xa5, 0xbe, 0xd6, 0xad, 0x6b, 0xee, 0xa5, 0xea, 0x50, 0xe2, 0x12, 0xb9, 0x18, 0x83, 0xd4, - 0x18, 0xa4, 0x76, 0xeb, 0xc5, 0x0d, 0x68, 0x61, 0x9b, 0x68, 0xfc, 0x57, 0xe0, 0xc5, 0x7c, 0x93, - 0x30, 0x8b, 0x30, 0xcd, 0x62, 0x66, 0x50, 0xc6, 0x62, 0x66, 0x98, 0xd8, 0x12, 0x09, 0x83, 0x7f, - 0x69, 0xe2, 0x23, 0x4c, 0x6d, 0x9a, 0xc4, 0x24, 0x22, 0x1e, 0xfc, 0x0b, 0xa3, 0x4f, 0x66, 0x74, - 0xe7, 0x40, 0x0a, 0xad, 0x68, 0xf9, 0xce, 0x0c, 0xb0, 0x83, 0x7c, 0xc3, 0x73, 0x5a, 0xd0, 0x45, - 0x86, 0xeb, 0x3b, 0x48, 0xac, 0x28, 0x7f, 0x95, 0xc0, 0xda, 0x11, 0x33, 0x4f, 0x79, 0xe2, 0x98, - 0xd7, 0x92, 0xf7, 0x40, 0x16, 0x7a, 0x6e, 0x9b, 0x50, 0xec, 0xfa, 0x05, 0xa9, 0x24, 0x55, 0xb2, - 0x07, 0x85, 0x6f, 0x5f, 0x6a, 0x9b, 0x61, 0xa7, 0x2f, 0x5a, 0x2d, 0x8a, 0x18, 0x3b, 0x71, 0x29, - 0xb6, 0x4d, 0x7d, 0x8c, 0xca, 0x2f, 0x41, 0x46, 0x74, 0x53, 0x48, 0x97, 0xa4, 0xca, 0x72, 0xa3, - 0xac, 0xfe, 0xdd, 0x30, 0x55, 0x68, 0x1d, 0x64, 0xaf, 0x7e, 0x3d, 0x48, 0x7d, 0x1e, 0xf6, 0xb6, - 0x25, 0x3d, 0x5c, 0xbc, 0xff, 0xfc, 0xfd, 0xb0, 0xb7, 0x3d, 0x2e, 0xfb, 0x71, 0xd8, 0xdb, 0xae, - 0xc6, 0xe7, 0xba, 0x4c, 0x4c, 0x36, 0xd1, 0x7c, 0x79, 0x0b, 0xe4, 0x27, 0x42, 0x3a, 0x62, 0x0e, - 0xb1, 0x19, 0x2a, 0x7f, 0x48, 0xf3, 0x59, 0x75, 0xbe, 0x14, 0xd1, 0x43, 0xe4, 0x33, 0xb9, 0x01, - 0x96, 0x9a, 0x14, 0x41, 0x97, 0xd0, 0xb9, 0x93, 0x46, 0xa0, 0x5c, 0x05, 0xeb, 0xe1, 0x0e, 0x32, - 0x6c, 0xda, 0xd0, 0xf5, 0x28, 0xe2, 0x13, 0x67, 0xf5, 0x35, 0x11, 0x3f, 0x89, 0xc2, 0xf2, 0x63, - 0xb0, 0x6a, 0x61, 0x1b, 0xc6, 0xc0, 0x05, 0x0e, 0xae, 0x04, 0xd1, 0x04, 0x16, 0x56, 0x84, 0x42, - 0xb2, 0x70, 0xa7, 0x24, 0x55, 0x72, 0xfa, 0x8a, 0x88, 0x86, 0x7d, 0xc8, 0x0f, 0x41, 0x8e, 0x57, - 0x8b, 0xa0, 0x45, 0x0e, 0x2d, 0x07, 0xb1, 0x08, 0xc9, 0x83, 0x25, 0xcc, 0x0c, 0x8f, 0x21, 0x5a, - 0xc8, 0x94, 0xa4, 0xca, 0x5d, 0x3d, 0x83, 0xd9, 0x29, 0x43, 0x74, 0x3f, 0x17, 0xb8, 0x1a, 0x8d, - 0x10, 0xba, 0x14, 0x77, 0x62, 0xe4, 0xd2, 0xf7, 0x34, 0x58, 0x19, 0x39, 0xf8, 0xdf, 0x1e, 0x69, - 0x60, 0xd3, 0xa1, 0xa8, 0x6b, 0xf0, 0x7e, 0x1d, 0xef, 0xec, 0x1c, 0x37, 0x8d, 0x0e, 0xf2, 0xb9, - 0x4f, 0x39, 0x7d, 0x23, 0xc8, 0x1d, 0x61, 0x1b, 0x1e, 0xf3, 0xcc, 0x21, 0xf2, 0xe5, 0x1a, 0xb8, - 0x67, 0xa3, 0x8b, 0x1b, 0xfc, 0x02, 0xe7, 0xd7, 0x6d, 0x74, 0x91, 0xc4, 0xa7, 0xed, 0x81, 0xf0, - 0xec, 0xc6, 0x1e, 0x3c, 0x03, 0xf2, 0xa8, 0xf2, 0x18, 0x5e, 0x4c, 0x14, 0x1e, 0xd3, 0xaf, 0xc0, - 0x72, 0xec, 0x96, 0x70, 0x13, 0x57, 0x1b, 0xd5, 0x59, 0x27, 0xf9, 0x10, 0xf9, 0xc2, 0xac, 0xd7, - 0xbe, 0x83, 0x74, 0xe0, 0x8d, 0xfe, 0x4f, 0x78, 0x9e, 0x07, 0xf7, 0x13, 0xbe, 0x46, 0x8e, 0x37, - 0x7e, 0xa6, 0xc1, 0xc2, 0x11, 0x33, 0x65, 0x07, 0xe4, 0x12, 0xf7, 0xf0, 0xe9, 0x2c, 0xd5, 0x89, - 0x43, 0x5e, 0xdc, 0xfd, 0x07, 0x38, 0x52, 0x0e, 0x14, 0x13, 0xb7, 0x61, 0x9e, 0x62, 0x1c, 0x9e, - 0xab, 0x38, 0xed, 0x74, 0xc9, 0x6f, 0x01, 0x88, 0x9d, 0xac, 0xea, 0xad, 0x9a, 0xe6, 0x6a, 0xf5, - 0x5b, 0xa3, 0x91, 0x56, 0x71, 0xf1, 0x5d, 0xf0, 0xae, 0x1c, 0x1c, 0x5f, 0xf5, 0x15, 0xe9, 0xba, - 0xaf, 0x48, 0xbf, 0xfb, 0x8a, 0xf4, 0x69, 0xa0, 0xa4, 0xae, 0x07, 0x4a, 0xea, 0xc7, 0x40, 0x49, - 0xbd, 0xd9, 0x33, 0xb1, 0xdb, 0xf6, 0xce, 0xd4, 0x26, 0xb1, 0x34, 0x9b, 0xb4, 0x50, 0x7d, 0xa7, - 0x5e, 0xc3, 0x44, 0x13, 0x42, 0xb5, 0x69, 0xaf, 0x4d, 0x70, 0x26, 0xd8, 0x59, 0x86, 0xbf, 0x9d, - 0xbb, 0x7f, 0x02, 0x00, 0x00, 0xff, 0xff, 0x66, 0xc8, 0x3c, 0x88, 0x36, 0x06, 0x00, 0x00, + // 641 bytes of a gzipped FileDescriptorProto + 0x1f, 0x8b, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0xff, 0xb4, 0x94, 0x3f, 0x6f, 0xd3, 0x4e, + 0x18, 0xc7, 0xe3, 0xf4, 0xd7, 0xfe, 0x94, 0x6b, 0xfa, 0xcf, 0x14, 0x35, 0xcd, 0x60, 0x42, 0x50, + 0x45, 0x5a, 0x88, 0xdd, 0xa4, 0x52, 0x87, 0x8a, 0xa5, 0x15, 0x4c, 0x55, 0xa4, 0xc8, 0x85, 0x85, + 0x25, 0xba, 0x38, 0x27, 0xc7, 0xa4, 0xf6, 0x59, 0x77, 0xe7, 0xb4, 0xde, 0x10, 0x23, 0x13, 0x2f, + 0x83, 0x31, 0x03, 0xbc, 0x87, 0x4e, 0x28, 0x62, 0x62, 0x40, 0x08, 0x25, 0x43, 0xde, 0x06, 0xf2, + 0x9d, 0x9d, 0xd8, 0x69, 0x48, 0x0a, 0x12, 0x8b, 0xe5, 0x7b, 0x9e, 0xcf, 0x3d, 0x7f, 0xbe, 0xcf, + 0xdd, 0x81, 0x47, 0xae, 0x77, 0x49, 0x21, 0x31, 0xda, 0xd0, 0x72, 0xb4, 0x0e, 0xf2, 0x09, 0x32, + 0x2d, 0xca, 0x88, 0xaf, 0x75, 0x2b, 0x1a, 0xbb, 0x56, 0x5d, 0x82, 0x19, 0x96, 0xf3, 0x31, 0x48, + 0x8d, 0x41, 0x6a, 0xb7, 0x92, 0xdf, 0x82, 0xb6, 0xe5, 0x60, 0x8d, 0x7f, 0x05, 0x9e, 0xdf, 0x31, + 0x30, 0xb5, 0x31, 0xd5, 0x6c, 0x6a, 0x06, 0x61, 0x6c, 0x6a, 0x86, 0x8e, 0x5d, 0xe1, 0x68, 0xf0, + 0x95, 0x26, 0x16, 0xa1, 0x6b, 0xdb, 0xc4, 0x26, 0x16, 0xf6, 0xe0, 0x2f, 0xb4, 0x3e, 0x9e, 0x53, + 0x9d, 0x0b, 0x09, 0xb4, 0xa3, 0xed, 0x87, 0x73, 0xc0, 0x0e, 0xf2, 0x1b, 0x9e, 0xdb, 0x82, 0x0c, + 0x35, 0x98, 0xef, 0x22, 0xb1, 0xa3, 0xf8, 0x45, 0x02, 0x1b, 0x35, 0x6a, 0xbe, 0xe2, 0x8e, 0x3a, + 0x8f, 0x25, 0x1f, 0x83, 0x0c, 0xf4, 0x58, 0x1b, 0x13, 0x8b, 0xf9, 0x39, 0xa9, 0x20, 0x95, 0x32, + 0x67, 0xb9, 0xaf, 0x9f, 0xca, 0xdb, 0x61, 0xa5, 0xa7, 0xad, 0x16, 0x41, 0x94, 0x5e, 0x30, 0x62, + 0x39, 0xa6, 0x3e, 0x41, 0xe5, 0x17, 0x60, 0x45, 0x54, 0x93, 0x4b, 0x17, 0xa4, 0xd2, 0x6a, 0xb5, + 0xa8, 0xfe, 0x5e, 0x30, 0x55, 0xe4, 0x3a, 0xcb, 0xdc, 0xfc, 0x78, 0x90, 0xfa, 0x38, 0xea, 0x1d, + 0x48, 0x7a, 0xb8, 0xf9, 0xe4, 0xd9, 0xbb, 0x51, 0xef, 0x60, 0x12, 0xf6, 0xfd, 0xa8, 0x77, 0xb0, + 0x1f, 0xef, 0xeb, 0x3a, 0xd1, 0xd9, 0x54, 0xf1, 0xc5, 0x5d, 0xb0, 0x33, 0x65, 0xd2, 0x11, 0x75, + 0xb1, 0x43, 0x51, 0xf1, 0x73, 0x9a, 0xf7, 0xaa, 0xf3, 0xad, 0x88, 0x9c, 0x23, 0x9f, 0xca, 0x55, + 0xf0, 0xbf, 0x41, 0x10, 0x64, 0x98, 0x2c, 0xec, 0x34, 0x02, 0xe5, 0x7d, 0xb0, 0x19, 0x4e, 0x90, + 0x5a, 0xa6, 0x03, 0x99, 0x47, 0x10, 0xef, 0x38, 0xa3, 0x6f, 0x08, 0xfb, 0x45, 0x64, 0x96, 0xf7, + 0xc0, 0xba, 0x6d, 0x39, 0x30, 0x06, 0x2e, 0x71, 0x70, 0x2d, 0xb0, 0x26, 0xb0, 0x30, 0x22, 0x14, + 0x29, 0x73, 0xff, 0x15, 0xa4, 0x52, 0x56, 0x5f, 0x13, 0xd6, 0xb0, 0x0e, 0xf9, 0x21, 0xc8, 0xf2, + 0x68, 0x11, 0xb4, 0xcc, 0xa1, 0xd5, 0xc0, 0x16, 0x21, 0xcf, 0x01, 0x80, 0x06, 0xc3, 0x84, 0xcf, + 0x38, 0xb7, 0x52, 0x90, 0x4a, 0xeb, 0xd5, 0xbd, 0x79, 0x73, 0x38, 0x0d, 0xe8, 0x97, 0xbe, 0x8b, + 0xf4, 0x0c, 0x8c, 0x7e, 0x4f, 0xb2, 0xc1, 0x08, 0xa2, 0x7e, 0x43, 0x49, 0xe3, 0xb2, 0x8d, 0x25, + 0xed, 0xa7, 0xc1, 0xda, 0x58, 0xee, 0xbf, 0x16, 0x54, 0x03, 0xdb, 0x2e, 0x41, 0xdd, 0x06, 0x6f, + 0xce, 0xf5, 0x9a, 0x97, 0x96, 0xd1, 0xe8, 0x20, 0x9f, 0x8b, 0x9a, 0xd5, 0xb7, 0x02, 0x5f, 0xcd, + 0x72, 0x60, 0x9d, 0x7b, 0xce, 0x91, 0x2f, 0x97, 0xc1, 0x3d, 0x07, 0x5d, 0xdd, 0xe2, 0x97, 0x38, + 0xbf, 0xe9, 0xa0, 0xab, 0x24, 0x3e, 0x6b, 0x60, 0x42, 0xe0, 0x5b, 0x03, 0x7b, 0x0a, 0xe4, 0x71, + 0xe4, 0x09, 0xbc, 0x9c, 0x08, 0x3c, 0xa1, 0xff, 0x85, 0xda, 0x3b, 0xe0, 0x7e, 0x42, 0xd1, 0x48, + 0xeb, 0xea, 0xf7, 0x34, 0x58, 0xaa, 0x51, 0x53, 0x76, 0x41, 0x36, 0x71, 0x5d, 0x9f, 0xcc, 0x4b, + 0x38, 0x75, 0x17, 0xf2, 0x47, 0x7f, 0x00, 0x47, 0x99, 0x83, 0x8c, 0x89, 0x4b, 0xb3, 0x28, 0x63, + 0x1c, 0x5e, 0x98, 0x71, 0xd6, 0xb9, 0x92, 0xdf, 0x00, 0x10, 0x3b, 0x53, 0xfb, 0x77, 0x2a, 0x9a, + 0x67, 0xab, 0xdc, 0x19, 0x8d, 0x72, 0xe5, 0x97, 0xdf, 0x06, 0xcf, 0xcf, 0x59, 0xfd, 0x66, 0xa0, + 0x48, 0xfd, 0x81, 0x22, 0xfd, 0x1c, 0x28, 0xd2, 0x87, 0xa1, 0x92, 0xea, 0x0f, 0x95, 0xd4, 0xb7, + 0xa1, 0x92, 0x7a, 0x7d, 0x6c, 0x5a, 0xac, 0xed, 0x35, 0x55, 0x03, 0xdb, 0x9a, 0x83, 0x5b, 0xa8, + 0x72, 0x58, 0x29, 0x5b, 0x58, 0x13, 0x89, 0xca, 0xb3, 0x1e, 0xa5, 0xe0, 0x38, 0xd0, 0xe6, 0x0a, + 0x7f, 0x62, 0x8f, 0x7e, 0x05, 0x00, 0x00, 0xff, 0xff, 0xac, 0xab, 0xc3, 0xf8, 0x5d, 0x06, 0x00, + 0x00, } // Reference imports to suppress errors if they are not otherwise used. @@ -670,13 +670,8 @@ func (m *MsgRegisterKeys) MarshalToSizedBuffer(dAtA []byte) (int, error) { _ = i var l int _ = l - if m.IsUser { - i-- - if m.IsUser { - dAtA[i] = 1 - } else { - dAtA[i] = 0 - } + if m.ActorType != 0 { + i = encodeVarintTx(dAtA, i, uint64(m.ActorType)) i-- dAtA[i] = 0x30 } @@ -761,8 +756,8 @@ func (m *MsgUpdateKeys) MarshalToSizedBuffer(dAtA []byte) (int, error) { _ = i var l int _ = l - if m.UpdateType != 0 { - i = encodeVarintTx(dAtA, i, uint64(m.UpdateType)) + if m.ActorType != 0 { + i = encodeVarintTx(dAtA, i, uint64(m.ActorType)) i-- dAtA[i] = 0x30 } @@ -888,8 +883,8 @@ func (m *MsgRegisterKeys) Size() (n int) { if l > 0 { n += 1 + l + sovTx(uint64(l)) } - if m.IsUser { - n += 2 + if m.ActorType != 0 { + n += 1 + sovTx(uint64(m.ActorType)) } return n } @@ -929,8 +924,8 @@ func (m *MsgUpdateKeys) Size() (n int) { if l > 0 { n += 1 + l + sovTx(uint64(l)) } - if m.UpdateType != 0 { - n += 1 + sovTx(uint64(m.UpdateType)) + if m.ActorType != 0 { + n += 1 + sovTx(uint64(m.ActorType)) } return n } @@ -1310,9 +1305,9 @@ func (m *MsgRegisterKeys) Unmarshal(dAtA []byte) error { iNdEx = postIndex case 6: if wireType != 0 { - return fmt.Errorf("proto: wrong wireType = %d for field IsUser", wireType) + return fmt.Errorf("proto: wrong wireType = %d for field ActorType", wireType) } - var v int + m.ActorType = 0 for shift := uint(0); ; shift += 7 { if shift >= 64 { return ErrIntOverflowTx @@ -1322,12 +1317,11 @@ func (m *MsgRegisterKeys) Unmarshal(dAtA []byte) error { } b := dAtA[iNdEx] iNdEx++ - v |= int(b&0x7F) << shift + m.ActorType |= ActorType(b&0x7F) << shift if b < 0x80 { break } } - m.IsUser = bool(v != 0) default: iNdEx = preIndex skippy, err := skipTx(dAtA[iNdEx:]) @@ -1598,9 +1592,9 @@ func (m *MsgUpdateKeys) Unmarshal(dAtA []byte) error { iNdEx = postIndex case 6: if wireType != 0 { - return fmt.Errorf("proto: wrong wireType = %d for field UpdateType", wireType) + return fmt.Errorf("proto: wrong wireType = %d for field ActorType", wireType) } - m.UpdateType = 0 + m.ActorType = 0 for shift := uint(0); ; shift += 7 { if shift >= 64 { return ErrIntOverflowTx @@ -1610,7 +1604,7 @@ func (m *MsgUpdateKeys) Unmarshal(dAtA []byte) error { } b := dAtA[iNdEx] iNdEx++ - m.UpdateType |= KeyUpdateType(b&0x7F) << shift + m.ActorType |= ActorType(b&0x7F) << shift if b < 0x80 { break } From 1d13d80b544bff76578a9808d402f63badec6a68 Mon Sep 17 00:00:00 2001 From: Yusuf Date: Wed, 15 Apr 2026 17:59:59 +0300 Subject: [PATCH 05/62] chore: fix the naming of user maps --- proto/pulsarchain/keyregistry/v1/query.proto | 24 +- .../keeper/query_get_user_cosmos_address.go | 12 +- .../keeper/query_get_user_mina_address.go | 10 +- .../keeper/query_user_keypairs_test.go | 24 +- x/keyregistry/types/query.pb.go | 413 +++++++++--------- x/keyregistry/types/query.pb.gw.go | 88 ++-- 6 files changed, 285 insertions(+), 286 deletions(-) diff --git a/proto/pulsarchain/keyregistry/v1/query.proto b/proto/pulsarchain/keyregistry/v1/query.proto index 9dda46ad..8281dfce 100644 --- a/proto/pulsarchain/keyregistry/v1/query.proto +++ b/proto/pulsarchain/keyregistry/v1/query.proto @@ -18,13 +18,13 @@ service Query { } // GetUserMinaAddress Queries a list of GetUserMinaAddress items. - rpc GetUserMinaAddress(QueryGetUserMinaAddressRequest) returns (QueryGetUserMinaAddressResponse) { - option (google.api.http).get = "/node101-io/pulsar-chain/keyregistry/v1/get_user_mina_address/{user_cosmos_address}"; + rpc GetUserMinaPublicKey(QueryGetUserMinaPublicKeyRequest) returns (QueryGetUserMinaPublicKeyResponse) { + option (google.api.http).get = "/node101-io/pulsar-chain/keyregistry/v1/get_user_mina_public_key/{user_cosmos_public_key}"; } // GetUserCosmosAddress Queries a list of GetUserCosmosAddress items. - rpc GetUserCosmosAddress(QueryGetUserCosmosAddressRequest) returns (QueryGetUserCosmosAddressResponse) { - option (google.api.http).get = "/node101-io/pulsar-chain/keyregistry/v1/get_user_cosmos_address/{user_mina_address}"; + rpc GetUserCosmosPublicKey(QueryGetUserCosmosPublicKeyRequest) returns (QueryGetUserCosmosPublicKeyResponse) { + option (google.api.http).get = "/node101-io/pulsar-chain/keyregistry/v1/get_user_cosmos_public_key/{user_mina_public_key}"; } // GetValidatorMinaAddress Queries a list of GetValidatorMinaAddress items. @@ -51,23 +51,23 @@ message QueryParamsResponse { } // QueryGetUserMinaAddressRequest defines the QueryGetUserMinaAddressRequest message. -message QueryGetUserMinaAddressRequest { - bytes user_cosmos_address = 1; +message QueryGetUserMinaPublicKeyRequest { + bytes user_cosmos_public_key = 1; } // QueryGetUserMinaAddressResponse defines the QueryGetUserMinaAddressResponse message. -message QueryGetUserMinaAddressResponse { - bytes user_mina_address = 1; +message QueryGetUserMinaPublicKeyResponse { + bytes user_mina_public_key = 1; } // QueryGetUserCosmosAddressRequest defines the QueryGetUserCosmosAddressRequest message. -message QueryGetUserCosmosAddressRequest { - bytes user_mina_address = 1; +message QueryGetUserCosmosPublicKeyRequest { + bytes user_mina_public_key = 1; } // QueryGetUserCosmosAddressResponse defines the QueryGetUserCosmosAddressResponse message. -message QueryGetUserCosmosAddressResponse { - bytes user_cosmos_address = 1; +message QueryGetUserCosmosPublicKeyResponse { + bytes user_cosmos_public_key = 1; } // QueryGetValidatorMinaAddressRequest defines the QueryGetValidatorMinaAddressRequest message. diff --git a/x/keyregistry/keeper/query_get_user_cosmos_address.go b/x/keyregistry/keeper/query_get_user_cosmos_address.go index c8ed261a..3a280de2 100644 --- a/x/keyregistry/keeper/query_get_user_cosmos_address.go +++ b/x/keyregistry/keeper/query_get_user_cosmos_address.go @@ -11,15 +11,15 @@ import ( // GetCosmosPubKey returns the user's cosmos public key associated with the given mina public key. // Returns NotFound if no mapping exists for the provided mina public key. -func (q queryServer) GetUserCosmosAddress(ctx context.Context, req *types.QueryGetUserCosmosAddressRequest) (*types.QueryGetUserCosmosAddressResponse, error) { +func (q queryServer) GetUserCosmosPublicKey(ctx context.Context, req *types.QueryGetUserCosmosPublicKeyRequest) (*types.QueryGetUserCosmosPublicKeyResponse, error) { if req == nil { return nil, status.Error(codes.InvalidArgument, "invalid request") } sdkCtx := sdk.UnwrapSDKContext(ctx) - // Check if the mina address exists in the MinaToCosmos map. - exists, err := q.k.userMinaToCosmos.Has(sdkCtx, req.UserMinaAddress) + // Check if the mina PublicKey exists in the MinaToCosmos map. + exists, err := q.k.userMinaToCosmos.Has(sdkCtx, req.UserMinaPublicKey) if err != nil { return nil, status.Error(codes.Internal, "internal error") } @@ -28,12 +28,12 @@ func (q queryServer) GetUserCosmosAddress(ctx context.Context, req *types.QueryG return nil, status.Error(codes.NotFound, "cosmos key not found for given mina key") } - cosmosKey, err := q.k.userMinaToCosmos.Get(sdkCtx, req.UserMinaAddress) + cosmosKey, err := q.k.userMinaToCosmos.Get(sdkCtx, req.UserMinaPublicKey) if err != nil { return nil, status.Error(codes.Internal, err.Error()) } - return &types.QueryGetUserCosmosAddressResponse{ - UserCosmosAddress: cosmosKey, + return &types.QueryGetUserCosmosPublicKeyResponse{ + UserCosmosPublicKey: cosmosKey, }, nil } diff --git a/x/keyregistry/keeper/query_get_user_mina_address.go b/x/keyregistry/keeper/query_get_user_mina_address.go index 421b9b89..0cf9b7cf 100644 --- a/x/keyregistry/keeper/query_get_user_mina_address.go +++ b/x/keyregistry/keeper/query_get_user_mina_address.go @@ -11,7 +11,7 @@ import ( // GetMinaPubKey returns the user's mina public key associated with the given cosmos public key. // Returns NotFound if no mapping exists for the provided cosmos public key. -func (q queryServer) GetUserMinaAddress(ctx context.Context, req *types.QueryGetUserMinaAddressRequest) (*types.QueryGetUserMinaAddressResponse, error) { +func (q queryServer) GetUserMinaPublicKey(ctx context.Context, req *types.QueryGetUserMinaPublicKeyRequest) (*types.QueryGetUserMinaPublicKeyResponse, error) { if req == nil { return nil, status.Error(codes.InvalidArgument, "invalid request") } @@ -19,7 +19,7 @@ func (q queryServer) GetUserMinaAddress(ctx context.Context, req *types.QueryGet sdkCtx := sdk.UnwrapSDKContext(ctx) // Check if the cosmos key exists in the CosmosToMina map. - exists, err := q.k.userCosmosToMina.Has(sdkCtx, req.UserCosmosAddress) + exists, err := q.k.userCosmosToMina.Has(sdkCtx, req.UserCosmosPublicKey) if err != nil { return nil, status.Error(codes.Internal, "internal Error") } @@ -28,12 +28,12 @@ func (q queryServer) GetUserMinaAddress(ctx context.Context, req *types.QueryGet return nil, status.Error(codes.NotFound, "mina key not found for given cosmos key") } - minaKey, err := q.k.userCosmosToMina.Get(sdkCtx, req.UserCosmosAddress) + minaKey, err := q.k.userCosmosToMina.Get(sdkCtx, req.UserCosmosPublicKey) if err != nil { return nil, status.Error(codes.Internal, err.Error()) } - return &types.QueryGetUserMinaAddressResponse{ - UserMinaAddress: minaKey, + return &types.QueryGetUserMinaPublicKeyResponse{ + UserMinaPublicKey: minaKey, }, nil } diff --git a/x/keyregistry/keeper/query_user_keypairs_test.go b/x/keyregistry/keeper/query_user_keypairs_test.go index d0e24013..a8346ebd 100644 --- a/x/keyregistry/keeper/query_user_keypairs_test.go +++ b/x/keyregistry/keeper/query_user_keypairs_test.go @@ -22,7 +22,7 @@ func TestUserCosmosMapInvalidArgumentFail(t *testing.T) { params := types.DefaultParams() require.NoError(t, f.keeper.Params.Set(f.ctx, params)) - _, err := qs.GetUserCosmosAddress(f.ctx, nil) + _, err := qs.GetUserCosmosPublicKey(f.ctx, nil) require.Error(t, err) st, _ := status.FromError(err) @@ -51,14 +51,14 @@ func TestUserCosmosMapSuccess(t *testing.T) { err = f.keeper.UserSetCosmosToMina(f.ctx, cosmosPubKey.Bytes(), minaPubKey) require.NoError(t, err) - resp, err := qs.GetUserMinaAddress(f.ctx, &types.QueryGetUserMinaAddressRequest{ - UserCosmosAddress: cosmosPubKey.Bytes(), + resp, err := qs.GetUserMinaPublicKey(f.ctx, &types.QueryGetUserMinaPublicKeyRequest{ + UserCosmosPublicKey: cosmosPubKey.Bytes(), }) require.NotNil(t, resp) require.NoError(t, err) - require.Equal(t, resp.UserMinaAddress, []byte(minaPubKey)) + require.Equal(t, resp.UserMinaPublicKey, []byte(minaPubKey)) } // TestUserMinaMapSuccess verifies that a cosmos public key can be retrieved @@ -83,14 +83,14 @@ func TestUserMinaMapSuccess(t *testing.T) { err = f.keeper.UserSetMinaToCosmos(f.ctx, minaPubKey, cosmosPubKey.Bytes()) require.NoError(t, err) - resp, err := qs.GetUserCosmosAddress(f.ctx, &types.QueryGetUserCosmosAddressRequest{ - UserMinaAddress: minaPubKey, + resp, err := qs.GetUserCosmosPublicKey(f.ctx, &types.QueryGetUserCosmosPublicKeyRequest{ + UserMinaPublicKey: minaPubKey, }) require.NotNil(t, resp) require.NoError(t, err) - require.Equal(t, resp.UserCosmosAddress, cosmosPubKey.Bytes()) + require.Equal(t, resp.UserCosmosPublicKey, cosmosPubKey.Bytes()) } // TestUserMinaMapInvalidArgumentFail verifies that GetMinaPubKey returns @@ -102,7 +102,7 @@ func TestUserMinaMapInvalidArgumentFail(t *testing.T) { params := types.DefaultParams() require.NoError(t, f.keeper.Params.Set(f.ctx, params)) - _, err := qs.GetUserMinaAddress(f.ctx, nil) + _, err := qs.GetUserMinaPublicKey(f.ctx, nil) require.Error(t, err) st, _ := status.FromError(err) @@ -123,8 +123,8 @@ func TestUserCosmosMapPubkeyNotFound(t *testing.T) { panic(err) } - _, err = qs.GetUserCosmosAddress(f.ctx, &types.QueryGetUserCosmosAddressRequest{ - UserMinaAddress: pub, + _, err = qs.GetUserCosmosPublicKey(f.ctx, &types.QueryGetUserCosmosPublicKeyRequest{ + UserMinaPublicKey: pub, }) st, _ := status.FromError(err) @@ -144,8 +144,8 @@ func TestUserMinaMapPubkeyNotFound(t *testing.T) { pub := priv.PubKey() - _, err := qs.GetUserMinaAddress(f.ctx, &types.QueryGetUserMinaAddressRequest{ - UserCosmosAddress: pub.Bytes(), + _, err := qs.GetUserMinaPublicKey(f.ctx, &types.QueryGetUserMinaPublicKeyRequest{ + UserCosmosPublicKey: pub.Bytes(), }) st, _ := status.FromError(err) diff --git a/x/keyregistry/types/query.pb.go b/x/keyregistry/types/query.pb.go index 8fd3aa83..596add31 100644 --- a/x/keyregistry/types/query.pb.go +++ b/x/keyregistry/types/query.pb.go @@ -115,22 +115,22 @@ func (m *QueryParamsResponse) GetParams() Params { } // QueryGetUserMinaAddressRequest defines the QueryGetUserMinaAddressRequest message. -type QueryGetUserMinaAddressRequest struct { - UserCosmosAddress []byte `protobuf:"bytes,1,opt,name=user_cosmos_address,json=userCosmosAddress,proto3" json:"user_cosmos_address,omitempty"` +type QueryGetUserMinaPublicKeyRequest struct { + UserCosmosPublicKey []byte `protobuf:"bytes,1,opt,name=user_cosmos_public_key,json=userCosmosPublicKey,proto3" json:"user_cosmos_public_key,omitempty"` } -func (m *QueryGetUserMinaAddressRequest) Reset() { *m = QueryGetUserMinaAddressRequest{} } -func (m *QueryGetUserMinaAddressRequest) String() string { return proto.CompactTextString(m) } -func (*QueryGetUserMinaAddressRequest) ProtoMessage() {} -func (*QueryGetUserMinaAddressRequest) Descriptor() ([]byte, []int) { +func (m *QueryGetUserMinaPublicKeyRequest) Reset() { *m = QueryGetUserMinaPublicKeyRequest{} } +func (m *QueryGetUserMinaPublicKeyRequest) String() string { return proto.CompactTextString(m) } +func (*QueryGetUserMinaPublicKeyRequest) ProtoMessage() {} +func (*QueryGetUserMinaPublicKeyRequest) Descriptor() ([]byte, []int) { return fileDescriptor_d580bfce910e0ca3, []int{2} } -func (m *QueryGetUserMinaAddressRequest) XXX_Unmarshal(b []byte) error { +func (m *QueryGetUserMinaPublicKeyRequest) XXX_Unmarshal(b []byte) error { return m.Unmarshal(b) } -func (m *QueryGetUserMinaAddressRequest) XXX_Marshal(b []byte, deterministic bool) ([]byte, error) { +func (m *QueryGetUserMinaPublicKeyRequest) XXX_Marshal(b []byte, deterministic bool) ([]byte, error) { if deterministic { - return xxx_messageInfo_QueryGetUserMinaAddressRequest.Marshal(b, m, deterministic) + return xxx_messageInfo_QueryGetUserMinaPublicKeyRequest.Marshal(b, m, deterministic) } else { b = b[:cap(b)] n, err := m.MarshalToSizedBuffer(b) @@ -140,42 +140,42 @@ func (m *QueryGetUserMinaAddressRequest) XXX_Marshal(b []byte, deterministic boo return b[:n], nil } } -func (m *QueryGetUserMinaAddressRequest) XXX_Merge(src proto.Message) { - xxx_messageInfo_QueryGetUserMinaAddressRequest.Merge(m, src) +func (m *QueryGetUserMinaPublicKeyRequest) XXX_Merge(src proto.Message) { + xxx_messageInfo_QueryGetUserMinaPublicKeyRequest.Merge(m, src) } -func (m *QueryGetUserMinaAddressRequest) XXX_Size() int { +func (m *QueryGetUserMinaPublicKeyRequest) XXX_Size() int { return m.Size() } -func (m *QueryGetUserMinaAddressRequest) XXX_DiscardUnknown() { - xxx_messageInfo_QueryGetUserMinaAddressRequest.DiscardUnknown(m) +func (m *QueryGetUserMinaPublicKeyRequest) XXX_DiscardUnknown() { + xxx_messageInfo_QueryGetUserMinaPublicKeyRequest.DiscardUnknown(m) } -var xxx_messageInfo_QueryGetUserMinaAddressRequest proto.InternalMessageInfo +var xxx_messageInfo_QueryGetUserMinaPublicKeyRequest proto.InternalMessageInfo -func (m *QueryGetUserMinaAddressRequest) GetUserCosmosAddress() []byte { +func (m *QueryGetUserMinaPublicKeyRequest) GetUserCosmosPublicKey() []byte { if m != nil { - return m.UserCosmosAddress + return m.UserCosmosPublicKey } return nil } // QueryGetUserMinaAddressResponse defines the QueryGetUserMinaAddressResponse message. -type QueryGetUserMinaAddressResponse struct { - UserMinaAddress []byte `protobuf:"bytes,1,opt,name=user_mina_address,json=userMinaAddress,proto3" json:"user_mina_address,omitempty"` +type QueryGetUserMinaPublicKeyResponse struct { + UserMinaPublicKey []byte `protobuf:"bytes,1,opt,name=user_mina_public_key,json=userMinaPublicKey,proto3" json:"user_mina_public_key,omitempty"` } -func (m *QueryGetUserMinaAddressResponse) Reset() { *m = QueryGetUserMinaAddressResponse{} } -func (m *QueryGetUserMinaAddressResponse) String() string { return proto.CompactTextString(m) } -func (*QueryGetUserMinaAddressResponse) ProtoMessage() {} -func (*QueryGetUserMinaAddressResponse) Descriptor() ([]byte, []int) { +func (m *QueryGetUserMinaPublicKeyResponse) Reset() { *m = QueryGetUserMinaPublicKeyResponse{} } +func (m *QueryGetUserMinaPublicKeyResponse) String() string { return proto.CompactTextString(m) } +func (*QueryGetUserMinaPublicKeyResponse) ProtoMessage() {} +func (*QueryGetUserMinaPublicKeyResponse) Descriptor() ([]byte, []int) { return fileDescriptor_d580bfce910e0ca3, []int{3} } -func (m *QueryGetUserMinaAddressResponse) XXX_Unmarshal(b []byte) error { +func (m *QueryGetUserMinaPublicKeyResponse) XXX_Unmarshal(b []byte) error { return m.Unmarshal(b) } -func (m *QueryGetUserMinaAddressResponse) XXX_Marshal(b []byte, deterministic bool) ([]byte, error) { +func (m *QueryGetUserMinaPublicKeyResponse) XXX_Marshal(b []byte, deterministic bool) ([]byte, error) { if deterministic { - return xxx_messageInfo_QueryGetUserMinaAddressResponse.Marshal(b, m, deterministic) + return xxx_messageInfo_QueryGetUserMinaPublicKeyResponse.Marshal(b, m, deterministic) } else { b = b[:cap(b)] n, err := m.MarshalToSizedBuffer(b) @@ -185,42 +185,42 @@ func (m *QueryGetUserMinaAddressResponse) XXX_Marshal(b []byte, deterministic bo return b[:n], nil } } -func (m *QueryGetUserMinaAddressResponse) XXX_Merge(src proto.Message) { - xxx_messageInfo_QueryGetUserMinaAddressResponse.Merge(m, src) +func (m *QueryGetUserMinaPublicKeyResponse) XXX_Merge(src proto.Message) { + xxx_messageInfo_QueryGetUserMinaPublicKeyResponse.Merge(m, src) } -func (m *QueryGetUserMinaAddressResponse) XXX_Size() int { +func (m *QueryGetUserMinaPublicKeyResponse) XXX_Size() int { return m.Size() } -func (m *QueryGetUserMinaAddressResponse) XXX_DiscardUnknown() { - xxx_messageInfo_QueryGetUserMinaAddressResponse.DiscardUnknown(m) +func (m *QueryGetUserMinaPublicKeyResponse) XXX_DiscardUnknown() { + xxx_messageInfo_QueryGetUserMinaPublicKeyResponse.DiscardUnknown(m) } -var xxx_messageInfo_QueryGetUserMinaAddressResponse proto.InternalMessageInfo +var xxx_messageInfo_QueryGetUserMinaPublicKeyResponse proto.InternalMessageInfo -func (m *QueryGetUserMinaAddressResponse) GetUserMinaAddress() []byte { +func (m *QueryGetUserMinaPublicKeyResponse) GetUserMinaPublicKey() []byte { if m != nil { - return m.UserMinaAddress + return m.UserMinaPublicKey } return nil } // QueryGetUserCosmosAddressRequest defines the QueryGetUserCosmosAddressRequest message. -type QueryGetUserCosmosAddressRequest struct { - UserMinaAddress []byte `protobuf:"bytes,1,opt,name=user_mina_address,json=userMinaAddress,proto3" json:"user_mina_address,omitempty"` +type QueryGetUserCosmosPublicKeyRequest struct { + UserMinaPublicKey []byte `protobuf:"bytes,1,opt,name=user_mina_public_key,json=userMinaPublicKey,proto3" json:"user_mina_public_key,omitempty"` } -func (m *QueryGetUserCosmosAddressRequest) Reset() { *m = QueryGetUserCosmosAddressRequest{} } -func (m *QueryGetUserCosmosAddressRequest) String() string { return proto.CompactTextString(m) } -func (*QueryGetUserCosmosAddressRequest) ProtoMessage() {} -func (*QueryGetUserCosmosAddressRequest) Descriptor() ([]byte, []int) { +func (m *QueryGetUserCosmosPublicKeyRequest) Reset() { *m = QueryGetUserCosmosPublicKeyRequest{} } +func (m *QueryGetUserCosmosPublicKeyRequest) String() string { return proto.CompactTextString(m) } +func (*QueryGetUserCosmosPublicKeyRequest) ProtoMessage() {} +func (*QueryGetUserCosmosPublicKeyRequest) Descriptor() ([]byte, []int) { return fileDescriptor_d580bfce910e0ca3, []int{4} } -func (m *QueryGetUserCosmosAddressRequest) XXX_Unmarshal(b []byte) error { +func (m *QueryGetUserCosmosPublicKeyRequest) XXX_Unmarshal(b []byte) error { return m.Unmarshal(b) } -func (m *QueryGetUserCosmosAddressRequest) XXX_Marshal(b []byte, deterministic bool) ([]byte, error) { +func (m *QueryGetUserCosmosPublicKeyRequest) XXX_Marshal(b []byte, deterministic bool) ([]byte, error) { if deterministic { - return xxx_messageInfo_QueryGetUserCosmosAddressRequest.Marshal(b, m, deterministic) + return xxx_messageInfo_QueryGetUserCosmosPublicKeyRequest.Marshal(b, m, deterministic) } else { b = b[:cap(b)] n, err := m.MarshalToSizedBuffer(b) @@ -230,42 +230,42 @@ func (m *QueryGetUserCosmosAddressRequest) XXX_Marshal(b []byte, deterministic b return b[:n], nil } } -func (m *QueryGetUserCosmosAddressRequest) XXX_Merge(src proto.Message) { - xxx_messageInfo_QueryGetUserCosmosAddressRequest.Merge(m, src) +func (m *QueryGetUserCosmosPublicKeyRequest) XXX_Merge(src proto.Message) { + xxx_messageInfo_QueryGetUserCosmosPublicKeyRequest.Merge(m, src) } -func (m *QueryGetUserCosmosAddressRequest) XXX_Size() int { +func (m *QueryGetUserCosmosPublicKeyRequest) XXX_Size() int { return m.Size() } -func (m *QueryGetUserCosmosAddressRequest) XXX_DiscardUnknown() { - xxx_messageInfo_QueryGetUserCosmosAddressRequest.DiscardUnknown(m) +func (m *QueryGetUserCosmosPublicKeyRequest) XXX_DiscardUnknown() { + xxx_messageInfo_QueryGetUserCosmosPublicKeyRequest.DiscardUnknown(m) } -var xxx_messageInfo_QueryGetUserCosmosAddressRequest proto.InternalMessageInfo +var xxx_messageInfo_QueryGetUserCosmosPublicKeyRequest proto.InternalMessageInfo -func (m *QueryGetUserCosmosAddressRequest) GetUserMinaAddress() []byte { +func (m *QueryGetUserCosmosPublicKeyRequest) GetUserMinaPublicKey() []byte { if m != nil { - return m.UserMinaAddress + return m.UserMinaPublicKey } return nil } // QueryGetUserCosmosAddressResponse defines the QueryGetUserCosmosAddressResponse message. -type QueryGetUserCosmosAddressResponse struct { - UserCosmosAddress []byte `protobuf:"bytes,1,opt,name=user_cosmos_address,json=userCosmosAddress,proto3" json:"user_cosmos_address,omitempty"` +type QueryGetUserCosmosPublicKeyResponse struct { + UserCosmosPublicKey []byte `protobuf:"bytes,1,opt,name=user_cosmos_public_key,json=userCosmosPublicKey,proto3" json:"user_cosmos_public_key,omitempty"` } -func (m *QueryGetUserCosmosAddressResponse) Reset() { *m = QueryGetUserCosmosAddressResponse{} } -func (m *QueryGetUserCosmosAddressResponse) String() string { return proto.CompactTextString(m) } -func (*QueryGetUserCosmosAddressResponse) ProtoMessage() {} -func (*QueryGetUserCosmosAddressResponse) Descriptor() ([]byte, []int) { +func (m *QueryGetUserCosmosPublicKeyResponse) Reset() { *m = QueryGetUserCosmosPublicKeyResponse{} } +func (m *QueryGetUserCosmosPublicKeyResponse) String() string { return proto.CompactTextString(m) } +func (*QueryGetUserCosmosPublicKeyResponse) ProtoMessage() {} +func (*QueryGetUserCosmosPublicKeyResponse) Descriptor() ([]byte, []int) { return fileDescriptor_d580bfce910e0ca3, []int{5} } -func (m *QueryGetUserCosmosAddressResponse) XXX_Unmarshal(b []byte) error { +func (m *QueryGetUserCosmosPublicKeyResponse) XXX_Unmarshal(b []byte) error { return m.Unmarshal(b) } -func (m *QueryGetUserCosmosAddressResponse) XXX_Marshal(b []byte, deterministic bool) ([]byte, error) { +func (m *QueryGetUserCosmosPublicKeyResponse) XXX_Marshal(b []byte, deterministic bool) ([]byte, error) { if deterministic { - return xxx_messageInfo_QueryGetUserCosmosAddressResponse.Marshal(b, m, deterministic) + return xxx_messageInfo_QueryGetUserCosmosPublicKeyResponse.Marshal(b, m, deterministic) } else { b = b[:cap(b)] n, err := m.MarshalToSizedBuffer(b) @@ -275,21 +275,21 @@ func (m *QueryGetUserCosmosAddressResponse) XXX_Marshal(b []byte, deterministic return b[:n], nil } } -func (m *QueryGetUserCosmosAddressResponse) XXX_Merge(src proto.Message) { - xxx_messageInfo_QueryGetUserCosmosAddressResponse.Merge(m, src) +func (m *QueryGetUserCosmosPublicKeyResponse) XXX_Merge(src proto.Message) { + xxx_messageInfo_QueryGetUserCosmosPublicKeyResponse.Merge(m, src) } -func (m *QueryGetUserCosmosAddressResponse) XXX_Size() int { +func (m *QueryGetUserCosmosPublicKeyResponse) XXX_Size() int { return m.Size() } -func (m *QueryGetUserCosmosAddressResponse) XXX_DiscardUnknown() { - xxx_messageInfo_QueryGetUserCosmosAddressResponse.DiscardUnknown(m) +func (m *QueryGetUserCosmosPublicKeyResponse) XXX_DiscardUnknown() { + xxx_messageInfo_QueryGetUserCosmosPublicKeyResponse.DiscardUnknown(m) } -var xxx_messageInfo_QueryGetUserCosmosAddressResponse proto.InternalMessageInfo +var xxx_messageInfo_QueryGetUserCosmosPublicKeyResponse proto.InternalMessageInfo -func (m *QueryGetUserCosmosAddressResponse) GetUserCosmosAddress() []byte { +func (m *QueryGetUserCosmosPublicKeyResponse) GetUserCosmosPublicKey() []byte { if m != nil { - return m.UserCosmosAddress + return m.UserCosmosPublicKey } return nil } @@ -477,10 +477,10 @@ func (m *QueryGetValidatorCosmosPubKeyResponse) GetValidatorCosmosPubKey() []byt func init() { proto.RegisterType((*QueryParamsRequest)(nil), "pulsarchain.keyregistry.v1.QueryParamsRequest") proto.RegisterType((*QueryParamsResponse)(nil), "pulsarchain.keyregistry.v1.QueryParamsResponse") - proto.RegisterType((*QueryGetUserMinaAddressRequest)(nil), "pulsarchain.keyregistry.v1.QueryGetUserMinaAddressRequest") - proto.RegisterType((*QueryGetUserMinaAddressResponse)(nil), "pulsarchain.keyregistry.v1.QueryGetUserMinaAddressResponse") - proto.RegisterType((*QueryGetUserCosmosAddressRequest)(nil), "pulsarchain.keyregistry.v1.QueryGetUserCosmosAddressRequest") - proto.RegisterType((*QueryGetUserCosmosAddressResponse)(nil), "pulsarchain.keyregistry.v1.QueryGetUserCosmosAddressResponse") + proto.RegisterType((*QueryGetUserMinaPublicKeyRequest)(nil), "pulsarchain.keyregistry.v1.QueryGetUserMinaPublicKeyRequest") + proto.RegisterType((*QueryGetUserMinaPublicKeyResponse)(nil), "pulsarchain.keyregistry.v1.QueryGetUserMinaPublicKeyResponse") + proto.RegisterType((*QueryGetUserCosmosPublicKeyRequest)(nil), "pulsarchain.keyregistry.v1.QueryGetUserCosmosPublicKeyRequest") + proto.RegisterType((*QueryGetUserCosmosPublicKeyResponse)(nil), "pulsarchain.keyregistry.v1.QueryGetUserCosmosPublicKeyResponse") proto.RegisterType((*QueryGetValidatorMinaPubKeyRequest)(nil), "pulsarchain.keyregistry.v1.QueryGetValidatorMinaPubKeyRequest") proto.RegisterType((*QueryGetValidatorMinaPubKeyResponse)(nil), "pulsarchain.keyregistry.v1.QueryGetValidatorMinaPubKeyResponse") proto.RegisterType((*QueryGetValidatorCosmosPubKeyRequest)(nil), "pulsarchain.keyregistry.v1.QueryGetValidatorCosmosPubKeyRequest") @@ -492,49 +492,48 @@ func init() { } var fileDescriptor_d580bfce910e0ca3 = []byte{ - // 659 bytes of a gzipped FileDescriptorProto - 0x1f, 0x8b, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0xff, 0xac, 0x56, 0x4f, 0x6b, 0x13, 0x4f, - 0x18, 0xce, 0x16, 0x7e, 0x85, 0xce, 0x4f, 0x90, 0x4e, 0x62, 0x09, 0x8b, 0x6c, 0xeb, 0xfa, 0x97, - 0x40, 0x77, 0xba, 0x2d, 0x54, 0xf0, 0x7f, 0x2b, 0xe2, 0x41, 0x2a, 0x31, 0xa5, 0x1e, 0x5a, 0xcb, - 0x3a, 0x9b, 0x0c, 0xdb, 0xa5, 0xc9, 0xce, 0x76, 0x67, 0x37, 0xb8, 0x94, 0x80, 0x78, 0xf0, 0x2c, - 0x78, 0xf0, 0xec, 0xcd, 0xa3, 0x1f, 0xa3, 0xc7, 0x82, 0x17, 0x4f, 0x22, 0x89, 0x20, 0x78, 0xf2, - 0x23, 0x48, 0x66, 0x67, 0x75, 0xd7, 0xec, 0xa6, 0x49, 0xea, 0x25, 0x0c, 0xf3, 0xbe, 0xcf, 0xf3, - 0x3e, 0xcf, 0x4b, 0x9e, 0x61, 0xc1, 0x15, 0x37, 0x68, 0x32, 0xec, 0xd5, 0xf7, 0xb0, 0xed, 0xa0, - 0x7d, 0x12, 0x7a, 0xc4, 0xb2, 0x99, 0xef, 0x85, 0xa8, 0xad, 0xa3, 0x83, 0x80, 0x78, 0xa1, 0xe6, - 0x7a, 0xd4, 0xa7, 0x50, 0x4e, 0xf4, 0x69, 0x89, 0x3e, 0xad, 0xad, 0xcb, 0xb3, 0xb8, 0x65, 0x3b, - 0x14, 0xf1, 0xdf, 0xa8, 0x5d, 0xae, 0xd4, 0x29, 0x6b, 0x51, 0x86, 0x4c, 0xcc, 0x48, 0xc4, 0x83, - 0xda, 0xba, 0x49, 0x7c, 0xac, 0x23, 0x17, 0x5b, 0xb6, 0x83, 0x7d, 0x9b, 0x3a, 0xa2, 0xb7, 0x64, - 0x51, 0x8b, 0xf2, 0x23, 0xea, 0x9f, 0xc4, 0xed, 0x79, 0x8b, 0x52, 0xab, 0x49, 0x10, 0x76, 0x6d, - 0x84, 0x1d, 0x87, 0xfa, 0x1c, 0xc2, 0x44, 0xf5, 0xea, 0x10, 0xd9, 0x2e, 0xf6, 0x70, 0x4b, 0x34, - 0xaa, 0x25, 0x00, 0x9f, 0xf4, 0xc7, 0x57, 0xf9, 0x65, 0x8d, 0x1c, 0x04, 0x84, 0xf9, 0xea, 0x33, - 0x50, 0x4c, 0xdd, 0x32, 0x97, 0x3a, 0x8c, 0xc0, 0x07, 0x60, 0x3a, 0x02, 0x97, 0xa5, 0x05, 0xe9, - 0xda, 0xff, 0xcb, 0xaa, 0x96, 0xef, 0x5a, 0x8b, 0xb0, 0xeb, 0x33, 0x47, 0x5f, 0xe6, 0x0b, 0x1f, - 0xbe, 0x7f, 0xac, 0x48, 0x35, 0x01, 0x56, 0xab, 0x40, 0xe1, 0xec, 0x0f, 0x89, 0xbf, 0xc5, 0x88, - 0xb7, 0x61, 0x3b, 0x78, 0xad, 0xd1, 0xf0, 0x08, 0x8b, 0xe7, 0x43, 0x0d, 0x14, 0x03, 0x46, 0x3c, - 0x23, 0xda, 0x92, 0x81, 0xa3, 0x2a, 0x9f, 0x7a, 0xa6, 0x36, 0xdb, 0x2f, 0xdd, 0xe7, 0x15, 0x01, - 0x53, 0x37, 0xc0, 0x7c, 0x2e, 0xa3, 0xd0, 0x5e, 0x01, 0x1c, 0x67, 0xb4, 0x6c, 0x07, 0xff, 0x45, - 0x78, 0x36, 0x48, 0x63, 0xd4, 0xc7, 0x60, 0x21, 0x49, 0x97, 0x9a, 0x15, 0x4b, 0x1c, 0x87, 0x6f, - 0x13, 0x5c, 0x18, 0xc2, 0x27, 0x04, 0x8e, 0xeb, 0x79, 0x17, 0xa8, 0x31, 0xe9, 0x53, 0xdc, 0xb4, - 0x1b, 0xd8, 0xa7, 0x7c, 0x68, 0x35, 0x30, 0x1f, 0x91, 0x30, 0x96, 0x79, 0x1d, 0x94, 0xdb, 0x71, - 0x35, 0xa6, 0x76, 0x03, 0xd3, 0xd8, 0x27, 0xa1, 0xa0, 0x3e, 0xf7, 0xbb, 0x1e, 0xf1, 0x47, 0x78, - 0x75, 0x1b, 0x5c, 0x1c, 0x4a, 0x2f, 0x54, 0xaf, 0x80, 0xb9, 0x3f, 0xfc, 0x7c, 0x17, 0x69, 0xf6, - 0x62, 0x7b, 0x10, 0xac, 0xee, 0x80, 0x4b, 0x03, 0xdc, 0xc9, 0xe1, 0xb1, 0xf8, 0x89, 0xc8, 0x9f, - 0x83, 0xcb, 0x27, 0x90, 0x0b, 0xe9, 0x93, 0xae, 0x66, 0xf9, 0xdd, 0x0c, 0xf8, 0x8f, 0x8f, 0x80, - 0xef, 0x25, 0x30, 0x1d, 0xfd, 0xcf, 0xa1, 0x36, 0x2c, 0x0b, 0x83, 0x11, 0x93, 0xd1, 0xc8, 0xfd, - 0x91, 0x5c, 0x75, 0xf5, 0xd5, 0xa7, 0x6f, 0x6f, 0xa7, 0x96, 0xa0, 0x86, 0x1c, 0xda, 0x20, 0xfa, - 0x92, 0xbe, 0x68, 0x53, 0x14, 0x71, 0x2c, 0x0e, 0xc9, 0x39, 0xfc, 0x21, 0x01, 0x38, 0x98, 0x0b, - 0x78, 0xe3, 0xc4, 0xf9, 0xb9, 0xf1, 0x94, 0x6f, 0x4e, 0x84, 0x15, 0x3e, 0x76, 0xb8, 0x8f, 0x2d, - 0xb8, 0x39, 0xaa, 0x0f, 0x8b, 0xf8, 0xc6, 0x40, 0xd4, 0xd0, 0x61, 0x46, 0x58, 0x3a, 0xf0, 0xa7, - 0x04, 0x4a, 0x59, 0x29, 0x83, 0xb7, 0x46, 0x95, 0x9c, 0x15, 0x76, 0xf9, 0xf6, 0x84, 0xe8, 0x53, - 0x5b, 0x4e, 0xfb, 0x13, 0xa6, 0x93, 0x7b, 0xe8, 0xc0, 0x97, 0x53, 0x60, 0x2e, 0x3b, 0xa4, 0xf0, - 0xce, 0x28, 0xb2, 0xf3, 0x1f, 0x0f, 0xf9, 0xee, 0xc4, 0x78, 0x61, 0x9c, 0x70, 0xe3, 0x06, 0xdc, - 0x1d, 0xc7, 0x78, 0x76, 0xe4, 0xd1, 0x61, 0x5e, 0x58, 0x3b, 0xf0, 0xf5, 0x14, 0x28, 0xe7, 0xc5, - 0x1d, 0xde, 0x1b, 0xcb, 0x44, 0xc6, 0x33, 0x24, 0xaf, 0x9d, 0x82, 0xe1, 0xdf, 0x2c, 0x22, 0x6d, - 0x38, 0xb9, 0x8a, 0xe4, 0x8a, 0x3a, 0xeb, 0xd5, 0xa3, 0xae, 0x22, 0x1d, 0x77, 0x15, 0xe9, 0x6b, - 0x57, 0x91, 0xde, 0xf4, 0x94, 0xc2, 0x71, 0x4f, 0x29, 0x7c, 0xee, 0x29, 0x85, 0xed, 0x55, 0xcb, - 0xf6, 0xf7, 0x02, 0x53, 0xab, 0xd3, 0x56, 0xae, 0x84, 0x17, 0x29, 0x11, 0x7e, 0xe8, 0x12, 0x66, - 0x4e, 0xf3, 0xcf, 0x84, 0x95, 0x5f, 0x01, 0x00, 0x00, 0xff, 0xff, 0x7c, 0x80, 0x7a, 0xbc, 0x08, - 0x09, 0x00, 0x00, + // 647 bytes of a gzipped FileDescriptorProto + 0x1f, 0x8b, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0xff, 0xac, 0x56, 0xcf, 0x6b, 0x13, 0x41, + 0x14, 0xce, 0x16, 0x0c, 0x74, 0xf4, 0xd2, 0x69, 0x2c, 0x61, 0x91, 0xb5, 0xae, 0x3f, 0x29, 0x74, + 0xa7, 0xdb, 0x42, 0xbd, 0xf8, 0xb3, 0x22, 0x1e, 0x44, 0x88, 0xc1, 0x2a, 0xb6, 0x96, 0x38, 0x49, + 0x87, 0xed, 0xd0, 0x64, 0x67, 0xbb, 0xb3, 0x1b, 0x5c, 0x4a, 0x40, 0x3c, 0x78, 0x16, 0xfc, 0x0b, + 0xbc, 0x79, 0xd3, 0x3f, 0xa3, 0xc7, 0x82, 0x17, 0x4f, 0x22, 0x89, 0xe0, 0x7f, 0xe0, 0xc9, 0x83, + 0x64, 0x76, 0x92, 0x4c, 0x92, 0xcd, 0x36, 0x49, 0xbd, 0x94, 0x65, 0xde, 0x7b, 0xdf, 0xfb, 0xbe, + 0x8f, 0x7e, 0x8f, 0x80, 0x6b, 0x5e, 0x58, 0xe5, 0xd8, 0xaf, 0xec, 0x61, 0xea, 0xa2, 0x7d, 0x12, + 0xf9, 0xc4, 0xa1, 0x3c, 0xf0, 0x23, 0x54, 0xb7, 0xd1, 0x41, 0x48, 0xfc, 0xc8, 0xf2, 0x7c, 0x16, + 0x30, 0xa8, 0x2b, 0x7d, 0x96, 0xd2, 0x67, 0xd5, 0x6d, 0x7d, 0x0e, 0xd7, 0xa8, 0xcb, 0x90, 0xf8, + 0x1b, 0xb7, 0xeb, 0x4b, 0x15, 0xc6, 0x6b, 0x8c, 0xa3, 0x32, 0xe6, 0x24, 0xc6, 0x41, 0x75, 0xbb, + 0x4c, 0x02, 0x6c, 0x23, 0x0f, 0x3b, 0xd4, 0xc5, 0x01, 0x65, 0xae, 0xec, 0xcd, 0x39, 0xcc, 0x61, + 0xe2, 0x13, 0xb5, 0xbf, 0xe4, 0xeb, 0x05, 0x87, 0x31, 0xa7, 0x4a, 0x10, 0xf6, 0x28, 0xc2, 0xae, + 0xcb, 0x02, 0x31, 0xc2, 0x65, 0xf5, 0x7a, 0x0a, 0x6d, 0x0f, 0xfb, 0xb8, 0x26, 0x1b, 0xcd, 0x1c, + 0x80, 0x4f, 0xdb, 0xeb, 0x0b, 0xe2, 0xb1, 0x48, 0x0e, 0x42, 0xc2, 0x03, 0xf3, 0x15, 0x98, 0xef, + 0x7b, 0xe5, 0x1e, 0x73, 0x39, 0x81, 0x0f, 0x41, 0x36, 0x1e, 0xce, 0x6b, 0x8b, 0xda, 0x8d, 0xb3, + 0xab, 0xa6, 0x35, 0x5a, 0xb5, 0x15, 0xcf, 0x6e, 0xcc, 0x1e, 0xfd, 0xb8, 0x98, 0xf9, 0xfc, 0xfb, + 0xeb, 0x92, 0x56, 0x94, 0xc3, 0xe6, 0x0b, 0xb0, 0x28, 0xd0, 0x1f, 0x91, 0x60, 0x93, 0x13, 0xff, + 0x09, 0x75, 0x71, 0x21, 0x2c, 0x57, 0x69, 0xe5, 0x31, 0x89, 0x24, 0x03, 0xb8, 0x06, 0x16, 0x42, + 0x4e, 0xfc, 0x52, 0xec, 0x53, 0xc9, 0x13, 0xf5, 0xd2, 0x3e, 0x89, 0xc4, 0xea, 0x73, 0xc5, 0xf9, + 0x76, 0xf5, 0x81, 0x28, 0x76, 0x67, 0xcd, 0x67, 0xe0, 0x52, 0x0a, 0xb0, 0x14, 0x81, 0x40, 0x4e, + 0x20, 0xd7, 0xa8, 0x8b, 0x87, 0x71, 0xe7, 0xc2, 0xc1, 0x41, 0x73, 0x13, 0x98, 0x2a, 0xea, 0xc0, + 0xd2, 0x0e, 0xe1, 0x89, 0x61, 0xb7, 0xc0, 0xe5, 0x54, 0x58, 0x49, 0x77, 0x2a, 0x23, 0x76, 0x7a, + 0x94, 0x9f, 0xe3, 0x2a, 0xdd, 0xc5, 0x01, 0xeb, 0x6c, 0x57, 0x28, 0xdf, 0x04, 0xf9, 0x7a, 0xa7, + 0xaa, 0xe0, 0x2b, 0xe0, 0xe7, 0xbb, 0xf5, 0xee, 0x86, 0x01, 0xea, 0x89, 0xf0, 0x3d, 0xea, 0x3d, + 0xfc, 0x8e, 0x2f, 0x2a, 0xf5, 0xfa, 0xf0, 0xb0, 0xb9, 0x0d, 0xae, 0x0c, 0x61, 0xab, 0xcb, 0x95, + 0x7f, 0x90, 0xc9, 0xc1, 0x5f, 0x83, 0xab, 0x27, 0x80, 0x4b, 0xea, 0xd3, 0x5a, 0xb3, 0xfa, 0x65, + 0x16, 0x9c, 0x11, 0x2b, 0xe0, 0x27, 0x0d, 0x64, 0xe3, 0x0c, 0x40, 0x2b, 0x2d, 0x27, 0xc3, 0xf1, + 0xd3, 0xd1, 0xd8, 0xfd, 0x31, 0x5d, 0x73, 0xfd, 0xdd, 0xb7, 0x5f, 0x1f, 0x67, 0x56, 0xa0, 0x85, + 0x5c, 0xb6, 0x4b, 0xec, 0x15, 0x7b, 0x99, 0x32, 0x14, 0x63, 0x2c, 0xa7, 0xdc, 0x00, 0xf8, 0x47, + 0x03, 0xb9, 0xa4, 0xb0, 0xc0, 0x5b, 0x27, 0x32, 0x48, 0x09, 0xaf, 0x7e, 0x7b, 0xca, 0x69, 0xa9, + 0x06, 0x0b, 0x35, 0xdb, 0xf0, 0xe5, 0xb8, 0x6a, 0x1c, 0x12, 0x94, 0x92, 0xc2, 0x87, 0x0e, 0x93, + 0xa3, 0xd3, 0x80, 0x7f, 0x35, 0xb0, 0x90, 0x1c, 0x3c, 0x78, 0x67, 0x5c, 0xf2, 0xc9, 0x87, 0x40, + 0xbf, 0x3b, 0xf5, 0xfc, 0xa9, 0xe5, 0x0f, 0x09, 0x95, 0x06, 0x0c, 0xd8, 0xd2, 0x80, 0x6f, 0x67, + 0x84, 0xfc, 0x84, 0xf0, 0x8e, 0x27, 0x7f, 0xf4, 0x51, 0x19, 0x4f, 0x7e, 0xca, 0xd5, 0x30, 0x89, + 0x90, 0x5f, 0x82, 0x3b, 0x93, 0xc8, 0x4f, 0x3e, 0x05, 0xe8, 0x70, 0x54, 0x88, 0x1b, 0xf0, 0xfd, + 0x0c, 0xc8, 0x8f, 0x3a, 0x03, 0xf0, 0xde, 0x44, 0x22, 0x12, 0xce, 0x93, 0x7e, 0xff, 0x14, 0x08, + 0xff, 0xc7, 0x88, 0x7e, 0xc1, 0xaa, 0x15, 0xaa, 0x45, 0x8d, 0x8d, 0xc2, 0x51, 0xd3, 0xd0, 0x8e, + 0x9b, 0x86, 0xf6, 0xb3, 0x69, 0x68, 0x1f, 0x5a, 0x46, 0xe6, 0xb8, 0x65, 0x64, 0xbe, 0xb7, 0x8c, + 0xcc, 0xd6, 0xba, 0x43, 0x83, 0xbd, 0xb0, 0x6c, 0x55, 0x58, 0x6d, 0x24, 0x85, 0x37, 0x7d, 0x24, + 0x82, 0xc8, 0x23, 0xbc, 0x9c, 0x15, 0x3f, 0x2d, 0xd6, 0xfe, 0x05, 0x00, 0x00, 0xff, 0xff, 0xd2, + 0xf4, 0x46, 0xb1, 0x3c, 0x09, 0x00, 0x00, } // Reference imports to suppress errors if they are not otherwise used. @@ -552,9 +551,9 @@ type QueryClient interface { // Parameters queries the parameters of the module. Params(ctx context.Context, in *QueryParamsRequest, opts ...grpc.CallOption) (*QueryParamsResponse, error) // GetUserMinaAddress Queries a list of GetUserMinaAddress items. - GetUserMinaAddress(ctx context.Context, in *QueryGetUserMinaAddressRequest, opts ...grpc.CallOption) (*QueryGetUserMinaAddressResponse, error) + GetUserMinaPublicKey(ctx context.Context, in *QueryGetUserMinaPublicKeyRequest, opts ...grpc.CallOption) (*QueryGetUserMinaPublicKeyResponse, error) // GetUserCosmosAddress Queries a list of GetUserCosmosAddress items. - GetUserCosmosAddress(ctx context.Context, in *QueryGetUserCosmosAddressRequest, opts ...grpc.CallOption) (*QueryGetUserCosmosAddressResponse, error) + GetUserCosmosPublicKey(ctx context.Context, in *QueryGetUserCosmosPublicKeyRequest, opts ...grpc.CallOption) (*QueryGetUserCosmosPublicKeyResponse, error) // GetValidatorMinaAddress Queries a list of GetValidatorMinaAddress items. GetValidatorMinaPubKey(ctx context.Context, in *QueryGetValidatorMinaPubKeyRequest, opts ...grpc.CallOption) (*QueryGetValidatorMinaPubKeyResponse, error) // GetValidatorCosmosAddress Queries a list of GetValidatorCosmosAddress items. @@ -578,18 +577,18 @@ func (c *queryClient) Params(ctx context.Context, in *QueryParamsRequest, opts . return out, nil } -func (c *queryClient) GetUserMinaAddress(ctx context.Context, in *QueryGetUserMinaAddressRequest, opts ...grpc.CallOption) (*QueryGetUserMinaAddressResponse, error) { - out := new(QueryGetUserMinaAddressResponse) - err := c.cc.Invoke(ctx, "/pulsarchain.keyregistry.v1.Query/GetUserMinaAddress", in, out, opts...) +func (c *queryClient) GetUserMinaPublicKey(ctx context.Context, in *QueryGetUserMinaPublicKeyRequest, opts ...grpc.CallOption) (*QueryGetUserMinaPublicKeyResponse, error) { + out := new(QueryGetUserMinaPublicKeyResponse) + err := c.cc.Invoke(ctx, "/pulsarchain.keyregistry.v1.Query/GetUserMinaPublicKey", in, out, opts...) if err != nil { return nil, err } return out, nil } -func (c *queryClient) GetUserCosmosAddress(ctx context.Context, in *QueryGetUserCosmosAddressRequest, opts ...grpc.CallOption) (*QueryGetUserCosmosAddressResponse, error) { - out := new(QueryGetUserCosmosAddressResponse) - err := c.cc.Invoke(ctx, "/pulsarchain.keyregistry.v1.Query/GetUserCosmosAddress", in, out, opts...) +func (c *queryClient) GetUserCosmosPublicKey(ctx context.Context, in *QueryGetUserCosmosPublicKeyRequest, opts ...grpc.CallOption) (*QueryGetUserCosmosPublicKeyResponse, error) { + out := new(QueryGetUserCosmosPublicKeyResponse) + err := c.cc.Invoke(ctx, "/pulsarchain.keyregistry.v1.Query/GetUserCosmosPublicKey", in, out, opts...) if err != nil { return nil, err } @@ -619,9 +618,9 @@ type QueryServer interface { // Parameters queries the parameters of the module. Params(context.Context, *QueryParamsRequest) (*QueryParamsResponse, error) // GetUserMinaAddress Queries a list of GetUserMinaAddress items. - GetUserMinaAddress(context.Context, *QueryGetUserMinaAddressRequest) (*QueryGetUserMinaAddressResponse, error) + GetUserMinaPublicKey(context.Context, *QueryGetUserMinaPublicKeyRequest) (*QueryGetUserMinaPublicKeyResponse, error) // GetUserCosmosAddress Queries a list of GetUserCosmosAddress items. - GetUserCosmosAddress(context.Context, *QueryGetUserCosmosAddressRequest) (*QueryGetUserCosmosAddressResponse, error) + GetUserCosmosPublicKey(context.Context, *QueryGetUserCosmosPublicKeyRequest) (*QueryGetUserCosmosPublicKeyResponse, error) // GetValidatorMinaAddress Queries a list of GetValidatorMinaAddress items. GetValidatorMinaPubKey(context.Context, *QueryGetValidatorMinaPubKeyRequest) (*QueryGetValidatorMinaPubKeyResponse, error) // GetValidatorCosmosAddress Queries a list of GetValidatorCosmosAddress items. @@ -635,11 +634,11 @@ type UnimplementedQueryServer struct { func (*UnimplementedQueryServer) Params(ctx context.Context, req *QueryParamsRequest) (*QueryParamsResponse, error) { return nil, status.Errorf(codes.Unimplemented, "method Params not implemented") } -func (*UnimplementedQueryServer) GetUserMinaAddress(ctx context.Context, req *QueryGetUserMinaAddressRequest) (*QueryGetUserMinaAddressResponse, error) { - return nil, status.Errorf(codes.Unimplemented, "method GetUserMinaAddress not implemented") +func (*UnimplementedQueryServer) GetUserMinaPublicKey(ctx context.Context, req *QueryGetUserMinaPublicKeyRequest) (*QueryGetUserMinaPublicKeyResponse, error) { + return nil, status.Errorf(codes.Unimplemented, "method GetUserMinaPublicKey not implemented") } -func (*UnimplementedQueryServer) GetUserCosmosAddress(ctx context.Context, req *QueryGetUserCosmosAddressRequest) (*QueryGetUserCosmosAddressResponse, error) { - return nil, status.Errorf(codes.Unimplemented, "method GetUserCosmosAddress not implemented") +func (*UnimplementedQueryServer) GetUserCosmosPublicKey(ctx context.Context, req *QueryGetUserCosmosPublicKeyRequest) (*QueryGetUserCosmosPublicKeyResponse, error) { + return nil, status.Errorf(codes.Unimplemented, "method GetUserCosmosPublicKey not implemented") } func (*UnimplementedQueryServer) GetValidatorMinaPubKey(ctx context.Context, req *QueryGetValidatorMinaPubKeyRequest) (*QueryGetValidatorMinaPubKeyResponse, error) { return nil, status.Errorf(codes.Unimplemented, "method GetValidatorMinaPubKey not implemented") @@ -670,38 +669,38 @@ func _Query_Params_Handler(srv interface{}, ctx context.Context, dec func(interf return interceptor(ctx, in, info, handler) } -func _Query_GetUserMinaAddress_Handler(srv interface{}, ctx context.Context, dec func(interface{}) error, interceptor grpc.UnaryServerInterceptor) (interface{}, error) { - in := new(QueryGetUserMinaAddressRequest) +func _Query_GetUserMinaPublicKey_Handler(srv interface{}, ctx context.Context, dec func(interface{}) error, interceptor grpc.UnaryServerInterceptor) (interface{}, error) { + in := new(QueryGetUserMinaPublicKeyRequest) if err := dec(in); err != nil { return nil, err } if interceptor == nil { - return srv.(QueryServer).GetUserMinaAddress(ctx, in) + return srv.(QueryServer).GetUserMinaPublicKey(ctx, in) } info := &grpc.UnaryServerInfo{ Server: srv, - FullMethod: "/pulsarchain.keyregistry.v1.Query/GetUserMinaAddress", + FullMethod: "/pulsarchain.keyregistry.v1.Query/GetUserMinaPublicKey", } handler := func(ctx context.Context, req interface{}) (interface{}, error) { - return srv.(QueryServer).GetUserMinaAddress(ctx, req.(*QueryGetUserMinaAddressRequest)) + return srv.(QueryServer).GetUserMinaPublicKey(ctx, req.(*QueryGetUserMinaPublicKeyRequest)) } return interceptor(ctx, in, info, handler) } -func _Query_GetUserCosmosAddress_Handler(srv interface{}, ctx context.Context, dec func(interface{}) error, interceptor grpc.UnaryServerInterceptor) (interface{}, error) { - in := new(QueryGetUserCosmosAddressRequest) +func _Query_GetUserCosmosPublicKey_Handler(srv interface{}, ctx context.Context, dec func(interface{}) error, interceptor grpc.UnaryServerInterceptor) (interface{}, error) { + in := new(QueryGetUserCosmosPublicKeyRequest) if err := dec(in); err != nil { return nil, err } if interceptor == nil { - return srv.(QueryServer).GetUserCosmosAddress(ctx, in) + return srv.(QueryServer).GetUserCosmosPublicKey(ctx, in) } info := &grpc.UnaryServerInfo{ Server: srv, - FullMethod: "/pulsarchain.keyregistry.v1.Query/GetUserCosmosAddress", + FullMethod: "/pulsarchain.keyregistry.v1.Query/GetUserCosmosPublicKey", } handler := func(ctx context.Context, req interface{}) (interface{}, error) { - return srv.(QueryServer).GetUserCosmosAddress(ctx, req.(*QueryGetUserCosmosAddressRequest)) + return srv.(QueryServer).GetUserCosmosPublicKey(ctx, req.(*QueryGetUserCosmosPublicKeyRequest)) } return interceptor(ctx, in, info, handler) } @@ -752,12 +751,12 @@ var _Query_serviceDesc = grpc.ServiceDesc{ Handler: _Query_Params_Handler, }, { - MethodName: "GetUserMinaAddress", - Handler: _Query_GetUserMinaAddress_Handler, + MethodName: "GetUserMinaPublicKey", + Handler: _Query_GetUserMinaPublicKey_Handler, }, { - MethodName: "GetUserCosmosAddress", - Handler: _Query_GetUserCosmosAddress_Handler, + MethodName: "GetUserCosmosPublicKey", + Handler: _Query_GetUserCosmosPublicKey_Handler, }, { MethodName: "GetValidatorMinaPubKey", @@ -828,7 +827,7 @@ func (m *QueryParamsResponse) MarshalToSizedBuffer(dAtA []byte) (int, error) { return len(dAtA) - i, nil } -func (m *QueryGetUserMinaAddressRequest) Marshal() (dAtA []byte, err error) { +func (m *QueryGetUserMinaPublicKeyRequest) Marshal() (dAtA []byte, err error) { size := m.Size() dAtA = make([]byte, size) n, err := m.MarshalToSizedBuffer(dAtA[:size]) @@ -838,27 +837,27 @@ func (m *QueryGetUserMinaAddressRequest) Marshal() (dAtA []byte, err error) { return dAtA[:n], nil } -func (m *QueryGetUserMinaAddressRequest) MarshalTo(dAtA []byte) (int, error) { +func (m *QueryGetUserMinaPublicKeyRequest) MarshalTo(dAtA []byte) (int, error) { size := m.Size() return m.MarshalToSizedBuffer(dAtA[:size]) } -func (m *QueryGetUserMinaAddressRequest) MarshalToSizedBuffer(dAtA []byte) (int, error) { +func (m *QueryGetUserMinaPublicKeyRequest) MarshalToSizedBuffer(dAtA []byte) (int, error) { i := len(dAtA) _ = i var l int _ = l - if len(m.UserCosmosAddress) > 0 { - i -= len(m.UserCosmosAddress) - copy(dAtA[i:], m.UserCosmosAddress) - i = encodeVarintQuery(dAtA, i, uint64(len(m.UserCosmosAddress))) + if len(m.UserCosmosPublicKey) > 0 { + i -= len(m.UserCosmosPublicKey) + copy(dAtA[i:], m.UserCosmosPublicKey) + i = encodeVarintQuery(dAtA, i, uint64(len(m.UserCosmosPublicKey))) i-- dAtA[i] = 0xa } return len(dAtA) - i, nil } -func (m *QueryGetUserMinaAddressResponse) Marshal() (dAtA []byte, err error) { +func (m *QueryGetUserMinaPublicKeyResponse) Marshal() (dAtA []byte, err error) { size := m.Size() dAtA = make([]byte, size) n, err := m.MarshalToSizedBuffer(dAtA[:size]) @@ -868,27 +867,27 @@ func (m *QueryGetUserMinaAddressResponse) Marshal() (dAtA []byte, err error) { return dAtA[:n], nil } -func (m *QueryGetUserMinaAddressResponse) MarshalTo(dAtA []byte) (int, error) { +func (m *QueryGetUserMinaPublicKeyResponse) MarshalTo(dAtA []byte) (int, error) { size := m.Size() return m.MarshalToSizedBuffer(dAtA[:size]) } -func (m *QueryGetUserMinaAddressResponse) MarshalToSizedBuffer(dAtA []byte) (int, error) { +func (m *QueryGetUserMinaPublicKeyResponse) MarshalToSizedBuffer(dAtA []byte) (int, error) { i := len(dAtA) _ = i var l int _ = l - if len(m.UserMinaAddress) > 0 { - i -= len(m.UserMinaAddress) - copy(dAtA[i:], m.UserMinaAddress) - i = encodeVarintQuery(dAtA, i, uint64(len(m.UserMinaAddress))) + if len(m.UserMinaPublicKey) > 0 { + i -= len(m.UserMinaPublicKey) + copy(dAtA[i:], m.UserMinaPublicKey) + i = encodeVarintQuery(dAtA, i, uint64(len(m.UserMinaPublicKey))) i-- dAtA[i] = 0xa } return len(dAtA) - i, nil } -func (m *QueryGetUserCosmosAddressRequest) Marshal() (dAtA []byte, err error) { +func (m *QueryGetUserCosmosPublicKeyRequest) Marshal() (dAtA []byte, err error) { size := m.Size() dAtA = make([]byte, size) n, err := m.MarshalToSizedBuffer(dAtA[:size]) @@ -898,27 +897,27 @@ func (m *QueryGetUserCosmosAddressRequest) Marshal() (dAtA []byte, err error) { return dAtA[:n], nil } -func (m *QueryGetUserCosmosAddressRequest) MarshalTo(dAtA []byte) (int, error) { +func (m *QueryGetUserCosmosPublicKeyRequest) MarshalTo(dAtA []byte) (int, error) { size := m.Size() return m.MarshalToSizedBuffer(dAtA[:size]) } -func (m *QueryGetUserCosmosAddressRequest) MarshalToSizedBuffer(dAtA []byte) (int, error) { +func (m *QueryGetUserCosmosPublicKeyRequest) MarshalToSizedBuffer(dAtA []byte) (int, error) { i := len(dAtA) _ = i var l int _ = l - if len(m.UserMinaAddress) > 0 { - i -= len(m.UserMinaAddress) - copy(dAtA[i:], m.UserMinaAddress) - i = encodeVarintQuery(dAtA, i, uint64(len(m.UserMinaAddress))) + if len(m.UserMinaPublicKey) > 0 { + i -= len(m.UserMinaPublicKey) + copy(dAtA[i:], m.UserMinaPublicKey) + i = encodeVarintQuery(dAtA, i, uint64(len(m.UserMinaPublicKey))) i-- dAtA[i] = 0xa } return len(dAtA) - i, nil } -func (m *QueryGetUserCosmosAddressResponse) Marshal() (dAtA []byte, err error) { +func (m *QueryGetUserCosmosPublicKeyResponse) Marshal() (dAtA []byte, err error) { size := m.Size() dAtA = make([]byte, size) n, err := m.MarshalToSizedBuffer(dAtA[:size]) @@ -928,20 +927,20 @@ func (m *QueryGetUserCosmosAddressResponse) Marshal() (dAtA []byte, err error) { return dAtA[:n], nil } -func (m *QueryGetUserCosmosAddressResponse) MarshalTo(dAtA []byte) (int, error) { +func (m *QueryGetUserCosmosPublicKeyResponse) MarshalTo(dAtA []byte) (int, error) { size := m.Size() return m.MarshalToSizedBuffer(dAtA[:size]) } -func (m *QueryGetUserCosmosAddressResponse) MarshalToSizedBuffer(dAtA []byte) (int, error) { +func (m *QueryGetUserCosmosPublicKeyResponse) MarshalToSizedBuffer(dAtA []byte) (int, error) { i := len(dAtA) _ = i var l int _ = l - if len(m.UserCosmosAddress) > 0 { - i -= len(m.UserCosmosAddress) - copy(dAtA[i:], m.UserCosmosAddress) - i = encodeVarintQuery(dAtA, i, uint64(len(m.UserCosmosAddress))) + if len(m.UserCosmosPublicKey) > 0 { + i -= len(m.UserCosmosPublicKey) + copy(dAtA[i:], m.UserCosmosPublicKey) + i = encodeVarintQuery(dAtA, i, uint64(len(m.UserCosmosPublicKey))) i-- dAtA[i] = 0xa } @@ -1099,52 +1098,52 @@ func (m *QueryParamsResponse) Size() (n int) { return n } -func (m *QueryGetUserMinaAddressRequest) Size() (n int) { +func (m *QueryGetUserMinaPublicKeyRequest) Size() (n int) { if m == nil { return 0 } var l int _ = l - l = len(m.UserCosmosAddress) + l = len(m.UserCosmosPublicKey) if l > 0 { n += 1 + l + sovQuery(uint64(l)) } return n } -func (m *QueryGetUserMinaAddressResponse) Size() (n int) { +func (m *QueryGetUserMinaPublicKeyResponse) Size() (n int) { if m == nil { return 0 } var l int _ = l - l = len(m.UserMinaAddress) + l = len(m.UserMinaPublicKey) if l > 0 { n += 1 + l + sovQuery(uint64(l)) } return n } -func (m *QueryGetUserCosmosAddressRequest) Size() (n int) { +func (m *QueryGetUserCosmosPublicKeyRequest) Size() (n int) { if m == nil { return 0 } var l int _ = l - l = len(m.UserMinaAddress) + l = len(m.UserMinaPublicKey) if l > 0 { n += 1 + l + sovQuery(uint64(l)) } return n } -func (m *QueryGetUserCosmosAddressResponse) Size() (n int) { +func (m *QueryGetUserCosmosPublicKeyResponse) Size() (n int) { if m == nil { return 0 } var l int _ = l - l = len(m.UserCosmosAddress) + l = len(m.UserCosmosPublicKey) if l > 0 { n += 1 + l + sovQuery(uint64(l)) } @@ -1342,7 +1341,7 @@ func (m *QueryParamsResponse) Unmarshal(dAtA []byte) error { } return nil } -func (m *QueryGetUserMinaAddressRequest) Unmarshal(dAtA []byte) error { +func (m *QueryGetUserMinaPublicKeyRequest) Unmarshal(dAtA []byte) error { l := len(dAtA) iNdEx := 0 for iNdEx < l { @@ -1365,15 +1364,15 @@ func (m *QueryGetUserMinaAddressRequest) Unmarshal(dAtA []byte) error { fieldNum := int32(wire >> 3) wireType := int(wire & 0x7) if wireType == 4 { - return fmt.Errorf("proto: QueryGetUserMinaAddressRequest: wiretype end group for non-group") + return fmt.Errorf("proto: QueryGetUserMinaPublicKeyRequest: wiretype end group for non-group") } if fieldNum <= 0 { - return fmt.Errorf("proto: QueryGetUserMinaAddressRequest: illegal tag %d (wire type %d)", fieldNum, wire) + return fmt.Errorf("proto: QueryGetUserMinaPublicKeyRequest: illegal tag %d (wire type %d)", fieldNum, wire) } switch fieldNum { case 1: if wireType != 2 { - return fmt.Errorf("proto: wrong wireType = %d for field UserCosmosAddress", wireType) + return fmt.Errorf("proto: wrong wireType = %d for field UserCosmosPublicKey", wireType) } var byteLen int for shift := uint(0); ; shift += 7 { @@ -1400,9 +1399,9 @@ func (m *QueryGetUserMinaAddressRequest) Unmarshal(dAtA []byte) error { if postIndex > l { return io.ErrUnexpectedEOF } - m.UserCosmosAddress = append(m.UserCosmosAddress[:0], dAtA[iNdEx:postIndex]...) - if m.UserCosmosAddress == nil { - m.UserCosmosAddress = []byte{} + m.UserCosmosPublicKey = append(m.UserCosmosPublicKey[:0], dAtA[iNdEx:postIndex]...) + if m.UserCosmosPublicKey == nil { + m.UserCosmosPublicKey = []byte{} } iNdEx = postIndex default: @@ -1426,7 +1425,7 @@ func (m *QueryGetUserMinaAddressRequest) Unmarshal(dAtA []byte) error { } return nil } -func (m *QueryGetUserMinaAddressResponse) Unmarshal(dAtA []byte) error { +func (m *QueryGetUserMinaPublicKeyResponse) Unmarshal(dAtA []byte) error { l := len(dAtA) iNdEx := 0 for iNdEx < l { @@ -1449,15 +1448,15 @@ func (m *QueryGetUserMinaAddressResponse) Unmarshal(dAtA []byte) error { fieldNum := int32(wire >> 3) wireType := int(wire & 0x7) if wireType == 4 { - return fmt.Errorf("proto: QueryGetUserMinaAddressResponse: wiretype end group for non-group") + return fmt.Errorf("proto: QueryGetUserMinaPublicKeyResponse: wiretype end group for non-group") } if fieldNum <= 0 { - return fmt.Errorf("proto: QueryGetUserMinaAddressResponse: illegal tag %d (wire type %d)", fieldNum, wire) + return fmt.Errorf("proto: QueryGetUserMinaPublicKeyResponse: illegal tag %d (wire type %d)", fieldNum, wire) } switch fieldNum { case 1: if wireType != 2 { - return fmt.Errorf("proto: wrong wireType = %d for field UserMinaAddress", wireType) + return fmt.Errorf("proto: wrong wireType = %d for field UserMinaPublicKey", wireType) } var byteLen int for shift := uint(0); ; shift += 7 { @@ -1484,9 +1483,9 @@ func (m *QueryGetUserMinaAddressResponse) Unmarshal(dAtA []byte) error { if postIndex > l { return io.ErrUnexpectedEOF } - m.UserMinaAddress = append(m.UserMinaAddress[:0], dAtA[iNdEx:postIndex]...) - if m.UserMinaAddress == nil { - m.UserMinaAddress = []byte{} + m.UserMinaPublicKey = append(m.UserMinaPublicKey[:0], dAtA[iNdEx:postIndex]...) + if m.UserMinaPublicKey == nil { + m.UserMinaPublicKey = []byte{} } iNdEx = postIndex default: @@ -1510,7 +1509,7 @@ func (m *QueryGetUserMinaAddressResponse) Unmarshal(dAtA []byte) error { } return nil } -func (m *QueryGetUserCosmosAddressRequest) Unmarshal(dAtA []byte) error { +func (m *QueryGetUserCosmosPublicKeyRequest) Unmarshal(dAtA []byte) error { l := len(dAtA) iNdEx := 0 for iNdEx < l { @@ -1533,15 +1532,15 @@ func (m *QueryGetUserCosmosAddressRequest) Unmarshal(dAtA []byte) error { fieldNum := int32(wire >> 3) wireType := int(wire & 0x7) if wireType == 4 { - return fmt.Errorf("proto: QueryGetUserCosmosAddressRequest: wiretype end group for non-group") + return fmt.Errorf("proto: QueryGetUserCosmosPublicKeyRequest: wiretype end group for non-group") } if fieldNum <= 0 { - return fmt.Errorf("proto: QueryGetUserCosmosAddressRequest: illegal tag %d (wire type %d)", fieldNum, wire) + return fmt.Errorf("proto: QueryGetUserCosmosPublicKeyRequest: illegal tag %d (wire type %d)", fieldNum, wire) } switch fieldNum { case 1: if wireType != 2 { - return fmt.Errorf("proto: wrong wireType = %d for field UserMinaAddress", wireType) + return fmt.Errorf("proto: wrong wireType = %d for field UserMinaPublicKey", wireType) } var byteLen int for shift := uint(0); ; shift += 7 { @@ -1568,9 +1567,9 @@ func (m *QueryGetUserCosmosAddressRequest) Unmarshal(dAtA []byte) error { if postIndex > l { return io.ErrUnexpectedEOF } - m.UserMinaAddress = append(m.UserMinaAddress[:0], dAtA[iNdEx:postIndex]...) - if m.UserMinaAddress == nil { - m.UserMinaAddress = []byte{} + m.UserMinaPublicKey = append(m.UserMinaPublicKey[:0], dAtA[iNdEx:postIndex]...) + if m.UserMinaPublicKey == nil { + m.UserMinaPublicKey = []byte{} } iNdEx = postIndex default: @@ -1594,7 +1593,7 @@ func (m *QueryGetUserCosmosAddressRequest) Unmarshal(dAtA []byte) error { } return nil } -func (m *QueryGetUserCosmosAddressResponse) Unmarshal(dAtA []byte) error { +func (m *QueryGetUserCosmosPublicKeyResponse) Unmarshal(dAtA []byte) error { l := len(dAtA) iNdEx := 0 for iNdEx < l { @@ -1617,15 +1616,15 @@ func (m *QueryGetUserCosmosAddressResponse) Unmarshal(dAtA []byte) error { fieldNum := int32(wire >> 3) wireType := int(wire & 0x7) if wireType == 4 { - return fmt.Errorf("proto: QueryGetUserCosmosAddressResponse: wiretype end group for non-group") + return fmt.Errorf("proto: QueryGetUserCosmosPublicKeyResponse: wiretype end group for non-group") } if fieldNum <= 0 { - return fmt.Errorf("proto: QueryGetUserCosmosAddressResponse: illegal tag %d (wire type %d)", fieldNum, wire) + return fmt.Errorf("proto: QueryGetUserCosmosPublicKeyResponse: illegal tag %d (wire type %d)", fieldNum, wire) } switch fieldNum { case 1: if wireType != 2 { - return fmt.Errorf("proto: wrong wireType = %d for field UserCosmosAddress", wireType) + return fmt.Errorf("proto: wrong wireType = %d for field UserCosmosPublicKey", wireType) } var byteLen int for shift := uint(0); ; shift += 7 { @@ -1652,9 +1651,9 @@ func (m *QueryGetUserCosmosAddressResponse) Unmarshal(dAtA []byte) error { if postIndex > l { return io.ErrUnexpectedEOF } - m.UserCosmosAddress = append(m.UserCosmosAddress[:0], dAtA[iNdEx:postIndex]...) - if m.UserCosmosAddress == nil { - m.UserCosmosAddress = []byte{} + m.UserCosmosPublicKey = append(m.UserCosmosPublicKey[:0], dAtA[iNdEx:postIndex]...) + if m.UserCosmosPublicKey == nil { + m.UserCosmosPublicKey = []byte{} } iNdEx = postIndex default: diff --git a/x/keyregistry/types/query.pb.gw.go b/x/keyregistry/types/query.pb.gw.go index 0de870c2..cfa29756 100644 --- a/x/keyregistry/types/query.pb.gw.go +++ b/x/keyregistry/types/query.pb.gw.go @@ -51,8 +51,8 @@ func local_request_Query_Params_0(ctx context.Context, marshaler runtime.Marshal } -func request_Query_GetUserMinaAddress_0(ctx context.Context, marshaler runtime.Marshaler, client QueryClient, req *http.Request, pathParams map[string]string) (proto.Message, runtime.ServerMetadata, error) { - var protoReq QueryGetUserMinaAddressRequest +func request_Query_GetUserMinaPublicKey_0(ctx context.Context, marshaler runtime.Marshaler, client QueryClient, req *http.Request, pathParams map[string]string) (proto.Message, runtime.ServerMetadata, error) { + var protoReq QueryGetUserMinaPublicKeyRequest var metadata runtime.ServerMetadata var ( @@ -62,24 +62,24 @@ func request_Query_GetUserMinaAddress_0(ctx context.Context, marshaler runtime.M _ = err ) - val, ok = pathParams["user_cosmos_address"] + val, ok = pathParams["user_cosmos_public_key"] if !ok { - return nil, metadata, status.Errorf(codes.InvalidArgument, "missing parameter %s", "user_cosmos_address") + return nil, metadata, status.Errorf(codes.InvalidArgument, "missing parameter %s", "user_cosmos_public_key") } - protoReq.UserCosmosAddress, err = runtime.Bytes(val) + protoReq.UserCosmosPublicKey, err = runtime.Bytes(val) if err != nil { - return nil, metadata, status.Errorf(codes.InvalidArgument, "type mismatch, parameter: %s, error: %v", "user_cosmos_address", err) + return nil, metadata, status.Errorf(codes.InvalidArgument, "type mismatch, parameter: %s, error: %v", "user_cosmos_public_key", err) } - msg, err := client.GetUserMinaAddress(ctx, &protoReq, grpc.Header(&metadata.HeaderMD), grpc.Trailer(&metadata.TrailerMD)) + msg, err := client.GetUserMinaPublicKey(ctx, &protoReq, grpc.Header(&metadata.HeaderMD), grpc.Trailer(&metadata.TrailerMD)) return msg, metadata, err } -func local_request_Query_GetUserMinaAddress_0(ctx context.Context, marshaler runtime.Marshaler, server QueryServer, req *http.Request, pathParams map[string]string) (proto.Message, runtime.ServerMetadata, error) { - var protoReq QueryGetUserMinaAddressRequest +func local_request_Query_GetUserMinaPublicKey_0(ctx context.Context, marshaler runtime.Marshaler, server QueryServer, req *http.Request, pathParams map[string]string) (proto.Message, runtime.ServerMetadata, error) { + var protoReq QueryGetUserMinaPublicKeyRequest var metadata runtime.ServerMetadata var ( @@ -89,24 +89,24 @@ func local_request_Query_GetUserMinaAddress_0(ctx context.Context, marshaler run _ = err ) - val, ok = pathParams["user_cosmos_address"] + val, ok = pathParams["user_cosmos_public_key"] if !ok { - return nil, metadata, status.Errorf(codes.InvalidArgument, "missing parameter %s", "user_cosmos_address") + return nil, metadata, status.Errorf(codes.InvalidArgument, "missing parameter %s", "user_cosmos_public_key") } - protoReq.UserCosmosAddress, err = runtime.Bytes(val) + protoReq.UserCosmosPublicKey, err = runtime.Bytes(val) if err != nil { - return nil, metadata, status.Errorf(codes.InvalidArgument, "type mismatch, parameter: %s, error: %v", "user_cosmos_address", err) + return nil, metadata, status.Errorf(codes.InvalidArgument, "type mismatch, parameter: %s, error: %v", "user_cosmos_public_key", err) } - msg, err := server.GetUserMinaAddress(ctx, &protoReq) + msg, err := server.GetUserMinaPublicKey(ctx, &protoReq) return msg, metadata, err } -func request_Query_GetUserCosmosAddress_0(ctx context.Context, marshaler runtime.Marshaler, client QueryClient, req *http.Request, pathParams map[string]string) (proto.Message, runtime.ServerMetadata, error) { - var protoReq QueryGetUserCosmosAddressRequest +func request_Query_GetUserCosmosPublicKey_0(ctx context.Context, marshaler runtime.Marshaler, client QueryClient, req *http.Request, pathParams map[string]string) (proto.Message, runtime.ServerMetadata, error) { + var protoReq QueryGetUserCosmosPublicKeyRequest var metadata runtime.ServerMetadata var ( @@ -116,24 +116,24 @@ func request_Query_GetUserCosmosAddress_0(ctx context.Context, marshaler runtime _ = err ) - val, ok = pathParams["user_mina_address"] + val, ok = pathParams["user_mina_public_key"] if !ok { - return nil, metadata, status.Errorf(codes.InvalidArgument, "missing parameter %s", "user_mina_address") + return nil, metadata, status.Errorf(codes.InvalidArgument, "missing parameter %s", "user_mina_public_key") } - protoReq.UserMinaAddress, err = runtime.Bytes(val) + protoReq.UserMinaPublicKey, err = runtime.Bytes(val) if err != nil { - return nil, metadata, status.Errorf(codes.InvalidArgument, "type mismatch, parameter: %s, error: %v", "user_mina_address", err) + return nil, metadata, status.Errorf(codes.InvalidArgument, "type mismatch, parameter: %s, error: %v", "user_mina_public_key", err) } - msg, err := client.GetUserCosmosAddress(ctx, &protoReq, grpc.Header(&metadata.HeaderMD), grpc.Trailer(&metadata.TrailerMD)) + msg, err := client.GetUserCosmosPublicKey(ctx, &protoReq, grpc.Header(&metadata.HeaderMD), grpc.Trailer(&metadata.TrailerMD)) return msg, metadata, err } -func local_request_Query_GetUserCosmosAddress_0(ctx context.Context, marshaler runtime.Marshaler, server QueryServer, req *http.Request, pathParams map[string]string) (proto.Message, runtime.ServerMetadata, error) { - var protoReq QueryGetUserCosmosAddressRequest +func local_request_Query_GetUserCosmosPublicKey_0(ctx context.Context, marshaler runtime.Marshaler, server QueryServer, req *http.Request, pathParams map[string]string) (proto.Message, runtime.ServerMetadata, error) { + var protoReq QueryGetUserCosmosPublicKeyRequest var metadata runtime.ServerMetadata var ( @@ -143,18 +143,18 @@ func local_request_Query_GetUserCosmosAddress_0(ctx context.Context, marshaler r _ = err ) - val, ok = pathParams["user_mina_address"] + val, ok = pathParams["user_mina_public_key"] if !ok { - return nil, metadata, status.Errorf(codes.InvalidArgument, "missing parameter %s", "user_mina_address") + return nil, metadata, status.Errorf(codes.InvalidArgument, "missing parameter %s", "user_mina_public_key") } - protoReq.UserMinaAddress, err = runtime.Bytes(val) + protoReq.UserMinaPublicKey, err = runtime.Bytes(val) if err != nil { - return nil, metadata, status.Errorf(codes.InvalidArgument, "type mismatch, parameter: %s, error: %v", "user_mina_address", err) + return nil, metadata, status.Errorf(codes.InvalidArgument, "type mismatch, parameter: %s, error: %v", "user_mina_public_key", err) } - msg, err := server.GetUserCosmosAddress(ctx, &protoReq) + msg, err := server.GetUserCosmosPublicKey(ctx, &protoReq) return msg, metadata, err } @@ -296,7 +296,7 @@ func RegisterQueryHandlerServer(ctx context.Context, mux *runtime.ServeMux, serv }) - mux.Handle("GET", pattern_Query_GetUserMinaAddress_0, func(w http.ResponseWriter, req *http.Request, pathParams map[string]string) { + mux.Handle("GET", pattern_Query_GetUserMinaPublicKey_0, func(w http.ResponseWriter, req *http.Request, pathParams map[string]string) { ctx, cancel := context.WithCancel(req.Context()) defer cancel() var stream runtime.ServerTransportStream @@ -307,7 +307,7 @@ func RegisterQueryHandlerServer(ctx context.Context, mux *runtime.ServeMux, serv runtime.HTTPError(ctx, mux, outboundMarshaler, w, req, err) return } - resp, md, err := local_request_Query_GetUserMinaAddress_0(rctx, inboundMarshaler, server, req, pathParams) + resp, md, err := local_request_Query_GetUserMinaPublicKey_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 { @@ -315,11 +315,11 @@ func RegisterQueryHandlerServer(ctx context.Context, mux *runtime.ServeMux, serv return } - forward_Query_GetUserMinaAddress_0(ctx, mux, outboundMarshaler, w, req, resp, mux.GetForwardResponseOptions()...) + forward_Query_GetUserMinaPublicKey_0(ctx, mux, outboundMarshaler, w, req, resp, mux.GetForwardResponseOptions()...) }) - mux.Handle("GET", pattern_Query_GetUserCosmosAddress_0, func(w http.ResponseWriter, req *http.Request, pathParams map[string]string) { + mux.Handle("GET", pattern_Query_GetUserCosmosPublicKey_0, func(w http.ResponseWriter, req *http.Request, pathParams map[string]string) { ctx, cancel := context.WithCancel(req.Context()) defer cancel() var stream runtime.ServerTransportStream @@ -330,7 +330,7 @@ func RegisterQueryHandlerServer(ctx context.Context, mux *runtime.ServeMux, serv runtime.HTTPError(ctx, mux, outboundMarshaler, w, req, err) return } - resp, md, err := local_request_Query_GetUserCosmosAddress_0(rctx, inboundMarshaler, server, req, pathParams) + resp, md, err := local_request_Query_GetUserCosmosPublicKey_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 { @@ -338,7 +338,7 @@ func RegisterQueryHandlerServer(ctx context.Context, mux *runtime.ServeMux, serv return } - forward_Query_GetUserCosmosAddress_0(ctx, mux, outboundMarshaler, w, req, resp, mux.GetForwardResponseOptions()...) + forward_Query_GetUserCosmosPublicKey_0(ctx, mux, outboundMarshaler, w, req, resp, mux.GetForwardResponseOptions()...) }) @@ -449,7 +449,7 @@ func RegisterQueryHandlerClient(ctx context.Context, mux *runtime.ServeMux, clie }) - mux.Handle("GET", pattern_Query_GetUserMinaAddress_0, func(w http.ResponseWriter, req *http.Request, pathParams map[string]string) { + mux.Handle("GET", pattern_Query_GetUserMinaPublicKey_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) @@ -458,18 +458,18 @@ func RegisterQueryHandlerClient(ctx context.Context, mux *runtime.ServeMux, clie runtime.HTTPError(ctx, mux, outboundMarshaler, w, req, err) return } - resp, md, err := request_Query_GetUserMinaAddress_0(rctx, inboundMarshaler, client, req, pathParams) + resp, md, err := request_Query_GetUserMinaPublicKey_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_GetUserMinaAddress_0(ctx, mux, outboundMarshaler, w, req, resp, mux.GetForwardResponseOptions()...) + forward_Query_GetUserMinaPublicKey_0(ctx, mux, outboundMarshaler, w, req, resp, mux.GetForwardResponseOptions()...) }) - mux.Handle("GET", pattern_Query_GetUserCosmosAddress_0, func(w http.ResponseWriter, req *http.Request, pathParams map[string]string) { + mux.Handle("GET", pattern_Query_GetUserCosmosPublicKey_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) @@ -478,14 +478,14 @@ func RegisterQueryHandlerClient(ctx context.Context, mux *runtime.ServeMux, clie runtime.HTTPError(ctx, mux, outboundMarshaler, w, req, err) return } - resp, md, err := request_Query_GetUserCosmosAddress_0(rctx, inboundMarshaler, client, req, pathParams) + resp, md, err := request_Query_GetUserCosmosPublicKey_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_GetUserCosmosAddress_0(ctx, mux, outboundMarshaler, w, req, resp, mux.GetForwardResponseOptions()...) + forward_Query_GetUserCosmosPublicKey_0(ctx, mux, outboundMarshaler, w, req, resp, mux.GetForwardResponseOptions()...) }) @@ -535,9 +535,9 @@ func RegisterQueryHandlerClient(ctx context.Context, mux *runtime.ServeMux, clie var ( pattern_Query_Params_0 = runtime.MustPattern(runtime.NewPattern(1, []int{2, 0, 2, 1, 2, 2, 2, 3, 2, 4}, []string{"node101-io", "pulsar-chain", "keyregistry", "v1", "params"}, "", runtime.AssumeColonVerbOpt(false))) - pattern_Query_GetUserMinaAddress_0 = runtime.MustPattern(runtime.NewPattern(1, []int{2, 0, 2, 1, 2, 2, 2, 3, 2, 4, 1, 0, 4, 1, 5, 5}, []string{"node101-io", "pulsar-chain", "keyregistry", "v1", "get_user_mina_address", "user_cosmos_address"}, "", runtime.AssumeColonVerbOpt(false))) + pattern_Query_GetUserMinaPublicKey_0 = runtime.MustPattern(runtime.NewPattern(1, []int{2, 0, 2, 1, 2, 2, 2, 3, 2, 4, 1, 0, 4, 1, 5, 5}, []string{"node101-io", "pulsar-chain", "keyregistry", "v1", "get_user_mina_public_key", "user_cosmos_public_key"}, "", runtime.AssumeColonVerbOpt(false))) - pattern_Query_GetUserCosmosAddress_0 = runtime.MustPattern(runtime.NewPattern(1, []int{2, 0, 2, 1, 2, 2, 2, 3, 2, 4, 1, 0, 4, 1, 5, 5}, []string{"node101-io", "pulsar-chain", "keyregistry", "v1", "get_user_cosmos_address", "user_mina_address"}, "", runtime.AssumeColonVerbOpt(false))) + pattern_Query_GetUserCosmosPublicKey_0 = runtime.MustPattern(runtime.NewPattern(1, []int{2, 0, 2, 1, 2, 2, 2, 3, 2, 4, 1, 0, 4, 1, 5, 5}, []string{"node101-io", "pulsar-chain", "keyregistry", "v1", "get_user_cosmos_public_key", "user_mina_public_key"}, "", runtime.AssumeColonVerbOpt(false))) pattern_Query_GetValidatorMinaPubKey_0 = runtime.MustPattern(runtime.NewPattern(1, []int{2, 0, 2, 1, 2, 2, 2, 3, 2, 4, 1, 0, 4, 1, 5, 5}, []string{"node101-io", "pulsar-chain", "keyregistry", "v1", "get_validator_mina_pub_key", "validator_cosmos_pub_key"}, "", runtime.AssumeColonVerbOpt(false))) @@ -547,9 +547,9 @@ var ( var ( forward_Query_Params_0 = runtime.ForwardResponseMessage - forward_Query_GetUserMinaAddress_0 = runtime.ForwardResponseMessage + forward_Query_GetUserMinaPublicKey_0 = runtime.ForwardResponseMessage - forward_Query_GetUserCosmosAddress_0 = runtime.ForwardResponseMessage + forward_Query_GetUserCosmosPublicKey_0 = runtime.ForwardResponseMessage forward_Query_GetValidatorMinaPubKey_0 = runtime.ForwardResponseMessage From 27a323605920a19f1e437413254ce36528b1c7eb Mon Sep 17 00:00:00 2001 From: Yusuf Date: Sun, 19 Apr 2026 13:27:34 +0300 Subject: [PATCH 06/62] fix: update keys checks if mina key previously registered to another address --- .../keeper/msg_server_update_keys.go | 232 +++++++++++------- 1 file changed, 141 insertions(+), 91 deletions(-) diff --git a/x/keyregistry/keeper/msg_server_update_keys.go b/x/keyregistry/keeper/msg_server_update_keys.go index 3b3d65ed..007122e4 100644 --- a/x/keyregistry/keeper/msg_server_update_keys.go +++ b/x/keyregistry/keeper/msg_server_update_keys.go @@ -1,105 +1,155 @@ package keeper import ( + "bytes" "context" errorsmod "cosmossdk.io/errors" + sdk "github.com/cosmos/cosmos-sdk/types" "github.com/node101-io/pulsar-chain/x/keyregistry/types" ) func (k msgServer) UpdateKeys(ctx context.Context, msg *types.MsgUpdateKeys) (*types.MsgUpdateKeysResponse, error) { - if _, err := k.addressCodec.StringToBytes(msg.Creator); err != nil { - return nil, errorsmod.Wrap(err, "invalid authority address") - } - - if msg.ActorType == types.ActorType_USER { - - exists, err := k.UserCosmosToMinaHas(ctx, []byte(msg.Creator)) - if err != nil { - return nil, err - } - if !exists { - return nil, types.ErrUserNotRegistered - } - exists, err = k.UserMinaToCosmosHas(ctx, msg.PrevMinaPublicKey) - if err != nil { - return nil, err - } - if !exists { - return nil, types.ErrUserNotRegistered - } - - if !VerifyUserCosmosSig(string(msg.CosmosSignature), msg.NewMinaPublicKey, []byte(msg.Creator)) { - return nil, types.ErrInvalidSignature - } - - if !VerifyUserMinaSig(string(msg.NewMinaSignature), []byte(msg.Creator), msg.NewMinaPublicKey) { - return nil, types.ErrInvalidSignature - } - - err = k.userMinaToCosmos.Remove(ctx, msg.PrevMinaPublicKey) - if err != nil { - return nil, err - } - err = k.userCosmosToMina.Remove(ctx, []byte(msg.Creator)) - if err != nil { - return nil, err - } - - err = k.userCosmosToMina.Set(ctx, []byte(msg.Creator), msg.NewMinaPublicKey) - if err != nil { - return nil, err - } - err = k.userMinaToCosmos.Set(ctx, msg.NewMinaPublicKey, []byte(msg.Creator)) - if err != nil { - return nil, err - } - } - - if msg.ActorType == types.ActorType_VALIDATOR { - - exists, err := k.ValidatorCosmosToMinaHas(ctx, []byte(msg.Creator)) - if err != nil { - return nil, err - } - if !exists { - return nil, types.ErrValidatorNotRegistered - } - - exists, err = k.ValidatorMinaToCosmosHas(ctx, msg.PrevMinaPublicKey) - if err != nil { - return nil, err - } - if !exists { - return nil, types.ErrValidatorNotRegistered - } - - if !VerifyUserCosmosSig(string(msg.CosmosSignature), msg.NewMinaPublicKey, []byte(msg.Creator)) { - return nil, types.ErrInvalidSignature - } - - if !VerifyValidatorMinaSig(string(msg.NewMinaSignature), []byte(msg.Creator), msg.NewMinaPublicKey) { - return nil, types.ErrInvalidSignature - } - - err = k.validatorMinaToCosmos.Remove(ctx, msg.PrevMinaPublicKey) - if err != nil { - return nil, err - } - err = k.validatorCosmosToMina.Remove(ctx, []byte(msg.Creator)) - if err != nil { - return nil, err - } - - err = k.validatorCosmosToMina.Set(ctx, []byte(msg.Creator), msg.NewMinaPublicKey) - if err != nil { - return nil, err - } - err = k.validatorMinaToCosmos.Set(ctx, msg.NewMinaPublicKey, []byte(msg.Creator)) - if err != nil { - return nil, err - } + var err error + + switch msg.ActorType { + case types.ActorType_USER: + err = k.updateUserKeys(ctx, msg) + case types.ActorType_VALIDATOR: + err = k.updateValidatorKeys(ctx, msg) + } + if err != nil { + return nil, err } return &types.MsgUpdateKeysResponse{}, nil } + +func (k msgServer) updateUserKeys(ctx context.Context, msg *types.MsgUpdateKeys) error { + creatorAddress, err := k.addressCodec.StringToBytes(msg.Creator) + if err != nil { + return errorsmod.Wrap(types.ErrInvalidCreatorAddres, "") + } + + exists, err := k.UserMinaToCosmosHas(ctx, msg.PrevMinaPublicKey) + if err != nil { + return err + } + if !exists { + return types.ErrUserNotRegistered + } + + cosmosAddress, err := k.UserGetMinaToCosmos(ctx, msg.PrevMinaPublicKey) + if err != nil { + return err + } + if !bytes.Equal(creatorAddress, cosmosAddress) { + return errorsmod.Wrap(types.ErrInvalidSigner, "") + } + + exists, err = k.UserCosmosToMinaHas(ctx, cosmosAddress) + if err != nil { + return err + } + if !exists { + return types.ErrUserNotRegistered + } + + currentMinaAddress, err := k.UserGetCosmosToMina(ctx, cosmosAddress) + if err != nil { + return err + } + if !bytes.Equal(currentMinaAddress, msg.PrevMinaPublicKey) { + return types.ErrUserNotRegistered + } + + exists, err = k.UserMinaToCosmosHas(ctx, msg.NewMinaPublicKey) + if err != nil { + return err + } + if exists && !bytes.Equal(msg.NewMinaPublicKey, msg.PrevMinaPublicKey) { + return types.ErrUserSecondaryKeyExists + } + + if !VerifyUserCosmosSig(string(msg.CosmosSignature), msg.NewMinaPublicKey, cosmosAddress) { + return types.ErrInvalidSignature + } + if !VerifyUserMinaSig(string(msg.NewMinaSignature), cosmosAddress, msg.NewMinaPublicKey) { + return types.ErrInvalidSignature + } + + err = k.userMinaToCosmos.Remove(ctx, msg.PrevMinaPublicKey) + if err != nil { + return err + } + err = k.userCosmosToMina.Set(ctx, cosmosAddress, msg.NewMinaPublicKey) + if err != nil { + return err + } + + return k.userMinaToCosmos.Set(ctx, msg.NewMinaPublicKey, cosmosAddress) +} + +func (k msgServer) updateValidatorKeys(ctx context.Context, msg *types.MsgUpdateKeys) error { + if _, err := sdk.ConsAddressFromBech32(msg.Creator); err != nil { + return errorsmod.Wrap(types.ErrInvalidCreatorAddres, "") + } + + exists, err := k.ValidatorMinaToCosmosHas(ctx, msg.PrevMinaPublicKey) + if err != nil { + return err + } + if !exists { + return types.ErrValidatorNotRegistered + } + + cosmosPublicKey, err := k.ValidatorGetMinaToCosmos(ctx, msg.PrevMinaPublicKey) + if err != nil { + return err + } + if deriveAddressFromPubkey(cosmosPublicKey, false) != msg.Creator { + return errorsmod.Wrap(types.ErrInvalidSigner, "") + } + + exists, err = k.ValidatorCosmosToMinaHas(ctx, cosmosPublicKey) + if err != nil { + return err + } + if !exists { + return types.ErrValidatorNotRegistered + } + + currentMinaPublicKey, err := k.ValidatorGetCosmosToMina(ctx, cosmosPublicKey) + if err != nil { + return err + } + if !bytes.Equal(currentMinaPublicKey, msg.PrevMinaPublicKey) { + return types.ErrValidatorNotRegistered + } + + exists, err = k.ValidatorMinaToCosmosHas(ctx, msg.NewMinaPublicKey) + if err != nil { + return err + } + if exists && !bytes.Equal(msg.NewMinaPublicKey, msg.PrevMinaPublicKey) { + return types.ErrValidatorSecondaryKeyExists + } + + if !VerifyValidatorCosmosSig(string(msg.CosmosSignature), msg.NewMinaPublicKey, cosmosPublicKey) { + return types.ErrInvalidSignature + } + if !VerifyValidatorMinaSig(string(msg.NewMinaSignature), cosmosPublicKey, msg.NewMinaPublicKey) { + return types.ErrInvalidSignature + } + + err = k.validatorMinaToCosmos.Remove(ctx, msg.PrevMinaPublicKey) + if err != nil { + return err + } + err = k.validatorCosmosToMina.Set(ctx, cosmosPublicKey, msg.NewMinaPublicKey) + if err != nil { + return err + } + + return k.validatorMinaToCosmos.Set(ctx, msg.NewMinaPublicKey, cosmosPublicKey) +} From 603a19c19eaba6d7f73289bbca99b76dd4bf9d84 Mon Sep 17 00:00:00 2001 From: Yusuf Date: Sun, 19 Apr 2026 13:27:56 +0300 Subject: [PATCH 07/62] test: add tests for update keys --- x/keyregistry/keeper/user_update_keys_test.go | 183 ++++++++++++++++ .../keeper/validator_update_keys_test.go | 206 ++++++++++++++++++ 2 files changed, 389 insertions(+) create mode 100644 x/keyregistry/keeper/user_update_keys_test.go create mode 100644 x/keyregistry/keeper/validator_update_keys_test.go diff --git a/x/keyregistry/keeper/user_update_keys_test.go b/x/keyregistry/keeper/user_update_keys_test.go new file mode 100644 index 00000000..63fe2249 --- /dev/null +++ b/x/keyregistry/keeper/user_update_keys_test.go @@ -0,0 +1,183 @@ +package keeper_test + +import ( + "crypto/rand" + "testing" + + "github.com/cometbft/cometbft/crypto/secp256k1" + sdk "github.com/cosmos/cosmos-sdk/types" + "github.com/node101-io/mina-signer-go/keys" + "github.com/node101-io/pulsar-chain/x/keyregistry/keeper" + "github.com/node101-io/pulsar-chain/x/keyregistry/types" + "github.com/stretchr/testify/require" +) + +func generateUserAddressPair() (sdk.AccAddress, []byte, error) { + cosmosPrivKey := secp256k1.GenPrivKey() + cosmosAddr := sdk.AccAddress(cosmosPrivKey.PubKey().Address()) + + var minaSeed [32]byte + _, err := rand.Read(minaSeed[:]) + if err != nil { + return nil, nil, err + } + + minaAddress, err := keys.NewPrivateKeyFromBytes(minaSeed).ToPublicKey().ToAddress() + if err != nil { + return nil, nil, err + } + + return cosmosAddr, []byte(minaAddress), nil +} + +func registerUserKeysForUpdateTest(t *testing.T, f *fixture, ms types.MsgServer) (sdk.AccAddress, []byte) { + t.Helper() + + cosmosAddr, minaAddr, err := generateUserAddressPair() + require.NoError(t, err) + + resp, err := ms.RegisterKeys(f.ctx, &types.MsgRegisterKeys{ + Creator: cosmosAddr.String(), + CosmosSignature: mockCosmosSignature, + MinaSignature: mockMinaSignature, + CosmosAddress: cosmosAddr.Bytes(), + MinaAddress: minaAddr, + ActorType: types.ActorType_USER, + }) + require.NoError(t, err) + require.NotNil(t, resp) + + return cosmosAddr, minaAddr +} + +func TestUserUpdateKeysSuccess(t *testing.T) { + f := initFixture(t) + ms := keeper.NewMsgServerImpl(f.keeper) + + cosmosAddr, prevMinaAddr := registerUserKeysForUpdateTest(t, f, ms) + _, newMinaAddr, err := generateUserAddressPair() + require.NoError(t, err) + + resp, err := ms.UpdateKeys(f.ctx, &types.MsgUpdateKeys{ + Creator: cosmosAddr.String(), + PrevMinaPublicKey: prevMinaAddr, + NewMinaPublicKey: newMinaAddr, + CosmosSignature: []byte(mockCosmosSignature), + NewMinaSignature: []byte(mockMinaSignature), + ActorType: types.ActorType_USER, + }) + require.NoError(t, err) + require.NotNil(t, resp) + + exists, err := f.keeper.UserMinaToCosmosHas(f.ctx, prevMinaAddr) + require.NoError(t, err) + require.False(t, exists) + + exists, err = f.keeper.UserMinaToCosmosHas(f.ctx, newMinaAddr) + require.NoError(t, err) + require.True(t, exists) + + minaAddr, err := f.keeper.UserGetCosmosToMina(f.ctx, cosmosAddr.Bytes()) + require.NoError(t, err) + require.Equal(t, newMinaAddr, minaAddr) + + storedCosmosAddr, err := f.keeper.UserGetMinaToCosmos(f.ctx, newMinaAddr) + require.NoError(t, err) + require.Equal(t, cosmosAddr.Bytes(), storedCosmosAddr) +} + +func TestUserUpdateKeysNotRegistered(t *testing.T) { + f := initFixture(t) + ms := keeper.NewMsgServerImpl(f.keeper) + + cosmosAddr, prevMinaAddr, err := generateUserAddressPair() + require.NoError(t, err) + _, newMinaAddr, err := generateUserAddressPair() + require.NoError(t, err) + + _, err = ms.UpdateKeys(f.ctx, &types.MsgUpdateKeys{ + Creator: cosmosAddr.String(), + PrevMinaPublicKey: prevMinaAddr, + NewMinaPublicKey: newMinaAddr, + CosmosSignature: []byte(mockCosmosSignature), + NewMinaSignature: []byte(mockMinaSignature), + ActorType: types.ActorType_USER, + }) + require.ErrorIs(t, err, types.ErrUserNotRegistered) +} + +func TestUserUpdateKeysInvalidCreatorAddress(t *testing.T) { + f := initFixture(t) + ms := keeper.NewMsgServerImpl(f.keeper) + + _, prevMinaAddr, err := generateUserAddressPair() + require.NoError(t, err) + _, newMinaAddr, err := generateUserAddressPair() + require.NoError(t, err) + + _, err = ms.UpdateKeys(f.ctx, &types.MsgUpdateKeys{ + Creator: "creator", + PrevMinaPublicKey: prevMinaAddr, + NewMinaPublicKey: newMinaAddr, + CosmosSignature: []byte(mockCosmosSignature), + NewMinaSignature: []byte(mockMinaSignature), + ActorType: types.ActorType_USER, + }) + require.ErrorIs(t, err, types.ErrInvalidCreatorAddres) +} + +func TestUserUpdateKeysInvalidSigner(t *testing.T) { + f := initFixture(t) + ms := keeper.NewMsgServerImpl(f.keeper) + + _, prevMinaAddr := registerUserKeysForUpdateTest(t, f, ms) + secondaryAddr, newMinaAddr, err := generateUserAddressPair() + require.NoError(t, err) + + _, err = ms.UpdateKeys(f.ctx, &types.MsgUpdateKeys{ + Creator: secondaryAddr.String(), + PrevMinaPublicKey: prevMinaAddr, + NewMinaPublicKey: newMinaAddr, + CosmosSignature: []byte(mockCosmosSignature), + NewMinaSignature: []byte(mockMinaSignature), + ActorType: types.ActorType_USER, + }) + require.ErrorIs(t, err, types.ErrInvalidSigner) +} + +func TestUserUpdateKeysInvalidSignature(t *testing.T) { + f := initFixture(t) + ms := keeper.NewMsgServerImpl(f.keeper) + + cosmosAddr, prevMinaAddr := registerUserKeysForUpdateTest(t, f, ms) + _, newMinaAddr, err := generateUserAddressPair() + require.NoError(t, err) + + _, err = ms.UpdateKeys(f.ctx, &types.MsgUpdateKeys{ + Creator: cosmosAddr.String(), + PrevMinaPublicKey: prevMinaAddr, + NewMinaPublicKey: newMinaAddr, + CosmosSignature: []byte("cosmosSig"), + NewMinaSignature: []byte(mockMinaSignature), + ActorType: types.ActorType_USER, + }) + require.NoError(t, err) +} + +func TestUserUpdateKeysInsertSecondaryKeysFail(t *testing.T) { + f := initFixture(t) + ms := keeper.NewMsgServerImpl(f.keeper) + + cosmosAddr, prevMinaAddr := registerUserKeysForUpdateTest(t, f, ms) + _, newMinaAddr := registerUserKeysForUpdateTest(t, f, ms) + + _, err := ms.UpdateKeys(f.ctx, &types.MsgUpdateKeys{ + Creator: cosmosAddr.String(), + PrevMinaPublicKey: prevMinaAddr, + NewMinaPublicKey: newMinaAddr, + CosmosSignature: []byte(mockCosmosSignature), + NewMinaSignature: []byte(mockMinaSignature), + ActorType: types.ActorType_USER, + }) + require.ErrorIs(t, err, types.ErrUserSecondaryKeyExists) +} diff --git a/x/keyregistry/keeper/validator_update_keys_test.go b/x/keyregistry/keeper/validator_update_keys_test.go new file mode 100644 index 00000000..a7a062c1 --- /dev/null +++ b/x/keyregistry/keeper/validator_update_keys_test.go @@ -0,0 +1,206 @@ +package keeper_test + +import ( + "crypto/rand" + "testing" + + "github.com/cosmos/cosmos-sdk/crypto/keys/ed25519" + sdk "github.com/cosmos/cosmos-sdk/types" + "github.com/node101-io/mina-signer-go/keys" + "github.com/node101-io/pulsar-chain/x/keyregistry/keeper" + "github.com/node101-io/pulsar-chain/x/keyregistry/types" + "github.com/stretchr/testify/require" +) + +func generateValidatorKeyPair() (string, []byte, []byte, error) { + cosmosPrivKey := ed25519.GenPrivKey() + cosmosPubKey := cosmosPrivKey.PubKey() + + var minaSeed [32]byte + _, err := rand.Read(minaSeed[:]) + if err != nil { + return "", nil, nil, err + } + + minaPubKey, err := keys.NewPrivateKeyFromBytes(minaSeed).ToPublicKey().Marshal() + if err != nil { + return "", nil, nil, err + } + + return sdk.ConsAddress(cosmosPubKey.Address()).String(), cosmosPubKey.Bytes(), minaPubKey, nil +} + +func registerValidatorKeysForUpdateTest(t *testing.T, f *fixture, ms types.MsgServer) (string, []byte, []byte) { + t.Helper() + + creator, cosmosPubKey, minaPubKey, err := generateValidatorKeyPair() + require.NoError(t, err) + + resp, err := ms.RegisterKeys(f.ctx, &types.MsgRegisterKeys{ + Creator: creator, + CosmosSignature: mockCosmosSignature, + MinaSignature: mockMinaSignature, + CosmosAddress: cosmosPubKey, + MinaAddress: minaPubKey, + ActorType: types.ActorType_VALIDATOR, + }) + require.NoError(t, err) + require.NotNil(t, resp) + + return creator, cosmosPubKey, minaPubKey +} + +func TestValidatorUpdateKeysSuccess(t *testing.T) { + f := initFixture(t) + ms := keeper.NewMsgServerImpl(f.keeper) + + creator, cosmosPubKey, prevMinaPubKey := registerValidatorKeysForUpdateTest(t, f, ms) + _, _, newMinaPubKey, err := generateValidatorKeyPair() + require.NoError(t, err) + + resp, err := ms.UpdateKeys(f.ctx, &types.MsgUpdateKeys{ + Creator: creator, + PrevMinaPublicKey: prevMinaPubKey, + NewMinaPublicKey: newMinaPubKey, + CosmosSignature: []byte(mockCosmosSignature), + NewMinaSignature: []byte(mockMinaSignature), + ActorType: types.ActorType_VALIDATOR, + }) + require.NoError(t, err) + require.NotNil(t, resp) + + exists, err := f.keeper.ValidatorMinaToCosmosHas(f.ctx, prevMinaPubKey) + require.NoError(t, err) + require.False(t, exists) + + exists, err = f.keeper.ValidatorMinaToCosmosHas(f.ctx, newMinaPubKey) + require.NoError(t, err) + require.True(t, exists) + + minaPubKey, err := f.keeper.ValidatorGetCosmosToMina(f.ctx, cosmosPubKey) + require.NoError(t, err) + require.Equal(t, newMinaPubKey, minaPubKey) + + storedCosmosPubKey, err := f.keeper.ValidatorGetMinaToCosmos(f.ctx, newMinaPubKey) + require.NoError(t, err) + require.Equal(t, cosmosPubKey, storedCosmosPubKey) +} + +func TestValidatorUpdateKeysNotRegistered(t *testing.T) { + f := initFixture(t) + ms := keeper.NewMsgServerImpl(f.keeper) + + creator, _, prevMinaPubKey, err := generateValidatorKeyPair() + require.NoError(t, err) + _, _, newMinaPubKey, err := generateValidatorKeyPair() + require.NoError(t, err) + + _, err = ms.UpdateKeys(f.ctx, &types.MsgUpdateKeys{ + Creator: creator, + PrevMinaPublicKey: prevMinaPubKey, + NewMinaPublicKey: newMinaPubKey, + CosmosSignature: []byte(mockCosmosSignature), + NewMinaSignature: []byte(mockMinaSignature), + ActorType: types.ActorType_VALIDATOR, + }) + require.ErrorIs(t, err, types.ErrValidatorNotRegistered) +} + +func TestValidatorUpdateKeysMissingCosmosToMinaMapping(t *testing.T) { + f := initFixture(t) + ms := keeper.NewMsgServerImpl(f.keeper) + + creator, cosmosPubKey, prevMinaPubKey, err := generateValidatorKeyPair() + require.NoError(t, err) + _, _, newMinaPubKey, err := generateValidatorKeyPair() + require.NoError(t, err) + + err = f.keeper.ValidatorSetMinaToCosmos(f.ctx, prevMinaPubKey, cosmosPubKey) + require.NoError(t, err) + + _, err = ms.UpdateKeys(f.ctx, &types.MsgUpdateKeys{ + Creator: creator, + PrevMinaPublicKey: prevMinaPubKey, + NewMinaPublicKey: newMinaPubKey, + CosmosSignature: []byte(mockCosmosSignature), + NewMinaSignature: []byte(mockMinaSignature), + ActorType: types.ActorType_VALIDATOR, + }) + require.ErrorIs(t, err, types.ErrValidatorNotRegistered) +} + +func TestValidatorUpdateKeysInvalidCreatorAddress(t *testing.T) { + f := initFixture(t) + ms := keeper.NewMsgServerImpl(f.keeper) + + _, _, prevMinaPubKey, err := generateValidatorKeyPair() + require.NoError(t, err) + _, _, newMinaPubKey, err := generateValidatorKeyPair() + require.NoError(t, err) + + _, err = ms.UpdateKeys(f.ctx, &types.MsgUpdateKeys{ + Creator: "creator", + PrevMinaPublicKey: prevMinaPubKey, + NewMinaPublicKey: newMinaPubKey, + CosmosSignature: []byte(mockCosmosSignature), + NewMinaSignature: []byte(mockMinaSignature), + ActorType: types.ActorType_VALIDATOR, + }) + require.ErrorIs(t, err, types.ErrInvalidCreatorAddres) +} + +func TestValidatorUpdateKeysInvalidSigner(t *testing.T) { + f := initFixture(t) + ms := keeper.NewMsgServerImpl(f.keeper) + + _, _, prevMinaPubKey := registerValidatorKeysForUpdateTest(t, f, ms) + secondaryCreator, _, newMinaPubKey, err := generateValidatorKeyPair() + require.NoError(t, err) + + _, err = ms.UpdateKeys(f.ctx, &types.MsgUpdateKeys{ + Creator: secondaryCreator, + PrevMinaPublicKey: prevMinaPubKey, + NewMinaPublicKey: newMinaPubKey, + CosmosSignature: []byte(mockCosmosSignature), + NewMinaSignature: []byte(mockMinaSignature), + ActorType: types.ActorType_VALIDATOR, + }) + require.ErrorIs(t, err, types.ErrInvalidSigner) +} + +func TestValidatorUpdateKeysInvalidSignature(t *testing.T) { + f := initFixture(t) + ms := keeper.NewMsgServerImpl(f.keeper) + + creator, _, prevMinaPubKey := registerValidatorKeysForUpdateTest(t, f, ms) + _, _, newMinaPubKey, err := generateValidatorKeyPair() + require.NoError(t, err) + + _, err = ms.UpdateKeys(f.ctx, &types.MsgUpdateKeys{ + Creator: creator, + PrevMinaPublicKey: prevMinaPubKey, + NewMinaPublicKey: newMinaPubKey, + CosmosSignature: []byte("cosmosSig"), + NewMinaSignature: []byte(mockMinaSignature), + ActorType: types.ActorType_VALIDATOR, + }) + require.NoError(t, err) +} + +func TestValidatorUpdateKeysInsertSecondaryKeysFail(t *testing.T) { + f := initFixture(t) + ms := keeper.NewMsgServerImpl(f.keeper) + + creator, _, prevMinaPubKey := registerValidatorKeysForUpdateTest(t, f, ms) + _, _, newMinaPubKey := registerValidatorKeysForUpdateTest(t, f, ms) + + _, err := ms.UpdateKeys(f.ctx, &types.MsgUpdateKeys{ + Creator: creator, + PrevMinaPublicKey: prevMinaPubKey, + NewMinaPublicKey: newMinaPubKey, + CosmosSignature: []byte(mockCosmosSignature), + NewMinaSignature: []byte(mockMinaSignature), + ActorType: types.ActorType_VALIDATOR, + }) + require.ErrorIs(t, err, types.ErrValidatorSecondaryKeyExists) +} From 7028b89b0a35f4262bf0218d4ba57da9f3ec717d Mon Sep 17 00:00:00 2001 From: Yusuf Date: Mon, 20 Apr 2026 21:26:06 +0300 Subject: [PATCH 08/62] refactor: use public keys as key value in user maps, instead of addresses --- docs/static/openapi.json | 2 +- .../keyregistry/v1/address_pair.proto | 11 - .../pulsarchain/keyregistry/v1/genesis.proto | 3 +- proto/pulsarchain/keyregistry/v1/query.proto | 24 +- proto/pulsarchain/keyregistry/v1/tx.proto | 4 +- x/keyregistry/keeper/genesis.go | 18 +- x/keyregistry/keeper/genesis_test.go | 6 +- .../keeper/msg_server_register_user_keys.go | 29 +- .../msg_server_register_validator_keys.go | 18 +- .../keeper/msg_server_update_keys.go | 18 +- .../keeper/user_register_keys_test.go | 57 ++- x/keyregistry/keeper/user_update_keys_test.go | 18 +- .../keeper/validator_register_keys_test.go | 32 +- .../keeper/validator_update_keys_test.go | 4 +- x/keyregistry/module/autocli.go | 18 +- x/keyregistry/types/address_pair.pb.go | 374 ------------------ x/keyregistry/types/address_pairs.go | 35 -- x/keyregistry/types/errors.go | 5 +- x/keyregistry/types/genesis.go | 4 +- x/keyregistry/types/genesis.pb.go | 39 +- x/keyregistry/types/query.pb.go | 32 +- x/keyregistry/types/tx.pb.go | 129 +++--- 22 files changed, 228 insertions(+), 652 deletions(-) delete mode 100644 proto/pulsarchain/keyregistry/v1/address_pair.proto delete mode 100644 x/keyregistry/types/address_pair.pb.go delete mode 100644 x/keyregistry/types/address_pairs.go diff --git a/docs/static/openapi.json b/docs/static/openapi.json index 63b795a0..43799f72 100644 --- a/docs/static/openapi.json +++ b/docs/static/openapi.json @@ -1 +1 @@ -{"id":"github.com/node101-io/pulsar-chain","consumes":["application/json"],"produces":["application/json"],"swagger":"2.0","info":{"description":"Chain github.com/node101-io/pulsar-chain REST API","title":"HTTP API Console","contact":{"name":"github.com/node101-io/pulsar-chain"},"version":"version not set"},"paths":{"/node101-io/pulsar-chain/keyregistry/v1/get_user_cosmos_address/{user_mina_address}":{"get":{"tags":["Query"],"summary":"GetUserCosmosAddress Queries a list of GetUserCosmosAddress items.","operationId":"GithubComnode101IopulsarChainQuery_GetUserCosmosAddress","parameters":[{"type":"string","format":"byte","name":"user_mina_address","in":"path","required":true}],"responses":{"200":{"description":"A successful response.","schema":{"$ref":"#/definitions/pulsarchain.keyregistry.v1.QueryGetUserCosmosAddressResponse"}},"default":{"description":"An unexpected error response.","schema":{"$ref":"#/definitions/google.rpc.Status"}}}}},"/node101-io/pulsar-chain/keyregistry/v1/get_user_mina_address/{user_cosmos_address}":{"get":{"tags":["Query"],"summary":"GetUserMinaAddress Queries a list of GetUserMinaAddress items.","operationId":"GithubComnode101IopulsarChainQuery_GetUserMinaAddress","parameters":[{"type":"string","format":"byte","name":"user_cosmos_address","in":"path","required":true}],"responses":{"200":{"description":"A successful response.","schema":{"$ref":"#/definitions/pulsarchain.keyregistry.v1.QueryGetUserMinaAddressResponse"}},"default":{"description":"An unexpected error response.","schema":{"$ref":"#/definitions/google.rpc.Status"}}}}},"/node101-io/pulsar-chain/keyregistry/v1/get_validator_cosmos_pub_key/{validator_mina_pub_key}":{"get":{"tags":["Query"],"summary":"GetValidatorCosmosAddress Queries a list of GetValidatorCosmosAddress items.","operationId":"GithubComnode101IopulsarChainQuery_GetValidatorCosmosPubKey","parameters":[{"type":"string","format":"byte","name":"validator_mina_pub_key","in":"path","required":true}],"responses":{"200":{"description":"A successful response.","schema":{"$ref":"#/definitions/pulsarchain.keyregistry.v1.QueryGetValidatorCosmosPubKeyResponse"}},"default":{"description":"An unexpected error response.","schema":{"$ref":"#/definitions/google.rpc.Status"}}}}},"/node101-io/pulsar-chain/keyregistry/v1/get_validator_mina_pub_key/{validator_cosmos_pub_key}":{"get":{"tags":["Query"],"summary":"GetValidatorMinaAddress Queries a list of GetValidatorMinaAddress items.","operationId":"GithubComnode101IopulsarChainQuery_GetValidatorMinaPubKey","parameters":[{"type":"string","format":"byte","name":"validator_cosmos_pub_key","in":"path","required":true}],"responses":{"200":{"description":"A successful response.","schema":{"$ref":"#/definitions/pulsarchain.keyregistry.v1.QueryGetValidatorMinaPubKeyResponse"}},"default":{"description":"An unexpected error response.","schema":{"$ref":"#/definitions/google.rpc.Status"}}}}},"/node101-io/pulsar-chain/keyregistry/v1/params":{"get":{"tags":["Query"],"summary":"Parameters queries the parameters of the module.","operationId":"GithubComnode101IopulsarChainQuery_ParamsMixin8","responses":{"200":{"description":"A successful response.","schema":{"$ref":"#/definitions/pulsarchain.keyregistry.v1.QueryParamsResponse"}},"default":{"description":"An unexpected error response.","schema":{"$ref":"#/definitions/google.rpc.Status"}}}}},"/pulsar/pulsar/v1/params":{"get":{"tags":["Query"],"summary":"Parameters queries the parameters of the module.","operationId":"GithubComnode101IopulsarChainQuery_Params","responses":{"200":{"description":"A successful response.","schema":{"$ref":"#/definitions/pulsar.pulsar.v1.QueryParamsResponse"}},"default":{"description":"An unexpected error response.","schema":{"$ref":"#/definitions/google.rpc.Status"}}}}}},"definitions":{"google.protobuf.Any":{"type":"object","properties":{"@type":{"type":"string"}},"additionalProperties":{}},"google.rpc.Status":{"type":"object","properties":{"code":{"type":"integer","format":"int32"},"details":{"type":"array","items":{"type":"object","$ref":"#/definitions/google.protobuf.Any"}},"message":{"type":"string"}}},"pulsar.pulsar.v1.Params":{"description":"Params defines the parameters for the module.","type":"object"},"pulsar.pulsar.v1.QueryParamsResponse":{"description":"QueryParamsResponse is response type for the Query/Params RPC method.","type":"object","properties":{"params":{"description":"params holds all the parameters of this module.","$ref":"#/definitions/pulsar.pulsar.v1.Params"}}},"pulsarchain.keyregistry.v1.Params":{"description":"Params defines the parameters for the module.","type":"object"},"pulsarchain.keyregistry.v1.QueryGetUserCosmosAddressResponse":{"description":"QueryGetUserCosmosAddressResponse defines the QueryGetUserCosmosAddressResponse message.","type":"object","properties":{"user_cosmos_address":{"type":"string","format":"byte"}}},"pulsarchain.keyregistry.v1.QueryGetUserMinaAddressResponse":{"description":"QueryGetUserMinaAddressResponse defines the QueryGetUserMinaAddressResponse message.","type":"object","properties":{"user_mina_address":{"type":"string","format":"byte"}}},"pulsarchain.keyregistry.v1.QueryGetValidatorCosmosPubKeyResponse":{"description":"QueryGetValidatorCosmosAddressResponse defines the QueryGetValidatorCosmosAddressResponse message.","type":"object","properties":{"validator_cosmos_pub_key":{"type":"string","format":"byte"}}},"pulsarchain.keyregistry.v1.QueryGetValidatorMinaPubKeyResponse":{"description":"QueryGetValidatorMinaAddressResponse defines the QueryGetValidatorMinaAddressResponse message.","type":"object","properties":{"validator_mina_pub_key":{"type":"string","format":"byte"}}},"pulsarchain.keyregistry.v1.QueryParamsResponse":{"description":"QueryParamsResponse is response type for the Query/Params RPC method.","type":"object","properties":{"params":{"description":"params holds all the parameters of this module.","$ref":"#/definitions/pulsarchain.keyregistry.v1.Params"}}}},"tags":[{"name":"Query"},{"name":"Msg"}]} \ No newline at end of file +{"id":"github.com/node101-io/pulsar-chain","consumes":["application/json"],"produces":["application/json"],"swagger":"2.0","info":{"description":"Chain github.com/node101-io/pulsar-chain REST API","title":"HTTP API Console","contact":{"name":"github.com/node101-io/pulsar-chain"},"version":"version not set"},"paths":{"/node101-io/pulsar-chain/keyregistry/v1/get_user_cosmos_public_key/{user_mina_public_key}":{"get":{"tags":["Query"],"summary":"GetUserCosmosPublicKey Queries a list of GetUserCosmosPublicKey items.","operationId":"GithubComnode101IopulsarChainQuery_GetUserCosmosPublicKey","parameters":[{"type":"string","format":"byte","name":"user_mina_public_key","in":"path","required":true}],"responses":{"200":{"description":"A successful response.","schema":{"$ref":"#/definitions/pulsarchain.keyregistry.v1.QueryGetUserCosmosPublicKeyResponse"}},"default":{"description":"An unexpected error response.","schema":{"$ref":"#/definitions/google.rpc.Status"}}}}},"/node101-io/pulsar-chain/keyregistry/v1/get_user_mina_public_key/{user_cosmos_public_key}":{"get":{"tags":["Query"],"summary":"GetUserMinaPublicKey Queries a list of GetUserMinaPublicKey items.","operationId":"GithubComnode101IopulsarChainQuery_GetUserMinaPublicKey","parameters":[{"type":"string","format":"byte","name":"user_cosmos_public_key","in":"path","required":true}],"responses":{"200":{"description":"A successful response.","schema":{"$ref":"#/definitions/pulsarchain.keyregistry.v1.QueryGetUserMinaPublicKeyResponse"}},"default":{"description":"An unexpected error response.","schema":{"$ref":"#/definitions/google.rpc.Status"}}}}},"/node101-io/pulsar-chain/keyregistry/v1/get_validator_cosmos_pub_key/{validator_mina_pub_key}":{"get":{"tags":["Query"],"summary":"GetValidatorCosmosPubKey Queries a list of GetValidatorCosmosPubKey items.","operationId":"GithubComnode101IopulsarChainQuery_GetValidatorCosmosPubKey","parameters":[{"type":"string","format":"byte","name":"validator_mina_pub_key","in":"path","required":true}],"responses":{"200":{"description":"A successful response.","schema":{"$ref":"#/definitions/pulsarchain.keyregistry.v1.QueryGetValidatorCosmosPubKeyResponse"}},"default":{"description":"An unexpected error response.","schema":{"$ref":"#/definitions/google.rpc.Status"}}}}},"/node101-io/pulsar-chain/keyregistry/v1/get_validator_mina_pub_key/{validator_cosmos_pub_key}":{"get":{"tags":["Query"],"summary":"GetValidatorMinaPubKey Queries a list of GetValidatorMinaPubKey items.","operationId":"GithubComnode101IopulsarChainQuery_GetValidatorMinaPubKey","parameters":[{"type":"string","format":"byte","name":"validator_cosmos_pub_key","in":"path","required":true}],"responses":{"200":{"description":"A successful response.","schema":{"$ref":"#/definitions/pulsarchain.keyregistry.v1.QueryGetValidatorMinaPubKeyResponse"}},"default":{"description":"An unexpected error response.","schema":{"$ref":"#/definitions/google.rpc.Status"}}}}},"/node101-io/pulsar-chain/keyregistry/v1/params":{"get":{"tags":["Query"],"summary":"Parameters queries the parameters of the module.","operationId":"GithubComnode101IopulsarChainQuery_ParamsMixin8","responses":{"200":{"description":"A successful response.","schema":{"$ref":"#/definitions/pulsarchain.keyregistry.v1.QueryParamsResponse"}},"default":{"description":"An unexpected error response.","schema":{"$ref":"#/definitions/google.rpc.Status"}}}}},"/pulsar/pulsar/v1/params":{"get":{"tags":["Query"],"summary":"Parameters queries the parameters of the module.","operationId":"GithubComnode101IopulsarChainQuery_Params","responses":{"200":{"description":"A successful response.","schema":{"$ref":"#/definitions/pulsar.pulsar.v1.QueryParamsResponse"}},"default":{"description":"An unexpected error response.","schema":{"$ref":"#/definitions/google.rpc.Status"}}}}}},"definitions":{"google.protobuf.Any":{"type":"object","properties":{"@type":{"type":"string"}},"additionalProperties":{}},"google.rpc.Status":{"type":"object","properties":{"code":{"type":"integer","format":"int32"},"details":{"type":"array","items":{"type":"object","$ref":"#/definitions/google.protobuf.Any"}},"message":{"type":"string"}}},"pulsar.pulsar.v1.Params":{"description":"Params defines the parameters for the module.","type":"object"},"pulsar.pulsar.v1.QueryParamsResponse":{"description":"QueryParamsResponse is response type for the Query/Params RPC method.","type":"object","properties":{"params":{"description":"params holds all the parameters of this module.","$ref":"#/definitions/pulsar.pulsar.v1.Params"}}},"pulsarchain.keyregistry.v1.Params":{"description":"Params defines the parameters for the module.","type":"object"},"pulsarchain.keyregistry.v1.QueryGetUserCosmosPublicKeyResponse":{"description":"QueryGetUserCosmosPublicKeyResponse defines the QueryGetUserCosmosPublicKeyResponse message.","type":"object","properties":{"user_cosmos_public_key":{"type":"string","format":"byte"}}},"pulsarchain.keyregistry.v1.QueryGetUserMinaPublicKeyResponse":{"description":"QueryGetUserMinaPublicKeyResponse defines the QueryGetUserMinaPublicKeyResponse message.","type":"object","properties":{"user_mina_public_key":{"type":"string","format":"byte"}}},"pulsarchain.keyregistry.v1.QueryGetValidatorCosmosPubKeyResponse":{"description":"QueryGetValidatorCosmosPubKeyResponse defines the QueryGetValidatorCosmosPubKeyResponse message.","type":"object","properties":{"validator_cosmos_pub_key":{"type":"string","format":"byte"}}},"pulsarchain.keyregistry.v1.QueryGetValidatorMinaPubKeyResponse":{"description":"QueryGetValidatorMinaPubKeyResponse defines the QueryGetValidatorMinaPubKeyResponse message.","type":"object","properties":{"validator_mina_pub_key":{"type":"string","format":"byte"}}},"pulsarchain.keyregistry.v1.QueryParamsResponse":{"description":"QueryParamsResponse is response type for the Query/Params RPC method.","type":"object","properties":{"params":{"description":"params holds all the parameters of this module.","$ref":"#/definitions/pulsarchain.keyregistry.v1.Params"}}}},"tags":[{"name":"Query"},{"name":"Msg"}]} \ No newline at end of file diff --git a/proto/pulsarchain/keyregistry/v1/address_pair.proto b/proto/pulsarchain/keyregistry/v1/address_pair.proto deleted file mode 100644 index 6d13c957..00000000 --- a/proto/pulsarchain/keyregistry/v1/address_pair.proto +++ /dev/null @@ -1,11 +0,0 @@ -syntax = "proto3"; -package pulsarchain.keyregistry.v1; - -option go_package = "github.com/node101-io/pulsar-chain/x/keyregistry/types"; - -// KeyPair defines the KeyPair message. - -message AddressPair { - bytes mina_addr = 1; - bytes cosmos_addr = 2; -} diff --git a/proto/pulsarchain/keyregistry/v1/genesis.proto b/proto/pulsarchain/keyregistry/v1/genesis.proto index 25d1bc37..9fbe466c 100644 --- a/proto/pulsarchain/keyregistry/v1/genesis.proto +++ b/proto/pulsarchain/keyregistry/v1/genesis.proto @@ -3,7 +3,6 @@ package pulsarchain.keyregistry.v1; import "amino/amino.proto"; import "gogoproto/gogo.proto"; -import "pulsarchain/keyregistry/v1/address_pair.proto"; import "pulsarchain/keyregistry/v1/params.proto"; import "pulsarchain/keyregistry/v1/public_key_pair.proto"; @@ -16,6 +15,6 @@ message GenesisState { (gogoproto.nullable) = false, (amino.dont_omitempty) = true ]; - repeated AddressPair user_key_pairs = 2; + repeated PublicKeyPair user_key_pairs = 2; repeated PublicKeyPair validator_key_pairs = 3; } diff --git a/proto/pulsarchain/keyregistry/v1/query.proto b/proto/pulsarchain/keyregistry/v1/query.proto index 8281dfce..87c61d22 100644 --- a/proto/pulsarchain/keyregistry/v1/query.proto +++ b/proto/pulsarchain/keyregistry/v1/query.proto @@ -17,22 +17,22 @@ service Query { option (google.api.http).get = "/node101-io/pulsar-chain/keyregistry/v1/params"; } - // GetUserMinaAddress Queries a list of GetUserMinaAddress items. + // GetUserMinaPublicKey Queries a list of GetUserMinaPublicKey items. rpc GetUserMinaPublicKey(QueryGetUserMinaPublicKeyRequest) returns (QueryGetUserMinaPublicKeyResponse) { option (google.api.http).get = "/node101-io/pulsar-chain/keyregistry/v1/get_user_mina_public_key/{user_cosmos_public_key}"; } - // GetUserCosmosAddress Queries a list of GetUserCosmosAddress items. + // GetUserCosmosPublicKey Queries a list of GetUserCosmosPublicKey items. rpc GetUserCosmosPublicKey(QueryGetUserCosmosPublicKeyRequest) returns (QueryGetUserCosmosPublicKeyResponse) { option (google.api.http).get = "/node101-io/pulsar-chain/keyregistry/v1/get_user_cosmos_public_key/{user_mina_public_key}"; } - // GetValidatorMinaAddress Queries a list of GetValidatorMinaAddress items. + // GetValidatorMinaPubKey Queries a list of GetValidatorMinaPubKey items. rpc GetValidatorMinaPubKey(QueryGetValidatorMinaPubKeyRequest) returns (QueryGetValidatorMinaPubKeyResponse) { option (google.api.http).get = "/node101-io/pulsar-chain/keyregistry/v1/get_validator_mina_pub_key/{validator_cosmos_pub_key}"; } - // GetValidatorCosmosAddress Queries a list of GetValidatorCosmosAddress items. + // GetValidatorCosmosPubKey Queries a list of GetValidatorCosmosPubKey items. rpc GetValidatorCosmosPubKey(QueryGetValidatorCosmosPubKeyRequest) returns (QueryGetValidatorCosmosPubKeyResponse) { option (google.api.http).get = "/node101-io/pulsar-chain/keyregistry/v1/get_validator_cosmos_pub_key/{validator_mina_pub_key}"; } @@ -50,42 +50,42 @@ message QueryParamsResponse { ]; } -// QueryGetUserMinaAddressRequest defines the QueryGetUserMinaAddressRequest message. +// QueryGetUserMinaPublicKeyRequest defines the QueryGetUserMinaPublicKeyRequest message. message QueryGetUserMinaPublicKeyRequest { bytes user_cosmos_public_key = 1; } -// QueryGetUserMinaAddressResponse defines the QueryGetUserMinaAddressResponse message. +// QueryGetUserMinaPublicKeyResponse defines the QueryGetUserMinaPublicKeyResponse message. message QueryGetUserMinaPublicKeyResponse { bytes user_mina_public_key = 1; } -// QueryGetUserCosmosAddressRequest defines the QueryGetUserCosmosAddressRequest message. +// QueryGetUserCosmosPublicKeyRequest defines the QueryGetUserCosmosPublicKeyRequest message. message QueryGetUserCosmosPublicKeyRequest { bytes user_mina_public_key = 1; } -// QueryGetUserCosmosAddressResponse defines the QueryGetUserCosmosAddressResponse message. +// QueryGetUserCosmosPublicKeyResponse defines the QueryGetUserCosmosPublicKeyResponse message. message QueryGetUserCosmosPublicKeyResponse { bytes user_cosmos_public_key = 1; } -// QueryGetValidatorMinaAddressRequest defines the QueryGetValidatorMinaAddressRequest message. +// QueryGetValidatorMinaPubKeyRequest defines the QueryGetValidatorMinaPubKeyRequest message. message QueryGetValidatorMinaPubKeyRequest { bytes validator_cosmos_pub_key = 1; } -// QueryGetValidatorMinaAddressResponse defines the QueryGetValidatorMinaAddressResponse message. +// QueryGetValidatorMinaPubKeyResponse defines the QueryGetValidatorMinaPubKeyResponse message. message QueryGetValidatorMinaPubKeyResponse { bytes validator_mina_pub_key = 1; } -// QueryGetValidatorCosmosAddressRequest defines the QueryGetValidatorCosmosAddressRequest message. +// QueryGetValidatorCosmosPubKeyRequest defines the QueryGetValidatorCosmosPubKeyRequest message. message QueryGetValidatorCosmosPubKeyRequest { bytes validator_mina_pub_key = 1; } -// QueryGetValidatorCosmosAddressResponse defines the QueryGetValidatorCosmosAddressResponse message. +// QueryGetValidatorCosmosPubKeyResponse defines the QueryGetValidatorCosmosPubKeyResponse message. message QueryGetValidatorCosmosPubKeyResponse { bytes validator_cosmos_pub_key = 1; } diff --git a/proto/pulsarchain/keyregistry/v1/tx.proto b/proto/pulsarchain/keyregistry/v1/tx.proto index bddf70c2..3b915f5f 100644 --- a/proto/pulsarchain/keyregistry/v1/tx.proto +++ b/proto/pulsarchain/keyregistry/v1/tx.proto @@ -53,8 +53,8 @@ message MsgRegisterKeys { string creator = 1 [(cosmos_proto.scalar) = "cosmos.AddressString"]; string cosmos_signature = 2; string mina_signature = 3; - bytes cosmos_address = 4; - bytes mina_address = 5; + bytes cosmos_public_key = 4; + bytes mina_public_key = 5; ActorType actor_type = 6; } diff --git a/x/keyregistry/keeper/genesis.go b/x/keyregistry/keeper/genesis.go index a3646643..4c8cd24f 100644 --- a/x/keyregistry/keeper/genesis.go +++ b/x/keyregistry/keeper/genesis.go @@ -14,11 +14,11 @@ func (k Keeper) InitGenesis(ctx context.Context, genState types.GenesisState) er // Insert genesis key pairs. for _, keyPair := range userKeyPairs { - err := k.userCosmosToMina.Set(ctx, keyPair.CosmosAddr, keyPair.MinaAddr) + err := k.userCosmosToMina.Set(ctx, keyPair.CosmosKey, keyPair.MinaKey) if err != nil { return err } - err = k.userMinaToCosmos.Set(ctx, keyPair.MinaAddr, keyPair.CosmosAddr) + err = k.userMinaToCosmos.Set(ctx, keyPair.MinaKey, keyPair.CosmosKey) if err != nil { return err } @@ -52,7 +52,7 @@ func (k Keeper) ExportGenesis(ctx context.Context) (*types.GenesisState, error) return nil, err } - var userKeyPairs []*types.AddressPair + var userKeyPairs []*types.PublicKeyPair var userKeypairExistenceMap = make(map[string]bool) @@ -72,9 +72,9 @@ func (k Keeper) ExportGenesis(ctx context.Context) (*types.GenesisState, error) if err != nil { return genesis, err } - keyPair := &types.AddressPair{ - MinaAddr: minaKey, - CosmosAddr: cosmosKey, + keyPair := &types.PublicKeyPair{ + MinaKey: minaKey, + CosmosKey: cosmosKey, } userKeyPairs = append(userKeyPairs, keyPair) userKeypairExistenceMap[keyPair.String()] = true @@ -105,9 +105,9 @@ func (k Keeper) ExportGenesis(ctx context.Context) (*types.GenesisState, error) if err != nil { return genesis, err } - keyPair := &types.AddressPair{ - MinaAddr: minaKey, - CosmosAddr: cosmosKey, + keyPair := &types.PublicKeyPair{ + MinaKey: minaKey, + CosmosKey: cosmosKey, } if userKeypairExistenceMap[keyPair.String()] { userMinaIterator.Next() diff --git a/x/keyregistry/keeper/genesis_test.go b/x/keyregistry/keeper/genesis_test.go index dc1dfce7..41ebe39e 100644 --- a/x/keyregistry/keeper/genesis_test.go +++ b/x/keyregistry/keeper/genesis_test.go @@ -43,10 +43,10 @@ func TestInitAndExportGenesis(t *testing.T) { genesisState := types.GenesisState{ Params: types.DefaultParams(), - UserKeyPairs: []*types.AddressPair{ + UserKeyPairs: []*types.PublicKeyPair{ { - MinaAddr: minaPubKey, - CosmosAddr: cosmosPubKey.Bytes(), + MinaKey: minaPubKey, + CosmosKey: cosmosPubKey.Bytes(), }, }, ValidatorKeyPairs: []*types.PublicKeyPair{ diff --git a/x/keyregistry/keeper/msg_server_register_user_keys.go b/x/keyregistry/keeper/msg_server_register_user_keys.go index 6bef940e..b5f96976 100644 --- a/x/keyregistry/keeper/msg_server_register_user_keys.go +++ b/x/keyregistry/keeper/msg_server_register_user_keys.go @@ -5,38 +5,39 @@ import ( "context" errorsmod "cosmossdk.io/errors" + sdk "github.com/cosmos/cosmos-sdk/types" "github.com/node101-io/pulsar-chain/x/keyregistry/types" ) -// handleUserRegistration encapsulates the user registration flow where both -// sides of the mapping are addresses, not public keys. func (k msgServer) handleUserRegistration(ctx context.Context, msg *types.MsgRegisterKeys) error { creatorAddress, err := k.addressCodec.StringToBytes(msg.Creator) if err != nil { return errorsmod.Wrap(types.ErrInvalidCreatorAddres, "") } - err = types.ValidateAddressPair(types.AddressPair{ - MinaAddr: msg.MinaAddress, - CosmosAddr: msg.CosmosAddress, + err = types.ValidatePublicKeyPair(types.PublicKeyPair{ + MinaKey: msg.MinaPublicKey, + CosmosKey: msg.CosmosPublicKey, }) if err != nil { - return errorsmod.Wrap(types.ErrInvalidAddress, "address must be valid") + return errorsmod.Wrap(types.ErrInvalidPublicKey, "") } - if !bytes.Equal(creatorAddress, msg.CosmosAddress) { - return errorsmod.Wrap(types.ErrInvalidSigner, "creator does not match provided cosmos address") + cosmosAddr := sdk.AccAddress(msg.CosmosPublicKey) + + if !bytes.Equal(creatorAddress, cosmosAddr.Bytes()) { + return errorsmod.Wrap(types.ErrInvalidSigner, "") } return k.persistUserRegistration(ctx, msg) } func (k msgServer) persistUserRegistration(ctx context.Context, msg *types.MsgRegisterKeys) error { - cosmosKeyExists, err := k.Keeper.userCosmosToMina.Has(ctx, msg.CosmosAddress) + cosmosKeyExists, err := k.Keeper.userCosmosToMina.Has(ctx, msg.CosmosPublicKey) if err != nil { return err } - minaKeyExists, err := k.Keeper.userMinaToCosmos.Has(ctx, msg.MinaAddress) + minaKeyExists, err := k.Keeper.userMinaToCosmos.Has(ctx, msg.MinaPublicKey) if err != nil { return err } @@ -44,17 +45,17 @@ func (k msgServer) persistUserRegistration(ctx context.Context, msg *types.MsgRe return errorsmod.Wrap(types.ErrUserSecondaryKeyExists, "") } - minaSigValidity := VerifyUserMinaSig(msg.MinaSignature, msg.CosmosAddress, msg.MinaAddress) - cosmosSigValidity := VerifyUserCosmosSig(msg.CosmosSignature, msg.MinaAddress, msg.CosmosAddress) + minaSigValidity := VerifyUserMinaSig(msg.MinaSignature, msg.CosmosPublicKey, msg.MinaPublicKey) + cosmosSigValidity := VerifyUserCosmosSig(msg.CosmosSignature, msg.MinaPublicKey, msg.CosmosPublicKey) if !minaSigValidity || !cosmosSigValidity { return errorsmod.Wrap(types.ErrInvalidSignature, "invalid cosmos or mina signature") } - err = k.Keeper.userCosmosToMina.Set(ctx, msg.CosmosAddress, msg.MinaAddress) + err = k.Keeper.userCosmosToMina.Set(ctx, msg.CosmosPublicKey, msg.MinaPublicKey) if err != nil { return err } - err = k.Keeper.userMinaToCosmos.Set(ctx, msg.MinaAddress, msg.CosmosAddress) + err = k.Keeper.userMinaToCosmos.Set(ctx, msg.MinaPublicKey, msg.CosmosPublicKey) if err != nil { return err } diff --git a/x/keyregistry/keeper/msg_server_register_validator_keys.go b/x/keyregistry/keeper/msg_server_register_validator_keys.go index 59e3f6e1..f1346226 100644 --- a/x/keyregistry/keeper/msg_server_register_validator_keys.go +++ b/x/keyregistry/keeper/msg_server_register_validator_keys.go @@ -17,14 +17,14 @@ func (k msgServer) handleValidatorRegistration(ctx context.Context, msg *types.M } err = types.ValidatePublicKeyPair(types.PublicKeyPair{ - MinaKey: msg.MinaAddress, - CosmosKey: msg.CosmosAddress, + MinaKey: msg.MinaPublicKey, + CosmosKey: msg.CosmosPublicKey, }) if err != nil { return errorsmod.Wrap(types.ErrInvalidPublicKey, "pubkeys must be valid") } - derivedAddress := deriveAddressFromPubkey(msg.CosmosAddress, false) + derivedAddress := deriveAddressFromPubkey(msg.CosmosPublicKey, false) if derivedAddress != msg.Creator { return errorsmod.Wrap(types.ErrInvalidSigner, "creator does not match provided cosmos consensus public key") } @@ -33,11 +33,11 @@ func (k msgServer) handleValidatorRegistration(ctx context.Context, msg *types.M } func (k msgServer) persistValidatorRegistration(ctx context.Context, msg *types.MsgRegisterKeys) error { - cosmosKeyExists, err := k.Keeper.validatorCosmosToMina.Has(ctx, msg.CosmosAddress) + cosmosKeyExists, err := k.Keeper.validatorCosmosToMina.Has(ctx, msg.CosmosPublicKey) if err != nil { return err } - minaKeyExists, err := k.Keeper.validatorMinaToCosmos.Has(ctx, msg.MinaAddress) + minaKeyExists, err := k.Keeper.validatorMinaToCosmos.Has(ctx, msg.MinaPublicKey) if err != nil { return err } @@ -45,17 +45,17 @@ func (k msgServer) persistValidatorRegistration(ctx context.Context, msg *types. return errorsmod.Wrap(types.ErrValidatorSecondaryKeyExists, "") } - minaSigValidity := VerifyValidatorMinaSig(msg.MinaSignature, msg.CosmosAddress, msg.MinaAddress) - cosmosSigValidity := VerifyValidatorCosmosSig(msg.CosmosSignature, msg.MinaAddress, msg.CosmosAddress) + minaSigValidity := VerifyValidatorMinaSig(msg.MinaSignature, msg.CosmosPublicKey, msg.MinaPublicKey) + cosmosSigValidity := VerifyValidatorCosmosSig(msg.CosmosSignature, msg.MinaPublicKey, msg.CosmosPublicKey) if !minaSigValidity || !cosmosSigValidity { return errorsmod.Wrap(types.ErrInvalidSignature, "invalid cosmos or mina signature") } - err = k.Keeper.validatorCosmosToMina.Set(ctx, msg.CosmosAddress, msg.MinaAddress) + err = k.Keeper.validatorCosmosToMina.Set(ctx, msg.CosmosPublicKey, msg.MinaPublicKey) if err != nil { return err } - err = k.Keeper.validatorMinaToCosmos.Set(ctx, msg.MinaAddress, msg.CosmosAddress) + err = k.Keeper.validatorMinaToCosmos.Set(ctx, msg.MinaPublicKey, msg.CosmosPublicKey) if err != nil { return err } diff --git a/x/keyregistry/keeper/msg_server_update_keys.go b/x/keyregistry/keeper/msg_server_update_keys.go index 007122e4..5a547d9c 100644 --- a/x/keyregistry/keeper/msg_server_update_keys.go +++ b/x/keyregistry/keeper/msg_server_update_keys.go @@ -39,15 +39,15 @@ func (k msgServer) updateUserKeys(ctx context.Context, msg *types.MsgUpdateKeys) return types.ErrUserNotRegistered } - cosmosAddress, err := k.UserGetMinaToCosmos(ctx, msg.PrevMinaPublicKey) + cosmosPublicKey, err := k.UserGetMinaToCosmos(ctx, msg.PrevMinaPublicKey) if err != nil { return err } - if !bytes.Equal(creatorAddress, cosmosAddress) { + if !bytes.Equal(creatorAddress, cosmosPublicKey) { return errorsmod.Wrap(types.ErrInvalidSigner, "") } - exists, err = k.UserCosmosToMinaHas(ctx, cosmosAddress) + exists, err = k.UserCosmosToMinaHas(ctx, cosmosPublicKey) if err != nil { return err } @@ -55,11 +55,11 @@ func (k msgServer) updateUserKeys(ctx context.Context, msg *types.MsgUpdateKeys) return types.ErrUserNotRegistered } - currentMinaAddress, err := k.UserGetCosmosToMina(ctx, cosmosAddress) + currentMinaPublicKey, err := k.UserGetCosmosToMina(ctx, cosmosPublicKey) if err != nil { return err } - if !bytes.Equal(currentMinaAddress, msg.PrevMinaPublicKey) { + if !bytes.Equal(currentMinaPublicKey, msg.PrevMinaPublicKey) { return types.ErrUserNotRegistered } @@ -71,10 +71,10 @@ func (k msgServer) updateUserKeys(ctx context.Context, msg *types.MsgUpdateKeys) return types.ErrUserSecondaryKeyExists } - if !VerifyUserCosmosSig(string(msg.CosmosSignature), msg.NewMinaPublicKey, cosmosAddress) { + if !VerifyUserCosmosSig(string(msg.CosmosSignature), msg.NewMinaPublicKey, cosmosPublicKey) { return types.ErrInvalidSignature } - if !VerifyUserMinaSig(string(msg.NewMinaSignature), cosmosAddress, msg.NewMinaPublicKey) { + if !VerifyUserMinaSig(string(msg.NewMinaSignature), cosmosPublicKey, msg.NewMinaPublicKey) { return types.ErrInvalidSignature } @@ -82,12 +82,12 @@ func (k msgServer) updateUserKeys(ctx context.Context, msg *types.MsgUpdateKeys) if err != nil { return err } - err = k.userCosmosToMina.Set(ctx, cosmosAddress, msg.NewMinaPublicKey) + err = k.userCosmosToMina.Set(ctx, cosmosPublicKey, msg.NewMinaPublicKey) if err != nil { return err } - return k.userMinaToCosmos.Set(ctx, msg.NewMinaPublicKey, cosmosAddress) + return k.userMinaToCosmos.Set(ctx, msg.NewMinaPublicKey, cosmosPublicKey) } func (k msgServer) updateValidatorKeys(ctx context.Context, msg *types.MsgUpdateKeys) error { diff --git a/x/keyregistry/keeper/user_register_keys_test.go b/x/keyregistry/keeper/user_register_keys_test.go index 298956ac..ebe6c7e7 100644 --- a/x/keyregistry/keeper/user_register_keys_test.go +++ b/x/keyregistry/keeper/user_register_keys_test.go @@ -1,9 +1,9 @@ package keeper_test import ( + "crypto/rand" "testing" - "github.com/cometbft/cometbft/crypto/secp256k1" sdk "github.com/cosmos/cosmos-sdk/types" "github.com/node101-io/mina-signer-go/keys" "github.com/node101-io/pulsar-chain/x/keyregistry/keeper" @@ -19,21 +19,21 @@ var mockMinaSignature = "minaSig" var MinaPriv = []byte("7olA5Knafb5E2hJoWFzD+oamtyXIXXUZmYG9+pBMjTGIjqZTVLNGbE7DQ3Zq5YL5NMW31UMMMGgNCeEk+gyzRA==") func generateAddress() (sdk.AccAddress, []byte, error) { - cosmosPrivKey := secp256k1.GenPrivKey() - - cosmosPubKey := cosmosPrivKey.PubKey() - - cosmosAddr := sdk.AccAddress(cosmosPubKey.Address()) + cosmosAddr := make(sdk.AccAddress, 32) + _, err := rand.Read(cosmosAddr) + if err != nil { + return nil, nil, err + } minaPrivKey := keys.NewPrivateKeyFromBytes([32]byte(MinaPriv)) - minaAddress, err := minaPrivKey.ToPublicKey().ToAddress() + minaPublicKey, err := minaPrivKey.ToPublicKey().Marshal() - return cosmosAddr, []byte(minaAddress), err + return cosmosAddr, minaPublicKey, err } // TestUserRegisterKeysFail verifies that RegisterKeys fails with ErrInvalidPublicKey -// when the provided cosmos public key is not a valid compressed secp256k1 key (33 bytes). +// when the provided key material does not satisfy the current user registration checks. func TestUserRegisterKeysFail(t *testing.T) { f := initFixture(t) @@ -44,11 +44,11 @@ func TestUserRegisterKeysFail(t *testing.T) { Creator: creatorAddr.String(), CosmosSignature: mockCosmosSignature, MinaSignature: mockMinaSignature, - CosmosAddress: CosmosPubKey, - MinaAddress: MinaPubKey, + CosmosPublicKey: CosmosPubKey, + MinaPublicKey: MinaPubKey, ActorType: types.ActorType_USER, }) - require.ErrorIs(t, err, types.ErrInvalidAddress) + require.ErrorIs(t, err, types.ErrInvalidPublicKey) } // TestUserRegisterKeysSuccess verifies that RegisterKeys succeeds with valid inputs @@ -65,8 +65,8 @@ func TestUserRegisterKeysSuccess(t *testing.T) { Creator: cosmosAddr.String(), CosmosSignature: mockCosmosSignature, MinaSignature: mockMinaSignature, - CosmosAddress: cosmosAddr.Bytes(), - MinaAddress: minaAddr, + CosmosPublicKey: cosmosAddr.Bytes(), + MinaPublicKey: minaAddr, ActorType: types.ActorType_USER, }) require.NoError(t, err) @@ -96,25 +96,22 @@ func TestUserInvalidCreatorAddress(t *testing.T) { Creator: "creator", CosmosSignature: mockCosmosSignature, MinaSignature: mockMinaSignature, - CosmosAddress: cosmosAddr.Bytes(), - MinaAddress: minaAddr, + CosmosPublicKey: cosmosAddr.Bytes(), + MinaPublicKey: minaAddr, ActorType: types.ActorType_USER, }) require.ErrorIs(t, err, types.ErrInvalidCreatorAddres) } // TestUserInvalidSigner verifies that RegisterKeys fails with ErrInvalidSigner -// when the creator address does not match the address derived from the provided cosmos public key. +// when the creator address bytes do not match the provided Cosmos-side value. func TestUserInvalidSigner(t *testing.T) { cosmosAddr, minaAddr, err := generateAddress() require.NoError(t, err) - secondaryPriv := secp256k1.GenPrivKey() - - secondaryPublic := secondaryPriv.PubKey() - - addr := sdk.AccAddress(secondaryPublic.Address()) + addr, _, err := generateAddress() + require.NoError(t, err) f := initFixture(t) ms := keeper.NewMsgServerImpl(f.keeper) @@ -123,8 +120,8 @@ func TestUserInvalidSigner(t *testing.T) { Creator: addr.String(), CosmosSignature: mockCosmosSignature, MinaSignature: mockMinaSignature, - CosmosAddress: cosmosAddr.Bytes(), - MinaAddress: minaAddr, + CosmosPublicKey: cosmosAddr.Bytes(), + MinaPublicKey: minaAddr, ActorType: types.ActorType_USER, }) @@ -149,8 +146,8 @@ func TestUserInvalidSignature(t *testing.T) { Creator: cosmosAddr.String(), CosmosSignature: invalidSig, MinaSignature: mockMinaSignature, - CosmosAddress: cosmosAddr.Bytes(), - MinaAddress: minaAddr, + CosmosPublicKey: cosmosAddr.Bytes(), + MinaPublicKey: minaAddr, ActorType: types.ActorType_USER, }) @@ -173,8 +170,8 @@ func TestUserInsertSecondaryKeysFail(t *testing.T) { Creator: cosmosAddr.String(), CosmosSignature: mockCosmosSignature, MinaSignature: mockMinaSignature, - CosmosAddress: cosmosAddr.Bytes(), - MinaAddress: minaAddr, + CosmosPublicKey: cosmosAddr.Bytes(), + MinaPublicKey: minaAddr, ActorType: types.ActorType_USER, }) require.NoError(t, err) @@ -185,8 +182,8 @@ func TestUserInsertSecondaryKeysFail(t *testing.T) { Creator: cosmosAddr.String(), CosmosSignature: mockCosmosSignature, MinaSignature: mockMinaSignature, - CosmosAddress: cosmosAddr.Bytes(), - MinaAddress: minaAddr, + CosmosPublicKey: cosmosAddr.Bytes(), + MinaPublicKey: minaAddr, ActorType: types.ActorType_USER, }) diff --git a/x/keyregistry/keeper/user_update_keys_test.go b/x/keyregistry/keeper/user_update_keys_test.go index 63fe2249..cbb39d6f 100644 --- a/x/keyregistry/keeper/user_update_keys_test.go +++ b/x/keyregistry/keeper/user_update_keys_test.go @@ -4,7 +4,6 @@ import ( "crypto/rand" "testing" - "github.com/cometbft/cometbft/crypto/secp256k1" sdk "github.com/cosmos/cosmos-sdk/types" "github.com/node101-io/mina-signer-go/keys" "github.com/node101-io/pulsar-chain/x/keyregistry/keeper" @@ -13,21 +12,24 @@ import ( ) func generateUserAddressPair() (sdk.AccAddress, []byte, error) { - cosmosPrivKey := secp256k1.GenPrivKey() - cosmosAddr := sdk.AccAddress(cosmosPrivKey.PubKey().Address()) + cosmosAddr := make(sdk.AccAddress, 32) + _, err := rand.Read(cosmosAddr) + if err != nil { + return nil, nil, err + } var minaSeed [32]byte - _, err := rand.Read(minaSeed[:]) + _, err = rand.Read(minaSeed[:]) if err != nil { return nil, nil, err } - minaAddress, err := keys.NewPrivateKeyFromBytes(minaSeed).ToPublicKey().ToAddress() + minaPublicKey, err := keys.NewPrivateKeyFromBytes(minaSeed).ToPublicKey().Marshal() if err != nil { return nil, nil, err } - return cosmosAddr, []byte(minaAddress), nil + return cosmosAddr, minaPublicKey, nil } func registerUserKeysForUpdateTest(t *testing.T, f *fixture, ms types.MsgServer) (sdk.AccAddress, []byte) { @@ -40,8 +42,8 @@ func registerUserKeysForUpdateTest(t *testing.T, f *fixture, ms types.MsgServer) Creator: cosmosAddr.String(), CosmosSignature: mockCosmosSignature, MinaSignature: mockMinaSignature, - CosmosAddress: cosmosAddr.Bytes(), - MinaAddress: minaAddr, + CosmosPublicKey: cosmosAddr.Bytes(), + MinaPublicKey: minaAddr, ActorType: types.ActorType_USER, }) require.NoError(t, err) diff --git a/x/keyregistry/keeper/validator_register_keys_test.go b/x/keyregistry/keeper/validator_register_keys_test.go index f475a0c8..09f2fc33 100644 --- a/x/keyregistry/keeper/validator_register_keys_test.go +++ b/x/keyregistry/keeper/validator_register_keys_test.go @@ -19,9 +19,9 @@ func generateValidatorPublicKeys() (cryptotypes.PubKey, []byte, error) { minaPrivKey := keys.NewPrivateKeyFromBytes([32]byte(MinaPriv)) - minaAddress, err := minaPrivKey.ToPublicKey().Marshal() + MinaPublicKey, err := minaPrivKey.ToPublicKey().Marshal() - return cosmosPubKey, minaAddress, err + return cosmosPubKey, MinaPublicKey, err } // TestValidatorRegisterKeysFail verifies that RegisterKeys fails with ErrInvalidPublicKey @@ -36,8 +36,8 @@ func TestValidatorRegisterKeysFail(t *testing.T) { Creator: creatorAddr.String(), CosmosSignature: mockCosmosSignature, MinaSignature: mockMinaSignature, - CosmosAddress: CosmosPubKey, - MinaAddress: MinaPubKey, + CosmosPublicKey: CosmosPubKey, + MinaPublicKey: MinaPubKey, ActorType: types.ActorType_VALIDATOR, }) require.ErrorIs(t, err, types.ErrInvalidPublicKey) @@ -59,8 +59,8 @@ func TestValidatorRegisterKeysSuccess(t *testing.T) { Creator: addr.String(), CosmosSignature: mockCosmosSignature, MinaSignature: mockMinaSignature, - CosmosAddress: cosmosPubKey.Bytes(), - MinaAddress: minaPubKey, + CosmosPublicKey: cosmosPubKey.Bytes(), + MinaPublicKey: minaPubKey, ActorType: types.ActorType_VALIDATOR, }) require.NoError(t, err) @@ -89,8 +89,8 @@ func TestValidatorInvalidCreatorAddress(t *testing.T) { Creator: "creator", CosmosSignature: mockCosmosSignature, MinaSignature: mockMinaSignature, - CosmosAddress: cosmosPubKey.Bytes(), - MinaAddress: minaPubKey, + CosmosPublicKey: cosmosPubKey.Bytes(), + MinaPublicKey: minaPubKey, ActorType: types.ActorType_VALIDATOR, }) require.ErrorIs(t, err, types.ErrInvalidCreatorAddres) @@ -116,8 +116,8 @@ func TestValidatorInvalidSigner(t *testing.T) { Creator: addr.String(), CosmosSignature: mockCosmosSignature, MinaSignature: mockMinaSignature, - CosmosAddress: cosmosPubKey.Bytes(), - MinaAddress: minaPubKey, + CosmosPublicKey: cosmosPubKey.Bytes(), + MinaPublicKey: minaPubKey, ActorType: types.ActorType_VALIDATOR, }) @@ -142,8 +142,8 @@ func TestValidatorInvalidSignature(t *testing.T) { Creator: addr.String(), CosmosSignature: invalidSig, MinaSignature: mockMinaSignature, - CosmosAddress: cosmosPubKey.Bytes(), - MinaAddress: minaPubKey, + CosmosPublicKey: cosmosPubKey.Bytes(), + MinaPublicKey: minaPubKey, ActorType: types.ActorType_VALIDATOR, }) @@ -168,8 +168,8 @@ func TestValidatorInsertSecondaryKeysFail(t *testing.T) { Creator: addr.String(), CosmosSignature: mockCosmosSignature, MinaSignature: mockMinaSignature, - CosmosAddress: cosmosPubKey.Bytes(), - MinaAddress: minaPubKey, + CosmosPublicKey: cosmosPubKey.Bytes(), + MinaPublicKey: minaPubKey, ActorType: types.ActorType_VALIDATOR, }) require.NoError(t, err) @@ -180,8 +180,8 @@ func TestValidatorInsertSecondaryKeysFail(t *testing.T) { Creator: addr.String(), CosmosSignature: mockCosmosSignature, MinaSignature: mockMinaSignature, - CosmosAddress: cosmosPubKey.Bytes(), - MinaAddress: minaPubKey, + CosmosPublicKey: cosmosPubKey.Bytes(), + MinaPublicKey: minaPubKey, ActorType: types.ActorType_VALIDATOR, }) diff --git a/x/keyregistry/keeper/validator_update_keys_test.go b/x/keyregistry/keeper/validator_update_keys_test.go index a7a062c1..f5233c3f 100644 --- a/x/keyregistry/keeper/validator_update_keys_test.go +++ b/x/keyregistry/keeper/validator_update_keys_test.go @@ -40,8 +40,8 @@ func registerValidatorKeysForUpdateTest(t *testing.T, f *fixture, ms types.MsgSe Creator: creator, CosmosSignature: mockCosmosSignature, MinaSignature: mockMinaSignature, - CosmosAddress: cosmosPubKey, - MinaAddress: minaPubKey, + CosmosPublicKey: cosmosPubKey, + MinaPublicKey: minaPubKey, ActorType: types.ActorType_VALIDATOR, }) require.NoError(t, err) diff --git a/x/keyregistry/module/autocli.go b/x/keyregistry/module/autocli.go index c74331e3..8b8c8bbb 100644 --- a/x/keyregistry/module/autocli.go +++ b/x/keyregistry/module/autocli.go @@ -18,17 +18,17 @@ func (am AppModule) AutoCLIOptions() *autocliv1.ModuleOptions { Short: "Shows the parameters of the module", }, { - RpcMethod: "GetUserMinaAddress", - Use: "get-user-mina-address [user-cosmos-address]", - Short: "Query GetUserMinaAddress", - PositionalArgs: []*autocliv1.PositionalArgDescriptor{{ProtoField: "user_cosmos_address", Varargs: true}}, + RpcMethod: "GetUserMinaPublicKey", + Use: "get-user-mina-public-key [user-cosmos-public-key]", + Short: "Query GetUserMinaPublicKey", + PositionalArgs: []*autocliv1.PositionalArgDescriptor{{ProtoField: "user_cosmos_public_key", Varargs: true}}, }, { - RpcMethod: "GetUserCosmosAddress", - Use: "get-user-cosmos-address [user-mina-address]", - Short: "Query GetUserCosmosAddress", - PositionalArgs: []*autocliv1.PositionalArgDescriptor{{ProtoField: "user_mina_address", Varargs: true}}, + RpcMethod: "GetUserCosmosPublicKey", + Use: "get-user-cosmos-public-key [user-mina-public-key]", + Short: "Query GetUserCosmosPublicKey", + PositionalArgs: []*autocliv1.PositionalArgDescriptor{{ProtoField: "user_mina_public_key", Varargs: true}}, }, { @@ -60,7 +60,7 @@ func (am AppModule) AutoCLIOptions() *autocliv1.ModuleOptions { RpcMethod: "RegisterKeys", Use: "register-keys [cosmos-signature] [mina-signature] [cosmos-public-key] [mina-public-key]", Short: "Send a registerKeys tx", - PositionalArgs: []*autocliv1.PositionalArgDescriptor{{ProtoField: "cosmos_signature"}, {ProtoField: "mina_signature"}, {ProtoField: "cosmos_address"}, {ProtoField: "mina_address", Varargs: true}}, + PositionalArgs: []*autocliv1.PositionalArgDescriptor{{ProtoField: "cosmos_signature"}, {ProtoField: "mina_signature"}, {ProtoField: "cosmos_public_key"}, {ProtoField: "mina_public_key", Varargs: true}}, }, { RpcMethod: "UpdateKeys", diff --git a/x/keyregistry/types/address_pair.pb.go b/x/keyregistry/types/address_pair.pb.go deleted file mode 100644 index 3f5b82ab..00000000 --- a/x/keyregistry/types/address_pair.pb.go +++ /dev/null @@ -1,374 +0,0 @@ -// Code generated by protoc-gen-gogo. DO NOT EDIT. -// source: pulsarchain/keyregistry/v1/address_pair.proto - -package types - -import ( - fmt "fmt" - proto "github.com/cosmos/gogoproto/proto" - io "io" - math "math" - math_bits "math/bits" -) - -// Reference imports to suppress errors if they are not otherwise used. -var _ = proto.Marshal -var _ = fmt.Errorf -var _ = math.Inf - -// This is a compile-time assertion to ensure that this generated file -// is compatible with the proto package it is being compiled against. -// A compilation error at this line likely means your copy of the -// proto package needs to be updated. -const _ = proto.GoGoProtoPackageIsVersion3 // please upgrade the proto package - -type AddressPair struct { - MinaAddr []byte `protobuf:"bytes,1,opt,name=mina_addr,json=minaAddr,proto3" json:"mina_addr,omitempty"` - CosmosAddr []byte `protobuf:"bytes,2,opt,name=cosmos_addr,json=cosmosAddr,proto3" json:"cosmos_addr,omitempty"` -} - -func (m *AddressPair) Reset() { *m = AddressPair{} } -func (m *AddressPair) String() string { return proto.CompactTextString(m) } -func (*AddressPair) ProtoMessage() {} -func (*AddressPair) Descriptor() ([]byte, []int) { - return fileDescriptor_eb9cea5d1b988cd3, []int{0} -} -func (m *AddressPair) XXX_Unmarshal(b []byte) error { - return m.Unmarshal(b) -} -func (m *AddressPair) XXX_Marshal(b []byte, deterministic bool) ([]byte, error) { - if deterministic { - return xxx_messageInfo_AddressPair.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 *AddressPair) XXX_Merge(src proto.Message) { - xxx_messageInfo_AddressPair.Merge(m, src) -} -func (m *AddressPair) XXX_Size() int { - return m.Size() -} -func (m *AddressPair) XXX_DiscardUnknown() { - xxx_messageInfo_AddressPair.DiscardUnknown(m) -} - -var xxx_messageInfo_AddressPair proto.InternalMessageInfo - -func (m *AddressPair) GetMinaAddr() []byte { - if m != nil { - return m.MinaAddr - } - return nil -} - -func (m *AddressPair) GetCosmosAddr() []byte { - if m != nil { - return m.CosmosAddr - } - return nil -} - -func init() { - proto.RegisterType((*AddressPair)(nil), "pulsarchain.keyregistry.v1.AddressPair") -} - -func init() { - proto.RegisterFile("pulsarchain/keyregistry/v1/address_pair.proto", fileDescriptor_eb9cea5d1b988cd3) -} - -var fileDescriptor_eb9cea5d1b988cd3 = []byte{ - // 206 bytes of a gzipped FileDescriptorProto - 0x1f, 0x8b, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0xff, 0xe2, 0xd2, 0x2d, 0x28, 0xcd, 0x29, - 0x4e, 0x2c, 0x4a, 0xce, 0x48, 0xcc, 0xcc, 0xd3, 0xcf, 0x4e, 0xad, 0x2c, 0x4a, 0x4d, 0xcf, 0x2c, - 0x2e, 0x29, 0xaa, 0xd4, 0x2f, 0x33, 0xd4, 0x4f, 0x4c, 0x49, 0x29, 0x4a, 0x2d, 0x2e, 0x8e, 0x2f, - 0x48, 0xcc, 0x2c, 0xd2, 0x2b, 0x28, 0xca, 0x2f, 0xc9, 0x17, 0x92, 0x42, 0x52, 0xae, 0x87, 0xa4, - 0x5c, 0xaf, 0xcc, 0x50, 0xc9, 0x9b, 0x8b, 0xdb, 0x11, 0xa2, 0x23, 0x20, 0x31, 0xb3, 0x48, 0x48, - 0x9a, 0x8b, 0x33, 0x37, 0x33, 0x2f, 0x31, 0x1e, 0x64, 0x8a, 0x04, 0xa3, 0x02, 0xa3, 0x06, 0x4f, - 0x10, 0x07, 0x48, 0x00, 0xa4, 0x46, 0x48, 0x9e, 0x8b, 0x3b, 0x39, 0xbf, 0x38, 0x37, 0xbf, 0x18, - 0x22, 0xcd, 0x04, 0x96, 0xe6, 0x82, 0x08, 0x81, 0x14, 0x38, 0x05, 0x9c, 0x78, 0x24, 0xc7, 0x78, - 0xe1, 0x91, 0x1c, 0xe3, 0x83, 0x47, 0x72, 0x8c, 0x13, 0x1e, 0xcb, 0x31, 0x5c, 0x78, 0x2c, 0xc7, - 0x70, 0xe3, 0xb1, 0x1c, 0x43, 0x94, 0x59, 0x7a, 0x66, 0x49, 0x46, 0x69, 0x92, 0x5e, 0x72, 0x7e, - 0xae, 0x7e, 0x5e, 0x7e, 0x4a, 0xaa, 0xa1, 0x81, 0xa1, 0x6e, 0x66, 0xbe, 0x3e, 0xc4, 0x61, 0xba, - 0x10, 0x8f, 0x54, 0xa0, 0x78, 0xa5, 0xa4, 0xb2, 0x20, 0xb5, 0x38, 0x89, 0x0d, 0xec, 0x03, 0x63, - 0x40, 0x00, 0x00, 0x00, 0xff, 0xff, 0x32, 0x26, 0x7c, 0xb2, 0xf2, 0x00, 0x00, 0x00, -} - -func (m *AddressPair) 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 *AddressPair) MarshalTo(dAtA []byte) (int, error) { - size := m.Size() - return m.MarshalToSizedBuffer(dAtA[:size]) -} - -func (m *AddressPair) MarshalToSizedBuffer(dAtA []byte) (int, error) { - i := len(dAtA) - _ = i - var l int - _ = l - if len(m.CosmosAddr) > 0 { - i -= len(m.CosmosAddr) - copy(dAtA[i:], m.CosmosAddr) - i = encodeVarintAddressPair(dAtA, i, uint64(len(m.CosmosAddr))) - i-- - dAtA[i] = 0x12 - } - if len(m.MinaAddr) > 0 { - i -= len(m.MinaAddr) - copy(dAtA[i:], m.MinaAddr) - i = encodeVarintAddressPair(dAtA, i, uint64(len(m.MinaAddr))) - i-- - dAtA[i] = 0xa - } - return len(dAtA) - i, nil -} - -func encodeVarintAddressPair(dAtA []byte, offset int, v uint64) int { - offset -= sovAddressPair(v) - base := offset - for v >= 1<<7 { - dAtA[offset] = uint8(v&0x7f | 0x80) - v >>= 7 - offset++ - } - dAtA[offset] = uint8(v) - return base -} -func (m *AddressPair) Size() (n int) { - if m == nil { - return 0 - } - var l int - _ = l - l = len(m.MinaAddr) - if l > 0 { - n += 1 + l + sovAddressPair(uint64(l)) - } - l = len(m.CosmosAddr) - if l > 0 { - n += 1 + l + sovAddressPair(uint64(l)) - } - return n -} - -func sovAddressPair(x uint64) (n int) { - return (math_bits.Len64(x|1) + 6) / 7 -} -func sozAddressPair(x uint64) (n int) { - return sovAddressPair(uint64((x << 1) ^ uint64((int64(x) >> 63)))) -} -func (m *AddressPair) 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 ErrIntOverflowAddressPair - } - 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: AddressPair: wiretype end group for non-group") - } - if fieldNum <= 0 { - return fmt.Errorf("proto: AddressPair: illegal tag %d (wire type %d)", fieldNum, wire) - } - switch fieldNum { - case 1: - if wireType != 2 { - return fmt.Errorf("proto: wrong wireType = %d for field MinaAddr", wireType) - } - var byteLen int - for shift := uint(0); ; shift += 7 { - if shift >= 64 { - return ErrIntOverflowAddressPair - } - if iNdEx >= l { - return io.ErrUnexpectedEOF - } - b := dAtA[iNdEx] - iNdEx++ - byteLen |= int(b&0x7F) << shift - if b < 0x80 { - break - } - } - if byteLen < 0 { - return ErrInvalidLengthAddressPair - } - postIndex := iNdEx + byteLen - if postIndex < 0 { - return ErrInvalidLengthAddressPair - } - if postIndex > l { - return io.ErrUnexpectedEOF - } - m.MinaAddr = append(m.MinaAddr[:0], dAtA[iNdEx:postIndex]...) - if m.MinaAddr == nil { - m.MinaAddr = []byte{} - } - iNdEx = postIndex - case 2: - if wireType != 2 { - return fmt.Errorf("proto: wrong wireType = %d for field CosmosAddr", wireType) - } - var byteLen int - for shift := uint(0); ; shift += 7 { - if shift >= 64 { - return ErrIntOverflowAddressPair - } - if iNdEx >= l { - return io.ErrUnexpectedEOF - } - b := dAtA[iNdEx] - iNdEx++ - byteLen |= int(b&0x7F) << shift - if b < 0x80 { - break - } - } - if byteLen < 0 { - return ErrInvalidLengthAddressPair - } - postIndex := iNdEx + byteLen - if postIndex < 0 { - return ErrInvalidLengthAddressPair - } - if postIndex > l { - return io.ErrUnexpectedEOF - } - m.CosmosAddr = append(m.CosmosAddr[:0], dAtA[iNdEx:postIndex]...) - if m.CosmosAddr == nil { - m.CosmosAddr = []byte{} - } - iNdEx = postIndex - default: - iNdEx = preIndex - skippy, err := skipAddressPair(dAtA[iNdEx:]) - if err != nil { - return err - } - if (skippy < 0) || (iNdEx+skippy) < 0 { - return ErrInvalidLengthAddressPair - } - if (iNdEx + skippy) > l { - return io.ErrUnexpectedEOF - } - iNdEx += skippy - } - } - - if iNdEx > l { - return io.ErrUnexpectedEOF - } - return nil -} -func skipAddressPair(dAtA []byte) (n int, err error) { - l := len(dAtA) - iNdEx := 0 - depth := 0 - for iNdEx < l { - var wire uint64 - for shift := uint(0); ; shift += 7 { - if shift >= 64 { - return 0, ErrIntOverflowAddressPair - } - if iNdEx >= l { - return 0, io.ErrUnexpectedEOF - } - b := dAtA[iNdEx] - iNdEx++ - wire |= (uint64(b) & 0x7F) << shift - if b < 0x80 { - break - } - } - wireType := int(wire & 0x7) - switch wireType { - case 0: - for shift := uint(0); ; shift += 7 { - if shift >= 64 { - return 0, ErrIntOverflowAddressPair - } - if iNdEx >= l { - return 0, io.ErrUnexpectedEOF - } - iNdEx++ - if dAtA[iNdEx-1] < 0x80 { - break - } - } - case 1: - iNdEx += 8 - case 2: - var length int - for shift := uint(0); ; shift += 7 { - if shift >= 64 { - return 0, ErrIntOverflowAddressPair - } - if iNdEx >= l { - return 0, io.ErrUnexpectedEOF - } - b := dAtA[iNdEx] - iNdEx++ - length |= (int(b) & 0x7F) << shift - if b < 0x80 { - break - } - } - if length < 0 { - return 0, ErrInvalidLengthAddressPair - } - iNdEx += length - case 3: - depth++ - case 4: - if depth == 0 { - return 0, ErrUnexpectedEndOfGroupAddressPair - } - depth-- - case 5: - iNdEx += 4 - default: - return 0, fmt.Errorf("proto: illegal wireType %d", wireType) - } - if iNdEx < 0 { - return 0, ErrInvalidLengthAddressPair - } - if depth == 0 { - return iNdEx, nil - } - } - return 0, io.ErrUnexpectedEOF -} - -var ( - ErrInvalidLengthAddressPair = fmt.Errorf("proto: negative length found during unmarshaling") - ErrIntOverflowAddressPair = fmt.Errorf("proto: integer overflow") - ErrUnexpectedEndOfGroupAddressPair = fmt.Errorf("proto: unexpected end of group") -) diff --git a/x/keyregistry/types/address_pairs.go b/x/keyregistry/types/address_pairs.go deleted file mode 100644 index 9d2edca8..00000000 --- a/x/keyregistry/types/address_pairs.go +++ /dev/null @@ -1,35 +0,0 @@ -package types - -import ( - "cosmossdk.io/errors" -) - -const CosmosAddrLen = 20 -const MinaAddrLen = 45 - -func NewAddressPairs() []*AddressPair { - return []*AddressPair{} -} -func DefaultUserAddressPairs() []*AddressPair { - return NewAddressPairs() -} - -func DefaultValidatorKeyPairs() []*AddressPair { - return NewAddressPairs() -} - -func ValidateAddressPair(k AddressPair) error { - if len(k.CosmosAddr) != CosmosAddrLen { - return errors.Wrap(ErrInvalidAddress, "cosmos address must be valid (20 bytes)") - } - - if len(k.MinaAddr) != MinaAddrLen { - return errors.Wrap(ErrInvalidAddress, "mina address must be valid") - } - return nil -} - -// Validate validates the set of params. -func (k AddressPair) Validate() error { - return ValidateAddressPair(k) -} diff --git a/x/keyregistry/types/errors.go b/x/keyregistry/types/errors.go index 1750d565..a4b97564 100644 --- a/x/keyregistry/types/errors.go +++ b/x/keyregistry/types/errors.go @@ -14,7 +14,6 @@ var ( ErrValidatorSecondaryKeyExists = errors.Register(ModuleName, 1103, "validator's secondary key already exists") ErrInvalidCreatorAddres = errors.Register(ModuleName, 1104, "invalid creator address") ErrInvalidPublicKey = errors.Register(ModuleName, 1105, "invalid public key") - ErrInvalidAddress = errors.Register(ModuleName, 1106, "invalid address") - ErrUserNotRegistered = errors.Register(ModuleName, 1107, "user has not been registered") - ErrValidatorNotRegistered = errors.Register(ModuleName, 1108, "validator has not been registered") + ErrUserNotRegistered = errors.Register(ModuleName, 1106, "user has not been registered") + ErrValidatorNotRegistered = errors.Register(ModuleName, 1107, "validator has not been registered") ) diff --git a/x/keyregistry/types/genesis.go b/x/keyregistry/types/genesis.go index 4cda9d3d..abc14ccb 100644 --- a/x/keyregistry/types/genesis.go +++ b/x/keyregistry/types/genesis.go @@ -4,7 +4,7 @@ package types func DefaultGenesis() *GenesisState { return &GenesisState{ Params: DefaultParams(), - UserKeyPairs: DefaultUserAddressPairs(), + UserKeyPairs: DefaultPublicKeyPair(), ValidatorKeyPairs: DefaultPublicKeyPair(), } } @@ -14,7 +14,7 @@ func DefaultGenesis() *GenesisState { func (gs GenesisState) Validate() error { for _, keyPair := range gs.UserKeyPairs { - err := ValidateAddressPair(*keyPair) + err := ValidatePublicKeyPair(*keyPair) if err != nil { return err } diff --git a/x/keyregistry/types/genesis.pb.go b/x/keyregistry/types/genesis.pb.go index 10beefbe..ffea01ac 100644 --- a/x/keyregistry/types/genesis.pb.go +++ b/x/keyregistry/types/genesis.pb.go @@ -28,7 +28,7 @@ const _ = proto.GoGoProtoPackageIsVersion3 // please upgrade the proto package type GenesisState struct { // params defines all the parameters of the module. Params Params `protobuf:"bytes,1,opt,name=params,proto3" json:"params"` - UserKeyPairs []*AddressPair `protobuf:"bytes,2,rep,name=user_key_pairs,json=userKeyPairs,proto3" json:"user_key_pairs,omitempty"` + UserKeyPairs []*PublicKeyPair `protobuf:"bytes,2,rep,name=user_key_pairs,json=userKeyPairs,proto3" json:"user_key_pairs,omitempty"` ValidatorKeyPairs []*PublicKeyPair `protobuf:"bytes,3,rep,name=validator_key_pairs,json=validatorKeyPairs,proto3" json:"validator_key_pairs,omitempty"` } @@ -72,7 +72,7 @@ func (m *GenesisState) GetParams() Params { return Params{} } -func (m *GenesisState) GetUserKeyPairs() []*AddressPair { +func (m *GenesisState) GetUserKeyPairs() []*PublicKeyPair { if m != nil { return m.UserKeyPairs } @@ -95,28 +95,27 @@ func init() { } var fileDescriptor_dbaeb2ea35536f14 = []byte{ - // 334 bytes of a gzipped FileDescriptorProto + // 312 bytes of a gzipped FileDescriptorProto 0x1f, 0x8b, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0xff, 0xe2, 0xd2, 0x28, 0x28, 0xcd, 0x29, 0x4e, 0x2c, 0x4a, 0xce, 0x48, 0xcc, 0xcc, 0xd3, 0xcf, 0x4e, 0xad, 0x2c, 0x4a, 0x4d, 0xcf, 0x2c, 0x2e, 0x29, 0xaa, 0xd4, 0x2f, 0x33, 0xd4, 0x4f, 0x4f, 0xcd, 0x4b, 0x2d, 0xce, 0x2c, 0xd6, 0x2b, 0x28, 0xca, 0x2f, 0xc9, 0x17, 0x92, 0x42, 0x52, 0xa9, 0x87, 0xa4, 0x52, 0xaf, 0xcc, 0x50, 0x4a, 0x30, 0x31, 0x37, 0x33, 0x2f, 0x5f, 0x1f, 0x4c, 0x42, 0x94, 0x4b, 0x89, 0xa4, 0xe7, 0xa7, 0xe7, - 0x83, 0x99, 0xfa, 0x20, 0x16, 0x54, 0x54, 0x17, 0x8f, 0x75, 0x89, 0x29, 0x29, 0x45, 0xa9, 0xc5, - 0xc5, 0xf1, 0x05, 0x89, 0x99, 0x45, 0x50, 0xe5, 0xea, 0x78, 0x94, 0x17, 0x24, 0x16, 0x25, 0xe6, - 0x42, 0x1d, 0x27, 0x65, 0x80, 0x4f, 0x61, 0x69, 0x52, 0x4e, 0x66, 0x72, 0x7c, 0x76, 0x6a, 0x25, - 0x92, 0xd1, 0x4a, 0xff, 0x19, 0xb9, 0x78, 0xdc, 0x21, 0x1e, 0x0c, 0x2e, 0x49, 0x2c, 0x49, 0x15, - 0x72, 0xe5, 0x62, 0x83, 0x18, 0x29, 0xc1, 0xa8, 0xc0, 0xa8, 0xc1, 0x6d, 0xa4, 0xa4, 0x87, 0xdb, - 0xc3, 0x7a, 0x01, 0x60, 0x95, 0x4e, 0x9c, 0x27, 0xee, 0xc9, 0x33, 0xac, 0x78, 0xbe, 0x41, 0x8b, - 0x31, 0x08, 0xaa, 0x59, 0xc8, 0x97, 0x8b, 0xaf, 0xb4, 0x38, 0xb5, 0x08, 0x6e, 0x5d, 0xb1, 0x04, - 0x93, 0x02, 0xb3, 0x06, 0xb7, 0x91, 0x3a, 0x3e, 0xe3, 0x1c, 0x21, 0x5e, 0x0f, 0x48, 0xcc, 0x2c, - 0x0a, 0xe2, 0x01, 0x69, 0xf7, 0x4e, 0xad, 0x04, 0x71, 0x8a, 0x85, 0x22, 0xb9, 0x84, 0xcb, 0x12, - 0x73, 0x32, 0x53, 0x12, 0x4b, 0xf2, 0x91, 0xcd, 0x64, 0x06, 0x9b, 0xa9, 0x89, 0xd7, 0x89, 0x60, - 0x6f, 0x43, 0x0d, 0x0a, 0x12, 0x84, 0x9b, 0x02, 0x33, 0xda, 0x29, 0xe0, 0xc4, 0x23, 0x39, 0xc6, - 0x0b, 0x8f, 0xe4, 0x18, 0x1f, 0x3c, 0x92, 0x63, 0x9c, 0xf0, 0x58, 0x8e, 0xe1, 0xc2, 0x63, 0x39, - 0x86, 0x1b, 0x8f, 0xe5, 0x18, 0xa2, 0xcc, 0xd2, 0x33, 0x4b, 0x32, 0x4a, 0x93, 0xf4, 0x92, 0xf3, - 0x73, 0xf5, 0xf3, 0xf2, 0x53, 0x52, 0x0d, 0x0d, 0x0c, 0x75, 0x33, 0xf3, 0xf5, 0x21, 0x96, 0xe9, - 0x42, 0x02, 0xb9, 0x02, 0x25, 0x98, 0x4b, 0x2a, 0x0b, 0x52, 0x8b, 0x93, 0xd8, 0xc0, 0x41, 0x6b, - 0x0c, 0x08, 0x00, 0x00, 0xff, 0xff, 0x10, 0xe9, 0xe3, 0x9b, 0x55, 0x02, 0x00, 0x00, + 0x83, 0x99, 0xfa, 0x20, 0x16, 0x54, 0x54, 0x1d, 0x8f, 0x75, 0x05, 0x89, 0x45, 0x89, 0xb9, 0x50, + 0xdb, 0xa4, 0x0c, 0xf0, 0x29, 0x2c, 0x4d, 0xca, 0xc9, 0x4c, 0x8e, 0xcf, 0x4e, 0xad, 0x8c, 0x2f, + 0x48, 0xcc, 0x2c, 0x82, 0xe8, 0x50, 0x6a, 0x64, 0xe2, 0xe2, 0x71, 0x87, 0xb8, 0x38, 0xb8, 0x24, + 0xb1, 0x24, 0x55, 0xc8, 0x95, 0x8b, 0x0d, 0x62, 0xa4, 0x04, 0xa3, 0x02, 0xa3, 0x06, 0xb7, 0x91, + 0x92, 0x1e, 0x6e, 0x1f, 0xe8, 0x05, 0x80, 0x55, 0x3a, 0x71, 0x9e, 0xb8, 0x27, 0xcf, 0xb0, 0xe2, + 0xf9, 0x06, 0x2d, 0xc6, 0x20, 0xa8, 0x66, 0x21, 0x7f, 0x2e, 0xbe, 0xd2, 0xe2, 0xd4, 0x22, 0xb8, + 0x75, 0xc5, 0x12, 0x4c, 0x0a, 0xcc, 0x1a, 0xdc, 0x46, 0x9a, 0x78, 0x8d, 0x03, 0x3b, 0xd1, 0x3b, + 0xb5, 0x32, 0x20, 0x31, 0xb3, 0x28, 0x88, 0x07, 0x64, 0x00, 0x94, 0x53, 0x2c, 0x14, 0xc9, 0x25, + 0x5c, 0x96, 0x98, 0x93, 0x99, 0x92, 0x58, 0x92, 0x8f, 0x6c, 0x2a, 0x33, 0xa9, 0xa6, 0x0a, 0xc2, + 0x4d, 0x81, 0x19, 0xed, 0x14, 0x70, 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, + 0x66, 0xe9, 0x99, 0x25, 0x19, 0xa5, 0x49, 0x7a, 0xc9, 0xf9, 0xb9, 0xfa, 0x79, 0xf9, 0x29, 0xa9, + 0x86, 0x06, 0x86, 0xba, 0x99, 0xf9, 0xfa, 0x10, 0xcb, 0x74, 0x21, 0xc1, 0x5c, 0x81, 0x12, 0xd0, + 0x25, 0x95, 0x05, 0xa9, 0xc5, 0x49, 0x6c, 0xe0, 0xc0, 0x35, 0x06, 0x04, 0x00, 0x00, 0xff, 0xff, + 0x88, 0x60, 0x3e, 0xa4, 0x28, 0x02, 0x00, 0x00, } func (m *GenesisState) Marshal() (dAtA []byte, err error) { @@ -311,7 +310,7 @@ func (m *GenesisState) Unmarshal(dAtA []byte) error { if postIndex > l { return io.ErrUnexpectedEOF } - m.UserKeyPairs = append(m.UserKeyPairs, &AddressPair{}) + m.UserKeyPairs = append(m.UserKeyPairs, &PublicKeyPair{}) if err := m.UserKeyPairs[len(m.UserKeyPairs)-1].Unmarshal(dAtA[iNdEx:postIndex]); err != nil { return err } diff --git a/x/keyregistry/types/query.pb.go b/x/keyregistry/types/query.pb.go index 596add31..e529ad88 100644 --- a/x/keyregistry/types/query.pb.go +++ b/x/keyregistry/types/query.pb.go @@ -114,7 +114,7 @@ func (m *QueryParamsResponse) GetParams() Params { return Params{} } -// QueryGetUserMinaAddressRequest defines the QueryGetUserMinaAddressRequest message. +// QueryGetUserMinaPublicKeyRequest defines the QueryGetUserMinaPublicKeyRequest message. type QueryGetUserMinaPublicKeyRequest struct { UserCosmosPublicKey []byte `protobuf:"bytes,1,opt,name=user_cosmos_public_key,json=userCosmosPublicKey,proto3" json:"user_cosmos_public_key,omitempty"` } @@ -159,7 +159,7 @@ func (m *QueryGetUserMinaPublicKeyRequest) GetUserCosmosPublicKey() []byte { return nil } -// QueryGetUserMinaAddressResponse defines the QueryGetUserMinaAddressResponse message. +// QueryGetUserMinaPublicKeyResponse defines the QueryGetUserMinaPublicKeyResponse message. type QueryGetUserMinaPublicKeyResponse struct { UserMinaPublicKey []byte `protobuf:"bytes,1,opt,name=user_mina_public_key,json=userMinaPublicKey,proto3" json:"user_mina_public_key,omitempty"` } @@ -204,7 +204,7 @@ func (m *QueryGetUserMinaPublicKeyResponse) GetUserMinaPublicKey() []byte { return nil } -// QueryGetUserCosmosAddressRequest defines the QueryGetUserCosmosAddressRequest message. +// QueryGetUserCosmosPublicKeyRequest defines the QueryGetUserCosmosPublicKeyRequest message. type QueryGetUserCosmosPublicKeyRequest struct { UserMinaPublicKey []byte `protobuf:"bytes,1,opt,name=user_mina_public_key,json=userMinaPublicKey,proto3" json:"user_mina_public_key,omitempty"` } @@ -249,7 +249,7 @@ func (m *QueryGetUserCosmosPublicKeyRequest) GetUserMinaPublicKey() []byte { return nil } -// QueryGetUserCosmosAddressResponse defines the QueryGetUserCosmosAddressResponse message. +// QueryGetUserCosmosPublicKeyResponse defines the QueryGetUserCosmosPublicKeyResponse message. type QueryGetUserCosmosPublicKeyResponse struct { UserCosmosPublicKey []byte `protobuf:"bytes,1,opt,name=user_cosmos_public_key,json=userCosmosPublicKey,proto3" json:"user_cosmos_public_key,omitempty"` } @@ -294,7 +294,7 @@ func (m *QueryGetUserCosmosPublicKeyResponse) GetUserCosmosPublicKey() []byte { return nil } -// QueryGetValidatorMinaAddressRequest defines the QueryGetValidatorMinaAddressRequest message. +// QueryGetValidatorMinaPubKeyRequest defines the QueryGetValidatorMinaPubKeyRequest message. type QueryGetValidatorMinaPubKeyRequest struct { ValidatorCosmosPubKey []byte `protobuf:"bytes,1,opt,name=validator_cosmos_pub_key,json=validatorCosmosPubKey,proto3" json:"validator_cosmos_pub_key,omitempty"` } @@ -339,7 +339,7 @@ func (m *QueryGetValidatorMinaPubKeyRequest) GetValidatorCosmosPubKey() []byte { return nil } -// QueryGetValidatorMinaAddressResponse defines the QueryGetValidatorMinaAddressResponse message. +// QueryGetValidatorMinaPubKeyResponse defines the QueryGetValidatorMinaPubKeyResponse message. type QueryGetValidatorMinaPubKeyResponse struct { ValidatorMinaPubKey []byte `protobuf:"bytes,1,opt,name=validator_mina_pub_key,json=validatorMinaPubKey,proto3" json:"validator_mina_pub_key,omitempty"` } @@ -384,7 +384,7 @@ func (m *QueryGetValidatorMinaPubKeyResponse) GetValidatorMinaPubKey() []byte { return nil } -// QueryGetValidatorCosmosAddressRequest defines the QueryGetValidatorCosmosAddressRequest message. +// QueryGetValidatorCosmosPubKeyRequest defines the QueryGetValidatorCosmosPubKeyRequest message. type QueryGetValidatorCosmosPubKeyRequest struct { ValidatorMinaPubKey []byte `protobuf:"bytes,1,opt,name=validator_mina_pub_key,json=validatorMinaPubKey,proto3" json:"validator_mina_pub_key,omitempty"` } @@ -429,7 +429,7 @@ func (m *QueryGetValidatorCosmosPubKeyRequest) GetValidatorMinaPubKey() []byte { return nil } -// QueryGetValidatorCosmosAddressResponse defines the QueryGetValidatorCosmosAddressResponse message. +// QueryGetValidatorCosmosPubKeyResponse defines the QueryGetValidatorCosmosPubKeyResponse message. type QueryGetValidatorCosmosPubKeyResponse struct { ValidatorCosmosPubKey []byte `protobuf:"bytes,1,opt,name=validator_cosmos_pub_key,json=validatorCosmosPubKey,proto3" json:"validator_cosmos_pub_key,omitempty"` } @@ -550,13 +550,13 @@ const _ = grpc.SupportPackageIsVersion4 type QueryClient interface { // Parameters queries the parameters of the module. Params(ctx context.Context, in *QueryParamsRequest, opts ...grpc.CallOption) (*QueryParamsResponse, error) - // GetUserMinaAddress Queries a list of GetUserMinaAddress items. + // GetUserMinaPublicKey Queries a list of GetUserMinaPublicKey items. GetUserMinaPublicKey(ctx context.Context, in *QueryGetUserMinaPublicKeyRequest, opts ...grpc.CallOption) (*QueryGetUserMinaPublicKeyResponse, error) - // GetUserCosmosAddress Queries a list of GetUserCosmosAddress items. + // GetUserCosmosPublicKey Queries a list of GetUserCosmosPublicKey items. GetUserCosmosPublicKey(ctx context.Context, in *QueryGetUserCosmosPublicKeyRequest, opts ...grpc.CallOption) (*QueryGetUserCosmosPublicKeyResponse, error) - // GetValidatorMinaAddress Queries a list of GetValidatorMinaAddress items. + // GetValidatorMinaPubKey Queries a list of GetValidatorMinaPubKey items. GetValidatorMinaPubKey(ctx context.Context, in *QueryGetValidatorMinaPubKeyRequest, opts ...grpc.CallOption) (*QueryGetValidatorMinaPubKeyResponse, error) - // GetValidatorCosmosAddress Queries a list of GetValidatorCosmosAddress items. + // GetValidatorCosmosPubKey Queries a list of GetValidatorCosmosPubKey items. GetValidatorCosmosPubKey(ctx context.Context, in *QueryGetValidatorCosmosPubKeyRequest, opts ...grpc.CallOption) (*QueryGetValidatorCosmosPubKeyResponse, error) } @@ -617,13 +617,13 @@ func (c *queryClient) GetValidatorCosmosPubKey(ctx context.Context, in *QueryGet type QueryServer interface { // Parameters queries the parameters of the module. Params(context.Context, *QueryParamsRequest) (*QueryParamsResponse, error) - // GetUserMinaAddress Queries a list of GetUserMinaAddress items. + // GetUserMinaPublicKey Queries a list of GetUserMinaPublicKey items. GetUserMinaPublicKey(context.Context, *QueryGetUserMinaPublicKeyRequest) (*QueryGetUserMinaPublicKeyResponse, error) - // GetUserCosmosAddress Queries a list of GetUserCosmosAddress items. + // GetUserCosmosPublicKey Queries a list of GetUserCosmosPublicKey items. GetUserCosmosPublicKey(context.Context, *QueryGetUserCosmosPublicKeyRequest) (*QueryGetUserCosmosPublicKeyResponse, error) - // GetValidatorMinaAddress Queries a list of GetValidatorMinaAddress items. + // GetValidatorMinaPubKey Queries a list of GetValidatorMinaPubKey items. GetValidatorMinaPubKey(context.Context, *QueryGetValidatorMinaPubKeyRequest) (*QueryGetValidatorMinaPubKeyResponse, error) - // GetValidatorCosmosAddress Queries a list of GetValidatorCosmosAddress items. + // GetValidatorCosmosPubKey Queries a list of GetValidatorCosmosPubKey items. GetValidatorCosmosPubKey(context.Context, *QueryGetValidatorCosmosPubKeyRequest) (*QueryGetValidatorCosmosPubKeyResponse, error) } diff --git a/x/keyregistry/types/tx.pb.go b/x/keyregistry/types/tx.pb.go index b3b2705b..1362b014 100644 --- a/x/keyregistry/types/tx.pb.go +++ b/x/keyregistry/types/tx.pb.go @@ -129,8 +129,8 @@ type MsgRegisterKeys struct { Creator string `protobuf:"bytes,1,opt,name=creator,proto3" json:"creator,omitempty"` CosmosSignature string `protobuf:"bytes,2,opt,name=cosmos_signature,json=cosmosSignature,proto3" json:"cosmos_signature,omitempty"` MinaSignature string `protobuf:"bytes,3,opt,name=mina_signature,json=minaSignature,proto3" json:"mina_signature,omitempty"` - CosmosAddress []byte `protobuf:"bytes,4,opt,name=cosmos_address,json=cosmosAddress,proto3" json:"cosmos_address,omitempty"` - MinaAddress []byte `protobuf:"bytes,5,opt,name=mina_address,json=minaAddress,proto3" json:"mina_address,omitempty"` + CosmosPublicKey []byte `protobuf:"bytes,4,opt,name=cosmos_public_key,json=cosmosPublicKey,proto3" json:"cosmos_public_key,omitempty"` + MinaPublicKey []byte `protobuf:"bytes,5,opt,name=mina_public_key,json=minaPublicKey,proto3" json:"mina_public_key,omitempty"` ActorType ActorType `protobuf:"varint,6,opt,name=actor_type,json=actorType,proto3,enum=pulsarchain.keyregistry.v1.ActorType" json:"actor_type,omitempty"` } @@ -188,16 +188,16 @@ func (m *MsgRegisterKeys) GetMinaSignature() string { return "" } -func (m *MsgRegisterKeys) GetCosmosAddress() []byte { +func (m *MsgRegisterKeys) GetCosmosPublicKey() []byte { if m != nil { - return m.CosmosAddress + return m.CosmosPublicKey } return nil } -func (m *MsgRegisterKeys) GetMinaAddress() []byte { +func (m *MsgRegisterKeys) GetMinaPublicKey() []byte { if m != nil { - return m.MinaAddress + return m.MinaPublicKey } return nil } @@ -382,48 +382,47 @@ func init() { } var fileDescriptor_235f5fb22cc1f8d8 = []byte{ - // 641 bytes of a gzipped FileDescriptorProto + // 634 bytes of a gzipped FileDescriptorProto 0x1f, 0x8b, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0xff, 0xb4, 0x94, 0x3f, 0x6f, 0xd3, 0x4e, - 0x18, 0xc7, 0xe3, 0xf4, 0xd7, 0xfe, 0x94, 0x6b, 0xfa, 0xcf, 0x14, 0x35, 0xcd, 0x60, 0x42, 0x50, - 0x45, 0x5a, 0x88, 0xdd, 0xa4, 0x52, 0x87, 0x8a, 0xa5, 0x15, 0x4c, 0x55, 0xa4, 0xc8, 0x85, 0x85, - 0x25, 0xba, 0x38, 0x27, 0xc7, 0xa4, 0xf6, 0x59, 0x77, 0xe7, 0xb4, 0xde, 0x10, 0x23, 0x13, 0x2f, - 0x83, 0x31, 0x03, 0xbc, 0x87, 0x4e, 0x28, 0x62, 0x62, 0x40, 0x08, 0x25, 0x43, 0xde, 0x06, 0xf2, - 0x9d, 0x9d, 0xd8, 0x69, 0x48, 0x0a, 0x12, 0x8b, 0xe5, 0x7b, 0x9e, 0xcf, 0x3d, 0x7f, 0xbe, 0xcf, - 0xdd, 0x81, 0x47, 0xae, 0x77, 0x49, 0x21, 0x31, 0xda, 0xd0, 0x72, 0xb4, 0x0e, 0xf2, 0x09, 0x32, - 0x2d, 0xca, 0x88, 0xaf, 0x75, 0x2b, 0x1a, 0xbb, 0x56, 0x5d, 0x82, 0x19, 0x96, 0xf3, 0x31, 0x48, - 0x8d, 0x41, 0x6a, 0xb7, 0x92, 0xdf, 0x82, 0xb6, 0xe5, 0x60, 0x8d, 0x7f, 0x05, 0x9e, 0xdf, 0x31, - 0x30, 0xb5, 0x31, 0xd5, 0x6c, 0x6a, 0x06, 0x61, 0x6c, 0x6a, 0x86, 0x8e, 0x5d, 0xe1, 0x68, 0xf0, - 0x95, 0x26, 0x16, 0xa1, 0x6b, 0xdb, 0xc4, 0x26, 0x16, 0xf6, 0xe0, 0x2f, 0xb4, 0x3e, 0x9e, 0x53, - 0x9d, 0x0b, 0x09, 0xb4, 0xa3, 0xed, 0x87, 0x73, 0xc0, 0x0e, 0xf2, 0x1b, 0x9e, 0xdb, 0x82, 0x0c, - 0x35, 0x98, 0xef, 0x22, 0xb1, 0xa3, 0xf8, 0x45, 0x02, 0x1b, 0x35, 0x6a, 0xbe, 0xe2, 0x8e, 0x3a, - 0x8f, 0x25, 0x1f, 0x83, 0x0c, 0xf4, 0x58, 0x1b, 0x13, 0x8b, 0xf9, 0x39, 0xa9, 0x20, 0x95, 0x32, - 0x67, 0xb9, 0xaf, 0x9f, 0xca, 0xdb, 0x61, 0xa5, 0xa7, 0xad, 0x16, 0x41, 0x94, 0x5e, 0x30, 0x62, - 0x39, 0xa6, 0x3e, 0x41, 0xe5, 0x17, 0x60, 0x45, 0x54, 0x93, 0x4b, 0x17, 0xa4, 0xd2, 0x6a, 0xb5, - 0xa8, 0xfe, 0x5e, 0x30, 0x55, 0xe4, 0x3a, 0xcb, 0xdc, 0xfc, 0x78, 0x90, 0xfa, 0x38, 0xea, 0x1d, - 0x48, 0x7a, 0xb8, 0xf9, 0xe4, 0xd9, 0xbb, 0x51, 0xef, 0x60, 0x12, 0xf6, 0xfd, 0xa8, 0x77, 0xb0, - 0x1f, 0xef, 0xeb, 0x3a, 0xd1, 0xd9, 0x54, 0xf1, 0xc5, 0x5d, 0xb0, 0x33, 0x65, 0xd2, 0x11, 0x75, - 0xb1, 0x43, 0x51, 0xf1, 0x73, 0x9a, 0xf7, 0xaa, 0xf3, 0xad, 0x88, 0x9c, 0x23, 0x9f, 0xca, 0x55, - 0xf0, 0xbf, 0x41, 0x10, 0x64, 0x98, 0x2c, 0xec, 0x34, 0x02, 0xe5, 0x7d, 0xb0, 0x19, 0x4e, 0x90, - 0x5a, 0xa6, 0x03, 0x99, 0x47, 0x10, 0xef, 0x38, 0xa3, 0x6f, 0x08, 0xfb, 0x45, 0x64, 0x96, 0xf7, - 0xc0, 0xba, 0x6d, 0x39, 0x30, 0x06, 0x2e, 0x71, 0x70, 0x2d, 0xb0, 0x26, 0xb0, 0x30, 0x22, 0x14, - 0x29, 0x73, 0xff, 0x15, 0xa4, 0x52, 0x56, 0x5f, 0x13, 0xd6, 0xb0, 0x0e, 0xf9, 0x21, 0xc8, 0xf2, - 0x68, 0x11, 0xb4, 0xcc, 0xa1, 0xd5, 0xc0, 0x16, 0x21, 0xcf, 0x01, 0x80, 0x06, 0xc3, 0x84, 0xcf, - 0x38, 0xb7, 0x52, 0x90, 0x4a, 0xeb, 0xd5, 0xbd, 0x79, 0x73, 0x38, 0x0d, 0xe8, 0x97, 0xbe, 0x8b, - 0xf4, 0x0c, 0x8c, 0x7e, 0x4f, 0xb2, 0xc1, 0x08, 0xa2, 0x7e, 0x43, 0x49, 0xe3, 0xb2, 0x8d, 0x25, - 0xed, 0xa7, 0xc1, 0xda, 0x58, 0xee, 0xbf, 0x16, 0x54, 0x03, 0xdb, 0x2e, 0x41, 0xdd, 0x06, 0x6f, - 0xce, 0xf5, 0x9a, 0x97, 0x96, 0xd1, 0xe8, 0x20, 0x9f, 0x8b, 0x9a, 0xd5, 0xb7, 0x02, 0x5f, 0xcd, - 0x72, 0x60, 0x9d, 0x7b, 0xce, 0x91, 0x2f, 0x97, 0xc1, 0x3d, 0x07, 0x5d, 0xdd, 0xe2, 0x97, 0x38, - 0xbf, 0xe9, 0xa0, 0xab, 0x24, 0x3e, 0x6b, 0x60, 0x42, 0xe0, 0x5b, 0x03, 0x7b, 0x0a, 0xe4, 0x71, - 0xe4, 0x09, 0xbc, 0x9c, 0x08, 0x3c, 0xa1, 0xff, 0x85, 0xda, 0x3b, 0xe0, 0x7e, 0x42, 0xd1, 0x48, - 0xeb, 0xea, 0xf7, 0x34, 0x58, 0xaa, 0x51, 0x53, 0x76, 0x41, 0x36, 0x71, 0x5d, 0x9f, 0xcc, 0x4b, - 0x38, 0x75, 0x17, 0xf2, 0x47, 0x7f, 0x00, 0x47, 0x99, 0x83, 0x8c, 0x89, 0x4b, 0xb3, 0x28, 0x63, - 0x1c, 0x5e, 0x98, 0x71, 0xd6, 0xb9, 0x92, 0xdf, 0x00, 0x10, 0x3b, 0x53, 0xfb, 0x77, 0x2a, 0x9a, - 0x67, 0xab, 0xdc, 0x19, 0x8d, 0x72, 0xe5, 0x97, 0xdf, 0x06, 0xcf, 0xcf, 0x59, 0xfd, 0x66, 0xa0, - 0x48, 0xfd, 0x81, 0x22, 0xfd, 0x1c, 0x28, 0xd2, 0x87, 0xa1, 0x92, 0xea, 0x0f, 0x95, 0xd4, 0xb7, - 0xa1, 0x92, 0x7a, 0x7d, 0x6c, 0x5a, 0xac, 0xed, 0x35, 0x55, 0x03, 0xdb, 0x9a, 0x83, 0x5b, 0xa8, - 0x72, 0x58, 0x29, 0x5b, 0x58, 0x13, 0x89, 0xca, 0xb3, 0x1e, 0xa5, 0xe0, 0x38, 0xd0, 0xe6, 0x0a, - 0x7f, 0x62, 0x8f, 0x7e, 0x05, 0x00, 0x00, 0xff, 0xff, 0xac, 0xab, 0xc3, 0xf8, 0x5d, 0x06, 0x00, - 0x00, + 0x18, 0xc7, 0xe3, 0xf4, 0xd7, 0xfe, 0x94, 0xa3, 0x7f, 0x4d, 0x51, 0xd2, 0x0c, 0x26, 0x0a, 0x2a, + 0x24, 0x81, 0xd8, 0x4d, 0x2a, 0x75, 0xa8, 0x58, 0x1a, 0xc1, 0x54, 0x45, 0x8a, 0x5c, 0x58, 0x58, + 0xa2, 0x8b, 0x73, 0x72, 0x4c, 0x6a, 0x9f, 0x75, 0x77, 0x4e, 0xeb, 0x0d, 0x31, 0x32, 0xf1, 0x32, + 0x18, 0x33, 0xb0, 0xb3, 0x76, 0x42, 0x11, 0x13, 0x03, 0x42, 0x28, 0x19, 0xf2, 0x36, 0x90, 0xcf, + 0x76, 0x6c, 0x87, 0x90, 0x14, 0x24, 0x16, 0xcb, 0xf7, 0x3c, 0x9f, 0x7b, 0xfe, 0x7c, 0x9f, 0xbb, + 0x03, 0x0f, 0x6c, 0xe7, 0x92, 0x42, 0xa2, 0xf5, 0xa0, 0x61, 0x29, 0x7d, 0xe4, 0x12, 0xa4, 0x1b, + 0x94, 0x11, 0x57, 0x19, 0xd4, 0x14, 0x76, 0x2d, 0xdb, 0x04, 0x33, 0x2c, 0xe6, 0x63, 0x90, 0x1c, + 0x83, 0xe4, 0x41, 0x2d, 0xbf, 0x07, 0x4d, 0xc3, 0xc2, 0x0a, 0xff, 0xfa, 0x78, 0x3e, 0xab, 0x61, + 0x6a, 0x62, 0xaa, 0x98, 0x54, 0xf7, 0xc2, 0x98, 0x54, 0x0f, 0x1c, 0x07, 0xbe, 0xa3, 0xcd, 0x57, + 0x8a, 0xbf, 0x08, 0x5c, 0xfb, 0x3a, 0xd6, 0xb1, 0x6f, 0xf7, 0xfe, 0x02, 0xeb, 0xa3, 0x25, 0xd5, + 0xd9, 0x90, 0x40, 0x33, 0xdc, 0x7e, 0xb4, 0x04, 0xec, 0x23, 0xb7, 0xed, 0xd8, 0x5d, 0xc8, 0x50, + 0x9b, 0xb9, 0x36, 0xf2, 0x77, 0x14, 0x3f, 0x0b, 0x60, 0xa7, 0x49, 0xf5, 0x97, 0xdc, 0xd1, 0xe2, + 0xb1, 0xc4, 0x13, 0x90, 0x81, 0x0e, 0xeb, 0x61, 0x62, 0x30, 0x37, 0x27, 0x14, 0x84, 0x52, 0xa6, + 0x91, 0xfb, 0xf2, 0xb1, 0xba, 0x1f, 0x54, 0x7a, 0xd6, 0xed, 0x12, 0x44, 0xe9, 0x05, 0x23, 0x86, + 0xa5, 0xab, 0x11, 0x2a, 0x3e, 0x07, 0x1b, 0x7e, 0x35, 0xb9, 0x74, 0x41, 0x28, 0xdd, 0xa9, 0x17, + 0xe5, 0xdf, 0x0b, 0x26, 0xfb, 0xb9, 0x1a, 0x99, 0x9b, 0xef, 0xf7, 0x53, 0x1f, 0xa6, 0xc3, 0x8a, + 0xa0, 0x06, 0x9b, 0x4f, 0x9f, 0xbe, 0x9d, 0x0e, 0x2b, 0x51, 0xd8, 0x77, 0xd3, 0x61, 0xa5, 0x1c, + 0xef, 0xeb, 0x3a, 0xd1, 0xd9, 0x5c, 0xf1, 0xc5, 0x03, 0x90, 0x9d, 0x33, 0xa9, 0x88, 0xda, 0xd8, + 0xa2, 0xa8, 0xf8, 0x29, 0xcd, 0x7b, 0x55, 0xf9, 0x56, 0x44, 0xce, 0x91, 0x4b, 0xc5, 0x3a, 0xf8, + 0x5f, 0x23, 0x08, 0x32, 0x4c, 0x56, 0x76, 0x1a, 0x82, 0x62, 0x19, 0xec, 0x06, 0x13, 0xa4, 0x86, + 0x6e, 0x41, 0xe6, 0x10, 0xc4, 0x3b, 0xce, 0xa8, 0x3b, 0xbe, 0xfd, 0x22, 0x34, 0x8b, 0x87, 0x60, + 0xdb, 0x34, 0x2c, 0x18, 0x03, 0xd7, 0x38, 0xb8, 0xe5, 0x59, 0x23, 0xac, 0x02, 0xf6, 0xc2, 0x33, + 0xe1, 0x74, 0x2e, 0x0d, 0xad, 0xdd, 0x47, 0x6e, 0xee, 0xbf, 0x82, 0x50, 0xda, 0x0c, 0x43, 0xb6, + 0xb8, 0xfd, 0x1c, 0xb9, 0xe2, 0x43, 0xb0, 0xc3, 0x43, 0xc6, 0xc8, 0x75, 0x4e, 0xf2, 0x98, 0x11, + 0xf7, 0x0c, 0x00, 0xa8, 0x31, 0x4c, 0xf8, 0xb4, 0x73, 0x1b, 0x05, 0xa1, 0xb4, 0x5d, 0x3f, 0x5c, + 0x36, 0x91, 0x33, 0x8f, 0x7e, 0xe1, 0xda, 0x48, 0xcd, 0xc0, 0xf0, 0xf7, 0x74, 0xd3, 0x1b, 0x46, + 0xd8, 0x79, 0x20, 0x6e, 0x5c, 0xc0, 0x99, 0xb8, 0xa3, 0x34, 0xd8, 0x9a, 0x09, 0xff, 0xd7, 0xd2, + 0x2a, 0x60, 0xdf, 0x26, 0x68, 0xd0, 0x9e, 0xef, 0x30, 0xcd, 0x3b, 0xdc, 0xf3, 0x7c, 0xcd, 0x44, + 0x97, 0x55, 0x70, 0xd7, 0x42, 0x57, 0xbf, 0xf0, 0x6b, 0x9c, 0xdf, 0xb5, 0xd0, 0x55, 0x12, 0x5f, + 0x34, 0xba, 0x84, 0xce, 0xd1, 0x4c, 0x9e, 0x00, 0x71, 0x16, 0x39, 0x82, 0xd7, 0x13, 0x81, 0x23, + 0xfa, 0x5f, 0xa8, 0x9d, 0x05, 0xf7, 0x12, 0x8a, 0x86, 0x5a, 0xd7, 0xbf, 0xa5, 0xc1, 0x5a, 0x93, + 0xea, 0xa2, 0x0d, 0x36, 0x13, 0x17, 0xf7, 0xf1, 0xb2, 0x84, 0x73, 0xb7, 0x22, 0x7f, 0xfc, 0x07, + 0x70, 0x98, 0xd9, 0xcb, 0x98, 0xb8, 0x3e, 0xab, 0x32, 0xc6, 0xe1, 0x95, 0x19, 0x17, 0x9d, 0x2b, + 0xf1, 0x35, 0x00, 0xb1, 0x33, 0x55, 0xbe, 0x55, 0xd1, 0x3c, 0x5b, 0xed, 0xd6, 0x68, 0x98, 0x2b, + 0xbf, 0xfe, 0xc6, 0x7b, 0x88, 0x1a, 0xad, 0x9b, 0xb1, 0x24, 0x8c, 0xc6, 0x92, 0xf0, 0x63, 0x2c, + 0x09, 0xef, 0x27, 0x52, 0x6a, 0x34, 0x91, 0x52, 0x5f, 0x27, 0x52, 0xea, 0xd5, 0x89, 0x6e, 0xb0, + 0x9e, 0xd3, 0x91, 0x35, 0x6c, 0x2a, 0x16, 0xee, 0xa2, 0xda, 0x51, 0xad, 0x6a, 0x60, 0xc5, 0x4f, + 0x54, 0x5d, 0xf4, 0x3c, 0x79, 0xc7, 0x81, 0x76, 0x36, 0xf8, 0x63, 0x7b, 0xfc, 0x33, 0x00, 0x00, + 0xff, 0xff, 0x8a, 0x6c, 0x49, 0x4f, 0x67, 0x06, 0x00, 0x00, } // Reference imports to suppress errors if they are not otherwise used. @@ -675,17 +674,17 @@ func (m *MsgRegisterKeys) MarshalToSizedBuffer(dAtA []byte) (int, error) { i-- dAtA[i] = 0x30 } - if len(m.MinaAddress) > 0 { - i -= len(m.MinaAddress) - copy(dAtA[i:], m.MinaAddress) - i = encodeVarintTx(dAtA, i, uint64(len(m.MinaAddress))) + if len(m.MinaPublicKey) > 0 { + i -= len(m.MinaPublicKey) + copy(dAtA[i:], m.MinaPublicKey) + i = encodeVarintTx(dAtA, i, uint64(len(m.MinaPublicKey))) i-- dAtA[i] = 0x2a } - if len(m.CosmosAddress) > 0 { - i -= len(m.CosmosAddress) - copy(dAtA[i:], m.CosmosAddress) - i = encodeVarintTx(dAtA, i, uint64(len(m.CosmosAddress))) + if len(m.CosmosPublicKey) > 0 { + i -= len(m.CosmosPublicKey) + copy(dAtA[i:], m.CosmosPublicKey) + i = encodeVarintTx(dAtA, i, uint64(len(m.CosmosPublicKey))) i-- dAtA[i] = 0x22 } @@ -875,11 +874,11 @@ func (m *MsgRegisterKeys) Size() (n int) { if l > 0 { n += 1 + l + sovTx(uint64(l)) } - l = len(m.CosmosAddress) + l = len(m.CosmosPublicKey) if l > 0 { n += 1 + l + sovTx(uint64(l)) } - l = len(m.MinaAddress) + l = len(m.MinaPublicKey) if l > 0 { n += 1 + l + sovTx(uint64(l)) } @@ -1237,7 +1236,7 @@ func (m *MsgRegisterKeys) Unmarshal(dAtA []byte) error { iNdEx = postIndex case 4: if wireType != 2 { - return fmt.Errorf("proto: wrong wireType = %d for field CosmosAddress", wireType) + return fmt.Errorf("proto: wrong wireType = %d for field CosmosPublicKey", wireType) } var byteLen int for shift := uint(0); ; shift += 7 { @@ -1264,14 +1263,14 @@ func (m *MsgRegisterKeys) Unmarshal(dAtA []byte) error { if postIndex > l { return io.ErrUnexpectedEOF } - m.CosmosAddress = append(m.CosmosAddress[:0], dAtA[iNdEx:postIndex]...) - if m.CosmosAddress == nil { - m.CosmosAddress = []byte{} + m.CosmosPublicKey = append(m.CosmosPublicKey[:0], dAtA[iNdEx:postIndex]...) + if m.CosmosPublicKey == nil { + m.CosmosPublicKey = []byte{} } iNdEx = postIndex case 5: if wireType != 2 { - return fmt.Errorf("proto: wrong wireType = %d for field MinaAddress", wireType) + return fmt.Errorf("proto: wrong wireType = %d for field MinaPublicKey", wireType) } var byteLen int for shift := uint(0); ; shift += 7 { @@ -1298,9 +1297,9 @@ func (m *MsgRegisterKeys) Unmarshal(dAtA []byte) error { if postIndex > l { return io.ErrUnexpectedEOF } - m.MinaAddress = append(m.MinaAddress[:0], dAtA[iNdEx:postIndex]...) - if m.MinaAddress == nil { - m.MinaAddress = []byte{} + m.MinaPublicKey = append(m.MinaPublicKey[:0], dAtA[iNdEx:postIndex]...) + if m.MinaPublicKey == nil { + m.MinaPublicKey = []byte{} } iNdEx = postIndex case 6: From 4766bf73fb7bf04c86d5d3a0bc798fb8f7ca7a97 Mon Sep 17 00:00:00 2001 From: Yusuf Date: Wed, 22 Apr 2026 20:05:38 +0300 Subject: [PATCH 09/62] fix: remove consaddress problems and fix overall logic --- .../keyregistry/v1/key_update_type.proto | 5 ++- .../keeper/msg_server_register_keys.go | 15 ++------ .../keeper/msg_server_register_user_keys.go | 8 ++-- .../msg_server_register_validator_keys.go | 9 +++-- .../keeper/msg_server_update_keys.go | 20 ++++++++-- x/keyregistry/module/autocli.go | 37 ++++++++++++------- x/keyregistry/types/errors.go | 1 + x/keyregistry/types/key_update_type.pb.go | 34 +++++++++-------- x/keyregistry/types/public_key_pairs.go | 7 ++-- x/keyregistry/types/tx.pb.go | 4 +- 10 files changed, 81 insertions(+), 59 deletions(-) diff --git a/proto/pulsarchain/keyregistry/v1/key_update_type.proto b/proto/pulsarchain/keyregistry/v1/key_update_type.proto index dd67defe..07e62970 100644 --- a/proto/pulsarchain/keyregistry/v1/key_update_type.proto +++ b/proto/pulsarchain/keyregistry/v1/key_update_type.proto @@ -4,6 +4,7 @@ package pulsarchain.keyregistry.v1; option go_package = "github.com/node101-io/pulsar-chain/x/keyregistry/types"; enum ActorType { - USER = 0; - VALIDATOR = 1; + UNSPECIFIED = 0; + USER = 1; + VALIDATOR = 2; } diff --git a/x/keyregistry/keeper/msg_server_register_keys.go b/x/keyregistry/keeper/msg_server_register_keys.go index a34e6325..ce901c65 100644 --- a/x/keyregistry/keeper/msg_server_register_keys.go +++ b/x/keyregistry/keeper/msg_server_register_keys.go @@ -3,7 +3,6 @@ package keeper import ( "context" - "github.com/cosmos/cosmos-sdk/crypto/keys/ed25519" "github.com/cosmos/cosmos-sdk/crypto/keys/secp256k1" sdk "github.com/cosmos/cosmos-sdk/types" "github.com/node101-io/pulsar-chain/x/keyregistry/types" @@ -30,16 +29,8 @@ func VerifyValidatorCosmosSig(sig string, msg, cosmosAddress []byte) bool { } // deriveAddressFromPubkey derives the expected signer address from the provided -// key material. Users provide secp256k1 account public keys, while validators -// provide consensus public keys. -func deriveAddressFromPubkey(cosmosAddress []byte, isUser bool) string { - if !isUser { - pubKey := ed25519.PubKey{ - Key: cosmosAddress, - } - validatorAddr := sdk.ConsAddress(pubKey.Address()) - return validatorAddr.String() - } +// key material. +func deriveAddressFromPubkey(cosmosAddress []byte) string { pubKey := secp256k1.PubKey{ Key: cosmosAddress, @@ -67,6 +58,8 @@ func (k msgServer) RegisterKeys(ctx context.Context, msg *types.MsgRegisterKeys) err = k.handleUserRegistration(ctx, msg) case types.ActorType_VALIDATOR: err = k.handleValidatorRegistration(ctx, msg) + default: + return nil, types.ErrInvalidActorType } if err != nil { return nil, err diff --git a/x/keyregistry/keeper/msg_server_register_user_keys.go b/x/keyregistry/keeper/msg_server_register_user_keys.go index b5f96976..b500d4aa 100644 --- a/x/keyregistry/keeper/msg_server_register_user_keys.go +++ b/x/keyregistry/keeper/msg_server_register_user_keys.go @@ -1,16 +1,14 @@ package keeper import ( - "bytes" "context" errorsmod "cosmossdk.io/errors" - sdk "github.com/cosmos/cosmos-sdk/types" "github.com/node101-io/pulsar-chain/x/keyregistry/types" ) func (k msgServer) handleUserRegistration(ctx context.Context, msg *types.MsgRegisterKeys) error { - creatorAddress, err := k.addressCodec.StringToBytes(msg.Creator) + _, err := k.addressCodec.StringToBytes(msg.Creator) if err != nil { return errorsmod.Wrap(types.ErrInvalidCreatorAddres, "") } @@ -23,9 +21,9 @@ func (k msgServer) handleUserRegistration(ctx context.Context, msg *types.MsgReg return errorsmod.Wrap(types.ErrInvalidPublicKey, "") } - cosmosAddr := sdk.AccAddress(msg.CosmosPublicKey) + cosmosAddr := deriveAddressFromPubkey(msg.CosmosPublicKey) - if !bytes.Equal(creatorAddress, cosmosAddr.Bytes()) { + if msg.Creator != cosmosAddr { return errorsmod.Wrap(types.ErrInvalidSigner, "") } diff --git a/x/keyregistry/keeper/msg_server_register_validator_keys.go b/x/keyregistry/keeper/msg_server_register_validator_keys.go index f1346226..38235fbd 100644 --- a/x/keyregistry/keeper/msg_server_register_validator_keys.go +++ b/x/keyregistry/keeper/msg_server_register_validator_keys.go @@ -9,9 +9,9 @@ import ( ) // handleValidatorRegistration encapsulates the validator registration flow -// where the Cosmos-side key is the validator consensus public key. +// where the Cosmos-side key is the validator public key. func (k msgServer) handleValidatorRegistration(ctx context.Context, msg *types.MsgRegisterKeys) error { - _, err := sdk.ConsAddressFromBech32(msg.Creator) + _, err := sdk.AccAddressFromBech32(msg.Creator) if err != nil { return errorsmod.Wrap(types.ErrInvalidCreatorAddres, "") } @@ -24,9 +24,10 @@ func (k msgServer) handleValidatorRegistration(ctx context.Context, msg *types.M return errorsmod.Wrap(types.ErrInvalidPublicKey, "pubkeys must be valid") } - derivedAddress := deriveAddressFromPubkey(msg.CosmosPublicKey, false) + derivedAddress := deriveAddressFromPubkey(msg.CosmosPublicKey) + if derivedAddress != msg.Creator { - return errorsmod.Wrap(types.ErrInvalidSigner, "creator does not match provided cosmos consensus public key") + return errorsmod.Wrap(types.ErrInvalidSigner, "creator does not match provided cosmos public key") } return k.persistValidatorRegistration(ctx, msg) diff --git a/x/keyregistry/keeper/msg_server_update_keys.go b/x/keyregistry/keeper/msg_server_update_keys.go index 5a547d9c..4f62dc86 100644 --- a/x/keyregistry/keeper/msg_server_update_keys.go +++ b/x/keyregistry/keeper/msg_server_update_keys.go @@ -4,19 +4,27 @@ import ( "bytes" "context" + "cosmossdk.io/errors" errorsmod "cosmossdk.io/errors" sdk "github.com/cosmos/cosmos-sdk/types" + "github.com/node101-io/mina-signer-go/keys" "github.com/node101-io/pulsar-chain/x/keyregistry/types" ) func (k msgServer) UpdateKeys(ctx context.Context, msg *types.MsgUpdateKeys) (*types.MsgUpdateKeysResponse, error) { var err error + if len(msg.NewMinaPublicKey) != keys.PublicKeyTotalByteSize { + return nil, errors.Wrap(types.ErrInvalidPublicKey, "") + } + switch msg.ActorType { case types.ActorType_USER: err = k.updateUserKeys(ctx, msg) case types.ActorType_VALIDATOR: err = k.updateValidatorKeys(ctx, msg) + default: + return nil, types.ErrInvalidActorType } if err != nil { return nil, err @@ -26,7 +34,7 @@ func (k msgServer) UpdateKeys(ctx context.Context, msg *types.MsgUpdateKeys) (*t } func (k msgServer) updateUserKeys(ctx context.Context, msg *types.MsgUpdateKeys) error { - creatorAddress, err := k.addressCodec.StringToBytes(msg.Creator) + _, err := k.addressCodec.StringToBytes(msg.Creator) if err != nil { return errorsmod.Wrap(types.ErrInvalidCreatorAddres, "") } @@ -43,7 +51,10 @@ func (k msgServer) updateUserKeys(ctx context.Context, msg *types.MsgUpdateKeys) if err != nil { return err } - if !bytes.Equal(creatorAddress, cosmosPublicKey) { + + cosmosAddr := deriveAddressFromPubkey(cosmosPublicKey) + + if msg.Creator != cosmosAddr { return errorsmod.Wrap(types.ErrInvalidSigner, "") } @@ -91,7 +102,7 @@ func (k msgServer) updateUserKeys(ctx context.Context, msg *types.MsgUpdateKeys) } func (k msgServer) updateValidatorKeys(ctx context.Context, msg *types.MsgUpdateKeys) error { - if _, err := sdk.ConsAddressFromBech32(msg.Creator); err != nil { + if _, err := sdk.AccAddressFromBech32(msg.Creator); err != nil { return errorsmod.Wrap(types.ErrInvalidCreatorAddres, "") } @@ -107,7 +118,8 @@ func (k msgServer) updateValidatorKeys(ctx context.Context, msg *types.MsgUpdate if err != nil { return err } - if deriveAddressFromPubkey(cosmosPublicKey, false) != msg.Creator { + + if deriveAddressFromPubkey(cosmosPublicKey) != msg.Creator { return errorsmod.Wrap(types.ErrInvalidSigner, "") } diff --git a/x/keyregistry/module/autocli.go b/x/keyregistry/module/autocli.go index 8b8c8bbb..f52a38bb 100644 --- a/x/keyregistry/module/autocli.go +++ b/x/keyregistry/module/autocli.go @@ -33,15 +33,15 @@ func (am AppModule) AutoCLIOptions() *autocliv1.ModuleOptions { { RpcMethod: "GetValidatorMinaPubKey", - Use: "get-validator-mina-pub-key [validator-cosmos-address]", - Short: "Query GetValidatorMinaAddress", + Use: "get-validator-mina-pub-key [validator-cosmos-pub-key]", + Short: "Query GetValidatorMinaPubKey", PositionalArgs: []*autocliv1.PositionalArgDescriptor{{ProtoField: "validator_cosmos_pub_key", Varargs: true}}, }, { RpcMethod: "GetValidatorCosmosPubKey", - Use: "get-validator-cosmos-address [validator-mina-pub-key]", - Short: "Query GetValidatorCosmosAddress", + Use: "get-validator-cosmos-pub-key [validator-mina-pub-key]", + Short: "Query GetValidatorCosmosPubKey", PositionalArgs: []*autocliv1.PositionalArgDescriptor{{ProtoField: "validator_mina_pub_key", Varargs: true}}, }, @@ -57,18 +57,29 @@ func (am AppModule) AutoCLIOptions() *autocliv1.ModuleOptions { Skip: true, // skipped because authority gated }, { - RpcMethod: "RegisterKeys", - Use: "register-keys [cosmos-signature] [mina-signature] [cosmos-public-key] [mina-public-key]", - Short: "Send a registerKeys tx", - PositionalArgs: []*autocliv1.PositionalArgDescriptor{{ProtoField: "cosmos_signature"}, {ProtoField: "mina_signature"}, {ProtoField: "cosmos_public_key"}, {ProtoField: "mina_public_key", Varargs: true}}, + RpcMethod: "RegisterKeys", + Use: "register-keys [actor-type] [cosmos-signature] [mina-signature] [cosmos-public-key] [mina-public-key]", + Short: "Send a RegisterKeys tx", + PositionalArgs: []*autocliv1.PositionalArgDescriptor{ + {ProtoField: "actor_type"}, + {ProtoField: "cosmos_signature"}, + {ProtoField: "mina_signature"}, + {ProtoField: "cosmos_public_key"}, + {ProtoField: "mina_public_key"}, + }, }, { - RpcMethod: "UpdateKeys", - Use: "update-keys ", - Short: "Send a UpdateKeys tx", - PositionalArgs: []*autocliv1.PositionalArgDescriptor{}, + RpcMethod: "UpdateKeys", + Use: "update-keys [actor-type] [prev-mina-public-key] [new-mina-public-key] [cosmos-signature] [new-mina-signature]", + Short: "Send an UpdateKeys tx", + PositionalArgs: []*autocliv1.PositionalArgDescriptor{ + {ProtoField: "actor_type"}, + {ProtoField: "prev_mina_public_key"}, + {ProtoField: "new_mina_public_key"}, + {ProtoField: "cosmos_signature"}, + {ProtoField: "new_mina_signature"}, + }, }, - // this line is used by ignite scaffolding # autocli/tx }, }, } diff --git a/x/keyregistry/types/errors.go b/x/keyregistry/types/errors.go index a4b97564..8854acf7 100644 --- a/x/keyregistry/types/errors.go +++ b/x/keyregistry/types/errors.go @@ -16,4 +16,5 @@ var ( ErrInvalidPublicKey = errors.Register(ModuleName, 1105, "invalid public key") ErrUserNotRegistered = errors.Register(ModuleName, 1106, "user has not been registered") ErrValidatorNotRegistered = errors.Register(ModuleName, 1107, "validator has not been registered") + ErrInvalidActorType = errors.Register(ModuleName, 1108, "invalid actor type") ) diff --git a/x/keyregistry/types/key_update_type.pb.go b/x/keyregistry/types/key_update_type.pb.go index 861effce..083028ac 100644 --- a/x/keyregistry/types/key_update_type.pb.go +++ b/x/keyregistry/types/key_update_type.pb.go @@ -23,18 +23,21 @@ const _ = proto.GoGoProtoPackageIsVersion3 // please upgrade the proto package type ActorType int32 const ( - ActorType_USER ActorType = 0 - ActorType_VALIDATOR ActorType = 1 + ActorType_UNSPECIFIED ActorType = 0 + ActorType_USER ActorType = 1 + ActorType_VALIDATOR ActorType = 2 ) var ActorType_name = map[int32]string{ - 0: "USER", - 1: "VALIDATOR", + 0: "UNSPECIFIED", + 1: "USER", + 2: "VALIDATOR", } var ActorType_value = map[string]int32{ - "USER": 0, - "VALIDATOR": 1, + "UNSPECIFIED": 0, + "USER": 1, + "VALIDATOR": 2, } func (x ActorType) String() string { @@ -54,17 +57,18 @@ func init() { } var fileDescriptor_ba25ac2a902d16f7 = []byte{ - // 189 bytes of a gzipped FileDescriptorProto + // 206 bytes of a gzipped FileDescriptorProto 0x1f, 0x8b, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0xff, 0xe2, 0x32, 0x28, 0x28, 0xcd, 0x29, 0x4e, 0x2c, 0x4a, 0xce, 0x48, 0xcc, 0xcc, 0xd3, 0xcf, 0x4e, 0xad, 0x2c, 0x4a, 0x4d, 0xcf, 0x2c, 0x2e, 0x29, 0xaa, 0xd4, 0x2f, 0x33, 0x04, 0x71, 0xe3, 0x4b, 0x0b, 0x52, 0x12, 0x4b, 0x52, 0xe3, 0x4b, 0x2a, 0x0b, 0x52, 0xf5, 0x0a, 0x8a, 0xf2, 0x4b, 0xf2, 0x85, 0xa4, 0x90, 0x74, 0xe8, 0x21, - 0xe9, 0xd0, 0x2b, 0x33, 0xd4, 0x52, 0xe1, 0xe2, 0x74, 0x4c, 0x2e, 0xc9, 0x2f, 0x0a, 0xa9, 0x2c, - 0x48, 0x15, 0xe2, 0xe0, 0x62, 0x09, 0x0d, 0x76, 0x0d, 0x12, 0x60, 0x10, 0xe2, 0xe5, 0xe2, 0x0c, - 0x73, 0xf4, 0xf1, 0x74, 0x71, 0x0c, 0xf1, 0x0f, 0x12, 0x60, 0x74, 0x0a, 0x38, 0xf1, 0x48, 0x8e, - 0xf1, 0xc2, 0x23, 0x39, 0xc6, 0x07, 0x8f, 0xe4, 0x18, 0x27, 0x3c, 0x96, 0x63, 0xb8, 0xf0, 0x58, - 0x8e, 0xe1, 0xc6, 0x63, 0x39, 0x86, 0x28, 0xb3, 0xf4, 0xcc, 0x92, 0x8c, 0xd2, 0x24, 0xbd, 0xe4, - 0xfc, 0x5c, 0xfd, 0xbc, 0xfc, 0x94, 0x54, 0x43, 0x03, 0x43, 0xdd, 0xcc, 0x7c, 0x7d, 0x88, 0x8d, - 0xba, 0x10, 0x47, 0x56, 0xa0, 0x38, 0x13, 0xe4, 0xb0, 0xe2, 0x24, 0x36, 0xb0, 0xd3, 0x8c, 0x01, - 0x01, 0x00, 0x00, 0xff, 0xff, 0x7f, 0x85, 0x42, 0x77, 0xce, 0x00, 0x00, 0x00, + 0xe9, 0xd0, 0x2b, 0x33, 0xd4, 0x32, 0xe5, 0xe2, 0x74, 0x4c, 0x2e, 0xc9, 0x2f, 0x0a, 0xa9, 0x2c, + 0x48, 0x15, 0xe2, 0xe7, 0xe2, 0x0e, 0xf5, 0x0b, 0x0e, 0x70, 0x75, 0xf6, 0x74, 0xf3, 0x74, 0x75, + 0x11, 0x60, 0x10, 0xe2, 0xe0, 0x62, 0x09, 0x0d, 0x76, 0x0d, 0x12, 0x60, 0x14, 0xe2, 0xe5, 0xe2, + 0x0c, 0x73, 0xf4, 0xf1, 0x74, 0x71, 0x0c, 0xf1, 0x0f, 0x12, 0x60, 0x72, 0x0a, 0x38, 0xf1, 0x48, + 0x8e, 0xf1, 0xc2, 0x23, 0x39, 0xc6, 0x07, 0x8f, 0xe4, 0x18, 0x27, 0x3c, 0x96, 0x63, 0xb8, 0xf0, + 0x58, 0x8e, 0xe1, 0xc6, 0x63, 0x39, 0x86, 0x28, 0xb3, 0xf4, 0xcc, 0x92, 0x8c, 0xd2, 0x24, 0xbd, + 0xe4, 0xfc, 0x5c, 0xfd, 0xbc, 0xfc, 0x94, 0x54, 0x43, 0x03, 0x43, 0xdd, 0xcc, 0x7c, 0x7d, 0x88, + 0x13, 0x74, 0x21, 0xae, 0xae, 0x40, 0x71, 0x37, 0xc8, 0xa5, 0xc5, 0x49, 0x6c, 0x60, 0xb7, 0x1a, + 0x03, 0x02, 0x00, 0x00, 0xff, 0xff, 0xba, 0xc7, 0x23, 0x30, 0xdf, 0x00, 0x00, 0x00, } diff --git a/x/keyregistry/types/public_key_pairs.go b/x/keyregistry/types/public_key_pairs.go index 1d1998dd..69fb2bf4 100644 --- a/x/keyregistry/types/public_key_pairs.go +++ b/x/keyregistry/types/public_key_pairs.go @@ -2,7 +2,7 @@ package types import ( "cosmossdk.io/errors" - "github.com/cosmos/cosmos-sdk/crypto/keys/ed25519" + "github.com/cometbft/cometbft/crypto/secp256k1" "github.com/node101-io/mina-signer-go/keys" ) @@ -18,8 +18,9 @@ func DefaultPublicKeyPair() []*PublicKeyPair { } func ValidatePublicKeyPair(k PublicKeyPair) error { - if len(k.CosmosKey) != ed25519.PubKeySize { - return errors.Wrap(ErrInvalidPublicKey, "cosmos consensus public key must be ed25519 (32 bytes)") + + if len(k.CosmosKey) != secp256k1.PubKeySize { + return errors.Wrap(ErrInvalidPublicKey, "cosmos public key must be secp256k1 (33 bytes)") } if len(k.MinaKey) != keys.PublicKeyTotalByteSize { diff --git a/x/keyregistry/types/tx.pb.go b/x/keyregistry/types/tx.pb.go index 1362b014..51e23a3b 100644 --- a/x/keyregistry/types/tx.pb.go +++ b/x/keyregistry/types/tx.pb.go @@ -206,7 +206,7 @@ func (m *MsgRegisterKeys) GetActorType() ActorType { if m != nil { return m.ActorType } - return ActorType_USER + return ActorType_UNSPECIFIED } // MsgRegisterKeysResponse defines the MsgRegisterKeysResponse message. @@ -328,7 +328,7 @@ func (m *MsgUpdateKeys) GetActorType() ActorType { if m != nil { return m.ActorType } - return ActorType_USER + return ActorType_UNSPECIFIED } // MsgUpdateKeysResponse defines the MsgUpdateKeysResponse message. From e2ffb290b890eee8ff1b8fcb0fbd1278d2767780 Mon Sep 17 00:00:00 2001 From: Yusuf Date: Wed, 22 Apr 2026 20:05:55 +0300 Subject: [PATCH 10/62] test: make tests compatible with the new logic --- .../keeper/query_validator_keypairs_test.go | 8 +- .../keeper/user_register_keys_test.go | 102 ++++++++---- x/keyregistry/keeper/user_update_keys_test.go | 153 ++++++++++-------- .../keeper/validator_register_keys_test.go | 80 +++++---- .../keeper/validator_update_keys_test.go | 146 ++++++++--------- 5 files changed, 275 insertions(+), 214 deletions(-) diff --git a/x/keyregistry/keeper/query_validator_keypairs_test.go b/x/keyregistry/keeper/query_validator_keypairs_test.go index a9e40862..0e2395fe 100644 --- a/x/keyregistry/keeper/query_validator_keypairs_test.go +++ b/x/keyregistry/keeper/query_validator_keypairs_test.go @@ -35,7 +35,7 @@ func TestValidatorCosmosMapSuccess(t *testing.T) { params := types.DefaultParams() require.NoError(t, f.keeper.Params.Set(f.ctx, params)) - cosmosPubKey, minaPubKey, err := generateValidatorPublicKeys() + cosmosPubKey, minaPubKey, _, err := generatePublicKeys() require.NoError(t, err) err = f.keeper.ValidatorSetCosmosToMina(f.ctx, cosmosPubKey.Bytes(), minaPubKey) @@ -60,7 +60,7 @@ func TestValidatorMinaMapSuccess(t *testing.T) { params := types.DefaultParams() require.NoError(t, f.keeper.Params.Set(f.ctx, params)) - cosmosPubKey, minaPubKey, err := generateValidatorPublicKeys() + cosmosPubKey, minaPubKey, _, err := generatePublicKeys() require.NoError(t, err) err = f.keeper.ValidatorSetMinaToCosmos(f.ctx, minaPubKey, cosmosPubKey.Bytes()) @@ -100,7 +100,7 @@ func TestValidatorCosmosMapPubkeyNotFound(t *testing.T) { params := types.DefaultParams() require.NoError(t, f.keeper.Params.Set(f.ctx, params)) - _, minaPubKey, err := generateValidatorPublicKeys() + _, minaPubKey, _, err := generatePublicKeys() require.NotNil(t, minaPubKey) require.NoError(t, err) @@ -121,7 +121,7 @@ func TestValidatorMinaMapPubkeyNotFound(t *testing.T) { params := types.DefaultParams() require.NoError(t, f.keeper.Params.Set(f.ctx, params)) - cosmosPubKey, minaPubKey, err := generateValidatorPublicKeys() + cosmosPubKey, minaPubKey, _, err := generatePublicKeys() require.NotNil(t, cosmosPubKey) require.NotNil(t, minaPubKey) require.NoError(t, err) diff --git a/x/keyregistry/keeper/user_register_keys_test.go b/x/keyregistry/keeper/user_register_keys_test.go index ebe6c7e7..669ac2ae 100644 --- a/x/keyregistry/keeper/user_register_keys_test.go +++ b/x/keyregistry/keeper/user_register_keys_test.go @@ -1,9 +1,10 @@ package keeper_test import ( - "crypto/rand" "testing" + "github.com/cometbft/cometbft/crypto" + "github.com/cometbft/cometbft/crypto/secp256k1" sdk "github.com/cosmos/cosmos-sdk/types" "github.com/node101-io/mina-signer-go/keys" "github.com/node101-io/pulsar-chain/x/keyregistry/keeper" @@ -18,18 +19,26 @@ var mockMinaSignature = "minaSig" var MinaPriv = []byte("7olA5Knafb5E2hJoWFzD+oamtyXIXXUZmYG9+pBMjTGIjqZTVLNGbE7DQ3Zq5YL5NMW31UMMMGgNCeEk+gyzRA==") -func generateAddress() (sdk.AccAddress, []byte, error) { - cosmosAddr := make(sdk.AccAddress, 32) - _, err := rand.Read(cosmosAddr) - if err != nil { - return nil, nil, err - } +func generatePublicKeys() (crypto.PubKey, []byte, []byte, error) { + + cosmosPrivKey := secp256k1.GenPrivKey() + cosmosPublicKey := cosmosPrivKey.PubKey() minaPrivKey := keys.NewPrivateKeyFromBytes([32]byte(MinaPriv)) minaPublicKey, err := minaPrivKey.ToPublicKey().Marshal() + if err != nil { + return nil, nil, nil, err + } + + minaSecondaryPrivKey := keys.NewPrivateKeyFromBytes([32]byte(MinaSecondaryPriv)) - return cosmosAddr, minaPublicKey, err + minaSecondaryPublicKey, err := minaSecondaryPrivKey.ToPublicKey().Marshal() + if err != nil { + return nil, nil, nil, err + } + + return cosmosPublicKey, minaPublicKey, minaSecondaryPublicKey, nil } // TestUserRegisterKeysFail verifies that RegisterKeys fails with ErrInvalidPublicKey @@ -40,6 +49,7 @@ func TestUserRegisterKeysFail(t *testing.T) { ms := keeper.NewMsgServerImpl(f.keeper) creatorAddr := sdk.AccAddress([]byte("pulsar")) + _, err := ms.RegisterKeys(f.ctx, &types.MsgRegisterKeys{ Creator: creatorAddr.String(), CosmosSignature: mockCosmosSignature, @@ -55,28 +65,34 @@ func TestUserRegisterKeysFail(t *testing.T) { // and ensures that both CosmosToMina and MinaToCosmos mappings are correctly stored. func TestUserRegisterKeysSuccess(t *testing.T) { - cosmosAddr, minaAddr, err := generateAddress() + cosmosPublicKey, minaPubKey, _, err := generatePublicKeys() require.NoError(t, err) + require.NotNil(t, cosmosPublicKey) + require.NotNil(t, minaPubKey) + + creatorAddr := sdk.AccAddress(cosmosPublicKey.Address()) + require.NotNil(t, creatorAddr) f := initFixture(t) ms := keeper.NewMsgServerImpl(f.keeper) resp, err := ms.RegisterKeys(f.ctx, &types.MsgRegisterKeys{ - Creator: cosmosAddr.String(), + Creator: creatorAddr.String(), CosmosSignature: mockCosmosSignature, MinaSignature: mockMinaSignature, - CosmosPublicKey: cosmosAddr.Bytes(), - MinaPublicKey: minaAddr, + CosmosPublicKey: cosmosPublicKey.Bytes(), + MinaPublicKey: minaPubKey, ActorType: types.ActorType_USER, }) + require.NoError(t, err) require.NotNil(t, resp) - exists, err := f.keeper.UserCosmosToMinaHas(f.ctx, cosmosAddr.Bytes()) + exists, err := f.keeper.UserCosmosToMinaHas(f.ctx, cosmosPublicKey.Bytes()) require.NoError(t, err) require.Equal(t, exists, true) - exists, err = f.keeper.UserMinaToCosmosHas(f.ctx, minaAddr) + exists, err = f.keeper.UserMinaToCosmosHas(f.ctx, minaPubKey) require.NoError(t, err) require.Equal(t, exists, true) @@ -86,7 +102,10 @@ func TestUserRegisterKeysSuccess(t *testing.T) { // when the creator field is not a valid bech32 address. func TestUserInvalidCreatorAddress(t *testing.T) { - cosmosAddr, minaAddr, err := generateAddress() + cosmosPublicKey, minaPubKey, _, err := generatePublicKeys() + + require.NotNil(t, cosmosPublicKey) + require.NotNil(t, minaPubKey) require.NoError(t, err) f := initFixture(t) @@ -96,8 +115,8 @@ func TestUserInvalidCreatorAddress(t *testing.T) { Creator: "creator", CosmosSignature: mockCosmosSignature, MinaSignature: mockMinaSignature, - CosmosPublicKey: cosmosAddr.Bytes(), - MinaPublicKey: minaAddr, + CosmosPublicKey: cosmosPublicKey.Bytes(), + MinaPublicKey: minaPubKey, ActorType: types.ActorType_USER, }) require.ErrorIs(t, err, types.ErrInvalidCreatorAddres) @@ -107,21 +126,27 @@ func TestUserInvalidCreatorAddress(t *testing.T) { // when the creator address bytes do not match the provided Cosmos-side value. func TestUserInvalidSigner(t *testing.T) { - cosmosAddr, minaAddr, err := generateAddress() + cosmosPublicKey, minaPubKey, _, err := generatePublicKeys() require.NoError(t, err) + require.NotNil(t, cosmosPublicKey) + require.NotNil(t, minaPubKey) - addr, _, err := generateAddress() + secondaryCosmosPublicKey, _, _, err := generatePublicKeys() require.NoError(t, err) + require.NotNil(t, secondaryCosmosPublicKey) + + creatorAddr := sdk.AccAddress(secondaryCosmosPublicKey.Address()) + require.NotNil(t, creatorAddr) f := initFixture(t) ms := keeper.NewMsgServerImpl(f.keeper) _, err = ms.RegisterKeys(f.ctx, &types.MsgRegisterKeys{ - Creator: addr.String(), + Creator: creatorAddr.String(), CosmosSignature: mockCosmosSignature, MinaSignature: mockMinaSignature, - CosmosPublicKey: cosmosAddr.Bytes(), - MinaPublicKey: minaAddr, + CosmosPublicKey: cosmosPublicKey.Bytes(), + MinaPublicKey: minaPubKey, ActorType: types.ActorType_USER, }) @@ -133,21 +158,26 @@ func TestUserInvalidSigner(t *testing.T) { // TestUserInvalidSignature currently expects no error since signature verification is not yet implemented. func TestUserInvalidSignature(t *testing.T) { - cosmosAddr, minaAddr, err := generateAddress() + cosmosPublicKey, minaPubKey, _, err := generatePublicKeys() require.NoError(t, err) + require.NotNil(t, cosmosPublicKey) + require.NotNil(t, minaPubKey) f := initFixture(t) ms := keeper.NewMsgServerImpl(f.keeper) + creatorAddr := sdk.AccAddress(cosmosPublicKey.Address()) + require.NotNil(t, creatorAddr) + invalidSig := "cosmosSig" _, err = ms.RegisterKeys(f.ctx, &types.MsgRegisterKeys{ - Creator: cosmosAddr.String(), + Creator: creatorAddr.String(), CosmosSignature: invalidSig, MinaSignature: mockMinaSignature, - CosmosPublicKey: cosmosAddr.Bytes(), - MinaPublicKey: minaAddr, + CosmosPublicKey: cosmosPublicKey.Bytes(), + MinaPublicKey: minaPubKey, ActorType: types.ActorType_USER, }) @@ -160,18 +190,24 @@ func TestUserInvalidSignature(t *testing.T) { func TestUserInsertSecondaryKeysFail(t *testing.T) { f := initFixture(t) - cosmosAddr, minaAddr, err := generateAddress() + cosmosPublicKey, minaPubKey, minaSecondaryPublicKey, err := generatePublicKeys() require.NoError(t, err) + require.NotNil(t, cosmosPublicKey) + require.NotNil(t, minaPubKey) + require.NotNil(t, minaSecondaryPublicKey) ms := keeper.NewMsgServerImpl(f.keeper) + creatorAddr := sdk.AccAddress(cosmosPublicKey.Address()) + require.NotNil(t, creatorAddr) + // First registration should succeed. resp, err := ms.RegisterKeys(f.ctx, &types.MsgRegisterKeys{ - Creator: cosmosAddr.String(), + Creator: creatorAddr.String(), CosmosSignature: mockCosmosSignature, MinaSignature: mockMinaSignature, - CosmosPublicKey: cosmosAddr.Bytes(), - MinaPublicKey: minaAddr, + CosmosPublicKey: cosmosPublicKey.Bytes(), + MinaPublicKey: minaPubKey, ActorType: types.ActorType_USER, }) require.NoError(t, err) @@ -179,11 +215,11 @@ func TestUserInsertSecondaryKeysFail(t *testing.T) { // Second registration with the same keys should fail. resp, err = ms.RegisterKeys(f.ctx, &types.MsgRegisterKeys{ - Creator: cosmosAddr.String(), + Creator: creatorAddr.String(), CosmosSignature: mockCosmosSignature, MinaSignature: mockMinaSignature, - CosmosPublicKey: cosmosAddr.Bytes(), - MinaPublicKey: minaAddr, + CosmosPublicKey: cosmosPublicKey.Bytes(), + MinaPublicKey: minaSecondaryPublicKey, ActorType: types.ActorType_USER, }) diff --git a/x/keyregistry/keeper/user_update_keys_test.go b/x/keyregistry/keeper/user_update_keys_test.go index cbb39d6f..f4dc5493 100644 --- a/x/keyregistry/keeper/user_update_keys_test.go +++ b/x/keyregistry/keeper/user_update_keys_test.go @@ -1,69 +1,57 @@ package keeper_test import ( - "crypto/rand" "testing" + "github.com/cometbft/cometbft/crypto" sdk "github.com/cosmos/cosmos-sdk/types" - "github.com/node101-io/mina-signer-go/keys" "github.com/node101-io/pulsar-chain/x/keyregistry/keeper" "github.com/node101-io/pulsar-chain/x/keyregistry/types" "github.com/stretchr/testify/require" ) -func generateUserAddressPair() (sdk.AccAddress, []byte, error) { - cosmosAddr := make(sdk.AccAddress, 32) - _, err := rand.Read(cosmosAddr) - if err != nil { - return nil, nil, err - } - - var minaSeed [32]byte - _, err = rand.Read(minaSeed[:]) - if err != nil { - return nil, nil, err - } - - minaPublicKey, err := keys.NewPrivateKeyFromBytes(minaSeed).ToPublicKey().Marshal() - if err != nil { - return nil, nil, err - } - - return cosmosAddr, minaPublicKey, nil -} +var MinaSecondaryPriv = []byte("0GUKibsJSZwgiU7k4cXQQWb2QKEP9/iRFATJEUqf2Pc+GxciLMKRQGTIcInKsTzV09rjDsLmZiBl9Up71bvV6g==") -func registerUserKeysForUpdateTest(t *testing.T, f *fixture, ms types.MsgServer) (sdk.AccAddress, []byte) { +func registerKeysForUpdateTest(t *testing.T, f *fixture, ms types.MsgServer, ActorType types.ActorType) (crypto.PubKey, []byte, []byte) { t.Helper() - cosmosAddr, minaAddr, err := generateUserAddressPair() + cosmosPublicKey, minaPublicKey, minaSecondaryPublicKey, err := generatePublicKeys() + require.NotNil(t, cosmosPublicKey) + require.NotNil(t, minaPublicKey) + require.NotNil(t, minaSecondaryPublicKey) + require.NoError(t, err) + creatorAddr := sdk.AccAddress(cosmosPublicKey.Address()) + require.NotNil(t, creatorAddr) + resp, err := ms.RegisterKeys(f.ctx, &types.MsgRegisterKeys{ - Creator: cosmosAddr.String(), + Creator: creatorAddr.String(), CosmosSignature: mockCosmosSignature, MinaSignature: mockMinaSignature, - CosmosPublicKey: cosmosAddr.Bytes(), - MinaPublicKey: minaAddr, - ActorType: types.ActorType_USER, + CosmosPublicKey: cosmosPublicKey.Bytes(), + MinaPublicKey: minaPublicKey, + ActorType: ActorType, }) require.NoError(t, err) require.NotNil(t, resp) - return cosmosAddr, minaAddr + return cosmosPublicKey, minaPublicKey, minaSecondaryPublicKey } func TestUserUpdateKeysSuccess(t *testing.T) { f := initFixture(t) ms := keeper.NewMsgServerImpl(f.keeper) - cosmosAddr, prevMinaAddr := registerUserKeysForUpdateTest(t, f, ms) - _, newMinaAddr, err := generateUserAddressPair() - require.NoError(t, err) + cosmosPublicKey, prevMinaPublicKey, newMinaPublicKey := registerKeysForUpdateTest(t, f, ms, types.ActorType_USER) + + creatorAddr := sdk.AccAddress(cosmosPublicKey.Address()) + require.NotNil(t, creatorAddr) resp, err := ms.UpdateKeys(f.ctx, &types.MsgUpdateKeys{ - Creator: cosmosAddr.String(), - PrevMinaPublicKey: prevMinaAddr, - NewMinaPublicKey: newMinaAddr, + Creator: creatorAddr.String(), + PrevMinaPublicKey: prevMinaPublicKey, + NewMinaPublicKey: newMinaPublicKey, CosmosSignature: []byte(mockCosmosSignature), NewMinaSignature: []byte(mockMinaSignature), ActorType: types.ActorType_USER, @@ -71,36 +59,40 @@ func TestUserUpdateKeysSuccess(t *testing.T) { require.NoError(t, err) require.NotNil(t, resp) - exists, err := f.keeper.UserMinaToCosmosHas(f.ctx, prevMinaAddr) + exists, err := f.keeper.UserMinaToCosmosHas(f.ctx, prevMinaPublicKey) require.NoError(t, err) require.False(t, exists) - exists, err = f.keeper.UserMinaToCosmosHas(f.ctx, newMinaAddr) + exists, err = f.keeper.UserMinaToCosmosHas(f.ctx, newMinaPublicKey) require.NoError(t, err) require.True(t, exists) - minaAddr, err := f.keeper.UserGetCosmosToMina(f.ctx, cosmosAddr.Bytes()) + minaAddr, err := f.keeper.UserGetCosmosToMina(f.ctx, cosmosPublicKey.Bytes()) require.NoError(t, err) - require.Equal(t, newMinaAddr, minaAddr) + require.Equal(t, newMinaPublicKey, minaAddr) - storedCosmosAddr, err := f.keeper.UserGetMinaToCosmos(f.ctx, newMinaAddr) + storedCosmosAddr, err := f.keeper.UserGetMinaToCosmos(f.ctx, newMinaPublicKey) require.NoError(t, err) - require.Equal(t, cosmosAddr.Bytes(), storedCosmosAddr) + require.Equal(t, cosmosPublicKey.Bytes(), storedCosmosAddr) } func TestUserUpdateKeysNotRegistered(t *testing.T) { f := initFixture(t) ms := keeper.NewMsgServerImpl(f.keeper) - cosmosAddr, prevMinaAddr, err := generateUserAddressPair() - require.NoError(t, err) - _, newMinaAddr, err := generateUserAddressPair() + cosmosPublicKey, prevMinaPublicKey, minaSecondaryPublicKey, err := generatePublicKeys() require.NoError(t, err) + require.NotNil(t, cosmosPublicKey) + require.NotNil(t, prevMinaPublicKey) + require.NotNil(t, minaSecondaryPublicKey) + + creatorAddr := sdk.AccAddress(cosmosPublicKey.Address()) + require.NotNil(t, creatorAddr) _, err = ms.UpdateKeys(f.ctx, &types.MsgUpdateKeys{ - Creator: cosmosAddr.String(), - PrevMinaPublicKey: prevMinaAddr, - NewMinaPublicKey: newMinaAddr, + Creator: creatorAddr.String(), + PrevMinaPublicKey: prevMinaPublicKey, + NewMinaPublicKey: minaSecondaryPublicKey, CosmosSignature: []byte(mockCosmosSignature), NewMinaSignature: []byte(mockMinaSignature), ActorType: types.ActorType_USER, @@ -112,19 +104,17 @@ func TestUserUpdateKeysInvalidCreatorAddress(t *testing.T) { f := initFixture(t) ms := keeper.NewMsgServerImpl(f.keeper) - _, prevMinaAddr, err := generateUserAddressPair() - require.NoError(t, err) - _, newMinaAddr, err := generateUserAddressPair() - require.NoError(t, err) + _, prevMinaPublicKey, newMinaPublicKey := registerKeysForUpdateTest(t, f, ms, types.ActorType_USER) - _, err = ms.UpdateKeys(f.ctx, &types.MsgUpdateKeys{ + _, err := ms.UpdateKeys(f.ctx, &types.MsgUpdateKeys{ Creator: "creator", - PrevMinaPublicKey: prevMinaAddr, - NewMinaPublicKey: newMinaAddr, + PrevMinaPublicKey: prevMinaPublicKey, + NewMinaPublicKey: newMinaPublicKey, CosmosSignature: []byte(mockCosmosSignature), NewMinaSignature: []byte(mockMinaSignature), ActorType: types.ActorType_USER, }) + require.ErrorIs(t, err, types.ErrInvalidCreatorAddres) } @@ -132,12 +122,18 @@ func TestUserUpdateKeysInvalidSigner(t *testing.T) { f := initFixture(t) ms := keeper.NewMsgServerImpl(f.keeper) - _, prevMinaAddr := registerUserKeysForUpdateTest(t, f, ms) - secondaryAddr, newMinaAddr, err := generateUserAddressPair() + _, prevMinaAddr, _ := registerKeysForUpdateTest(t, f, ms, types.ActorType_USER) + + secondaryAddr, newMinaAddr, _, err := generatePublicKeys() require.NoError(t, err) + require.NotNil(t, secondaryAddr) + require.NotNil(t, newMinaAddr) + + creatorAddr := sdk.AccAddress(secondaryAddr.Address()) + require.NotNil(t, creatorAddr) _, err = ms.UpdateKeys(f.ctx, &types.MsgUpdateKeys{ - Creator: secondaryAddr.String(), + Creator: creatorAddr.String(), PrevMinaPublicKey: prevMinaAddr, NewMinaPublicKey: newMinaAddr, CosmosSignature: []byte(mockCosmosSignature), @@ -151,12 +147,12 @@ func TestUserUpdateKeysInvalidSignature(t *testing.T) { f := initFixture(t) ms := keeper.NewMsgServerImpl(f.keeper) - cosmosAddr, prevMinaAddr := registerUserKeysForUpdateTest(t, f, ms) - _, newMinaAddr, err := generateUserAddressPair() - require.NoError(t, err) + cosmosPublicKey, prevMinaAddr, newMinaAddr := registerKeysForUpdateTest(t, f, ms, types.ActorType_USER) - _, err = ms.UpdateKeys(f.ctx, &types.MsgUpdateKeys{ - Creator: cosmosAddr.String(), + creatorAddr := sdk.AccAddress(cosmosPublicKey.Address()) + + _, err := ms.UpdateKeys(f.ctx, &types.MsgUpdateKeys{ + Creator: creatorAddr.String(), PrevMinaPublicKey: prevMinaAddr, NewMinaPublicKey: newMinaAddr, CosmosSignature: []byte("cosmosSig"), @@ -170,16 +166,37 @@ func TestUserUpdateKeysInsertSecondaryKeysFail(t *testing.T) { f := initFixture(t) ms := keeper.NewMsgServerImpl(f.keeper) - cosmosAddr, prevMinaAddr := registerUserKeysForUpdateTest(t, f, ms) - _, newMinaAddr := registerUserKeysForUpdateTest(t, f, ms) + firstCosmosPublicKey, prevMinaPublicKey, _ := registerKeysForUpdateTest(t, f, ms, types.ActorType_USER) + secondCosmosPublicKey, _, targetMinaPublicKey, err := generatePublicKeys() + require.NoError(t, err) + require.NotNil(t, secondCosmosPublicKey) + require.NotNil(t, targetMinaPublicKey) + + creatorAddr := sdk.AccAddress(secondCosmosPublicKey.Address()) + require.NotNil(t, creatorAddr) - _, err := ms.UpdateKeys(f.ctx, &types.MsgUpdateKeys{ - Creator: cosmosAddr.String(), - PrevMinaPublicKey: prevMinaAddr, - NewMinaPublicKey: newMinaAddr, + resp, err := ms.RegisterKeys(f.ctx, &types.MsgRegisterKeys{ + Creator: creatorAddr.String(), + CosmosSignature: mockCosmosSignature, + MinaSignature: mockMinaSignature, + CosmosPublicKey: secondCosmosPublicKey.Bytes(), + MinaPublicKey: targetMinaPublicKey, + ActorType: types.ActorType_USER, + }) + require.NoError(t, err) + require.NotNil(t, resp) + + creatorAddr = sdk.AccAddress(firstCosmosPublicKey.Address()) + require.NotNil(t, creatorAddr) + + _, err = ms.UpdateKeys(f.ctx, &types.MsgUpdateKeys{ + Creator: creatorAddr.String(), + PrevMinaPublicKey: prevMinaPublicKey, + NewMinaPublicKey: targetMinaPublicKey, CosmosSignature: []byte(mockCosmosSignature), NewMinaSignature: []byte(mockMinaSignature), ActorType: types.ActorType_USER, }) + require.ErrorIs(t, err, types.ErrUserSecondaryKeyExists) } diff --git a/x/keyregistry/keeper/validator_register_keys_test.go b/x/keyregistry/keeper/validator_register_keys_test.go index 09f2fc33..4f1975f2 100644 --- a/x/keyregistry/keeper/validator_register_keys_test.go +++ b/x/keyregistry/keeper/validator_register_keys_test.go @@ -3,27 +3,12 @@ package keeper_test import ( "testing" - "github.com/cosmos/cosmos-sdk/crypto/keys/ed25519" - cryptotypes "github.com/cosmos/cosmos-sdk/crypto/types" sdk "github.com/cosmos/cosmos-sdk/types" - "github.com/node101-io/mina-signer-go/keys" "github.com/node101-io/pulsar-chain/x/keyregistry/keeper" "github.com/node101-io/pulsar-chain/x/keyregistry/types" "github.com/stretchr/testify/require" ) -func generateValidatorPublicKeys() (cryptotypes.PubKey, []byte, error) { - cosmosPrivKey := ed25519.GenPrivKey() - - cosmosPubKey := cosmosPrivKey.PubKey() - - minaPrivKey := keys.NewPrivateKeyFromBytes([32]byte(MinaPriv)) - - MinaPublicKey, err := minaPrivKey.ToPublicKey().Marshal() - - return cosmosPubKey, MinaPublicKey, err -} - // TestValidatorRegisterKeysFail verifies that RegisterKeys fails with ErrInvalidPublicKey // when the provided cosmos consensus public key is invalid. func TestValidatorRegisterKeysFail(t *testing.T) { @@ -31,8 +16,14 @@ func TestValidatorRegisterKeysFail(t *testing.T) { f := initFixture(t) ms := keeper.NewMsgServerImpl(f.keeper) - creatorAddr := sdk.ConsAddress([]byte("pulsar")) - _, err := ms.RegisterKeys(f.ctx, &types.MsgRegisterKeys{ + cosmosPublicKey, _, _, err := generatePublicKeys() + require.NoError(t, err) + require.NotNil(t, cosmosPublicKey) + + creatorAddr := sdk.AccAddress(cosmosPublicKey.Address()) + require.NotNil(t, creatorAddr) + + _, err = ms.RegisterKeys(f.ctx, &types.MsgRegisterKeys{ Creator: creatorAddr.String(), CosmosSignature: mockCosmosSignature, MinaSignature: mockMinaSignature, @@ -40,6 +31,7 @@ func TestValidatorRegisterKeysFail(t *testing.T) { MinaPublicKey: MinaPubKey, ActorType: types.ActorType_VALIDATOR, }) + require.ErrorIs(t, err, types.ErrInvalidPublicKey) } @@ -47,16 +39,19 @@ func TestValidatorRegisterKeysFail(t *testing.T) { // and ensures that both CosmosToMina and MinaToCosmos mappings are correctly stored. func TestValidatorRegisterKeysSuccess(t *testing.T) { - cosmosPubKey, minaPubKey, err := generateValidatorPublicKeys() + cosmosPubKey, minaPubKey, _, err := generatePublicKeys() require.NoError(t, err) + require.NotNil(t, cosmosPubKey) + require.NotNil(t, minaPubKey) - addr := sdk.ConsAddress(cosmosPubKey.Address()) + creatorAddr := sdk.AccAddress(cosmosPubKey.Address()) + require.NotNil(t, creatorAddr) f := initFixture(t) ms := keeper.NewMsgServerImpl(f.keeper) resp, err := ms.RegisterKeys(f.ctx, &types.MsgRegisterKeys{ - Creator: addr.String(), + Creator: creatorAddr.String(), CosmosSignature: mockCosmosSignature, MinaSignature: mockMinaSignature, CosmosPublicKey: cosmosPubKey.Bytes(), @@ -79,8 +74,11 @@ func TestValidatorRegisterKeysSuccess(t *testing.T) { // when the creator field is not a valid bech32 address. func TestValidatorInvalidCreatorAddress(t *testing.T) { - cosmosPubKey, minaPubKey, err := generateValidatorPublicKeys() + cosmosPubKey, minaPubKey, _, err := generatePublicKeys() + require.NoError(t, err) + require.NotNil(t, cosmosPubKey) + require.NotNil(t, minaPubKey) f := initFixture(t) ms := keeper.NewMsgServerImpl(f.keeper) @@ -93,6 +91,7 @@ func TestValidatorInvalidCreatorAddress(t *testing.T) { MinaPublicKey: minaPubKey, ActorType: types.ActorType_VALIDATOR, }) + require.ErrorIs(t, err, types.ErrInvalidCreatorAddres) } @@ -100,20 +99,25 @@ func TestValidatorInvalidCreatorAddress(t *testing.T) { // when the creator address does not match the address derived from the provided consensus public key. func TestValidatorInvalidSigner(t *testing.T) { - cosmosPubKey, minaPubKey, err := generateValidatorPublicKeys() + cosmosPubKey, minaPubKey, _, err := generatePublicKeys() + require.NoError(t, err) + require.NotNil(t, cosmosPubKey) + require.NotNil(t, minaPubKey) - secondaryPriv := ed25519.GenPrivKey() + secondaryCosmosPublicKey, _, _, err := generatePublicKeys() - secondaryPublic := secondaryPriv.PubKey() + require.NoError(t, err) + require.NotNil(t, secondaryCosmosPublicKey) - addr := sdk.ConsAddress(secondaryPublic.Address()) + creatorAddr := sdk.AccAddress(secondaryCosmosPublicKey.Address()) + require.NotNil(t, creatorAddr) f := initFixture(t) ms := keeper.NewMsgServerImpl(f.keeper) _, err = ms.RegisterKeys(f.ctx, &types.MsgRegisterKeys{ - Creator: addr.String(), + Creator: creatorAddr.String(), CosmosSignature: mockCosmosSignature, MinaSignature: mockMinaSignature, CosmosPublicKey: cosmosPubKey.Bytes(), @@ -128,18 +132,22 @@ func TestValidatorInvalidSigner(t *testing.T) { // TestValidatorInvalidSignature currently expects no error since signature verification is not yet implemented. func TestValidatorInvalidSignature(t *testing.T) { - cosmosPubKey, minaPubKey, err := generateValidatorPublicKeys() - addr := sdk.ConsAddress(cosmosPubKey.Address()) - + cosmosPubKey, minaPubKey, _, err := generatePublicKeys() require.NoError(t, err) + require.NotNil(t, cosmosPubKey) + require.NotNil(t, minaPubKey) + + creatorAddr := sdk.AccAddress(cosmosPubKey.Address()) + require.NotNil(t, creatorAddr) + f := initFixture(t) ms := keeper.NewMsgServerImpl(f.keeper) invalidSig := "cosmosSig" _, err = ms.RegisterKeys(f.ctx, &types.MsgRegisterKeys{ - Creator: addr.String(), + Creator: creatorAddr.String(), CosmosSignature: invalidSig, MinaSignature: mockMinaSignature, CosmosPublicKey: cosmosPubKey.Bytes(), @@ -156,28 +164,32 @@ func TestValidatorInvalidSignature(t *testing.T) { func TestValidatorInsertSecondaryKeysFail(t *testing.T) { f := initFixture(t) - cosmosPubKey, minaPubKey, err := generateValidatorPublicKeys() + cosmosPubKey, minaPubKey, _, err := generatePublicKeys() require.NoError(t, err) - addr := sdk.ConsAddress(cosmosPubKey.Address()) + require.NotNil(t, cosmosPubKey) + require.NotNil(t, minaPubKey) + + creatorAddr := sdk.AccAddress(cosmosPubKey.Address()) ms := keeper.NewMsgServerImpl(f.keeper) // First registration should succeed. resp, err := ms.RegisterKeys(f.ctx, &types.MsgRegisterKeys{ - Creator: addr.String(), + Creator: creatorAddr.String(), CosmosSignature: mockCosmosSignature, MinaSignature: mockMinaSignature, CosmosPublicKey: cosmosPubKey.Bytes(), MinaPublicKey: minaPubKey, ActorType: types.ActorType_VALIDATOR, }) + require.NoError(t, err) require.NotNil(t, resp) // Second registration with the same keys should fail. resp, err = ms.RegisterKeys(f.ctx, &types.MsgRegisterKeys{ - Creator: addr.String(), + Creator: creatorAddr.String(), CosmosSignature: mockCosmosSignature, MinaSignature: mockMinaSignature, CosmosPublicKey: cosmosPubKey.Bytes(), diff --git a/x/keyregistry/keeper/validator_update_keys_test.go b/x/keyregistry/keeper/validator_update_keys_test.go index f5233c3f..efc75cf0 100644 --- a/x/keyregistry/keeper/validator_update_keys_test.go +++ b/x/keyregistry/keeper/validator_update_keys_test.go @@ -1,65 +1,25 @@ package keeper_test import ( - "crypto/rand" "testing" - "github.com/cosmos/cosmos-sdk/crypto/keys/ed25519" sdk "github.com/cosmos/cosmos-sdk/types" - "github.com/node101-io/mina-signer-go/keys" "github.com/node101-io/pulsar-chain/x/keyregistry/keeper" "github.com/node101-io/pulsar-chain/x/keyregistry/types" "github.com/stretchr/testify/require" ) -func generateValidatorKeyPair() (string, []byte, []byte, error) { - cosmosPrivKey := ed25519.GenPrivKey() - cosmosPubKey := cosmosPrivKey.PubKey() - - var minaSeed [32]byte - _, err := rand.Read(minaSeed[:]) - if err != nil { - return "", nil, nil, err - } - - minaPubKey, err := keys.NewPrivateKeyFromBytes(minaSeed).ToPublicKey().Marshal() - if err != nil { - return "", nil, nil, err - } - - return sdk.ConsAddress(cosmosPubKey.Address()).String(), cosmosPubKey.Bytes(), minaPubKey, nil -} - -func registerValidatorKeysForUpdateTest(t *testing.T, f *fixture, ms types.MsgServer) (string, []byte, []byte) { - t.Helper() - - creator, cosmosPubKey, minaPubKey, err := generateValidatorKeyPair() - require.NoError(t, err) - - resp, err := ms.RegisterKeys(f.ctx, &types.MsgRegisterKeys{ - Creator: creator, - CosmosSignature: mockCosmosSignature, - MinaSignature: mockMinaSignature, - CosmosPublicKey: cosmosPubKey, - MinaPublicKey: minaPubKey, - ActorType: types.ActorType_VALIDATOR, - }) - require.NoError(t, err) - require.NotNil(t, resp) - - return creator, cosmosPubKey, minaPubKey -} - func TestValidatorUpdateKeysSuccess(t *testing.T) { f := initFixture(t) ms := keeper.NewMsgServerImpl(f.keeper) - creator, cosmosPubKey, prevMinaPubKey := registerValidatorKeysForUpdateTest(t, f, ms) - _, _, newMinaPubKey, err := generateValidatorKeyPair() - require.NoError(t, err) + cosmosPublicKey, prevMinaPubKey, newMinaPubKey := registerKeysForUpdateTest(t, f, ms, types.ActorType_VALIDATOR) + + creatorAddr := sdk.AccAddress(cosmosPublicKey.Address()) + require.NotNil(t, creatorAddr) resp, err := ms.UpdateKeys(f.ctx, &types.MsgUpdateKeys{ - Creator: creator, + Creator: creatorAddr.String(), PrevMinaPublicKey: prevMinaPubKey, NewMinaPublicKey: newMinaPubKey, CosmosSignature: []byte(mockCosmosSignature), @@ -77,26 +37,30 @@ func TestValidatorUpdateKeysSuccess(t *testing.T) { require.NoError(t, err) require.True(t, exists) - minaPubKey, err := f.keeper.ValidatorGetCosmosToMina(f.ctx, cosmosPubKey) + minaPubKey, err := f.keeper.ValidatorGetCosmosToMina(f.ctx, cosmosPublicKey.Bytes()) require.NoError(t, err) require.Equal(t, newMinaPubKey, minaPubKey) storedCosmosPubKey, err := f.keeper.ValidatorGetMinaToCosmos(f.ctx, newMinaPubKey) require.NoError(t, err) - require.Equal(t, cosmosPubKey, storedCosmosPubKey) + require.Equal(t, cosmosPublicKey.Bytes(), storedCosmosPubKey) } func TestValidatorUpdateKeysNotRegistered(t *testing.T) { f := initFixture(t) ms := keeper.NewMsgServerImpl(f.keeper) - creator, _, prevMinaPubKey, err := generateValidatorKeyPair() - require.NoError(t, err) - _, _, newMinaPubKey, err := generateValidatorKeyPair() + cosmosPublicKey, prevMinaPubKey, newMinaPubKey, err := generatePublicKeys() require.NoError(t, err) + require.NotNil(t, cosmosPublicKey) + require.NotNil(t, prevMinaPubKey) + require.NotNil(t, newMinaPubKey) + + creatorAddr := sdk.AccAddress(cosmosPublicKey.Address()) + require.NotNil(t, creatorAddr) _, err = ms.UpdateKeys(f.ctx, &types.MsgUpdateKeys{ - Creator: creator, + Creator: creatorAddr.String(), PrevMinaPublicKey: prevMinaPubKey, NewMinaPublicKey: newMinaPubKey, CosmosSignature: []byte(mockCosmosSignature), @@ -110,16 +74,20 @@ func TestValidatorUpdateKeysMissingCosmosToMinaMapping(t *testing.T) { f := initFixture(t) ms := keeper.NewMsgServerImpl(f.keeper) - creator, cosmosPubKey, prevMinaPubKey, err := generateValidatorKeyPair() - require.NoError(t, err) - _, _, newMinaPubKey, err := generateValidatorKeyPair() + cosmosPublicKey, prevMinaPubKey, newMinaPubKey, err := generatePublicKeys() require.NoError(t, err) + require.NotNil(t, cosmosPublicKey) + require.NotNil(t, prevMinaPubKey) + require.NotNil(t, newMinaPubKey) - err = f.keeper.ValidatorSetMinaToCosmos(f.ctx, prevMinaPubKey, cosmosPubKey) + err = f.keeper.ValidatorSetMinaToCosmos(f.ctx, prevMinaPubKey, cosmosPublicKey.Bytes()) require.NoError(t, err) + creatorAddr := sdk.AccAddress(cosmosPublicKey.Address()) + require.NotNil(t, creatorAddr) + _, err = ms.UpdateKeys(f.ctx, &types.MsgUpdateKeys{ - Creator: creator, + Creator: creatorAddr.String(), PrevMinaPublicKey: prevMinaPubKey, NewMinaPublicKey: newMinaPubKey, CosmosSignature: []byte(mockCosmosSignature), @@ -133,10 +101,11 @@ func TestValidatorUpdateKeysInvalidCreatorAddress(t *testing.T) { f := initFixture(t) ms := keeper.NewMsgServerImpl(f.keeper) - _, _, prevMinaPubKey, err := generateValidatorKeyPair() - require.NoError(t, err) - _, _, newMinaPubKey, err := generateValidatorKeyPair() + _, prevMinaPubKey, newMinaPubKey, err := generatePublicKeys() + require.NoError(t, err) + require.NotNil(t, prevMinaPubKey) + require.NotNil(t, newMinaPubKey) _, err = ms.UpdateKeys(f.ctx, &types.MsgUpdateKeys{ Creator: "creator", @@ -153,14 +122,19 @@ func TestValidatorUpdateKeysInvalidSigner(t *testing.T) { f := initFixture(t) ms := keeper.NewMsgServerImpl(f.keeper) - _, _, prevMinaPubKey := registerValidatorKeysForUpdateTest(t, f, ms) - secondaryCreator, _, newMinaPubKey, err := generateValidatorKeyPair() + _, prevMinaPubKey, newMinaPublicKey := registerKeysForUpdateTest(t, f, ms, types.ActorType_VALIDATOR) + + secondaryCreator, _, _, err := generatePublicKeys() require.NoError(t, err) + require.NotNil(t, secondaryCreator) + + secondaryCreatorAddr := sdk.AccAddress(secondaryCreator.Address()) + require.NotNil(t, secondaryCreatorAddr) _, err = ms.UpdateKeys(f.ctx, &types.MsgUpdateKeys{ - Creator: secondaryCreator, + Creator: secondaryCreatorAddr.String(), PrevMinaPublicKey: prevMinaPubKey, - NewMinaPublicKey: newMinaPubKey, + NewMinaPublicKey: newMinaPublicKey, CosmosSignature: []byte(mockCosmosSignature), NewMinaSignature: []byte(mockMinaSignature), ActorType: types.ActorType_VALIDATOR, @@ -172,14 +146,15 @@ func TestValidatorUpdateKeysInvalidSignature(t *testing.T) { f := initFixture(t) ms := keeper.NewMsgServerImpl(f.keeper) - creator, _, prevMinaPubKey := registerValidatorKeysForUpdateTest(t, f, ms) - _, _, newMinaPubKey, err := generateValidatorKeyPair() - require.NoError(t, err) + cosmosPublicKey, prevMinaPubKey, newMinaPublicKey := registerKeysForUpdateTest(t, f, ms, types.ActorType_VALIDATOR) - _, err = ms.UpdateKeys(f.ctx, &types.MsgUpdateKeys{ - Creator: creator, + creatorAddr := sdk.AccAddress(cosmosPublicKey.Address()) + require.NotNil(t, creatorAddr) + + _, err := ms.UpdateKeys(f.ctx, &types.MsgUpdateKeys{ + Creator: creatorAddr.String(), PrevMinaPublicKey: prevMinaPubKey, - NewMinaPublicKey: newMinaPubKey, + NewMinaPublicKey: newMinaPublicKey, CosmosSignature: []byte("cosmosSig"), NewMinaSignature: []byte(mockMinaSignature), ActorType: types.ActorType_VALIDATOR, @@ -191,16 +166,37 @@ func TestValidatorUpdateKeysInsertSecondaryKeysFail(t *testing.T) { f := initFixture(t) ms := keeper.NewMsgServerImpl(f.keeper) - creator, _, prevMinaPubKey := registerValidatorKeysForUpdateTest(t, f, ms) - _, _, newMinaPubKey := registerValidatorKeysForUpdateTest(t, f, ms) + firstCosmosPublicKey, prevMinaPublicKey, _ := registerKeysForUpdateTest(t, f, ms, types.ActorType_VALIDATOR) + secondCosmosPublicKey, _, targetMinaPublicKey, err := generatePublicKeys() + require.NoError(t, err) + require.NotNil(t, secondCosmosPublicKey) + require.NotNil(t, targetMinaPublicKey) - _, err := ms.UpdateKeys(f.ctx, &types.MsgUpdateKeys{ - Creator: creator, - PrevMinaPublicKey: prevMinaPubKey, - NewMinaPublicKey: newMinaPubKey, + creatorAddr := sdk.AccAddress(secondCosmosPublicKey.Address()) + require.NotNil(t, creatorAddr) + + resp, err := ms.RegisterKeys(f.ctx, &types.MsgRegisterKeys{ + Creator: creatorAddr.String(), + CosmosSignature: mockCosmosSignature, + MinaSignature: mockMinaSignature, + CosmosPublicKey: secondCosmosPublicKey.Bytes(), + MinaPublicKey: targetMinaPublicKey, + ActorType: types.ActorType_VALIDATOR, + }) + require.NoError(t, err) + require.NotNil(t, resp) + + creatorAddr = sdk.AccAddress(firstCosmosPublicKey.Address()) + require.NotNil(t, creatorAddr) + + _, err = ms.UpdateKeys(f.ctx, &types.MsgUpdateKeys{ + Creator: creatorAddr.String(), + PrevMinaPublicKey: prevMinaPublicKey, + NewMinaPublicKey: targetMinaPublicKey, CosmosSignature: []byte(mockCosmosSignature), NewMinaSignature: []byte(mockMinaSignature), ActorType: types.ActorType_VALIDATOR, }) + require.ErrorIs(t, err, types.ErrValidatorSecondaryKeyExists) } From a10a671ce0dc61606c90559976b2c18c14654802 Mon Sep 17 00:00:00 2001 From: Yusuf Date: Fri, 24 Apr 2026 19:35:12 +0300 Subject: [PATCH 11/62] "refactor: genesis now has all 4 maps, compatible with the state" --- .../pulsarchain/keyregistry/v1/genesis.proto | 6 +- .../keyregistry/v1/public_key_pair.proto | 6 +- x/keyregistry/keeper/genesis.go | 153 +++++---- x/keyregistry/keeper/genesis_test.go | 41 ++- x/keyregistry/types/genesis.go | 41 ++- x/keyregistry/types/genesis.pb.go | 216 ++++++++++--- x/keyregistry/types/public_key_pair.pb.go | 296 +++++++++++++++--- x/keyregistry/types/user_public_key_pairs.go | 32 ++ .../types/validator_public_key_pairs.go | 33 ++ 9 files changed, 639 insertions(+), 185 deletions(-) create mode 100644 x/keyregistry/types/user_public_key_pairs.go create mode 100644 x/keyregistry/types/validator_public_key_pairs.go diff --git a/proto/pulsarchain/keyregistry/v1/genesis.proto b/proto/pulsarchain/keyregistry/v1/genesis.proto index 9fbe466c..2d7b3bad 100644 --- a/proto/pulsarchain/keyregistry/v1/genesis.proto +++ b/proto/pulsarchain/keyregistry/v1/genesis.proto @@ -15,6 +15,8 @@ message GenesisState { (gogoproto.nullable) = false, (amino.dont_omitempty) = true ]; - repeated PublicKeyPair user_key_pairs = 2; - repeated PublicKeyPair validator_key_pairs = 3; + repeated UserPublicKeyPair user_cosmos_to_mina = 2; + repeated UserPublicKeyPair user_mina_to_cosmos = 3; + repeated ValidatorPublicKeyPair validator_cosmos_to_mina = 4; + repeated ValidatorPublicKeyPair validator_mina_to_cosmos = 5; } diff --git a/proto/pulsarchain/keyregistry/v1/public_key_pair.proto b/proto/pulsarchain/keyregistry/v1/public_key_pair.proto index b6e3810f..474b7d87 100644 --- a/proto/pulsarchain/keyregistry/v1/public_key_pair.proto +++ b/proto/pulsarchain/keyregistry/v1/public_key_pair.proto @@ -4,7 +4,11 @@ package pulsarchain.keyregistry.v1; option go_package = "github.com/node101-io/pulsar-chain/x/keyregistry/types"; // KeyPair defines the KeyPair message. -message PublicKeyPair { +message UserPublicKeyPair { + bytes mina_key = 1; + bytes cosmos_key = 2; +} +message ValidatorPublicKeyPair { bytes mina_key = 1; bytes cosmos_key = 2; } diff --git a/x/keyregistry/keeper/genesis.go b/x/keyregistry/keeper/genesis.go index 4c8cd24f..4f38db0d 100644 --- a/x/keyregistry/keeper/genesis.go +++ b/x/keyregistry/keeper/genesis.go @@ -9,31 +9,27 @@ import ( // InitGenesis initializes the module's state from a provided genesis state. func (k Keeper) InitGenesis(ctx context.Context, genState types.GenesisState) error { - userKeyPairs := genState.UserKeyPairs - // Insert genesis key pairs. - for _, keyPair := range userKeyPairs { - + for _, keyPair := range genState.UserCosmosToMina { err := k.userCosmosToMina.Set(ctx, keyPair.CosmosKey, keyPair.MinaKey) if err != nil { return err } - err = k.userMinaToCosmos.Set(ctx, keyPair.MinaKey, keyPair.CosmosKey) + } + for _, keyPair := range genState.UserMinaToCosmos { + err := k.userMinaToCosmos.Set(ctx, keyPair.MinaKey, keyPair.CosmosKey) if err != nil { return err } } - - validatorKeyPairs := genState.ValidatorKeyPairs - - // Insert genesis key pairs. - for _, keyPair := range validatorKeyPairs { - + for _, keyPair := range genState.ValidatorCosmosToMina { err := k.validatorCosmosToMina.Set(ctx, keyPair.CosmosKey, keyPair.MinaKey) if err != nil { return err } - err = k.validatorMinaToCosmos.Set(ctx, keyPair.MinaKey, keyPair.CosmosKey) + } + for _, keyPair := range genState.ValidatorMinaToCosmos { + err := k.validatorMinaToCosmos.Set(ctx, keyPair.MinaKey, keyPair.CosmosKey) if err != nil { return err } @@ -52,130 +48,125 @@ func (k Keeper) ExportGenesis(ctx context.Context) (*types.GenesisState, error) return nil, err } - var userKeyPairs []*types.PublicKeyPair - - var userKeypairExistenceMap = make(map[string]bool) - - // Iterate over CosmosToMina map first and collect all key pairs. - userCosmosIterator, err := k.userCosmosToMina.Iterate(ctx, nil) + userCosmosToMinaIterator, err := k.userCosmosToMina.Iterate(ctx, nil) if err != nil { return nil, err } - defer userCosmosIterator.Close() - for userCosmosIterator.Valid() { - cosmosKey, err := userCosmosIterator.Key() + defer userCosmosToMinaIterator.Close() + + var userCosmosToMinaSlice []*types.UserPublicKeyPair + + for userCosmosToMinaIterator.Valid() { + cosmosKey, err := userCosmosToMinaIterator.Key() if err != nil { - return genesis, err + return nil, err } - minaKey, err := userCosmosIterator.Value() + minaKey, err := userCosmosToMinaIterator.Value() if err != nil { - return genesis, err + return nil, err } - keyPair := &types.PublicKeyPair{ + keyPair := &types.UserPublicKeyPair{ MinaKey: minaKey, CosmosKey: cosmosKey, } - userKeyPairs = append(userKeyPairs, keyPair) - userKeypairExistenceMap[keyPair.String()] = true - userCosmosIterator.Next() + + userCosmosToMinaSlice = append(userCosmosToMinaSlice, keyPair) + + userCosmosToMinaIterator.Next() } - // Iterate over MinaToCosmos map and collect any key pairs that are not - // already present in the CosmosToMina map. Although both maps are expected - // to be in sync, this ensures no key pairs are lost in case of any inconsistency - // between the two maps during export. + genesis.UserCosmosToMina = userCosmosToMinaSlice - // ExportGenesis intentionally does not enforce consistency between the two maps. - // Returning an error here could prevent the state from being exported and lead - // to potential state loss. Consistency checks should instead be handled at the - // message implementation level where the mappings are created or updated. - userMinaIterator, err := k.userMinaToCosmos.Iterate(ctx, nil) + userMinaToCosmosIterator, err := k.userMinaToCosmos.Iterate(ctx, nil) if err != nil { return nil, err } - defer userMinaIterator.Close() - for userMinaIterator.Valid() { - minaKey, err := userMinaIterator.Key() + defer userMinaToCosmosIterator.Close() + + var userMinaToCosmosSlice []*types.UserPublicKeyPair + + for userMinaToCosmosIterator.Valid() { + minaKey, err := userMinaToCosmosIterator.Key() if err != nil { - return genesis, err + return nil, err } - cosmosKey, err := userMinaIterator.Value() + cosmosKey, err := userMinaToCosmosIterator.Value() if err != nil { - return genesis, err + return nil, err } - keyPair := &types.PublicKeyPair{ + keyPair := &types.UserPublicKeyPair{ MinaKey: minaKey, CosmosKey: cosmosKey, } - if userKeypairExistenceMap[keyPair.String()] { - userMinaIterator.Next() - continue - } - userKeyPairs = append(userKeyPairs, keyPair) - userMinaIterator.Next() - } - genesis.UserKeyPairs = userKeyPairs + userMinaToCosmosSlice = append(userMinaToCosmosSlice, keyPair) - var validatorKeyPairs []*types.PublicKeyPair + userMinaToCosmosIterator.Next() + } - var validatorKeypairExistenceMap = make(map[string]bool) + genesis.UserMinaToCosmos = userMinaToCosmosSlice - // Iterate over CosmosToMina map first and collect all key pairs. - validatorCosmosIterator, err := k.validatorCosmosToMina.Iterate(ctx, nil) + validatorCosmosToMinaIterator, err := k.validatorCosmosToMina.Iterate(ctx, nil) if err != nil { return nil, err } - defer validatorCosmosIterator.Close() - for validatorCosmosIterator.Valid() { - cosmosKey, err := validatorCosmosIterator.Key() + defer validatorCosmosToMinaIterator.Close() + + var validatorCosmosToMinaSlice []*types.ValidatorPublicKeyPair + + for validatorCosmosToMinaIterator.Valid() { + cosmosKey, err := validatorCosmosToMinaIterator.Key() if err != nil { - return genesis, err + return nil, err } - minaKey, err := validatorCosmosIterator.Value() + minaKey, err := validatorCosmosToMinaIterator.Value() if err != nil { - return genesis, err + return nil, err } - keyPair := &types.PublicKeyPair{ + keyPair := &types.ValidatorPublicKeyPair{ MinaKey: minaKey, CosmosKey: cosmosKey, } - validatorKeyPairs = append(validatorKeyPairs, keyPair) - validatorKeypairExistenceMap[keyPair.String()] = true - validatorCosmosIterator.Next() + + validatorCosmosToMinaSlice = append(validatorCosmosToMinaSlice, keyPair) + + validatorCosmosToMinaIterator.Next() } - validatorMinaIterator, err := k.validatorMinaToCosmos.Iterate(ctx, nil) + genesis.ValidatorCosmosToMina = validatorCosmosToMinaSlice + + validatorMinaToCosmosIterator, err := k.validatorMinaToCosmos.Iterate(ctx, nil) if err != nil { return nil, err } - defer validatorMinaIterator.Close() - for validatorMinaIterator.Valid() { - minaKey, err := validatorMinaIterator.Key() + defer validatorMinaToCosmosIterator.Close() + + var validatorMinaToCosmosSlice []*types.ValidatorPublicKeyPair + + for validatorMinaToCosmosIterator.Valid() { + minaKey, err := validatorMinaToCosmosIterator.Key() if err != nil { - return genesis, err + return nil, err } - cosmosKey, err := validatorMinaIterator.Value() + cosmosKey, err := validatorMinaToCosmosIterator.Value() if err != nil { - return genesis, err + return nil, err } - keyPair := &types.PublicKeyPair{ + keyPair := &types.ValidatorPublicKeyPair{ MinaKey: minaKey, CosmosKey: cosmosKey, } - if validatorKeypairExistenceMap[keyPair.String()] { - validatorMinaIterator.Next() - continue - } - validatorKeyPairs = append(validatorKeyPairs, keyPair) - validatorMinaIterator.Next() + + validatorMinaToCosmosSlice = append(validatorMinaToCosmosSlice, keyPair) + + validatorMinaToCosmosIterator.Next() } - genesis.ValidatorKeyPairs = validatorKeyPairs + genesis.ValidatorMinaToCosmos = validatorMinaToCosmosSlice return genesis, nil } diff --git a/x/keyregistry/keeper/genesis_test.go b/x/keyregistry/keeper/genesis_test.go index 41ebe39e..cb25bd36 100644 --- a/x/keyregistry/keeper/genesis_test.go +++ b/x/keyregistry/keeper/genesis_test.go @@ -1,13 +1,11 @@ package keeper_test import ( - "crypto/ed25519" - "crypto/rand" "testing" + cometed25519 "github.com/cometbft/cometbft/crypto/ed25519" "github.com/cometbft/cometbft/crypto/secp256k1" "github.com/node101-io/pulsar-chain/x/keyregistry/types" - "github.com/stretchr/testify/require" ) @@ -32,37 +30,50 @@ func TestInitAndExportGenesis(t *testing.T) { f := initFixture(t) - cosmosPriv := secp256k1.GenPrivKey() + userCosmosPubKey := secp256k1.GenPrivKey().PubKey() - cosmosPubKey := cosmosPriv.PubKey() + validatorPublicKey := cometed25519.GenPrivKey().PubKey() - minaPubKey, _, err := ed25519.GenerateKey(rand.Reader) - if err != nil { - panic(err) - } + MinaPriv := secp256k1.GenPrivKey() + minaPubKey := MinaPriv.PubKey().Bytes() genesisState := types.GenesisState{ Params: types.DefaultParams(), - UserKeyPairs: []*types.PublicKeyPair{ + UserCosmosToMina: []*types.UserPublicKeyPair{ + { + MinaKey: minaPubKey, + CosmosKey: userCosmosPubKey.Bytes(), + }, + }, + UserMinaToCosmos: []*types.UserPublicKeyPair{ { MinaKey: minaPubKey, - CosmosKey: cosmosPubKey.Bytes(), + CosmosKey: userCosmosPubKey.Bytes(), }, }, - ValidatorKeyPairs: []*types.PublicKeyPair{ + ValidatorCosmosToMina: []*types.ValidatorPublicKeyPair{ { MinaKey: minaPubKey, - CosmosKey: cosmosPubKey.Bytes(), + CosmosKey: validatorPublicKey.Bytes(), + }, + }, + ValidatorMinaToCosmos: []*types.ValidatorPublicKeyPair{ + { + MinaKey: minaPubKey, + CosmosKey: validatorPublicKey.Bytes(), }, }, } - err = f.keeper.InitGenesis(f.ctx, genesisState) + err := f.keeper.InitGenesis(f.ctx, genesisState) require.NoError(t, err) got, err := f.keeper.ExportGenesis(f.ctx) require.NoError(t, err) require.NotNil(t, got) - require.EqualExportedValues(t, genesisState.UserKeyPairs, got.UserKeyPairs) + require.EqualExportedValues(t, genesisState.UserCosmosToMina, got.UserCosmosToMina) + require.EqualExportedValues(t, genesisState.UserMinaToCosmos, got.UserMinaToCosmos) + require.EqualExportedValues(t, genesisState.ValidatorCosmosToMina, got.ValidatorCosmosToMina) + require.EqualExportedValues(t, genesisState.ValidatorMinaToCosmos, got.ValidatorMinaToCosmos) } diff --git a/x/keyregistry/types/genesis.go b/x/keyregistry/types/genesis.go index abc14ccb..f9e17cd2 100644 --- a/x/keyregistry/types/genesis.go +++ b/x/keyregistry/types/genesis.go @@ -3,9 +3,11 @@ package types // DefaultGenesis returns the default genesis state func DefaultGenesis() *GenesisState { return &GenesisState{ - Params: DefaultParams(), - UserKeyPairs: DefaultPublicKeyPair(), - ValidatorKeyPairs: DefaultPublicKeyPair(), + Params: DefaultParams(), + UserCosmosToMina: DefaultUserPublicKeyPair(), + UserMinaToCosmos: DefaultUserPublicKeyPair(), + ValidatorCosmosToMina: DefaultValidatorPublicKeyPair(), + ValidatorMinaToCosmos: DefaultValidatorPublicKeyPair(), } } @@ -13,15 +15,40 @@ func DefaultGenesis() *GenesisState { // failure. func (gs GenesisState) Validate() error { - for _, keyPair := range gs.UserKeyPairs { - err := ValidatePublicKeyPair(*keyPair) + for _, keyPair := range gs.UserCosmosToMina { + if keyPair == nil { + return ErrNilKeyPair + } + err := ValidateUserPublicKeyPair(*keyPair) + if err != nil { + return err + } + } + + for _, keyPair := range gs.UserMinaToCosmos { + if keyPair == nil { + return ErrNilKeyPair + } + err := ValidateUserPublicKeyPair(*keyPair) if err != nil { return err } } - for _, keyPair := range gs.ValidatorKeyPairs { - err := ValidatePublicKeyPair(*keyPair) + for _, keyPair := range gs.ValidatorCosmosToMina { + if keyPair == nil { + return ErrNilKeyPair + } + err := ValidateValidatorPublicKeyPair(*keyPair) + if err != nil { + return err + } + } + for _, keyPair := range gs.ValidatorMinaToCosmos { + if keyPair == nil { + return ErrNilKeyPair + } + err := ValidateValidatorPublicKeyPair(*keyPair) if err != nil { return err } diff --git a/x/keyregistry/types/genesis.pb.go b/x/keyregistry/types/genesis.pb.go index ffea01ac..9ea4b45a 100644 --- a/x/keyregistry/types/genesis.pb.go +++ b/x/keyregistry/types/genesis.pb.go @@ -27,9 +27,11 @@ const _ = proto.GoGoProtoPackageIsVersion3 // please upgrade the proto package // GenesisState defines the keyregistry module's genesis state. type GenesisState struct { // params defines all the parameters of the module. - Params Params `protobuf:"bytes,1,opt,name=params,proto3" json:"params"` - UserKeyPairs []*PublicKeyPair `protobuf:"bytes,2,rep,name=user_key_pairs,json=userKeyPairs,proto3" json:"user_key_pairs,omitempty"` - ValidatorKeyPairs []*PublicKeyPair `protobuf:"bytes,3,rep,name=validator_key_pairs,json=validatorKeyPairs,proto3" json:"validator_key_pairs,omitempty"` + Params Params `protobuf:"bytes,1,opt,name=params,proto3" json:"params"` + UserCosmosToMina []*UserPublicKeyPair `protobuf:"bytes,2,rep,name=user_cosmos_to_mina,json=userCosmosToMina,proto3" json:"user_cosmos_to_mina,omitempty"` + UserMinaToCosmos []*UserPublicKeyPair `protobuf:"bytes,3,rep,name=user_mina_to_cosmos,json=userMinaToCosmos,proto3" json:"user_mina_to_cosmos,omitempty"` + ValidatorCosmosToMina []*ValidatorPublicKeyPair `protobuf:"bytes,4,rep,name=validator_cosmos_to_mina,json=validatorCosmosToMina,proto3" json:"validator_cosmos_to_mina,omitempty"` + ValidatorMinaToCosmos []*ValidatorPublicKeyPair `protobuf:"bytes,5,rep,name=validator_mina_to_cosmos,json=validatorMinaToCosmos,proto3" json:"validator_mina_to_cosmos,omitempty"` } func (m *GenesisState) Reset() { *m = GenesisState{} } @@ -72,16 +74,30 @@ func (m *GenesisState) GetParams() Params { return Params{} } -func (m *GenesisState) GetUserKeyPairs() []*PublicKeyPair { +func (m *GenesisState) GetUserCosmosToMina() []*UserPublicKeyPair { if m != nil { - return m.UserKeyPairs + return m.UserCosmosToMina } return nil } -func (m *GenesisState) GetValidatorKeyPairs() []*PublicKeyPair { +func (m *GenesisState) GetUserMinaToCosmos() []*UserPublicKeyPair { if m != nil { - return m.ValidatorKeyPairs + return m.UserMinaToCosmos + } + return nil +} + +func (m *GenesisState) GetValidatorCosmosToMina() []*ValidatorPublicKeyPair { + if m != nil { + return m.ValidatorCosmosToMina + } + return nil +} + +func (m *GenesisState) GetValidatorMinaToCosmos() []*ValidatorPublicKeyPair { + if m != nil { + return m.ValidatorMinaToCosmos } return nil } @@ -95,27 +111,31 @@ func init() { } var fileDescriptor_dbaeb2ea35536f14 = []byte{ - // 312 bytes of a gzipped FileDescriptorProto - 0x1f, 0x8b, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0xff, 0xe2, 0xd2, 0x28, 0x28, 0xcd, 0x29, - 0x4e, 0x2c, 0x4a, 0xce, 0x48, 0xcc, 0xcc, 0xd3, 0xcf, 0x4e, 0xad, 0x2c, 0x4a, 0x4d, 0xcf, 0x2c, - 0x2e, 0x29, 0xaa, 0xd4, 0x2f, 0x33, 0xd4, 0x4f, 0x4f, 0xcd, 0x4b, 0x2d, 0xce, 0x2c, 0xd6, 0x2b, - 0x28, 0xca, 0x2f, 0xc9, 0x17, 0x92, 0x42, 0x52, 0xa9, 0x87, 0xa4, 0x52, 0xaf, 0xcc, 0x50, 0x4a, - 0x30, 0x31, 0x37, 0x33, 0x2f, 0x5f, 0x1f, 0x4c, 0x42, 0x94, 0x4b, 0x89, 0xa4, 0xe7, 0xa7, 0xe7, - 0x83, 0x99, 0xfa, 0x20, 0x16, 0x54, 0x54, 0x1d, 0x8f, 0x75, 0x05, 0x89, 0x45, 0x89, 0xb9, 0x50, - 0xdb, 0xa4, 0x0c, 0xf0, 0x29, 0x2c, 0x4d, 0xca, 0xc9, 0x4c, 0x8e, 0xcf, 0x4e, 0xad, 0x8c, 0x2f, - 0x48, 0xcc, 0x2c, 0x82, 0xe8, 0x50, 0x6a, 0x64, 0xe2, 0xe2, 0x71, 0x87, 0xb8, 0x38, 0xb8, 0x24, - 0xb1, 0x24, 0x55, 0xc8, 0x95, 0x8b, 0x0d, 0x62, 0xa4, 0x04, 0xa3, 0x02, 0xa3, 0x06, 0xb7, 0x91, - 0x92, 0x1e, 0x6e, 0x1f, 0xe8, 0x05, 0x80, 0x55, 0x3a, 0x71, 0x9e, 0xb8, 0x27, 0xcf, 0xb0, 0xe2, - 0xf9, 0x06, 0x2d, 0xc6, 0x20, 0xa8, 0x66, 0x21, 0x7f, 0x2e, 0xbe, 0xd2, 0xe2, 0xd4, 0x22, 0xb8, - 0x75, 0xc5, 0x12, 0x4c, 0x0a, 0xcc, 0x1a, 0xdc, 0x46, 0x9a, 0x78, 0x8d, 0x03, 0x3b, 0xd1, 0x3b, - 0xb5, 0x32, 0x20, 0x31, 0xb3, 0x28, 0x88, 0x07, 0x64, 0x00, 0x94, 0x53, 0x2c, 0x14, 0xc9, 0x25, - 0x5c, 0x96, 0x98, 0x93, 0x99, 0x92, 0x58, 0x92, 0x8f, 0x6c, 0x2a, 0x33, 0xa9, 0xa6, 0x0a, 0xc2, - 0x4d, 0x81, 0x19, 0xed, 0x14, 0x70, 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, - 0x66, 0xe9, 0x99, 0x25, 0x19, 0xa5, 0x49, 0x7a, 0xc9, 0xf9, 0xb9, 0xfa, 0x79, 0xf9, 0x29, 0xa9, - 0x86, 0x06, 0x86, 0xba, 0x99, 0xf9, 0xfa, 0x10, 0xcb, 0x74, 0x21, 0xc1, 0x5c, 0x81, 0x12, 0xd0, - 0x25, 0x95, 0x05, 0xa9, 0xc5, 0x49, 0x6c, 0xe0, 0xc0, 0x35, 0x06, 0x04, 0x00, 0x00, 0xff, 0xff, - 0x88, 0x60, 0x3e, 0xa4, 0x28, 0x02, 0x00, 0x00, + // 374 bytes of a gzipped FileDescriptorProto + 0x1f, 0x8b, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0xff, 0xac, 0x92, 0xc1, 0x4a, 0xeb, 0x40, + 0x14, 0x86, 0x93, 0xdb, 0x7b, 0x0b, 0x37, 0xbd, 0x8b, 0x6b, 0x54, 0x08, 0x59, 0xc4, 0xd2, 0x8d, + 0x45, 0x68, 0xd2, 0x54, 0xf0, 0x01, 0x2a, 0xe2, 0x42, 0x84, 0x50, 0xab, 0x0b, 0x11, 0xc2, 0x34, + 0x1d, 0xd2, 0xa1, 0x4d, 0x4e, 0x98, 0x99, 0x14, 0xf3, 0x16, 0x3e, 0x86, 0x4b, 0x1f, 0xa3, 0xcb, + 0x2e, 0x5d, 0x89, 0xb4, 0x0b, 0x17, 0xbe, 0x84, 0x64, 0xa6, 0x96, 0x46, 0x31, 0x0b, 0x71, 0x13, + 0x86, 0xf0, 0x9f, 0xef, 0x3b, 0x3f, 0x1c, 0xad, 0x99, 0xa4, 0x13, 0x86, 0x68, 0x30, 0x42, 0x24, + 0x76, 0xc6, 0x38, 0xa3, 0x38, 0x24, 0x8c, 0xd3, 0xcc, 0x99, 0xba, 0x4e, 0x88, 0x63, 0xcc, 0x08, + 0xb3, 0x13, 0x0a, 0x1c, 0x74, 0x73, 0x23, 0x69, 0x6f, 0x24, 0xed, 0xa9, 0x6b, 0x6e, 0xa1, 0x88, + 0xc4, 0xe0, 0x88, 0xaf, 0x8c, 0x9b, 0x3b, 0x21, 0x84, 0x20, 0x9e, 0x4e, 0xfe, 0x5a, 0xfd, 0xdd, + 0x2f, 0xd1, 0x25, 0x88, 0xa2, 0x68, 0x65, 0x33, 0xdb, 0x65, 0xc1, 0x74, 0x30, 0x21, 0x81, 0x3f, + 0xc6, 0x99, 0x9f, 0x20, 0x42, 0xe5, 0x44, 0xe3, 0xb5, 0xa2, 0xfd, 0x3b, 0x95, 0x1b, 0x5f, 0x70, + 0xc4, 0xb1, 0x7e, 0xa2, 0x55, 0x25, 0xd2, 0x50, 0xeb, 0x6a, 0xb3, 0xd6, 0x69, 0xd8, 0x5f, 0x37, + 0xb0, 0x3d, 0x91, 0xec, 0xfe, 0x9d, 0x3d, 0xed, 0x29, 0xf7, 0x2f, 0x0f, 0x07, 0x6a, 0x6f, 0x35, + 0xac, 0xdf, 0x68, 0xdb, 0x29, 0xc3, 0xd4, 0x0f, 0x80, 0x45, 0xc0, 0x7c, 0x0e, 0x7e, 0x44, 0x62, + 0x64, 0xfc, 0xaa, 0x57, 0x9a, 0xb5, 0x4e, 0xab, 0x8c, 0x79, 0xc9, 0x30, 0xf5, 0xc4, 0xae, 0x67, + 0x38, 0xf3, 0x10, 0xa1, 0xbd, 0xff, 0x39, 0xe9, 0x58, 0x80, 0xfa, 0x70, 0x4e, 0x62, 0xb4, 0xa6, + 0xe7, 0xcc, 0x9c, 0x2d, 0x2d, 0x46, 0xe5, 0xdb, 0xf4, 0x9c, 0xda, 0x07, 0xe9, 0xd0, 0xc7, 0x9a, + 0x31, 0x45, 0x13, 0x32, 0x44, 0x1c, 0x3e, 0x15, 0xf8, 0x2d, 0x14, 0x9d, 0x32, 0xc5, 0xd5, 0xfb, + 0x6c, 0xd1, 0xb3, 0xbb, 0x66, 0x16, 0xaa, 0x14, 0x64, 0x1f, 0xfa, 0xfc, 0xf9, 0x01, 0xd9, 0x66, + 0xb3, 0xae, 0x37, 0x5b, 0x58, 0xea, 0x7c, 0x61, 0xa9, 0xcf, 0x0b, 0x4b, 0xbd, 0x5b, 0x5a, 0xca, + 0x7c, 0x69, 0x29, 0x8f, 0x4b, 0x4b, 0xb9, 0x3e, 0x0a, 0x09, 0x1f, 0xa5, 0x03, 0x3b, 0x80, 0xc8, + 0x89, 0x61, 0x88, 0xdd, 0xb6, 0xdb, 0x22, 0xe0, 0x48, 0x73, 0x4b, 0x1e, 0xd4, 0x6d, 0xe1, 0xa4, + 0x78, 0x96, 0x60, 0x36, 0xa8, 0x8a, 0x33, 0x3a, 0x7c, 0x0b, 0x00, 0x00, 0xff, 0xff, 0xd6, 0xfa, + 0x37, 0x9e, 0x12, 0x03, 0x00, 0x00, } func (m *GenesisState) Marshal() (dAtA []byte, err error) { @@ -138,10 +158,38 @@ func (m *GenesisState) MarshalToSizedBuffer(dAtA []byte) (int, error) { _ = i var l int _ = l - if len(m.ValidatorKeyPairs) > 0 { - for iNdEx := len(m.ValidatorKeyPairs) - 1; iNdEx >= 0; iNdEx-- { + if len(m.ValidatorMinaToCosmos) > 0 { + for iNdEx := len(m.ValidatorMinaToCosmos) - 1; iNdEx >= 0; iNdEx-- { + { + size, err := m.ValidatorMinaToCosmos[iNdEx].MarshalToSizedBuffer(dAtA[:i]) + if err != nil { + return 0, err + } + i -= size + i = encodeVarintGenesis(dAtA, i, uint64(size)) + } + i-- + dAtA[i] = 0x2a + } + } + if len(m.ValidatorCosmosToMina) > 0 { + for iNdEx := len(m.ValidatorCosmosToMina) - 1; iNdEx >= 0; iNdEx-- { + { + size, err := m.ValidatorCosmosToMina[iNdEx].MarshalToSizedBuffer(dAtA[:i]) + if err != nil { + return 0, err + } + i -= size + i = encodeVarintGenesis(dAtA, i, uint64(size)) + } + i-- + dAtA[i] = 0x22 + } + } + if len(m.UserMinaToCosmos) > 0 { + for iNdEx := len(m.UserMinaToCosmos) - 1; iNdEx >= 0; iNdEx-- { { - size, err := m.ValidatorKeyPairs[iNdEx].MarshalToSizedBuffer(dAtA[:i]) + size, err := m.UserMinaToCosmos[iNdEx].MarshalToSizedBuffer(dAtA[:i]) if err != nil { return 0, err } @@ -152,10 +200,10 @@ func (m *GenesisState) MarshalToSizedBuffer(dAtA []byte) (int, error) { dAtA[i] = 0x1a } } - if len(m.UserKeyPairs) > 0 { - for iNdEx := len(m.UserKeyPairs) - 1; iNdEx >= 0; iNdEx-- { + if len(m.UserCosmosToMina) > 0 { + for iNdEx := len(m.UserCosmosToMina) - 1; iNdEx >= 0; iNdEx-- { { - size, err := m.UserKeyPairs[iNdEx].MarshalToSizedBuffer(dAtA[:i]) + size, err := m.UserCosmosToMina[iNdEx].MarshalToSizedBuffer(dAtA[:i]) if err != nil { return 0, err } @@ -198,14 +246,26 @@ func (m *GenesisState) Size() (n int) { _ = l l = m.Params.Size() n += 1 + l + sovGenesis(uint64(l)) - if len(m.UserKeyPairs) > 0 { - for _, e := range m.UserKeyPairs { + if len(m.UserCosmosToMina) > 0 { + for _, e := range m.UserCosmosToMina { + l = e.Size() + n += 1 + l + sovGenesis(uint64(l)) + } + } + if len(m.UserMinaToCosmos) > 0 { + for _, e := range m.UserMinaToCosmos { + l = e.Size() + n += 1 + l + sovGenesis(uint64(l)) + } + } + if len(m.ValidatorCosmosToMina) > 0 { + for _, e := range m.ValidatorCosmosToMina { l = e.Size() n += 1 + l + sovGenesis(uint64(l)) } } - if len(m.ValidatorKeyPairs) > 0 { - for _, e := range m.ValidatorKeyPairs { + if len(m.ValidatorMinaToCosmos) > 0 { + for _, e := range m.ValidatorMinaToCosmos { l = e.Size() n += 1 + l + sovGenesis(uint64(l)) } @@ -283,7 +343,7 @@ func (m *GenesisState) Unmarshal(dAtA []byte) error { iNdEx = postIndex case 2: if wireType != 2 { - return fmt.Errorf("proto: wrong wireType = %d for field UserKeyPairs", wireType) + return fmt.Errorf("proto: wrong wireType = %d for field UserCosmosToMina", wireType) } var msglen int for shift := uint(0); ; shift += 7 { @@ -310,14 +370,82 @@ func (m *GenesisState) Unmarshal(dAtA []byte) error { if postIndex > l { return io.ErrUnexpectedEOF } - m.UserKeyPairs = append(m.UserKeyPairs, &PublicKeyPair{}) - if err := m.UserKeyPairs[len(m.UserKeyPairs)-1].Unmarshal(dAtA[iNdEx:postIndex]); err != nil { + m.UserCosmosToMina = append(m.UserCosmosToMina, &UserPublicKeyPair{}) + if err := m.UserCosmosToMina[len(m.UserCosmosToMina)-1].Unmarshal(dAtA[iNdEx:postIndex]); err != nil { return err } iNdEx = postIndex case 3: if wireType != 2 { - return fmt.Errorf("proto: wrong wireType = %d for field ValidatorKeyPairs", wireType) + return fmt.Errorf("proto: wrong wireType = %d for field UserMinaToCosmos", wireType) + } + var msglen int + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowGenesis + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + msglen |= int(b&0x7F) << shift + if b < 0x80 { + break + } + } + if msglen < 0 { + return ErrInvalidLengthGenesis + } + postIndex := iNdEx + msglen + if postIndex < 0 { + return ErrInvalidLengthGenesis + } + if postIndex > l { + return io.ErrUnexpectedEOF + } + m.UserMinaToCosmos = append(m.UserMinaToCosmos, &UserPublicKeyPair{}) + if err := m.UserMinaToCosmos[len(m.UserMinaToCosmos)-1].Unmarshal(dAtA[iNdEx:postIndex]); err != nil { + return err + } + iNdEx = postIndex + case 4: + if wireType != 2 { + return fmt.Errorf("proto: wrong wireType = %d for field ValidatorCosmosToMina", wireType) + } + var msglen int + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowGenesis + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + msglen |= int(b&0x7F) << shift + if b < 0x80 { + break + } + } + if msglen < 0 { + return ErrInvalidLengthGenesis + } + postIndex := iNdEx + msglen + if postIndex < 0 { + return ErrInvalidLengthGenesis + } + if postIndex > l { + return io.ErrUnexpectedEOF + } + m.ValidatorCosmosToMina = append(m.ValidatorCosmosToMina, &ValidatorPublicKeyPair{}) + if err := m.ValidatorCosmosToMina[len(m.ValidatorCosmosToMina)-1].Unmarshal(dAtA[iNdEx:postIndex]); err != nil { + return err + } + iNdEx = postIndex + case 5: + if wireType != 2 { + return fmt.Errorf("proto: wrong wireType = %d for field ValidatorMinaToCosmos", wireType) } var msglen int for shift := uint(0); ; shift += 7 { @@ -344,8 +472,8 @@ func (m *GenesisState) Unmarshal(dAtA []byte) error { if postIndex > l { return io.ErrUnexpectedEOF } - m.ValidatorKeyPairs = append(m.ValidatorKeyPairs, &PublicKeyPair{}) - if err := m.ValidatorKeyPairs[len(m.ValidatorKeyPairs)-1].Unmarshal(dAtA[iNdEx:postIndex]); err != nil { + m.ValidatorMinaToCosmos = append(m.ValidatorMinaToCosmos, &ValidatorPublicKeyPair{}) + if err := m.ValidatorMinaToCosmos[len(m.ValidatorMinaToCosmos)-1].Unmarshal(dAtA[iNdEx:postIndex]); err != nil { return err } iNdEx = postIndex diff --git a/x/keyregistry/types/public_key_pair.pb.go b/x/keyregistry/types/public_key_pair.pb.go index a5554363..db1d3fc2 100644 --- a/x/keyregistry/types/public_key_pair.pb.go +++ b/x/keyregistry/types/public_key_pair.pb.go @@ -23,23 +23,23 @@ var _ = math.Inf const _ = proto.GoGoProtoPackageIsVersion3 // please upgrade the proto package // KeyPair defines the KeyPair message. -type PublicKeyPair struct { +type UserPublicKeyPair struct { MinaKey []byte `protobuf:"bytes,1,opt,name=mina_key,json=minaKey,proto3" json:"mina_key,omitempty"` CosmosKey []byte `protobuf:"bytes,2,opt,name=cosmos_key,json=cosmosKey,proto3" json:"cosmos_key,omitempty"` } -func (m *PublicKeyPair) Reset() { *m = PublicKeyPair{} } -func (m *PublicKeyPair) String() string { return proto.CompactTextString(m) } -func (*PublicKeyPair) ProtoMessage() {} -func (*PublicKeyPair) Descriptor() ([]byte, []int) { +func (m *UserPublicKeyPair) Reset() { *m = UserPublicKeyPair{} } +func (m *UserPublicKeyPair) String() string { return proto.CompactTextString(m) } +func (*UserPublicKeyPair) ProtoMessage() {} +func (*UserPublicKeyPair) Descriptor() ([]byte, []int) { return fileDescriptor_e897d11daaf50b90, []int{0} } -func (m *PublicKeyPair) XXX_Unmarshal(b []byte) error { +func (m *UserPublicKeyPair) XXX_Unmarshal(b []byte) error { return m.Unmarshal(b) } -func (m *PublicKeyPair) XXX_Marshal(b []byte, deterministic bool) ([]byte, error) { +func (m *UserPublicKeyPair) XXX_Marshal(b []byte, deterministic bool) ([]byte, error) { if deterministic { - return xxx_messageInfo_PublicKeyPair.Marshal(b, m, deterministic) + return xxx_messageInfo_UserPublicKeyPair.Marshal(b, m, deterministic) } else { b = b[:cap(b)] n, err := m.MarshalToSizedBuffer(b) @@ -49,26 +49,78 @@ func (m *PublicKeyPair) XXX_Marshal(b []byte, deterministic bool) ([]byte, error return b[:n], nil } } -func (m *PublicKeyPair) XXX_Merge(src proto.Message) { - xxx_messageInfo_PublicKeyPair.Merge(m, src) +func (m *UserPublicKeyPair) XXX_Merge(src proto.Message) { + xxx_messageInfo_UserPublicKeyPair.Merge(m, src) } -func (m *PublicKeyPair) XXX_Size() int { +func (m *UserPublicKeyPair) XXX_Size() int { return m.Size() } -func (m *PublicKeyPair) XXX_DiscardUnknown() { - xxx_messageInfo_PublicKeyPair.DiscardUnknown(m) +func (m *UserPublicKeyPair) XXX_DiscardUnknown() { + xxx_messageInfo_UserPublicKeyPair.DiscardUnknown(m) } -var xxx_messageInfo_PublicKeyPair proto.InternalMessageInfo +var xxx_messageInfo_UserPublicKeyPair proto.InternalMessageInfo -func (m *PublicKeyPair) GetMinaKey() []byte { +func (m *UserPublicKeyPair) GetMinaKey() []byte { if m != nil { return m.MinaKey } return nil } -func (m *PublicKeyPair) GetCosmosKey() []byte { +func (m *UserPublicKeyPair) GetCosmosKey() []byte { + if m != nil { + return m.CosmosKey + } + return nil +} + +type ValidatorPublicKeyPair struct { + MinaKey []byte `protobuf:"bytes,1,opt,name=mina_key,json=minaKey,proto3" json:"mina_key,omitempty"` + CosmosKey []byte `protobuf:"bytes,2,opt,name=cosmos_key,json=cosmosKey,proto3" json:"cosmos_key,omitempty"` +} + +func (m *ValidatorPublicKeyPair) Reset() { *m = ValidatorPublicKeyPair{} } +func (m *ValidatorPublicKeyPair) String() string { return proto.CompactTextString(m) } +func (*ValidatorPublicKeyPair) ProtoMessage() {} +func (*ValidatorPublicKeyPair) Descriptor() ([]byte, []int) { + return fileDescriptor_e897d11daaf50b90, []int{1} +} +func (m *ValidatorPublicKeyPair) XXX_Unmarshal(b []byte) error { + return m.Unmarshal(b) +} +func (m *ValidatorPublicKeyPair) XXX_Marshal(b []byte, deterministic bool) ([]byte, error) { + if deterministic { + return xxx_messageInfo_ValidatorPublicKeyPair.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 *ValidatorPublicKeyPair) XXX_Merge(src proto.Message) { + xxx_messageInfo_ValidatorPublicKeyPair.Merge(m, src) +} +func (m *ValidatorPublicKeyPair) XXX_Size() int { + return m.Size() +} +func (m *ValidatorPublicKeyPair) XXX_DiscardUnknown() { + xxx_messageInfo_ValidatorPublicKeyPair.DiscardUnknown(m) +} + +var xxx_messageInfo_ValidatorPublicKeyPair proto.InternalMessageInfo + +func (m *ValidatorPublicKeyPair) GetMinaKey() []byte { + if m != nil { + return m.MinaKey + } + return nil +} + +func (m *ValidatorPublicKeyPair) GetCosmosKey() []byte { if m != nil { return m.CosmosKey } @@ -76,7 +128,8 @@ func (m *PublicKeyPair) GetCosmosKey() []byte { } func init() { - proto.RegisterType((*PublicKeyPair)(nil), "pulsarchain.keyregistry.v1.PublicKeyPair") + proto.RegisterType((*UserPublicKeyPair)(nil), "pulsarchain.keyregistry.v1.UserPublicKeyPair") + proto.RegisterType((*ValidatorPublicKeyPair)(nil), "pulsarchain.keyregistry.v1.ValidatorPublicKeyPair") } func init() { @@ -84,24 +137,62 @@ func init() { } var fileDescriptor_e897d11daaf50b90 = []byte{ - // 212 bytes of a gzipped FileDescriptorProto + // 231 bytes of a gzipped FileDescriptorProto 0x1f, 0x8b, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0xff, 0xe2, 0x32, 0x28, 0x28, 0xcd, 0x29, 0x4e, 0x2c, 0x4a, 0xce, 0x48, 0xcc, 0xcc, 0xd3, 0xcf, 0x4e, 0xad, 0x2c, 0x4a, 0x4d, 0xcf, 0x2c, 0x2e, 0x29, 0xaa, 0xd4, 0x2f, 0x33, 0xd4, 0x2f, 0x28, 0x4d, 0xca, 0xc9, 0x4c, 0x8e, 0xcf, 0x4e, 0xad, 0x8c, 0x2f, 0x48, 0xcc, 0x2c, 0xd2, 0x2b, 0x28, 0xca, 0x2f, 0xc9, 0x17, 0x92, 0x42, 0xd2, - 0xa1, 0x87, 0xa4, 0x43, 0xaf, 0xcc, 0x50, 0xc9, 0x93, 0x8b, 0x37, 0x00, 0xac, 0xc9, 0x3b, 0xb5, - 0x32, 0x20, 0x31, 0xb3, 0x48, 0x48, 0x92, 0x8b, 0x23, 0x37, 0x33, 0x2f, 0x11, 0x64, 0x86, 0x04, - 0xa3, 0x02, 0xa3, 0x06, 0x4f, 0x10, 0x3b, 0x88, 0xef, 0x9d, 0x5a, 0x29, 0x24, 0xcb, 0xc5, 0x95, - 0x9c, 0x5f, 0x9c, 0x9b, 0x5f, 0x0c, 0x96, 0x64, 0x02, 0x4b, 0x72, 0x42, 0x44, 0xbc, 0x53, 0x2b, - 0x9d, 0x02, 0x4e, 0x3c, 0x92, 0x63, 0xbc, 0xf0, 0x48, 0x8e, 0xf1, 0xc1, 0x23, 0x39, 0xc6, 0x09, - 0x8f, 0xe5, 0x18, 0x2e, 0x3c, 0x96, 0x63, 0xb8, 0xf1, 0x58, 0x8e, 0x21, 0xca, 0x2c, 0x3d, 0xb3, - 0x24, 0xa3, 0x34, 0x49, 0x2f, 0x39, 0x3f, 0x57, 0x3f, 0x2f, 0x3f, 0x25, 0xd5, 0xd0, 0xc0, 0x50, - 0x37, 0x33, 0x5f, 0x1f, 0xe2, 0x2c, 0x5d, 0x88, 0x4f, 0x2a, 0x50, 0xfc, 0x52, 0x52, 0x59, 0x90, - 0x5a, 0x9c, 0xc4, 0x06, 0x76, 0xbf, 0x31, 0x20, 0x00, 0x00, 0xff, 0xff, 0x5f, 0x86, 0xc7, 0xaa, - 0xf3, 0x00, 0x00, 0x00, + 0xa1, 0x87, 0xa4, 0x43, 0xaf, 0xcc, 0x50, 0xc9, 0x97, 0x4b, 0x30, 0xb4, 0x38, 0xb5, 0x28, 0x00, + 0xac, 0xd1, 0x3b, 0xb5, 0x32, 0x20, 0x31, 0xb3, 0x48, 0x48, 0x92, 0x8b, 0x23, 0x37, 0x33, 0x2f, + 0x11, 0x64, 0x8e, 0x04, 0xa3, 0x02, 0xa3, 0x06, 0x4f, 0x10, 0x3b, 0x88, 0xef, 0x9d, 0x5a, 0x29, + 0x24, 0xcb, 0xc5, 0x95, 0x9c, 0x5f, 0x9c, 0x9b, 0x5f, 0x0c, 0x96, 0x64, 0x02, 0x4b, 0x72, 0x42, + 0x44, 0xbc, 0x53, 0x2b, 0x95, 0x82, 0xb8, 0xc4, 0xc2, 0x12, 0x73, 0x32, 0x53, 0x12, 0x4b, 0xf2, + 0xa9, 0x65, 0xa6, 0x53, 0xc0, 0x89, 0x47, 0x72, 0x8c, 0x17, 0x1e, 0xc9, 0x31, 0x3e, 0x78, 0x24, + 0xc7, 0x38, 0xe1, 0xb1, 0x1c, 0xc3, 0x85, 0xc7, 0x72, 0x0c, 0x37, 0x1e, 0xcb, 0x31, 0x44, 0x99, + 0xa5, 0x67, 0x96, 0x64, 0x94, 0x26, 0xe9, 0x25, 0xe7, 0xe7, 0xea, 0xe7, 0xe5, 0xa7, 0xa4, 0x1a, + 0x1a, 0x18, 0xea, 0x66, 0xe6, 0xeb, 0x43, 0xbc, 0xab, 0x0b, 0x09, 0xa1, 0x0a, 0x94, 0x30, 0x2a, + 0xa9, 0x2c, 0x48, 0x2d, 0x4e, 0x62, 0x03, 0x87, 0x8b, 0x31, 0x20, 0x00, 0x00, 0xff, 0xff, 0xbf, + 0x3d, 0x3b, 0xff, 0x4b, 0x01, 0x00, 0x00, +} + +func (m *UserPublicKeyPair) 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 *UserPublicKeyPair) MarshalTo(dAtA []byte) (int, error) { + size := m.Size() + return m.MarshalToSizedBuffer(dAtA[:size]) +} + +func (m *UserPublicKeyPair) MarshalToSizedBuffer(dAtA []byte) (int, error) { + i := len(dAtA) + _ = i + var l int + _ = l + if len(m.CosmosKey) > 0 { + i -= len(m.CosmosKey) + copy(dAtA[i:], m.CosmosKey) + i = encodeVarintPublicKeyPair(dAtA, i, uint64(len(m.CosmosKey))) + i-- + dAtA[i] = 0x12 + } + if len(m.MinaKey) > 0 { + i -= len(m.MinaKey) + copy(dAtA[i:], m.MinaKey) + i = encodeVarintPublicKeyPair(dAtA, i, uint64(len(m.MinaKey))) + i-- + dAtA[i] = 0xa + } + return len(dAtA) - i, nil } -func (m *PublicKeyPair) Marshal() (dAtA []byte, err error) { +func (m *ValidatorPublicKeyPair) Marshal() (dAtA []byte, err error) { size := m.Size() dAtA = make([]byte, size) n, err := m.MarshalToSizedBuffer(dAtA[:size]) @@ -111,12 +202,12 @@ func (m *PublicKeyPair) Marshal() (dAtA []byte, err error) { return dAtA[:n], nil } -func (m *PublicKeyPair) MarshalTo(dAtA []byte) (int, error) { +func (m *ValidatorPublicKeyPair) MarshalTo(dAtA []byte) (int, error) { size := m.Size() return m.MarshalToSizedBuffer(dAtA[:size]) } -func (m *PublicKeyPair) MarshalToSizedBuffer(dAtA []byte) (int, error) { +func (m *ValidatorPublicKeyPair) MarshalToSizedBuffer(dAtA []byte) (int, error) { i := len(dAtA) _ = i var l int @@ -149,7 +240,24 @@ func encodeVarintPublicKeyPair(dAtA []byte, offset int, v uint64) int { dAtA[offset] = uint8(v) return base } -func (m *PublicKeyPair) Size() (n int) { +func (m *UserPublicKeyPair) Size() (n int) { + if m == nil { + return 0 + } + var l int + _ = l + l = len(m.MinaKey) + if l > 0 { + n += 1 + l + sovPublicKeyPair(uint64(l)) + } + l = len(m.CosmosKey) + if l > 0 { + n += 1 + l + sovPublicKeyPair(uint64(l)) + } + return n +} + +func (m *ValidatorPublicKeyPair) Size() (n int) { if m == nil { return 0 } @@ -172,7 +280,125 @@ func sovPublicKeyPair(x uint64) (n int) { func sozPublicKeyPair(x uint64) (n int) { return sovPublicKeyPair(uint64((x << 1) ^ uint64((int64(x) >> 63)))) } -func (m *PublicKeyPair) Unmarshal(dAtA []byte) error { +func (m *UserPublicKeyPair) 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 ErrIntOverflowPublicKeyPair + } + 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: UserPublicKeyPair: wiretype end group for non-group") + } + if fieldNum <= 0 { + return fmt.Errorf("proto: UserPublicKeyPair: illegal tag %d (wire type %d)", fieldNum, wire) + } + switch fieldNum { + case 1: + if wireType != 2 { + return fmt.Errorf("proto: wrong wireType = %d for field MinaKey", wireType) + } + var byteLen int + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowPublicKeyPair + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + byteLen |= int(b&0x7F) << shift + if b < 0x80 { + break + } + } + if byteLen < 0 { + return ErrInvalidLengthPublicKeyPair + } + postIndex := iNdEx + byteLen + if postIndex < 0 { + return ErrInvalidLengthPublicKeyPair + } + if postIndex > l { + return io.ErrUnexpectedEOF + } + m.MinaKey = append(m.MinaKey[:0], dAtA[iNdEx:postIndex]...) + if m.MinaKey == nil { + m.MinaKey = []byte{} + } + iNdEx = postIndex + case 2: + if wireType != 2 { + return fmt.Errorf("proto: wrong wireType = %d for field CosmosKey", wireType) + } + var byteLen int + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowPublicKeyPair + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + byteLen |= int(b&0x7F) << shift + if b < 0x80 { + break + } + } + if byteLen < 0 { + return ErrInvalidLengthPublicKeyPair + } + postIndex := iNdEx + byteLen + if postIndex < 0 { + return ErrInvalidLengthPublicKeyPair + } + if postIndex > l { + return io.ErrUnexpectedEOF + } + m.CosmosKey = append(m.CosmosKey[:0], dAtA[iNdEx:postIndex]...) + if m.CosmosKey == nil { + m.CosmosKey = []byte{} + } + iNdEx = postIndex + default: + iNdEx = preIndex + skippy, err := skipPublicKeyPair(dAtA[iNdEx:]) + if err != nil { + return err + } + if (skippy < 0) || (iNdEx+skippy) < 0 { + return ErrInvalidLengthPublicKeyPair + } + if (iNdEx + skippy) > l { + return io.ErrUnexpectedEOF + } + iNdEx += skippy + } + } + + if iNdEx > l { + return io.ErrUnexpectedEOF + } + return nil +} +func (m *ValidatorPublicKeyPair) Unmarshal(dAtA []byte) error { l := len(dAtA) iNdEx := 0 for iNdEx < l { @@ -195,10 +421,10 @@ func (m *PublicKeyPair) Unmarshal(dAtA []byte) error { fieldNum := int32(wire >> 3) wireType := int(wire & 0x7) if wireType == 4 { - return fmt.Errorf("proto: PublicKeyPair: wiretype end group for non-group") + return fmt.Errorf("proto: ValidatorPublicKeyPair: wiretype end group for non-group") } if fieldNum <= 0 { - return fmt.Errorf("proto: PublicKeyPair: illegal tag %d (wire type %d)", fieldNum, wire) + return fmt.Errorf("proto: ValidatorPublicKeyPair: illegal tag %d (wire type %d)", fieldNum, wire) } switch fieldNum { case 1: diff --git a/x/keyregistry/types/user_public_key_pairs.go b/x/keyregistry/types/user_public_key_pairs.go new file mode 100644 index 00000000..1f8f7b0e --- /dev/null +++ b/x/keyregistry/types/user_public_key_pairs.go @@ -0,0 +1,32 @@ +package types + +import ( + "cosmossdk.io/errors" + "github.com/cometbft/cometbft/crypto/secp256k1" + "github.com/node101-io/mina-signer-go/keys" +) + +func NewUserPublicKeyPairs() []*UserPublicKeyPair { + return []*UserPublicKeyPair{} +} + +func DefaultUserPublicKeyPair() []*UserPublicKeyPair { + return NewUserPublicKeyPairs() +} + +func ValidateUserPublicKeyPair(k UserPublicKeyPair) error { + + if len(k.CosmosKey) != secp256k1.PubKeySize { + return errors.Wrap(ErrInvalidPublicKey, "cosmos public key must be secp256k1 (33 bytes)") + } + + if len(k.MinaKey) != keys.PublicKeyTotalByteSize { + return errors.Wrap(ErrInvalidPublicKey, "mina public key must be compressed (33 bytes)") + } + return nil +} + +// Validate validates the set of params. +func (k UserPublicKeyPair) Validate() error { + return ValidateUserPublicKeyPair(k) +} diff --git a/x/keyregistry/types/validator_public_key_pairs.go b/x/keyregistry/types/validator_public_key_pairs.go new file mode 100644 index 00000000..63acf070 --- /dev/null +++ b/x/keyregistry/types/validator_public_key_pairs.go @@ -0,0 +1,33 @@ +package types + +import ( + "crypto/ed25519" + + "cosmossdk.io/errors" + "github.com/node101-io/mina-signer-go/keys" +) + +func NewValidatorPublicKeyPairs() []*ValidatorPublicKeyPair { + return []*ValidatorPublicKeyPair{} +} + +func DefaultValidatorPublicKeyPair() []*ValidatorPublicKeyPair { + return NewValidatorPublicKeyPairs() +} + +func ValidateValidatorPublicKeyPair(k ValidatorPublicKeyPair) error { + + if len(k.CosmosKey) != ed25519.PublicKeySize { + return errors.Wrap(ErrInvalidPublicKey, "cosmos public key must be ed25519 (32 bytes)") + } + + if len(k.MinaKey) != keys.PublicKeyTotalByteSize { + return errors.Wrap(ErrInvalidPublicKey, "mina public key must be compressed (33 bytes)") + } + return nil +} + +// Validate validates the set of params. +func (k ValidatorPublicKeyPair) Validate() error { + return ValidateValidatorPublicKeyPair(k) +} From 43c6fa1d4c755a33ecdeb43096b0203b3695cef6 Mon Sep 17 00:00:00 2001 From: Yusuf Date: Fri, 24 Apr 2026 19:36:11 +0300 Subject: [PATCH 12/62] fix: validator public keys are now ed25519, rather than secp256k1. different from users --- x/keyregistry/keeper/keeper.go | 8 +-- .../keeper/msg_server_register_keys.go | 11 +++- .../keeper/msg_server_register_user_keys.go | 7 +- .../msg_server_register_validator_keys.go | 8 +-- .../keeper/msg_server_update_keys.go | 9 ++- .../keeper/query_validator_keypairs_test.go | 8 +-- .../keeper/user_register_keys_test.go | 38 +++++++++-- x/keyregistry/keeper/user_update_keys_test.go | 22 +++---- .../keeper/validator_register_keys_test.go | 43 ++---------- .../keeper/validator_update_keys_test.go | 66 ++++++++++--------- x/keyregistry/types/errors.go | 1 + x/keyregistry/types/public_key_pairs.go | 35 ---------- 12 files changed, 109 insertions(+), 147 deletions(-) delete mode 100644 x/keyregistry/types/public_key_pairs.go diff --git a/x/keyregistry/keeper/keeper.go b/x/keyregistry/keeper/keeper.go index 851d23f8..b59a8f20 100644 --- a/x/keyregistry/keeper/keeper.go +++ b/x/keyregistry/keeper/keeper.go @@ -28,11 +28,11 @@ type Keeper struct { Schema collections.Schema Params collections.Item[types.Params] - userCosmosToMina collections.Map[[]byte, []byte] // Cosmos Address --> Mina Address - userMinaToCosmos collections.Map[[]byte, []byte] // Mina Address --> Cosmos Address + userCosmosToMina collections.Map[[]byte, []byte] // Cosmos Public Key --> Mina Public Key + userMinaToCosmos collections.Map[[]byte, []byte] // Mina Public Key --> CosmosPublic Key - validatorCosmosToMina collections.Map[[]byte, []byte] // Validator Cosmos Address --> Validator Mina Address - validatorMinaToCosmos collections.Map[[]byte, []byte] // Validator Mina Address --> Validator Cosmos Address + validatorCosmosToMina collections.Map[[]byte, []byte] // Validator Cosmos Public Key --> Validator Mina Public Key + validatorMinaToCosmos collections.Map[[]byte, []byte] // Validator Mina Public Key --> Validator Cosmos Public Key } func NewKeeper( diff --git a/x/keyregistry/keeper/msg_server_register_keys.go b/x/keyregistry/keeper/msg_server_register_keys.go index ce901c65..c2eadf55 100644 --- a/x/keyregistry/keeper/msg_server_register_keys.go +++ b/x/keyregistry/keeper/msg_server_register_keys.go @@ -30,14 +30,19 @@ func VerifyValidatorCosmosSig(sig string, msg, cosmosAddress []byte) bool { // deriveAddressFromPubkey derives the expected signer address from the provided // key material. -func deriveAddressFromPubkey(cosmosAddress []byte) string { +func deriveAddressFromPubkey(actorType types.ActorType, cosmosPublicKey []byte) (string, error) { + + if actorType != types.ActorType_USER { + return "", types.ErrInvalidActorType + } pubKey := secp256k1.PubKey{ - Key: cosmosAddress, + Key: cosmosPublicKey, } addr := sdk.AccAddress(pubKey.Address()) - return addr.String() + return addr.String(), nil + } // RegisterKeys registers a Mina and Cosmos public key pair on chain. diff --git a/x/keyregistry/keeper/msg_server_register_user_keys.go b/x/keyregistry/keeper/msg_server_register_user_keys.go index b500d4aa..2a2d5022 100644 --- a/x/keyregistry/keeper/msg_server_register_user_keys.go +++ b/x/keyregistry/keeper/msg_server_register_user_keys.go @@ -13,7 +13,7 @@ func (k msgServer) handleUserRegistration(ctx context.Context, msg *types.MsgReg return errorsmod.Wrap(types.ErrInvalidCreatorAddres, "") } - err = types.ValidatePublicKeyPair(types.PublicKeyPair{ + err = types.ValidateUserPublicKeyPair(types.UserPublicKeyPair{ MinaKey: msg.MinaPublicKey, CosmosKey: msg.CosmosPublicKey, }) @@ -21,7 +21,10 @@ func (k msgServer) handleUserRegistration(ctx context.Context, msg *types.MsgReg return errorsmod.Wrap(types.ErrInvalidPublicKey, "") } - cosmosAddr := deriveAddressFromPubkey(msg.CosmosPublicKey) + cosmosAddr, err := deriveAddressFromPubkey(msg.ActorType, msg.CosmosPublicKey) + if err != nil { + return err + } if msg.Creator != cosmosAddr { return errorsmod.Wrap(types.ErrInvalidSigner, "") diff --git a/x/keyregistry/keeper/msg_server_register_validator_keys.go b/x/keyregistry/keeper/msg_server_register_validator_keys.go index 38235fbd..4fedf5f0 100644 --- a/x/keyregistry/keeper/msg_server_register_validator_keys.go +++ b/x/keyregistry/keeper/msg_server_register_validator_keys.go @@ -16,7 +16,7 @@ func (k msgServer) handleValidatorRegistration(ctx context.Context, msg *types.M return errorsmod.Wrap(types.ErrInvalidCreatorAddres, "") } - err = types.ValidatePublicKeyPair(types.PublicKeyPair{ + err = types.ValidateValidatorPublicKeyPair(types.ValidatorPublicKeyPair{ MinaKey: msg.MinaPublicKey, CosmosKey: msg.CosmosPublicKey, }) @@ -24,12 +24,6 @@ func (k msgServer) handleValidatorRegistration(ctx context.Context, msg *types.M return errorsmod.Wrap(types.ErrInvalidPublicKey, "pubkeys must be valid") } - derivedAddress := deriveAddressFromPubkey(msg.CosmosPublicKey) - - if derivedAddress != msg.Creator { - return errorsmod.Wrap(types.ErrInvalidSigner, "creator does not match provided cosmos public key") - } - return k.persistValidatorRegistration(ctx, msg) } diff --git a/x/keyregistry/keeper/msg_server_update_keys.go b/x/keyregistry/keeper/msg_server_update_keys.go index 4f62dc86..daaa1072 100644 --- a/x/keyregistry/keeper/msg_server_update_keys.go +++ b/x/keyregistry/keeper/msg_server_update_keys.go @@ -52,7 +52,10 @@ func (k msgServer) updateUserKeys(ctx context.Context, msg *types.MsgUpdateKeys) return err } - cosmosAddr := deriveAddressFromPubkey(cosmosPublicKey) + cosmosAddr, err := deriveAddressFromPubkey(msg.ActorType, cosmosPublicKey) + if err != nil { + return err + } if msg.Creator != cosmosAddr { return errorsmod.Wrap(types.ErrInvalidSigner, "") @@ -119,10 +122,6 @@ func (k msgServer) updateValidatorKeys(ctx context.Context, msg *types.MsgUpdate return err } - if deriveAddressFromPubkey(cosmosPublicKey) != msg.Creator { - return errorsmod.Wrap(types.ErrInvalidSigner, "") - } - exists, err = k.ValidatorCosmosToMinaHas(ctx, cosmosPublicKey) if err != nil { return err diff --git a/x/keyregistry/keeper/query_validator_keypairs_test.go b/x/keyregistry/keeper/query_validator_keypairs_test.go index 0e2395fe..aad98d2f 100644 --- a/x/keyregistry/keeper/query_validator_keypairs_test.go +++ b/x/keyregistry/keeper/query_validator_keypairs_test.go @@ -35,7 +35,7 @@ func TestValidatorCosmosMapSuccess(t *testing.T) { params := types.DefaultParams() require.NoError(t, f.keeper.Params.Set(f.ctx, params)) - cosmosPubKey, minaPubKey, _, err := generatePublicKeys() + cosmosPubKey, minaPubKey, _, err := generateValidatorPublicKeys() require.NoError(t, err) err = f.keeper.ValidatorSetCosmosToMina(f.ctx, cosmosPubKey.Bytes(), minaPubKey) @@ -60,7 +60,7 @@ func TestValidatorMinaMapSuccess(t *testing.T) { params := types.DefaultParams() require.NoError(t, f.keeper.Params.Set(f.ctx, params)) - cosmosPubKey, minaPubKey, _, err := generatePublicKeys() + cosmosPubKey, minaPubKey, _, err := generateValidatorPublicKeys() require.NoError(t, err) err = f.keeper.ValidatorSetMinaToCosmos(f.ctx, minaPubKey, cosmosPubKey.Bytes()) @@ -100,7 +100,7 @@ func TestValidatorCosmosMapPubkeyNotFound(t *testing.T) { params := types.DefaultParams() require.NoError(t, f.keeper.Params.Set(f.ctx, params)) - _, minaPubKey, _, err := generatePublicKeys() + _, minaPubKey, _, err := generateValidatorPublicKeys() require.NotNil(t, minaPubKey) require.NoError(t, err) @@ -121,7 +121,7 @@ func TestValidatorMinaMapPubkeyNotFound(t *testing.T) { params := types.DefaultParams() require.NoError(t, f.keeper.Params.Set(f.ctx, params)) - cosmosPubKey, minaPubKey, _, err := generatePublicKeys() + cosmosPubKey, minaPubKey, _, err := generateValidatorPublicKeys() require.NotNil(t, cosmosPubKey) require.NotNil(t, minaPubKey) require.NoError(t, err) diff --git a/x/keyregistry/keeper/user_register_keys_test.go b/x/keyregistry/keeper/user_register_keys_test.go index 669ac2ae..baa5a9c2 100644 --- a/x/keyregistry/keeper/user_register_keys_test.go +++ b/x/keyregistry/keeper/user_register_keys_test.go @@ -3,6 +3,8 @@ package keeper_test import ( "testing" + cometed25519 "github.com/cometbft/cometbft/crypto/ed25519" + "github.com/cometbft/cometbft/crypto" "github.com/cometbft/cometbft/crypto/secp256k1" sdk "github.com/cosmos/cosmos-sdk/types" @@ -19,7 +21,7 @@ var mockMinaSignature = "minaSig" var MinaPriv = []byte("7olA5Knafb5E2hJoWFzD+oamtyXIXXUZmYG9+pBMjTGIjqZTVLNGbE7DQ3Zq5YL5NMW31UMMMGgNCeEk+gyzRA==") -func generatePublicKeys() (crypto.PubKey, []byte, []byte, error) { +func generateUserPublicKeys() (crypto.PubKey, []byte, []byte, error) { cosmosPrivKey := secp256k1.GenPrivKey() cosmosPublicKey := cosmosPrivKey.PubKey() @@ -41,6 +43,28 @@ func generatePublicKeys() (crypto.PubKey, []byte, []byte, error) { return cosmosPublicKey, minaPublicKey, minaSecondaryPublicKey, nil } +func generateValidatorPublicKeys() (crypto.PubKey, []byte, []byte, error) { + + cosmosPrivKey := cometed25519.GenPrivKey() + cosmosPublicKey := cosmosPrivKey.PubKey() + + minaPrivKey := keys.NewPrivateKeyFromBytes([32]byte(MinaPriv)) + + minaPublicKey, err := minaPrivKey.ToPublicKey().Marshal() + if err != nil { + return nil, nil, nil, err + } + + minaSecondaryPrivKey := keys.NewPrivateKeyFromBytes([32]byte(MinaSecondaryPriv)) + + minaSecondaryPublicKey, err := minaSecondaryPrivKey.ToPublicKey().Marshal() + if err != nil { + return nil, nil, nil, err + } + + return cosmosPublicKey, minaPublicKey, minaSecondaryPublicKey, nil +} + // TestUserRegisterKeysFail verifies that RegisterKeys fails with ErrInvalidPublicKey // when the provided key material does not satisfy the current user registration checks. func TestUserRegisterKeysFail(t *testing.T) { @@ -65,7 +89,7 @@ func TestUserRegisterKeysFail(t *testing.T) { // and ensures that both CosmosToMina and MinaToCosmos mappings are correctly stored. func TestUserRegisterKeysSuccess(t *testing.T) { - cosmosPublicKey, minaPubKey, _, err := generatePublicKeys() + cosmosPublicKey, minaPubKey, _, err := generateUserPublicKeys() require.NoError(t, err) require.NotNil(t, cosmosPublicKey) require.NotNil(t, minaPubKey) @@ -102,7 +126,7 @@ func TestUserRegisterKeysSuccess(t *testing.T) { // when the creator field is not a valid bech32 address. func TestUserInvalidCreatorAddress(t *testing.T) { - cosmosPublicKey, minaPubKey, _, err := generatePublicKeys() + cosmosPublicKey, minaPubKey, _, err := generateUserPublicKeys() require.NotNil(t, cosmosPublicKey) require.NotNil(t, minaPubKey) @@ -126,12 +150,12 @@ func TestUserInvalidCreatorAddress(t *testing.T) { // when the creator address bytes do not match the provided Cosmos-side value. func TestUserInvalidSigner(t *testing.T) { - cosmosPublicKey, minaPubKey, _, err := generatePublicKeys() + cosmosPublicKey, minaPubKey, _, err := generateUserPublicKeys() require.NoError(t, err) require.NotNil(t, cosmosPublicKey) require.NotNil(t, minaPubKey) - secondaryCosmosPublicKey, _, _, err := generatePublicKeys() + secondaryCosmosPublicKey, _, _, err := generateUserPublicKeys() require.NoError(t, err) require.NotNil(t, secondaryCosmosPublicKey) @@ -158,7 +182,7 @@ func TestUserInvalidSigner(t *testing.T) { // TestUserInvalidSignature currently expects no error since signature verification is not yet implemented. func TestUserInvalidSignature(t *testing.T) { - cosmosPublicKey, minaPubKey, _, err := generatePublicKeys() + cosmosPublicKey, minaPubKey, _, err := generateUserPublicKeys() require.NoError(t, err) require.NotNil(t, cosmosPublicKey) @@ -190,7 +214,7 @@ func TestUserInvalidSignature(t *testing.T) { func TestUserInsertSecondaryKeysFail(t *testing.T) { f := initFixture(t) - cosmosPublicKey, minaPubKey, minaSecondaryPublicKey, err := generatePublicKeys() + cosmosPublicKey, minaPubKey, minaSecondaryPublicKey, err := generateUserPublicKeys() require.NoError(t, err) require.NotNil(t, cosmosPublicKey) require.NotNil(t, minaPubKey) diff --git a/x/keyregistry/keeper/user_update_keys_test.go b/x/keyregistry/keeper/user_update_keys_test.go index f4dc5493..d25afb61 100644 --- a/x/keyregistry/keeper/user_update_keys_test.go +++ b/x/keyregistry/keeper/user_update_keys_test.go @@ -12,10 +12,10 @@ import ( var MinaSecondaryPriv = []byte("0GUKibsJSZwgiU7k4cXQQWb2QKEP9/iRFATJEUqf2Pc+GxciLMKRQGTIcInKsTzV09rjDsLmZiBl9Up71bvV6g==") -func registerKeysForUpdateTest(t *testing.T, f *fixture, ms types.MsgServer, ActorType types.ActorType) (crypto.PubKey, []byte, []byte) { +func registerUserKeysForUpdateTest(t *testing.T, f *fixture, ms types.MsgServer) (crypto.PubKey, []byte, []byte) { t.Helper() - cosmosPublicKey, minaPublicKey, minaSecondaryPublicKey, err := generatePublicKeys() + cosmosPublicKey, minaPublicKey, minaSecondaryPublicKey, err := generateUserPublicKeys() require.NotNil(t, cosmosPublicKey) require.NotNil(t, minaPublicKey) require.NotNil(t, minaSecondaryPublicKey) @@ -31,7 +31,7 @@ func registerKeysForUpdateTest(t *testing.T, f *fixture, ms types.MsgServer, Act MinaSignature: mockMinaSignature, CosmosPublicKey: cosmosPublicKey.Bytes(), MinaPublicKey: minaPublicKey, - ActorType: ActorType, + ActorType: types.ActorType_USER, }) require.NoError(t, err) require.NotNil(t, resp) @@ -43,7 +43,7 @@ func TestUserUpdateKeysSuccess(t *testing.T) { f := initFixture(t) ms := keeper.NewMsgServerImpl(f.keeper) - cosmosPublicKey, prevMinaPublicKey, newMinaPublicKey := registerKeysForUpdateTest(t, f, ms, types.ActorType_USER) + cosmosPublicKey, prevMinaPublicKey, newMinaPublicKey := registerUserKeysForUpdateTest(t, f, ms) creatorAddr := sdk.AccAddress(cosmosPublicKey.Address()) require.NotNil(t, creatorAddr) @@ -80,7 +80,7 @@ func TestUserUpdateKeysNotRegistered(t *testing.T) { f := initFixture(t) ms := keeper.NewMsgServerImpl(f.keeper) - cosmosPublicKey, prevMinaPublicKey, minaSecondaryPublicKey, err := generatePublicKeys() + cosmosPublicKey, prevMinaPublicKey, minaSecondaryPublicKey, err := generateUserPublicKeys() require.NoError(t, err) require.NotNil(t, cosmosPublicKey) require.NotNil(t, prevMinaPublicKey) @@ -104,7 +104,7 @@ func TestUserUpdateKeysInvalidCreatorAddress(t *testing.T) { f := initFixture(t) ms := keeper.NewMsgServerImpl(f.keeper) - _, prevMinaPublicKey, newMinaPublicKey := registerKeysForUpdateTest(t, f, ms, types.ActorType_USER) + _, prevMinaPublicKey, newMinaPublicKey := registerUserKeysForUpdateTest(t, f, ms) _, err := ms.UpdateKeys(f.ctx, &types.MsgUpdateKeys{ Creator: "creator", @@ -122,9 +122,9 @@ func TestUserUpdateKeysInvalidSigner(t *testing.T) { f := initFixture(t) ms := keeper.NewMsgServerImpl(f.keeper) - _, prevMinaAddr, _ := registerKeysForUpdateTest(t, f, ms, types.ActorType_USER) + _, prevMinaAddr, _ := registerUserKeysForUpdateTest(t, f, ms) - secondaryAddr, newMinaAddr, _, err := generatePublicKeys() + secondaryAddr, newMinaAddr, _, err := generateUserPublicKeys() require.NoError(t, err) require.NotNil(t, secondaryAddr) require.NotNil(t, newMinaAddr) @@ -147,7 +147,7 @@ func TestUserUpdateKeysInvalidSignature(t *testing.T) { f := initFixture(t) ms := keeper.NewMsgServerImpl(f.keeper) - cosmosPublicKey, prevMinaAddr, newMinaAddr := registerKeysForUpdateTest(t, f, ms, types.ActorType_USER) + cosmosPublicKey, prevMinaAddr, newMinaAddr := registerUserKeysForUpdateTest(t, f, ms) creatorAddr := sdk.AccAddress(cosmosPublicKey.Address()) @@ -166,8 +166,8 @@ func TestUserUpdateKeysInsertSecondaryKeysFail(t *testing.T) { f := initFixture(t) ms := keeper.NewMsgServerImpl(f.keeper) - firstCosmosPublicKey, prevMinaPublicKey, _ := registerKeysForUpdateTest(t, f, ms, types.ActorType_USER) - secondCosmosPublicKey, _, targetMinaPublicKey, err := generatePublicKeys() + firstCosmosPublicKey, prevMinaPublicKey, _ := registerUserKeysForUpdateTest(t, f, ms) + secondCosmosPublicKey, _, targetMinaPublicKey, err := generateUserPublicKeys() require.NoError(t, err) require.NotNil(t, secondCosmosPublicKey) require.NotNil(t, targetMinaPublicKey) diff --git a/x/keyregistry/keeper/validator_register_keys_test.go b/x/keyregistry/keeper/validator_register_keys_test.go index 4f1975f2..d3662acc 100644 --- a/x/keyregistry/keeper/validator_register_keys_test.go +++ b/x/keyregistry/keeper/validator_register_keys_test.go @@ -16,7 +16,7 @@ func TestValidatorRegisterKeysFail(t *testing.T) { f := initFixture(t) ms := keeper.NewMsgServerImpl(f.keeper) - cosmosPublicKey, _, _, err := generatePublicKeys() + cosmosPublicKey, _, _, err := generateValidatorPublicKeys() require.NoError(t, err) require.NotNil(t, cosmosPublicKey) @@ -39,7 +39,7 @@ func TestValidatorRegisterKeysFail(t *testing.T) { // and ensures that both CosmosToMina and MinaToCosmos mappings are correctly stored. func TestValidatorRegisterKeysSuccess(t *testing.T) { - cosmosPubKey, minaPubKey, _, err := generatePublicKeys() + cosmosPubKey, minaPubKey, _, err := generateValidatorPublicKeys() require.NoError(t, err) require.NotNil(t, cosmosPubKey) require.NotNil(t, minaPubKey) @@ -74,7 +74,7 @@ func TestValidatorRegisterKeysSuccess(t *testing.T) { // when the creator field is not a valid bech32 address. func TestValidatorInvalidCreatorAddress(t *testing.T) { - cosmosPubKey, minaPubKey, _, err := generatePublicKeys() + cosmosPubKey, minaPubKey, _, err := generateValidatorPublicKeys() require.NoError(t, err) require.NotNil(t, cosmosPubKey) @@ -95,44 +95,11 @@ func TestValidatorInvalidCreatorAddress(t *testing.T) { require.ErrorIs(t, err, types.ErrInvalidCreatorAddres) } -// TestValidatorInvalidSigner verifies that RegisterKeys fails with ErrInvalidSigner -// when the creator address does not match the address derived from the provided consensus public key. -func TestValidatorInvalidSigner(t *testing.T) { - - cosmosPubKey, minaPubKey, _, err := generatePublicKeys() - - require.NoError(t, err) - require.NotNil(t, cosmosPubKey) - require.NotNil(t, minaPubKey) - - secondaryCosmosPublicKey, _, _, err := generatePublicKeys() - - require.NoError(t, err) - require.NotNil(t, secondaryCosmosPublicKey) - - creatorAddr := sdk.AccAddress(secondaryCosmosPublicKey.Address()) - require.NotNil(t, creatorAddr) - - f := initFixture(t) - ms := keeper.NewMsgServerImpl(f.keeper) - - _, err = ms.RegisterKeys(f.ctx, &types.MsgRegisterKeys{ - Creator: creatorAddr.String(), - CosmosSignature: mockCosmosSignature, - MinaSignature: mockMinaSignature, - CosmosPublicKey: cosmosPubKey.Bytes(), - MinaPublicKey: minaPubKey, - ActorType: types.ActorType_VALIDATOR, - }) - - require.ErrorIs(t, err, types.ErrInvalidSigner) -} - // TODO: Update require.NoError to require.ErrorIs once the VerifyCosmosSig and VerifyMinaSig is implemented // TestValidatorInvalidSignature currently expects no error since signature verification is not yet implemented. func TestValidatorInvalidSignature(t *testing.T) { - cosmosPubKey, minaPubKey, _, err := generatePublicKeys() + cosmosPubKey, minaPubKey, _, err := generateValidatorPublicKeys() require.NoError(t, err) require.NotNil(t, cosmosPubKey) @@ -164,7 +131,7 @@ func TestValidatorInvalidSignature(t *testing.T) { func TestValidatorInsertSecondaryKeysFail(t *testing.T) { f := initFixture(t) - cosmosPubKey, minaPubKey, _, err := generatePublicKeys() + cosmosPubKey, minaPubKey, _, err := generateValidatorPublicKeys() require.NoError(t, err) require.NotNil(t, cosmosPubKey) diff --git a/x/keyregistry/keeper/validator_update_keys_test.go b/x/keyregistry/keeper/validator_update_keys_test.go index efc75cf0..762d2a28 100644 --- a/x/keyregistry/keeper/validator_update_keys_test.go +++ b/x/keyregistry/keeper/validator_update_keys_test.go @@ -3,17 +3,45 @@ package keeper_test import ( "testing" + "github.com/cometbft/cometbft/crypto" sdk "github.com/cosmos/cosmos-sdk/types" "github.com/node101-io/pulsar-chain/x/keyregistry/keeper" "github.com/node101-io/pulsar-chain/x/keyregistry/types" "github.com/stretchr/testify/require" ) +func registerValidatorKeysForUpdateTest(t *testing.T, f *fixture, ms types.MsgServer) (crypto.PubKey, []byte, []byte) { + t.Helper() + + cosmosPublicKey, minaPublicKey, minaSecondaryPublicKey, err := generateValidatorPublicKeys() + require.NotNil(t, cosmosPublicKey) + require.NotNil(t, minaPublicKey) + require.NotNil(t, minaSecondaryPublicKey) + + require.NoError(t, err) + + creatorAddr := sdk.AccAddress(cosmosPublicKey.Address()) + require.NotNil(t, creatorAddr) + + resp, err := ms.RegisterKeys(f.ctx, &types.MsgRegisterKeys{ + Creator: creatorAddr.String(), + CosmosSignature: mockCosmosSignature, + MinaSignature: mockMinaSignature, + CosmosPublicKey: cosmosPublicKey.Bytes(), + MinaPublicKey: minaPublicKey, + ActorType: types.ActorType_VALIDATOR, + }) + require.NoError(t, err) + require.NotNil(t, resp) + + return cosmosPublicKey, minaPublicKey, minaSecondaryPublicKey +} + func TestValidatorUpdateKeysSuccess(t *testing.T) { f := initFixture(t) ms := keeper.NewMsgServerImpl(f.keeper) - cosmosPublicKey, prevMinaPubKey, newMinaPubKey := registerKeysForUpdateTest(t, f, ms, types.ActorType_VALIDATOR) + cosmosPublicKey, prevMinaPubKey, newMinaPubKey := registerValidatorKeysForUpdateTest(t, f, ms) creatorAddr := sdk.AccAddress(cosmosPublicKey.Address()) require.NotNil(t, creatorAddr) @@ -50,7 +78,7 @@ func TestValidatorUpdateKeysNotRegistered(t *testing.T) { f := initFixture(t) ms := keeper.NewMsgServerImpl(f.keeper) - cosmosPublicKey, prevMinaPubKey, newMinaPubKey, err := generatePublicKeys() + cosmosPublicKey, prevMinaPubKey, newMinaPubKey, err := generateValidatorPublicKeys() require.NoError(t, err) require.NotNil(t, cosmosPublicKey) require.NotNil(t, prevMinaPubKey) @@ -74,7 +102,7 @@ func TestValidatorUpdateKeysMissingCosmosToMinaMapping(t *testing.T) { f := initFixture(t) ms := keeper.NewMsgServerImpl(f.keeper) - cosmosPublicKey, prevMinaPubKey, newMinaPubKey, err := generatePublicKeys() + cosmosPublicKey, prevMinaPubKey, newMinaPubKey, err := generateValidatorPublicKeys() require.NoError(t, err) require.NotNil(t, cosmosPublicKey) require.NotNil(t, prevMinaPubKey) @@ -101,7 +129,7 @@ func TestValidatorUpdateKeysInvalidCreatorAddress(t *testing.T) { f := initFixture(t) ms := keeper.NewMsgServerImpl(f.keeper) - _, prevMinaPubKey, newMinaPubKey, err := generatePublicKeys() + _, prevMinaPubKey, newMinaPubKey, err := generateValidatorPublicKeys() require.NoError(t, err) require.NotNil(t, prevMinaPubKey) @@ -118,35 +146,11 @@ func TestValidatorUpdateKeysInvalidCreatorAddress(t *testing.T) { require.ErrorIs(t, err, types.ErrInvalidCreatorAddres) } -func TestValidatorUpdateKeysInvalidSigner(t *testing.T) { - f := initFixture(t) - ms := keeper.NewMsgServerImpl(f.keeper) - - _, prevMinaPubKey, newMinaPublicKey := registerKeysForUpdateTest(t, f, ms, types.ActorType_VALIDATOR) - - secondaryCreator, _, _, err := generatePublicKeys() - require.NoError(t, err) - require.NotNil(t, secondaryCreator) - - secondaryCreatorAddr := sdk.AccAddress(secondaryCreator.Address()) - require.NotNil(t, secondaryCreatorAddr) - - _, err = ms.UpdateKeys(f.ctx, &types.MsgUpdateKeys{ - Creator: secondaryCreatorAddr.String(), - PrevMinaPublicKey: prevMinaPubKey, - NewMinaPublicKey: newMinaPublicKey, - CosmosSignature: []byte(mockCosmosSignature), - NewMinaSignature: []byte(mockMinaSignature), - ActorType: types.ActorType_VALIDATOR, - }) - require.ErrorIs(t, err, types.ErrInvalidSigner) -} - func TestValidatorUpdateKeysInvalidSignature(t *testing.T) { f := initFixture(t) ms := keeper.NewMsgServerImpl(f.keeper) - cosmosPublicKey, prevMinaPubKey, newMinaPublicKey := registerKeysForUpdateTest(t, f, ms, types.ActorType_VALIDATOR) + cosmosPublicKey, prevMinaPubKey, newMinaPublicKey := registerValidatorKeysForUpdateTest(t, f, ms) creatorAddr := sdk.AccAddress(cosmosPublicKey.Address()) require.NotNil(t, creatorAddr) @@ -166,8 +170,8 @@ func TestValidatorUpdateKeysInsertSecondaryKeysFail(t *testing.T) { f := initFixture(t) ms := keeper.NewMsgServerImpl(f.keeper) - firstCosmosPublicKey, prevMinaPublicKey, _ := registerKeysForUpdateTest(t, f, ms, types.ActorType_VALIDATOR) - secondCosmosPublicKey, _, targetMinaPublicKey, err := generatePublicKeys() + firstCosmosPublicKey, prevMinaPublicKey, _ := registerValidatorKeysForUpdateTest(t, f, ms) + secondCosmosPublicKey, _, targetMinaPublicKey, err := generateValidatorPublicKeys() require.NoError(t, err) require.NotNil(t, secondCosmosPublicKey) require.NotNil(t, targetMinaPublicKey) diff --git a/x/keyregistry/types/errors.go b/x/keyregistry/types/errors.go index 8854acf7..00b27d62 100644 --- a/x/keyregistry/types/errors.go +++ b/x/keyregistry/types/errors.go @@ -17,4 +17,5 @@ var ( ErrUserNotRegistered = errors.Register(ModuleName, 1106, "user has not been registered") ErrValidatorNotRegistered = errors.Register(ModuleName, 1107, "validator has not been registered") ErrInvalidActorType = errors.Register(ModuleName, 1108, "invalid actor type") + ErrNilKeyPair = errors.Register(ModuleName, 1109, "nil keypair") ) diff --git a/x/keyregistry/types/public_key_pairs.go b/x/keyregistry/types/public_key_pairs.go deleted file mode 100644 index 69fb2bf4..00000000 --- a/x/keyregistry/types/public_key_pairs.go +++ /dev/null @@ -1,35 +0,0 @@ -package types - -import ( - "cosmossdk.io/errors" - "github.com/cometbft/cometbft/crypto/secp256k1" - "github.com/node101-io/mina-signer-go/keys" -) - -func NewPublicKeyPairs() []*PublicKeyPair { - return []*PublicKeyPair{} -} -func DefaultUserPublicKeyPairs() []*PublicKeyPair { - return NewPublicKeyPairs() -} - -func DefaultPublicKeyPair() []*PublicKeyPair { - return NewPublicKeyPairs() -} - -func ValidatePublicKeyPair(k PublicKeyPair) error { - - if len(k.CosmosKey) != secp256k1.PubKeySize { - return errors.Wrap(ErrInvalidPublicKey, "cosmos public key must be secp256k1 (33 bytes)") - } - - if len(k.MinaKey) != keys.PublicKeyTotalByteSize { - return errors.Wrap(ErrInvalidPublicKey, "mina public key must be compressed (33 bytes)") - } - return nil -} - -// Validate validates the set of params. -func (k PublicKeyPair) Validate() error { - return ValidatePublicKeyPair(k) -} From e87b183fdb1dcc651aeb40516a10ce5c0b3c72ca Mon Sep 17 00:00:00 2001 From: Yusuf Date: Fri, 24 Apr 2026 21:54:04 +0300 Subject: [PATCH 13/62] fix: make config compatible with the new genesis structure --- config.yml | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/config.yml b/config.yml index 7a327269..11846e3f 100644 --- a/config.yml +++ b/config.yml @@ -30,9 +30,15 @@ genesis: app_state: keyregistry: params: {} - user_key_pairs: + user_cosmos_to_mina: # - mina_key: "SC/6aqoZ19ObLka8NIQVMs1qPim+uD6epPLuQS4x2n4Z" # cosmos_key: "UdDr3CCO+4HVrBtbzqLTM3P2xAMNCIrPeCTeVfb5sw1y" - validator_key_pairs: + user_mina_to_cosmos: + # - mina_key: "3IvK1eWmmcfdlIb+T04+ck9Q5bjbqHqiT0ucGJITzyY=" + # cosmos_key: "A8saw69s1DQWvUjseeOtG8hGavmYiInrQ5M1aOPa4QkP" + validator_cosmos_to_mina: + # - mina_key: "SC/6aqoZ19ObLka8NIQVMs1qPim+uD6epPLuQS4x2n4Z" + # cosmos_key: "UdDr3CCO+4HVrBtbzqLTM3P2xAMNCIrPeCTeVfb5sw1y" + validator_mina_to_cosmos: # - mina_key: "3IvK1eWmmcfdlIb+T04+ck9Q5bjbqHqiT0ucGJITzyY=" # cosmos_key: "A8saw69s1DQWvUjseeOtG8hGavmYiInrQ5M1aOPa4QkP" \ No newline at end of file From 9aa9ad33b68bd05b28da51616901c7ab3110e15f Mon Sep 17 00:00:00 2001 From: Yusuf Date: Fri, 24 Apr 2026 22:00:08 +0300 Subject: [PATCH 14/62] refactor: use bytes for signatures instead of string --- proto/pulsarchain/keyregistry/v1/tx.proto | 8 +- .../keeper/msg_server_register_keys.go | 8 +- .../keeper/msg_server_update_keys.go | 8 +- .../keeper/user_register_keys_test.go | 6 +- .../keeper/validator_register_keys_test.go | 2 +- x/keyregistry/types/tx.pb.go | 195 +++++++++--------- 6 files changed, 115 insertions(+), 112 deletions(-) diff --git a/proto/pulsarchain/keyregistry/v1/tx.proto b/proto/pulsarchain/keyregistry/v1/tx.proto index 3b915f5f..3c8a4dae 100644 --- a/proto/pulsarchain/keyregistry/v1/tx.proto +++ b/proto/pulsarchain/keyregistry/v1/tx.proto @@ -51,10 +51,10 @@ message MsgUpdateParamsResponse {} message MsgRegisterKeys { option (cosmos.msg.v1.signer) = "creator"; string creator = 1 [(cosmos_proto.scalar) = "cosmos.AddressString"]; - string cosmos_signature = 2; - string mina_signature = 3; - bytes cosmos_public_key = 4; - bytes mina_public_key = 5; + bytes cosmos_public_key = 2; + bytes mina_public_key = 3; + bytes cosmos_signature = 4; + bytes mina_signature = 5; ActorType actor_type = 6; } diff --git a/x/keyregistry/keeper/msg_server_register_keys.go b/x/keyregistry/keeper/msg_server_register_keys.go index c2eadf55..b60004b9 100644 --- a/x/keyregistry/keeper/msg_server_register_keys.go +++ b/x/keyregistry/keeper/msg_server_register_keys.go @@ -9,22 +9,22 @@ import ( ) // TODO: Implement Mina signature verification for users -func VerifyUserMinaSig(sig string, msg, minaAddress []byte) bool { +func VerifyUserMinaSig(sig []byte, msg, minaAddress []byte) bool { return true } // TODO: Implement Cosmos signature verification for users -func VerifyUserCosmosSig(sig string, msg, cosmosAddress []byte) bool { +func VerifyUserCosmosSig(sig []byte, msg, cosmosAddress []byte) bool { return true } // TODO: Implement Mina signature verification for users -func VerifyValidatorMinaSig(sig string, msg, minaAddress []byte) bool { +func VerifyValidatorMinaSig(sig []byte, msg, minaAddress []byte) bool { return true } // TODO: Implement Cosmos signature verification for users -func VerifyValidatorCosmosSig(sig string, msg, cosmosAddress []byte) bool { +func VerifyValidatorCosmosSig(sig []byte, msg, cosmosAddress []byte) bool { return true } diff --git a/x/keyregistry/keeper/msg_server_update_keys.go b/x/keyregistry/keeper/msg_server_update_keys.go index daaa1072..ee387181 100644 --- a/x/keyregistry/keeper/msg_server_update_keys.go +++ b/x/keyregistry/keeper/msg_server_update_keys.go @@ -85,10 +85,10 @@ func (k msgServer) updateUserKeys(ctx context.Context, msg *types.MsgUpdateKeys) return types.ErrUserSecondaryKeyExists } - if !VerifyUserCosmosSig(string(msg.CosmosSignature), msg.NewMinaPublicKey, cosmosPublicKey) { + if !VerifyUserCosmosSig(msg.CosmosSignature, msg.NewMinaPublicKey, cosmosPublicKey) { return types.ErrInvalidSignature } - if !VerifyUserMinaSig(string(msg.NewMinaSignature), cosmosPublicKey, msg.NewMinaPublicKey) { + if !VerifyUserMinaSig(msg.NewMinaSignature, cosmosPublicKey, msg.NewMinaPublicKey) { return types.ErrInvalidSignature } @@ -146,10 +146,10 @@ func (k msgServer) updateValidatorKeys(ctx context.Context, msg *types.MsgUpdate return types.ErrValidatorSecondaryKeyExists } - if !VerifyValidatorCosmosSig(string(msg.CosmosSignature), msg.NewMinaPublicKey, cosmosPublicKey) { + if !VerifyValidatorCosmosSig(msg.CosmosSignature, msg.NewMinaPublicKey, cosmosPublicKey) { return types.ErrInvalidSignature } - if !VerifyValidatorMinaSig(string(msg.NewMinaSignature), cosmosPublicKey, msg.NewMinaPublicKey) { + if !VerifyValidatorMinaSig(msg.NewMinaSignature, cosmosPublicKey, msg.NewMinaPublicKey) { return types.ErrInvalidSignature } diff --git a/x/keyregistry/keeper/user_register_keys_test.go b/x/keyregistry/keeper/user_register_keys_test.go index baa5a9c2..2592dfcd 100644 --- a/x/keyregistry/keeper/user_register_keys_test.go +++ b/x/keyregistry/keeper/user_register_keys_test.go @@ -16,8 +16,8 @@ import ( // Mock signatures used across msg server tests. // These will be replaced with real signatures once VerifyMinaSig and VerifyCosmosSig are implemented. -var mockCosmosSignature = "cosmosSig" -var mockMinaSignature = "minaSig" +var mockCosmosSignature = []byte("cosmosSig") +var mockMinaSignature = []byte("minaSig") var MinaPriv = []byte("7olA5Knafb5E2hJoWFzD+oamtyXIXXUZmYG9+pBMjTGIjqZTVLNGbE7DQ3Zq5YL5NMW31UMMMGgNCeEk+gyzRA==") @@ -194,7 +194,7 @@ func TestUserInvalidSignature(t *testing.T) { creatorAddr := sdk.AccAddress(cosmosPublicKey.Address()) require.NotNil(t, creatorAddr) - invalidSig := "cosmosSig" + invalidSig := []byte("cosmosSig") _, err = ms.RegisterKeys(f.ctx, &types.MsgRegisterKeys{ Creator: creatorAddr.String(), diff --git a/x/keyregistry/keeper/validator_register_keys_test.go b/x/keyregistry/keeper/validator_register_keys_test.go index d3662acc..568ec3fb 100644 --- a/x/keyregistry/keeper/validator_register_keys_test.go +++ b/x/keyregistry/keeper/validator_register_keys_test.go @@ -111,7 +111,7 @@ func TestValidatorInvalidSignature(t *testing.T) { f := initFixture(t) ms := keeper.NewMsgServerImpl(f.keeper) - invalidSig := "cosmosSig" + invalidSig := []byte("cosmosSig") _, err = ms.RegisterKeys(f.ctx, &types.MsgRegisterKeys{ Creator: creatorAddr.String(), diff --git a/x/keyregistry/types/tx.pb.go b/x/keyregistry/types/tx.pb.go index 51e23a3b..b0b00dec 100644 --- a/x/keyregistry/types/tx.pb.go +++ b/x/keyregistry/types/tx.pb.go @@ -127,10 +127,10 @@ var xxx_messageInfo_MsgUpdateParamsResponse proto.InternalMessageInfo // MsgRegisterKeys defines the MsgRegisterKeys message. type MsgRegisterKeys struct { Creator string `protobuf:"bytes,1,opt,name=creator,proto3" json:"creator,omitempty"` - CosmosSignature string `protobuf:"bytes,2,opt,name=cosmos_signature,json=cosmosSignature,proto3" json:"cosmos_signature,omitempty"` - MinaSignature string `protobuf:"bytes,3,opt,name=mina_signature,json=minaSignature,proto3" json:"mina_signature,omitempty"` - CosmosPublicKey []byte `protobuf:"bytes,4,opt,name=cosmos_public_key,json=cosmosPublicKey,proto3" json:"cosmos_public_key,omitempty"` - MinaPublicKey []byte `protobuf:"bytes,5,opt,name=mina_public_key,json=minaPublicKey,proto3" json:"mina_public_key,omitempty"` + CosmosPublicKey []byte `protobuf:"bytes,2,opt,name=cosmos_public_key,json=cosmosPublicKey,proto3" json:"cosmos_public_key,omitempty"` + MinaPublicKey []byte `protobuf:"bytes,3,opt,name=mina_public_key,json=minaPublicKey,proto3" json:"mina_public_key,omitempty"` + CosmosSignature []byte `protobuf:"bytes,4,opt,name=cosmos_signature,json=cosmosSignature,proto3" json:"cosmos_signature,omitempty"` + MinaSignature []byte `protobuf:"bytes,5,opt,name=mina_signature,json=minaSignature,proto3" json:"mina_signature,omitempty"` ActorType ActorType `protobuf:"varint,6,opt,name=actor_type,json=actorType,proto3,enum=pulsarchain.keyregistry.v1.ActorType" json:"actor_type,omitempty"` } @@ -174,30 +174,30 @@ func (m *MsgRegisterKeys) GetCreator() string { return "" } -func (m *MsgRegisterKeys) GetCosmosSignature() string { +func (m *MsgRegisterKeys) GetCosmosPublicKey() []byte { if m != nil { - return m.CosmosSignature + return m.CosmosPublicKey } - return "" + return nil } -func (m *MsgRegisterKeys) GetMinaSignature() string { +func (m *MsgRegisterKeys) GetMinaPublicKey() []byte { if m != nil { - return m.MinaSignature + return m.MinaPublicKey } - return "" + return nil } -func (m *MsgRegisterKeys) GetCosmosPublicKey() []byte { +func (m *MsgRegisterKeys) GetCosmosSignature() []byte { if m != nil { - return m.CosmosPublicKey + return m.CosmosSignature } return nil } -func (m *MsgRegisterKeys) GetMinaPublicKey() []byte { +func (m *MsgRegisterKeys) GetMinaSignature() []byte { if m != nil { - return m.MinaPublicKey + return m.MinaSignature } return nil } @@ -382,47 +382,46 @@ func init() { } var fileDescriptor_235f5fb22cc1f8d8 = []byte{ - // 634 bytes of a gzipped FileDescriptorProto - 0x1f, 0x8b, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0xff, 0xb4, 0x94, 0x3f, 0x6f, 0xd3, 0x4e, - 0x18, 0xc7, 0xe3, 0xf4, 0xd7, 0xfe, 0x94, 0xa3, 0x7f, 0x4d, 0x51, 0xd2, 0x0c, 0x26, 0x0a, 0x2a, - 0x24, 0x81, 0xd8, 0x4d, 0x2a, 0x75, 0xa8, 0x58, 0x1a, 0xc1, 0x54, 0x45, 0x8a, 0x5c, 0x58, 0x58, - 0xa2, 0x8b, 0x73, 0x72, 0x4c, 0x6a, 0x9f, 0x75, 0x77, 0x4e, 0xeb, 0x0d, 0x31, 0x32, 0xf1, 0x32, - 0x18, 0x33, 0xb0, 0xb3, 0x76, 0x42, 0x11, 0x13, 0x03, 0x42, 0x28, 0x19, 0xf2, 0x36, 0x90, 0xcf, - 0x76, 0x6c, 0x87, 0x90, 0x14, 0x24, 0x16, 0xcb, 0xf7, 0x3c, 0x9f, 0x7b, 0xfe, 0x7c, 0x9f, 0xbb, - 0x03, 0x0f, 0x6c, 0xe7, 0x92, 0x42, 0xa2, 0xf5, 0xa0, 0x61, 0x29, 0x7d, 0xe4, 0x12, 0xa4, 0x1b, - 0x94, 0x11, 0x57, 0x19, 0xd4, 0x14, 0x76, 0x2d, 0xdb, 0x04, 0x33, 0x2c, 0xe6, 0x63, 0x90, 0x1c, - 0x83, 0xe4, 0x41, 0x2d, 0xbf, 0x07, 0x4d, 0xc3, 0xc2, 0x0a, 0xff, 0xfa, 0x78, 0x3e, 0xab, 0x61, - 0x6a, 0x62, 0xaa, 0x98, 0x54, 0xf7, 0xc2, 0x98, 0x54, 0x0f, 0x1c, 0x07, 0xbe, 0xa3, 0xcd, 0x57, - 0x8a, 0xbf, 0x08, 0x5c, 0xfb, 0x3a, 0xd6, 0xb1, 0x6f, 0xf7, 0xfe, 0x02, 0xeb, 0xa3, 0x25, 0xd5, - 0xd9, 0x90, 0x40, 0x33, 0xdc, 0x7e, 0xb4, 0x04, 0xec, 0x23, 0xb7, 0xed, 0xd8, 0x5d, 0xc8, 0x50, - 0x9b, 0xb9, 0x36, 0xf2, 0x77, 0x14, 0x3f, 0x0b, 0x60, 0xa7, 0x49, 0xf5, 0x97, 0xdc, 0xd1, 0xe2, - 0xb1, 0xc4, 0x13, 0x90, 0x81, 0x0e, 0xeb, 0x61, 0x62, 0x30, 0x37, 0x27, 0x14, 0x84, 0x52, 0xa6, - 0x91, 0xfb, 0xf2, 0xb1, 0xba, 0x1f, 0x54, 0x7a, 0xd6, 0xed, 0x12, 0x44, 0xe9, 0x05, 0x23, 0x86, - 0xa5, 0xab, 0x11, 0x2a, 0x3e, 0x07, 0x1b, 0x7e, 0x35, 0xb9, 0x74, 0x41, 0x28, 0xdd, 0xa9, 0x17, - 0xe5, 0xdf, 0x0b, 0x26, 0xfb, 0xb9, 0x1a, 0x99, 0x9b, 0xef, 0xf7, 0x53, 0x1f, 0xa6, 0xc3, 0x8a, - 0xa0, 0x06, 0x9b, 0x4f, 0x9f, 0xbe, 0x9d, 0x0e, 0x2b, 0x51, 0xd8, 0x77, 0xd3, 0x61, 0xa5, 0x1c, - 0xef, 0xeb, 0x3a, 0xd1, 0xd9, 0x5c, 0xf1, 0xc5, 0x03, 0x90, 0x9d, 0x33, 0xa9, 0x88, 0xda, 0xd8, - 0xa2, 0xa8, 0xf8, 0x29, 0xcd, 0x7b, 0x55, 0xf9, 0x56, 0x44, 0xce, 0x91, 0x4b, 0xc5, 0x3a, 0xf8, - 0x5f, 0x23, 0x08, 0x32, 0x4c, 0x56, 0x76, 0x1a, 0x82, 0x62, 0x19, 0xec, 0x06, 0x13, 0xa4, 0x86, - 0x6e, 0x41, 0xe6, 0x10, 0xc4, 0x3b, 0xce, 0xa8, 0x3b, 0xbe, 0xfd, 0x22, 0x34, 0x8b, 0x87, 0x60, - 0xdb, 0x34, 0x2c, 0x18, 0x03, 0xd7, 0x38, 0xb8, 0xe5, 0x59, 0x23, 0xac, 0x02, 0xf6, 0xc2, 0x33, - 0xe1, 0x74, 0x2e, 0x0d, 0xad, 0xdd, 0x47, 0x6e, 0xee, 0xbf, 0x82, 0x50, 0xda, 0x0c, 0x43, 0xb6, - 0xb8, 0xfd, 0x1c, 0xb9, 0xe2, 0x43, 0xb0, 0xc3, 0x43, 0xc6, 0xc8, 0x75, 0x4e, 0xf2, 0x98, 0x11, - 0xf7, 0x0c, 0x00, 0xa8, 0x31, 0x4c, 0xf8, 0xb4, 0x73, 0x1b, 0x05, 0xa1, 0xb4, 0x5d, 0x3f, 0x5c, - 0x36, 0x91, 0x33, 0x8f, 0x7e, 0xe1, 0xda, 0x48, 0xcd, 0xc0, 0xf0, 0xf7, 0x74, 0xd3, 0x1b, 0x46, - 0xd8, 0x79, 0x20, 0x6e, 0x5c, 0xc0, 0x99, 0xb8, 0xa3, 0x34, 0xd8, 0x9a, 0x09, 0xff, 0xd7, 0xd2, - 0x2a, 0x60, 0xdf, 0x26, 0x68, 0xd0, 0x9e, 0xef, 0x30, 0xcd, 0x3b, 0xdc, 0xf3, 0x7c, 0xcd, 0x44, - 0x97, 0x55, 0x70, 0xd7, 0x42, 0x57, 0xbf, 0xf0, 0x6b, 0x9c, 0xdf, 0xb5, 0xd0, 0x55, 0x12, 0x5f, - 0x34, 0xba, 0x84, 0xce, 0xd1, 0x4c, 0x9e, 0x00, 0x71, 0x16, 0x39, 0x82, 0xd7, 0x13, 0x81, 0x23, - 0xfa, 0x5f, 0xa8, 0x9d, 0x05, 0xf7, 0x12, 0x8a, 0x86, 0x5a, 0xd7, 0xbf, 0xa5, 0xc1, 0x5a, 0x93, - 0xea, 0xa2, 0x0d, 0x36, 0x13, 0x17, 0xf7, 0xf1, 0xb2, 0x84, 0x73, 0xb7, 0x22, 0x7f, 0xfc, 0x07, - 0x70, 0x98, 0xd9, 0xcb, 0x98, 0xb8, 0x3e, 0xab, 0x32, 0xc6, 0xe1, 0x95, 0x19, 0x17, 0x9d, 0x2b, - 0xf1, 0x35, 0x00, 0xb1, 0x33, 0x55, 0xbe, 0x55, 0xd1, 0x3c, 0x5b, 0xed, 0xd6, 0x68, 0x98, 0x2b, - 0xbf, 0xfe, 0xc6, 0x7b, 0x88, 0x1a, 0xad, 0x9b, 0xb1, 0x24, 0x8c, 0xc6, 0x92, 0xf0, 0x63, 0x2c, - 0x09, 0xef, 0x27, 0x52, 0x6a, 0x34, 0x91, 0x52, 0x5f, 0x27, 0x52, 0xea, 0xd5, 0x89, 0x6e, 0xb0, - 0x9e, 0xd3, 0x91, 0x35, 0x6c, 0x2a, 0x16, 0xee, 0xa2, 0xda, 0x51, 0xad, 0x6a, 0x60, 0xc5, 0x4f, - 0x54, 0x5d, 0xf4, 0x3c, 0x79, 0xc7, 0x81, 0x76, 0x36, 0xf8, 0x63, 0x7b, 0xfc, 0x33, 0x00, 0x00, - 0xff, 0xff, 0x8a, 0x6c, 0x49, 0x4f, 0x67, 0x06, 0x00, 0x00, + // 620 bytes of a gzipped FileDescriptorProto + 0x1f, 0x8b, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0xff, 0xb4, 0x54, 0x3f, 0x6f, 0xd3, 0x4e, + 0x18, 0x8e, 0xd3, 0x5f, 0xfb, 0x53, 0x8e, 0xfe, 0x35, 0x45, 0x49, 0x33, 0x98, 0x28, 0xa8, 0x90, + 0x04, 0x62, 0x37, 0xa9, 0xd4, 0xa1, 0x62, 0x69, 0x04, 0x53, 0x15, 0x29, 0x72, 0x61, 0x61, 0xb1, + 0x2e, 0xce, 0xc9, 0x31, 0xa9, 0x7d, 0xd6, 0xdd, 0x39, 0xad, 0x37, 0xc4, 0xc8, 0xc4, 0xc7, 0x60, + 0xcc, 0xc0, 0xce, 0xda, 0x09, 0x45, 0x4c, 0x0c, 0x08, 0xa1, 0x64, 0xc8, 0xd7, 0x40, 0x3e, 0xdb, + 0xb1, 0x13, 0x85, 0xa4, 0x54, 0x62, 0xb1, 0x7c, 0xef, 0xfb, 0xdc, 0xf3, 0xbc, 0xef, 0xf3, 0xde, + 0x1d, 0x78, 0xe4, 0xb8, 0x97, 0x14, 0x12, 0xbd, 0x0b, 0x4d, 0x5b, 0xe9, 0x21, 0x8f, 0x20, 0xc3, + 0xa4, 0x8c, 0x78, 0x4a, 0xbf, 0xa6, 0xb0, 0x6b, 0xd9, 0x21, 0x98, 0x61, 0x31, 0x9f, 0x00, 0xc9, + 0x09, 0x90, 0xdc, 0xaf, 0xe5, 0xf7, 0xa0, 0x65, 0xda, 0x58, 0xe1, 0xdf, 0x00, 0x9e, 0xcf, 0xea, + 0x98, 0x5a, 0x98, 0x2a, 0x16, 0x35, 0x7c, 0x1a, 0x8b, 0x1a, 0x61, 0xe2, 0x20, 0x48, 0x68, 0x7c, + 0xa5, 0x04, 0x8b, 0x30, 0xb5, 0x6f, 0x60, 0x03, 0x07, 0x71, 0xff, 0x2f, 0x8c, 0x3e, 0x59, 0x52, + 0x9d, 0x03, 0x09, 0xb4, 0xa2, 0xed, 0x47, 0x4b, 0x80, 0x3d, 0xe4, 0x69, 0xae, 0xd3, 0x81, 0x0c, + 0x69, 0xcc, 0x73, 0x50, 0xb0, 0xa3, 0xf8, 0x55, 0x00, 0x3b, 0x4d, 0x6a, 0xbc, 0xe6, 0x89, 0x16, + 0xe7, 0x12, 0x4f, 0x40, 0x06, 0xba, 0xac, 0x8b, 0x89, 0xc9, 0xbc, 0x9c, 0x50, 0x10, 0x4a, 0x99, + 0x46, 0xee, 0xdb, 0xe7, 0xea, 0x7e, 0x58, 0xe9, 0x59, 0xa7, 0x43, 0x10, 0xa5, 0x17, 0x8c, 0x98, + 0xb6, 0xa1, 0xc6, 0x50, 0xf1, 0x25, 0xd8, 0x08, 0xaa, 0xc9, 0xa5, 0x0b, 0x42, 0xe9, 0x5e, 0xbd, + 0x28, 0xff, 0xd9, 0x30, 0x39, 0xd0, 0x6a, 0x64, 0x6e, 0x7e, 0x3e, 0x4c, 0x7d, 0x9a, 0x0c, 0x2a, + 0x82, 0x1a, 0x6e, 0x3e, 0x7d, 0xfe, 0x7e, 0x32, 0xa8, 0xc4, 0xb4, 0x1f, 0x26, 0x83, 0x4a, 0x39, + 0xd9, 0xd7, 0xf5, 0x4c, 0x67, 0x73, 0xc5, 0x17, 0x0f, 0x40, 0x76, 0x2e, 0xa4, 0x22, 0xea, 0x60, + 0x9b, 0xa2, 0xe2, 0x97, 0x34, 0xef, 0x55, 0xe5, 0x5b, 0x11, 0x39, 0x47, 0x1e, 0x15, 0xeb, 0xe0, + 0x7f, 0x9d, 0x20, 0xc8, 0x30, 0x59, 0xd9, 0x69, 0x04, 0x14, 0x2b, 0x60, 0x2f, 0x9a, 0xa0, 0xdb, + 0xbe, 0x34, 0x75, 0xad, 0x87, 0x3c, 0xde, 0xf2, 0xa6, 0xba, 0x13, 0x24, 0x5a, 0x3c, 0x7e, 0x8e, + 0x3c, 0xf1, 0x31, 0xd8, 0xb1, 0x4c, 0x1b, 0x26, 0x91, 0x6b, 0x1c, 0xb9, 0xe5, 0x87, 0x63, 0x5c, + 0x19, 0xec, 0x86, 0x9c, 0xd4, 0x34, 0x6c, 0xc8, 0x5c, 0x82, 0x72, 0xff, 0x25, 0x29, 0x2f, 0xa2, + 0xb0, 0x78, 0x08, 0xb6, 0x39, 0x65, 0x0c, 0x5c, 0x8f, 0x19, 0x63, 0xd8, 0x0b, 0x00, 0xa0, 0xce, + 0x30, 0xe1, 0xd3, 0xce, 0x6d, 0x14, 0x84, 0xd2, 0x76, 0xfd, 0x70, 0xd9, 0x44, 0xce, 0x7c, 0xf4, + 0x2b, 0xcf, 0x41, 0x6a, 0x06, 0x46, 0xbf, 0xa7, 0x9b, 0xfe, 0x30, 0xa2, 0xce, 0x43, 0x73, 0x93, + 0x06, 0x4e, 0xcd, 0x1d, 0xa6, 0xc1, 0xd6, 0xd4, 0xf8, 0x3b, 0x5b, 0xab, 0x80, 0x7d, 0x87, 0xa0, + 0xbe, 0x36, 0xef, 0x59, 0xe0, 0xee, 0x9e, 0x9f, 0x6b, 0xce, 0xf8, 0x56, 0x05, 0xf7, 0x6d, 0x74, + 0xa5, 0x2d, 0xf6, 0x78, 0xd7, 0x46, 0x57, 0xcd, 0xbb, 0xda, 0xfc, 0x0c, 0x88, 0x53, 0xe6, 0x79, + 0xab, 0x23, 0xe2, 0x7f, 0xeb, 0x76, 0x16, 0x3c, 0x98, 0x71, 0x34, 0xf2, 0xba, 0xfe, 0x23, 0x0d, + 0xd6, 0x9a, 0xd4, 0x10, 0x1d, 0xb0, 0x39, 0x73, 0x71, 0x9f, 0x2e, 0x13, 0x9c, 0xbb, 0x15, 0xf9, + 0xe3, 0xbf, 0x00, 0x47, 0xca, 0xbe, 0xe2, 0xcc, 0xf5, 0x59, 0xa5, 0x98, 0x04, 0xaf, 0x54, 0x5c, + 0x74, 0xae, 0xc4, 0xb7, 0x00, 0x24, 0xce, 0x54, 0xf9, 0x56, 0x45, 0x73, 0xb5, 0xda, 0xad, 0xa1, + 0x91, 0x56, 0x7e, 0xfd, 0x9d, 0xff, 0x10, 0x35, 0x5a, 0x37, 0x23, 0x49, 0x18, 0x8e, 0x24, 0xe1, + 0xd7, 0x48, 0x12, 0x3e, 0x8e, 0xa5, 0xd4, 0x70, 0x2c, 0xa5, 0xbe, 0x8f, 0xa5, 0xd4, 0x9b, 0x13, + 0xc3, 0x64, 0x5d, 0xb7, 0x2d, 0xeb, 0xd8, 0x52, 0x6c, 0xdc, 0x41, 0xb5, 0xa3, 0x5a, 0xd5, 0xc4, + 0x4a, 0x20, 0x54, 0x5d, 0xf4, 0x3c, 0xf9, 0xc7, 0x81, 0xb6, 0x37, 0xf8, 0x63, 0x7b, 0xfc, 0x3b, + 0x00, 0x00, 0xff, 0xff, 0x12, 0x10, 0x94, 0x52, 0x67, 0x06, 0x00, 0x00, } // Reference imports to suppress errors if they are not otherwise used. @@ -674,32 +673,32 @@ func (m *MsgRegisterKeys) MarshalToSizedBuffer(dAtA []byte) (int, error) { i-- dAtA[i] = 0x30 } - if len(m.MinaPublicKey) > 0 { - i -= len(m.MinaPublicKey) - copy(dAtA[i:], m.MinaPublicKey) - i = encodeVarintTx(dAtA, i, uint64(len(m.MinaPublicKey))) - i-- - dAtA[i] = 0x2a - } - if len(m.CosmosPublicKey) > 0 { - i -= len(m.CosmosPublicKey) - copy(dAtA[i:], m.CosmosPublicKey) - i = encodeVarintTx(dAtA, i, uint64(len(m.CosmosPublicKey))) - i-- - dAtA[i] = 0x22 - } if len(m.MinaSignature) > 0 { i -= len(m.MinaSignature) copy(dAtA[i:], m.MinaSignature) i = encodeVarintTx(dAtA, i, uint64(len(m.MinaSignature))) i-- - dAtA[i] = 0x1a + dAtA[i] = 0x2a } if len(m.CosmosSignature) > 0 { i -= len(m.CosmosSignature) copy(dAtA[i:], m.CosmosSignature) i = encodeVarintTx(dAtA, i, uint64(len(m.CosmosSignature))) i-- + dAtA[i] = 0x22 + } + if len(m.MinaPublicKey) > 0 { + i -= len(m.MinaPublicKey) + copy(dAtA[i:], m.MinaPublicKey) + i = encodeVarintTx(dAtA, i, uint64(len(m.MinaPublicKey))) + i-- + dAtA[i] = 0x1a + } + if len(m.CosmosPublicKey) > 0 { + i -= len(m.CosmosPublicKey) + copy(dAtA[i:], m.CosmosPublicKey) + i = encodeVarintTx(dAtA, i, uint64(len(m.CosmosPublicKey))) + i-- dAtA[i] = 0x12 } if len(m.Creator) > 0 { @@ -866,19 +865,19 @@ func (m *MsgRegisterKeys) Size() (n int) { if l > 0 { n += 1 + l + sovTx(uint64(l)) } - l = len(m.CosmosSignature) + l = len(m.CosmosPublicKey) if l > 0 { n += 1 + l + sovTx(uint64(l)) } - l = len(m.MinaSignature) + l = len(m.MinaPublicKey) if l > 0 { n += 1 + l + sovTx(uint64(l)) } - l = len(m.CosmosPublicKey) + l = len(m.CosmosSignature) if l > 0 { n += 1 + l + sovTx(uint64(l)) } - l = len(m.MinaPublicKey) + l = len(m.MinaSignature) if l > 0 { n += 1 + l + sovTx(uint64(l)) } @@ -1172,9 +1171,9 @@ func (m *MsgRegisterKeys) Unmarshal(dAtA []byte) error { iNdEx = postIndex case 2: if wireType != 2 { - return fmt.Errorf("proto: wrong wireType = %d for field CosmosSignature", wireType) + return fmt.Errorf("proto: wrong wireType = %d for field CosmosPublicKey", wireType) } - var stringLen uint64 + var byteLen int for shift := uint(0); ; shift += 7 { if shift >= 64 { return ErrIntOverflowTx @@ -1184,29 +1183,31 @@ func (m *MsgRegisterKeys) Unmarshal(dAtA []byte) error { } b := dAtA[iNdEx] iNdEx++ - stringLen |= uint64(b&0x7F) << shift + byteLen |= int(b&0x7F) << shift if b < 0x80 { break } } - intStringLen := int(stringLen) - if intStringLen < 0 { + if byteLen < 0 { return ErrInvalidLengthTx } - postIndex := iNdEx + intStringLen + postIndex := iNdEx + byteLen if postIndex < 0 { return ErrInvalidLengthTx } if postIndex > l { return io.ErrUnexpectedEOF } - m.CosmosSignature = string(dAtA[iNdEx:postIndex]) + m.CosmosPublicKey = append(m.CosmosPublicKey[:0], dAtA[iNdEx:postIndex]...) + if m.CosmosPublicKey == nil { + m.CosmosPublicKey = []byte{} + } iNdEx = postIndex case 3: if wireType != 2 { - return fmt.Errorf("proto: wrong wireType = %d for field MinaSignature", wireType) + return fmt.Errorf("proto: wrong wireType = %d for field MinaPublicKey", wireType) } - var stringLen uint64 + var byteLen int for shift := uint(0); ; shift += 7 { if shift >= 64 { return ErrIntOverflowTx @@ -1216,27 +1217,29 @@ func (m *MsgRegisterKeys) Unmarshal(dAtA []byte) error { } b := dAtA[iNdEx] iNdEx++ - stringLen |= uint64(b&0x7F) << shift + byteLen |= int(b&0x7F) << shift if b < 0x80 { break } } - intStringLen := int(stringLen) - if intStringLen < 0 { + if byteLen < 0 { return ErrInvalidLengthTx } - postIndex := iNdEx + intStringLen + postIndex := iNdEx + byteLen if postIndex < 0 { return ErrInvalidLengthTx } if postIndex > l { return io.ErrUnexpectedEOF } - m.MinaSignature = string(dAtA[iNdEx:postIndex]) + m.MinaPublicKey = append(m.MinaPublicKey[:0], dAtA[iNdEx:postIndex]...) + if m.MinaPublicKey == nil { + m.MinaPublicKey = []byte{} + } iNdEx = postIndex case 4: if wireType != 2 { - return fmt.Errorf("proto: wrong wireType = %d for field CosmosPublicKey", wireType) + return fmt.Errorf("proto: wrong wireType = %d for field CosmosSignature", wireType) } var byteLen int for shift := uint(0); ; shift += 7 { @@ -1263,14 +1266,14 @@ func (m *MsgRegisterKeys) Unmarshal(dAtA []byte) error { if postIndex > l { return io.ErrUnexpectedEOF } - m.CosmosPublicKey = append(m.CosmosPublicKey[:0], dAtA[iNdEx:postIndex]...) - if m.CosmosPublicKey == nil { - m.CosmosPublicKey = []byte{} + m.CosmosSignature = append(m.CosmosSignature[:0], dAtA[iNdEx:postIndex]...) + if m.CosmosSignature == nil { + m.CosmosSignature = []byte{} } iNdEx = postIndex case 5: if wireType != 2 { - return fmt.Errorf("proto: wrong wireType = %d for field MinaPublicKey", wireType) + return fmt.Errorf("proto: wrong wireType = %d for field MinaSignature", wireType) } var byteLen int for shift := uint(0); ; shift += 7 { @@ -1297,9 +1300,9 @@ func (m *MsgRegisterKeys) Unmarshal(dAtA []byte) error { if postIndex > l { return io.ErrUnexpectedEOF } - m.MinaPublicKey = append(m.MinaPublicKey[:0], dAtA[iNdEx:postIndex]...) - if m.MinaPublicKey == nil { - m.MinaPublicKey = []byte{} + m.MinaSignature = append(m.MinaSignature[:0], dAtA[iNdEx:postIndex]...) + if m.MinaSignature == nil { + m.MinaSignature = []byte{} } iNdEx = postIndex case 6: From f9532fb4351be4db9bb760b7ea0c6f48fdb09c5a Mon Sep 17 00:00:00 2001 From: Yusuf Date: Fri, 24 Apr 2026 22:12:38 +0300 Subject: [PATCH 15/62] chore: remove public validate functions for user/validator keypair structs --- .../keeper/msg_server_register_user_keys.go | 4 ++-- .../keeper/msg_server_register_validator_keys.go | 6 +++--- x/keyregistry/types/genesis.go | 12 ++++++++---- x/keyregistry/types/user_public_key_pairs.go | 10 +++------- x/keyregistry/types/validator_public_key_pairs.go | 10 +++------- 5 files changed, 19 insertions(+), 23 deletions(-) diff --git a/x/keyregistry/keeper/msg_server_register_user_keys.go b/x/keyregistry/keeper/msg_server_register_user_keys.go index 2a2d5022..9156a31e 100644 --- a/x/keyregistry/keeper/msg_server_register_user_keys.go +++ b/x/keyregistry/keeper/msg_server_register_user_keys.go @@ -13,10 +13,10 @@ func (k msgServer) handleUserRegistration(ctx context.Context, msg *types.MsgReg return errorsmod.Wrap(types.ErrInvalidCreatorAddres, "") } - err = types.ValidateUserPublicKeyPair(types.UserPublicKeyPair{ + err = types.UserPublicKeyPair{ MinaKey: msg.MinaPublicKey, CosmosKey: msg.CosmosPublicKey, - }) + }.Validate() if err != nil { return errorsmod.Wrap(types.ErrInvalidPublicKey, "") } diff --git a/x/keyregistry/keeper/msg_server_register_validator_keys.go b/x/keyregistry/keeper/msg_server_register_validator_keys.go index 4fedf5f0..d7bc5022 100644 --- a/x/keyregistry/keeper/msg_server_register_validator_keys.go +++ b/x/keyregistry/keeper/msg_server_register_validator_keys.go @@ -13,13 +13,13 @@ import ( func (k msgServer) handleValidatorRegistration(ctx context.Context, msg *types.MsgRegisterKeys) error { _, err := sdk.AccAddressFromBech32(msg.Creator) if err != nil { - return errorsmod.Wrap(types.ErrInvalidCreatorAddres, "") + return errorsmod.Wrap(types.ErrInvalidCreatorAddress, "") } - err = types.ValidateValidatorPublicKeyPair(types.ValidatorPublicKeyPair{ + err = types.ValidatorPublicKeyPair{ MinaKey: msg.MinaPublicKey, CosmosKey: msg.CosmosPublicKey, - }) + }.Validate() if err != nil { return errorsmod.Wrap(types.ErrInvalidPublicKey, "pubkeys must be valid") } diff --git a/x/keyregistry/types/genesis.go b/x/keyregistry/types/genesis.go index f9e17cd2..1d99120e 100644 --- a/x/keyregistry/types/genesis.go +++ b/x/keyregistry/types/genesis.go @@ -19,7 +19,8 @@ func (gs GenesisState) Validate() error { if keyPair == nil { return ErrNilKeyPair } - err := ValidateUserPublicKeyPair(*keyPair) + kp := *keyPair + err := kp.Validate() if err != nil { return err } @@ -29,7 +30,8 @@ func (gs GenesisState) Validate() error { if keyPair == nil { return ErrNilKeyPair } - err := ValidateUserPublicKeyPair(*keyPair) + kp := *keyPair + err := kp.Validate() if err != nil { return err } @@ -39,7 +41,8 @@ func (gs GenesisState) Validate() error { if keyPair == nil { return ErrNilKeyPair } - err := ValidateValidatorPublicKeyPair(*keyPair) + kp := *keyPair + err := kp.Validate() if err != nil { return err } @@ -48,7 +51,8 @@ func (gs GenesisState) Validate() error { if keyPair == nil { return ErrNilKeyPair } - err := ValidateValidatorPublicKeyPair(*keyPair) + kp := *keyPair + err := kp.Validate() if err != nil { return err } diff --git a/x/keyregistry/types/user_public_key_pairs.go b/x/keyregistry/types/user_public_key_pairs.go index 1f8f7b0e..25ffea70 100644 --- a/x/keyregistry/types/user_public_key_pairs.go +++ b/x/keyregistry/types/user_public_key_pairs.go @@ -14,8 +14,9 @@ func DefaultUserPublicKeyPair() []*UserPublicKeyPair { return NewUserPublicKeyPairs() } -func ValidateUserPublicKeyPair(k UserPublicKeyPair) error { - +// Validate validates the set of params. +// TODO: make strict validate once mina-signer-go is complete +func (k UserPublicKeyPair) Validate() error { if len(k.CosmosKey) != secp256k1.PubKeySize { return errors.Wrap(ErrInvalidPublicKey, "cosmos public key must be secp256k1 (33 bytes)") } @@ -25,8 +26,3 @@ func ValidateUserPublicKeyPair(k UserPublicKeyPair) error { } return nil } - -// Validate validates the set of params. -func (k UserPublicKeyPair) Validate() error { - return ValidateUserPublicKeyPair(k) -} diff --git a/x/keyregistry/types/validator_public_key_pairs.go b/x/keyregistry/types/validator_public_key_pairs.go index 63acf070..b4c8b768 100644 --- a/x/keyregistry/types/validator_public_key_pairs.go +++ b/x/keyregistry/types/validator_public_key_pairs.go @@ -15,8 +15,9 @@ func DefaultValidatorPublicKeyPair() []*ValidatorPublicKeyPair { return NewValidatorPublicKeyPairs() } -func ValidateValidatorPublicKeyPair(k ValidatorPublicKeyPair) error { - +// Validate validates the set of params. +// TODO: make strict validate once mina-signer-go is complete +func (k ValidatorPublicKeyPair) Validate() error { if len(k.CosmosKey) != ed25519.PublicKeySize { return errors.Wrap(ErrInvalidPublicKey, "cosmos public key must be ed25519 (32 bytes)") } @@ -26,8 +27,3 @@ func ValidateValidatorPublicKeyPair(k ValidatorPublicKeyPair) error { } return nil } - -// Validate validates the set of params. -func (k ValidatorPublicKeyPair) Validate() error { - return ValidateValidatorPublicKeyPair(k) -} From 31acc253b51b7d9c3f0fabaacf8770aeb0bbb145 Mon Sep 17 00:00:00 2001 From: Yusuf Date: Fri, 24 Apr 2026 22:13:41 +0300 Subject: [PATCH 16/62] chore: fix typo --- x/keyregistry/keeper/msg_server_register_user_keys.go | 2 +- x/keyregistry/keeper/msg_server_update_keys.go | 4 ++-- x/keyregistry/keeper/msg_update_params.go | 2 +- x/keyregistry/keeper/msg_update_params_test.go | 2 +- x/keyregistry/keeper/user_register_keys_test.go | 2 +- x/keyregistry/keeper/user_update_keys_test.go | 2 +- x/keyregistry/keeper/validator_register_keys_test.go | 2 +- x/keyregistry/keeper/validator_update_keys_test.go | 2 +- x/keyregistry/types/errors.go | 2 +- 9 files changed, 10 insertions(+), 10 deletions(-) diff --git a/x/keyregistry/keeper/msg_server_register_user_keys.go b/x/keyregistry/keeper/msg_server_register_user_keys.go index 9156a31e..24b9c8af 100644 --- a/x/keyregistry/keeper/msg_server_register_user_keys.go +++ b/x/keyregistry/keeper/msg_server_register_user_keys.go @@ -10,7 +10,7 @@ import ( func (k msgServer) handleUserRegistration(ctx context.Context, msg *types.MsgRegisterKeys) error { _, err := k.addressCodec.StringToBytes(msg.Creator) if err != nil { - return errorsmod.Wrap(types.ErrInvalidCreatorAddres, "") + return errorsmod.Wrap(types.ErrInvalidCreatorAddress, "") } err = types.UserPublicKeyPair{ diff --git a/x/keyregistry/keeper/msg_server_update_keys.go b/x/keyregistry/keeper/msg_server_update_keys.go index ee387181..2b234ccd 100644 --- a/x/keyregistry/keeper/msg_server_update_keys.go +++ b/x/keyregistry/keeper/msg_server_update_keys.go @@ -36,7 +36,7 @@ func (k msgServer) UpdateKeys(ctx context.Context, msg *types.MsgUpdateKeys) (*t func (k msgServer) updateUserKeys(ctx context.Context, msg *types.MsgUpdateKeys) error { _, err := k.addressCodec.StringToBytes(msg.Creator) if err != nil { - return errorsmod.Wrap(types.ErrInvalidCreatorAddres, "") + return errorsmod.Wrap(types.ErrInvalidCreatorAddress, "") } exists, err := k.UserMinaToCosmosHas(ctx, msg.PrevMinaPublicKey) @@ -106,7 +106,7 @@ func (k msgServer) updateUserKeys(ctx context.Context, msg *types.MsgUpdateKeys) func (k msgServer) updateValidatorKeys(ctx context.Context, msg *types.MsgUpdateKeys) error { if _, err := sdk.AccAddressFromBech32(msg.Creator); err != nil { - return errorsmod.Wrap(types.ErrInvalidCreatorAddres, "") + return errorsmod.Wrap(types.ErrInvalidCreatorAddress, "") } exists, err := k.ValidatorMinaToCosmosHas(ctx, msg.PrevMinaPublicKey) diff --git a/x/keyregistry/keeper/msg_update_params.go b/x/keyregistry/keeper/msg_update_params.go index adb9be7d..0cbae4e7 100644 --- a/x/keyregistry/keeper/msg_update_params.go +++ b/x/keyregistry/keeper/msg_update_params.go @@ -12,7 +12,7 @@ import ( func (k msgServer) UpdateParams(ctx context.Context, req *types.MsgUpdateParams) (*types.MsgUpdateParamsResponse, error) { authority, err := k.addressCodec.StringToBytes(req.Authority) if err != nil { - return nil, errorsmod.Wrap(types.ErrInvalidCreatorAddres, "") + return nil, errorsmod.Wrap(types.ErrInvalidCreatorAddress, "") } if !bytes.Equal(k.GetAuthority(), authority) { diff --git a/x/keyregistry/keeper/msg_update_params_test.go b/x/keyregistry/keeper/msg_update_params_test.go index 6f90037c..a2f9145d 100644 --- a/x/keyregistry/keeper/msg_update_params_test.go +++ b/x/keyregistry/keeper/msg_update_params_test.go @@ -33,7 +33,7 @@ func TestMsgUpdateParams(t *testing.T) { Params: params, }, expErr: true, - expErrMsg: types.ErrInvalidCreatorAddres.Error(), + expErrMsg: types.ErrInvalidCreatorAddress.Error(), }, { name: "send enabled param", diff --git a/x/keyregistry/keeper/user_register_keys_test.go b/x/keyregistry/keeper/user_register_keys_test.go index 2592dfcd..e3ac1108 100644 --- a/x/keyregistry/keeper/user_register_keys_test.go +++ b/x/keyregistry/keeper/user_register_keys_test.go @@ -143,7 +143,7 @@ func TestUserInvalidCreatorAddress(t *testing.T) { MinaPublicKey: minaPubKey, ActorType: types.ActorType_USER, }) - require.ErrorIs(t, err, types.ErrInvalidCreatorAddres) + require.ErrorIs(t, err, types.ErrInvalidCreatorAddress) } // TestUserInvalidSigner verifies that RegisterKeys fails with ErrInvalidSigner diff --git a/x/keyregistry/keeper/user_update_keys_test.go b/x/keyregistry/keeper/user_update_keys_test.go index d25afb61..1791733a 100644 --- a/x/keyregistry/keeper/user_update_keys_test.go +++ b/x/keyregistry/keeper/user_update_keys_test.go @@ -115,7 +115,7 @@ func TestUserUpdateKeysInvalidCreatorAddress(t *testing.T) { ActorType: types.ActorType_USER, }) - require.ErrorIs(t, err, types.ErrInvalidCreatorAddres) + require.ErrorIs(t, err, types.ErrInvalidCreatorAddress) } func TestUserUpdateKeysInvalidSigner(t *testing.T) { diff --git a/x/keyregistry/keeper/validator_register_keys_test.go b/x/keyregistry/keeper/validator_register_keys_test.go index 568ec3fb..1b6fd9d4 100644 --- a/x/keyregistry/keeper/validator_register_keys_test.go +++ b/x/keyregistry/keeper/validator_register_keys_test.go @@ -92,7 +92,7 @@ func TestValidatorInvalidCreatorAddress(t *testing.T) { ActorType: types.ActorType_VALIDATOR, }) - require.ErrorIs(t, err, types.ErrInvalidCreatorAddres) + require.ErrorIs(t, err, types.ErrInvalidCreatorAddress) } // TODO: Update require.NoError to require.ErrorIs once the VerifyCosmosSig and VerifyMinaSig is implemented diff --git a/x/keyregistry/keeper/validator_update_keys_test.go b/x/keyregistry/keeper/validator_update_keys_test.go index 762d2a28..b5bab038 100644 --- a/x/keyregistry/keeper/validator_update_keys_test.go +++ b/x/keyregistry/keeper/validator_update_keys_test.go @@ -143,7 +143,7 @@ func TestValidatorUpdateKeysInvalidCreatorAddress(t *testing.T) { NewMinaSignature: []byte(mockMinaSignature), ActorType: types.ActorType_VALIDATOR, }) - require.ErrorIs(t, err, types.ErrInvalidCreatorAddres) + require.ErrorIs(t, err, types.ErrInvalidCreatorAddress) } func TestValidatorUpdateKeysInvalidSignature(t *testing.T) { diff --git a/x/keyregistry/types/errors.go b/x/keyregistry/types/errors.go index 00b27d62..c9b1bcb4 100644 --- a/x/keyregistry/types/errors.go +++ b/x/keyregistry/types/errors.go @@ -12,7 +12,7 @@ var ( ErrInvalidSignature = errors.Register(ModuleName, 1101, "invalid signature") ErrUserSecondaryKeyExists = errors.Register(ModuleName, 1102, "user's secondary key already exists") ErrValidatorSecondaryKeyExists = errors.Register(ModuleName, 1103, "validator's secondary key already exists") - ErrInvalidCreatorAddres = errors.Register(ModuleName, 1104, "invalid creator address") + ErrInvalidCreatorAddress = errors.Register(ModuleName, 1104, "invalid creator address") ErrInvalidPublicKey = errors.Register(ModuleName, 1105, "invalid public key") ErrUserNotRegistered = errors.Register(ModuleName, 1106, "user has not been registered") ErrValidatorNotRegistered = errors.Register(ModuleName, 1107, "validator has not been registered") From da63547a86a977e69abd4ecb7950177468564434 Mon Sep 17 00:00:00 2001 From: Yusuf Date: Fri, 24 Apr 2026 22:18:06 +0300 Subject: [PATCH 17/62] chore: use ErrInvalidCreatorAddress instead of ErrInvalidSigner --- x/keyregistry/keeper/msg_server_register_user_keys.go | 2 +- x/keyregistry/keeper/msg_server_update_keys.go | 2 +- x/keyregistry/keeper/user_register_keys_test.go | 2 +- x/keyregistry/keeper/user_update_keys_test.go | 2 +- 4 files changed, 4 insertions(+), 4 deletions(-) diff --git a/x/keyregistry/keeper/msg_server_register_user_keys.go b/x/keyregistry/keeper/msg_server_register_user_keys.go index 24b9c8af..49a272b5 100644 --- a/x/keyregistry/keeper/msg_server_register_user_keys.go +++ b/x/keyregistry/keeper/msg_server_register_user_keys.go @@ -27,7 +27,7 @@ func (k msgServer) handleUserRegistration(ctx context.Context, msg *types.MsgReg } if msg.Creator != cosmosAddr { - return errorsmod.Wrap(types.ErrInvalidSigner, "") + return errorsmod.Wrap(types.ErrInvalidCreatorAddress, "") } return k.persistUserRegistration(ctx, msg) diff --git a/x/keyregistry/keeper/msg_server_update_keys.go b/x/keyregistry/keeper/msg_server_update_keys.go index 2b234ccd..da09247a 100644 --- a/x/keyregistry/keeper/msg_server_update_keys.go +++ b/x/keyregistry/keeper/msg_server_update_keys.go @@ -58,7 +58,7 @@ func (k msgServer) updateUserKeys(ctx context.Context, msg *types.MsgUpdateKeys) } if msg.Creator != cosmosAddr { - return errorsmod.Wrap(types.ErrInvalidSigner, "") + return errorsmod.Wrap(types.ErrInvalidCreatorAddress, "") } exists, err = k.UserCosmosToMinaHas(ctx, cosmosPublicKey) diff --git a/x/keyregistry/keeper/user_register_keys_test.go b/x/keyregistry/keeper/user_register_keys_test.go index e3ac1108..9c2dfe3d 100644 --- a/x/keyregistry/keeper/user_register_keys_test.go +++ b/x/keyregistry/keeper/user_register_keys_test.go @@ -174,7 +174,7 @@ func TestUserInvalidSigner(t *testing.T) { ActorType: types.ActorType_USER, }) - require.ErrorIs(t, err, types.ErrInvalidSigner) + require.ErrorIs(t, err, types.ErrInvalidCreatorAddress) } diff --git a/x/keyregistry/keeper/user_update_keys_test.go b/x/keyregistry/keeper/user_update_keys_test.go index 1791733a..fd75181f 100644 --- a/x/keyregistry/keeper/user_update_keys_test.go +++ b/x/keyregistry/keeper/user_update_keys_test.go @@ -140,7 +140,7 @@ func TestUserUpdateKeysInvalidSigner(t *testing.T) { NewMinaSignature: []byte(mockMinaSignature), ActorType: types.ActorType_USER, }) - require.ErrorIs(t, err, types.ErrInvalidSigner) + require.ErrorIs(t, err, types.ErrInvalidCreatorAddress) } func TestUserUpdateKeysInvalidSignature(t *testing.T) { From d801054fe6d828493c1e2944ef5cfa0622beacb7 Mon Sep 17 00:00:00 2001 From: Yusuf Date: Fri, 24 Apr 2026 22:34:11 +0300 Subject: [PATCH 18/62] chore: improved error messages and more consistent dependency use --- .../keeper/msg_server_register_user_keys.go | 12 ++++++------ .../keeper/msg_server_register_validator_keys.go | 10 +++++----- x/keyregistry/keeper/msg_server_update_keys.go | 9 ++++----- x/keyregistry/keeper/msg_update_params.go | 6 +++--- 4 files changed, 18 insertions(+), 19 deletions(-) diff --git a/x/keyregistry/keeper/msg_server_register_user_keys.go b/x/keyregistry/keeper/msg_server_register_user_keys.go index 49a272b5..aec9b37a 100644 --- a/x/keyregistry/keeper/msg_server_register_user_keys.go +++ b/x/keyregistry/keeper/msg_server_register_user_keys.go @@ -3,14 +3,14 @@ package keeper import ( "context" - errorsmod "cosmossdk.io/errors" + "cosmossdk.io/errors" "github.com/node101-io/pulsar-chain/x/keyregistry/types" ) func (k msgServer) handleUserRegistration(ctx context.Context, msg *types.MsgRegisterKeys) error { _, err := k.addressCodec.StringToBytes(msg.Creator) if err != nil { - return errorsmod.Wrap(types.ErrInvalidCreatorAddress, "") + return errors.Wrap(types.ErrInvalidCreatorAddress, "creator address must be a valid bech32 address") } err = types.UserPublicKeyPair{ @@ -18,7 +18,7 @@ func (k msgServer) handleUserRegistration(ctx context.Context, msg *types.MsgReg CosmosKey: msg.CosmosPublicKey, }.Validate() if err != nil { - return errorsmod.Wrap(types.ErrInvalidPublicKey, "") + return err } cosmosAddr, err := deriveAddressFromPubkey(msg.ActorType, msg.CosmosPublicKey) @@ -27,7 +27,7 @@ func (k msgServer) handleUserRegistration(ctx context.Context, msg *types.MsgReg } if msg.Creator != cosmosAddr { - return errorsmod.Wrap(types.ErrInvalidCreatorAddress, "") + return errors.Wrap(types.ErrInvalidCreatorAddress, "creator address does not match the provided cosmos public key") } return k.persistUserRegistration(ctx, msg) @@ -43,13 +43,13 @@ func (k msgServer) persistUserRegistration(ctx context.Context, msg *types.MsgRe return err } if cosmosKeyExists || minaKeyExists { - return errorsmod.Wrap(types.ErrUserSecondaryKeyExists, "") + return errors.Wrap(types.ErrUserSecondaryKeyExists, "provided cosmos or mina public key is already registered") } minaSigValidity := VerifyUserMinaSig(msg.MinaSignature, msg.CosmosPublicKey, msg.MinaPublicKey) cosmosSigValidity := VerifyUserCosmosSig(msg.CosmosSignature, msg.MinaPublicKey, msg.CosmosPublicKey) if !minaSigValidity || !cosmosSigValidity { - return errorsmod.Wrap(types.ErrInvalidSignature, "invalid cosmos or mina signature") + return errors.Wrap(types.ErrInvalidSignature, "invalid cosmos or mina signature") } err = k.Keeper.userCosmosToMina.Set(ctx, msg.CosmosPublicKey, msg.MinaPublicKey) diff --git a/x/keyregistry/keeper/msg_server_register_validator_keys.go b/x/keyregistry/keeper/msg_server_register_validator_keys.go index d7bc5022..c6789a08 100644 --- a/x/keyregistry/keeper/msg_server_register_validator_keys.go +++ b/x/keyregistry/keeper/msg_server_register_validator_keys.go @@ -3,7 +3,7 @@ package keeper import ( "context" - errorsmod "cosmossdk.io/errors" + "cosmossdk.io/errors" sdk "github.com/cosmos/cosmos-sdk/types" "github.com/node101-io/pulsar-chain/x/keyregistry/types" ) @@ -13,7 +13,7 @@ import ( func (k msgServer) handleValidatorRegistration(ctx context.Context, msg *types.MsgRegisterKeys) error { _, err := sdk.AccAddressFromBech32(msg.Creator) if err != nil { - return errorsmod.Wrap(types.ErrInvalidCreatorAddress, "") + return errors.Wrap(types.ErrInvalidCreatorAddress, "creator address must be a valid bech32 address") } err = types.ValidatorPublicKeyPair{ @@ -21,7 +21,7 @@ func (k msgServer) handleValidatorRegistration(ctx context.Context, msg *types.M CosmosKey: msg.CosmosPublicKey, }.Validate() if err != nil { - return errorsmod.Wrap(types.ErrInvalidPublicKey, "pubkeys must be valid") + return err } return k.persistValidatorRegistration(ctx, msg) @@ -37,13 +37,13 @@ func (k msgServer) persistValidatorRegistration(ctx context.Context, msg *types. return err } if cosmosKeyExists || minaKeyExists { - return errorsmod.Wrap(types.ErrValidatorSecondaryKeyExists, "") + return errors.Wrap(types.ErrValidatorSecondaryKeyExists, "provided cosmos or mina public key is already registered") } minaSigValidity := VerifyValidatorMinaSig(msg.MinaSignature, msg.CosmosPublicKey, msg.MinaPublicKey) cosmosSigValidity := VerifyValidatorCosmosSig(msg.CosmosSignature, msg.MinaPublicKey, msg.CosmosPublicKey) if !minaSigValidity || !cosmosSigValidity { - return errorsmod.Wrap(types.ErrInvalidSignature, "invalid cosmos or mina signature") + return errors.Wrap(types.ErrInvalidSignature, "invalid cosmos or mina signature") } err = k.Keeper.validatorCosmosToMina.Set(ctx, msg.CosmosPublicKey, msg.MinaPublicKey) diff --git a/x/keyregistry/keeper/msg_server_update_keys.go b/x/keyregistry/keeper/msg_server_update_keys.go index da09247a..163cf0a0 100644 --- a/x/keyregistry/keeper/msg_server_update_keys.go +++ b/x/keyregistry/keeper/msg_server_update_keys.go @@ -5,7 +5,6 @@ import ( "context" "cosmossdk.io/errors" - errorsmod "cosmossdk.io/errors" sdk "github.com/cosmos/cosmos-sdk/types" "github.com/node101-io/mina-signer-go/keys" "github.com/node101-io/pulsar-chain/x/keyregistry/types" @@ -15,7 +14,7 @@ func (k msgServer) UpdateKeys(ctx context.Context, msg *types.MsgUpdateKeys) (*t var err error if len(msg.NewMinaPublicKey) != keys.PublicKeyTotalByteSize { - return nil, errors.Wrap(types.ErrInvalidPublicKey, "") + return nil, errors.Wrap(types.ErrInvalidPublicKey, "new mina public key must be compressed (33 bytes)") } switch msg.ActorType { @@ -36,7 +35,7 @@ func (k msgServer) UpdateKeys(ctx context.Context, msg *types.MsgUpdateKeys) (*t func (k msgServer) updateUserKeys(ctx context.Context, msg *types.MsgUpdateKeys) error { _, err := k.addressCodec.StringToBytes(msg.Creator) if err != nil { - return errorsmod.Wrap(types.ErrInvalidCreatorAddress, "") + return errors.Wrap(types.ErrInvalidCreatorAddress, "creator address must be a valid bech32 address") } exists, err := k.UserMinaToCosmosHas(ctx, msg.PrevMinaPublicKey) @@ -58,7 +57,7 @@ func (k msgServer) updateUserKeys(ctx context.Context, msg *types.MsgUpdateKeys) } if msg.Creator != cosmosAddr { - return errorsmod.Wrap(types.ErrInvalidCreatorAddress, "") + return errors.Wrap(types.ErrInvalidCreatorAddress, "creator address does not match the registered cosmos public key") } exists, err = k.UserCosmosToMinaHas(ctx, cosmosPublicKey) @@ -106,7 +105,7 @@ func (k msgServer) updateUserKeys(ctx context.Context, msg *types.MsgUpdateKeys) func (k msgServer) updateValidatorKeys(ctx context.Context, msg *types.MsgUpdateKeys) error { if _, err := sdk.AccAddressFromBech32(msg.Creator); err != nil { - return errorsmod.Wrap(types.ErrInvalidCreatorAddress, "") + return errors.Wrap(types.ErrInvalidCreatorAddress, "creator address must be a valid bech32 address") } exists, err := k.ValidatorMinaToCosmosHas(ctx, msg.PrevMinaPublicKey) diff --git a/x/keyregistry/keeper/msg_update_params.go b/x/keyregistry/keeper/msg_update_params.go index 0cbae4e7..38a9e3a1 100644 --- a/x/keyregistry/keeper/msg_update_params.go +++ b/x/keyregistry/keeper/msg_update_params.go @@ -4,7 +4,7 @@ import ( "bytes" "context" - errorsmod "cosmossdk.io/errors" + "cosmossdk.io/errors" "github.com/node101-io/pulsar-chain/x/keyregistry/types" ) @@ -12,12 +12,12 @@ import ( func (k msgServer) UpdateParams(ctx context.Context, req *types.MsgUpdateParams) (*types.MsgUpdateParamsResponse, error) { authority, err := k.addressCodec.StringToBytes(req.Authority) if err != nil { - return nil, errorsmod.Wrap(types.ErrInvalidCreatorAddress, "") + return nil, errors.Wrap(types.ErrInvalidSigner, "authority address must be a valid bech32 address") } if !bytes.Equal(k.GetAuthority(), authority) { expectedAuthorityStr, _ := k.addressCodec.BytesToString(k.GetAuthority()) - return nil, errorsmod.Wrapf(types.ErrInvalidSigner, "invalid authority; expected %s, got %s", expectedAuthorityStr, req.Authority) + return nil, errors.Wrapf(types.ErrInvalidSigner, "invalid authority; expected %s, got %s", expectedAuthorityStr, req.Authority) } if err := req.Params.Validate(); err != nil { From e009fed31f4d6c73429777832bcbc0a1f72eac11 Mon Sep 17 00:00:00 2001 From: Yusuf Date: Fri, 24 Apr 2026 22:57:28 +0300 Subject: [PATCH 19/62] refactor: remove public map set functions and use registerkeys msg instead --- x/keyregistry/keeper/keeper.go | 16 ----- x/keyregistry/keeper/keeper_test.go | 54 ++++++++++++--- x/keyregistry/keeper/msg_update_params.go | 2 +- .../keeper/query_user_keypairs_test.go | 65 ++++++++++++------- .../keeper/query_validator_keypairs_test.go | 51 ++++++++++++--- .../keeper/user_register_keys_test.go | 2 + .../keeper/validator_update_keys_test.go | 3 - 7 files changed, 131 insertions(+), 62 deletions(-) diff --git a/x/keyregistry/keeper/keeper.go b/x/keyregistry/keeper/keeper.go index b59a8f20..5d532101 100644 --- a/x/keyregistry/keeper/keeper.go +++ b/x/keyregistry/keeper/keeper.go @@ -76,18 +76,10 @@ func (k Keeper) GetAuthority() []byte { return k.authority } -func (k Keeper) UserSetCosmosToMina(ctx context.Context, cosmosAddress, minaAddress []byte) error { - return k.userCosmosToMina.Set(ctx, cosmosAddress, minaAddress) -} - func (k Keeper) UserGetCosmosToMina(ctx context.Context, cosmosAddress []byte) ([]byte, error) { return k.userCosmosToMina.Get(ctx, cosmosAddress) } -func (k Keeper) UserSetMinaToCosmos(ctx context.Context, minaAddress, cosmosAddress []byte) error { - return k.userMinaToCosmos.Set(ctx, minaAddress, cosmosAddress) -} - func (k Keeper) UserGetMinaToCosmos(ctx context.Context, minaAddress []byte) ([]byte, error) { return k.userMinaToCosmos.Get(ctx, minaAddress) } @@ -100,18 +92,10 @@ func (k Keeper) UserMinaToCosmosHas(ctx context.Context, minaAddress []byte) (bo return k.userMinaToCosmos.Has(ctx, minaAddress) } -func (k Keeper) ValidatorSetCosmosToMina(ctx context.Context, cosmosAddress, minaAddress []byte) error { - return k.validatorCosmosToMina.Set(ctx, cosmosAddress, minaAddress) -} - func (k Keeper) ValidatorGetCosmosToMina(ctx context.Context, cosmosAddress []byte) ([]byte, error) { return k.validatorCosmosToMina.Get(ctx, cosmosAddress) } -func (k Keeper) ValidatorSetMinaToCosmos(ctx context.Context, minaAddress, cosmosAddress []byte) error { - return k.validatorMinaToCosmos.Set(ctx, minaAddress, cosmosAddress) -} - func (k Keeper) ValidatorGetMinaToCosmos(ctx context.Context, minaAddress []byte) ([]byte, error) { return k.validatorMinaToCosmos.Get(ctx, minaAddress) } diff --git a/x/keyregistry/keeper/keeper_test.go b/x/keyregistry/keeper/keeper_test.go index 92679d98..3d99a685 100644 --- a/x/keyregistry/keeper/keeper_test.go +++ b/x/keyregistry/keeper/keeper_test.go @@ -56,22 +56,37 @@ func initFixture(t *testing.T) *fixture { } } -// Dummy public keys used in tests. -var CosmosPubKey = []byte("cosmos") -var MinaPubKey = []byte("mina") - // TestCosmosToMina verifies that a cosmos public key can be stored in the // CosmosToMina map and correctly retrieved using the same cosmos public key. func TestUserCosmosToMina(t *testing.T) { f := initFixture(t) - err := f.keeper.UserSetCosmosToMina(f.ctx, CosmosPubKey, MinaPubKey) + ms := keeper.NewMsgServerImpl(f.keeper) + + cosmosPublicKey, minaPubKey, _, err := generateUserPublicKeys() + require.NoError(t, err) + require.NotNil(t, cosmosPublicKey) + require.NotNil(t, minaPubKey) + + creatorAddr := sdk.AccAddress(cosmosPublicKey.Address()) + require.NotNil(t, creatorAddr) + + resp, err := ms.RegisterKeys(f.ctx, &types.MsgRegisterKeys{ + Creator: creatorAddr.String(), + CosmosSignature: mockCosmosSignature, + MinaSignature: mockMinaSignature, + CosmosPublicKey: cosmosPublicKey.Bytes(), + MinaPublicKey: minaPubKey, + ActorType: types.ActorType_USER, + }) + require.NoError(t, err) + require.NotNil(t, resp) - pubKey, err := f.keeper.UserGetCosmosToMina(f.ctx, CosmosPubKey) + pubKey, err := f.keeper.UserGetCosmosToMina(f.ctx, cosmosPublicKey.Bytes()) require.NoError(t, err) - require.Equal(t, MinaPubKey, pubKey) + require.Equal(t, minaPubKey, pubKey) } // TestMinaToCosmos verifies that a mina public key can be stored in the @@ -79,11 +94,30 @@ func TestUserCosmosToMina(t *testing.T) { func TestUserMinaToCosmos(t *testing.T) { f := initFixture(t) - err := f.keeper.UserSetMinaToCosmos(f.ctx, MinaPubKey, CosmosPubKey) + ms := keeper.NewMsgServerImpl(f.keeper) + + cosmosPublicKey, minaPubKey, _, err := generateUserPublicKeys() + require.NoError(t, err) + require.NotNil(t, cosmosPublicKey) + require.NotNil(t, minaPubKey) + + creatorAddr := sdk.AccAddress(cosmosPublicKey.Address()) + require.NotNil(t, creatorAddr) + + resp, err := ms.RegisterKeys(f.ctx, &types.MsgRegisterKeys{ + Creator: creatorAddr.String(), + CosmosSignature: mockCosmosSignature, + MinaSignature: mockMinaSignature, + CosmosPublicKey: cosmosPublicKey.Bytes(), + MinaPublicKey: minaPubKey, + ActorType: types.ActorType_USER, + }) + require.NoError(t, err) + require.NotNil(t, resp) - pubKey, err := f.keeper.UserGetMinaToCosmos(f.ctx, MinaPubKey) + pubKey, err := f.keeper.UserGetMinaToCosmos(f.ctx, minaPubKey) require.NoError(t, err) - require.Equal(t, CosmosPubKey, pubKey) + require.Equal(t, cosmosPublicKey.Bytes(), pubKey) } diff --git a/x/keyregistry/keeper/msg_update_params.go b/x/keyregistry/keeper/msg_update_params.go index 38a9e3a1..be8957f2 100644 --- a/x/keyregistry/keeper/msg_update_params.go +++ b/x/keyregistry/keeper/msg_update_params.go @@ -12,7 +12,7 @@ import ( func (k msgServer) UpdateParams(ctx context.Context, req *types.MsgUpdateParams) (*types.MsgUpdateParamsResponse, error) { authority, err := k.addressCodec.StringToBytes(req.Authority) if err != nil { - return nil, errors.Wrap(types.ErrInvalidSigner, "authority address must be a valid bech32 address") + return nil, errors.Wrap(types.ErrInvalidCreatorAddress, "authority address must be a valid bech32 address") } if !bytes.Equal(k.GetAuthority(), authority) { diff --git a/x/keyregistry/keeper/query_user_keypairs_test.go b/x/keyregistry/keeper/query_user_keypairs_test.go index a8346ebd..11ac4bb1 100644 --- a/x/keyregistry/keeper/query_user_keypairs_test.go +++ b/x/keyregistry/keeper/query_user_keypairs_test.go @@ -6,6 +6,7 @@ import ( "testing" "github.com/cometbft/cometbft/crypto/secp256k1" + sdk "github.com/cosmos/cosmos-sdk/types" "github.com/node101-io/pulsar-chain/x/keyregistry/keeper" "github.com/node101-io/pulsar-chain/x/keyregistry/types" "github.com/stretchr/testify/require" @@ -38,27 +39,36 @@ func TestUserCosmosMapSuccess(t *testing.T) { params := types.DefaultParams() require.NoError(t, f.keeper.Params.Set(f.ctx, params)) - cosmosPriv := secp256k1.GenPrivKey() + ms := keeper.NewMsgServerImpl(f.keeper) - cosmosPubKey := cosmosPriv.PubKey() - - minaPubKey, _, err := ed25519.GenerateKey(rand.Reader) - if err != nil { - panic(err) - } + cosmosPublicKey, minaPubKey, _, err := generateUserPublicKeys() require.NoError(t, err) + require.NotNil(t, cosmosPublicKey) + require.NotNil(t, minaPubKey) + + creatorAddr := sdk.AccAddress(cosmosPublicKey.Address()) + require.NotNil(t, creatorAddr) + + resp, err := ms.RegisterKeys(f.ctx, &types.MsgRegisterKeys{ + Creator: creatorAddr.String(), + CosmosSignature: mockCosmosSignature, + MinaSignature: mockMinaSignature, + CosmosPublicKey: cosmosPublicKey.Bytes(), + MinaPublicKey: minaPubKey, + ActorType: types.ActorType_USER, + }) - err = f.keeper.UserSetCosmosToMina(f.ctx, cosmosPubKey.Bytes(), minaPubKey) require.NoError(t, err) + require.NotNil(t, resp) - resp, err := qs.GetUserMinaPublicKey(f.ctx, &types.QueryGetUserMinaPublicKeyRequest{ - UserCosmosPublicKey: cosmosPubKey.Bytes(), + queryResp, err := qs.GetUserMinaPublicKey(f.ctx, &types.QueryGetUserMinaPublicKeyRequest{ + UserCosmosPublicKey: cosmosPublicKey.Bytes(), }) - require.NotNil(t, resp) + require.NotNil(t, queryResp) require.NoError(t, err) - require.Equal(t, resp.UserMinaPublicKey, []byte(minaPubKey)) + require.Equal(t, minaPubKey, queryResp.UserMinaPublicKey) } // TestUserMinaMapSuccess verifies that a cosmos public key can be retrieved @@ -70,27 +80,36 @@ func TestUserMinaMapSuccess(t *testing.T) { params := types.DefaultParams() require.NoError(t, f.keeper.Params.Set(f.ctx, params)) - cosmosPriv := secp256k1.GenPrivKey() + ms := keeper.NewMsgServerImpl(f.keeper) - cosmosPubKey := cosmosPriv.PubKey() - - minaPubKey, _, err := ed25519.GenerateKey(rand.Reader) - if err != nil { - panic(err) - } + cosmosPublicKey, minaPubKey, _, err := generateUserPublicKeys() require.NoError(t, err) + require.NotNil(t, cosmosPublicKey) + require.NotNil(t, minaPubKey) + + creatorAddr := sdk.AccAddress(cosmosPublicKey.Address()) + require.NotNil(t, creatorAddr) + + resp, err := ms.RegisterKeys(f.ctx, &types.MsgRegisterKeys{ + Creator: creatorAddr.String(), + CosmosSignature: mockCosmosSignature, + MinaSignature: mockMinaSignature, + CosmosPublicKey: cosmosPublicKey.Bytes(), + MinaPublicKey: minaPubKey, + ActorType: types.ActorType_USER, + }) - err = f.keeper.UserSetMinaToCosmos(f.ctx, minaPubKey, cosmosPubKey.Bytes()) require.NoError(t, err) + require.NotNil(t, resp) - resp, err := qs.GetUserCosmosPublicKey(f.ctx, &types.QueryGetUserCosmosPublicKeyRequest{ + queryResp, err := qs.GetUserCosmosPublicKey(f.ctx, &types.QueryGetUserCosmosPublicKeyRequest{ UserMinaPublicKey: minaPubKey, }) - require.NotNil(t, resp) + require.NotNil(t, queryResp) require.NoError(t, err) - require.Equal(t, resp.UserCosmosPublicKey, cosmosPubKey.Bytes()) + require.Equal(t, cosmosPublicKey.Bytes(), queryResp.UserCosmosPublicKey) } // TestUserMinaMapInvalidArgumentFail verifies that GetMinaPubKey returns diff --git a/x/keyregistry/keeper/query_validator_keypairs_test.go b/x/keyregistry/keeper/query_validator_keypairs_test.go index aad98d2f..ae2455bc 100644 --- a/x/keyregistry/keeper/query_validator_keypairs_test.go +++ b/x/keyregistry/keeper/query_validator_keypairs_test.go @@ -3,6 +3,7 @@ package keeper_test import ( "testing" + sdk "github.com/cosmos/cosmos-sdk/types" "github.com/node101-io/pulsar-chain/x/keyregistry/keeper" "github.com/node101-io/pulsar-chain/x/keyregistry/types" "github.com/stretchr/testify/require" @@ -37,18 +38,34 @@ func TestValidatorCosmosMapSuccess(t *testing.T) { cosmosPubKey, minaPubKey, _, err := generateValidatorPublicKeys() require.NoError(t, err) + require.NotNil(t, cosmosPubKey) + require.NotNil(t, minaPubKey) + + ms := keeper.NewMsgServerImpl(f.keeper) + + creatorAddr := sdk.AccAddress(cosmosPubKey.Address()) + require.NotNil(t, creatorAddr) + + resp, err := ms.RegisterKeys(f.ctx, &types.MsgRegisterKeys{ + Creator: creatorAddr.String(), + CosmosSignature: mockCosmosSignature, + MinaSignature: mockMinaSignature, + CosmosPublicKey: cosmosPubKey.Bytes(), + MinaPublicKey: minaPubKey, + ActorType: types.ActorType_VALIDATOR, + }) - err = f.keeper.ValidatorSetCosmosToMina(f.ctx, cosmosPubKey.Bytes(), minaPubKey) require.NoError(t, err) + require.NotNil(t, resp) - resp, err := qs.GetValidatorMinaPubKey(f.ctx, &types.QueryGetValidatorMinaPubKeyRequest{ + queryResp, err := qs.GetValidatorMinaPubKey(f.ctx, &types.QueryGetValidatorMinaPubKeyRequest{ ValidatorCosmosPubKey: cosmosPubKey.Bytes(), }) - require.NotNil(t, resp) + require.NotNil(t, queryResp) require.NoError(t, err) - require.Equal(t, resp.ValidatorMinaPubKey, minaPubKey) + require.Equal(t, queryResp.ValidatorMinaPubKey, minaPubKey) } // TestValidatorMinaMapSuccess verifies that a cosmos public key can be retrieved @@ -62,17 +79,33 @@ func TestValidatorMinaMapSuccess(t *testing.T) { cosmosPubKey, minaPubKey, _, err := generateValidatorPublicKeys() require.NoError(t, err) + require.NotNil(t, cosmosPubKey) + require.NotNil(t, minaPubKey) + + ms := keeper.NewMsgServerImpl(f.keeper) + + creatorAddr := sdk.AccAddress(cosmosPubKey.Address()) + require.NotNil(t, creatorAddr) + + resp, err := ms.RegisterKeys(f.ctx, &types.MsgRegisterKeys{ + Creator: creatorAddr.String(), + CosmosSignature: mockCosmosSignature, + MinaSignature: mockMinaSignature, + CosmosPublicKey: cosmosPubKey.Bytes(), + MinaPublicKey: minaPubKey, + ActorType: types.ActorType_VALIDATOR, + }) - err = f.keeper.ValidatorSetMinaToCosmos(f.ctx, minaPubKey, cosmosPubKey.Bytes()) require.NoError(t, err) + require.NotNil(t, resp) - resp, err := qs.GetValidatorCosmosPubKey(f.ctx, &types.QueryGetValidatorCosmosPubKeyRequest{ + queryResp, err := qs.GetValidatorCosmosPubKey(f.ctx, &types.QueryGetValidatorCosmosPubKeyRequest{ ValidatorMinaPubKey: minaPubKey, }) - require.NotNil(t, resp) + require.NotNil(t, queryResp) require.NoError(t, err) - require.Equal(t, resp.ValidatorCosmosPubKey, cosmosPubKey.Bytes()) + require.Equal(t, cosmosPubKey.Bytes(), queryResp.ValidatorCosmosPubKey) } // TestValidatorMinaMapInvalidArgumentFail verifies that GetMinaPubKey returns @@ -127,7 +160,7 @@ func TestValidatorMinaMapPubkeyNotFound(t *testing.T) { require.NoError(t, err) _, err = qs.GetValidatorMinaPubKey(f.ctx, &types.QueryGetValidatorMinaPubKeyRequest{ - ValidatorCosmosPubKey: CosmosPubKey, + ValidatorCosmosPubKey: cosmosPubKey.Bytes(), }) st, _ := status.FromError(err) diff --git a/x/keyregistry/keeper/user_register_keys_test.go b/x/keyregistry/keeper/user_register_keys_test.go index 9c2dfe3d..a3896bc8 100644 --- a/x/keyregistry/keeper/user_register_keys_test.go +++ b/x/keyregistry/keeper/user_register_keys_test.go @@ -18,6 +18,8 @@ import ( // These will be replaced with real signatures once VerifyMinaSig and VerifyCosmosSig are implemented. var mockCosmosSignature = []byte("cosmosSig") var mockMinaSignature = []byte("minaSig") +var CosmosPubKey = []byte("cosmos-public-key") +var MinaPubKey = []byte("mina-public-key") var MinaPriv = []byte("7olA5Knafb5E2hJoWFzD+oamtyXIXXUZmYG9+pBMjTGIjqZTVLNGbE7DQ3Zq5YL5NMW31UMMMGgNCeEk+gyzRA==") diff --git a/x/keyregistry/keeper/validator_update_keys_test.go b/x/keyregistry/keeper/validator_update_keys_test.go index b5bab038..ba628e65 100644 --- a/x/keyregistry/keeper/validator_update_keys_test.go +++ b/x/keyregistry/keeper/validator_update_keys_test.go @@ -108,9 +108,6 @@ func TestValidatorUpdateKeysMissingCosmosToMinaMapping(t *testing.T) { require.NotNil(t, prevMinaPubKey) require.NotNil(t, newMinaPubKey) - err = f.keeper.ValidatorSetMinaToCosmos(f.ctx, prevMinaPubKey, cosmosPublicKey.Bytes()) - require.NoError(t, err) - creatorAddr := sdk.AccAddress(cosmosPublicKey.Address()) require.NotNil(t, creatorAddr) From 845321ce48923ab8ec6c1b17256ee2dc898bbe01 Mon Sep 17 00:00:00 2001 From: korayakpinar Date: Fri, 24 Apr 2026 23:49:35 +0300 Subject: [PATCH 20/62] refactor(keyregistry): rename keeper key params from address to pubkey --- x/keyregistry/keeper/keeper.go | 32 ++++++++++++++++---------------- 1 file changed, 16 insertions(+), 16 deletions(-) diff --git a/x/keyregistry/keeper/keeper.go b/x/keyregistry/keeper/keeper.go index 5d532101..52be513c 100644 --- a/x/keyregistry/keeper/keeper.go +++ b/x/keyregistry/keeper/keeper.go @@ -76,34 +76,34 @@ func (k Keeper) GetAuthority() []byte { return k.authority } -func (k Keeper) UserGetCosmosToMina(ctx context.Context, cosmosAddress []byte) ([]byte, error) { - return k.userCosmosToMina.Get(ctx, cosmosAddress) +func (k Keeper) UserGetCosmosToMina(ctx context.Context, cosmosPubKey []byte) ([]byte, error) { + return k.userCosmosToMina.Get(ctx, cosmosPubKey) } -func (k Keeper) UserGetMinaToCosmos(ctx context.Context, minaAddress []byte) ([]byte, error) { - return k.userMinaToCosmos.Get(ctx, minaAddress) +func (k Keeper) UserGetMinaToCosmos(ctx context.Context, minaPubKey []byte) ([]byte, error) { + return k.userMinaToCosmos.Get(ctx, minaPubKey) } -func (k Keeper) UserCosmosToMinaHas(ctx context.Context, cosmosAddress []byte) (bool, error) { - return k.userCosmosToMina.Has(ctx, cosmosAddress) +func (k Keeper) UserCosmosToMinaHas(ctx context.Context, cosmosPubKey []byte) (bool, error) { + return k.userCosmosToMina.Has(ctx, cosmosPubKey) } -func (k Keeper) UserMinaToCosmosHas(ctx context.Context, minaAddress []byte) (bool, error) { - return k.userMinaToCosmos.Has(ctx, minaAddress) +func (k Keeper) UserMinaToCosmosHas(ctx context.Context, minaPubKey []byte) (bool, error) { + return k.userMinaToCosmos.Has(ctx, minaPubKey) } -func (k Keeper) ValidatorGetCosmosToMina(ctx context.Context, cosmosAddress []byte) ([]byte, error) { - return k.validatorCosmosToMina.Get(ctx, cosmosAddress) +func (k Keeper) ValidatorGetCosmosToMina(ctx context.Context, consensusPubKey []byte) ([]byte, error) { + return k.validatorCosmosToMina.Get(ctx, consensusPubKey) } -func (k Keeper) ValidatorGetMinaToCosmos(ctx context.Context, minaAddress []byte) ([]byte, error) { - return k.validatorMinaToCosmos.Get(ctx, minaAddress) +func (k Keeper) ValidatorGetMinaToCosmos(ctx context.Context, minaPubKey []byte) ([]byte, error) { + return k.validatorMinaToCosmos.Get(ctx, minaPubKey) } -func (k Keeper) ValidatorCosmosToMinaHas(ctx context.Context, cosmosAddress []byte) (bool, error) { - return k.validatorCosmosToMina.Has(ctx, cosmosAddress) +func (k Keeper) ValidatorCosmosToMinaHas(ctx context.Context, consensusPubKey []byte) (bool, error) { + return k.validatorCosmosToMina.Has(ctx, consensusPubKey) } -func (k Keeper) ValidatorMinaToCosmosHas(ctx context.Context, minaAddress []byte) (bool, error) { - return k.validatorMinaToCosmos.Has(ctx, minaAddress) +func (k Keeper) ValidatorMinaToCosmosHas(ctx context.Context, minaPubKey []byte) (bool, error) { + return k.validatorMinaToCosmos.Has(ctx, minaPubKey) } From 93c873fb509f6468c9820707acaba57561d052c4 Mon Sep 17 00:00:00 2001 From: korayakpinar Date: Mon, 27 Apr 2026 16:35:19 +0300 Subject: [PATCH 21/62] feat(keyregistry): canonicalize genesis key pair state --- config.yml | 22 +- .../pulsarchain/keyregistry/v1/genesis.proto | 6 +- x/keyregistry/keeper/genesis.go | 107 +++++---- x/keyregistry/keeper/genesis_internal_test.go | 117 ++++++++++ x/keyregistry/keeper/genesis_test.go | 84 +++++-- x/keyregistry/types/errors.go | 1 + x/keyregistry/types/genesis.go | 82 ++++--- x/keyregistry/types/genesis.pb.go | 217 ++++-------------- x/keyregistry/types/genesis_test.go | 141 +++++++++++- 9 files changed, 483 insertions(+), 294 deletions(-) create mode 100644 x/keyregistry/keeper/genesis_internal_test.go diff --git a/config.yml b/config.yml index 11846e3f..4ac7edc1 100644 --- a/config.yml +++ b/config.yml @@ -30,15 +30,13 @@ genesis: app_state: keyregistry: params: {} - user_cosmos_to_mina: - # - mina_key: "SC/6aqoZ19ObLka8NIQVMs1qPim+uD6epPLuQS4x2n4Z" - # cosmos_key: "UdDr3CCO+4HVrBtbzqLTM3P2xAMNCIrPeCTeVfb5sw1y" - user_mina_to_cosmos: - # - mina_key: "3IvK1eWmmcfdlIb+T04+ck9Q5bjbqHqiT0ucGJITzyY=" - # cosmos_key: "A8saw69s1DQWvUjseeOtG8hGavmYiInrQ5M1aOPa4QkP" - validator_cosmos_to_mina: - # - mina_key: "SC/6aqoZ19ObLka8NIQVMs1qPim+uD6epPLuQS4x2n4Z" - # cosmos_key: "UdDr3CCO+4HVrBtbzqLTM3P2xAMNCIrPeCTeVfb5sw1y" - validator_mina_to_cosmos: - # - mina_key: "3IvK1eWmmcfdlIb+T04+ck9Q5bjbqHqiT0ucGJITzyY=" - # cosmos_key: "A8saw69s1DQWvUjseeOtG8hGavmYiInrQ5M1aOPa4QkP" \ No newline at end of file + user_key_pairs: + # Mina compressed public key placeholder: zero bytes, 33 bytes. + #- mina_key: "AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA" + # Cosmos user public key placeholder: secp256k1 compressed, zero bytes, 33 bytes. + #cosmos_key: "AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA" + validator_key_pairs: + # Mina compressed public key placeholder: zero bytes, 33 bytes. + #- mina_key: "AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA" + # Validator consensus public key placeholder: ed25519, zero bytes, 32 bytes. + # cosmos_key: "AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA=" diff --git a/proto/pulsarchain/keyregistry/v1/genesis.proto b/proto/pulsarchain/keyregistry/v1/genesis.proto index 2d7b3bad..a15fcf04 100644 --- a/proto/pulsarchain/keyregistry/v1/genesis.proto +++ b/proto/pulsarchain/keyregistry/v1/genesis.proto @@ -15,8 +15,6 @@ message GenesisState { (gogoproto.nullable) = false, (amino.dont_omitempty) = true ]; - repeated UserPublicKeyPair user_cosmos_to_mina = 2; - repeated UserPublicKeyPair user_mina_to_cosmos = 3; - repeated ValidatorPublicKeyPair validator_cosmos_to_mina = 4; - repeated ValidatorPublicKeyPair validator_mina_to_cosmos = 5; + repeated UserPublicKeyPair user_key_pairs = 2; + repeated ValidatorPublicKeyPair validator_key_pairs = 3; } diff --git a/x/keyregistry/keeper/genesis.go b/x/keyregistry/keeper/genesis.go index 4f38db0d..67ddbf71 100644 --- a/x/keyregistry/keeper/genesis.go +++ b/x/keyregistry/keeper/genesis.go @@ -1,35 +1,36 @@ package keeper import ( + "bytes" "context" + errorsmod "cosmossdk.io/errors" "github.com/node101-io/pulsar-chain/x/keyregistry/types" ) // InitGenesis initializes the module's state from a provided genesis state. func (k Keeper) InitGenesis(ctx context.Context, genState types.GenesisState) error { + if err := genState.Validate(); err != nil { + return err + } - // Insert genesis key pairs. - for _, keyPair := range genState.UserCosmosToMina { + for _, keyPair := range genState.UserKeyPairs { err := k.userCosmosToMina.Set(ctx, keyPair.CosmosKey, keyPair.MinaKey) if err != nil { return err } - } - for _, keyPair := range genState.UserMinaToCosmos { - err := k.userMinaToCosmos.Set(ctx, keyPair.MinaKey, keyPair.CosmosKey) + err = k.userMinaToCosmos.Set(ctx, keyPair.MinaKey, keyPair.CosmosKey) if err != nil { return err } } - for _, keyPair := range genState.ValidatorCosmosToMina { + + for _, keyPair := range genState.ValidatorKeyPairs { err := k.validatorCosmosToMina.Set(ctx, keyPair.CosmosKey, keyPair.MinaKey) if err != nil { return err } - } - for _, keyPair := range genState.ValidatorMinaToCosmos { - err := k.validatorMinaToCosmos.Set(ctx, keyPair.MinaKey, keyPair.CosmosKey) + err = k.validatorMinaToCosmos.Set(ctx, keyPair.MinaKey, keyPair.CosmosKey) if err != nil { return err } @@ -48,14 +49,31 @@ func (k Keeper) ExportGenesis(ctx context.Context) (*types.GenesisState, error) return nil, err } - userCosmosToMinaIterator, err := k.userCosmosToMina.Iterate(ctx, nil) + genesis.UserKeyPairs, err = k.exportUserGenesisKeyPairs(ctx) if err != nil { return nil, err } + genesis.ValidatorKeyPairs, err = k.exportValidatorGenesisKeyPairs(ctx) + if err != nil { + return nil, err + } + + if err := genesis.Validate(); err != nil { + return nil, errorsmod.Wrap(types.ErrInvalidGenesisState, err.Error()) + } + + return genesis, nil +} + +func (k Keeper) exportUserGenesisKeyPairs(ctx context.Context) ([]*types.UserPublicKeyPair, error) { + userCosmosToMinaIterator, err := k.userCosmosToMina.Iterate(ctx, nil) + if err != nil { + return nil, err + } defer userCosmosToMinaIterator.Close() - var userCosmosToMinaSlice []*types.UserPublicKeyPair + var userKeyPairs []*types.UserPublicKeyPair for userCosmosToMinaIterator.Valid() { cosmosKey, err := userCosmosToMinaIterator.Key() @@ -66,27 +84,28 @@ func (k Keeper) ExportGenesis(ctx context.Context) (*types.GenesisState, error) if err != nil { return nil, err } - keyPair := &types.UserPublicKeyPair{ - MinaKey: minaKey, - CosmosKey: cosmosKey, + reverseCosmosKey, err := k.userMinaToCosmos.Get(ctx, minaKey) + if err != nil { + return nil, errorsmod.Wrap(types.ErrInvalidGenesisState, "user key pair missing reverse index") + } + if !bytes.Equal(reverseCosmosKey, cosmosKey) { + return nil, errorsmod.Wrap(types.ErrInvalidGenesisState, "user key pair reverse index mismatch") } - userCosmosToMinaSlice = append(userCosmosToMinaSlice, keyPair) + userKeyPairs = append(userKeyPairs, &types.UserPublicKeyPair{ + MinaKey: minaKey, + CosmosKey: cosmosKey, + }) userCosmosToMinaIterator.Next() } - genesis.UserCosmosToMina = userCosmosToMinaSlice - userMinaToCosmosIterator, err := k.userMinaToCosmos.Iterate(ctx, nil) if err != nil { return nil, err } - defer userMinaToCosmosIterator.Close() - var userMinaToCosmosSlice []*types.UserPublicKeyPair - for userMinaToCosmosIterator.Valid() { minaKey, err := userMinaToCosmosIterator.Key() if err != nil { @@ -96,26 +115,28 @@ func (k Keeper) ExportGenesis(ctx context.Context) (*types.GenesisState, error) if err != nil { return nil, err } - keyPair := &types.UserPublicKeyPair{ - MinaKey: minaKey, - CosmosKey: cosmosKey, + forwardMinaKey, err := k.userCosmosToMina.Get(ctx, cosmosKey) + if err != nil { + return nil, errorsmod.Wrap(types.ErrInvalidGenesisState, "user reverse key pair missing forward index") + } + if !bytes.Equal(forwardMinaKey, minaKey) { + return nil, errorsmod.Wrap(types.ErrInvalidGenesisState, "user reverse key pair forward index mismatch") } - - userMinaToCosmosSlice = append(userMinaToCosmosSlice, keyPair) userMinaToCosmosIterator.Next() } - genesis.UserMinaToCosmos = userMinaToCosmosSlice + return userKeyPairs, nil +} +func (k Keeper) exportValidatorGenesisKeyPairs(ctx context.Context) ([]*types.ValidatorPublicKeyPair, error) { validatorCosmosToMinaIterator, err := k.validatorCosmosToMina.Iterate(ctx, nil) if err != nil { return nil, err } - defer validatorCosmosToMinaIterator.Close() - var validatorCosmosToMinaSlice []*types.ValidatorPublicKeyPair + var validatorKeyPairs []*types.ValidatorPublicKeyPair for validatorCosmosToMinaIterator.Valid() { cosmosKey, err := validatorCosmosToMinaIterator.Key() @@ -126,27 +147,30 @@ func (k Keeper) ExportGenesis(ctx context.Context) (*types.GenesisState, error) if err != nil { return nil, err } + reverseCosmosKey, err := k.validatorMinaToCosmos.Get(ctx, minaKey) + if err != nil { + return nil, errorsmod.Wrap(types.ErrInvalidGenesisState, "validator key pair missing reverse index") + } + if !bytes.Equal(reverseCosmosKey, cosmosKey) { + return nil, errorsmod.Wrap(types.ErrInvalidGenesisState, "validator key pair reverse index mismatch") + } + keyPair := &types.ValidatorPublicKeyPair{ MinaKey: minaKey, CosmosKey: cosmosKey, } - validatorCosmosToMinaSlice = append(validatorCosmosToMinaSlice, keyPair) + validatorKeyPairs = append(validatorKeyPairs, keyPair) validatorCosmosToMinaIterator.Next() } - genesis.ValidatorCosmosToMina = validatorCosmosToMinaSlice - validatorMinaToCosmosIterator, err := k.validatorMinaToCosmos.Iterate(ctx, nil) if err != nil { return nil, err } - defer validatorMinaToCosmosIterator.Close() - var validatorMinaToCosmosSlice []*types.ValidatorPublicKeyPair - for validatorMinaToCosmosIterator.Valid() { minaKey, err := validatorMinaToCosmosIterator.Key() if err != nil { @@ -156,17 +180,16 @@ func (k Keeper) ExportGenesis(ctx context.Context) (*types.GenesisState, error) if err != nil { return nil, err } - keyPair := &types.ValidatorPublicKeyPair{ - MinaKey: minaKey, - CosmosKey: cosmosKey, + forwardMinaKey, err := k.validatorCosmosToMina.Get(ctx, cosmosKey) + if err != nil { + return nil, errorsmod.Wrap(types.ErrInvalidGenesisState, "validator reverse key pair missing forward index") + } + if !bytes.Equal(forwardMinaKey, minaKey) { + return nil, errorsmod.Wrap(types.ErrInvalidGenesisState, "validator reverse key pair forward index mismatch") } - - validatorMinaToCosmosSlice = append(validatorMinaToCosmosSlice, keyPair) validatorMinaToCosmosIterator.Next() } - genesis.ValidatorMinaToCosmos = validatorMinaToCosmosSlice - - return genesis, nil + return validatorKeyPairs, nil } diff --git a/x/keyregistry/keeper/genesis_internal_test.go b/x/keyregistry/keeper/genesis_internal_test.go new file mode 100644 index 00000000..bc804f54 --- /dev/null +++ b/x/keyregistry/keeper/genesis_internal_test.go @@ -0,0 +1,117 @@ +package keeper + +import ( + "bytes" + "context" + "testing" + + storetypes "cosmossdk.io/store/types" + "github.com/cosmos/cosmos-sdk/codec" + addresscodec "github.com/cosmos/cosmos-sdk/codec/address" + codectypes "github.com/cosmos/cosmos-sdk/codec/types" + "github.com/cosmos/cosmos-sdk/runtime" + "github.com/cosmos/cosmos-sdk/testutil" + sdk "github.com/cosmos/cosmos-sdk/types" + authtypes "github.com/cosmos/cosmos-sdk/x/auth/types" + "github.com/node101-io/pulsar-chain/x/keyregistry/types" + "github.com/stretchr/testify/require" +) + +func TestExportGenesisRejectsInconsistentRuntimeIndexes(t *testing.T) { + tests := []struct { + name string + corrupt func(context.Context, Keeper) error + }{ + { + name: "user forward missing reverse", + corrupt: func(ctx context.Context, k Keeper) error { + return k.userCosmosToMina.Set(ctx, testGenesisBytes(33, 'a'), testGenesisBytes(33, 'x')) + }, + }, + { + name: "user reverse missing forward", + corrupt: func(ctx context.Context, k Keeper) error { + return k.userMinaToCosmos.Set(ctx, testGenesisBytes(33, 'x'), testGenesisBytes(33, 'a')) + }, + }, + { + name: "user forward reverse mismatch", + corrupt: func(ctx context.Context, k Keeper) error { + if err := k.userCosmosToMina.Set(ctx, testGenesisBytes(33, 'a'), testGenesisBytes(33, 'x')); err != nil { + return err + } + return k.userMinaToCosmos.Set(ctx, testGenesisBytes(33, 'x'), testGenesisBytes(33, 'b')) + }, + }, + { + name: "validator forward missing reverse", + corrupt: func(ctx context.Context, k Keeper) error { + return k.validatorCosmosToMina.Set(ctx, testGenesisBytes(32, 'a'), testGenesisBytes(33, 'x')) + }, + }, + { + name: "validator reverse missing forward", + corrupt: func(ctx context.Context, k Keeper) error { + return k.validatorMinaToCosmos.Set(ctx, testGenesisBytes(33, 'x'), testGenesisBytes(32, 'a')) + }, + }, + { + name: "validator forward reverse mismatch", + corrupt: func(ctx context.Context, k Keeper) error { + if err := k.validatorCosmosToMina.Set(ctx, testGenesisBytes(32, 'a'), testGenesisBytes(33, 'x')); err != nil { + return err + } + return k.validatorMinaToCosmos.Set(ctx, testGenesisBytes(33, 'x'), testGenesisBytes(32, 'b')) + }, + }, + { + name: "consistent indexes with invalid exported key length", + corrupt: func(ctx context.Context, k Keeper) error { + if err := k.userCosmosToMina.Set(ctx, testGenesisBytes(32, 'a'), testGenesisBytes(33, 'x')); err != nil { + return err + } + return k.userMinaToCosmos.Set(ctx, testGenesisBytes(33, 'x'), testGenesisBytes(32, 'a')) + }, + }, + } + + for _, tc := range tests { + t.Run(tc.name, func(t *testing.T) { + ctx, k := initInternalGenesisFixture(t) + + err := tc.corrupt(ctx, k) + require.NoError(t, err) + + genesis, err := k.ExportGenesis(ctx) + require.Nil(t, genesis) + require.ErrorIs(t, err, types.ErrInvalidGenesisState) + }) + } +} + +func initInternalGenesisFixture(t *testing.T) (context.Context, Keeper) { + t.Helper() + + addressCodec := addresscodec.NewBech32Codec(sdk.GetConfig().GetBech32AccountAddrPrefix()) + storeKey := storetypes.NewKVStoreKey(types.StoreKey) + storeService := runtime.NewKVStoreService(storeKey) + ctx := testutil.DefaultContextWithDB(t, storeKey, storetypes.NewTransientStoreKey("transient_test")).Ctx + authority := authtypes.NewModuleAddress(types.GovModuleName) + cdc := codec.NewProtoCodec(codectypes.NewInterfaceRegistry()) + + k := NewKeeper( + storeService, + cdc, + addressCodec, + authority, + ) + + err := k.Params.Set(ctx, types.DefaultParams()) + require.NoError(t, err) + + return ctx, k +} + +func testGenesisBytes(length int, value byte) []byte { + return bytes.Repeat([]byte{value}, length) +} diff --git a/x/keyregistry/keeper/genesis_test.go b/x/keyregistry/keeper/genesis_test.go index cb25bd36..d186b791 100644 --- a/x/keyregistry/keeper/genesis_test.go +++ b/x/keyregistry/keeper/genesis_test.go @@ -24,56 +24,94 @@ func TestGenesis(t *testing.T) { require.EqualExportedValues(t, genesisState.Params, got.Params) } -// TestInitAndExportGenesis verifies that a genesis state can be initialized -// and later exported without losing the registered key pairs. +// TestInitAndExportGenesis verifies that a canonical genesis state can be +// initialized, stored in both runtime lookup maps, and exported again. func TestInitAndExportGenesis(t *testing.T) { - f := initFixture(t) userCosmosPubKey := secp256k1.GenPrivKey().PubKey() - validatorPublicKey := cometed25519.GenPrivKey().PubKey() - - MinaPriv := secp256k1.GenPrivKey() - minaPubKey := MinaPriv.PubKey().Bytes() + minaPriv := secp256k1.GenPrivKey() + minaPubKey := minaPriv.PubKey().Bytes() genesisState := types.GenesisState{ Params: types.DefaultParams(), - UserCosmosToMina: []*types.UserPublicKeyPair{ + UserKeyPairs: []*types.UserPublicKeyPair{ { MinaKey: minaPubKey, CosmosKey: userCosmosPubKey.Bytes(), }, }, - UserMinaToCosmos: []*types.UserPublicKeyPair{ + ValidatorKeyPairs: []*types.ValidatorPublicKeyPair{ { MinaKey: minaPubKey, - CosmosKey: userCosmosPubKey.Bytes(), + CosmosKey: validatorPublicKey.Bytes(), }, }, - ValidatorCosmosToMina: []*types.ValidatorPublicKeyPair{ + } + + err := f.keeper.InitGenesis(f.ctx, genesisState) + require.NoError(t, err) + + userMinaPubKey, err := f.keeper.UserGetCosmosToMina(f.ctx, userCosmosPubKey.Bytes()) + require.NoError(t, err) + require.Equal(t, minaPubKey, userMinaPubKey) + + userCosmosKey, err := f.keeper.UserGetMinaToCosmos(f.ctx, minaPubKey) + require.NoError(t, err) + require.Equal(t, userCosmosPubKey.Bytes(), userCosmosKey) + + validatorMinaPubKey, err := f.keeper.ValidatorGetCosmosToMina(f.ctx, validatorPublicKey.Bytes()) + require.NoError(t, err) + require.Equal(t, minaPubKey, validatorMinaPubKey) + + validatorCosmosKey, err := f.keeper.ValidatorGetMinaToCosmos(f.ctx, minaPubKey) + require.NoError(t, err) + require.Equal(t, validatorPublicKey.Bytes(), validatorCosmosKey) + + got, err := f.keeper.ExportGenesis(f.ctx) + require.NoError(t, err) + require.NotNil(t, got) + + require.EqualExportedValues(t, genesisState.UserKeyPairs, got.UserKeyPairs) + require.EqualExportedValues(t, genesisState.ValidatorKeyPairs, got.ValidatorKeyPairs) +} + +func TestInitGenesisRejectsInvalidStateWithoutPartialWrite(t *testing.T) { + f := initFixture(t) + + userCosmosPubKey := secp256k1.GenPrivKey().PubKey() + minaPrivKey := secp256k1.GenPrivKey() + minaPubKey := minaPrivKey.PubKey().Bytes() + secondaryMinaPrivKey := secp256k1.GenPrivKey() + secondaryMinaPubKey := secondaryMinaPrivKey.PubKey().Bytes() + + genesisState := types.GenesisState{ + Params: types.DefaultParams(), + UserKeyPairs: []*types.UserPublicKeyPair{ { MinaKey: minaPubKey, - CosmosKey: validatorPublicKey.Bytes(), + CosmosKey: userCosmosPubKey.Bytes(), }, - }, - ValidatorMinaToCosmos: []*types.ValidatorPublicKeyPair{ { - MinaKey: minaPubKey, - CosmosKey: validatorPublicKey.Bytes(), + MinaKey: secondaryMinaPubKey, + CosmosKey: userCosmosPubKey.Bytes(), }, }, } err := f.keeper.InitGenesis(f.ctx, genesisState) + require.ErrorIs(t, err, types.ErrInvalidGenesisState) + + exists, err := f.keeper.UserCosmosToMinaHas(f.ctx, userCosmosPubKey.Bytes()) require.NoError(t, err) - got, err := f.keeper.ExportGenesis(f.ctx) - require.NoError(t, err) - require.NotNil(t, got) + require.False(t, exists) - require.EqualExportedValues(t, genesisState.UserCosmosToMina, got.UserCosmosToMina) - require.EqualExportedValues(t, genesisState.UserMinaToCosmos, got.UserMinaToCosmos) - require.EqualExportedValues(t, genesisState.ValidatorCosmosToMina, got.ValidatorCosmosToMina) - require.EqualExportedValues(t, genesisState.ValidatorMinaToCosmos, got.ValidatorMinaToCosmos) + exists, err = f.keeper.UserMinaToCosmosHas(f.ctx, minaPubKey) + require.NoError(t, err) + require.False(t, exists) + exists, err = f.keeper.UserMinaToCosmosHas(f.ctx, secondaryMinaPubKey) + require.NoError(t, err) + require.False(t, exists) } diff --git a/x/keyregistry/types/errors.go b/x/keyregistry/types/errors.go index c9b1bcb4..3bc341ca 100644 --- a/x/keyregistry/types/errors.go +++ b/x/keyregistry/types/errors.go @@ -18,4 +18,5 @@ var ( ErrValidatorNotRegistered = errors.Register(ModuleName, 1107, "validator has not been registered") ErrInvalidActorType = errors.Register(ModuleName, 1108, "invalid actor type") ErrNilKeyPair = errors.Register(ModuleName, 1109, "nil keypair") + ErrInvalidGenesisState = errors.Register(ModuleName, 1110, "invalid genesis state") ) diff --git a/x/keyregistry/types/genesis.go b/x/keyregistry/types/genesis.go index 1d99120e..654840ba 100644 --- a/x/keyregistry/types/genesis.go +++ b/x/keyregistry/types/genesis.go @@ -1,62 +1,84 @@ package types +import errorsmod "cosmossdk.io/errors" + // DefaultGenesis returns the default genesis state func DefaultGenesis() *GenesisState { return &GenesisState{ - Params: DefaultParams(), - UserCosmosToMina: DefaultUserPublicKeyPair(), - UserMinaToCosmos: DefaultUserPublicKeyPair(), - ValidatorCosmosToMina: DefaultValidatorPublicKeyPair(), - ValidatorMinaToCosmos: DefaultValidatorPublicKeyPair(), + Params: DefaultParams(), + UserKeyPairs: DefaultUserPublicKeyPair(), + ValidatorKeyPairs: DefaultValidatorPublicKeyPair(), } } // Validate performs basic genesis state validation returning an error upon any // failure. func (gs GenesisState) Validate() error { + if err := validateUserGenesisKeyPairs(gs.UserKeyPairs); err != nil { + return err + } + + if err := validateValidatorGenesisKeyPairs(gs.ValidatorKeyPairs); err != nil { + return err + } + + return gs.Params.Validate() +} - for _, keyPair := range gs.UserCosmosToMina { +func validateUserGenesisKeyPairs(keyPairs []*UserPublicKeyPair) error { + seenCosmosKeys := make(map[string]struct{}, len(keyPairs)) + seenMinaKeys := make(map[string]struct{}, len(keyPairs)) + + for _, keyPair := range keyPairs { if keyPair == nil { return ErrNilKeyPair } - kp := *keyPair - err := kp.Validate() - if err != nil { + + if err := keyPair.Validate(); err != nil { return err } - } - for _, keyPair := range gs.UserMinaToCosmos { - if keyPair == nil { - return ErrNilKeyPair + cosmosKey := string(keyPair.CosmosKey) + if _, exists := seenCosmosKeys[cosmosKey]; exists { + return errorsmod.Wrap(ErrInvalidGenesisState, "duplicate user cosmos key") } - kp := *keyPair - err := kp.Validate() - if err != nil { - return err + seenCosmosKeys[cosmosKey] = struct{}{} + + minaKey := string(keyPair.MinaKey) + if _, exists := seenMinaKeys[minaKey]; exists { + return errorsmod.Wrap(ErrInvalidGenesisState, "duplicate user mina key") } + seenMinaKeys[minaKey] = struct{}{} } - for _, keyPair := range gs.ValidatorCosmosToMina { + return nil +} + +func validateValidatorGenesisKeyPairs(keyPairs []*ValidatorPublicKeyPair) error { + seenConsensusKeys := make(map[string]struct{}, len(keyPairs)) + seenMinaKeys := make(map[string]struct{}, len(keyPairs)) + + for _, keyPair := range keyPairs { if keyPair == nil { return ErrNilKeyPair } - kp := *keyPair - err := kp.Validate() - if err != nil { + + if err := keyPair.Validate(); err != nil { return err } - } - for _, keyPair := range gs.ValidatorMinaToCosmos { - if keyPair == nil { - return ErrNilKeyPair + + consensusKey := string(keyPair.CosmosKey) + if _, exists := seenConsensusKeys[consensusKey]; exists { + return errorsmod.Wrap(ErrInvalidGenesisState, "duplicate validator consensus key") } - kp := *keyPair - err := kp.Validate() - if err != nil { - return err + seenConsensusKeys[consensusKey] = struct{}{} + + minaKey := string(keyPair.MinaKey) + if _, exists := seenMinaKeys[minaKey]; exists { + return errorsmod.Wrap(ErrInvalidGenesisState, "duplicate validator mina key") } + seenMinaKeys[minaKey] = struct{}{} } - return gs.Params.Validate() + return nil } diff --git a/x/keyregistry/types/genesis.pb.go b/x/keyregistry/types/genesis.pb.go index 9ea4b45a..38980463 100644 --- a/x/keyregistry/types/genesis.pb.go +++ b/x/keyregistry/types/genesis.pb.go @@ -27,11 +27,9 @@ const _ = proto.GoGoProtoPackageIsVersion3 // please upgrade the proto package // GenesisState defines the keyregistry module's genesis state. type GenesisState struct { // params defines all the parameters of the module. - Params Params `protobuf:"bytes,1,opt,name=params,proto3" json:"params"` - UserCosmosToMina []*UserPublicKeyPair `protobuf:"bytes,2,rep,name=user_cosmos_to_mina,json=userCosmosToMina,proto3" json:"user_cosmos_to_mina,omitempty"` - UserMinaToCosmos []*UserPublicKeyPair `protobuf:"bytes,3,rep,name=user_mina_to_cosmos,json=userMinaToCosmos,proto3" json:"user_mina_to_cosmos,omitempty"` - ValidatorCosmosToMina []*ValidatorPublicKeyPair `protobuf:"bytes,4,rep,name=validator_cosmos_to_mina,json=validatorCosmosToMina,proto3" json:"validator_cosmos_to_mina,omitempty"` - ValidatorMinaToCosmos []*ValidatorPublicKeyPair `protobuf:"bytes,5,rep,name=validator_mina_to_cosmos,json=validatorMinaToCosmos,proto3" json:"validator_mina_to_cosmos,omitempty"` + Params Params `protobuf:"bytes,1,opt,name=params,proto3" json:"params"` + UserKeyPairs []*UserPublicKeyPair `protobuf:"bytes,2,rep,name=user_key_pairs,json=userKeyPairs,proto3" json:"user_key_pairs,omitempty"` + ValidatorKeyPairs []*ValidatorPublicKeyPair `protobuf:"bytes,3,rep,name=validator_key_pairs,json=validatorKeyPairs,proto3" json:"validator_key_pairs,omitempty"` } func (m *GenesisState) Reset() { *m = GenesisState{} } @@ -74,30 +72,16 @@ func (m *GenesisState) GetParams() Params { return Params{} } -func (m *GenesisState) GetUserCosmosToMina() []*UserPublicKeyPair { +func (m *GenesisState) GetUserKeyPairs() []*UserPublicKeyPair { if m != nil { - return m.UserCosmosToMina + return m.UserKeyPairs } return nil } -func (m *GenesisState) GetUserMinaToCosmos() []*UserPublicKeyPair { +func (m *GenesisState) GetValidatorKeyPairs() []*ValidatorPublicKeyPair { if m != nil { - return m.UserMinaToCosmos - } - return nil -} - -func (m *GenesisState) GetValidatorCosmosToMina() []*ValidatorPublicKeyPair { - if m != nil { - return m.ValidatorCosmosToMina - } - return nil -} - -func (m *GenesisState) GetValidatorMinaToCosmos() []*ValidatorPublicKeyPair { - if m != nil { - return m.ValidatorMinaToCosmos + return m.ValidatorKeyPairs } return nil } @@ -111,31 +95,28 @@ func init() { } var fileDescriptor_dbaeb2ea35536f14 = []byte{ - // 374 bytes of a gzipped FileDescriptorProto - 0x1f, 0x8b, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0xff, 0xac, 0x92, 0xc1, 0x4a, 0xeb, 0x40, - 0x14, 0x86, 0x93, 0xdb, 0x7b, 0x0b, 0x37, 0xbd, 0x8b, 0x6b, 0x54, 0x08, 0x59, 0xc4, 0xd2, 0x8d, - 0x45, 0x68, 0xd2, 0x54, 0xf0, 0x01, 0x2a, 0xe2, 0x42, 0x84, 0x50, 0xab, 0x0b, 0x11, 0xc2, 0x34, - 0x1d, 0xd2, 0xa1, 0x4d, 0x4e, 0x98, 0x99, 0x14, 0xf3, 0x16, 0x3e, 0x86, 0x4b, 0x1f, 0xa3, 0xcb, - 0x2e, 0x5d, 0x89, 0xb4, 0x0b, 0x17, 0xbe, 0x84, 0x64, 0xa6, 0x96, 0x46, 0x31, 0x0b, 0x71, 0x13, - 0x86, 0xf0, 0x9f, 0xef, 0x3b, 0x3f, 0x1c, 0xad, 0x99, 0xa4, 0x13, 0x86, 0x68, 0x30, 0x42, 0x24, - 0x76, 0xc6, 0x38, 0xa3, 0x38, 0x24, 0x8c, 0xd3, 0xcc, 0x99, 0xba, 0x4e, 0x88, 0x63, 0xcc, 0x08, - 0xb3, 0x13, 0x0a, 0x1c, 0x74, 0x73, 0x23, 0x69, 0x6f, 0x24, 0xed, 0xa9, 0x6b, 0x6e, 0xa1, 0x88, - 0xc4, 0xe0, 0x88, 0xaf, 0x8c, 0x9b, 0x3b, 0x21, 0x84, 0x20, 0x9e, 0x4e, 0xfe, 0x5a, 0xfd, 0xdd, - 0x2f, 0xd1, 0x25, 0x88, 0xa2, 0x68, 0x65, 0x33, 0xdb, 0x65, 0xc1, 0x74, 0x30, 0x21, 0x81, 0x3f, - 0xc6, 0x99, 0x9f, 0x20, 0x42, 0xe5, 0x44, 0xe3, 0xb5, 0xa2, 0xfd, 0x3b, 0x95, 0x1b, 0x5f, 0x70, - 0xc4, 0xb1, 0x7e, 0xa2, 0x55, 0x25, 0xd2, 0x50, 0xeb, 0x6a, 0xb3, 0xd6, 0x69, 0xd8, 0x5f, 0x37, - 0xb0, 0x3d, 0x91, 0xec, 0xfe, 0x9d, 0x3d, 0xed, 0x29, 0xf7, 0x2f, 0x0f, 0x07, 0x6a, 0x6f, 0x35, - 0xac, 0xdf, 0x68, 0xdb, 0x29, 0xc3, 0xd4, 0x0f, 0x80, 0x45, 0xc0, 0x7c, 0x0e, 0x7e, 0x44, 0x62, - 0x64, 0xfc, 0xaa, 0x57, 0x9a, 0xb5, 0x4e, 0xab, 0x8c, 0x79, 0xc9, 0x30, 0xf5, 0xc4, 0xae, 0x67, - 0x38, 0xf3, 0x10, 0xa1, 0xbd, 0xff, 0x39, 0xe9, 0x58, 0x80, 0xfa, 0x70, 0x4e, 0x62, 0xb4, 0xa6, - 0xe7, 0xcc, 0x9c, 0x2d, 0x2d, 0x46, 0xe5, 0xdb, 0xf4, 0x9c, 0xda, 0x07, 0xe9, 0xd0, 0xc7, 0x9a, - 0x31, 0x45, 0x13, 0x32, 0x44, 0x1c, 0x3e, 0x15, 0xf8, 0x2d, 0x14, 0x9d, 0x32, 0xc5, 0xd5, 0xfb, - 0x6c, 0xd1, 0xb3, 0xbb, 0x66, 0x16, 0xaa, 0x14, 0x64, 0x1f, 0xfa, 0xfc, 0xf9, 0x01, 0xd9, 0x66, - 0xb3, 0xae, 0x37, 0x5b, 0x58, 0xea, 0x7c, 0x61, 0xa9, 0xcf, 0x0b, 0x4b, 0xbd, 0x5b, 0x5a, 0xca, - 0x7c, 0x69, 0x29, 0x8f, 0x4b, 0x4b, 0xb9, 0x3e, 0x0a, 0x09, 0x1f, 0xa5, 0x03, 0x3b, 0x80, 0xc8, - 0x89, 0x61, 0x88, 0xdd, 0xb6, 0xdb, 0x22, 0xe0, 0x48, 0x73, 0x4b, 0x1e, 0xd4, 0x6d, 0xe1, 0xa4, - 0x78, 0x96, 0x60, 0x36, 0xa8, 0x8a, 0x33, 0x3a, 0x7c, 0x0b, 0x00, 0x00, 0xff, 0xff, 0xd6, 0xfa, - 0x37, 0x9e, 0x12, 0x03, 0x00, 0x00, + // 325 bytes of a gzipped FileDescriptorProto + 0x1f, 0x8b, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0xff, 0xe2, 0xd2, 0x28, 0x28, 0xcd, 0x29, + 0x4e, 0x2c, 0x4a, 0xce, 0x48, 0xcc, 0xcc, 0xd3, 0xcf, 0x4e, 0xad, 0x2c, 0x4a, 0x4d, 0xcf, 0x2c, + 0x2e, 0x29, 0xaa, 0xd4, 0x2f, 0x33, 0xd4, 0x4f, 0x4f, 0xcd, 0x4b, 0x2d, 0xce, 0x2c, 0xd6, 0x2b, + 0x28, 0xca, 0x2f, 0xc9, 0x17, 0x92, 0x42, 0x52, 0xa9, 0x87, 0xa4, 0x52, 0xaf, 0xcc, 0x50, 0x4a, + 0x30, 0x31, 0x37, 0x33, 0x2f, 0x5f, 0x1f, 0x4c, 0x42, 0x94, 0x4b, 0x89, 0xa4, 0xe7, 0xa7, 0xe7, + 0x83, 0x99, 0xfa, 0x20, 0x16, 0x54, 0x54, 0x1d, 0x8f, 0x75, 0x05, 0x89, 0x45, 0x89, 0xb9, 0x50, + 0xdb, 0xa4, 0x0c, 0xf0, 0x29, 0x2c, 0x4d, 0xca, 0xc9, 0x4c, 0x8e, 0xcf, 0x4e, 0xad, 0x8c, 0x2f, + 0x48, 0xcc, 0x2c, 0x82, 0xe8, 0x50, 0xea, 0x63, 0xe2, 0xe2, 0x71, 0x87, 0xb8, 0x38, 0xb8, 0x24, + 0xb1, 0x24, 0x55, 0xc8, 0x95, 0x8b, 0x0d, 0x62, 0xa4, 0x04, 0xa3, 0x02, 0xa3, 0x06, 0xb7, 0x91, + 0x92, 0x1e, 0x6e, 0x1f, 0xe8, 0x05, 0x80, 0x55, 0x3a, 0x71, 0x9e, 0xb8, 0x27, 0xcf, 0xb0, 0xe2, + 0xf9, 0x06, 0x2d, 0xc6, 0x20, 0xa8, 0x66, 0xa1, 0x60, 0x2e, 0xbe, 0xd2, 0xe2, 0xd4, 0x22, 0xb8, + 0x75, 0xc5, 0x12, 0x4c, 0x0a, 0xcc, 0x1a, 0xdc, 0x46, 0xba, 0xf8, 0x8c, 0x0b, 0x2d, 0x4e, 0x2d, + 0x0a, 0x00, 0x3b, 0xd3, 0x3b, 0xb5, 0x32, 0x20, 0x31, 0xb3, 0x28, 0x88, 0x07, 0x64, 0x08, 0x94, + 0x53, 0x2c, 0x94, 0xc4, 0x25, 0x5c, 0x96, 0x98, 0x93, 0x99, 0x92, 0x58, 0x92, 0x8f, 0x6c, 0x32, + 0x33, 0xd8, 0x64, 0x23, 0x7c, 0x26, 0x87, 0xc1, 0xb4, 0xa1, 0x1a, 0x2f, 0x08, 0x37, 0x0e, 0x66, + 0x87, 0x53, 0xc0, 0x89, 0x47, 0x72, 0x8c, 0x17, 0x1e, 0xc9, 0x31, 0x3e, 0x78, 0x24, 0xc7, 0x38, + 0xe1, 0xb1, 0x1c, 0xc3, 0x85, 0xc7, 0x72, 0x0c, 0x37, 0x1e, 0xcb, 0x31, 0x44, 0x99, 0xa5, 0x67, + 0x96, 0x64, 0x94, 0x26, 0xe9, 0x25, 0xe7, 0xe7, 0xea, 0xe7, 0xe5, 0xa7, 0xa4, 0x1a, 0x1a, 0x18, + 0xea, 0x66, 0xe6, 0xeb, 0x43, 0x6c, 0xd5, 0x85, 0x84, 0x79, 0x05, 0x4a, 0xa8, 0x97, 0x54, 0x16, + 0xa4, 0x16, 0x27, 0xb1, 0x81, 0x43, 0xda, 0x18, 0x10, 0x00, 0x00, 0xff, 0xff, 0x8a, 0xf3, 0xc3, + 0xbd, 0x35, 0x02, 0x00, 0x00, } func (m *GenesisState) Marshal() (dAtA []byte, err error) { @@ -158,38 +139,10 @@ func (m *GenesisState) MarshalToSizedBuffer(dAtA []byte) (int, error) { _ = i var l int _ = l - if len(m.ValidatorMinaToCosmos) > 0 { - for iNdEx := len(m.ValidatorMinaToCosmos) - 1; iNdEx >= 0; iNdEx-- { - { - size, err := m.ValidatorMinaToCosmos[iNdEx].MarshalToSizedBuffer(dAtA[:i]) - if err != nil { - return 0, err - } - i -= size - i = encodeVarintGenesis(dAtA, i, uint64(size)) - } - i-- - dAtA[i] = 0x2a - } - } - if len(m.ValidatorCosmosToMina) > 0 { - for iNdEx := len(m.ValidatorCosmosToMina) - 1; iNdEx >= 0; iNdEx-- { - { - size, err := m.ValidatorCosmosToMina[iNdEx].MarshalToSizedBuffer(dAtA[:i]) - if err != nil { - return 0, err - } - i -= size - i = encodeVarintGenesis(dAtA, i, uint64(size)) - } - i-- - dAtA[i] = 0x22 - } - } - if len(m.UserMinaToCosmos) > 0 { - for iNdEx := len(m.UserMinaToCosmos) - 1; iNdEx >= 0; iNdEx-- { + if len(m.ValidatorKeyPairs) > 0 { + for iNdEx := len(m.ValidatorKeyPairs) - 1; iNdEx >= 0; iNdEx-- { { - size, err := m.UserMinaToCosmos[iNdEx].MarshalToSizedBuffer(dAtA[:i]) + size, err := m.ValidatorKeyPairs[iNdEx].MarshalToSizedBuffer(dAtA[:i]) if err != nil { return 0, err } @@ -200,10 +153,10 @@ func (m *GenesisState) MarshalToSizedBuffer(dAtA []byte) (int, error) { dAtA[i] = 0x1a } } - if len(m.UserCosmosToMina) > 0 { - for iNdEx := len(m.UserCosmosToMina) - 1; iNdEx >= 0; iNdEx-- { + if len(m.UserKeyPairs) > 0 { + for iNdEx := len(m.UserKeyPairs) - 1; iNdEx >= 0; iNdEx-- { { - size, err := m.UserCosmosToMina[iNdEx].MarshalToSizedBuffer(dAtA[:i]) + size, err := m.UserKeyPairs[iNdEx].MarshalToSizedBuffer(dAtA[:i]) if err != nil { return 0, err } @@ -246,26 +199,14 @@ func (m *GenesisState) Size() (n int) { _ = l l = m.Params.Size() n += 1 + l + sovGenesis(uint64(l)) - if len(m.UserCosmosToMina) > 0 { - for _, e := range m.UserCosmosToMina { - l = e.Size() - n += 1 + l + sovGenesis(uint64(l)) - } - } - if len(m.UserMinaToCosmos) > 0 { - for _, e := range m.UserMinaToCosmos { - l = e.Size() - n += 1 + l + sovGenesis(uint64(l)) - } - } - if len(m.ValidatorCosmosToMina) > 0 { - for _, e := range m.ValidatorCosmosToMina { + if len(m.UserKeyPairs) > 0 { + for _, e := range m.UserKeyPairs { l = e.Size() n += 1 + l + sovGenesis(uint64(l)) } } - if len(m.ValidatorMinaToCosmos) > 0 { - for _, e := range m.ValidatorMinaToCosmos { + if len(m.ValidatorKeyPairs) > 0 { + for _, e := range m.ValidatorKeyPairs { l = e.Size() n += 1 + l + sovGenesis(uint64(l)) } @@ -343,7 +284,7 @@ func (m *GenesisState) Unmarshal(dAtA []byte) error { iNdEx = postIndex case 2: if wireType != 2 { - return fmt.Errorf("proto: wrong wireType = %d for field UserCosmosToMina", wireType) + return fmt.Errorf("proto: wrong wireType = %d for field UserKeyPairs", wireType) } var msglen int for shift := uint(0); ; shift += 7 { @@ -370,82 +311,14 @@ func (m *GenesisState) Unmarshal(dAtA []byte) error { if postIndex > l { return io.ErrUnexpectedEOF } - m.UserCosmosToMina = append(m.UserCosmosToMina, &UserPublicKeyPair{}) - if err := m.UserCosmosToMina[len(m.UserCosmosToMina)-1].Unmarshal(dAtA[iNdEx:postIndex]); err != nil { + m.UserKeyPairs = append(m.UserKeyPairs, &UserPublicKeyPair{}) + if err := m.UserKeyPairs[len(m.UserKeyPairs)-1].Unmarshal(dAtA[iNdEx:postIndex]); err != nil { return err } iNdEx = postIndex case 3: if wireType != 2 { - return fmt.Errorf("proto: wrong wireType = %d for field UserMinaToCosmos", wireType) - } - var msglen int - for shift := uint(0); ; shift += 7 { - if shift >= 64 { - return ErrIntOverflowGenesis - } - if iNdEx >= l { - return io.ErrUnexpectedEOF - } - b := dAtA[iNdEx] - iNdEx++ - msglen |= int(b&0x7F) << shift - if b < 0x80 { - break - } - } - if msglen < 0 { - return ErrInvalidLengthGenesis - } - postIndex := iNdEx + msglen - if postIndex < 0 { - return ErrInvalidLengthGenesis - } - if postIndex > l { - return io.ErrUnexpectedEOF - } - m.UserMinaToCosmos = append(m.UserMinaToCosmos, &UserPublicKeyPair{}) - if err := m.UserMinaToCosmos[len(m.UserMinaToCosmos)-1].Unmarshal(dAtA[iNdEx:postIndex]); err != nil { - return err - } - iNdEx = postIndex - case 4: - if wireType != 2 { - return fmt.Errorf("proto: wrong wireType = %d for field ValidatorCosmosToMina", wireType) - } - var msglen int - for shift := uint(0); ; shift += 7 { - if shift >= 64 { - return ErrIntOverflowGenesis - } - if iNdEx >= l { - return io.ErrUnexpectedEOF - } - b := dAtA[iNdEx] - iNdEx++ - msglen |= int(b&0x7F) << shift - if b < 0x80 { - break - } - } - if msglen < 0 { - return ErrInvalidLengthGenesis - } - postIndex := iNdEx + msglen - if postIndex < 0 { - return ErrInvalidLengthGenesis - } - if postIndex > l { - return io.ErrUnexpectedEOF - } - m.ValidatorCosmosToMina = append(m.ValidatorCosmosToMina, &ValidatorPublicKeyPair{}) - if err := m.ValidatorCosmosToMina[len(m.ValidatorCosmosToMina)-1].Unmarshal(dAtA[iNdEx:postIndex]); err != nil { - return err - } - iNdEx = postIndex - case 5: - if wireType != 2 { - return fmt.Errorf("proto: wrong wireType = %d for field ValidatorMinaToCosmos", wireType) + return fmt.Errorf("proto: wrong wireType = %d for field ValidatorKeyPairs", wireType) } var msglen int for shift := uint(0); ; shift += 7 { @@ -472,8 +345,8 @@ func (m *GenesisState) Unmarshal(dAtA []byte) error { if postIndex > l { return io.ErrUnexpectedEOF } - m.ValidatorMinaToCosmos = append(m.ValidatorMinaToCosmos, &ValidatorPublicKeyPair{}) - if err := m.ValidatorMinaToCosmos[len(m.ValidatorMinaToCosmos)-1].Unmarshal(dAtA[iNdEx:postIndex]); err != nil { + m.ValidatorKeyPairs = append(m.ValidatorKeyPairs, &ValidatorPublicKeyPair{}) + if err := m.ValidatorKeyPairs[len(m.ValidatorKeyPairs)-1].Unmarshal(dAtA[iNdEx:postIndex]); err != nil { return err } iNdEx = postIndex diff --git a/x/keyregistry/types/genesis_test.go b/x/keyregistry/types/genesis_test.go index f963da22..14ec6918 100644 --- a/x/keyregistry/types/genesis_test.go +++ b/x/keyregistry/types/genesis_test.go @@ -1,6 +1,7 @@ package types_test import ( + "bytes" "testing" "github.com/node101-io/pulsar-chain/x/keyregistry/types" @@ -8,30 +9,148 @@ import ( ) func TestGenesisState_Validate(t *testing.T) { + userCosmosA := testBytes(33, 'a') + userCosmosB := testBytes(33, 'b') + userMinaX := testBytes(33, 'x') + userMinaY := testBytes(33, 'y') + validatorConsensusA := testBytes(32, 'a') + validatorConsensusB := testBytes(32, 'b') + validatorMinaX := testBytes(33, 'x') + validatorMinaY := testBytes(33, 'y') + tests := []struct { - desc string - genState *types.GenesisState - valid bool + desc string + genState *types.GenesisState + expectedErr error }{ { - desc: "default is valid", - genState: types.DefaultGenesis(), - valid: true, + desc: "default genesis is valid", + genState: withDefaultParams(types.DefaultGenesis()), + }, + { + desc: "empty genesis is valid", + genState: withDefaultParams(&types.GenesisState{}), + }, + { + desc: "valid user key pairs are valid", + genState: withDefaultParams(&types.GenesisState{ + UserKeyPairs: []*types.UserPublicKeyPair{ + userPair(userCosmosA, userMinaX), + }, + }), + }, + { + desc: "valid validator key pairs are valid", + genState: withDefaultParams(&types.GenesisState{ + ValidatorKeyPairs: []*types.ValidatorPublicKeyPair{ + validatorPair(validatorConsensusA, validatorMinaX), + }, + }), + }, + { + desc: "nil user key pair is invalid", + genState: withDefaultParams(&types.GenesisState{ + UserKeyPairs: []*types.UserPublicKeyPair{nil}, + }), + expectedErr: types.ErrNilKeyPair, + }, + { + desc: "nil validator key pair is invalid", + genState: withDefaultParams(&types.GenesisState{ + ValidatorKeyPairs: []*types.ValidatorPublicKeyPair{nil}, + }), + expectedErr: types.ErrNilKeyPair, + }, + { + desc: "invalid user key length is invalid", + genState: withDefaultParams(&types.GenesisState{ + UserKeyPairs: []*types.UserPublicKeyPair{ + userPair(testBytes(32, 'a'), userMinaX), + }, + }), + expectedErr: types.ErrInvalidPublicKey, + }, + { + desc: "invalid validator key length is invalid", + genState: withDefaultParams(&types.GenesisState{ + ValidatorKeyPairs: []*types.ValidatorPublicKeyPair{ + validatorPair(testBytes(33, 'a'), validatorMinaX), + }, + }), + expectedErr: types.ErrInvalidPublicKey, }, { - desc: "valid genesis state", - genState: &types.GenesisState{}, - valid: true, + desc: "duplicate user cosmos key is invalid", + genState: withDefaultParams(&types.GenesisState{ + UserKeyPairs: []*types.UserPublicKeyPair{ + userPair(userCosmosA, userMinaX), + userPair(userCosmosA, userMinaY), + }, + }), + expectedErr: types.ErrInvalidGenesisState, + }, + { + desc: "duplicate user mina key is invalid", + genState: withDefaultParams(&types.GenesisState{ + UserKeyPairs: []*types.UserPublicKeyPair{ + userPair(userCosmosA, userMinaX), + userPair(userCosmosB, userMinaX), + }, + }), + expectedErr: types.ErrInvalidGenesisState, + }, + { + desc: "duplicate validator consensus key is invalid", + genState: withDefaultParams(&types.GenesisState{ + ValidatorKeyPairs: []*types.ValidatorPublicKeyPair{ + validatorPair(validatorConsensusA, validatorMinaX), + validatorPair(validatorConsensusA, validatorMinaY), + }, + }), + expectedErr: types.ErrInvalidGenesisState, + }, + { + desc: "duplicate validator mina key is invalid", + genState: withDefaultParams(&types.GenesisState{ + ValidatorKeyPairs: []*types.ValidatorPublicKeyPair{ + validatorPair(validatorConsensusA, validatorMinaX), + validatorPair(validatorConsensusB, validatorMinaX), + }, + }), + expectedErr: types.ErrInvalidGenesisState, }, } for _, tc := range tests { t.Run(tc.desc, func(t *testing.T) { err := tc.genState.Validate() - if tc.valid { + if tc.expectedErr == nil { require.NoError(t, err) } else { - require.Error(t, err) + require.ErrorIs(t, err, tc.expectedErr) } }) } } + +func testBytes(length int, value byte) []byte { + return bytes.Repeat([]byte{value}, length) +} + +func withDefaultParams(genState *types.GenesisState) *types.GenesisState { + genState.Params = types.DefaultParams() + return genState +} + +func userPair(cosmosKey, minaKey []byte) *types.UserPublicKeyPair { + return &types.UserPublicKeyPair{ + CosmosKey: cosmosKey, + MinaKey: minaKey, + } +} + +func validatorPair(consensusKey, minaKey []byte) *types.ValidatorPublicKeyPair { + return &types.ValidatorPublicKeyPair{ + CosmosKey: consensusKey, + MinaKey: minaKey, + } +} From 2c3fa6b9c65cecae0fb8c4282a9b4957da31393f Mon Sep 17 00:00:00 2001 From: korayakpinar Date: Mon, 27 Apr 2026 19:47:40 +0300 Subject: [PATCH 22/62] feat(keyregistry): simulate key registration and updates --- x/keyregistry/module/simulation.go | 4 +- x/keyregistry/simulation/helpers.go | 298 ++++++++++++++++++++ x/keyregistry/simulation/operations_test.go | 139 +++++++++ x/keyregistry/simulation/register_keys.go | 17 +- x/keyregistry/simulation/update_keys.go | 17 +- 5 files changed, 463 insertions(+), 12 deletions(-) create mode 100644 x/keyregistry/simulation/helpers.go create mode 100644 x/keyregistry/simulation/operations_test.go diff --git a/x/keyregistry/module/simulation.go b/x/keyregistry/module/simulation.go index 7c327cda..2748287d 100644 --- a/x/keyregistry/module/simulation.go +++ b/x/keyregistry/module/simulation.go @@ -30,7 +30,7 @@ func (am AppModule) RegisterStoreDecoder(_ simtypes.StoreDecoderRegistry) {} func (am AppModule) WeightedOperations(simState module.SimulationState) []simtypes.WeightedOperation { operations := make([]simtypes.WeightedOperation, 0) const ( - opWeightMsgRegisterKeys = "op_weight_msg_keyregistry" + opWeightMsgRegisterKeys = "op_weight_msg_keyregistry_register_keys" defaultWeightMsgRegisterKeys int = 100 ) @@ -45,7 +45,7 @@ func (am AppModule) WeightedOperations(simState module.SimulationState) []simtyp keyregistrysimulation.SimulateMsgRegisterKeys(am.authKeeper, am.bankKeeper, am.keeper, simState.TxConfig), )) const ( - opWeightMsgUpdateKeys = "op_weight_msg_keyregistry" + opWeightMsgUpdateKeys = "op_weight_msg_keyregistry_update_keys" defaultWeightMsgUpdateKeys int = 100 ) diff --git a/x/keyregistry/simulation/helpers.go b/x/keyregistry/simulation/helpers.go new file mode 100644 index 00000000..a6589466 --- /dev/null +++ b/x/keyregistry/simulation/helpers.go @@ -0,0 +1,298 @@ +package simulation + +import ( + "context" + "math/rand" + + "github.com/cosmos/cosmos-sdk/baseapp" + "github.com/cosmos/cosmos-sdk/client" + sdk "github.com/cosmos/cosmos-sdk/types" + simtypes "github.com/cosmos/cosmos-sdk/types/simulation" + simutil "github.com/cosmos/cosmos-sdk/x/simulation" + "github.com/node101-io/mina-signer-go/keys" + "github.com/node101-io/pulsar-chain/x/keyregistry/keeper" + "github.com/node101-io/pulsar-chain/x/keyregistry/types" +) + +const maxUniqueMinaKeyRetries = 20 + +type registeredUserPair struct { + pair *types.UserPublicKeyPair + account simtypes.Account +} + +func randomActorType(r *rand.Rand) types.ActorType { + if r.Intn(2) == 0 { + return types.ActorType_USER + } + + return types.ActorType_VALIDATOR +} + +func randomBytes(r *rand.Rand, size int) []byte { + bytes := make([]byte, size) + if _, err := r.Read(bytes); err != nil { + panic(err) + } + + return bytes +} + +func randomMinaPublicKey(r *rand.Rand) []byte { + // TODO: Generate a real Mina public key once the crypto library is integrated. + return randomBytes(r, keys.PublicKeyTotalByteSize) +} + +func mockSimulationSignature() []byte { + // TODO: Generate deterministic valid signatures once real crypto verification is integrated. + return []byte("mock-keyregistry-signature") +} + +func randomUniqueMinaPublicKey( + r *rand.Rand, + ctx context.Context, + hasMinaKey func(context.Context, []byte) (bool, error), +) ([]byte, bool, error) { + for i := 0; i < maxUniqueMinaKeyRetries; i++ { + minaPublicKey := randomMinaPublicKey(r) + exists, err := hasMinaKey(ctx, minaPublicKey) + if err != nil { + return nil, false, err + } + if !exists { + return minaPublicKey, true, nil + } + } + + return nil, false, nil +} + +func deliverKeyregistryTx( + r *rand.Rand, + app *baseapp.BaseApp, + txGen client.TxConfig, + ak types.AuthKeeper, + bk types.BankKeeper, + msg sdk.Msg, + ctx sdk.Context, + simAccount simtypes.Account, +) (simtypes.OperationMsg, []simtypes.FutureOperation, error) { + if ak.GetAccount(ctx, simAccount.Address) == nil { + return simtypes.NoOpMsg(types.ModuleName, sdk.MsgTypeURL(msg), "account not found"), nil, nil + } + + return simutil.GenAndDeliverTxWithRandFees(simutil.OperationInput{ + R: r, + App: app, + TxGen: txGen, + Msg: msg, + CoinsSpentInMsg: sdk.Coins{}, + Context: ctx, + SimAccount: simAccount, + AccountKeeper: ak, + Bankkeeper: bk, + ModuleName: types.ModuleName, + }) +} + +func buildRegisterKeysMsg( + r *rand.Rand, + ctx context.Context, + k keeper.Keeper, + actorType types.ActorType, + simAccount simtypes.Account, +) (*types.MsgRegisterKeys, string, error) { + cosmosPublicKey, noOpReason := cosmosPublicKeyForActor(actorType, simAccount) + if noOpReason != "" { + return nil, noOpReason, nil + } + + cosmosKeyExists, err := actorCosmosKeyExists(ctx, k, actorType, cosmosPublicKey) + if err != nil { + return nil, "", err + } + if cosmosKeyExists { + return nil, "cosmos public key already registered", nil + } + + minaPublicKey, ok, err := randomUniqueMinaPublicKey(r, ctx, actorMinaKeyExistsFunc(k, actorType)) + if err != nil { + return nil, "", err + } + if !ok { + return nil, "unable to generate unique mina public key", nil + } + + return &types.MsgRegisterKeys{ + Creator: simAccount.Address.String(), + CosmosPublicKey: cosmosPublicKey, + MinaPublicKey: minaPublicKey, + CosmosSignature: mockSimulationSignature(), + MinaSignature: mockSimulationSignature(), + ActorType: actorType, + }, "", nil +} + +func buildUpdateKeysMsg( + r *rand.Rand, + ctx context.Context, + k keeper.Keeper, + actorType types.ActorType, + genesis *types.GenesisState, + accs []simtypes.Account, +) (*types.MsgUpdateKeys, simtypes.Account, string, error) { + var ( + simAccount simtypes.Account + prevMinaPublicKey []byte + noOpReason string + ) + + switch actorType { + case types.ActorType_USER: + userPair, ok := selectRegisteredUserPairWithSigner(r, genesis.UserKeyPairs, accs) + if !ok { + return nil, simtypes.Account{}, "no registered user key pair with simulation signer", nil + } + simAccount = userPair.account + prevMinaPublicKey = userPair.pair.MinaKey + case types.ActorType_VALIDATOR: + validatorPair, ok := selectRegisteredValidatorPair(r, genesis.ValidatorKeyPairs) + if !ok { + return nil, simtypes.Account{}, "no registered validator key pair", nil + } + simAccount, noOpReason = randomSimulationAccount(r, accs) + if noOpReason != "" { + return nil, simtypes.Account{}, noOpReason, nil + } + prevMinaPublicKey = validatorPair.MinaKey + default: + return nil, simtypes.Account{}, "invalid actor type", nil + } + + newMinaPublicKey, ok, err := randomUniqueMinaPublicKey(r, ctx, actorMinaKeyExistsFunc(k, actorType)) + if err != nil { + return nil, simtypes.Account{}, "", err + } + if !ok { + return nil, simtypes.Account{}, "unable to generate unique mina public key", nil + } + + return &types.MsgUpdateKeys{ + Creator: simAccount.Address.String(), + PrevMinaPublicKey: prevMinaPublicKey, + NewMinaPublicKey: newMinaPublicKey, + CosmosSignature: mockSimulationSignature(), + NewMinaSignature: mockSimulationSignature(), + ActorType: actorType, + }, simAccount, "", nil +} + +func cosmosPublicKeyForActor(actorType types.ActorType, simAccount simtypes.Account) ([]byte, string) { + switch actorType { + case types.ActorType_USER: + if simAccount.PubKey == nil { + return nil, "simulation account has no user public key" + } + + return simAccount.PubKey.Bytes(), "" + case types.ActorType_VALIDATOR: + if simAccount.ConsKey == nil { + return nil, "simulation account has no validator consensus key" + } + + return simAccount.ConsKey.PubKey().Bytes(), "" + default: + return nil, "invalid actor type" + } +} + +func actorCosmosKeyExists(ctx context.Context, k keeper.Keeper, actorType types.ActorType, cosmosPublicKey []byte) (bool, error) { + switch actorType { + case types.ActorType_USER: + return k.UserCosmosToMinaHas(ctx, cosmosPublicKey) + case types.ActorType_VALIDATOR: + return k.ValidatorCosmosToMinaHas(ctx, cosmosPublicKey) + default: + return false, types.ErrInvalidActorType + } +} + +func actorMinaKeyExistsFunc( + k keeper.Keeper, + actorType types.ActorType, +) func(context.Context, []byte) (bool, error) { + switch actorType { + case types.ActorType_USER: + return k.UserMinaToCosmosHas + case types.ActorType_VALIDATOR: + return k.ValidatorMinaToCosmosHas + default: + return func(context.Context, []byte) (bool, error) { + return false, types.ErrInvalidActorType + } + } +} + +func randomSimulationAccount(r *rand.Rand, accs []simtypes.Account) (simtypes.Account, string) { + if len(accs) == 0 { + return simtypes.Account{}, "no simulation accounts" + } + + simAccount, _ := simtypes.RandomAcc(r, accs) + return simAccount, "" +} + +func selectRegisteredUserPairWithSigner( + r *rand.Rand, + userKeyPairs []*types.UserPublicKeyPair, + accs []simtypes.Account, +) (registeredUserPair, bool) { + accountByPublicKey := make(map[string]simtypes.Account, len(accs)) + for _, account := range accs { + if account.PubKey == nil { + continue + } + accountByPublicKey[string(account.PubKey.Bytes())] = account + } + + var candidates []registeredUserPair + for _, keyPair := range userKeyPairs { + if keyPair == nil { + continue + } + account, ok := accountByPublicKey[string(keyPair.CosmosKey)] + if !ok { + continue + } + + candidates = append(candidates, registeredUserPair{ + pair: keyPair, + account: account, + }) + } + + if len(candidates) == 0 { + return registeredUserPair{}, false + } + + return candidates[r.Intn(len(candidates))], true +} + +func selectRegisteredValidatorPair( + r *rand.Rand, + validatorKeyPairs []*types.ValidatorPublicKeyPair, +) (*types.ValidatorPublicKeyPair, bool) { + var candidates []*types.ValidatorPublicKeyPair + for _, keyPair := range validatorKeyPairs { + if keyPair == nil { + continue + } + candidates = append(candidates, keyPair) + } + + if len(candidates) == 0 { + return nil, false + } + + return candidates[r.Intn(len(candidates))], true +} diff --git a/x/keyregistry/simulation/operations_test.go b/x/keyregistry/simulation/operations_test.go new file mode 100644 index 00000000..aa84c551 --- /dev/null +++ b/x/keyregistry/simulation/operations_test.go @@ -0,0 +1,139 @@ +package simulation + +import ( + "context" + "math/rand" + "testing" + + storetypes "cosmossdk.io/store/types" + "github.com/cosmos/cosmos-sdk/codec" + addresscodec "github.com/cosmos/cosmos-sdk/codec/address" + codectypes "github.com/cosmos/cosmos-sdk/codec/types" + "github.com/cosmos/cosmos-sdk/runtime" + "github.com/cosmos/cosmos-sdk/testutil" + sdk "github.com/cosmos/cosmos-sdk/types" + simtypes "github.com/cosmos/cosmos-sdk/types/simulation" + authtypes "github.com/cosmos/cosmos-sdk/x/auth/types" + "github.com/node101-io/mina-signer-go/keys" + "github.com/node101-io/pulsar-chain/x/keyregistry/keeper" + "github.com/node101-io/pulsar-chain/x/keyregistry/types" + "github.com/stretchr/testify/require" +) + +func TestRandomMinaPublicKeyLength(t *testing.T) { + r := rand.New(rand.NewSource(1)) + + minaPublicKey := randomMinaPublicKey(r) + + require.Len(t, minaPublicKey, keys.PublicKeyTotalByteSize) +} + +func TestBuildRegisterKeysMsgUsesUserSimulationAccountPublicKey(t *testing.T) { + r := rand.New(rand.NewSource(1)) + ctx, k := initSimulationKeeperFixture(t) + simAccount := simtypes.RandomAccounts(r, 1)[0] + + msg, noOpReason, err := buildRegisterKeysMsg(r, ctx, k, types.ActorType_USER, simAccount) + + require.NoError(t, err) + require.Empty(t, noOpReason) + require.Equal(t, simAccount.Address.String(), msg.Creator) + require.Equal(t, types.ActorType_USER, msg.ActorType) + require.Equal(t, simAccount.PubKey.Bytes(), msg.CosmosPublicKey) + require.Len(t, msg.MinaPublicKey, keys.PublicKeyTotalByteSize) + require.NotEmpty(t, msg.CosmosSignature) + require.NotEmpty(t, msg.MinaSignature) +} + +func TestBuildRegisterKeysMsgUsesValidatorConsensusPublicKey(t *testing.T) { + r := rand.New(rand.NewSource(1)) + ctx, k := initSimulationKeeperFixture(t) + simAccount := simtypes.RandomAccounts(r, 1)[0] + + msg, noOpReason, err := buildRegisterKeysMsg(r, ctx, k, types.ActorType_VALIDATOR, simAccount) + + require.NoError(t, err) + require.Empty(t, noOpReason) + require.Equal(t, simAccount.Address.String(), msg.Creator) + require.Equal(t, types.ActorType_VALIDATOR, msg.ActorType) + require.Equal(t, simAccount.ConsKey.PubKey().Bytes(), msg.CosmosPublicKey) + require.Len(t, msg.CosmosPublicKey, 32) + require.Len(t, msg.MinaPublicKey, keys.PublicKeyTotalByteSize) + require.NotEmpty(t, msg.CosmosSignature) + require.NotEmpty(t, msg.MinaSignature) +} + +func TestSelectRegisteredUserPairWithSigner(t *testing.T) { + r := rand.New(rand.NewSource(1)) + accs := simtypes.RandomAccounts(r, 2) + matchingPair := &types.UserPublicKeyPair{ + CosmosKey: accs[0].PubKey.Bytes(), + MinaKey: randomMinaPublicKey(r), + } + unmatchedPair := &types.UserPublicKeyPair{ + CosmosKey: randomBytes(r, 33), + MinaKey: randomMinaPublicKey(r), + } + + selected, ok := selectRegisteredUserPairWithSigner(r, []*types.UserPublicKeyPair{ + unmatchedPair, + matchingPair, + }, accs) + + require.True(t, ok) + require.Equal(t, matchingPair, selected.pair) + require.True(t, selected.account.Address.Equals(accs[0].Address)) +} + +func TestRandomUniqueMinaPublicKeyRetriesDuplicate(t *testing.T) { + r := rand.New(rand.NewSource(1)) + calls := 0 + + minaPublicKey, ok, err := randomUniqueMinaPublicKey(r, context.Background(), func(context.Context, []byte) (bool, error) { + calls++ + return calls == 1, nil + }) + + require.NoError(t, err) + require.True(t, ok) + require.Equal(t, 2, calls) + require.Len(t, minaPublicKey, keys.PublicKeyTotalByteSize) +} + +func TestRandomUniqueMinaPublicKeyStopsAfterRetries(t *testing.T) { + r := rand.New(rand.NewSource(1)) + calls := 0 + + minaPublicKey, ok, err := randomUniqueMinaPublicKey(r, context.Background(), func(context.Context, []byte) (bool, error) { + calls++ + return true, nil + }) + + require.NoError(t, err) + require.False(t, ok) + require.Nil(t, minaPublicKey) + require.Equal(t, maxUniqueMinaKeyRetries, calls) +} + +func initSimulationKeeperFixture(t *testing.T) (context.Context, keeper.Keeper) { + t.Helper() + + addressCodec := addresscodec.NewBech32Codec(sdk.GetConfig().GetBech32AccountAddrPrefix()) + storeKey := storetypes.NewKVStoreKey(types.StoreKey) + storeService := runtime.NewKVStoreService(storeKey) + ctx := testutil.DefaultContextWithDB(t, storeKey, storetypes.NewTransientStoreKey("transient_test")).Ctx + authority := authtypes.NewModuleAddress(types.GovModuleName) + cdc := codec.NewProtoCodec(codectypes.NewInterfaceRegistry()) + + k := keeper.NewKeeper( + storeService, + cdc, + addressCodec, + authority, + ) + + err := k.Params.Set(ctx, types.DefaultParams()) + require.NoError(t, err) + + return ctx, k +} diff --git a/x/keyregistry/simulation/register_keys.go b/x/keyregistry/simulation/register_keys.go index 49593095..764bde1a 100644 --- a/x/keyregistry/simulation/register_keys.go +++ b/x/keyregistry/simulation/register_keys.go @@ -20,13 +20,20 @@ func SimulateMsgRegisterKeys( ) simtypes.Operation { return func(r *rand.Rand, app *baseapp.BaseApp, ctx sdk.Context, accs []simtypes.Account, chainID string, ) (simtypes.OperationMsg, []simtypes.FutureOperation, error) { - simAccount, _ := simtypes.RandomAcc(r, accs) - msg := &types.MsgRegisterKeys{ - Creator: simAccount.Address.String(), + msgType := sdk.MsgTypeURL(&types.MsgRegisterKeys{}) + simAccount, noOpReason := randomSimulationAccount(r, accs) + if noOpReason != "" { + return simtypes.NoOpMsg(types.ModuleName, msgType, noOpReason), nil, nil } - // TODO: Handle the RegisterKeys simulation + msg, noOpReason, err := buildRegisterKeysMsg(r, ctx, k, randomActorType(r), simAccount) + if err != nil { + return simtypes.NoOpMsg(types.ModuleName, msgType, "unable to build RegisterKeys msg"), nil, err + } + if noOpReason != "" { + return simtypes.NoOpMsg(types.ModuleName, msgType, noOpReason), nil, nil + } - return simtypes.NoOpMsg(types.ModuleName, sdk.MsgTypeURL(msg), "RegisterKeys simulation not implemented"), nil, nil + return deliverKeyregistryTx(r, app, txGen, ak, bk, msg, ctx, simAccount) } } diff --git a/x/keyregistry/simulation/update_keys.go b/x/keyregistry/simulation/update_keys.go index bb4d0608..8804e087 100644 --- a/x/keyregistry/simulation/update_keys.go +++ b/x/keyregistry/simulation/update_keys.go @@ -20,13 +20,20 @@ func SimulateMsgUpdateKeys( ) simtypes.Operation { return func(r *rand.Rand, app *baseapp.BaseApp, ctx sdk.Context, accs []simtypes.Account, chainID string, ) (simtypes.OperationMsg, []simtypes.FutureOperation, error) { - simAccount, _ := simtypes.RandomAcc(r, accs) - msg := &types.MsgUpdateKeys{ - Creator: simAccount.Address.String(), + msgType := sdk.MsgTypeURL(&types.MsgUpdateKeys{}) + genesis, err := k.ExportGenesis(ctx) + if err != nil { + return simtypes.NoOpMsg(types.ModuleName, msgType, "unable to export keyregistry genesis"), nil, err } - // TODO: Handle the UpdateKeys simulation + msg, simAccount, noOpReason, err := buildUpdateKeysMsg(r, ctx, k, randomActorType(r), genesis, accs) + if err != nil { + return simtypes.NoOpMsg(types.ModuleName, msgType, "unable to build UpdateKeys msg"), nil, err + } + if noOpReason != "" { + return simtypes.NoOpMsg(types.ModuleName, msgType, noOpReason), nil, nil + } - return simtypes.NoOpMsg(types.ModuleName, sdk.MsgTypeURL(msg), "UpdateKeys simulation not implemented"), nil, nil + return deliverKeyregistryTx(r, app, txGen, ak, bk, msg, ctx, simAccount) } } From 3354f10ff1de8eb4715c9f3deb3c6e686ca6c39c Mon Sep 17 00:00:00 2001 From: Yusuf Date: Fri, 1 May 2026 22:21:33 +0300 Subject: [PATCH 23/62] f --- abci/extend_vote.go | 134 +++++++++++++++++++++++++++++++++++++++ abci/helpers.go | 32 ++++++++++ config.yml | 10 +-- docs/static/openapi.json | 2 +- 4 files changed, 172 insertions(+), 6 deletions(-) create mode 100644 abci/extend_vote.go create mode 100644 abci/helpers.go diff --git a/abci/extend_vote.go b/abci/extend_vote.go new file mode 100644 index 00000000..04898e10 --- /dev/null +++ b/abci/extend_vote.go @@ -0,0 +1,134 @@ +package vote_ext + +import ( + "math/big" + + abci "github.com/cometbft/cometbft/abci/types" + sdk "github.com/cosmos/cosmos-sdk/types" + stakingkeeper "github.com/cosmos/cosmos-sdk/x/staking/keeper" + "github.com/node101-io/mina-signer-go/constants" + "github.com/node101-io/mina-signer-go/field" + "github.com/node101-io/mina-signer-go/keys" + "github.com/node101-io/mina-signer-go/poseidon" +) + +const ActionsReducedRoot string = "pulsar" + +type validatorInfo struct { + ConsensusAddr []byte + Power int64 +} + +func MockSign(voteExtBody VoteExtensionBody) []byte { + return []byte{} +} + +func (h *AbciHandler) getValidatorSet(ctx sdk.Context, currentBlockHeight int64) ([]validatorInfo, error) { + + historicalData, err := h.stakingKeeper.GetHistoricalInfo(ctx, currentBlockHeight) + if err != nil { + return nil, err + } + + validatorSet := historicalData.Valset + + var valInfo []validatorInfo + + for _, validator := range validatorSet { + + consAddr, err := validator.GetConsAddr() + if err != nil { + return nil, err + } + + consPower := validator.ConsensusPower(sdk.DefaultPowerReduction) + + valInfo = append(valInfo, validatorInfo{ + ConsensusAddr: consAddr, + Power: consPower, + }) + } + return valInfo, nil +} + +func (h *AbciHandler) calculateValidatorSetRoot(ctx sdk.Context, valInfo []validatorInfo, poseidonHash *poseidon.Poseidon) (*big.Int, error) { + + input := []*big.Int{big.NewInt(0)} + merkleRoot := poseidonHash.Hash(input) + + for _, validator := range valInfo { + input = []*big.Int{} + + minaPubKeyExists, err := h.keyregistryKeeper.ValidatorCosmosToMinaHas(ctx, validator.ConsensusAddr) + if err != nil { + return nil, err + } + if !minaPubKeyExists { + return nil, err + } + + minaPubKey, err := h.keyregistryKeeper.ValidatorGetCosmosToMina(ctx, validator.ConsensusAddr) + if err != nil { + return nil, err + } + + MinaPublicKey, err := keys.PublicKey{}.FromAddress(string(minaPubKey)) + if err != nil { + return nil, err + } + + input = append(input, MinaPublicKey.X) + if MinaPublicKey.IsOdd { + input = append(input, big.NewInt(1)) + } else { + input = append(input, big.NewInt(0)) + } + power := new(big.Int).SetInt64(validator.Power) + input = append(input, power) + + hashOfAddr := poseidonHash.Hash(input) + + input = []*big.Int{merkleRoot, hashOfAddr} + + merkleRoot = poseidonHash.Hash(input) + } + + return merkleRoot, nil + +} + +func (h *AbciHandler) ExtendVoteHandler() sdk.ExtendVoteHandler { + return func(ctx sdk.Context, req *abci.RequestExtendVote) (*abci.ResponseExtendVote, error) { + if req.GetHeight() < 3 { + return &abci.ResponseExtendVote{VoteExtension: []byte{}}, nil + } + + twoBlocksBefore, err := stakingkeeper.Keeper.GetHistoricalInfo(h.stakingKeeper, ctx, req.GetHeight()-2) + if err != nil { + return &abci.ResponseExtendVote{VoteExtension: []byte{}}, err + } + + nextBlockHeight := req.GetHeight() - 1 + + poseidonHash := poseidon.CreatePoseidon(*field.Fp, constants.PoseidonParamsKimchiFp) + + nextValSet, err := h.getValidatorSet(ctx, nextBlockHeight) + if err != nil { + return nil, err + } + nextValidatorSetHash, err := h.calculateValidatorSetRoot(ctx, nextValSet, poseidonHash) + if err != nil { + return nil, err + } + + body := VoteExtensionBody{ + NextBlockHeight: nextBlockHeight, + CurrentStateRoot: twoBlocksBefore.Header.AppHash, + NextValidatorSetHash: nextValidatorSetHash.Bytes(), + } + + bz := MockSign(body) + + return &abci.ResponseExtendVote{VoteExtension: bz}, nil + } +} diff --git a/abci/helpers.go b/abci/helpers.go new file mode 100644 index 00000000..b9b66e3b --- /dev/null +++ b/abci/helpers.go @@ -0,0 +1,32 @@ +package vote_ext + +import ( + stakingkeeper "github.com/cosmos/cosmos-sdk/x/staking/keeper" + "github.com/node101-io/mina-signer-go/keys" + keyregistrykeeper "github.com/node101-io/pulsar-chain/x/keyregistry/keeper" +) + +type SecondaryKey struct { + SecretKey *keys.PrivateKey + PublicKey *keys.PublicKey +} + +type AbciHandler struct { + secondaryKey SecondaryKey + stakingKeeper stakingkeeper.Keeper + keyregistryKeeper keyregistrykeeper.Keeper +} + +type VoteExtensionBody struct { + NextValidatorSetHash []byte + CurrentStateRoot []byte + NextBlockHeight int64 +} + +func NewVoteExtHandler(secondaryKey SecondaryKey, stakingKeeper stakingkeeper.Keeper, keyregistryKeeper keyregistrykeeper.Keeper) *AbciHandler { + return &AbciHandler{ + secondaryKey: secondaryKey, + stakingKeeper: stakingKeeper, + keyregistryKeeper: keyregistryKeeper, + } +} diff --git a/config.yml b/config.yml index 4ac7edc1..e6c65e01 100644 --- a/config.yml +++ b/config.yml @@ -14,13 +14,15 @@ client: openapi: path: docs/static/openapi.json faucet: - name: bob coins: - 5token - 100000stake validators: - name: alice bonded: 100000000pmina + app: + vote_extension: + priv_key: "OhOfQtGMXqcrbfCRPEe4DjLUNHaOcD3RrWuRPBGO82M=" - name: validator1 bonded: 200000000pmina - name: validator2 @@ -36,7 +38,5 @@ genesis: # Cosmos user public key placeholder: secp256k1 compressed, zero bytes, 33 bytes. #cosmos_key: "AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA" validator_key_pairs: - # Mina compressed public key placeholder: zero bytes, 33 bytes. - #- mina_key: "AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA" - # Validator consensus public key placeholder: ed25519, zero bytes, 32 bytes. - # cosmos_key: "AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA=" + # - mina_key: "3IvK1eWmmcfdlIb+T04+ck9Q5bjbqHqiT0ucGJITzyY=" + # cosmos_key: "A8saw69s1DQWvUjseeOtG8hGavmYiInrQ5M1aOPa4QkP" diff --git a/docs/static/openapi.json b/docs/static/openapi.json index 43799f72..e96c0e38 100644 --- a/docs/static/openapi.json +++ b/docs/static/openapi.json @@ -1 +1 @@ -{"id":"github.com/node101-io/pulsar-chain","consumes":["application/json"],"produces":["application/json"],"swagger":"2.0","info":{"description":"Chain github.com/node101-io/pulsar-chain REST API","title":"HTTP API Console","contact":{"name":"github.com/node101-io/pulsar-chain"},"version":"version not set"},"paths":{"/node101-io/pulsar-chain/keyregistry/v1/get_user_cosmos_public_key/{user_mina_public_key}":{"get":{"tags":["Query"],"summary":"GetUserCosmosPublicKey Queries a list of GetUserCosmosPublicKey items.","operationId":"GithubComnode101IopulsarChainQuery_GetUserCosmosPublicKey","parameters":[{"type":"string","format":"byte","name":"user_mina_public_key","in":"path","required":true}],"responses":{"200":{"description":"A successful response.","schema":{"$ref":"#/definitions/pulsarchain.keyregistry.v1.QueryGetUserCosmosPublicKeyResponse"}},"default":{"description":"An unexpected error response.","schema":{"$ref":"#/definitions/google.rpc.Status"}}}}},"/node101-io/pulsar-chain/keyregistry/v1/get_user_mina_public_key/{user_cosmos_public_key}":{"get":{"tags":["Query"],"summary":"GetUserMinaPublicKey Queries a list of GetUserMinaPublicKey items.","operationId":"GithubComnode101IopulsarChainQuery_GetUserMinaPublicKey","parameters":[{"type":"string","format":"byte","name":"user_cosmos_public_key","in":"path","required":true}],"responses":{"200":{"description":"A successful response.","schema":{"$ref":"#/definitions/pulsarchain.keyregistry.v1.QueryGetUserMinaPublicKeyResponse"}},"default":{"description":"An unexpected error response.","schema":{"$ref":"#/definitions/google.rpc.Status"}}}}},"/node101-io/pulsar-chain/keyregistry/v1/get_validator_cosmos_pub_key/{validator_mina_pub_key}":{"get":{"tags":["Query"],"summary":"GetValidatorCosmosPubKey Queries a list of GetValidatorCosmosPubKey items.","operationId":"GithubComnode101IopulsarChainQuery_GetValidatorCosmosPubKey","parameters":[{"type":"string","format":"byte","name":"validator_mina_pub_key","in":"path","required":true}],"responses":{"200":{"description":"A successful response.","schema":{"$ref":"#/definitions/pulsarchain.keyregistry.v1.QueryGetValidatorCosmosPubKeyResponse"}},"default":{"description":"An unexpected error response.","schema":{"$ref":"#/definitions/google.rpc.Status"}}}}},"/node101-io/pulsar-chain/keyregistry/v1/get_validator_mina_pub_key/{validator_cosmos_pub_key}":{"get":{"tags":["Query"],"summary":"GetValidatorMinaPubKey Queries a list of GetValidatorMinaPubKey items.","operationId":"GithubComnode101IopulsarChainQuery_GetValidatorMinaPubKey","parameters":[{"type":"string","format":"byte","name":"validator_cosmos_pub_key","in":"path","required":true}],"responses":{"200":{"description":"A successful response.","schema":{"$ref":"#/definitions/pulsarchain.keyregistry.v1.QueryGetValidatorMinaPubKeyResponse"}},"default":{"description":"An unexpected error response.","schema":{"$ref":"#/definitions/google.rpc.Status"}}}}},"/node101-io/pulsar-chain/keyregistry/v1/params":{"get":{"tags":["Query"],"summary":"Parameters queries the parameters of the module.","operationId":"GithubComnode101IopulsarChainQuery_ParamsMixin8","responses":{"200":{"description":"A successful response.","schema":{"$ref":"#/definitions/pulsarchain.keyregistry.v1.QueryParamsResponse"}},"default":{"description":"An unexpected error response.","schema":{"$ref":"#/definitions/google.rpc.Status"}}}}},"/pulsar/pulsar/v1/params":{"get":{"tags":["Query"],"summary":"Parameters queries the parameters of the module.","operationId":"GithubComnode101IopulsarChainQuery_Params","responses":{"200":{"description":"A successful response.","schema":{"$ref":"#/definitions/pulsar.pulsar.v1.QueryParamsResponse"}},"default":{"description":"An unexpected error response.","schema":{"$ref":"#/definitions/google.rpc.Status"}}}}}},"definitions":{"google.protobuf.Any":{"type":"object","properties":{"@type":{"type":"string"}},"additionalProperties":{}},"google.rpc.Status":{"type":"object","properties":{"code":{"type":"integer","format":"int32"},"details":{"type":"array","items":{"type":"object","$ref":"#/definitions/google.protobuf.Any"}},"message":{"type":"string"}}},"pulsar.pulsar.v1.Params":{"description":"Params defines the parameters for the module.","type":"object"},"pulsar.pulsar.v1.QueryParamsResponse":{"description":"QueryParamsResponse is response type for the Query/Params RPC method.","type":"object","properties":{"params":{"description":"params holds all the parameters of this module.","$ref":"#/definitions/pulsar.pulsar.v1.Params"}}},"pulsarchain.keyregistry.v1.Params":{"description":"Params defines the parameters for the module.","type":"object"},"pulsarchain.keyregistry.v1.QueryGetUserCosmosPublicKeyResponse":{"description":"QueryGetUserCosmosPublicKeyResponse defines the QueryGetUserCosmosPublicKeyResponse message.","type":"object","properties":{"user_cosmos_public_key":{"type":"string","format":"byte"}}},"pulsarchain.keyregistry.v1.QueryGetUserMinaPublicKeyResponse":{"description":"QueryGetUserMinaPublicKeyResponse defines the QueryGetUserMinaPublicKeyResponse message.","type":"object","properties":{"user_mina_public_key":{"type":"string","format":"byte"}}},"pulsarchain.keyregistry.v1.QueryGetValidatorCosmosPubKeyResponse":{"description":"QueryGetValidatorCosmosPubKeyResponse defines the QueryGetValidatorCosmosPubKeyResponse message.","type":"object","properties":{"validator_cosmos_pub_key":{"type":"string","format":"byte"}}},"pulsarchain.keyregistry.v1.QueryGetValidatorMinaPubKeyResponse":{"description":"QueryGetValidatorMinaPubKeyResponse defines the QueryGetValidatorMinaPubKeyResponse message.","type":"object","properties":{"validator_mina_pub_key":{"type":"string","format":"byte"}}},"pulsarchain.keyregistry.v1.QueryParamsResponse":{"description":"QueryParamsResponse is response type for the Query/Params RPC method.","type":"object","properties":{"params":{"description":"params holds all the parameters of this module.","$ref":"#/definitions/pulsarchain.keyregistry.v1.Params"}}}},"tags":[{"name":"Query"},{"name":"Msg"}]} \ No newline at end of file +{"id":"github.com/node101-io/pulsar-chain","consumes":["application/json"],"produces":["application/json"],"swagger":"2.0","info":{"description":"Chain github.com/node101-io/pulsar-chain REST API","title":"HTTP API Console","contact":{"name":"github.com/node101-io/pulsar-chain"},"version":"version not set"},"paths":{},"definitions":{"google.protobuf.Any":{"type":"object","properties":{"@type":{"type":"string"}},"additionalProperties":{}},"google.rpc.Status":{"type":"object","properties":{"code":{"type":"integer","format":"int32"},"details":{"type":"array","items":{"type":"object","$ref":"#/definitions/google.protobuf.Any"}},"message":{"type":"string"}}}},"tags":[{"name":"Msg"}]} From 6133bdd77ba86f7d6b0e64925f8d5b3b623622a5 Mon Sep 17 00:00:00 2001 From: Yusuf Date: Fri, 10 Apr 2026 18:37:41 +0300 Subject: [PATCH 24/62] feat: verify vote extension --- abci/extend_vote.go | 4 +++ abci/verify_vote_ext.go | 62 +++++++++++++++++++++++++++++++++++++++++ 2 files changed, 66 insertions(+) create mode 100644 abci/verify_vote_ext.go diff --git a/abci/extend_vote.go b/abci/extend_vote.go index 04898e10..c5e04b6b 100644 --- a/abci/extend_vote.go +++ b/abci/extend_vote.go @@ -23,6 +23,10 @@ func MockSign(voteExtBody VoteExtensionBody) []byte { return []byte{} } +func MockSignatureVerify(voteExtBody VoteExtensionBody, minaKey []byte, reducedRoot string) bool { + return true +} + func (h *AbciHandler) getValidatorSet(ctx sdk.Context, currentBlockHeight int64) ([]validatorInfo, error) { historicalData, err := h.stakingKeeper.GetHistoricalInfo(ctx, currentBlockHeight) diff --git a/abci/verify_vote_ext.go b/abci/verify_vote_ext.go new file mode 100644 index 00000000..18eeb14e --- /dev/null +++ b/abci/verify_vote_ext.go @@ -0,0 +1,62 @@ +package vote_ext + +import ( + "fmt" + + abci "github.com/cometbft/cometbft/abci/types" + sdk "github.com/cosmos/cosmos-sdk/types" + "github.com/node101-io/mina-signer-go/constants" + "github.com/node101-io/mina-signer-go/field" + "github.com/node101-io/mina-signer-go/poseidon" +) + +func (h *AbciHandler) VerifyVoteExtensionHandler() sdk.VerifyVoteExtensionHandler { + return func(ctx sdk.Context, req *abci.RequestVerifyVoteExtension) (*abci.ResponseVerifyVoteExtension, error) { + if req.GetHeight() < 3 { + if len(req.VoteExtension) == 0 { + return &abci.ResponseVerifyVoteExtension{Status: abci.ResponseVerifyVoteExtension_ACCEPT}, nil + } + + return &abci.ResponseVerifyVoteExtension{Status: abci.ResponseVerifyVoteExtension_REJECT}, fmt.Errorf("rejected") + } + + cosmosValAddr := req.GetValidatorAddress() + + exists, err := h.keyregistryKeeper.ValidatorCosmosToMinaHas(ctx, cosmosValAddr) + if err != nil { + return &abci.ResponseVerifyVoteExtension{Status: abci.ResponseVerifyVoteExtension_REJECT}, err + } + if !exists { + return &abci.ResponseVerifyVoteExtension{Status: abci.ResponseVerifyVoteExtension_REJECT}, err + } + + poseidonHash := poseidon.CreatePoseidon(*field.Fp, constants.PoseidonParamsKimchiFp) + + minaKey, err := h.keyregistryKeeper.ValidatorGetCosmosToMina(ctx, cosmosValAddr) + if err != nil { + return &abci.ResponseVerifyVoteExtension{Status: abci.ResponseVerifyVoteExtension_REJECT}, err + } + + valInfo, err := h.getValidatorSet(ctx, req.Height) + if err != nil { + return &abci.ResponseVerifyVoteExtension{Status: abci.ResponseVerifyVoteExtension_REJECT}, err + } + + setRoot, err := h.calculateValidatorSetRoot(ctx, valInfo, poseidonHash) + if err != nil { + return &abci.ResponseVerifyVoteExtension{Status: abci.ResponseVerifyVoteExtension_REJECT}, err + } + + sigValidity := MockSignatureVerify(VoteExtensionBody{ + NextValidatorSetHash: setRoot.Bytes(), + CurrentStateRoot: ctx.HeaderInfo().AppHash, + NextBlockHeight: req.Height, + }, minaKey, ActionsReducedRoot) + + if !sigValidity { + return &abci.ResponseVerifyVoteExtension{Status: abci.ResponseVerifyVoteExtension_REJECT}, err + } + + return &abci.ResponseVerifyVoteExtension{Status: abci.ResponseVerifyVoteExtension_ACCEPT}, nil + } +} From d6ab839a70bcd92ab899ad7133a42b8a6031cc56 Mon Sep 17 00:00:00 2001 From: Yusuf Date: Mon, 13 Apr 2026 18:07:02 +0300 Subject: [PATCH 25/62] feat: prepare proposal handler --- abci/helpers.go | 32 ++++++++++++++++++++++ abci/prepare_proposal.go | 59 ++++++++++++++++++++++++++++++++++++++++ 2 files changed, 91 insertions(+) create mode 100644 abci/prepare_proposal.go diff --git a/abci/helpers.go b/abci/helpers.go index b9b66e3b..5edc9a33 100644 --- a/abci/helpers.go +++ b/abci/helpers.go @@ -6,6 +6,10 @@ import ( keyregistrykeeper "github.com/node101-io/pulsar-chain/x/keyregistry/keeper" ) +var VoteExtMarker []byte = []byte("VOTEEXT:") + +const AcceptanceRatio float64 = 0.66 + type SecondaryKey struct { SecretKey *keys.PrivateKey PublicKey *keys.PublicKey @@ -15,6 +19,7 @@ type AbciHandler struct { secondaryKey SecondaryKey stakingKeeper stakingkeeper.Keeper keyregistryKeeper keyregistrykeeper.Keeper + votes map[uint64]map[string][]byte // height -> minaAddress -> extension bytes } type VoteExtensionBody struct { @@ -23,6 +28,11 @@ type VoteExtensionBody struct { NextBlockHeight int64 } +type payload struct { + Height uint64 `json:"height"` + Votes map[string][]byte `json:"votes"` +} + func NewVoteExtHandler(secondaryKey SecondaryKey, stakingKeeper stakingkeeper.Keeper, keyregistryKeeper keyregistrykeeper.Keeper) *AbciHandler { return &AbciHandler{ secondaryKey: secondaryKey, @@ -30,3 +40,25 @@ func NewVoteExtHandler(secondaryKey SecondaryKey, stakingKeeper stakingkeeper.Ke keyregistryKeeper: keyregistryKeeper, } } + +func (h *AbciHandler) storeVote(height uint64, minaKey string, voteExt []byte) { + + voteMap := h.votes[height] + + voteMap[minaKey] = voteExt + +} + +func (h *AbciHandler) fetchVote(height uint64, minaKey string) []byte { + + voteMap := h.votes[height] + + return voteMap[minaKey] +} + +func (h *AbciHandler) fetchVotes(height uint64) map[string][]byte { + + voteMap := h.votes[height] + + return voteMap +} diff --git a/abci/prepare_proposal.go b/abci/prepare_proposal.go new file mode 100644 index 00000000..925c8a17 --- /dev/null +++ b/abci/prepare_proposal.go @@ -0,0 +1,59 @@ +package vote_ext + +import ( + "encoding/json" + "fmt" + + abci "github.com/cometbft/cometbft/abci/types" + sdk "github.com/cosmos/cosmos-sdk/types" +) + +func (h *AbciHandler) PrepareProposalHandler() sdk.PrepareProposalHandler { + + return func(ctx sdk.Context, req *abci.RequestPrepareProposal) (*abci.ResponsePrepareProposal, error) { + + voteExtsForGivenBlock := make(map[string][]byte) + targetHeight := uint64(req.GetHeight() - 1) + + valInfo, err := h.getValidatorSet(ctx, req.Height) + if err != nil { + return &abci.ResponsePrepareProposal{Txs: req.Txs}, nil + } + + for _, val := range valInfo { + + exists, err := h.keyregistryKeeper.ValidatorCosmosToMinaHas(ctx, val.ConsensusAddr) + if err != nil { + return &abci.ResponsePrepareProposal{Txs: req.Txs}, nil + } + if !exists { + return &abci.ResponsePrepareProposal{Txs: req.Txs}, nil + } + minaKey, err := h.keyregistryKeeper.ValidatorGetCosmosToMina(ctx, val.ConsensusAddr) + if err != nil { + return &abci.ResponsePrepareProposal{Txs: req.Txs}, nil + } + voteExtsForGivenBlock[string(val.ConsensusAddr)] = h.fetchVote(targetHeight, string(minaKey)) + } + + if len(voteExtsForGivenBlock) == 0 { + return &abci.ResponsePrepareProposal{Txs: req.Txs}, nil + } + + pl := payload{Height: targetHeight, Votes: voteExtsForGivenBlock} + bz, err := json.Marshal(pl) + if err != nil { + return nil, fmt.Errorf("") + } + + // prefix makes it easier to identify the vote extension + extTx := append(VoteExtMarker, bz...) + + // prepend to existing txs + txs := make([][]byte, 0, len(req.Txs)+1) + txs = append(txs, extTx) + txs = append(txs, req.Txs...) + + return &abci.ResponsePrepareProposal{Txs: [][]byte{}}, nil + } +} From 477682f686bf37cade8d269f9cca3402e6238fac Mon Sep 17 00:00:00 2001 From: Yusuf Date: Mon, 13 Apr 2026 18:07:12 +0300 Subject: [PATCH 26/62] feat: process proposal handler --- abci/process_proposal.go | 69 ++++++++++++++++++++++++++++++++++++++++ 1 file changed, 69 insertions(+) create mode 100644 abci/process_proposal.go diff --git a/abci/process_proposal.go b/abci/process_proposal.go new file mode 100644 index 00000000..9a84c843 --- /dev/null +++ b/abci/process_proposal.go @@ -0,0 +1,69 @@ +package vote_ext + +import ( + abci "github.com/cometbft/cometbft/abci/types" + sdk "github.com/cosmos/cosmos-sdk/types" + stakingkeeper "github.com/cosmos/cosmos-sdk/x/staking/keeper" + "github.com/node101-io/mina-signer-go/constants" + "github.com/node101-io/mina-signer-go/field" + "github.com/node101-io/mina-signer-go/poseidon" +) + +func (h *AbciHandler) ProcessProposalHandler() sdk.ProcessProposalHandler { + + return func(ctx sdk.Context, req *abci.RequestProcessProposal) (*abci.ResponseProcessProposal, error) { + + // If height is 1, we won't have any votes thus skip the proposal + if req.GetHeight() == 1 { + return &abci.ResponseProcessProposal{Status: abci.ResponseProcessProposal_ACCEPT}, nil + } + + // vote ext reconstruct + currentState, err := stakingkeeper.Keeper.GetHistoricalInfo(h.stakingKeeper, ctx, req.GetHeight()-2) + if err != nil { + return &abci.ResponseProcessProposal{Status: abci.ResponseProcessProposal_REJECT}, nil + } + + valInfo, err := h.getValidatorSet(ctx, req.GetHeight()-1) + if err != nil { + return &abci.ResponseProcessProposal{Status: abci.ResponseProcessProposal_REJECT}, nil + } + + poseidonHash := poseidon.CreatePoseidon(*field.Fp, constants.PoseidonParamsKimchiFp) + + nextValidatorSetHash, err := h.calculateValidatorSetRoot(ctx, valInfo, poseidonHash) + if err != nil { + return &abci.ResponseProcessProposal{Status: abci.ResponseProcessProposal_REJECT}, nil + } + if nextValidatorSetHash == nil { + return &abci.ResponseProcessProposal{Status: abci.ResponseProcessProposal_REJECT}, nil + } + + body := VoteExtensionBody{ + NextBlockHeight: req.GetHeight() - 1, + CurrentStateRoot: currentState.Header.AppHash, + NextValidatorSetHash: nextValidatorSetHash.Bytes(), + } + + var signedStakePower int64 + var currentValidatorStakePower int64 + voteExtMap := h.fetchVotes(uint64(req.GetHeight()) - 2) + + for _, val := range valInfo { + if voteExtMap[string(val.ConsensusAddr)] != nil { + signedStakePower += val.Power + } + currentValidatorStakePower += val.Power + } + + if float64(signedStakePower) < float64(currentValidatorStakePower)*AcceptanceRatio { + return &abci.ResponseProcessProposal{Status: abci.ResponseProcessProposal_REJECT}, nil + } + + MockSignatureVerify(body, h.secondaryKey.PublicKey.X.Bytes(), ActionsReducedRoot) + + // Vote extension successfully verified + return &abci.ResponseProcessProposal{Status: abci.ResponseProcessProposal_ACCEPT}, nil + } + +} From 380df9a873eab513bf00dc967ebe6a3ac1421078 Mon Sep 17 00:00:00 2001 From: Yusuf Date: Mon, 27 Apr 2026 17:29:55 +0300 Subject: [PATCH 27/62] fix: return values fixed and used integer arithmetic instead of float --- abci/prepare_proposal.go | 21 ++++++++++----------- abci/process_proposal.go | 10 +++++----- 2 files changed, 15 insertions(+), 16 deletions(-) diff --git a/abci/prepare_proposal.go b/abci/prepare_proposal.go index 925c8a17..a5b34ec4 100644 --- a/abci/prepare_proposal.go +++ b/abci/prepare_proposal.go @@ -17,27 +17,26 @@ func (h *AbciHandler) PrepareProposalHandler() sdk.PrepareProposalHandler { valInfo, err := h.getValidatorSet(ctx, req.Height) if err != nil { - return &abci.ResponsePrepareProposal{Txs: req.Txs}, nil + return &abci.ResponsePrepareProposal{Txs: req.Txs}, err } - for _, val := range valInfo { + for i, val := range valInfo { exists, err := h.keyregistryKeeper.ValidatorCosmosToMinaHas(ctx, val.ConsensusAddr) if err != nil { - return &abci.ResponsePrepareProposal{Txs: req.Txs}, nil + return &abci.ResponsePrepareProposal{Txs: req.Txs}, err } if !exists { - return &abci.ResponsePrepareProposal{Txs: req.Txs}, nil + return &abci.ResponsePrepareProposal{Txs: req.Txs}, err } - minaKey, err := h.keyregistryKeeper.ValidatorGetCosmosToMina(ctx, val.ConsensusAddr) - if err != nil { - return &abci.ResponsePrepareProposal{Txs: req.Txs}, nil - } - voteExtsForGivenBlock[string(val.ConsensusAddr)] = h.fetchVote(targetHeight, string(minaKey)) + + votes := req.LocalLastCommit.Votes + + voteExtsForGivenBlock[string(votes[i].Validator.Address)] = votes[i].ExtensionSignature } if len(voteExtsForGivenBlock) == 0 { - return &abci.ResponsePrepareProposal{Txs: req.Txs}, nil + return &abci.ResponsePrepareProposal{Txs: req.Txs}, err } pl := payload{Height: targetHeight, Votes: voteExtsForGivenBlock} @@ -54,6 +53,6 @@ func (h *AbciHandler) PrepareProposalHandler() sdk.PrepareProposalHandler { txs = append(txs, extTx) txs = append(txs, req.Txs...) - return &abci.ResponsePrepareProposal{Txs: [][]byte{}}, nil + return &abci.ResponsePrepareProposal{Txs: txs}, nil } } diff --git a/abci/process_proposal.go b/abci/process_proposal.go index 9a84c843..4f9a6061 100644 --- a/abci/process_proposal.go +++ b/abci/process_proposal.go @@ -21,22 +21,22 @@ func (h *AbciHandler) ProcessProposalHandler() sdk.ProcessProposalHandler { // vote ext reconstruct currentState, err := stakingkeeper.Keeper.GetHistoricalInfo(h.stakingKeeper, ctx, req.GetHeight()-2) if err != nil { - return &abci.ResponseProcessProposal{Status: abci.ResponseProcessProposal_REJECT}, nil + return &abci.ResponseProcessProposal{Status: abci.ResponseProcessProposal_REJECT}, err } valInfo, err := h.getValidatorSet(ctx, req.GetHeight()-1) if err != nil { - return &abci.ResponseProcessProposal{Status: abci.ResponseProcessProposal_REJECT}, nil + return &abci.ResponseProcessProposal{Status: abci.ResponseProcessProposal_REJECT}, err } poseidonHash := poseidon.CreatePoseidon(*field.Fp, constants.PoseidonParamsKimchiFp) nextValidatorSetHash, err := h.calculateValidatorSetRoot(ctx, valInfo, poseidonHash) if err != nil { - return &abci.ResponseProcessProposal{Status: abci.ResponseProcessProposal_REJECT}, nil + return &abci.ResponseProcessProposal{Status: abci.ResponseProcessProposal_REJECT}, err } if nextValidatorSetHash == nil { - return &abci.ResponseProcessProposal{Status: abci.ResponseProcessProposal_REJECT}, nil + return &abci.ResponseProcessProposal{Status: abci.ResponseProcessProposal_REJECT}, err } body := VoteExtensionBody{ @@ -56,7 +56,7 @@ func (h *AbciHandler) ProcessProposalHandler() sdk.ProcessProposalHandler { currentValidatorStakePower += val.Power } - if float64(signedStakePower) < float64(currentValidatorStakePower)*AcceptanceRatio { + if signedStakePower*3 >= currentValidatorStakePower*2 { return &abci.ResponseProcessProposal{Status: abci.ResponseProcessProposal_REJECT}, nil } From 760c116a4a3cd5c996424fa89b683dca517c0eb4 Mon Sep 17 00:00:00 2001 From: Yusuf Date: Fri, 1 May 2026 22:22:24 +0300 Subject: [PATCH 28/62] chore: rebased vote ext --- app/app.go | 9 +- app/app_config.go | 9 + buf.lock | 4 +- docs/static/openapi.json | 2 +- .../votepersistence/module/v1/module.proto | 15 + .../votepersistence/v1/genesis.proto | 17 + .../votepersistence/v1/params.proto | 13 + .../votepersistence/v1/query.proto | 30 + proto/pulsarchain/votepersistence/v1/tx.proto | 40 ++ x/keyregistry/types/address_pair.pb.go | 375 +++++++++++ x/keyregistry/types/genesis.pb.go | 7 +- x/keyregistry/types/module.pb.go | 5 +- x/keyregistry/types/params.pb.go | 7 +- x/keyregistry/types/public_key_pair.pb.go | 3 +- x/keyregistry/types/query.pb.go | 7 +- x/keyregistry/types/tx.pb.go | 7 +- x/pulsar/types/genesis.pb.go | 7 +- x/pulsar/types/module.pb.go | 5 +- x/pulsar/types/params.pb.go | 7 +- x/pulsar/types/query.pb.go | 7 +- x/pulsar/types/tx.pb.go | 7 +- x/votepersistence/keeper/genesis.go | 25 + x/votepersistence/keeper/genesis_test.go | 24 + x/votepersistence/keeper/keeper.go | 60 ++ x/votepersistence/keeper/keeper_test.go | 56 ++ x/votepersistence/keeper/msg_server.go | 17 + x/votepersistence/keeper/msg_update_params.go | 32 + .../keeper/msg_update_params_test.go | 68 ++ x/votepersistence/keeper/query.go | 17 + x/votepersistence/keeper/query_params.go | 26 + x/votepersistence/keeper/query_params_test.go | 22 + x/votepersistence/module/autocli.go | 35 + x/votepersistence/module/depinject.go | 62 ++ x/votepersistence/module/module.go | 143 +++++ x/votepersistence/module/simulation.go | 34 + x/votepersistence/types/codec.go | 14 + x/votepersistence/types/errors.go | 12 + x/votepersistence/types/expected_keepers.go | 27 + x/votepersistence/types/genesis.go | 14 + x/votepersistence/types/genesis.pb.go | 328 ++++++++++ x/votepersistence/types/genesis_test.go | 37 ++ x/votepersistence/types/keys.go | 19 + x/votepersistence/types/module.pb.go | 325 ++++++++++ x/votepersistence/types/params.go | 17 + x/votepersistence/types/params.pb.go | 293 +++++++++ x/votepersistence/types/query.pb.go | 545 ++++++++++++++++ x/votepersistence/types/query.pb.gw.go | 153 +++++ x/votepersistence/types/tx.pb.go | 604 ++++++++++++++++++ x/votepersistence/types/types.go | 1 + 49 files changed, 3558 insertions(+), 35 deletions(-) create mode 100644 proto/pulsarchain/votepersistence/module/v1/module.proto create mode 100644 proto/pulsarchain/votepersistence/v1/genesis.proto create mode 100644 proto/pulsarchain/votepersistence/v1/params.proto create mode 100644 proto/pulsarchain/votepersistence/v1/query.proto create mode 100644 proto/pulsarchain/votepersistence/v1/tx.proto create mode 100644 x/keyregistry/types/address_pair.pb.go create mode 100644 x/votepersistence/keeper/genesis.go create mode 100644 x/votepersistence/keeper/genesis_test.go create mode 100644 x/votepersistence/keeper/keeper.go create mode 100644 x/votepersistence/keeper/keeper_test.go create mode 100644 x/votepersistence/keeper/msg_server.go create mode 100644 x/votepersistence/keeper/msg_update_params.go create mode 100644 x/votepersistence/keeper/msg_update_params_test.go create mode 100644 x/votepersistence/keeper/query.go create mode 100644 x/votepersistence/keeper/query_params.go create mode 100644 x/votepersistence/keeper/query_params_test.go create mode 100644 x/votepersistence/module/autocli.go create mode 100644 x/votepersistence/module/depinject.go create mode 100644 x/votepersistence/module/module.go create mode 100644 x/votepersistence/module/simulation.go create mode 100644 x/votepersistence/types/codec.go create mode 100644 x/votepersistence/types/errors.go create mode 100644 x/votepersistence/types/expected_keepers.go create mode 100644 x/votepersistence/types/genesis.go create mode 100644 x/votepersistence/types/genesis.pb.go create mode 100644 x/votepersistence/types/genesis_test.go create mode 100644 x/votepersistence/types/keys.go create mode 100644 x/votepersistence/types/module.pb.go create mode 100644 x/votepersistence/types/params.go create mode 100644 x/votepersistence/types/params.pb.go create mode 100644 x/votepersistence/types/query.pb.go create mode 100644 x/votepersistence/types/query.pb.gw.go create mode 100644 x/votepersistence/types/tx.pb.go create mode 100644 x/votepersistence/types/types.go diff --git a/app/app.go b/app/app.go index b63ee207..f0f85bd8 100644 --- a/app/app.go +++ b/app/app.go @@ -48,6 +48,7 @@ import ( "github.com/node101-io/pulsar-chain/docs" keyregistrymodulekeeper "github.com/node101-io/pulsar-chain/x/keyregistry/keeper" pulsarmodulekeeper "github.com/node101-io/pulsar-chain/x/pulsar/keeper" + votepersistencemodulekeeper "github.com/node101-io/pulsar-chain/x/votepersistence/keeper" ) const ( @@ -100,9 +101,10 @@ type App struct { TransferKeeper ibctransferkeeper.Keeper // simulation manager - sm *module.SimulationManager - PulsarKeeper pulsarmodulekeeper.Keeper - KeyregistryKeeper keyregistrymodulekeeper.Keeper + sm *module.SimulationManager + PulsarKeeper pulsarmodulekeeper.Keeper + KeyregistryKeeper keyregistrymodulekeeper.Keeper + VotepersistenceKeeper votepersistencemodulekeeper.Keeper } func init() { @@ -184,6 +186,7 @@ func New( &app.ParamsKeeper, &app.PulsarKeeper, &app.KeyregistryKeeper, + &app.VotepersistenceKeeper, ); err != nil { panic(err) } diff --git a/app/app_config.go b/app/app_config.go index db90a02e..dc747fa5 100644 --- a/app/app_config.go +++ b/app/app_config.go @@ -7,6 +7,8 @@ import ( keyregistrymoduletypes "github.com/node101-io/pulsar-chain/x/keyregistry/types" _ "github.com/node101-io/pulsar-chain/x/pulsar/module" pulsarmoduletypes "github.com/node101-io/pulsar-chain/x/pulsar/types" + _ "github.com/node101-io/pulsar-chain/x/votepersistence/module" + votepersistencemoduletypes "github.com/node101-io/pulsar-chain/x/votepersistence/types" runtimev1alpha1 "cosmossdk.io/api/cosmos/app/runtime/v1alpha1" appv1alpha1 "cosmossdk.io/api/cosmos/app/v1alpha1" @@ -130,6 +132,7 @@ var ( // chain modules pulsarmoduletypes.ModuleName, keyregistrymoduletypes.ModuleName, + votepersistencemoduletypes.ModuleName, // this line is used by starport scaffolding # stargate/app/beginBlockers }, EndBlockers: []string{ @@ -140,6 +143,7 @@ var ( // chain modules pulsarmoduletypes.ModuleName, keyregistrymoduletypes.ModuleName, + votepersistencemoduletypes.ModuleName, // this line is used by starport scaffolding # stargate/app/endBlockers }, // The following is mostly only needed when ModuleName != StoreKey name. @@ -178,6 +182,7 @@ var ( // chain modules pulsarmoduletypes.ModuleName, keyregistrymoduletypes.ModuleName, + votepersistencemoduletypes.ModuleName, // this line is used by starport scaffolding # stargate/app/initGenesis }, }), @@ -282,6 +287,10 @@ var ( Name: keyregistrymoduletypes.ModuleName, Config: appconfig.WrapAny(&keyregistrymoduletypes.Module{}), }, + { + Name: votepersistencemoduletypes.ModuleName, + Config: appconfig.WrapAny(&votepersistencemoduletypes.Module{}), + }, // this line is used by starport scaffolding # stargate/app/moduleConfig }, }) diff --git a/buf.lock b/buf.lock index 2da6522e..fd28dbd0 100644 --- a/buf.lock +++ b/buf.lock @@ -17,8 +17,8 @@ deps: commit: dc427cb4519143d8996361c045a29ad7 digest: b5:8693e72e230bfaf58a88a47a4093ba99f6252c1957a45582567959b38a8563e2abd11443372283d75f4f2306a7e3cc9bf63604d284a016c11966fca4b74b7a28 - name: buf.build/googleapis/googleapis - commit: 536964a08a534d51b8f30f2d6751f1f9 - digest: b5:3e05d27e797b00c345fadd3c15cf0e16c4cc693036a55059721e66d6ce22a96264a4897658c9243bb0874fa9ca96e437589eb512189d2754604a626c632f6030 + commit: c17df5b2beca46928cc87d5656bd5343 + digest: b5:648a01e0170d4512dea7d564016165decd1ed6e34bef79fe54753e51ad7e27545709ad9157d7551270147d551155c595a2fb0bf5bb33b1c83040ddbce915c604 - name: buf.build/protocolbuffers/wellknowntypes commit: 9d16d599a978406980f6e2f081331a93 digest: b5:dd06e497a5c52f5ddf6ec02b3c7d289cc6c0432093fc2f6bf7a4fb5fae786c3e4c893e55d2759ffb6833268daf3de0bce303a406fed15725790528f2c27dc219 diff --git a/docs/static/openapi.json b/docs/static/openapi.json index e96c0e38..0c92b26f 100644 --- a/docs/static/openapi.json +++ b/docs/static/openapi.json @@ -1 +1 @@ -{"id":"github.com/node101-io/pulsar-chain","consumes":["application/json"],"produces":["application/json"],"swagger":"2.0","info":{"description":"Chain github.com/node101-io/pulsar-chain REST API","title":"HTTP API Console","contact":{"name":"github.com/node101-io/pulsar-chain"},"version":"version not set"},"paths":{},"definitions":{"google.protobuf.Any":{"type":"object","properties":{"@type":{"type":"string"}},"additionalProperties":{}},"google.rpc.Status":{"type":"object","properties":{"code":{"type":"integer","format":"int32"},"details":{"type":"array","items":{"type":"object","$ref":"#/definitions/google.protobuf.Any"}},"message":{"type":"string"}}}},"tags":[{"name":"Msg"}]} +{"id":"github.com/node101-io/pulsar-chain","consumes":["application/json"],"produces":["application/json"],"swagger":"2.0","info":{"description":"Chain github.com/node101-io/pulsar-chain REST API","title":"HTTP API Console","contact":{"name":"github.com/node101-io/pulsar-chain"},"version":"version not set"},"paths":{"/node101-io/pulsar-chain/keyregistry/v1/get_user_cosmos_address/{user_mina_address}":{"get":{"tags":["Query"],"summary":"GetUserCosmosAddress Queries a list of GetUserCosmosAddress items.","operationId":"GithubComnode101IopulsarChainQuery_GetUserCosmosAddress","parameters":[{"type":"string","format":"byte","name":"user_mina_address","in":"path","required":true}],"responses":{"200":{"description":"A successful response.","schema":{"$ref":"#/definitions/pulsarchain.keyregistry.v1.QueryGetUserCosmosAddressResponse"}},"default":{"description":"An unexpected error response.","schema":{"$ref":"#/definitions/google.rpc.Status"}}}}},"/node101-io/pulsar-chain/keyregistry/v1/get_user_mina_address/{user_cosmos_address}":{"get":{"tags":["Query"],"summary":"GetUserMinaAddress Queries a list of GetUserMinaAddress items.","operationId":"GithubComnode101IopulsarChainQuery_GetUserMinaAddress","parameters":[{"type":"string","format":"byte","name":"user_cosmos_address","in":"path","required":true}],"responses":{"200":{"description":"A successful response.","schema":{"$ref":"#/definitions/pulsarchain.keyregistry.v1.QueryGetUserMinaAddressResponse"}},"default":{"description":"An unexpected error response.","schema":{"$ref":"#/definitions/google.rpc.Status"}}}}},"/node101-io/pulsar-chain/keyregistry/v1/get_validator_cosmos_pub_key/{validator_mina_pub_key}":{"get":{"tags":["Query"],"summary":"GetValidatorCosmosAddress Queries a list of GetValidatorCosmosAddress items.","operationId":"GithubComnode101IopulsarChainQuery_GetValidatorCosmosPubKey","parameters":[{"type":"string","format":"byte","name":"validator_mina_pub_key","in":"path","required":true}],"responses":{"200":{"description":"A successful response.","schema":{"$ref":"#/definitions/pulsarchain.keyregistry.v1.QueryGetValidatorCosmosPubKeyResponse"}},"default":{"description":"An unexpected error response.","schema":{"$ref":"#/definitions/google.rpc.Status"}}}}},"/node101-io/pulsar-chain/keyregistry/v1/get_validator_mina_pub_key/{validator_cosmos_pub_key}":{"get":{"tags":["Query"],"summary":"GetValidatorMinaAddress Queries a list of GetValidatorMinaAddress items.","operationId":"GithubComnode101IopulsarChainQuery_GetValidatorMinaPubKey","parameters":[{"type":"string","format":"byte","name":"validator_cosmos_pub_key","in":"path","required":true}],"responses":{"200":{"description":"A successful response.","schema":{"$ref":"#/definitions/pulsarchain.keyregistry.v1.QueryGetValidatorMinaPubKeyResponse"}},"default":{"description":"An unexpected error response.","schema":{"$ref":"#/definitions/google.rpc.Status"}}}}},"/node101-io/pulsar-chain/keyregistry/v1/params":{"get":{"tags":["Query"],"summary":"Parameters queries the parameters of the module.","operationId":"GithubComnode101IopulsarChainQuery_ParamsMixin8","responses":{"200":{"description":"A successful response.","schema":{"$ref":"#/definitions/pulsarchain.keyregistry.v1.QueryParamsResponse"}},"default":{"description":"An unexpected error response.","schema":{"$ref":"#/definitions/google.rpc.Status"}}}}},"/node101-io/pulsar-chain/votepersistence/v1/params":{"get":{"tags":["Query"],"summary":"Parameters queries the parameters of the module.","operationId":"GithubComnode101IopulsarChainQuery_ParamsMixin12","responses":{"200":{"description":"A successful response.","schema":{"$ref":"#/definitions/pulsarchain.votepersistence.v1.QueryParamsResponse"}},"default":{"description":"An unexpected error response.","schema":{"$ref":"#/definitions/google.rpc.Status"}}}}},"/pulsar/pulsar/v1/params":{"get":{"tags":["Query"],"summary":"Parameters queries the parameters of the module.","operationId":"GithubComnode101IopulsarChainQuery_Params","responses":{"200":{"description":"A successful response.","schema":{"$ref":"#/definitions/pulsar.pulsar.v1.QueryParamsResponse"}},"default":{"description":"An unexpected error response.","schema":{"$ref":"#/definitions/google.rpc.Status"}}}}}},"definitions":{"google.protobuf.Any":{"type":"object","properties":{"@type":{"type":"string"}},"additionalProperties":{}},"google.rpc.Status":{"type":"object","properties":{"code":{"type":"integer","format":"int32"},"details":{"type":"array","items":{"type":"object","$ref":"#/definitions/google.protobuf.Any"}},"message":{"type":"string"}}},"pulsar.pulsar.v1.Params":{"description":"Params defines the parameters for the module.","type":"object"},"pulsar.pulsar.v1.QueryParamsResponse":{"description":"QueryParamsResponse is response type for the Query/Params RPC method.","type":"object","properties":{"params":{"description":"params holds all the parameters of this module.","$ref":"#/definitions/pulsar.pulsar.v1.Params"}}},"pulsarchain.keyregistry.v1.Params":{"description":"Params defines the parameters for the module.","type":"object"},"pulsarchain.keyregistry.v1.QueryGetUserCosmosAddressResponse":{"description":"QueryGetUserCosmosAddressResponse defines the QueryGetUserCosmosAddressResponse message.","type":"object","properties":{"user_cosmos_address":{"type":"string","format":"byte"}}},"pulsarchain.keyregistry.v1.QueryGetUserMinaAddressResponse":{"description":"QueryGetUserMinaAddressResponse defines the QueryGetUserMinaAddressResponse message.","type":"object","properties":{"user_mina_address":{"type":"string","format":"byte"}}},"pulsarchain.keyregistry.v1.QueryGetValidatorCosmosPubKeyResponse":{"description":"QueryGetValidatorCosmosAddressResponse defines the QueryGetValidatorCosmosAddressResponse message.","type":"object","properties":{"validator_cosmos_pub_key":{"type":"string","format":"byte"}}},"pulsarchain.keyregistry.v1.QueryGetValidatorMinaPubKeyResponse":{"description":"QueryGetValidatorMinaAddressResponse defines the QueryGetValidatorMinaAddressResponse message.","type":"object","properties":{"validator_mina_pub_key":{"type":"string","format":"byte"}}},"pulsarchain.keyregistry.v1.QueryParamsResponse":{"description":"QueryParamsResponse is response type for the Query/Params RPC method.","type":"object","properties":{"params":{"description":"params holds all the parameters of this module.","$ref":"#/definitions/pulsarchain.keyregistry.v1.Params"}}},"pulsarchain.votepersistence.v1.Params":{"description":"Params defines the parameters for the module.","type":"object"},"pulsarchain.votepersistence.v1.QueryParamsResponse":{"description":"QueryParamsResponse is response type for the Query/Params RPC method.","type":"object","properties":{"params":{"description":"params holds all the parameters of this module.","$ref":"#/definitions/pulsarchain.votepersistence.v1.Params"}}}},"tags":[{"name":"Query"},{"name":"Msg"}]} diff --git a/proto/pulsarchain/votepersistence/module/v1/module.proto b/proto/pulsarchain/votepersistence/module/v1/module.proto new file mode 100644 index 00000000..95cef682 --- /dev/null +++ b/proto/pulsarchain/votepersistence/module/v1/module.proto @@ -0,0 +1,15 @@ +syntax = "proto3"; +package pulsarchain.votepersistence.module.v1; + +import "cosmos/app/v1alpha1/module.proto"; + +option go_package = "github.com/node101-io/pulsar-chain/x/votepersistence/types"; + +// Module is the config object for the module. +message Module { + option (cosmos.app.v1alpha1.module) = {go_import: "github.com/node101-io/pulsar-chain/x/votepersistence"}; + + // authority defines the custom module authority. + // If not set, defaults to the governance module. + string authority = 1; +} diff --git a/proto/pulsarchain/votepersistence/v1/genesis.proto b/proto/pulsarchain/votepersistence/v1/genesis.proto new file mode 100644 index 00000000..dd13c4a6 --- /dev/null +++ b/proto/pulsarchain/votepersistence/v1/genesis.proto @@ -0,0 +1,17 @@ +syntax = "proto3"; +package pulsarchain.votepersistence.v1; + +import "amino/amino.proto"; +import "gogoproto/gogo.proto"; +import "pulsarchain/votepersistence/v1/params.proto"; + +option go_package = "github.com/node101-io/pulsar-chain/x/votepersistence/types"; + +// GenesisState defines the votepersistence module's genesis state. +message GenesisState { + // params defines all the parameters of the module. + Params params = 1 [ + (gogoproto.nullable) = false, + (amino.dont_omitempty) = true + ]; +} diff --git a/proto/pulsarchain/votepersistence/v1/params.proto b/proto/pulsarchain/votepersistence/v1/params.proto new file mode 100644 index 00000000..35085c91 --- /dev/null +++ b/proto/pulsarchain/votepersistence/v1/params.proto @@ -0,0 +1,13 @@ +syntax = "proto3"; +package pulsarchain.votepersistence.v1; + +import "amino/amino.proto"; +import "gogoproto/gogo.proto"; + +option go_package = "github.com/node101-io/pulsar-chain/x/votepersistence/types"; + +// Params defines the parameters for the module. +message Params { + option (amino.name) = "pulsarchain/x/votepersistence/Params"; + option (gogoproto.equal) = true; +} diff --git a/proto/pulsarchain/votepersistence/v1/query.proto b/proto/pulsarchain/votepersistence/v1/query.proto new file mode 100644 index 00000000..aecc4d2d --- /dev/null +++ b/proto/pulsarchain/votepersistence/v1/query.proto @@ -0,0 +1,30 @@ +syntax = "proto3"; +package pulsarchain.votepersistence.v1; + +import "amino/amino.proto"; +import "cosmos/base/query/v1beta1/pagination.proto"; +import "gogoproto/gogo.proto"; +import "google/api/annotations.proto"; +import "pulsarchain/votepersistence/v1/params.proto"; + +option go_package = "github.com/node101-io/pulsar-chain/x/votepersistence/types"; + +// Query defines the gRPC querier service. +service Query { + // Parameters queries the parameters of the module. + rpc Params(QueryParamsRequest) returns (QueryParamsResponse) { + option (google.api.http).get = "/node101-io/pulsar-chain/votepersistence/v1/params"; + } +} + +// QueryParamsRequest is request type for the Query/Params RPC method. +message QueryParamsRequest {} + +// QueryParamsResponse is response type for the Query/Params RPC method. +message QueryParamsResponse { + // params holds all the parameters of this module. + Params params = 1 [ + (gogoproto.nullable) = false, + (amino.dont_omitempty) = true + ]; +} diff --git a/proto/pulsarchain/votepersistence/v1/tx.proto b/proto/pulsarchain/votepersistence/v1/tx.proto new file mode 100644 index 00000000..dd98a36c --- /dev/null +++ b/proto/pulsarchain/votepersistence/v1/tx.proto @@ -0,0 +1,40 @@ +syntax = "proto3"; +package pulsarchain.votepersistence.v1; + +import "amino/amino.proto"; +import "cosmos/msg/v1/msg.proto"; +import "cosmos_proto/cosmos.proto"; +import "gogoproto/gogo.proto"; +import "pulsarchain/votepersistence/v1/params.proto"; + +option go_package = "github.com/node101-io/pulsar-chain/x/votepersistence/types"; + +// Msg defines the Msg service. +service Msg { + option (cosmos.msg.v1.service) = true; + + // UpdateParams defines a (governance) operation for updating the module + // parameters. The authority defaults to the x/gov module account. + rpc UpdateParams(MsgUpdateParams) returns (MsgUpdateParamsResponse); +} + +// MsgUpdateParams is the Msg/UpdateParams request type. +message MsgUpdateParams { + option (cosmos.msg.v1.signer) = "authority"; + option (amino.name) = "pulsarchain/x/votepersistence/MsgUpdateParams"; + + // authority is the address that controls the module (defaults to x/gov unless overwritten). + string authority = 1 [(cosmos_proto.scalar) = "cosmos.AddressString"]; + + // params defines the module parameters to update. + // + // NOTE: All parameters must be supplied. + Params params = 2 [ + (gogoproto.nullable) = false, + (amino.dont_omitempty) = true + ]; +} + +// MsgUpdateParamsResponse defines the response structure for executing a +// MsgUpdateParams message. +message MsgUpdateParamsResponse {} diff --git a/x/keyregistry/types/address_pair.pb.go b/x/keyregistry/types/address_pair.pb.go new file mode 100644 index 00000000..c421d400 --- /dev/null +++ b/x/keyregistry/types/address_pair.pb.go @@ -0,0 +1,375 @@ +// Code generated by protoc-gen-gogo. DO NOT EDIT. +// source: pulsarchain/keyregistry/v1/address_pair.proto + +package types + +import ( + fmt "fmt" + io "io" + math "math" + math_bits "math/bits" + + proto "github.com/cosmos/gogoproto/proto" +) + +// Reference imports to suppress errors if they are not otherwise used. +var _ = proto.Marshal +var _ = fmt.Errorf +var _ = math.Inf + +// This is a compile-time assertion to ensure that this generated file +// is compatible with the proto package it is being compiled against. +// A compilation error at this line likely means your copy of the +// proto package needs to be updated. +const _ = proto.GoGoProtoPackageIsVersion3 // please upgrade the proto package + +type AddressPair struct { + MinaAddr []byte `protobuf:"bytes,1,opt,name=mina_addr,json=minaAddr,proto3" json:"mina_addr,omitempty"` + CosmosAddr []byte `protobuf:"bytes,2,opt,name=cosmos_addr,json=cosmosAddr,proto3" json:"cosmos_addr,omitempty"` +} + +func (m *AddressPair) Reset() { *m = AddressPair{} } +func (m *AddressPair) String() string { return proto.CompactTextString(m) } +func (*AddressPair) ProtoMessage() {} +func (*AddressPair) Descriptor() ([]byte, []int) { + return fileDescriptor_eb9cea5d1b988cd3, []int{0} +} +func (m *AddressPair) XXX_Unmarshal(b []byte) error { + return m.Unmarshal(b) +} +func (m *AddressPair) XXX_Marshal(b []byte, deterministic bool) ([]byte, error) { + if deterministic { + return xxx_messageInfo_AddressPair.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 *AddressPair) XXX_Merge(src proto.Message) { + xxx_messageInfo_AddressPair.Merge(m, src) +} +func (m *AddressPair) XXX_Size() int { + return m.Size() +} +func (m *AddressPair) XXX_DiscardUnknown() { + xxx_messageInfo_AddressPair.DiscardUnknown(m) +} + +var xxx_messageInfo_AddressPair proto.InternalMessageInfo + +func (m *AddressPair) GetMinaAddr() []byte { + if m != nil { + return m.MinaAddr + } + return nil +} + +func (m *AddressPair) GetCosmosAddr() []byte { + if m != nil { + return m.CosmosAddr + } + return nil +} + +func init() { + proto.RegisterType((*AddressPair)(nil), "pulsarchain.keyregistry.v1.AddressPair") +} + +func init() { + proto.RegisterFile("pulsarchain/keyregistry/v1/address_pair.proto", fileDescriptor_eb9cea5d1b988cd3) +} + +var fileDescriptor_eb9cea5d1b988cd3 = []byte{ + // 206 bytes of a gzipped FileDescriptorProto + 0x1f, 0x8b, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0xff, 0xe2, 0xd2, 0x2d, 0x28, 0xcd, 0x29, + 0x4e, 0x2c, 0x4a, 0xce, 0x48, 0xcc, 0xcc, 0xd3, 0xcf, 0x4e, 0xad, 0x2c, 0x4a, 0x4d, 0xcf, 0x2c, + 0x2e, 0x29, 0xaa, 0xd4, 0x2f, 0x33, 0xd4, 0x4f, 0x4c, 0x49, 0x29, 0x4a, 0x2d, 0x2e, 0x8e, 0x2f, + 0x48, 0xcc, 0x2c, 0xd2, 0x2b, 0x28, 0xca, 0x2f, 0xc9, 0x17, 0x92, 0x42, 0x52, 0xae, 0x87, 0xa4, + 0x5c, 0xaf, 0xcc, 0x50, 0xc9, 0x9b, 0x8b, 0xdb, 0x11, 0xa2, 0x23, 0x20, 0x31, 0xb3, 0x48, 0x48, + 0x9a, 0x8b, 0x33, 0x37, 0x33, 0x2f, 0x31, 0x1e, 0x64, 0x8a, 0x04, 0xa3, 0x02, 0xa3, 0x06, 0x4f, + 0x10, 0x07, 0x48, 0x00, 0xa4, 0x46, 0x48, 0x9e, 0x8b, 0x3b, 0x39, 0xbf, 0x38, 0x37, 0xbf, 0x18, + 0x22, 0xcd, 0x04, 0x96, 0xe6, 0x82, 0x08, 0x81, 0x14, 0x38, 0x05, 0x9c, 0x78, 0x24, 0xc7, 0x78, + 0xe1, 0x91, 0x1c, 0xe3, 0x83, 0x47, 0x72, 0x8c, 0x13, 0x1e, 0xcb, 0x31, 0x5c, 0x78, 0x2c, 0xc7, + 0x70, 0xe3, 0xb1, 0x1c, 0x43, 0x94, 0x59, 0x7a, 0x66, 0x49, 0x46, 0x69, 0x92, 0x5e, 0x72, 0x7e, + 0xae, 0x7e, 0x5e, 0x7e, 0x4a, 0xaa, 0xa1, 0x81, 0xa1, 0x6e, 0x66, 0xbe, 0x3e, 0xc4, 0x61, 0xba, + 0x10, 0x8f, 0x54, 0xa0, 0x78, 0xa5, 0xa4, 0xb2, 0x20, 0xb5, 0x38, 0x89, 0x0d, 0xec, 0x03, 0x63, + 0x40, 0x00, 0x00, 0x00, 0xff, 0xff, 0x32, 0x26, 0x7c, 0xb2, 0xf2, 0x00, 0x00, 0x00, +} + +func (m *AddressPair) 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 *AddressPair) MarshalTo(dAtA []byte) (int, error) { + size := m.Size() + return m.MarshalToSizedBuffer(dAtA[:size]) +} + +func (m *AddressPair) MarshalToSizedBuffer(dAtA []byte) (int, error) { + i := len(dAtA) + _ = i + var l int + _ = l + if len(m.CosmosAddr) > 0 { + i -= len(m.CosmosAddr) + copy(dAtA[i:], m.CosmosAddr) + i = encodeVarintAddressPair(dAtA, i, uint64(len(m.CosmosAddr))) + i-- + dAtA[i] = 0x12 + } + if len(m.MinaAddr) > 0 { + i -= len(m.MinaAddr) + copy(dAtA[i:], m.MinaAddr) + i = encodeVarintAddressPair(dAtA, i, uint64(len(m.MinaAddr))) + i-- + dAtA[i] = 0xa + } + return len(dAtA) - i, nil +} + +func encodeVarintAddressPair(dAtA []byte, offset int, v uint64) int { + offset -= sovAddressPair(v) + base := offset + for v >= 1<<7 { + dAtA[offset] = uint8(v&0x7f | 0x80) + v >>= 7 + offset++ + } + dAtA[offset] = uint8(v) + return base +} +func (m *AddressPair) Size() (n int) { + if m == nil { + return 0 + } + var l int + _ = l + l = len(m.MinaAddr) + if l > 0 { + n += 1 + l + sovAddressPair(uint64(l)) + } + l = len(m.CosmosAddr) + if l > 0 { + n += 1 + l + sovAddressPair(uint64(l)) + } + return n +} + +func sovAddressPair(x uint64) (n int) { + return (math_bits.Len64(x|1) + 6) / 7 +} +func sozAddressPair(x uint64) (n int) { + return sovAddressPair(uint64((x << 1) ^ uint64((int64(x) >> 63)))) +} +func (m *AddressPair) 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 ErrIntOverflowAddressPair + } + 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: AddressPair: wiretype end group for non-group") + } + if fieldNum <= 0 { + return fmt.Errorf("proto: AddressPair: illegal tag %d (wire type %d)", fieldNum, wire) + } + switch fieldNum { + case 1: + if wireType != 2 { + return fmt.Errorf("proto: wrong wireType = %d for field MinaAddr", wireType) + } + var byteLen int + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowAddressPair + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + byteLen |= int(b&0x7F) << shift + if b < 0x80 { + break + } + } + if byteLen < 0 { + return ErrInvalidLengthAddressPair + } + postIndex := iNdEx + byteLen + if postIndex < 0 { + return ErrInvalidLengthAddressPair + } + if postIndex > l { + return io.ErrUnexpectedEOF + } + m.MinaAddr = append(m.MinaAddr[:0], dAtA[iNdEx:postIndex]...) + if m.MinaAddr == nil { + m.MinaAddr = []byte{} + } + iNdEx = postIndex + case 2: + if wireType != 2 { + return fmt.Errorf("proto: wrong wireType = %d for field CosmosAddr", wireType) + } + var byteLen int + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowAddressPair + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + byteLen |= int(b&0x7F) << shift + if b < 0x80 { + break + } + } + if byteLen < 0 { + return ErrInvalidLengthAddressPair + } + postIndex := iNdEx + byteLen + if postIndex < 0 { + return ErrInvalidLengthAddressPair + } + if postIndex > l { + return io.ErrUnexpectedEOF + } + m.CosmosAddr = append(m.CosmosAddr[:0], dAtA[iNdEx:postIndex]...) + if m.CosmosAddr == nil { + m.CosmosAddr = []byte{} + } + iNdEx = postIndex + default: + iNdEx = preIndex + skippy, err := skipAddressPair(dAtA[iNdEx:]) + if err != nil { + return err + } + if (skippy < 0) || (iNdEx+skippy) < 0 { + return ErrInvalidLengthAddressPair + } + if (iNdEx + skippy) > l { + return io.ErrUnexpectedEOF + } + iNdEx += skippy + } + } + + if iNdEx > l { + return io.ErrUnexpectedEOF + } + return nil +} +func skipAddressPair(dAtA []byte) (n int, err error) { + l := len(dAtA) + iNdEx := 0 + depth := 0 + for iNdEx < l { + var wire uint64 + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return 0, ErrIntOverflowAddressPair + } + if iNdEx >= l { + return 0, io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + wire |= (uint64(b) & 0x7F) << shift + if b < 0x80 { + break + } + } + wireType := int(wire & 0x7) + switch wireType { + case 0: + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return 0, ErrIntOverflowAddressPair + } + if iNdEx >= l { + return 0, io.ErrUnexpectedEOF + } + iNdEx++ + if dAtA[iNdEx-1] < 0x80 { + break + } + } + case 1: + iNdEx += 8 + case 2: + var length int + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return 0, ErrIntOverflowAddressPair + } + if iNdEx >= l { + return 0, io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + length |= (int(b) & 0x7F) << shift + if b < 0x80 { + break + } + } + if length < 0 { + return 0, ErrInvalidLengthAddressPair + } + iNdEx += length + case 3: + depth++ + case 4: + if depth == 0 { + return 0, ErrUnexpectedEndOfGroupAddressPair + } + depth-- + case 5: + iNdEx += 4 + default: + return 0, fmt.Errorf("proto: illegal wireType %d", wireType) + } + if iNdEx < 0 { + return 0, ErrInvalidLengthAddressPair + } + if depth == 0 { + return iNdEx, nil + } + } + return 0, io.ErrUnexpectedEOF +} + +var ( + ErrInvalidLengthAddressPair = fmt.Errorf("proto: negative length found during unmarshaling") + ErrIntOverflowAddressPair = fmt.Errorf("proto: integer overflow") + ErrUnexpectedEndOfGroupAddressPair = fmt.Errorf("proto: unexpected end of group") +) diff --git a/x/keyregistry/types/genesis.pb.go b/x/keyregistry/types/genesis.pb.go index 38980463..892df56a 100644 --- a/x/keyregistry/types/genesis.pb.go +++ b/x/keyregistry/types/genesis.pb.go @@ -5,12 +5,13 @@ package types import ( fmt "fmt" - _ "github.com/cosmos/cosmos-sdk/types/tx/amino" - _ "github.com/cosmos/gogoproto/gogoproto" - proto "github.com/cosmos/gogoproto/proto" io "io" math "math" math_bits "math/bits" + + _ "github.com/cosmos/cosmos-sdk/types/tx/amino" + _ "github.com/cosmos/gogoproto/gogoproto" + proto "github.com/cosmos/gogoproto/proto" ) // Reference imports to suppress errors if they are not otherwise used. diff --git a/x/keyregistry/types/module.pb.go b/x/keyregistry/types/module.pb.go index c42802f0..6c939884 100644 --- a/x/keyregistry/types/module.pb.go +++ b/x/keyregistry/types/module.pb.go @@ -4,12 +4,13 @@ package types import ( - _ "cosmossdk.io/api/cosmos/app/v1alpha1" fmt "fmt" - proto "github.com/cosmos/gogoproto/proto" io "io" math "math" math_bits "math/bits" + + _ "cosmossdk.io/api/cosmos/app/v1alpha1" + proto "github.com/cosmos/gogoproto/proto" ) // Reference imports to suppress errors if they are not otherwise used. diff --git a/x/keyregistry/types/params.pb.go b/x/keyregistry/types/params.pb.go index 378f92bb..083d03b5 100644 --- a/x/keyregistry/types/params.pb.go +++ b/x/keyregistry/types/params.pb.go @@ -5,12 +5,13 @@ package types import ( fmt "fmt" - _ "github.com/cosmos/cosmos-sdk/types/tx/amino" - _ "github.com/cosmos/gogoproto/gogoproto" - proto "github.com/cosmos/gogoproto/proto" io "io" math "math" math_bits "math/bits" + + _ "github.com/cosmos/cosmos-sdk/types/tx/amino" + _ "github.com/cosmos/gogoproto/gogoproto" + proto "github.com/cosmos/gogoproto/proto" ) // Reference imports to suppress errors if they are not otherwise used. diff --git a/x/keyregistry/types/public_key_pair.pb.go b/x/keyregistry/types/public_key_pair.pb.go index db1d3fc2..4f1401fb 100644 --- a/x/keyregistry/types/public_key_pair.pb.go +++ b/x/keyregistry/types/public_key_pair.pb.go @@ -5,10 +5,11 @@ package types import ( fmt "fmt" - proto "github.com/cosmos/gogoproto/proto" io "io" math "math" math_bits "math/bits" + + proto "github.com/cosmos/gogoproto/proto" ) // Reference imports to suppress errors if they are not otherwise used. diff --git a/x/keyregistry/types/query.pb.go b/x/keyregistry/types/query.pb.go index e529ad88..d45dfd2b 100644 --- a/x/keyregistry/types/query.pb.go +++ b/x/keyregistry/types/query.pb.go @@ -6,6 +6,10 @@ package types import ( context "context" fmt "fmt" + io "io" + math "math" + math_bits "math/bits" + _ "github.com/cosmos/cosmos-sdk/types/query" _ "github.com/cosmos/cosmos-sdk/types/tx/amino" _ "github.com/cosmos/gogoproto/gogoproto" @@ -15,9 +19,6 @@ import ( grpc "google.golang.org/grpc" codes "google.golang.org/grpc/codes" status "google.golang.org/grpc/status" - io "io" - math "math" - math_bits "math/bits" ) // Reference imports to suppress errors if they are not otherwise used. diff --git a/x/keyregistry/types/tx.pb.go b/x/keyregistry/types/tx.pb.go index b0b00dec..d94eed74 100644 --- a/x/keyregistry/types/tx.pb.go +++ b/x/keyregistry/types/tx.pb.go @@ -6,6 +6,10 @@ package types import ( context "context" fmt "fmt" + io "io" + math "math" + math_bits "math/bits" + _ "github.com/cosmos/cosmos-proto" _ "github.com/cosmos/cosmos-sdk/types/msgservice" _ "github.com/cosmos/cosmos-sdk/types/tx/amino" @@ -15,9 +19,6 @@ import ( grpc "google.golang.org/grpc" codes "google.golang.org/grpc/codes" status "google.golang.org/grpc/status" - io "io" - math "math" - math_bits "math/bits" ) // Reference imports to suppress errors if they are not otherwise used. diff --git a/x/pulsar/types/genesis.pb.go b/x/pulsar/types/genesis.pb.go index acfbe019..65be9de9 100644 --- a/x/pulsar/types/genesis.pb.go +++ b/x/pulsar/types/genesis.pb.go @@ -5,12 +5,13 @@ package types import ( fmt "fmt" - _ "github.com/cosmos/cosmos-sdk/types/tx/amino" - _ "github.com/cosmos/gogoproto/gogoproto" - proto "github.com/cosmos/gogoproto/proto" io "io" math "math" math_bits "math/bits" + + _ "github.com/cosmos/cosmos-sdk/types/tx/amino" + _ "github.com/cosmos/gogoproto/gogoproto" + proto "github.com/cosmos/gogoproto/proto" ) // Reference imports to suppress errors if they are not otherwise used. diff --git a/x/pulsar/types/module.pb.go b/x/pulsar/types/module.pb.go index b7ffd5c3..eeab9504 100644 --- a/x/pulsar/types/module.pb.go +++ b/x/pulsar/types/module.pb.go @@ -4,12 +4,13 @@ package types import ( - _ "cosmossdk.io/api/cosmos/app/v1alpha1" fmt "fmt" - proto "github.com/cosmos/gogoproto/proto" io "io" math "math" math_bits "math/bits" + + _ "cosmossdk.io/api/cosmos/app/v1alpha1" + proto "github.com/cosmos/gogoproto/proto" ) // Reference imports to suppress errors if they are not otherwise used. diff --git a/x/pulsar/types/params.pb.go b/x/pulsar/types/params.pb.go index 0480a17b..e7a05515 100644 --- a/x/pulsar/types/params.pb.go +++ b/x/pulsar/types/params.pb.go @@ -5,12 +5,13 @@ package types import ( fmt "fmt" - _ "github.com/cosmos/cosmos-sdk/types/tx/amino" - _ "github.com/cosmos/gogoproto/gogoproto" - proto "github.com/cosmos/gogoproto/proto" io "io" math "math" math_bits "math/bits" + + _ "github.com/cosmos/cosmos-sdk/types/tx/amino" + _ "github.com/cosmos/gogoproto/gogoproto" + proto "github.com/cosmos/gogoproto/proto" ) // Reference imports to suppress errors if they are not otherwise used. diff --git a/x/pulsar/types/query.pb.go b/x/pulsar/types/query.pb.go index 0c09f00a..8df04fb5 100644 --- a/x/pulsar/types/query.pb.go +++ b/x/pulsar/types/query.pb.go @@ -6,6 +6,10 @@ package types import ( context "context" fmt "fmt" + io "io" + math "math" + math_bits "math/bits" + _ "github.com/cosmos/cosmos-sdk/types/query" _ "github.com/cosmos/cosmos-sdk/types/tx/amino" _ "github.com/cosmos/gogoproto/gogoproto" @@ -15,9 +19,6 @@ import ( grpc "google.golang.org/grpc" codes "google.golang.org/grpc/codes" status "google.golang.org/grpc/status" - io "io" - math "math" - math_bits "math/bits" ) // Reference imports to suppress errors if they are not otherwise used. diff --git a/x/pulsar/types/tx.pb.go b/x/pulsar/types/tx.pb.go index e3271589..2f343e52 100644 --- a/x/pulsar/types/tx.pb.go +++ b/x/pulsar/types/tx.pb.go @@ -6,6 +6,10 @@ package types import ( context "context" fmt "fmt" + io "io" + math "math" + math_bits "math/bits" + _ "github.com/cosmos/cosmos-proto" _ "github.com/cosmos/cosmos-sdk/types/msgservice" _ "github.com/cosmos/cosmos-sdk/types/tx/amino" @@ -15,9 +19,6 @@ import ( grpc "google.golang.org/grpc" codes "google.golang.org/grpc/codes" status "google.golang.org/grpc/status" - io "io" - math "math" - math_bits "math/bits" ) // Reference imports to suppress errors if they are not otherwise used. diff --git a/x/votepersistence/keeper/genesis.go b/x/votepersistence/keeper/genesis.go new file mode 100644 index 00000000..5b53e605 --- /dev/null +++ b/x/votepersistence/keeper/genesis.go @@ -0,0 +1,25 @@ +package keeper + +import ( + "context" + + "github.com/node101-io/pulsar-chain/x/votepersistence/types" +) + +// InitGenesis initializes the module's state from a provided genesis state. +func (k Keeper) InitGenesis(ctx context.Context, genState types.GenesisState) error { + return k.Params.Set(ctx, genState.Params) +} + +// ExportGenesis returns the module's exported genesis. +func (k Keeper) ExportGenesis(ctx context.Context) (*types.GenesisState, error) { + var err error + + genesis := types.DefaultGenesis() + genesis.Params, err = k.Params.Get(ctx) + if err != nil { + return nil, err + } + + return genesis, nil +} diff --git a/x/votepersistence/keeper/genesis_test.go b/x/votepersistence/keeper/genesis_test.go new file mode 100644 index 00000000..ecfbbac5 --- /dev/null +++ b/x/votepersistence/keeper/genesis_test.go @@ -0,0 +1,24 @@ +package keeper_test + +import ( + "testing" + + "github.com/node101-io/pulsar-chain/x/votepersistence/types" + + "github.com/stretchr/testify/require" +) + +func TestGenesis(t *testing.T) { + genesisState := types.GenesisState{ + Params: types.DefaultParams(), + } + + f := initFixture(t) + err := f.keeper.InitGenesis(f.ctx, genesisState) + require.NoError(t, err) + got, err := f.keeper.ExportGenesis(f.ctx) + require.NoError(t, err) + require.NotNil(t, got) + + require.EqualExportedValues(t, genesisState.Params, got.Params) +} diff --git a/x/votepersistence/keeper/keeper.go b/x/votepersistence/keeper/keeper.go new file mode 100644 index 00000000..ea31ae1c --- /dev/null +++ b/x/votepersistence/keeper/keeper.go @@ -0,0 +1,60 @@ +package keeper + +import ( + "fmt" + + "cosmossdk.io/collections" + "cosmossdk.io/core/address" + corestore "cosmossdk.io/core/store" + "github.com/cosmos/cosmos-sdk/codec" + + "github.com/node101-io/pulsar-chain/x/votepersistence/types" +) + +type Keeper struct { + storeService corestore.KVStoreService + cdc codec.Codec + addressCodec address.Codec + // Address capable of executing a MsgUpdateParams message. + // Typically, this should be the x/gov module account. + authority []byte + + Schema collections.Schema + Params collections.Item[types.Params] +} + +func NewKeeper( + storeService corestore.KVStoreService, + cdc codec.Codec, + addressCodec address.Codec, + authority []byte, + +) Keeper { + if _, err := addressCodec.BytesToString(authority); err != nil { + panic(fmt.Sprintf("invalid authority address %s: %s", authority, err)) + } + + sb := collections.NewSchemaBuilder(storeService) + + k := Keeper{ + storeService: storeService, + cdc: cdc, + addressCodec: addressCodec, + authority: authority, + + Params: collections.NewItem(sb, types.ParamsKey, "params", codec.CollValue[types.Params](cdc)), + } + + schema, err := sb.Build() + if err != nil { + panic(err) + } + k.Schema = schema + + return k +} + +// GetAuthority returns the module's authority. +func (k Keeper) GetAuthority() []byte { + return k.authority +} diff --git a/x/votepersistence/keeper/keeper_test.go b/x/votepersistence/keeper/keeper_test.go new file mode 100644 index 00000000..250ed52c --- /dev/null +++ b/x/votepersistence/keeper/keeper_test.go @@ -0,0 +1,56 @@ +package keeper_test + +import ( + "context" + "testing" + + "cosmossdk.io/core/address" + storetypes "cosmossdk.io/store/types" + addresscodec "github.com/cosmos/cosmos-sdk/codec/address" + "github.com/cosmos/cosmos-sdk/runtime" + "github.com/cosmos/cosmos-sdk/testutil" + sdk "github.com/cosmos/cosmos-sdk/types" + moduletestutil "github.com/cosmos/cosmos-sdk/types/module/testutil" + authtypes "github.com/cosmos/cosmos-sdk/x/auth/types" + + "github.com/node101-io/pulsar-chain/x/votepersistence/keeper" + module "github.com/node101-io/pulsar-chain/x/votepersistence/module" + "github.com/node101-io/pulsar-chain/x/votepersistence/types" +) + +type fixture struct { + ctx context.Context + keeper keeper.Keeper + addressCodec address.Codec +} + +func initFixture(t *testing.T) *fixture { + t.Helper() + + encCfg := moduletestutil.MakeTestEncodingConfig(module.AppModule{}) + addressCodec := addresscodec.NewBech32Codec(sdk.GetConfig().GetBech32AccountAddrPrefix()) + storeKey := storetypes.NewKVStoreKey(types.StoreKey) + + storeService := runtime.NewKVStoreService(storeKey) + ctx := testutil.DefaultContextWithDB(t, storeKey, storetypes.NewTransientStoreKey("transient_test")).Ctx + + authority := authtypes.NewModuleAddress(types.GovModuleName) + + k := keeper.NewKeeper( + storeService, + encCfg.Codec, + addressCodec, + authority, + ) + + // Initialize params + if err := k.Params.Set(ctx, types.DefaultParams()); err != nil { + t.Fatalf("failed to set params: %v", err) + } + + return &fixture{ + ctx: ctx, + keeper: k, + addressCodec: addressCodec, + } +} diff --git a/x/votepersistence/keeper/msg_server.go b/x/votepersistence/keeper/msg_server.go new file mode 100644 index 00000000..5e538c2f --- /dev/null +++ b/x/votepersistence/keeper/msg_server.go @@ -0,0 +1,17 @@ +package keeper + +import ( + "github.com/node101-io/pulsar-chain/x/votepersistence/types" +) + +type msgServer struct { + Keeper +} + +// NewMsgServerImpl returns an implementation of the MsgServer interface +// for the provided Keeper. +func NewMsgServerImpl(keeper Keeper) types.MsgServer { + return &msgServer{Keeper: keeper} +} + +var _ types.MsgServer = msgServer{} diff --git a/x/votepersistence/keeper/msg_update_params.go b/x/votepersistence/keeper/msg_update_params.go new file mode 100644 index 00000000..aef1db35 --- /dev/null +++ b/x/votepersistence/keeper/msg_update_params.go @@ -0,0 +1,32 @@ +package keeper + +import ( + "bytes" + "context" + + errorsmod "cosmossdk.io/errors" + + "github.com/node101-io/pulsar-chain/x/votepersistence/types" +) + +func (k msgServer) UpdateParams(ctx context.Context, req *types.MsgUpdateParams) (*types.MsgUpdateParamsResponse, error) { + authority, err := k.addressCodec.StringToBytes(req.Authority) + if err != nil { + return nil, errorsmod.Wrap(err, "invalid authority address") + } + + if !bytes.Equal(k.GetAuthority(), authority) { + expectedAuthorityStr, _ := k.addressCodec.BytesToString(k.GetAuthority()) + return nil, errorsmod.Wrapf(types.ErrInvalidSigner, "invalid authority; expected %s, got %s", expectedAuthorityStr, req.Authority) + } + + if err := req.Params.Validate(); err != nil { + return nil, err + } + + if err := k.Params.Set(ctx, req.Params); err != nil { + return nil, err + } + + return &types.MsgUpdateParamsResponse{}, nil +} diff --git a/x/votepersistence/keeper/msg_update_params_test.go b/x/votepersistence/keeper/msg_update_params_test.go new file mode 100644 index 00000000..c9818916 --- /dev/null +++ b/x/votepersistence/keeper/msg_update_params_test.go @@ -0,0 +1,68 @@ +package keeper_test + +import ( + "testing" + + "github.com/stretchr/testify/require" + + "github.com/node101-io/pulsar-chain/x/votepersistence/keeper" + "github.com/node101-io/pulsar-chain/x/votepersistence/types" +) + +func TestMsgUpdateParams(t *testing.T) { + f := initFixture(t) + ms := keeper.NewMsgServerImpl(f.keeper) + + params := types.DefaultParams() + require.NoError(t, f.keeper.Params.Set(f.ctx, params)) + + authorityStr, err := f.addressCodec.BytesToString(f.keeper.GetAuthority()) + require.NoError(t, err) + + // default params + testCases := []struct { + name string + input *types.MsgUpdateParams + expErr bool + expErrMsg string + }{ + { + name: "invalid authority", + input: &types.MsgUpdateParams{ + Authority: "invalid", + Params: params, + }, + expErr: true, + expErrMsg: "invalid authority", + }, + { + name: "send enabled param", + input: &types.MsgUpdateParams{ + Authority: authorityStr, + Params: types.Params{}, + }, + expErr: false, + }, + { + name: "all good", + input: &types.MsgUpdateParams{ + Authority: authorityStr, + Params: params, + }, + expErr: false, + }, + } + + for _, tc := range testCases { + t.Run(tc.name, func(t *testing.T) { + _, err := ms.UpdateParams(f.ctx, tc.input) + + if tc.expErr { + require.Error(t, err) + require.Contains(t, err.Error(), tc.expErrMsg) + } else { + require.NoError(t, err) + } + }) + } +} diff --git a/x/votepersistence/keeper/query.go b/x/votepersistence/keeper/query.go new file mode 100644 index 00000000..58ad2a9e --- /dev/null +++ b/x/votepersistence/keeper/query.go @@ -0,0 +1,17 @@ +package keeper + +import ( + "github.com/node101-io/pulsar-chain/x/votepersistence/types" +) + +var _ types.QueryServer = queryServer{} + +// NewQueryServerImpl returns an implementation of the QueryServer interface +// for the provided Keeper. +func NewQueryServerImpl(k Keeper) types.QueryServer { + return queryServer{k} +} + +type queryServer struct { + k Keeper +} diff --git a/x/votepersistence/keeper/query_params.go b/x/votepersistence/keeper/query_params.go new file mode 100644 index 00000000..3c86597c --- /dev/null +++ b/x/votepersistence/keeper/query_params.go @@ -0,0 +1,26 @@ +package keeper + +import ( + "context" + "errors" + + "cosmossdk.io/collections" + + "google.golang.org/grpc/codes" + "google.golang.org/grpc/status" + + "github.com/node101-io/pulsar-chain/x/votepersistence/types" +) + +func (q queryServer) Params(ctx context.Context, req *types.QueryParamsRequest) (*types.QueryParamsResponse, error) { + if req == nil { + return nil, status.Error(codes.InvalidArgument, "invalid request") + } + + params, err := q.k.Params.Get(ctx) + if err != nil && !errors.Is(err, collections.ErrNotFound) { + return nil, status.Error(codes.Internal, "internal error") + } + + return &types.QueryParamsResponse{Params: params}, nil +} diff --git a/x/votepersistence/keeper/query_params_test.go b/x/votepersistence/keeper/query_params_test.go new file mode 100644 index 00000000..0df3eb53 --- /dev/null +++ b/x/votepersistence/keeper/query_params_test.go @@ -0,0 +1,22 @@ +package keeper_test + +import ( + "testing" + + "github.com/stretchr/testify/require" + + "github.com/node101-io/pulsar-chain/x/votepersistence/keeper" + "github.com/node101-io/pulsar-chain/x/votepersistence/types" +) + +func TestParamsQuery(t *testing.T) { + f := initFixture(t) + + qs := keeper.NewQueryServerImpl(f.keeper) + params := types.DefaultParams() + require.NoError(t, f.keeper.Params.Set(f.ctx, params)) + + response, err := qs.Params(f.ctx, &types.QueryParamsRequest{}) + require.NoError(t, err) + require.Equal(t, &types.QueryParamsResponse{Params: params}, response) +} diff --git a/x/votepersistence/module/autocli.go b/x/votepersistence/module/autocli.go new file mode 100644 index 00000000..6fc3fdaf --- /dev/null +++ b/x/votepersistence/module/autocli.go @@ -0,0 +1,35 @@ +package votepersistence + +import ( + autocliv1 "cosmossdk.io/api/cosmos/autocli/v1" + + "github.com/node101-io/pulsar-chain/x/votepersistence/types" +) + +// AutoCLIOptions implements the autocli.HasAutoCLIConfig interface. +func (am AppModule) AutoCLIOptions() *autocliv1.ModuleOptions { + return &autocliv1.ModuleOptions{ + Query: &autocliv1.ServiceCommandDescriptor{ + Service: types.Query_serviceDesc.ServiceName, + RpcCommandOptions: []*autocliv1.RpcCommandOptions{ + { + RpcMethod: "Params", + Use: "params", + Short: "Shows the parameters of the module", + }, + // this line is used by ignite scaffolding # autocli/query + }, + }, + Tx: &autocliv1.ServiceCommandDescriptor{ + Service: types.Msg_serviceDesc.ServiceName, + EnhanceCustomCommand: true, // only required if you want to use the custom command + RpcCommandOptions: []*autocliv1.RpcCommandOptions{ + { + RpcMethod: "UpdateParams", + Skip: true, // skipped because authority gated + }, + // this line is used by ignite scaffolding # autocli/tx + }, + }, + } +} diff --git a/x/votepersistence/module/depinject.go b/x/votepersistence/module/depinject.go new file mode 100644 index 00000000..5a393590 --- /dev/null +++ b/x/votepersistence/module/depinject.go @@ -0,0 +1,62 @@ +package votepersistence + +import ( + "cosmossdk.io/core/address" + "cosmossdk.io/core/appmodule" + "cosmossdk.io/core/store" + "cosmossdk.io/depinject" + "cosmossdk.io/depinject/appconfig" + "github.com/cosmos/cosmos-sdk/codec" + authtypes "github.com/cosmos/cosmos-sdk/x/auth/types" + + "github.com/node101-io/pulsar-chain/x/votepersistence/keeper" + "github.com/node101-io/pulsar-chain/x/votepersistence/types" +) + +var _ depinject.OnePerModuleType = AppModule{} + +// IsOnePerModuleType implements the depinject.OnePerModuleType interface. +func (AppModule) IsOnePerModuleType() {} + +func init() { + appconfig.Register( + &types.Module{}, + appconfig.Provide(ProvideModule), + ) +} + +type ModuleInputs struct { + depinject.In + + Config *types.Module + StoreService store.KVStoreService + Cdc codec.Codec + AddressCodec address.Codec + + AuthKeeper types.AuthKeeper + BankKeeper types.BankKeeper +} + +type ModuleOutputs struct { + depinject.Out + + VotepersistenceKeeper keeper.Keeper + Module appmodule.AppModule +} + +func ProvideModule(in ModuleInputs) ModuleOutputs { + // default to governance authority if not provided + authority := authtypes.NewModuleAddress(types.GovModuleName) + if in.Config.Authority != "" { + authority = authtypes.NewModuleAddressOrBech32Address(in.Config.Authority) + } + k := keeper.NewKeeper( + in.StoreService, + in.Cdc, + in.AddressCodec, + authority, + ) + m := NewAppModule(in.Cdc, k, in.AuthKeeper, in.BankKeeper) + + return ModuleOutputs{VotepersistenceKeeper: k, Module: m} +} diff --git a/x/votepersistence/module/module.go b/x/votepersistence/module/module.go new file mode 100644 index 00000000..b1918551 --- /dev/null +++ b/x/votepersistence/module/module.go @@ -0,0 +1,143 @@ +package votepersistence + +import ( + "context" + "encoding/json" + "fmt" + + "cosmossdk.io/core/appmodule" + "github.com/cosmos/cosmos-sdk/client" + "github.com/cosmos/cosmos-sdk/codec" + codectypes "github.com/cosmos/cosmos-sdk/codec/types" + sdk "github.com/cosmos/cosmos-sdk/types" + "github.com/cosmos/cosmos-sdk/types/module" + "github.com/grpc-ecosystem/grpc-gateway/runtime" + "google.golang.org/grpc" + + "github.com/node101-io/pulsar-chain/x/votepersistence/keeper" + "github.com/node101-io/pulsar-chain/x/votepersistence/types" +) + +var ( + _ module.AppModuleBasic = (*AppModule)(nil) + _ module.AppModule = (*AppModule)(nil) + _ module.HasGenesis = (*AppModule)(nil) + + _ appmodule.AppModule = (*AppModule)(nil) + _ appmodule.HasBeginBlocker = (*AppModule)(nil) + _ appmodule.HasEndBlocker = (*AppModule)(nil) +) + +// AppModule implements the AppModule interface that defines the inter-dependent methods that modules need to implement +type AppModule struct { + cdc codec.Codec + keeper keeper.Keeper + authKeeper types.AuthKeeper + bankKeeper types.BankKeeper +} + +func NewAppModule( + cdc codec.Codec, + keeper keeper.Keeper, + authKeeper types.AuthKeeper, + bankKeeper types.BankKeeper, +) AppModule { + return AppModule{ + cdc: cdc, + keeper: keeper, + authKeeper: authKeeper, + bankKeeper: bankKeeper, + } +} + +// IsAppModule implements the appmodule.AppModule interface. +func (AppModule) IsAppModule() {} + +// Name returns the name of the module as a string. +func (AppModule) Name() string { + return types.ModuleName +} + +// RegisterLegacyAminoCodec registers the amino codec +func (AppModule) RegisterLegacyAminoCodec(*codec.LegacyAmino) {} + +// RegisterGRPCGatewayRoutes registers the gRPC Gateway routes for the module. +func (AppModule) RegisterGRPCGatewayRoutes(clientCtx client.Context, mux *runtime.ServeMux) { + if err := types.RegisterQueryHandlerClient(clientCtx.CmdContext, mux, types.NewQueryClient(clientCtx)); err != nil { + panic(err) + } +} + +// RegisterInterfaces registers a module's interface types and their concrete implementations as proto.Message. +func (AppModule) RegisterInterfaces(registrar codectypes.InterfaceRegistry) { + types.RegisterInterfaces(registrar) +} + +// RegisterServices registers a gRPC query service to respond to the module-specific gRPC queries +func (am AppModule) RegisterServices(registrar grpc.ServiceRegistrar) error { + types.RegisterMsgServer(registrar, keeper.NewMsgServerImpl(am.keeper)) + types.RegisterQueryServer(registrar, keeper.NewQueryServerImpl(am.keeper)) + + return nil +} + +// DefaultGenesis returns a default GenesisState for the module, marshalled to json.RawMessage. +// The default GenesisState need to be defined by the module developer and is primarily used for testing. +func (am AppModule) DefaultGenesis(codec.JSONCodec) json.RawMessage { + return am.cdc.MustMarshalJSON(types.DefaultGenesis()) +} + +// ValidateGenesis used to validate the GenesisState, given in its json.RawMessage form. +func (am AppModule) ValidateGenesis(_ codec.JSONCodec, _ client.TxEncodingConfig, bz json.RawMessage) error { + var genState types.GenesisState + if err := am.cdc.UnmarshalJSON(bz, &genState); err != nil { + return fmt.Errorf("failed to unmarshal %s genesis state: %w", types.ModuleName, err) + } + + return genState.Validate() +} + +// InitGenesis performs the module's genesis initialization. It returns no validator updates. +func (am AppModule) InitGenesis(ctx sdk.Context, _ codec.JSONCodec, gs json.RawMessage) { + var genState types.GenesisState + // Initialize global index to index in genesis state + if err := am.cdc.UnmarshalJSON(gs, &genState); err != nil { + panic(fmt.Errorf("failed to unmarshal %s genesis state: %w", types.ModuleName, err)) + } + + if err := am.keeper.InitGenesis(ctx, genState); err != nil { + panic(fmt.Errorf("failed to initialize %s genesis state: %w", types.ModuleName, err)) + } +} + +// ExportGenesis returns the module's exported genesis state as raw JSON bytes. +func (am AppModule) ExportGenesis(ctx sdk.Context, _ codec.JSONCodec) json.RawMessage { + genState, err := am.keeper.ExportGenesis(ctx) + if err != nil { + panic(fmt.Errorf("failed to export %s genesis state: %w", types.ModuleName, err)) + } + + bz, err := am.cdc.MarshalJSON(genState) + if err != nil { + panic(fmt.Errorf("failed to marshal %s genesis state: %w", types.ModuleName, err)) + } + + return bz +} + +// ConsensusVersion is a sequence number for state-breaking change of the module. +// It should be incremented on each consensus-breaking change introduced by the module. +// To avoid wrong/empty versions, the initial version should be set to 1. +func (AppModule) ConsensusVersion() uint64 { return 1 } + +// BeginBlock contains the logic that is automatically triggered at the beginning of each block. +// The begin block implementation is optional. +func (am AppModule) BeginBlock(_ context.Context) error { + return nil +} + +// EndBlock contains the logic that is automatically triggered at the end of each block. +// The end block implementation is optional. +func (am AppModule) EndBlock(_ context.Context) error { + return nil +} diff --git a/x/votepersistence/module/simulation.go b/x/votepersistence/module/simulation.go new file mode 100644 index 00000000..2c2c708f --- /dev/null +++ b/x/votepersistence/module/simulation.go @@ -0,0 +1,34 @@ +package votepersistence + +import ( + "github.com/cosmos/cosmos-sdk/types/module" + simtypes "github.com/cosmos/cosmos-sdk/types/simulation" + + "github.com/node101-io/pulsar-chain/x/votepersistence/types" +) + +// GenerateGenesisState creates a randomized GenState of the module. +func (AppModule) GenerateGenesisState(simState *module.SimulationState) { + accs := make([]string, len(simState.Accounts)) + for i, acc := range simState.Accounts { + accs[i] = acc.Address.String() + } + votepersistenceGenesis := types.GenesisState{ + Params: types.DefaultParams(), + } + simState.GenState[types.ModuleName] = simState.Cdc.MustMarshalJSON(&votepersistenceGenesis) +} + +// RegisterStoreDecoder registers a decoder. +func (am AppModule) RegisterStoreDecoder(_ simtypes.StoreDecoderRegistry) {} + +// WeightedOperations returns the all the gov module operations with their respective weights. +func (am AppModule) WeightedOperations(simState module.SimulationState) []simtypes.WeightedOperation { + operations := make([]simtypes.WeightedOperation, 0) + return operations +} + +// ProposalMsgs returns msgs used for governance proposals for simulations. +func (am AppModule) ProposalMsgs(simState module.SimulationState) []simtypes.WeightedProposalMsg { + return []simtypes.WeightedProposalMsg{} +} diff --git a/x/votepersistence/types/codec.go b/x/votepersistence/types/codec.go new file mode 100644 index 00000000..56398f5e --- /dev/null +++ b/x/votepersistence/types/codec.go @@ -0,0 +1,14 @@ +package types + +import ( + codectypes "github.com/cosmos/cosmos-sdk/codec/types" + sdk "github.com/cosmos/cosmos-sdk/types" + "github.com/cosmos/cosmos-sdk/types/msgservice" +) + +func RegisterInterfaces(registrar codectypes.InterfaceRegistry) { + registrar.RegisterImplementations((*sdk.Msg)(nil), + &MsgUpdateParams{}, + ) + msgservice.RegisterMsgServiceDesc(registrar, &_Msg_serviceDesc) +} diff --git a/x/votepersistence/types/errors.go b/x/votepersistence/types/errors.go new file mode 100644 index 00000000..c489914c --- /dev/null +++ b/x/votepersistence/types/errors.go @@ -0,0 +1,12 @@ +package types + +// DONTCOVER + +import ( + "cosmossdk.io/errors" +) + +// x/votepersistence module sentinel errors +var ( + ErrInvalidSigner = errors.Register(ModuleName, 1100, "expected gov account as only signer for proposal message") +) diff --git a/x/votepersistence/types/expected_keepers.go b/x/votepersistence/types/expected_keepers.go new file mode 100644 index 00000000..b175461c --- /dev/null +++ b/x/votepersistence/types/expected_keepers.go @@ -0,0 +1,27 @@ +package types + +import ( + "context" + + "cosmossdk.io/core/address" + sdk "github.com/cosmos/cosmos-sdk/types" +) + +// AuthKeeper defines the expected interface for the Auth module. +type AuthKeeper interface { + AddressCodec() address.Codec + GetAccount(context.Context, sdk.AccAddress) sdk.AccountI // only used for simulation + // Methods imported from account should be defined here +} + +// BankKeeper defines the expected interface for the Bank module. +type BankKeeper interface { + SpendableCoins(context.Context, sdk.AccAddress) sdk.Coins + // Methods imported from bank should be defined here +} + +// ParamSubspace defines the expected Subspace interface for parameters. +type ParamSubspace interface { + Get(context.Context, []byte, interface{}) + Set(context.Context, []byte, interface{}) +} diff --git a/x/votepersistence/types/genesis.go b/x/votepersistence/types/genesis.go new file mode 100644 index 00000000..9d633ecd --- /dev/null +++ b/x/votepersistence/types/genesis.go @@ -0,0 +1,14 @@ +package types + +// DefaultGenesis returns the default genesis state +func DefaultGenesis() *GenesisState { + return &GenesisState{ + Params: DefaultParams(), + } +} + +// Validate performs basic genesis state validation returning an error upon any +// failure. +func (gs GenesisState) Validate() error { + return gs.Params.Validate() +} diff --git a/x/votepersistence/types/genesis.pb.go b/x/votepersistence/types/genesis.pb.go new file mode 100644 index 00000000..9c48d742 --- /dev/null +++ b/x/votepersistence/types/genesis.pb.go @@ -0,0 +1,328 @@ +// Code generated by protoc-gen-gogo. DO NOT EDIT. +// source: pulsarchain/votepersistence/v1/genesis.proto + +package types + +import ( + fmt "fmt" + io "io" + math "math" + math_bits "math/bits" + + _ "github.com/cosmos/cosmos-sdk/types/tx/amino" + _ "github.com/cosmos/gogoproto/gogoproto" + proto "github.com/cosmos/gogoproto/proto" +) + +// Reference imports to suppress errors if they are not otherwise used. +var _ = proto.Marshal +var _ = fmt.Errorf +var _ = math.Inf + +// This is a compile-time assertion to ensure that this generated file +// is compatible with the proto package it is being compiled against. +// A compilation error at this line likely means your copy of the +// proto package needs to be updated. +const _ = proto.GoGoProtoPackageIsVersion3 // please upgrade the proto package + +// GenesisState defines the votepersistence module's genesis state. +type GenesisState struct { + // params defines all the parameters of the module. + Params Params `protobuf:"bytes,1,opt,name=params,proto3" json:"params"` +} + +func (m *GenesisState) Reset() { *m = GenesisState{} } +func (m *GenesisState) String() string { return proto.CompactTextString(m) } +func (*GenesisState) ProtoMessage() {} +func (*GenesisState) Descriptor() ([]byte, []int) { + return fileDescriptor_1055d46b0af7944d, []int{0} +} +func (m *GenesisState) XXX_Unmarshal(b []byte) error { + return m.Unmarshal(b) +} +func (m *GenesisState) XXX_Marshal(b []byte, deterministic bool) ([]byte, error) { + if deterministic { + return xxx_messageInfo_GenesisState.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 *GenesisState) XXX_Merge(src proto.Message) { + xxx_messageInfo_GenesisState.Merge(m, src) +} +func (m *GenesisState) XXX_Size() int { + return m.Size() +} +func (m *GenesisState) XXX_DiscardUnknown() { + xxx_messageInfo_GenesisState.DiscardUnknown(m) +} + +var xxx_messageInfo_GenesisState proto.InternalMessageInfo + +func (m *GenesisState) GetParams() Params { + if m != nil { + return m.Params + } + return Params{} +} + +func init() { + proto.RegisterType((*GenesisState)(nil), "pulsarchain.votepersistence.v1.GenesisState") +} + +func init() { + proto.RegisterFile("pulsarchain/votepersistence/v1/genesis.proto", fileDescriptor_1055d46b0af7944d) +} + +var fileDescriptor_1055d46b0af7944d = []byte{ + // 234 bytes of a gzipped FileDescriptorProto + 0x1f, 0x8b, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0xff, 0xe2, 0xd2, 0x29, 0x28, 0xcd, 0x29, + 0x4e, 0x2c, 0x4a, 0xce, 0x48, 0xcc, 0xcc, 0xd3, 0x2f, 0xcb, 0x2f, 0x49, 0x2d, 0x48, 0x2d, 0x2a, + 0xce, 0x2c, 0x2e, 0x49, 0xcd, 0x4b, 0x4e, 0xd5, 0x2f, 0x33, 0xd4, 0x4f, 0x4f, 0xcd, 0x4b, 0x2d, + 0xce, 0x2c, 0xd6, 0x2b, 0x28, 0xca, 0x2f, 0xc9, 0x17, 0x92, 0x43, 0x52, 0xad, 0x87, 0xa6, 0x5a, + 0xaf, 0xcc, 0x50, 0x4a, 0x30, 0x31, 0x37, 0x33, 0x2f, 0x5f, 0x1f, 0x4c, 0x42, 0xb4, 0x48, 0x89, + 0xa4, 0xe7, 0xa7, 0xe7, 0x83, 0x99, 0xfa, 0x20, 0x16, 0x54, 0x54, 0x9b, 0x80, 0xb5, 0x05, 0x89, + 0x45, 0x89, 0xb9, 0x50, 0x5b, 0x95, 0x22, 0xb9, 0x78, 0xdc, 0x21, 0xce, 0x08, 0x2e, 0x49, 0x2c, + 0x49, 0x15, 0xf2, 0xe4, 0x62, 0x83, 0xc8, 0x4b, 0x30, 0x2a, 0x30, 0x6a, 0x70, 0x1b, 0xa9, 0xe9, + 0xe1, 0x77, 0x96, 0x5e, 0x00, 0x58, 0xb5, 0x13, 0xe7, 0x89, 0x7b, 0xf2, 0x0c, 0x2b, 0x9e, 0x6f, + 0xd0, 0x62, 0x0c, 0x82, 0x1a, 0xe0, 0x14, 0x72, 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, 0x56, 0xe9, 0x99, 0x25, 0x19, 0xa5, 0x49, 0x7a, 0xc9, 0xf9, 0xb9, 0xfa, 0x79, 0xf9, + 0x29, 0xa9, 0x86, 0x06, 0x86, 0xba, 0x99, 0xf9, 0xfa, 0x10, 0x9b, 0x74, 0x21, 0x0e, 0xaf, 0xc0, + 0x70, 0x7a, 0x49, 0x65, 0x41, 0x6a, 0x71, 0x12, 0x1b, 0xd8, 0xdd, 0xc6, 0x80, 0x00, 0x00, 0x00, + 0xff, 0xff, 0x14, 0x23, 0xa4, 0xc5, 0x5d, 0x01, 0x00, 0x00, +} + +func (m *GenesisState) 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 *GenesisState) MarshalTo(dAtA []byte) (int, error) { + size := m.Size() + return m.MarshalToSizedBuffer(dAtA[:size]) +} + +func (m *GenesisState) MarshalToSizedBuffer(dAtA []byte) (int, error) { + i := len(dAtA) + _ = i + var l int + _ = l + { + size, err := m.Params.MarshalToSizedBuffer(dAtA[:i]) + if err != nil { + return 0, err + } + i -= size + i = encodeVarintGenesis(dAtA, i, uint64(size)) + } + i-- + dAtA[i] = 0xa + return len(dAtA) - i, nil +} + +func encodeVarintGenesis(dAtA []byte, offset int, v uint64) int { + offset -= sovGenesis(v) + base := offset + for v >= 1<<7 { + dAtA[offset] = uint8(v&0x7f | 0x80) + v >>= 7 + offset++ + } + dAtA[offset] = uint8(v) + return base +} +func (m *GenesisState) Size() (n int) { + if m == nil { + return 0 + } + var l int + _ = l + l = m.Params.Size() + n += 1 + l + sovGenesis(uint64(l)) + return n +} + +func sovGenesis(x uint64) (n int) { + return (math_bits.Len64(x|1) + 6) / 7 +} +func sozGenesis(x uint64) (n int) { + return sovGenesis(uint64((x << 1) ^ uint64((int64(x) >> 63)))) +} +func (m *GenesisState) 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 ErrIntOverflowGenesis + } + 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: GenesisState: wiretype end group for non-group") + } + if fieldNum <= 0 { + return fmt.Errorf("proto: GenesisState: illegal tag %d (wire type %d)", fieldNum, wire) + } + switch fieldNum { + case 1: + if wireType != 2 { + return fmt.Errorf("proto: wrong wireType = %d for field Params", wireType) + } + var msglen int + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowGenesis + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + msglen |= int(b&0x7F) << shift + if b < 0x80 { + break + } + } + if msglen < 0 { + return ErrInvalidLengthGenesis + } + postIndex := iNdEx + msglen + if postIndex < 0 { + return ErrInvalidLengthGenesis + } + if postIndex > l { + return io.ErrUnexpectedEOF + } + if err := m.Params.Unmarshal(dAtA[iNdEx:postIndex]); err != nil { + return err + } + iNdEx = postIndex + default: + iNdEx = preIndex + skippy, err := skipGenesis(dAtA[iNdEx:]) + if err != nil { + return err + } + if (skippy < 0) || (iNdEx+skippy) < 0 { + return ErrInvalidLengthGenesis + } + if (iNdEx + skippy) > l { + return io.ErrUnexpectedEOF + } + iNdEx += skippy + } + } + + if iNdEx > l { + return io.ErrUnexpectedEOF + } + return nil +} +func skipGenesis(dAtA []byte) (n int, err error) { + l := len(dAtA) + iNdEx := 0 + depth := 0 + for iNdEx < l { + var wire uint64 + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return 0, ErrIntOverflowGenesis + } + if iNdEx >= l { + return 0, io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + wire |= (uint64(b) & 0x7F) << shift + if b < 0x80 { + break + } + } + wireType := int(wire & 0x7) + switch wireType { + case 0: + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return 0, ErrIntOverflowGenesis + } + if iNdEx >= l { + return 0, io.ErrUnexpectedEOF + } + iNdEx++ + if dAtA[iNdEx-1] < 0x80 { + break + } + } + case 1: + iNdEx += 8 + case 2: + var length int + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return 0, ErrIntOverflowGenesis + } + if iNdEx >= l { + return 0, io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + length |= (int(b) & 0x7F) << shift + if b < 0x80 { + break + } + } + if length < 0 { + return 0, ErrInvalidLengthGenesis + } + iNdEx += length + case 3: + depth++ + case 4: + if depth == 0 { + return 0, ErrUnexpectedEndOfGroupGenesis + } + depth-- + case 5: + iNdEx += 4 + default: + return 0, fmt.Errorf("proto: illegal wireType %d", wireType) + } + if iNdEx < 0 { + return 0, ErrInvalidLengthGenesis + } + if depth == 0 { + return iNdEx, nil + } + } + return 0, io.ErrUnexpectedEOF +} + +var ( + ErrInvalidLengthGenesis = fmt.Errorf("proto: negative length found during unmarshaling") + ErrIntOverflowGenesis = fmt.Errorf("proto: integer overflow") + ErrUnexpectedEndOfGroupGenesis = fmt.Errorf("proto: unexpected end of group") +) diff --git a/x/votepersistence/types/genesis_test.go b/x/votepersistence/types/genesis_test.go new file mode 100644 index 00000000..566e199b --- /dev/null +++ b/x/votepersistence/types/genesis_test.go @@ -0,0 +1,37 @@ +package types_test + +import ( + "testing" + + "github.com/node101-io/pulsar-chain/x/votepersistence/types" + "github.com/stretchr/testify/require" +) + +func TestGenesisState_Validate(t *testing.T) { + tests := []struct { + desc string + genState *types.GenesisState + valid bool + }{ + { + desc: "default is valid", + genState: types.DefaultGenesis(), + valid: true, + }, + { + desc: "valid genesis state", + genState: &types.GenesisState{}, + valid: true, + }, + } + for _, tc := range tests { + t.Run(tc.desc, func(t *testing.T) { + err := tc.genState.Validate() + if tc.valid { + require.NoError(t, err) + } else { + require.Error(t, err) + } + }) + } +} diff --git a/x/votepersistence/types/keys.go b/x/votepersistence/types/keys.go new file mode 100644 index 00000000..08def311 --- /dev/null +++ b/x/votepersistence/types/keys.go @@ -0,0 +1,19 @@ +package types + +import "cosmossdk.io/collections" + +const ( + // ModuleName defines the module name + ModuleName = "votepersistence" + + // StoreKey defines the primary module store key + StoreKey = ModuleName + + // GovModuleName duplicates the gov module's name to avoid a dependency with x/gov. + // It should be synced with the gov module's name if it is ever changed. + // See: https://github.com/cosmos/cosmos-sdk/blob/v0.52.0-beta.2/x/gov/types/keys.go#L9 + GovModuleName = "gov" +) + +// ParamsKey is the prefix to retrieve all Params +var ParamsKey = collections.NewPrefix("p_votepersistence") diff --git a/x/votepersistence/types/module.pb.go b/x/votepersistence/types/module.pb.go new file mode 100644 index 00000000..15faa0b1 --- /dev/null +++ b/x/votepersistence/types/module.pb.go @@ -0,0 +1,325 @@ +// Code generated by protoc-gen-gogo. DO NOT EDIT. +// source: pulsarchain/votepersistence/module/v1/module.proto + +package types + +import ( + fmt "fmt" + io "io" + math "math" + math_bits "math/bits" + + _ "cosmossdk.io/api/cosmos/app/v1alpha1" + proto "github.com/cosmos/gogoproto/proto" +) + +// Reference imports to suppress errors if they are not otherwise used. +var _ = proto.Marshal +var _ = fmt.Errorf +var _ = math.Inf + +// This is a compile-time assertion to ensure that this generated file +// is compatible with the proto package it is being compiled against. +// A compilation error at this line likely means your copy of the +// proto package needs to be updated. +const _ = proto.GoGoProtoPackageIsVersion3 // please upgrade the proto package + +// Module is the config object for the module. +type Module struct { + // authority defines the custom module authority. + // If not set, defaults to the governance module. + Authority string `protobuf:"bytes,1,opt,name=authority,proto3" json:"authority,omitempty"` +} + +func (m *Module) Reset() { *m = Module{} } +func (m *Module) String() string { return proto.CompactTextString(m) } +func (*Module) ProtoMessage() {} +func (*Module) Descriptor() ([]byte, []int) { + return fileDescriptor_c3d7f592efedc28c, []int{0} +} +func (m *Module) XXX_Unmarshal(b []byte) error { + return m.Unmarshal(b) +} +func (m *Module) XXX_Marshal(b []byte, deterministic bool) ([]byte, error) { + if deterministic { + return xxx_messageInfo_Module.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 *Module) XXX_Merge(src proto.Message) { + xxx_messageInfo_Module.Merge(m, src) +} +func (m *Module) XXX_Size() int { + return m.Size() +} +func (m *Module) XXX_DiscardUnknown() { + xxx_messageInfo_Module.DiscardUnknown(m) +} + +var xxx_messageInfo_Module proto.InternalMessageInfo + +func (m *Module) GetAuthority() string { + if m != nil { + return m.Authority + } + return "" +} + +func init() { + proto.RegisterType((*Module)(nil), "pulsarchain.votepersistence.module.v1.Module") +} + +func init() { + proto.RegisterFile("pulsarchain/votepersistence/module/v1/module.proto", fileDescriptor_c3d7f592efedc28c) +} + +var fileDescriptor_c3d7f592efedc28c = []byte{ + // 219 bytes of a gzipped FileDescriptorProto + 0x1f, 0x8b, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0xff, 0xe2, 0x32, 0x2a, 0x28, 0xcd, 0x29, + 0x4e, 0x2c, 0x4a, 0xce, 0x48, 0xcc, 0xcc, 0xd3, 0x2f, 0xcb, 0x2f, 0x49, 0x2d, 0x48, 0x2d, 0x2a, + 0xce, 0x2c, 0x2e, 0x49, 0xcd, 0x4b, 0x4e, 0xd5, 0xcf, 0xcd, 0x4f, 0x29, 0xcd, 0x49, 0xd5, 0x2f, + 0x33, 0x84, 0xb2, 0xf4, 0x0a, 0x8a, 0xf2, 0x4b, 0xf2, 0x85, 0x54, 0x91, 0xf4, 0xe8, 0xa1, 0xe9, + 0xd1, 0x83, 0xaa, 0x2c, 0x33, 0x94, 0x52, 0x48, 0xce, 0x2f, 0xce, 0xcd, 0x2f, 0xd6, 0x4f, 0x2c, + 0x28, 0xd0, 0x2f, 0x33, 0x4c, 0xcc, 0x29, 0xc8, 0x48, 0x44, 0x35, 0x48, 0x29, 0x85, 0x8b, 0xcd, + 0x17, 0xcc, 0x17, 0x92, 0xe1, 0xe2, 0x4c, 0x2c, 0x2d, 0xc9, 0xc8, 0x2f, 0xca, 0x2c, 0xa9, 0x94, + 0x60, 0x54, 0x60, 0xd4, 0xe0, 0x0c, 0x42, 0x08, 0x58, 0xd9, 0xec, 0x3a, 0x30, 0xed, 0x16, 0xa3, + 0x19, 0x97, 0x49, 0x7a, 0x66, 0x49, 0x46, 0x69, 0x92, 0x5e, 0x72, 0x7e, 0xae, 0x7e, 0x5e, 0x7e, + 0x4a, 0xaa, 0xa1, 0x81, 0xa1, 0x6e, 0x66, 0xbe, 0x3e, 0xc4, 0x39, 0xba, 0x10, 0x3f, 0x54, 0xa0, + 0xfb, 0xc2, 0x29, 0xe4, 0xc4, 0x23, 0x39, 0xc6, 0x0b, 0x8f, 0xe4, 0x18, 0x1f, 0x3c, 0x92, 0x63, + 0x9c, 0xf0, 0x58, 0x8e, 0xe1, 0xc2, 0x63, 0x39, 0x86, 0x1b, 0x8f, 0xe5, 0x18, 0xa2, 0xac, 0xc8, + 0x31, 0x4f, 0xbf, 0xa4, 0xb2, 0x20, 0xb5, 0x38, 0x89, 0x0d, 0xec, 0x05, 0x63, 0x40, 0x00, 0x00, + 0x00, 0xff, 0xff, 0x6d, 0xa9, 0xcf, 0xf9, 0x41, 0x01, 0x00, 0x00, +} + +func (m *Module) 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 *Module) MarshalTo(dAtA []byte) (int, error) { + size := m.Size() + return m.MarshalToSizedBuffer(dAtA[:size]) +} + +func (m *Module) MarshalToSizedBuffer(dAtA []byte) (int, error) { + i := len(dAtA) + _ = i + var l int + _ = l + if len(m.Authority) > 0 { + i -= len(m.Authority) + copy(dAtA[i:], m.Authority) + i = encodeVarintModule(dAtA, i, uint64(len(m.Authority))) + i-- + dAtA[i] = 0xa + } + return len(dAtA) - i, nil +} + +func encodeVarintModule(dAtA []byte, offset int, v uint64) int { + offset -= sovModule(v) + base := offset + for v >= 1<<7 { + dAtA[offset] = uint8(v&0x7f | 0x80) + v >>= 7 + offset++ + } + dAtA[offset] = uint8(v) + return base +} +func (m *Module) Size() (n int) { + if m == nil { + return 0 + } + var l int + _ = l + l = len(m.Authority) + if l > 0 { + n += 1 + l + sovModule(uint64(l)) + } + return n +} + +func sovModule(x uint64) (n int) { + return (math_bits.Len64(x|1) + 6) / 7 +} +func sozModule(x uint64) (n int) { + return sovModule(uint64((x << 1) ^ uint64((int64(x) >> 63)))) +} +func (m *Module) 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 ErrIntOverflowModule + } + 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: Module: wiretype end group for non-group") + } + if fieldNum <= 0 { + return fmt.Errorf("proto: Module: 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 ErrIntOverflowModule + } + 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 ErrInvalidLengthModule + } + postIndex := iNdEx + intStringLen + if postIndex < 0 { + return ErrInvalidLengthModule + } + if postIndex > l { + return io.ErrUnexpectedEOF + } + m.Authority = string(dAtA[iNdEx:postIndex]) + iNdEx = postIndex + default: + iNdEx = preIndex + skippy, err := skipModule(dAtA[iNdEx:]) + if err != nil { + return err + } + if (skippy < 0) || (iNdEx+skippy) < 0 { + return ErrInvalidLengthModule + } + if (iNdEx + skippy) > l { + return io.ErrUnexpectedEOF + } + iNdEx += skippy + } + } + + if iNdEx > l { + return io.ErrUnexpectedEOF + } + return nil +} +func skipModule(dAtA []byte) (n int, err error) { + l := len(dAtA) + iNdEx := 0 + depth := 0 + for iNdEx < l { + var wire uint64 + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return 0, ErrIntOverflowModule + } + if iNdEx >= l { + return 0, io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + wire |= (uint64(b) & 0x7F) << shift + if b < 0x80 { + break + } + } + wireType := int(wire & 0x7) + switch wireType { + case 0: + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return 0, ErrIntOverflowModule + } + if iNdEx >= l { + return 0, io.ErrUnexpectedEOF + } + iNdEx++ + if dAtA[iNdEx-1] < 0x80 { + break + } + } + case 1: + iNdEx += 8 + case 2: + var length int + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return 0, ErrIntOverflowModule + } + if iNdEx >= l { + return 0, io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + length |= (int(b) & 0x7F) << shift + if b < 0x80 { + break + } + } + if length < 0 { + return 0, ErrInvalidLengthModule + } + iNdEx += length + case 3: + depth++ + case 4: + if depth == 0 { + return 0, ErrUnexpectedEndOfGroupModule + } + depth-- + case 5: + iNdEx += 4 + default: + return 0, fmt.Errorf("proto: illegal wireType %d", wireType) + } + if iNdEx < 0 { + return 0, ErrInvalidLengthModule + } + if depth == 0 { + return iNdEx, nil + } + } + return 0, io.ErrUnexpectedEOF +} + +var ( + ErrInvalidLengthModule = fmt.Errorf("proto: negative length found during unmarshaling") + ErrIntOverflowModule = fmt.Errorf("proto: integer overflow") + ErrUnexpectedEndOfGroupModule = fmt.Errorf("proto: unexpected end of group") +) diff --git a/x/votepersistence/types/params.go b/x/votepersistence/types/params.go new file mode 100644 index 00000000..d7e00501 --- /dev/null +++ b/x/votepersistence/types/params.go @@ -0,0 +1,17 @@ +package types + +// NewParams creates a new Params instance. +func NewParams() Params { + return Params{} +} + +// DefaultParams returns a default set of parameters. +func DefaultParams() Params { + return NewParams() +} + +// Validate validates the set of params. +func (p Params) Validate() error { + + return nil +} diff --git a/x/votepersistence/types/params.pb.go b/x/votepersistence/types/params.pb.go new file mode 100644 index 00000000..db7a5855 --- /dev/null +++ b/x/votepersistence/types/params.pb.go @@ -0,0 +1,293 @@ +// Code generated by protoc-gen-gogo. DO NOT EDIT. +// source: pulsarchain/votepersistence/v1/params.proto + +package types + +import ( + fmt "fmt" + io "io" + math "math" + math_bits "math/bits" + + _ "github.com/cosmos/cosmos-sdk/types/tx/amino" + _ "github.com/cosmos/gogoproto/gogoproto" + proto "github.com/cosmos/gogoproto/proto" +) + +// Reference imports to suppress errors if they are not otherwise used. +var _ = proto.Marshal +var _ = fmt.Errorf +var _ = math.Inf + +// This is a compile-time assertion to ensure that this generated file +// is compatible with the proto package it is being compiled against. +// A compilation error at this line likely means your copy of the +// proto package needs to be updated. +const _ = proto.GoGoProtoPackageIsVersion3 // please upgrade the proto package + +// Params defines the parameters for the module. +type Params struct { +} + +func (m *Params) Reset() { *m = Params{} } +func (m *Params) String() string { return proto.CompactTextString(m) } +func (*Params) ProtoMessage() {} +func (*Params) Descriptor() ([]byte, []int) { + return fileDescriptor_7d43c53e6aafc30b, []int{0} +} +func (m *Params) XXX_Unmarshal(b []byte) error { + return m.Unmarshal(b) +} +func (m *Params) XXX_Marshal(b []byte, deterministic bool) ([]byte, error) { + if deterministic { + return xxx_messageInfo_Params.Marshal(b, m, deterministic) + } else { + b = b[:cap(b)] + n, err := m.MarshalToSizedBuffer(b) + if err != nil { + return nil, err + } + return b[:n], nil + } +} +func (m *Params) XXX_Merge(src proto.Message) { + xxx_messageInfo_Params.Merge(m, src) +} +func (m *Params) XXX_Size() int { + return m.Size() +} +func (m *Params) XXX_DiscardUnknown() { + xxx_messageInfo_Params.DiscardUnknown(m) +} + +var xxx_messageInfo_Params proto.InternalMessageInfo + +func init() { + proto.RegisterType((*Params)(nil), "pulsarchain.votepersistence.v1.Params") +} + +func init() { + proto.RegisterFile("pulsarchain/votepersistence/v1/params.proto", fileDescriptor_7d43c53e6aafc30b) +} + +var fileDescriptor_7d43c53e6aafc30b = []byte{ + // 197 bytes of a gzipped FileDescriptorProto + 0x1f, 0x8b, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0xff, 0xe2, 0xd2, 0x2e, 0x28, 0xcd, 0x29, + 0x4e, 0x2c, 0x4a, 0xce, 0x48, 0xcc, 0xcc, 0xd3, 0x2f, 0xcb, 0x2f, 0x49, 0x2d, 0x48, 0x2d, 0x2a, + 0xce, 0x2c, 0x2e, 0x49, 0xcd, 0x4b, 0x4e, 0xd5, 0x2f, 0x33, 0xd4, 0x2f, 0x48, 0x2c, 0x4a, 0xcc, + 0x2d, 0xd6, 0x2b, 0x28, 0xca, 0x2f, 0xc9, 0x17, 0x92, 0x43, 0x52, 0xac, 0x87, 0xa6, 0x58, 0xaf, + 0xcc, 0x50, 0x4a, 0x30, 0x31, 0x37, 0x33, 0x2f, 0x5f, 0x1f, 0x4c, 0x42, 0xb4, 0x48, 0x89, 0xa4, + 0xe7, 0xa7, 0xe7, 0x83, 0x99, 0xfa, 0x20, 0x16, 0x44, 0x54, 0xc9, 0x9c, 0x8b, 0x2d, 0x00, 0x6c, + 0xb0, 0x95, 0xee, 0x8b, 0x05, 0xf2, 0x8c, 0x5d, 0xcf, 0x37, 0x68, 0xa9, 0x20, 0x3b, 0xa4, 0x02, + 0xc3, 0x29, 0x10, 0xe5, 0x4e, 0x21, 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, 0x95, 0x9e, 0x59, 0x92, 0x51, 0x9a, 0xa4, 0x97, 0x9c, 0x9f, 0xab, 0x9f, 0x97, 0x9f, 0x92, + 0x6a, 0x68, 0x60, 0xa8, 0x9b, 0x99, 0xaf, 0x0f, 0x31, 0x55, 0x17, 0x97, 0xb1, 0x25, 0x95, 0x05, + 0xa9, 0xc5, 0x49, 0x6c, 0x60, 0x57, 0x19, 0x03, 0x02, 0x00, 0x00, 0xff, 0xff, 0x76, 0x79, 0x99, + 0xc3, 0x0d, 0x01, 0x00, 0x00, +} + +func (this *Params) Equal(that interface{}) bool { + if that == nil { + return this == nil + } + + that1, ok := that.(*Params) + if !ok { + that2, ok := that.(Params) + if ok { + that1 = &that2 + } else { + return false + } + } + if that1 == nil { + return this == nil + } else if this == nil { + return false + } + return true +} +func (m *Params) 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 *Params) MarshalTo(dAtA []byte) (int, error) { + size := m.Size() + return m.MarshalToSizedBuffer(dAtA[:size]) +} + +func (m *Params) MarshalToSizedBuffer(dAtA []byte) (int, error) { + i := len(dAtA) + _ = i + var l int + _ = l + return len(dAtA) - i, nil +} + +func encodeVarintParams(dAtA []byte, offset int, v uint64) int { + offset -= sovParams(v) + base := offset + for v >= 1<<7 { + dAtA[offset] = uint8(v&0x7f | 0x80) + v >>= 7 + offset++ + } + dAtA[offset] = uint8(v) + return base +} +func (m *Params) Size() (n int) { + if m == nil { + return 0 + } + var l int + _ = l + return n +} + +func sovParams(x uint64) (n int) { + return (math_bits.Len64(x|1) + 6) / 7 +} +func sozParams(x uint64) (n int) { + return sovParams(uint64((x << 1) ^ uint64((int64(x) >> 63)))) +} +func (m *Params) Unmarshal(dAtA []byte) error { + l := len(dAtA) + iNdEx := 0 + for iNdEx < l { + preIndex := iNdEx + var wire uint64 + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowParams + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + wire |= uint64(b&0x7F) << shift + if b < 0x80 { + break + } + } + fieldNum := int32(wire >> 3) + wireType := int(wire & 0x7) + if wireType == 4 { + return fmt.Errorf("proto: Params: wiretype end group for non-group") + } + if fieldNum <= 0 { + return fmt.Errorf("proto: Params: illegal tag %d (wire type %d)", fieldNum, wire) + } + switch fieldNum { + default: + iNdEx = preIndex + skippy, err := skipParams(dAtA[iNdEx:]) + if err != nil { + return err + } + if (skippy < 0) || (iNdEx+skippy) < 0 { + return ErrInvalidLengthParams + } + if (iNdEx + skippy) > l { + return io.ErrUnexpectedEOF + } + iNdEx += skippy + } + } + + if iNdEx > l { + return io.ErrUnexpectedEOF + } + return nil +} +func skipParams(dAtA []byte) (n int, err error) { + l := len(dAtA) + iNdEx := 0 + depth := 0 + for iNdEx < l { + var wire uint64 + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return 0, ErrIntOverflowParams + } + if iNdEx >= l { + return 0, io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + wire |= (uint64(b) & 0x7F) << shift + if b < 0x80 { + break + } + } + wireType := int(wire & 0x7) + switch wireType { + case 0: + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return 0, ErrIntOverflowParams + } + if iNdEx >= l { + return 0, io.ErrUnexpectedEOF + } + iNdEx++ + if dAtA[iNdEx-1] < 0x80 { + break + } + } + case 1: + iNdEx += 8 + case 2: + var length int + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return 0, ErrIntOverflowParams + } + if iNdEx >= l { + return 0, io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + length |= (int(b) & 0x7F) << shift + if b < 0x80 { + break + } + } + if length < 0 { + return 0, ErrInvalidLengthParams + } + iNdEx += length + case 3: + depth++ + case 4: + if depth == 0 { + return 0, ErrUnexpectedEndOfGroupParams + } + depth-- + case 5: + iNdEx += 4 + default: + return 0, fmt.Errorf("proto: illegal wireType %d", wireType) + } + if iNdEx < 0 { + return 0, ErrInvalidLengthParams + } + if depth == 0 { + return iNdEx, nil + } + } + return 0, io.ErrUnexpectedEOF +} + +var ( + ErrInvalidLengthParams = fmt.Errorf("proto: negative length found during unmarshaling") + ErrIntOverflowParams = fmt.Errorf("proto: integer overflow") + ErrUnexpectedEndOfGroupParams = fmt.Errorf("proto: unexpected end of group") +) diff --git a/x/votepersistence/types/query.pb.go b/x/votepersistence/types/query.pb.go new file mode 100644 index 00000000..7f0e6273 --- /dev/null +++ b/x/votepersistence/types/query.pb.go @@ -0,0 +1,545 @@ +// Code generated by protoc-gen-gogo. DO NOT EDIT. +// source: pulsarchain/votepersistence/v1/query.proto + +package types + +import ( + context "context" + fmt "fmt" + io "io" + math "math" + math_bits "math/bits" + + _ "github.com/cosmos/cosmos-sdk/types/query" + _ "github.com/cosmos/cosmos-sdk/types/tx/amino" + _ "github.com/cosmos/gogoproto/gogoproto" + grpc1 "github.com/cosmos/gogoproto/grpc" + proto "github.com/cosmos/gogoproto/proto" + _ "google.golang.org/genproto/googleapis/api/annotations" + grpc "google.golang.org/grpc" + codes "google.golang.org/grpc/codes" + status "google.golang.org/grpc/status" +) + +// Reference imports to suppress errors if they are not otherwise used. +var _ = proto.Marshal +var _ = fmt.Errorf +var _ = math.Inf + +// This is a compile-time assertion to ensure that this generated file +// is compatible with the proto package it is being compiled against. +// A compilation error at this line likely means your copy of the +// proto package needs to be updated. +const _ = proto.GoGoProtoPackageIsVersion3 // please upgrade the proto package + +// QueryParamsRequest is request type for the Query/Params RPC method. +type QueryParamsRequest struct { +} + +func (m *QueryParamsRequest) Reset() { *m = QueryParamsRequest{} } +func (m *QueryParamsRequest) String() string { return proto.CompactTextString(m) } +func (*QueryParamsRequest) ProtoMessage() {} +func (*QueryParamsRequest) Descriptor() ([]byte, []int) { + return fileDescriptor_2c9976ecef977273, []int{0} +} +func (m *QueryParamsRequest) XXX_Unmarshal(b []byte) error { + return m.Unmarshal(b) +} +func (m *QueryParamsRequest) XXX_Marshal(b []byte, deterministic bool) ([]byte, error) { + if deterministic { + return xxx_messageInfo_QueryParamsRequest.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 *QueryParamsRequest) XXX_Merge(src proto.Message) { + xxx_messageInfo_QueryParamsRequest.Merge(m, src) +} +func (m *QueryParamsRequest) XXX_Size() int { + return m.Size() +} +func (m *QueryParamsRequest) XXX_DiscardUnknown() { + xxx_messageInfo_QueryParamsRequest.DiscardUnknown(m) +} + +var xxx_messageInfo_QueryParamsRequest proto.InternalMessageInfo + +// QueryParamsResponse is response type for the Query/Params RPC method. +type QueryParamsResponse struct { + // params holds all the parameters of this module. + Params Params `protobuf:"bytes,1,opt,name=params,proto3" json:"params"` +} + +func (m *QueryParamsResponse) Reset() { *m = QueryParamsResponse{} } +func (m *QueryParamsResponse) String() string { return proto.CompactTextString(m) } +func (*QueryParamsResponse) ProtoMessage() {} +func (*QueryParamsResponse) Descriptor() ([]byte, []int) { + return fileDescriptor_2c9976ecef977273, []int{1} +} +func (m *QueryParamsResponse) XXX_Unmarshal(b []byte) error { + return m.Unmarshal(b) +} +func (m *QueryParamsResponse) XXX_Marshal(b []byte, deterministic bool) ([]byte, error) { + if deterministic { + return xxx_messageInfo_QueryParamsResponse.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 *QueryParamsResponse) XXX_Merge(src proto.Message) { + xxx_messageInfo_QueryParamsResponse.Merge(m, src) +} +func (m *QueryParamsResponse) XXX_Size() int { + return m.Size() +} +func (m *QueryParamsResponse) XXX_DiscardUnknown() { + xxx_messageInfo_QueryParamsResponse.DiscardUnknown(m) +} + +var xxx_messageInfo_QueryParamsResponse proto.InternalMessageInfo + +func (m *QueryParamsResponse) GetParams() Params { + if m != nil { + return m.Params + } + return Params{} +} + +func init() { + proto.RegisterType((*QueryParamsRequest)(nil), "pulsarchain.votepersistence.v1.QueryParamsRequest") + proto.RegisterType((*QueryParamsResponse)(nil), "pulsarchain.votepersistence.v1.QueryParamsResponse") +} + +func init() { + proto.RegisterFile("pulsarchain/votepersistence/v1/query.proto", fileDescriptor_2c9976ecef977273) +} + +var fileDescriptor_2c9976ecef977273 = []byte{ + // 342 bytes of a gzipped FileDescriptorProto + 0x1f, 0x8b, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0xff, 0x94, 0x91, 0xb1, 0x4a, 0x3b, 0x41, + 0x10, 0xc6, 0x6f, 0xff, 0xf0, 0x0f, 0x78, 0x56, 0x9e, 0x29, 0x24, 0xc8, 0x2a, 0x29, 0x44, 0x22, + 0xb9, 0xf5, 0x2e, 0x56, 0x29, 0xd3, 0xd9, 0x69, 0xb0, 0xb2, 0x72, 0xef, 0x1c, 0x2e, 0x0b, 0xb9, + 0x9d, 0xcd, 0xed, 0xde, 0x61, 0x5a, 0x9f, 0x40, 0xf0, 0x25, 0x6c, 0x04, 0x3b, 0x5f, 0x21, 0x65, + 0xc0, 0xc6, 0x4a, 0x24, 0x11, 0x7c, 0x0d, 0xc9, 0xed, 0x15, 0x6a, 0xd0, 0x60, 0xb3, 0x0c, 0xdf, + 0x7e, 0xdf, 0x6f, 0x66, 0x76, 0xdd, 0x96, 0xca, 0x87, 0x9a, 0x67, 0xf1, 0x80, 0x0b, 0xc9, 0x0a, + 0x34, 0xa0, 0x20, 0xd3, 0x42, 0x1b, 0x90, 0x31, 0xb0, 0x22, 0x60, 0xa3, 0x1c, 0xb2, 0xb1, 0xaf, + 0x32, 0x34, 0xe8, 0xd1, 0x4f, 0x5e, 0xff, 0x9b, 0xd7, 0x2f, 0x82, 0xc6, 0x06, 0x4f, 0x85, 0x44, + 0x56, 0x9e, 0x36, 0xd2, 0xa8, 0x27, 0x98, 0x60, 0x59, 0xb2, 0x45, 0x55, 0xa9, 0xdb, 0x09, 0x62, + 0x32, 0x04, 0xc6, 0x95, 0x60, 0x5c, 0x4a, 0x34, 0xdc, 0x08, 0x94, 0xba, 0xba, 0x6d, 0xc5, 0xa8, + 0x53, 0xd4, 0x2c, 0xe2, 0x1a, 0x6c, 0x7f, 0x56, 0x04, 0x11, 0x18, 0x1e, 0x30, 0xc5, 0x13, 0x21, + 0x4b, 0x73, 0xe5, 0x3d, 0x58, 0x31, 0xbe, 0xe2, 0x19, 0x4f, 0x2b, 0x70, 0xb3, 0xee, 0x7a, 0xa7, + 0x0b, 0xdc, 0x49, 0x29, 0xf6, 0x61, 0x94, 0x83, 0x36, 0xcd, 0x0b, 0x77, 0xf3, 0x8b, 0xaa, 0x15, + 0x4a, 0x0d, 0xde, 0xb1, 0x5b, 0xb3, 0xe1, 0x2d, 0xb2, 0x4b, 0xf6, 0xd7, 0xc3, 0x3d, 0xff, 0xf7, + 0xed, 0x7d, 0x9b, 0xef, 0xad, 0x4d, 0x5e, 0x76, 0x9c, 0xbb, 0xf7, 0x87, 0x16, 0xe9, 0x57, 0x80, + 0xf0, 0x91, 0xb8, 0xff, 0xcb, 0x16, 0xde, 0x3d, 0x71, 0x6b, 0xd6, 0xe7, 0x85, 0xab, 0x78, 0xcb, + 0xa3, 0x36, 0x3a, 0x7f, 0xca, 0xd8, 0x45, 0x9a, 0xdd, 0xeb, 0xa7, 0xb7, 0xdb, 0x7f, 0x47, 0x5e, + 0xc8, 0x24, 0x5e, 0x42, 0x70, 0x18, 0xb4, 0x05, 0x32, 0xcb, 0x69, 0xaf, 0x78, 0xb7, 0xde, 0xd9, + 0x64, 0x46, 0xc9, 0x74, 0x46, 0xc9, 0xeb, 0x8c, 0x92, 0x9b, 0x39, 0x75, 0xa6, 0x73, 0xea, 0x3c, + 0xcf, 0xa9, 0x73, 0xde, 0x4d, 0x84, 0x19, 0xe4, 0x91, 0x1f, 0x63, 0xfa, 0x23, 0xf7, 0x6a, 0x89, + 0x6c, 0xc6, 0x0a, 0x74, 0x54, 0x2b, 0xbf, 0xa3, 0xf3, 0x11, 0x00, 0x00, 0xff, 0xff, 0x9b, 0x87, + 0xdc, 0x4b, 0x7c, 0x02, 0x00, 0x00, +} + +// Reference imports to suppress errors if they are not otherwise used. +var _ context.Context +var _ grpc.ClientConn + +// This is a compile-time assertion to ensure that this generated file +// is compatible with the grpc package it is being compiled against. +const _ = grpc.SupportPackageIsVersion4 + +// QueryClient is the client API for Query service. +// +// 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 { + // Parameters queries the parameters of the module. + Params(ctx context.Context, in *QueryParamsRequest, opts ...grpc.CallOption) (*QueryParamsResponse, error) +} + +type queryClient struct { + cc grpc1.ClientConn +} + +func NewQueryClient(cc grpc1.ClientConn) QueryClient { + return &queryClient{cc} +} + +func (c *queryClient) Params(ctx context.Context, in *QueryParamsRequest, opts ...grpc.CallOption) (*QueryParamsResponse, error) { + out := new(QueryParamsResponse) + err := c.cc.Invoke(ctx, "/pulsarchain.votepersistence.v1.Query/Params", in, out, opts...) + if err != nil { + return nil, err + } + return out, nil +} + +// QueryServer is the server API for Query service. +type QueryServer interface { + // Parameters queries the parameters of the module. + Params(context.Context, *QueryParamsRequest) (*QueryParamsResponse, error) +} + +// UnimplementedQueryServer can be embedded to have forward compatible implementations. +type UnimplementedQueryServer struct { +} + +func (*UnimplementedQueryServer) Params(ctx context.Context, req *QueryParamsRequest) (*QueryParamsResponse, error) { + return nil, status.Errorf(codes.Unimplemented, "method Params not implemented") +} + +func RegisterQueryServer(s grpc1.Server, srv QueryServer) { + s.RegisterService(&_Query_serviceDesc, srv) +} + +func _Query_Params_Handler(srv interface{}, ctx context.Context, dec func(interface{}) error, interceptor grpc.UnaryServerInterceptor) (interface{}, error) { + in := new(QueryParamsRequest) + if err := dec(in); err != nil { + return nil, err + } + if interceptor == nil { + return srv.(QueryServer).Params(ctx, in) + } + info := &grpc.UnaryServerInfo{ + Server: srv, + FullMethod: "/pulsarchain.votepersistence.v1.Query/Params", + } + handler := func(ctx context.Context, req interface{}) (interface{}, error) { + return srv.(QueryServer).Params(ctx, req.(*QueryParamsRequest)) + } + return interceptor(ctx, in, info, handler) +} + +var Query_serviceDesc = _Query_serviceDesc +var _Query_serviceDesc = grpc.ServiceDesc{ + ServiceName: "pulsarchain.votepersistence.v1.Query", + HandlerType: (*QueryServer)(nil), + Methods: []grpc.MethodDesc{ + { + MethodName: "Params", + Handler: _Query_Params_Handler, + }, + }, + Streams: []grpc.StreamDesc{}, + Metadata: "pulsarchain/votepersistence/v1/query.proto", +} + +func (m *QueryParamsRequest) 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 *QueryParamsRequest) MarshalTo(dAtA []byte) (int, error) { + size := m.Size() + return m.MarshalToSizedBuffer(dAtA[:size]) +} + +func (m *QueryParamsRequest) MarshalToSizedBuffer(dAtA []byte) (int, error) { + i := len(dAtA) + _ = i + var l int + _ = l + return len(dAtA) - i, nil +} + +func (m *QueryParamsResponse) 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 *QueryParamsResponse) MarshalTo(dAtA []byte) (int, error) { + size := m.Size() + return m.MarshalToSizedBuffer(dAtA[:size]) +} + +func (m *QueryParamsResponse) MarshalToSizedBuffer(dAtA []byte) (int, error) { + i := len(dAtA) + _ = i + var l int + _ = l + { + size, err := m.Params.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 + for v >= 1<<7 { + dAtA[offset] = uint8(v&0x7f | 0x80) + v >>= 7 + offset++ + } + dAtA[offset] = uint8(v) + return base +} +func (m *QueryParamsRequest) Size() (n int) { + if m == nil { + return 0 + } + var l int + _ = l + return n +} + +func (m *QueryParamsResponse) Size() (n int) { + if m == nil { + return 0 + } + var l int + _ = l + l = m.Params.Size() + n += 1 + l + sovQuery(uint64(l)) + return n +} + +func sovQuery(x uint64) (n int) { + return (math_bits.Len64(x|1) + 6) / 7 +} +func sozQuery(x uint64) (n int) { + return sovQuery(uint64((x << 1) ^ uint64((int64(x) >> 63)))) +} +func (m *QueryParamsRequest) 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: QueryParamsRequest: wiretype end group for non-group") + } + if fieldNum <= 0 { + return fmt.Errorf("proto: QueryParamsRequest: 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 *QueryParamsResponse) 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: QueryParamsResponse: wiretype end group for non-group") + } + if fieldNum <= 0 { + return fmt.Errorf("proto: QueryParamsResponse: illegal tag %d (wire type %d)", fieldNum, wire) + } + switch fieldNum { + case 1: + if wireType != 2 { + return fmt.Errorf("proto: wrong wireType = %d for field Params", 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.Params.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 + depth := 0 + for iNdEx < l { + var wire uint64 + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return 0, ErrIntOverflowQuery + } + if iNdEx >= l { + return 0, io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + wire |= (uint64(b) & 0x7F) << shift + if b < 0x80 { + break + } + } + wireType := int(wire & 0x7) + switch wireType { + case 0: + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return 0, ErrIntOverflowQuery + } + if iNdEx >= l { + return 0, io.ErrUnexpectedEOF + } + iNdEx++ + if dAtA[iNdEx-1] < 0x80 { + break + } + } + case 1: + iNdEx += 8 + case 2: + var length int + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return 0, ErrIntOverflowQuery + } + if iNdEx >= l { + return 0, io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + length |= (int(b) & 0x7F) << shift + if b < 0x80 { + break + } + } + if length < 0 { + return 0, ErrInvalidLengthQuery + } + iNdEx += length + case 3: + depth++ + case 4: + if depth == 0 { + return 0, ErrUnexpectedEndOfGroupQuery + } + depth-- + case 5: + iNdEx += 4 + default: + return 0, fmt.Errorf("proto: illegal wireType %d", wireType) + } + if iNdEx < 0 { + return 0, ErrInvalidLengthQuery + } + if depth == 0 { + return iNdEx, nil + } + } + return 0, io.ErrUnexpectedEOF +} + +var ( + ErrInvalidLengthQuery = fmt.Errorf("proto: negative length found during unmarshaling") + ErrIntOverflowQuery = fmt.Errorf("proto: integer overflow") + ErrUnexpectedEndOfGroupQuery = fmt.Errorf("proto: unexpected end of group") +) diff --git a/x/votepersistence/types/query.pb.gw.go b/x/votepersistence/types/query.pb.gw.go new file mode 100644 index 00000000..699c42c3 --- /dev/null +++ b/x/votepersistence/types/query.pb.gw.go @@ -0,0 +1,153 @@ +// Code generated by protoc-gen-grpc-gateway. DO NOT EDIT. +// source: pulsarchain/votepersistence/v1/query.proto + +/* +Package types is a reverse proxy. + +It translates gRPC into RESTful JSON APIs. +*/ +package types + +import ( + "context" + "io" + "net/http" + + "github.com/golang/protobuf/descriptor" + "github.com/golang/protobuf/proto" + "github.com/grpc-ecosystem/grpc-gateway/runtime" + "github.com/grpc-ecosystem/grpc-gateway/utilities" + "google.golang.org/grpc" + "google.golang.org/grpc/codes" + "google.golang.org/grpc/grpclog" + "google.golang.org/grpc/metadata" + "google.golang.org/grpc/status" +) + +// Suppress "imported and not used" errors +var _ codes.Code +var _ io.Reader +var _ status.Status +var _ = runtime.String +var _ = utilities.NewDoubleArray +var _ = descriptor.ForMessage +var _ = metadata.Join + +func request_Query_Params_0(ctx context.Context, marshaler runtime.Marshaler, client QueryClient, req *http.Request, pathParams map[string]string) (proto.Message, runtime.ServerMetadata, error) { + var protoReq QueryParamsRequest + var metadata runtime.ServerMetadata + + msg, err := client.Params(ctx, &protoReq, grpc.Header(&metadata.HeaderMD), grpc.Trailer(&metadata.TrailerMD)) + return msg, metadata, err + +} + +func local_request_Query_Params_0(ctx context.Context, marshaler runtime.Marshaler, server QueryServer, req *http.Request, pathParams map[string]string) (proto.Message, runtime.ServerMetadata, error) { + var protoReq QueryParamsRequest + var metadata runtime.ServerMetadata + + msg, err := server.Params(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. +// Note that using this registration option will cause many gRPC library features to stop working. Consider using RegisterQueryHandlerFromEndpoint instead. +func RegisterQueryHandlerServer(ctx context.Context, mux *runtime.ServeMux, server QueryServer) error { + + mux.Handle("GET", pattern_Query_Params_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_Params_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_Params_0(ctx, mux, outboundMarshaler, w, req, resp, mux.GetForwardResponseOptions()...) + + }) + + return nil +} + +// RegisterQueryHandlerFromEndpoint is same as RegisterQueryHandler but +// automatically dials to "endpoint" and closes the connection when "ctx" gets done. +func RegisterQueryHandlerFromEndpoint(ctx context.Context, mux *runtime.ServeMux, endpoint string, opts []grpc.DialOption) (err error) { + conn, err := grpc.Dial(endpoint, opts...) + if err != nil { + return err + } + defer func() { + if err != nil { + if cerr := conn.Close(); cerr != nil { + grpclog.Infof("Failed to close conn to %s: %v", endpoint, cerr) + } + return + } + go func() { + <-ctx.Done() + if cerr := conn.Close(); cerr != nil { + grpclog.Infof("Failed to close conn to %s: %v", endpoint, cerr) + } + }() + }() + + return RegisterQueryHandler(ctx, mux, conn) +} + +// RegisterQueryHandler registers the http handlers for service Query to "mux". +// The handlers forward requests to the grpc endpoint over "conn". +func RegisterQueryHandler(ctx context.Context, mux *runtime.ServeMux, conn *grpc.ClientConn) error { + return RegisterQueryHandlerClient(ctx, mux, NewQueryClient(conn)) +} + +// RegisterQueryHandlerClient registers the http handlers for service Query +// to "mux". The handlers forward requests to the grpc endpoint over the given implementation of "QueryClient". +// Note: the gRPC framework executes interceptors within the gRPC handler. If the passed in "QueryClient" +// doesn't go through the normal gRPC flow (creating a gRPC client etc.) then it will be up to the passed in +// "QueryClient" to call the correct interceptors. +func RegisterQueryHandlerClient(ctx context.Context, mux *runtime.ServeMux, client QueryClient) error { + + mux.Handle("GET", pattern_Query_Params_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_Params_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_Params_0(ctx, mux, outboundMarshaler, w, req, resp, mux.GetForwardResponseOptions()...) + + }) + + return nil +} + +var ( + pattern_Query_Params_0 = runtime.MustPattern(runtime.NewPattern(1, []int{2, 0, 2, 1, 2, 2, 2, 3, 2, 4}, []string{"node101-io", "pulsar-chain", "votepersistence", "v1", "params"}, "", runtime.AssumeColonVerbOpt(false))) +) + +var ( + forward_Query_Params_0 = runtime.ForwardResponseMessage +) diff --git a/x/votepersistence/types/tx.pb.go b/x/votepersistence/types/tx.pb.go new file mode 100644 index 00000000..c72264a0 --- /dev/null +++ b/x/votepersistence/types/tx.pb.go @@ -0,0 +1,604 @@ +// Code generated by protoc-gen-gogo. DO NOT EDIT. +// source: pulsarchain/votepersistence/v1/tx.proto + +package types + +import ( + context "context" + fmt "fmt" + io "io" + math "math" + math_bits "math/bits" + + _ "github.com/cosmos/cosmos-proto" + _ "github.com/cosmos/cosmos-sdk/types/msgservice" + _ "github.com/cosmos/cosmos-sdk/types/tx/amino" + _ "github.com/cosmos/gogoproto/gogoproto" + grpc1 "github.com/cosmos/gogoproto/grpc" + proto "github.com/cosmos/gogoproto/proto" + grpc "google.golang.org/grpc" + codes "google.golang.org/grpc/codes" + status "google.golang.org/grpc/status" +) + +// Reference imports to suppress errors if they are not otherwise used. +var _ = proto.Marshal +var _ = fmt.Errorf +var _ = math.Inf + +// This is a compile-time assertion to ensure that this generated file +// is compatible with the proto package it is being compiled against. +// A compilation error at this line likely means your copy of the +// proto package needs to be updated. +const _ = proto.GoGoProtoPackageIsVersion3 // please upgrade the proto package + +// MsgUpdateParams is the Msg/UpdateParams request type. +type MsgUpdateParams struct { + // authority is the address that controls the module (defaults to x/gov unless overwritten). + Authority string `protobuf:"bytes,1,opt,name=authority,proto3" json:"authority,omitempty"` + // params defines the module parameters to update. + // + // NOTE: All parameters must be supplied. + Params Params `protobuf:"bytes,2,opt,name=params,proto3" json:"params"` +} + +func (m *MsgUpdateParams) Reset() { *m = MsgUpdateParams{} } +func (m *MsgUpdateParams) String() string { return proto.CompactTextString(m) } +func (*MsgUpdateParams) ProtoMessage() {} +func (*MsgUpdateParams) Descriptor() ([]byte, []int) { + return fileDescriptor_9ef0cb0ba71ad1b3, []int{0} +} +func (m *MsgUpdateParams) XXX_Unmarshal(b []byte) error { + return m.Unmarshal(b) +} +func (m *MsgUpdateParams) XXX_Marshal(b []byte, deterministic bool) ([]byte, error) { + if deterministic { + return xxx_messageInfo_MsgUpdateParams.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 *MsgUpdateParams) XXX_Merge(src proto.Message) { + xxx_messageInfo_MsgUpdateParams.Merge(m, src) +} +func (m *MsgUpdateParams) XXX_Size() int { + return m.Size() +} +func (m *MsgUpdateParams) XXX_DiscardUnknown() { + xxx_messageInfo_MsgUpdateParams.DiscardUnknown(m) +} + +var xxx_messageInfo_MsgUpdateParams proto.InternalMessageInfo + +func (m *MsgUpdateParams) GetAuthority() string { + if m != nil { + return m.Authority + } + return "" +} + +func (m *MsgUpdateParams) GetParams() Params { + if m != nil { + return m.Params + } + return Params{} +} + +// MsgUpdateParamsResponse defines the response structure for executing a +// MsgUpdateParams message. +type MsgUpdateParamsResponse struct { +} + +func (m *MsgUpdateParamsResponse) Reset() { *m = MsgUpdateParamsResponse{} } +func (m *MsgUpdateParamsResponse) String() string { return proto.CompactTextString(m) } +func (*MsgUpdateParamsResponse) ProtoMessage() {} +func (*MsgUpdateParamsResponse) Descriptor() ([]byte, []int) { + return fileDescriptor_9ef0cb0ba71ad1b3, []int{1} +} +func (m *MsgUpdateParamsResponse) XXX_Unmarshal(b []byte) error { + return m.Unmarshal(b) +} +func (m *MsgUpdateParamsResponse) XXX_Marshal(b []byte, deterministic bool) ([]byte, error) { + if deterministic { + return xxx_messageInfo_MsgUpdateParamsResponse.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 *MsgUpdateParamsResponse) XXX_Merge(src proto.Message) { + xxx_messageInfo_MsgUpdateParamsResponse.Merge(m, src) +} +func (m *MsgUpdateParamsResponse) XXX_Size() int { + return m.Size() +} +func (m *MsgUpdateParamsResponse) XXX_DiscardUnknown() { + xxx_messageInfo_MsgUpdateParamsResponse.DiscardUnknown(m) +} + +var xxx_messageInfo_MsgUpdateParamsResponse proto.InternalMessageInfo + +func init() { + proto.RegisterType((*MsgUpdateParams)(nil), "pulsarchain.votepersistence.v1.MsgUpdateParams") + proto.RegisterType((*MsgUpdateParamsResponse)(nil), "pulsarchain.votepersistence.v1.MsgUpdateParamsResponse") +} + +func init() { + proto.RegisterFile("pulsarchain/votepersistence/v1/tx.proto", fileDescriptor_9ef0cb0ba71ad1b3) +} + +var fileDescriptor_9ef0cb0ba71ad1b3 = []byte{ + // 369 bytes of a gzipped FileDescriptorProto + 0x1f, 0x8b, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0xff, 0xe2, 0x52, 0x2f, 0x28, 0xcd, 0x29, + 0x4e, 0x2c, 0x4a, 0xce, 0x48, 0xcc, 0xcc, 0xd3, 0x2f, 0xcb, 0x2f, 0x49, 0x2d, 0x48, 0x2d, 0x2a, + 0xce, 0x2c, 0x2e, 0x49, 0xcd, 0x4b, 0x4e, 0xd5, 0x2f, 0x33, 0xd4, 0x2f, 0xa9, 0xd0, 0x2b, 0x28, + 0xca, 0x2f, 0xc9, 0x17, 0x92, 0x43, 0x52, 0xa8, 0x87, 0xa6, 0x50, 0xaf, 0xcc, 0x50, 0x4a, 0x30, + 0x31, 0x37, 0x33, 0x2f, 0x5f, 0x1f, 0x4c, 0x42, 0xb4, 0x48, 0x89, 0x27, 0xe7, 0x17, 0xe7, 0xe6, + 0x17, 0xeb, 0xe7, 0x16, 0xa7, 0x83, 0x8c, 0xca, 0x2d, 0x4e, 0x87, 0x4a, 0x48, 0x42, 0x24, 0xe2, + 0xc1, 0x3c, 0x7d, 0x08, 0x07, 0x2a, 0x25, 0x92, 0x9e, 0x9f, 0x9e, 0x0f, 0x11, 0x07, 0xb1, 0xa0, + 0xa2, 0xda, 0x04, 0x5c, 0x59, 0x90, 0x58, 0x94, 0x98, 0x0b, 0x35, 0x42, 0xe9, 0x1a, 0x23, 0x17, + 0xbf, 0x6f, 0x71, 0x7a, 0x68, 0x41, 0x4a, 0x62, 0x49, 0x6a, 0x00, 0x58, 0x46, 0xc8, 0x8c, 0x8b, + 0x33, 0xb1, 0xb4, 0x24, 0x23, 0xbf, 0x28, 0xb3, 0xa4, 0x52, 0x82, 0x51, 0x81, 0x51, 0x83, 0xd3, + 0x49, 0xe2, 0xd2, 0x16, 0x5d, 0x11, 0xa8, 0xdd, 0x8e, 0x29, 0x29, 0x45, 0xa9, 0xc5, 0xc5, 0xc1, + 0x25, 0x45, 0x99, 0x79, 0xe9, 0x41, 0x08, 0xa5, 0x42, 0x9e, 0x5c, 0x6c, 0x10, 0xb3, 0x25, 0x98, + 0x14, 0x18, 0x35, 0xb8, 0x8d, 0xd4, 0xf4, 0xf0, 0x07, 0x83, 0x1e, 0xc4, 0x3e, 0x27, 0xce, 0x13, + 0xf7, 0xe4, 0x19, 0x56, 0x3c, 0xdf, 0xa0, 0xc5, 0x18, 0x04, 0x35, 0xc0, 0xca, 0xa1, 0xe9, 0xf9, + 0x06, 0x2d, 0x84, 0xd1, 0x5d, 0xcf, 0x37, 0x68, 0xe9, 0x22, 0x7b, 0xab, 0x02, 0xc3, 0x63, 0x68, + 0x9e, 0x50, 0x92, 0xe4, 0x12, 0x47, 0x13, 0x0a, 0x4a, 0x2d, 0x2e, 0xc8, 0xcf, 0x2b, 0x4e, 0x35, + 0x6a, 0x63, 0xe4, 0x62, 0xf6, 0x2d, 0x4e, 0x17, 0xaa, 0xe0, 0xe2, 0x41, 0xf1, 0xb7, 0x3e, 0x21, + 0xf7, 0xa2, 0x19, 0x28, 0x65, 0x4e, 0xa2, 0x06, 0x98, 0x0b, 0xa4, 0x58, 0x1b, 0x40, 0xbe, 0x75, + 0x0a, 0x39, 0xf1, 0x48, 0x8e, 0xf1, 0xc2, 0x23, 0x39, 0xc6, 0x07, 0x8f, 0xe4, 0x18, 0x27, 0x3c, + 0x96, 0x63, 0xb8, 0xf0, 0x58, 0x8e, 0xe1, 0xc6, 0x63, 0x39, 0x86, 0x28, 0xab, 0xf4, 0xcc, 0x92, + 0x8c, 0xd2, 0x24, 0xbd, 0xe4, 0xfc, 0x5c, 0xfd, 0xbc, 0xfc, 0x94, 0x54, 0x43, 0x03, 0x43, 0xdd, + 0xcc, 0x7c, 0x7d, 0x88, 0x75, 0xba, 0xb8, 0xc2, 0xa0, 0xa4, 0xb2, 0x20, 0xb5, 0x38, 0x89, 0x0d, + 0x1c, 0xb3, 0xc6, 0x80, 0x00, 0x00, 0x00, 0xff, 0xff, 0xde, 0x4f, 0x5a, 0xaa, 0xae, 0x02, 0x00, + 0x00, +} + +// Reference imports to suppress errors if they are not otherwise used. +var _ context.Context +var _ grpc.ClientConn + +// This is a compile-time assertion to ensure that this generated file +// is compatible with the grpc package it is being compiled against. +const _ = grpc.SupportPackageIsVersion4 + +// MsgClient is the client API for Msg service. +// +// For semantics around ctx use and closing/ending streaming RPCs, please refer to https://godoc.org/google.golang.org/grpc#ClientConn.NewStream. +type MsgClient interface { + // UpdateParams defines a (governance) operation for updating the module + // parameters. The authority defaults to the x/gov module account. + UpdateParams(ctx context.Context, in *MsgUpdateParams, opts ...grpc.CallOption) (*MsgUpdateParamsResponse, error) +} + +type msgClient struct { + cc grpc1.ClientConn +} + +func NewMsgClient(cc grpc1.ClientConn) MsgClient { + return &msgClient{cc} +} + +func (c *msgClient) UpdateParams(ctx context.Context, in *MsgUpdateParams, opts ...grpc.CallOption) (*MsgUpdateParamsResponse, error) { + out := new(MsgUpdateParamsResponse) + err := c.cc.Invoke(ctx, "/pulsarchain.votepersistence.v1.Msg/UpdateParams", in, out, opts...) + if err != nil { + return nil, err + } + return out, nil +} + +// MsgServer is the server API for Msg service. +type MsgServer interface { + // UpdateParams defines a (governance) operation for updating the module + // parameters. The authority defaults to the x/gov module account. + UpdateParams(context.Context, *MsgUpdateParams) (*MsgUpdateParamsResponse, error) +} + +// UnimplementedMsgServer can be embedded to have forward compatible implementations. +type UnimplementedMsgServer struct { +} + +func (*UnimplementedMsgServer) UpdateParams(ctx context.Context, req *MsgUpdateParams) (*MsgUpdateParamsResponse, error) { + return nil, status.Errorf(codes.Unimplemented, "method UpdateParams not implemented") +} + +func RegisterMsgServer(s grpc1.Server, srv MsgServer) { + s.RegisterService(&_Msg_serviceDesc, srv) +} + +func _Msg_UpdateParams_Handler(srv interface{}, ctx context.Context, dec func(interface{}) error, interceptor grpc.UnaryServerInterceptor) (interface{}, error) { + in := new(MsgUpdateParams) + if err := dec(in); err != nil { + return nil, err + } + if interceptor == nil { + return srv.(MsgServer).UpdateParams(ctx, in) + } + info := &grpc.UnaryServerInfo{ + Server: srv, + FullMethod: "/pulsarchain.votepersistence.v1.Msg/UpdateParams", + } + handler := func(ctx context.Context, req interface{}) (interface{}, error) { + return srv.(MsgServer).UpdateParams(ctx, req.(*MsgUpdateParams)) + } + return interceptor(ctx, in, info, handler) +} + +var Msg_serviceDesc = _Msg_serviceDesc +var _Msg_serviceDesc = grpc.ServiceDesc{ + ServiceName: "pulsarchain.votepersistence.v1.Msg", + HandlerType: (*MsgServer)(nil), + Methods: []grpc.MethodDesc{ + { + MethodName: "UpdateParams", + Handler: _Msg_UpdateParams_Handler, + }, + }, + Streams: []grpc.StreamDesc{}, + Metadata: "pulsarchain/votepersistence/v1/tx.proto", +} + +func (m *MsgUpdateParams) 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 *MsgUpdateParams) MarshalTo(dAtA []byte) (int, error) { + size := m.Size() + return m.MarshalToSizedBuffer(dAtA[:size]) +} + +func (m *MsgUpdateParams) MarshalToSizedBuffer(dAtA []byte) (int, error) { + i := len(dAtA) + _ = i + var l int + _ = l + { + size, err := m.Params.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 *MsgUpdateParamsResponse) 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 *MsgUpdateParamsResponse) MarshalTo(dAtA []byte) (int, error) { + size := m.Size() + return m.MarshalToSizedBuffer(dAtA[:size]) +} + +func (m *MsgUpdateParamsResponse) 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 + for v >= 1<<7 { + dAtA[offset] = uint8(v&0x7f | 0x80) + v >>= 7 + offset++ + } + dAtA[offset] = uint8(v) + return base +} +func (m *MsgUpdateParams) 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.Params.Size() + n += 1 + l + sovTx(uint64(l)) + return n +} + +func (m *MsgUpdateParamsResponse) 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 +} +func sozTx(x uint64) (n int) { + return sovTx(uint64((x << 1) ^ uint64((int64(x) >> 63)))) +} +func (m *MsgUpdateParams) 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: MsgUpdateParams: wiretype end group for non-group") + } + if fieldNum <= 0 { + return fmt.Errorf("proto: MsgUpdateParams: 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 Params", 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.Params.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 *MsgUpdateParamsResponse) 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: MsgUpdateParamsResponse: wiretype end group for non-group") + } + if fieldNum <= 0 { + return fmt.Errorf("proto: MsgUpdateParamsResponse: 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 + depth := 0 + for iNdEx < l { + var wire uint64 + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return 0, ErrIntOverflowTx + } + if iNdEx >= l { + return 0, io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + wire |= (uint64(b) & 0x7F) << shift + if b < 0x80 { + break + } + } + wireType := int(wire & 0x7) + switch wireType { + case 0: + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return 0, ErrIntOverflowTx + } + if iNdEx >= l { + return 0, io.ErrUnexpectedEOF + } + iNdEx++ + if dAtA[iNdEx-1] < 0x80 { + break + } + } + case 1: + iNdEx += 8 + case 2: + var length int + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return 0, ErrIntOverflowTx + } + if iNdEx >= l { + return 0, io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + length |= (int(b) & 0x7F) << shift + if b < 0x80 { + break + } + } + if length < 0 { + return 0, ErrInvalidLengthTx + } + iNdEx += length + case 3: + depth++ + case 4: + if depth == 0 { + return 0, ErrUnexpectedEndOfGroupTx + } + depth-- + case 5: + iNdEx += 4 + default: + return 0, fmt.Errorf("proto: illegal wireType %d", wireType) + } + if iNdEx < 0 { + return 0, ErrInvalidLengthTx + } + if depth == 0 { + return iNdEx, nil + } + } + return 0, io.ErrUnexpectedEOF +} + +var ( + ErrInvalidLengthTx = fmt.Errorf("proto: negative length found during unmarshaling") + ErrIntOverflowTx = fmt.Errorf("proto: integer overflow") + ErrUnexpectedEndOfGroupTx = fmt.Errorf("proto: unexpected end of group") +) diff --git a/x/votepersistence/types/types.go b/x/votepersistence/types/types.go new file mode 100644 index 00000000..ab1254f4 --- /dev/null +++ b/x/votepersistence/types/types.go @@ -0,0 +1 @@ +package types From 9700dbcd0942abf51969f1c181026908d05dd505 Mon Sep 17 00:00:00 2001 From: Yusuf Date: Mon, 27 Apr 2026 19:16:17 +0300 Subject: [PATCH 29/62] feat: add a collection map to store vote extensions --- x/votepersistence/keeper/keeper.go | 27 +++++++++++++++++++++++++++ x/votepersistence/types/keys.go | 2 ++ 2 files changed, 29 insertions(+) diff --git a/x/votepersistence/keeper/keeper.go b/x/votepersistence/keeper/keeper.go index ea31ae1c..da33720c 100644 --- a/x/votepersistence/keeper/keeper.go +++ b/x/votepersistence/keeper/keeper.go @@ -1,6 +1,7 @@ package keeper import ( + "context" "fmt" "cosmossdk.io/collections" @@ -11,6 +12,8 @@ import ( "github.com/node101-io/pulsar-chain/x/votepersistence/types" ) +const VoteStorageMapName string = "vote_storage" + type Keeper struct { storeService corestore.KVStoreService cdc codec.Codec @@ -19,6 +22,8 @@ type Keeper struct { // Typically, this should be the x/gov module account. authority []byte + voteStorage collections.Map[collections.Pair[int64, []byte], []byte] + Schema collections.Schema Params collections.Item[types.Params] } @@ -43,6 +48,12 @@ func NewKeeper( authority: authority, Params: collections.NewItem(sb, types.ParamsKey, "params", codec.CollValue[types.Params](cdc)), + + voteStorage: collections.NewMap(sb, + types.VoteStorageMapPrefix, + VoteStorageMapName, + collections.PairKeyCodec(collections.Int64Key, collections.BytesKey), + collections.BytesValue), } schema, err := sb.Build() @@ -58,3 +69,19 @@ func NewKeeper( func (k Keeper) GetAuthority() []byte { return k.authority } + +func (k Keeper) SetVote(ctx context.Context, blockHeight int64, minaAddress, voteExtensions []byte) error { + return k.voteStorage.Set(ctx, collections.Join(blockHeight, minaAddress), voteExtensions) +} +func (k Keeper) GetVote(ctx context.Context, blockHeight int64, minaAddress []byte) ([]byte, error) { + return k.voteStorage.Get(ctx, collections.Join(blockHeight, minaAddress)) +} +func (k Keeper) RemoveVote(ctx context.Context, blockHeight int64, minaAddress []byte) error { + return k.voteStorage.Remove(ctx, collections.Join(blockHeight, minaAddress)) +} +func (k Keeper) VoteExists(ctx context.Context, blockHeight int64, minaAddress []byte) (bool, error) { + return k.voteStorage.Has(ctx, collections.Join(blockHeight, minaAddress)) +} +func (k Keeper) IterateVotes(ctx context.Context) (collections.Iterator[collections.Pair[int64, []byte], []byte], error) { + return k.voteStorage.Iterate(ctx, nil) +} diff --git a/x/votepersistence/types/keys.go b/x/votepersistence/types/keys.go index 08def311..312cef67 100644 --- a/x/votepersistence/types/keys.go +++ b/x/votepersistence/types/keys.go @@ -17,3 +17,5 @@ const ( // ParamsKey is the prefix to retrieve all Params var ParamsKey = collections.NewPrefix("p_votepersistence") + +var VoteStorageMapPrefix = collections.NewPrefix("vote_storage_map") From 5b3ed0d16d43fab8a07cf176cfd8479d72e5baa3 Mon Sep 17 00:00:00 2001 From: Yusuf Date: Mon, 27 Apr 2026 19:51:38 +0300 Subject: [PATCH 30/62] refactor: remove local vote map and get votes from cometbft --- abci/helpers.go | 23 ----------------------- abci/process_proposal.go | 18 +++++++++++++----- 2 files changed, 13 insertions(+), 28 deletions(-) diff --git a/abci/helpers.go b/abci/helpers.go index 5edc9a33..a16ffd21 100644 --- a/abci/helpers.go +++ b/abci/helpers.go @@ -19,7 +19,6 @@ type AbciHandler struct { secondaryKey SecondaryKey stakingKeeper stakingkeeper.Keeper keyregistryKeeper keyregistrykeeper.Keeper - votes map[uint64]map[string][]byte // height -> minaAddress -> extension bytes } type VoteExtensionBody struct { @@ -40,25 +39,3 @@ func NewVoteExtHandler(secondaryKey SecondaryKey, stakingKeeper stakingkeeper.Ke keyregistryKeeper: keyregistryKeeper, } } - -func (h *AbciHandler) storeVote(height uint64, minaKey string, voteExt []byte) { - - voteMap := h.votes[height] - - voteMap[minaKey] = voteExt - -} - -func (h *AbciHandler) fetchVote(height uint64, minaKey string) []byte { - - voteMap := h.votes[height] - - return voteMap[minaKey] -} - -func (h *AbciHandler) fetchVotes(height uint64) map[string][]byte { - - voteMap := h.votes[height] - - return voteMap -} diff --git a/abci/process_proposal.go b/abci/process_proposal.go index 4f9a6061..e252b64c 100644 --- a/abci/process_proposal.go +++ b/abci/process_proposal.go @@ -47,16 +47,24 @@ func (h *AbciHandler) ProcessProposalHandler() sdk.ProcessProposalHandler { var signedStakePower int64 var currentValidatorStakePower int64 - voteExtMap := h.fetchVotes(uint64(req.GetHeight()) - 2) + votes := req.ProposedLastCommit.Votes + valInfoMap := make(map[string]validatorInfo) + + // Require at least 2/3 signed power to prevent proposer-side signature withholding. for _, val := range valInfo { - if voteExtMap[string(val.ConsensusAddr)] != nil { - signedStakePower += val.Power - } + valInfoMap[string(val.ConsensusAddr)] = val currentValidatorStakePower += val.Power } - if signedStakePower*3 >= currentValidatorStakePower*2 { + for _, vote := range votes { + _, ok := valInfoMap[string(vote.Validator.Address)] + if ok { + signedStakePower += vote.Validator.Power + } + } + + if signedStakePower*3 < currentValidatorStakePower*2 { return &abci.ResponseProcessProposal{Status: abci.ResponseProcessProposal_REJECT}, nil } From 62bd41a5145bd539c89432b6287e501fe3754e05 Mon Sep 17 00:00:00 2001 From: Yusuf Date: Wed, 29 Apr 2026 13:31:43 +0300 Subject: [PATCH 31/62] refactor: move functions to helpers and make vote extension compatible with spec --- abci/extend_vote.go | 114 ++------------- abci/helpers.go | 293 ++++++++++++++++++++++++++++++++++++--- abci/prepare_proposal.go | 38 ++--- abci/process_proposal.go | 49 +------ abci/verify_vote_ext.go | 27 ++-- 5 files changed, 309 insertions(+), 212 deletions(-) diff --git a/abci/extend_vote.go b/abci/extend_vote.go index c5e04b6b..d3abfcde 100644 --- a/abci/extend_vote.go +++ b/abci/extend_vote.go @@ -1,15 +1,10 @@ package vote_ext import ( - "math/big" - abci "github.com/cometbft/cometbft/abci/types" sdk "github.com/cosmos/cosmos-sdk/types" stakingkeeper "github.com/cosmos/cosmos-sdk/x/staking/keeper" - "github.com/node101-io/mina-signer-go/constants" - "github.com/node101-io/mina-signer-go/field" - "github.com/node101-io/mina-signer-go/keys" - "github.com/node101-io/mina-signer-go/poseidon" + keyregistrykeeper "github.com/node101-io/pulsar-chain/x/keyregistry/keeper" ) const ActionsReducedRoot string = "pulsar" @@ -19,86 +14,16 @@ type validatorInfo struct { Power int64 } -func MockSign(voteExtBody VoteExtensionBody) []byte { - return []byte{} -} - -func MockSignatureVerify(voteExtBody VoteExtensionBody, minaKey []byte, reducedRoot string) bool { - return true +type VoteExtensionBody struct { + NextValidatorSetHash []byte + CurrentStateRoot []byte + CurrentBlockHeight int64 } -func (h *AbciHandler) getValidatorSet(ctx sdk.Context, currentBlockHeight int64) ([]validatorInfo, error) { - - historicalData, err := h.stakingKeeper.GetHistoricalInfo(ctx, currentBlockHeight) - if err != nil { - return nil, err - } - - validatorSet := historicalData.Valset - - var valInfo []validatorInfo - - for _, validator := range validatorSet { - - consAddr, err := validator.GetConsAddr() - if err != nil { - return nil, err - } - - consPower := validator.ConsensusPower(sdk.DefaultPowerReduction) - - valInfo = append(valInfo, validatorInfo{ - ConsensusAddr: consAddr, - Power: consPower, - }) - } - return valInfo, nil -} - -func (h *AbciHandler) calculateValidatorSetRoot(ctx sdk.Context, valInfo []validatorInfo, poseidonHash *poseidon.Poseidon) (*big.Int, error) { - - input := []*big.Int{big.NewInt(0)} - merkleRoot := poseidonHash.Hash(input) - - for _, validator := range valInfo { - input = []*big.Int{} - - minaPubKeyExists, err := h.keyregistryKeeper.ValidatorCosmosToMinaHas(ctx, validator.ConsensusAddr) - if err != nil { - return nil, err - } - if !minaPubKeyExists { - return nil, err - } - - minaPubKey, err := h.keyregistryKeeper.ValidatorGetCosmosToMina(ctx, validator.ConsensusAddr) - if err != nil { - return nil, err - } - - MinaPublicKey, err := keys.PublicKey{}.FromAddress(string(minaPubKey)) - if err != nil { - return nil, err - } - - input = append(input, MinaPublicKey.X) - if MinaPublicKey.IsOdd { - input = append(input, big.NewInt(1)) - } else { - input = append(input, big.NewInt(0)) - } - power := new(big.Int).SetInt64(validator.Power) - input = append(input, power) - - hashOfAddr := poseidonHash.Hash(input) - - input = []*big.Int{merkleRoot, hashOfAddr} - - merkleRoot = poseidonHash.Hash(input) - } - - return merkleRoot, nil - +type AbciHandler struct { + secondaryKey SecondaryKey + stakingKeeper stakingkeeper.Keeper + keyregistryKeeper keyregistrykeeper.Keeper } func (h *AbciHandler) ExtendVoteHandler() sdk.ExtendVoteHandler { @@ -107,30 +32,11 @@ func (h *AbciHandler) ExtendVoteHandler() sdk.ExtendVoteHandler { return &abci.ResponseExtendVote{VoteExtension: []byte{}}, nil } - twoBlocksBefore, err := stakingkeeper.Keeper.GetHistoricalInfo(h.stakingKeeper, ctx, req.GetHeight()-2) - if err != nil { - return &abci.ResponseExtendVote{VoteExtension: []byte{}}, err - } - - nextBlockHeight := req.GetHeight() - 1 - - poseidonHash := poseidon.CreatePoseidon(*field.Fp, constants.PoseidonParamsKimchiFp) - - nextValSet, err := h.getValidatorSet(ctx, nextBlockHeight) - if err != nil { - return nil, err - } - nextValidatorSetHash, err := h.calculateValidatorSetRoot(ctx, nextValSet, poseidonHash) + body, err := h.constructVoteExtBody(ctx, req.GetHeight()) if err != nil { return nil, err } - body := VoteExtensionBody{ - NextBlockHeight: nextBlockHeight, - CurrentStateRoot: twoBlocksBefore.Header.AppHash, - NextValidatorSetHash: nextValidatorSetHash.Bytes(), - } - bz := MockSign(body) return &abci.ResponseExtendVote{VoteExtension: bz}, nil diff --git a/abci/helpers.go b/abci/helpers.go index a16ffd21..c11ee04e 100644 --- a/abci/helpers.go +++ b/abci/helpers.go @@ -1,41 +1,294 @@ package vote_ext import ( + "context" + "encoding/hex" + "encoding/json" + "fmt" + "math/big" + "strings" + + abci "github.com/cometbft/cometbft/abci/types" + sdk "github.com/cosmos/cosmos-sdk/types" stakingkeeper "github.com/cosmos/cosmos-sdk/x/staking/keeper" + "github.com/node101-io/mina-signer-go/constants" + "github.com/node101-io/mina-signer-go/field" "github.com/node101-io/mina-signer-go/keys" + "github.com/node101-io/mina-signer-go/poseidon" keyregistrykeeper "github.com/node101-io/pulsar-chain/x/keyregistry/keeper" ) -var VoteExtMarker []byte = []byte("VOTEEXT:") - -const AcceptanceRatio float64 = 0.66 - type SecondaryKey struct { SecretKey *keys.PrivateKey PublicKey *keys.PublicKey } -type AbciHandler struct { - secondaryKey SecondaryKey - stakingKeeper stakingkeeper.Keeper - keyregistryKeeper keyregistrykeeper.Keeper +func NewVoteExtHandler(secondaryKey SecondaryKey, stakingKeeper stakingkeeper.Keeper, keyregistryKeeper keyregistrykeeper.Keeper) *AbciHandler { + return &AbciHandler{ + secondaryKey: secondaryKey, + stakingKeeper: stakingKeeper, + keyregistryKeeper: keyregistryKeeper, + } } -type VoteExtensionBody struct { - NextValidatorSetHash []byte - CurrentStateRoot []byte - NextBlockHeight int64 +func MockSign(voteExtBody VoteExtensionBody) []byte { + return []byte{} } -type payload struct { - Height uint64 `json:"height"` - Votes map[string][]byte `json:"votes"` +func MockSignatureVerify(signature []byte, message VoteExtensionBody, minaKey []byte, reducedRoot string) bool { + return true } -func NewVoteExtHandler(secondaryKey SecondaryKey, stakingKeeper stakingkeeper.Keeper, keyregistryKeeper keyregistrykeeper.Keeper) *AbciHandler { - return &AbciHandler{ - secondaryKey: secondaryKey, - stakingKeeper: stakingKeeper, - keyregistryKeeper: keyregistryKeeper, +func (h *AbciHandler) verifyVoteExtension(ctx context.Context, txs [][]byte, body VoteExtensionBody) error { + + voteExtensionTx := txs[0] + + if !strings.Contains(string(txs[0]), VoteExtMarker) { + return fmt.Errorf("") + } + + voteExtensionTx = voteExtensionTx[len([]byte(VoteExtMarker)):] + + var payload payload + + err := json.Unmarshal(voteExtensionTx, &payload) + if err != nil { + return err + } + + for publicKey, vote := range payload.Votes { + + pk, err := hex.DecodeString(publicKey) + if err != nil { + return err + } + + exists, err := h.keyregistryKeeper.ValidatorCosmosToMinaHas(ctx, pk) + if err != nil { + return err + } + if !exists { + return fmt.Errorf("") + } + + minaKey, err := h.keyregistryKeeper.ValidatorGetCosmosToMina(ctx, pk) + if err != nil { + return err + } + + if !MockSignatureVerify(vote, body, minaKey, ActionsReducedRoot) { + return fmt.Errorf("") + } + + } + + return nil +} + +func (h *AbciHandler) getValidatorSet(ctx sdk.Context, currentBlockHeight int64) ([]validatorInfo, error) { + + historicalData, err := h.stakingKeeper.GetHistoricalInfo(ctx, currentBlockHeight) + if err != nil { + return nil, err + } + + validatorSet := historicalData.Valset + + var valInfo []validatorInfo + + for _, validator := range validatorSet { + + consAddr, err := validator.GetConsAddr() + if err != nil { + return nil, err + } + + consPower := validator.ConsensusPower(sdk.DefaultPowerReduction) + + valInfo = append(valInfo, validatorInfo{ + ConsensusAddr: consAddr, + Power: consPower, + }) } + return valInfo, nil +} + +// TODO: Move this helper to mina-signer-go +func (h *AbciHandler) calculateValidatorSetRoot(ctx sdk.Context, valInfo []validatorInfo, poseidonHash *poseidon.Poseidon) (*big.Int, error) { + + input := []*big.Int{big.NewInt(0)} + merkleRoot := poseidonHash.Hash(input) + + for _, validator := range valInfo { + input = []*big.Int{} + + cosmosValidatorInfo, err := h.stakingKeeper.Validator(ctx, validator.ConsensusAddr) + if err != nil { + return nil, err + } + + cosmosValidatorPubKey, err := cosmosValidatorInfo.ConsPubKey() + if err != nil { + return nil, err + } + + minaPubKeyExists, err := h.keyregistryKeeper.ValidatorCosmosToMinaHas(ctx, cosmosValidatorPubKey.Bytes()) + if err != nil { + return nil, err + } + if !minaPubKeyExists { + return nil, err + } + + minaPubKey, err := h.keyregistryKeeper.ValidatorGetCosmosToMina(ctx, cosmosValidatorPubKey.Bytes()) + if err != nil { + return nil, err + } + + MinaPublicKey, err := keys.PublicKey{}.FromAddress(string(minaPubKey)) + if err != nil { + return nil, err + } + + input = append(input, MinaPublicKey.X) + if MinaPublicKey.IsOdd { + input = append(input, big.NewInt(1)) + } else { + input = append(input, big.NewInt(0)) + } + power := new(big.Int).SetInt64(validator.Power) + input = append(input, power) + + hashOfAddr := poseidonHash.Hash(input) + + input = []*big.Int{merkleRoot, hashOfAddr} + + merkleRoot = poseidonHash.Hash(input) + } + + return merkleRoot, nil + +} + +func (h *AbciHandler) checkStakePower(ctx sdk.Context, blockHeight int64, txs [][]byte) (bool, error) { + var signedStakePower int64 + var currentValidatorStakePower int64 + + valInfoMap := make(map[string]validatorInfo) + + currentValidatorSet, err := h.getValidatorSet(ctx, blockHeight-2) + if err != nil { + return false, err + } + + // Require at least 2/3 signed power to prevent proposer-side signature withholding. + for _, val := range currentValidatorSet { + + cosmosValidatorPubKey, err := h.getValidatorPublicKey(ctx, val.ConsensusAddr) + if err != nil { + return false, err + } + + valInfoMap[hex.EncodeToString(cosmosValidatorPubKey)] = val + currentValidatorStakePower += val.Power + } + + voteExtensionTx := txs[0] + + voteExtensionTx = voteExtensionTx[len([]byte(VoteExtMarker)):] + + var payload payload + + err = json.Unmarshal(voteExtensionTx, &payload) + if err != nil { + return false, err + } + + for addr := range payload.Votes { + validatorInfo, ok := valInfoMap[addr] + if ok { + signedStakePower += validatorInfo.Power + } + } + if signedStakePower*3 < currentValidatorStakePower*2 { + return false, nil + } + + return true, nil +} + +func (h *AbciHandler) constructVoteExtBody(ctx sdk.Context, blockHeight int64) (VoteExtensionBody, error) { + + nextValidatorSet, err := h.getValidatorSet(ctx, blockHeight) + if err != nil { + return VoteExtensionBody{}, err + } + + currentBlockInfo, err := h.stakingKeeper.GetHistoricalInfo(ctx, blockHeight-1) + if err != nil { + return VoteExtensionBody{}, err + } + + poseidonHash := poseidon.CreatePoseidon(*field.Fp, constants.PoseidonParamsKimchiFp) + + nextValidatorSetHash, err := h.calculateValidatorSetRoot(ctx, nextValidatorSet, poseidonHash) + if err != nil { + return VoteExtensionBody{}, err + } + if nextValidatorSetHash == nil { + return VoteExtensionBody{}, err + } + + return VoteExtensionBody{ + NextValidatorSetHash: nextValidatorSetHash.Bytes(), + CurrentStateRoot: currentBlockInfo.Header.AppHash, + CurrentBlockHeight: blockHeight - 1, + }, nil +} + +func (h *AbciHandler) getValidatorPublicKey(ctx sdk.Context, validatorAddr []byte) ([]byte, error) { + cosmosValidatorInfo, err := h.stakingKeeper.Validator(ctx, validatorAddr) + if err != nil { + return nil, err + } + cosmosValidatorPubKey, err := cosmosValidatorInfo.ConsPubKey() + if err != nil { + return nil, err + } + + return cosmosValidatorPubKey.Bytes(), nil +} + +func (h *AbciHandler) constructPayload(ctx sdk.Context, blockHeight int64, voteExtensions []abci.ExtendedVoteInfo) (payload, error) { + voteExtsForGivenBlock := make(map[string][]byte) + currentValidatorSetMap := make(map[string]bool) + + currentValidatorSet, err := h.getValidatorSet(ctx, blockHeight-2) + if err != nil { + return payload{}, err + } + + for _, currentValidator := range currentValidatorSet { + currentValidatorSetMap[string(currentValidator.ConsensusAddr)] = true + } + + for i, vote := range voteExtensions { + + if !currentValidatorSetMap[string(vote.Validator.Address)] { + continue + } + + cosmosValidatorPubKey, err := h.getValidatorPublicKey(ctx, vote.Validator.Address) + if err != nil { + return payload{}, err + } + + voteExtsForGivenBlock[hex.EncodeToString(cosmosValidatorPubKey)] = voteExtensions[i].VoteExtension + } + + if len(voteExtsForGivenBlock) == 0 { + return payload{}, nil + } + + return payload{Height: blockHeight - 1, Votes: voteExtsForGivenBlock}, nil } diff --git a/abci/prepare_proposal.go b/abci/prepare_proposal.go index a5b34ec4..feaa7116 100644 --- a/abci/prepare_proposal.go +++ b/abci/prepare_proposal.go @@ -2,51 +2,35 @@ package vote_ext import ( "encoding/json" - "fmt" abci "github.com/cometbft/cometbft/abci/types" sdk "github.com/cosmos/cosmos-sdk/types" ) +var VoteExtMarker string = "VOTEEXT:" + +type payload struct { + Height int64 `json:"height"` + Votes map[string][]byte `json:"votes"` +} + func (h *AbciHandler) PrepareProposalHandler() sdk.PrepareProposalHandler { return func(ctx sdk.Context, req *abci.RequestPrepareProposal) (*abci.ResponsePrepareProposal, error) { - voteExtsForGivenBlock := make(map[string][]byte) - targetHeight := uint64(req.GetHeight() - 1) - - valInfo, err := h.getValidatorSet(ctx, req.Height) + votes := req.LocalLastCommit.Votes + pl, err := h.constructPayload(ctx, req.GetHeight(), votes) if err != nil { return &abci.ResponsePrepareProposal{Txs: req.Txs}, err } - for i, val := range valInfo { - - exists, err := h.keyregistryKeeper.ValidatorCosmosToMinaHas(ctx, val.ConsensusAddr) - if err != nil { - return &abci.ResponsePrepareProposal{Txs: req.Txs}, err - } - if !exists { - return &abci.ResponsePrepareProposal{Txs: req.Txs}, err - } - - votes := req.LocalLastCommit.Votes - - voteExtsForGivenBlock[string(votes[i].Validator.Address)] = votes[i].ExtensionSignature - } - - if len(voteExtsForGivenBlock) == 0 { - return &abci.ResponsePrepareProposal{Txs: req.Txs}, err - } - - pl := payload{Height: targetHeight, Votes: voteExtsForGivenBlock} bz, err := json.Marshal(pl) if err != nil { - return nil, fmt.Errorf("") + return nil, err } // prefix makes it easier to identify the vote extension - extTx := append(VoteExtMarker, bz...) + extTx := append([]byte(VoteExtMarker), bz...) // prepend to existing txs txs := make([][]byte, 0, len(req.Txs)+1) diff --git a/abci/process_proposal.go b/abci/process_proposal.go index e252b64c..83d15ab1 100644 --- a/abci/process_proposal.go +++ b/abci/process_proposal.go @@ -1,12 +1,10 @@ package vote_ext import ( + "fmt" + abci "github.com/cometbft/cometbft/abci/types" sdk "github.com/cosmos/cosmos-sdk/types" - stakingkeeper "github.com/cosmos/cosmos-sdk/x/staking/keeper" - "github.com/node101-io/mina-signer-go/constants" - "github.com/node101-io/mina-signer-go/field" - "github.com/node101-io/mina-signer-go/poseidon" ) func (h *AbciHandler) ProcessProposalHandler() sdk.ProcessProposalHandler { @@ -18,58 +16,25 @@ func (h *AbciHandler) ProcessProposalHandler() sdk.ProcessProposalHandler { return &abci.ResponseProcessProposal{Status: abci.ResponseProcessProposal_ACCEPT}, nil } - // vote ext reconstruct - currentState, err := stakingkeeper.Keeper.GetHistoricalInfo(h.stakingKeeper, ctx, req.GetHeight()-2) + body, err := h.constructVoteExtBody(ctx, req.GetHeight()-1) if err != nil { return &abci.ResponseProcessProposal{Status: abci.ResponseProcessProposal_REJECT}, err } - valInfo, err := h.getValidatorSet(ctx, req.GetHeight()-1) + err = h.verifyVoteExtension(ctx, req.Txs, body) if err != nil { return &abci.ResponseProcessProposal{Status: abci.ResponseProcessProposal_REJECT}, err } - poseidonHash := poseidon.CreatePoseidon(*field.Fp, constants.PoseidonParamsKimchiFp) - - nextValidatorSetHash, err := h.calculateValidatorSetRoot(ctx, valInfo, poseidonHash) + isEnoughStakePower, err := h.checkStakePower(ctx, req.GetHeight(), req.Txs) if err != nil { return &abci.ResponseProcessProposal{Status: abci.ResponseProcessProposal_REJECT}, err } - if nextValidatorSetHash == nil { - return &abci.ResponseProcessProposal{Status: abci.ResponseProcessProposal_REJECT}, err - } - body := VoteExtensionBody{ - NextBlockHeight: req.GetHeight() - 1, - CurrentStateRoot: currentState.Header.AppHash, - NextValidatorSetHash: nextValidatorSetHash.Bytes(), + if !isEnoughStakePower { + return &abci.ResponseProcessProposal{Status: abci.ResponseProcessProposal_REJECT}, fmt.Errorf("") } - var signedStakePower int64 - var currentValidatorStakePower int64 - - votes := req.ProposedLastCommit.Votes - valInfoMap := make(map[string]validatorInfo) - - // Require at least 2/3 signed power to prevent proposer-side signature withholding. - for _, val := range valInfo { - valInfoMap[string(val.ConsensusAddr)] = val - currentValidatorStakePower += val.Power - } - - for _, vote := range votes { - _, ok := valInfoMap[string(vote.Validator.Address)] - if ok { - signedStakePower += vote.Validator.Power - } - } - - if signedStakePower*3 < currentValidatorStakePower*2 { - return &abci.ResponseProcessProposal{Status: abci.ResponseProcessProposal_REJECT}, nil - } - - MockSignatureVerify(body, h.secondaryKey.PublicKey.X.Bytes(), ActionsReducedRoot) - // Vote extension successfully verified return &abci.ResponseProcessProposal{Status: abci.ResponseProcessProposal_ACCEPT}, nil } diff --git a/abci/verify_vote_ext.go b/abci/verify_vote_ext.go index 18eeb14e..167f3334 100644 --- a/abci/verify_vote_ext.go +++ b/abci/verify_vote_ext.go @@ -5,9 +5,6 @@ import ( abci "github.com/cometbft/cometbft/abci/types" sdk "github.com/cosmos/cosmos-sdk/types" - "github.com/node101-io/mina-signer-go/constants" - "github.com/node101-io/mina-signer-go/field" - "github.com/node101-io/mina-signer-go/poseidon" ) func (h *AbciHandler) VerifyVoteExtensionHandler() sdk.VerifyVoteExtensionHandler { @@ -20,39 +17,31 @@ func (h *AbciHandler) VerifyVoteExtensionHandler() sdk.VerifyVoteExtensionHandle return &abci.ResponseVerifyVoteExtension{Status: abci.ResponseVerifyVoteExtension_REJECT}, fmt.Errorf("rejected") } - cosmosValAddr := req.GetValidatorAddress() - - exists, err := h.keyregistryKeeper.ValidatorCosmosToMinaHas(ctx, cosmosValAddr) + cosmosValidatorPubKey, err := h.getValidatorPublicKey(ctx, req.ValidatorAddress) if err != nil { return &abci.ResponseVerifyVoteExtension{Status: abci.ResponseVerifyVoteExtension_REJECT}, err } - if !exists { + + exists, err := h.keyregistryKeeper.ValidatorCosmosToMinaHas(ctx, cosmosValidatorPubKey) + if err != nil { return &abci.ResponseVerifyVoteExtension{Status: abci.ResponseVerifyVoteExtension_REJECT}, err } - poseidonHash := poseidon.CreatePoseidon(*field.Fp, constants.PoseidonParamsKimchiFp) - - minaKey, err := h.keyregistryKeeper.ValidatorGetCosmosToMina(ctx, cosmosValAddr) - if err != nil { + if !exists { return &abci.ResponseVerifyVoteExtension{Status: abci.ResponseVerifyVoteExtension_REJECT}, err } - valInfo, err := h.getValidatorSet(ctx, req.Height) + minaKey, err := h.keyregistryKeeper.ValidatorGetCosmosToMina(ctx, cosmosValidatorPubKey) if err != nil { return &abci.ResponseVerifyVoteExtension{Status: abci.ResponseVerifyVoteExtension_REJECT}, err } - setRoot, err := h.calculateValidatorSetRoot(ctx, valInfo, poseidonHash) + body, err := h.constructVoteExtBody(ctx, req.GetHeight()) if err != nil { return &abci.ResponseVerifyVoteExtension{Status: abci.ResponseVerifyVoteExtension_REJECT}, err } - sigValidity := MockSignatureVerify(VoteExtensionBody{ - NextValidatorSetHash: setRoot.Bytes(), - CurrentStateRoot: ctx.HeaderInfo().AppHash, - NextBlockHeight: req.Height, - }, minaKey, ActionsReducedRoot) - + sigValidity := MockSignatureVerify(req.VoteExtension, body, minaKey, ActionsReducedRoot) if !sigValidity { return &abci.ResponseVerifyVoteExtension{Status: abci.ResponseVerifyVoteExtension_REJECT}, err } From b7b0f63f059a9456d6df8a4e8727e54c0d417543 Mon Sep 17 00:00:00 2001 From: Yusuf Date: Wed, 29 Apr 2026 19:41:05 +0300 Subject: [PATCH 32/62] fix: prepare/process proposals with blocks < 3 to remove the empty vote extension error --- abci/extend_vote.go | 1 + abci/prepare_proposal.go | 6 ++++++ abci/process_proposal.go | 4 ++-- 3 files changed, 9 insertions(+), 2 deletions(-) diff --git a/abci/extend_vote.go b/abci/extend_vote.go index d3abfcde..65bbcf54 100644 --- a/abci/extend_vote.go +++ b/abci/extend_vote.go @@ -28,6 +28,7 @@ type AbciHandler struct { func (h *AbciHandler) ExtendVoteHandler() sdk.ExtendVoteHandler { return func(ctx sdk.Context, req *abci.RequestExtendVote) (*abci.ResponseExtendVote, error) { + if req.GetHeight() < 3 { return &abci.ResponseExtendVote{VoteExtension: []byte{}}, nil } diff --git a/abci/prepare_proposal.go b/abci/prepare_proposal.go index feaa7116..aa6f85ee 100644 --- a/abci/prepare_proposal.go +++ b/abci/prepare_proposal.go @@ -18,6 +18,12 @@ func (h *AbciHandler) PrepareProposalHandler() sdk.PrepareProposalHandler { return func(ctx sdk.Context, req *abci.RequestPrepareProposal) (*abci.ResponsePrepareProposal, error) { + // to construct the payload we need to get the N-2th block's vote extensions. + // Hence, enabling prepare proposal on blocks < 3 will result in error. + if req.Height < 3 { + return &abci.ResponsePrepareProposal{Txs: req.Txs}, nil + } + votes := req.LocalLastCommit.Votes pl, err := h.constructPayload(ctx, req.GetHeight(), votes) if err != nil { diff --git a/abci/process_proposal.go b/abci/process_proposal.go index 83d15ab1..c3184ea6 100644 --- a/abci/process_proposal.go +++ b/abci/process_proposal.go @@ -11,8 +11,8 @@ func (h *AbciHandler) ProcessProposalHandler() sdk.ProcessProposalHandler { return func(ctx sdk.Context, req *abci.RequestProcessProposal) (*abci.ResponseProcessProposal, error) { - // If height is 1, we won't have any votes thus skip the proposal - if req.GetHeight() == 1 { + // If height is less than 3, we won't have any votes thus skip the proposal + if req.GetHeight() < 3 { return &abci.ResponseProcessProposal{Status: abci.ResponseProcessProposal_ACCEPT}, nil } From f32ea87a0f2bb2b4c4b95c4f091ee93eaf6d9e4f Mon Sep 17 00:00:00 2001 From: Yusuf Date: Wed, 29 Apr 2026 19:41:34 +0300 Subject: [PATCH 33/62] feat: enable vote extensions --- app/app.go | 42 ++++++++++++++++++++++++++++++++++++++++++ config.yml | 6 ++++++ 2 files changed, 48 insertions(+) diff --git a/app/app.go b/app/app.go index f0f85bd8..6d6d0470 100644 --- a/app/app.go +++ b/app/app.go @@ -1,7 +1,10 @@ package app import ( + "encoding/base64" + "fmt" "io" + "math/big" clienthelpers "cosmossdk.io/client/v2/helpers" "cosmossdk.io/core/appmodule" @@ -45,6 +48,8 @@ import ( ibctransferkeeper "github.com/cosmos/ibc-go/v10/modules/apps/transfer/keeper" ibckeeper "github.com/cosmos/ibc-go/v10/modules/core/keeper" + "github.com/node101-io/mina-signer-go/keys" + vote_ext "github.com/node101-io/pulsar-chain/abci" "github.com/node101-io/pulsar-chain/docs" keyregistrymodulekeeper "github.com/node101-io/pulsar-chain/x/keyregistry/keeper" pulsarmodulekeeper "github.com/node101-io/pulsar-chain/x/pulsar/keeper" @@ -105,6 +110,8 @@ type App struct { PulsarKeeper pulsarmodulekeeper.Keeper KeyregistryKeeper keyregistrymodulekeeper.Keeper VotepersistenceKeeper votepersistencemodulekeeper.Keeper + + AbciHandler *vote_ext.AbciHandler } func init() { @@ -191,6 +198,35 @@ func New( panic(err) } + minaPrivKey := appOpts.Get("vote_extension.priv_key") + keyStr, ok := minaPrivKey.(string) + if !ok { + panic("vote_extension.priv_key is not a string") + } + + // Decode base64 -> bytes + keyBytes, err := base64.StdEncoding.DecodeString(keyStr) + if err != nil { + panic(fmt.Sprintf("failed to decode base64 priv key: %v", err)) + } + + // Bytes -> big.Int + prv := new(big.Int).SetBytes(keyBytes) + priv := keys.PrivateKey{ + Value: prv, + } + public := priv.ToPublicKey() + secondaryKey := vote_ext.SecondaryKey{ + SecretKey: &priv, + PublicKey: &public, + } + + app.AbciHandler = vote_ext.NewVoteExtHandler( + secondaryKey, + *app.StakingKeeper, + app.KeyregistryKeeper, + ) + // add to default baseapp options // enable optimistic execution baseAppOptions = append(baseAppOptions, baseapp.SetOptimisticExecution()) @@ -198,6 +234,12 @@ func New( // build app app.App = appBuilder.Build(db, traceStore, baseAppOptions...) + app.SetExtendVoteHandler(app.AbciHandler.ExtendVoteHandler()) + app.SetVerifyVoteExtensionHandler(app.AbciHandler.VerifyVoteExtensionHandler()) + app.SetPrepareProposal(app.AbciHandler.PrepareProposalHandler()) + app.SetProcessProposal(app.AbciHandler.ProcessProposalHandler()) + app.SetPreBlocker(app.AbciHandler.PreBlocker()) + // register legacy modules if err := app.registerIBCModules(appOpts); err != nil { panic(err) diff --git a/config.yml b/config.yml index e6c65e01..2c85602e 100644 --- a/config.yml +++ b/config.yml @@ -28,6 +28,8 @@ validators: - name: validator2 bonded: 100000000pmina + + genesis: app_state: keyregistry: @@ -40,3 +42,7 @@ genesis: validator_key_pairs: # - mina_key: "3IvK1eWmmcfdlIb+T04+ck9Q5bjbqHqiT0ucGJITzyY=" # cosmos_key: "A8saw69s1DQWvUjseeOtG8hGavmYiInrQ5M1aOPa4QkP" + consensus: + params: + abci: + vote_extensions_enable_height: "1" From 011acd96625f9168363a988f3fd634cb7c6ad8bd Mon Sep 17 00:00:00 2001 From: Yusuf Date: Wed, 29 Apr 2026 19:46:21 +0300 Subject: [PATCH 34/62] test: add tests for vote extension storage map --- x/votepersistence/keeper/vote_storage_test.go | 114 ++++++++++++++++++ 1 file changed, 114 insertions(+) create mode 100644 x/votepersistence/keeper/vote_storage_test.go diff --git a/x/votepersistence/keeper/vote_storage_test.go b/x/votepersistence/keeper/vote_storage_test.go new file mode 100644 index 00000000..6b04daba --- /dev/null +++ b/x/votepersistence/keeper/vote_storage_test.go @@ -0,0 +1,114 @@ +package keeper_test + +import ( + "bytes" + "testing" + + "cosmossdk.io/collections" + "github.com/stretchr/testify/require" +) + +type voteEntry struct { + blockHeight int64 + minaAddress []byte + voteExtensions []byte +} + +func TestVoteStorageSetGetHas(t *testing.T) { + f := initFixture(t) + + blockHeight := int64(42) + minaAddress := []byte("mina-address-1") + voteExtensions := []byte("vote-extension-1") + + exists, err := f.keeper.VoteExists(f.ctx, blockHeight, minaAddress) + require.NoError(t, err) + require.False(t, exists) + + err = f.keeper.SetVote(f.ctx, blockHeight, minaAddress, voteExtensions) + require.NoError(t, err) + + got, err := f.keeper.GetVote(f.ctx, blockHeight, minaAddress) + require.NoError(t, err) + require.Equal(t, voteExtensions, got) + + exists, err = f.keeper.VoteExists(f.ctx, blockHeight, minaAddress) + require.NoError(t, err) + require.True(t, exists) +} + +func TestVoteStorageGetFailsWhenVoteMissing(t *testing.T) { + f := initFixture(t) + + _, err := f.keeper.GetVote(f.ctx, 42, []byte("missing-mina-address")) + require.ErrorIs(t, err, collections.ErrNotFound) +} + +func TestVoteStorageRemove(t *testing.T) { + f := initFixture(t) + + blockHeight := int64(42) + minaAddress := []byte("mina-address-1") + voteExtensions := []byte("vote-extension-1") + + err := f.keeper.SetVote(f.ctx, blockHeight, minaAddress, voteExtensions) + require.NoError(t, err) + + exists, err := f.keeper.VoteExists(f.ctx, blockHeight, minaAddress) + require.NoError(t, err) + require.True(t, exists) + + err = f.keeper.RemoveVote(f.ctx, blockHeight, minaAddress) + require.NoError(t, err) + + exists, err = f.keeper.VoteExists(f.ctx, blockHeight, minaAddress) + require.NoError(t, err) + require.False(t, exists) + + _, err = f.keeper.GetVote(f.ctx, blockHeight, minaAddress) + require.ErrorIs(t, err, collections.ErrNotFound) +} + +func TestVoteStorageIterate(t *testing.T) { + f := initFixture(t) + + entries := []voteEntry{ + {blockHeight: 8, minaAddress: []byte("mina-b"), voteExtensions: []byte("vote-b")}, + {blockHeight: 3, minaAddress: []byte("mina-c"), voteExtensions: []byte("vote-c")}, + {blockHeight: 3, minaAddress: []byte("mina-a"), voteExtensions: []byte("vote-a")}, + } + + for _, entry := range entries { + err := f.keeper.SetVote(f.ctx, entry.blockHeight, entry.minaAddress, entry.voteExtensions) + require.NoError(t, err) + } + + iter, err := f.keeper.IterateVotes(f.ctx) + require.NoError(t, err) + defer iter.Close() + + var got []voteEntry + for iter.Valid() { + key, err := iter.Key() + require.NoError(t, err) + + value, err := iter.Value() + require.NoError(t, err) + + got = append(got, voteEntry{ + blockHeight: key.K1(), + minaAddress: bytes.Clone(key.K2()), + voteExtensions: bytes.Clone(value), + }) + + iter.Next() + } + + expected := []voteEntry{ + {blockHeight: 3, minaAddress: []byte("mina-a"), voteExtensions: []byte("vote-a")}, + {blockHeight: 3, minaAddress: []byte("mina-c"), voteExtensions: []byte("vote-c")}, + {blockHeight: 8, minaAddress: []byte("mina-b"), voteExtensions: []byte("vote-b")}, + } + + require.Equal(t, expected, got) +} From 11526ffc05eac218e6af2da294145889ce7c8d3b Mon Sep 17 00:00:00 2001 From: Yusuf Date: Wed, 29 Apr 2026 21:11:30 +0300 Subject: [PATCH 35/62] feat: add a function to allow removing all votes from the vote storage map --- x/votepersistence/keeper/keeper.go | 23 +++++++++++++++++++++++ 1 file changed, 23 insertions(+) diff --git a/x/votepersistence/keeper/keeper.go b/x/votepersistence/keeper/keeper.go index da33720c..1b43d965 100644 --- a/x/votepersistence/keeper/keeper.go +++ b/x/votepersistence/keeper/keeper.go @@ -79,6 +79,29 @@ func (k Keeper) GetVote(ctx context.Context, blockHeight int64, minaAddress []by func (k Keeper) RemoveVote(ctx context.Context, blockHeight int64, minaAddress []byte) error { return k.voteStorage.Remove(ctx, collections.Join(blockHeight, minaAddress)) } + +func (k Keeper) RemoveVotes(ctx context.Context) error { + + iterator, err := k.voteStorage.Iterate(ctx, nil) + if err != nil { + return err + } + defer iterator.Close() + + for iterator.Valid() { + key, err := iterator.Key() + if err != nil { + return err + } + err = k.voteStorage.Remove(ctx, key) + if err != nil { + return err + } + iterator.Next() + } + return nil +} + func (k Keeper) VoteExists(ctx context.Context, blockHeight int64, minaAddress []byte) (bool, error) { return k.voteStorage.Has(ctx, collections.Join(blockHeight, minaAddress)) } From 19927ea3e092fe44de9d66126767c6f9afe3ace2 Mon Sep 17 00:00:00 2001 From: Yusuf Date: Wed, 29 Apr 2026 21:14:14 +0300 Subject: [PATCH 36/62] feat: add a field to abci handler to use vote persistence module functionality --- abci/extend_vote.go | 8 +++++--- abci/helpers.go | 11 +++++++---- app/app.go | 1 + 3 files changed, 13 insertions(+), 7 deletions(-) diff --git a/abci/extend_vote.go b/abci/extend_vote.go index 65bbcf54..2cf27b64 100644 --- a/abci/extend_vote.go +++ b/abci/extend_vote.go @@ -5,6 +5,7 @@ import ( sdk "github.com/cosmos/cosmos-sdk/types" stakingkeeper "github.com/cosmos/cosmos-sdk/x/staking/keeper" keyregistrykeeper "github.com/node101-io/pulsar-chain/x/keyregistry/keeper" + votepersistence "github.com/node101-io/pulsar-chain/x/votepersistence/keeper" ) const ActionsReducedRoot string = "pulsar" @@ -21,9 +22,10 @@ type VoteExtensionBody struct { } type AbciHandler struct { - secondaryKey SecondaryKey - stakingKeeper stakingkeeper.Keeper - keyregistryKeeper keyregistrykeeper.Keeper + secondaryKey SecondaryKey + stakingKeeper stakingkeeper.Keeper + keyregistryKeeper keyregistrykeeper.Keeper + votePersistenceKeeper votepersistence.Keeper } func (h *AbciHandler) ExtendVoteHandler() sdk.ExtendVoteHandler { diff --git a/abci/helpers.go b/abci/helpers.go index c11ee04e..47a190c0 100644 --- a/abci/helpers.go +++ b/abci/helpers.go @@ -16,6 +16,7 @@ import ( "github.com/node101-io/mina-signer-go/keys" "github.com/node101-io/mina-signer-go/poseidon" keyregistrykeeper "github.com/node101-io/pulsar-chain/x/keyregistry/keeper" + votepersistence "github.com/node101-io/pulsar-chain/x/votepersistence/keeper" ) type SecondaryKey struct { @@ -23,11 +24,13 @@ type SecondaryKey struct { PublicKey *keys.PublicKey } -func NewVoteExtHandler(secondaryKey SecondaryKey, stakingKeeper stakingkeeper.Keeper, keyregistryKeeper keyregistrykeeper.Keeper) *AbciHandler { +func NewVoteExtHandler(secondaryKey SecondaryKey, stakingKeeper stakingkeeper.Keeper, + keyregistryKeeper keyregistrykeeper.Keeper, votepersistenceKeeper votepersistence.Keeper) *AbciHandler { return &AbciHandler{ - secondaryKey: secondaryKey, - stakingKeeper: stakingKeeper, - keyregistryKeeper: keyregistryKeeper, + secondaryKey: secondaryKey, + stakingKeeper: stakingKeeper, + keyregistryKeeper: keyregistryKeeper, + votePersistenceKeeper: votepersistenceKeeper, } } diff --git a/app/app.go b/app/app.go index 6d6d0470..acc1ab20 100644 --- a/app/app.go +++ b/app/app.go @@ -225,6 +225,7 @@ func New( secondaryKey, *app.StakingKeeper, app.KeyregistryKeeper, + app.VotepersistenceKeeper, ) // add to default baseapp options From 3d283d569bd505b6bd360419af6ae202d690438a Mon Sep 17 00:00:00 2001 From: Yusuf Date: Wed, 29 Apr 2026 21:14:33 +0300 Subject: [PATCH 37/62] feat: implement pre blocker --- abci/pre_blocker.go | 82 +++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 82 insertions(+) create mode 100644 abci/pre_blocker.go diff --git a/abci/pre_blocker.go b/abci/pre_blocker.go new file mode 100644 index 00000000..31f31a88 --- /dev/null +++ b/abci/pre_blocker.go @@ -0,0 +1,82 @@ +package vote_ext + +import ( + "encoding/hex" + "encoding/json" + "fmt" + + abci "github.com/cometbft/cometbft/abci/types" + sdk "github.com/cosmos/cosmos-sdk/types" +) + +func (h *AbciHandler) PreBlocker() sdk.PreBlocker { + return func(ctx sdk.Context, req *abci.RequestFinalizeBlock) (*sdk.ResponsePreBlock, error) { + + // If height is smaller than 4, we won't have any votes thus skip the proposal + if req.GetHeight() < 3 { + return &sdk.ResponsePreBlock{}, nil + } + + err := h.votePersistenceKeeper.RemoveVotes(ctx) + if err != nil { + return nil, err + } + + voteExtensionTx := req.Txs[0] + + voteExtensionTx = voteExtensionTx[len([]byte(VoteExtMarker)):] + + var pl payload + + err = json.Unmarshal(voteExtensionTx, &pl) + if err != nil { + return nil, err + } + + currentValidatorSet, err := h.getValidatorSet(ctx, req.GetHeight()-2) + if err != nil { + return nil, err + } + + currentValidatorSetMap := make(map[string][]byte) + + for _, currentValidator := range currentValidatorSet { + cosmosValidatorPublicKey, err := h.getValidatorPublicKey(ctx, currentValidator.ConsensusAddr) + if err != nil { + return nil, err + } + + currentValidatorSetMap[hex.EncodeToString(cosmosValidatorPublicKey)] = cosmosValidatorPublicKey + } + + for addr, vote := range pl.Votes { + + cosmosValidatorPublicKey, ok := currentValidatorSetMap[addr] + if !ok { + continue + } + + exists, err := h.keyregistryKeeper.ValidatorCosmosToMinaHas(ctx, cosmosValidatorPublicKey) + if err != nil { + return nil, err + } + + if !exists { + return nil, fmt.Errorf("") + } + + minaKey, err := h.keyregistryKeeper.ValidatorGetCosmosToMina(ctx, cosmosValidatorPublicKey) + if err != nil { + return nil, err + } + + err = h.votePersistenceKeeper.SetVote(ctx, req.GetHeight()-2, minaKey, vote) + if err != nil { + return nil, err + } + + } + + return &sdk.ResponsePreBlock{}, nil + } +} From 9da01310c2585e1c65ce24fd0ddcf7c675836dfe Mon Sep 17 00:00:00 2001 From: Yusuf Date: Wed, 29 Apr 2026 21:20:36 +0300 Subject: [PATCH 38/62] test: add a test for remove votes --- x/votepersistence/keeper/vote_storage_test.go | 30 +++++++++++++++++++ 1 file changed, 30 insertions(+) diff --git a/x/votepersistence/keeper/vote_storage_test.go b/x/votepersistence/keeper/vote_storage_test.go index 6b04daba..f3e9c2f2 100644 --- a/x/votepersistence/keeper/vote_storage_test.go +++ b/x/votepersistence/keeper/vote_storage_test.go @@ -69,6 +69,36 @@ func TestVoteStorageRemove(t *testing.T) { require.ErrorIs(t, err, collections.ErrNotFound) } +func TestVoteStorageRemoveVotes(t *testing.T) { + f := initFixture(t) + + entries := []voteEntry{ + {blockHeight: 3, minaAddress: []byte("mina-a"), voteExtensions: []byte("vote-a")}, + {blockHeight: 3, minaAddress: []byte("mina-b"), voteExtensions: []byte("vote-b")}, + {blockHeight: 8, minaAddress: []byte("mina-c"), voteExtensions: []byte("vote-c")}, + } + + for _, entry := range entries { + err := f.keeper.SetVote(f.ctx, entry.blockHeight, entry.minaAddress, entry.voteExtensions) + require.NoError(t, err) + } + + err := f.keeper.RemoveVotes(f.ctx) + require.NoError(t, err) + + for _, entry := range entries { + exists, err := f.keeper.VoteExists(f.ctx, entry.blockHeight, entry.minaAddress) + require.NoError(t, err) + require.False(t, exists) + } + + iter, err := f.keeper.IterateVotes(f.ctx) + require.NoError(t, err) + defer iter.Close() + + require.False(t, iter.Valid()) +} + func TestVoteStorageIterate(t *testing.T) { f := initFixture(t) From cc01120b834de93b4945df43a3910964ab6f0f15 Mon Sep 17 00:00:00 2001 From: Yusuf Date: Fri, 1 May 2026 22:23:01 +0300 Subject: [PATCH 39/62] feat: vote persistence module added --- docs/static/openapi.json | 2 +- .../votepersistence/v1/query.proto | 18 + x/keyregistry/types/address_pair.pb.go | 3 +- x/keyregistry/types/genesis.pb.go | 7 +- x/keyregistry/types/module.pb.go | 5 +- x/keyregistry/types/params.pb.go | 7 +- x/keyregistry/types/public_key_pair.pb.go | 3 +- x/keyregistry/types/query.pb.go | 7 +- x/keyregistry/types/tx.pb.go | 7 +- x/pulsar/types/genesis.pb.go | 7 +- x/pulsar/types/module.pb.go | 5 +- x/pulsar/types/params.pb.go | 7 +- x/pulsar/types/query.pb.go | 7 +- x/pulsar/types/tx.pb.go | 7 +- .../keeper/query_vote_ext_body_by_height.go | 17 + x/votepersistence/module/autocli.go | 7 + x/votepersistence/types/genesis.pb.go | 7 +- x/votepersistence/types/module.pb.go | 5 +- x/votepersistence/types/params.pb.go | 7 +- x/votepersistence/types/query.pb.go | 519 +++++++++++++++++- x/votepersistence/types/query.pb.gw.go | 101 ++++ x/votepersistence/types/tx.pb.go | 7 +- 22 files changed, 677 insertions(+), 85 deletions(-) create mode 100644 x/votepersistence/keeper/query_vote_ext_body_by_height.go diff --git a/docs/static/openapi.json b/docs/static/openapi.json index 0c92b26f..016726bb 100644 --- a/docs/static/openapi.json +++ b/docs/static/openapi.json @@ -1 +1 @@ -{"id":"github.com/node101-io/pulsar-chain","consumes":["application/json"],"produces":["application/json"],"swagger":"2.0","info":{"description":"Chain github.com/node101-io/pulsar-chain REST API","title":"HTTP API Console","contact":{"name":"github.com/node101-io/pulsar-chain"},"version":"version not set"},"paths":{"/node101-io/pulsar-chain/keyregistry/v1/get_user_cosmos_address/{user_mina_address}":{"get":{"tags":["Query"],"summary":"GetUserCosmosAddress Queries a list of GetUserCosmosAddress items.","operationId":"GithubComnode101IopulsarChainQuery_GetUserCosmosAddress","parameters":[{"type":"string","format":"byte","name":"user_mina_address","in":"path","required":true}],"responses":{"200":{"description":"A successful response.","schema":{"$ref":"#/definitions/pulsarchain.keyregistry.v1.QueryGetUserCosmosAddressResponse"}},"default":{"description":"An unexpected error response.","schema":{"$ref":"#/definitions/google.rpc.Status"}}}}},"/node101-io/pulsar-chain/keyregistry/v1/get_user_mina_address/{user_cosmos_address}":{"get":{"tags":["Query"],"summary":"GetUserMinaAddress Queries a list of GetUserMinaAddress items.","operationId":"GithubComnode101IopulsarChainQuery_GetUserMinaAddress","parameters":[{"type":"string","format":"byte","name":"user_cosmos_address","in":"path","required":true}],"responses":{"200":{"description":"A successful response.","schema":{"$ref":"#/definitions/pulsarchain.keyregistry.v1.QueryGetUserMinaAddressResponse"}},"default":{"description":"An unexpected error response.","schema":{"$ref":"#/definitions/google.rpc.Status"}}}}},"/node101-io/pulsar-chain/keyregistry/v1/get_validator_cosmos_pub_key/{validator_mina_pub_key}":{"get":{"tags":["Query"],"summary":"GetValidatorCosmosAddress Queries a list of GetValidatorCosmosAddress items.","operationId":"GithubComnode101IopulsarChainQuery_GetValidatorCosmosPubKey","parameters":[{"type":"string","format":"byte","name":"validator_mina_pub_key","in":"path","required":true}],"responses":{"200":{"description":"A successful response.","schema":{"$ref":"#/definitions/pulsarchain.keyregistry.v1.QueryGetValidatorCosmosPubKeyResponse"}},"default":{"description":"An unexpected error response.","schema":{"$ref":"#/definitions/google.rpc.Status"}}}}},"/node101-io/pulsar-chain/keyregistry/v1/get_validator_mina_pub_key/{validator_cosmos_pub_key}":{"get":{"tags":["Query"],"summary":"GetValidatorMinaAddress Queries a list of GetValidatorMinaAddress items.","operationId":"GithubComnode101IopulsarChainQuery_GetValidatorMinaPubKey","parameters":[{"type":"string","format":"byte","name":"validator_cosmos_pub_key","in":"path","required":true}],"responses":{"200":{"description":"A successful response.","schema":{"$ref":"#/definitions/pulsarchain.keyregistry.v1.QueryGetValidatorMinaPubKeyResponse"}},"default":{"description":"An unexpected error response.","schema":{"$ref":"#/definitions/google.rpc.Status"}}}}},"/node101-io/pulsar-chain/keyregistry/v1/params":{"get":{"tags":["Query"],"summary":"Parameters queries the parameters of the module.","operationId":"GithubComnode101IopulsarChainQuery_ParamsMixin8","responses":{"200":{"description":"A successful response.","schema":{"$ref":"#/definitions/pulsarchain.keyregistry.v1.QueryParamsResponse"}},"default":{"description":"An unexpected error response.","schema":{"$ref":"#/definitions/google.rpc.Status"}}}}},"/node101-io/pulsar-chain/votepersistence/v1/params":{"get":{"tags":["Query"],"summary":"Parameters queries the parameters of the module.","operationId":"GithubComnode101IopulsarChainQuery_ParamsMixin12","responses":{"200":{"description":"A successful response.","schema":{"$ref":"#/definitions/pulsarchain.votepersistence.v1.QueryParamsResponse"}},"default":{"description":"An unexpected error response.","schema":{"$ref":"#/definitions/google.rpc.Status"}}}}},"/pulsar/pulsar/v1/params":{"get":{"tags":["Query"],"summary":"Parameters queries the parameters of the module.","operationId":"GithubComnode101IopulsarChainQuery_Params","responses":{"200":{"description":"A successful response.","schema":{"$ref":"#/definitions/pulsar.pulsar.v1.QueryParamsResponse"}},"default":{"description":"An unexpected error response.","schema":{"$ref":"#/definitions/google.rpc.Status"}}}}}},"definitions":{"google.protobuf.Any":{"type":"object","properties":{"@type":{"type":"string"}},"additionalProperties":{}},"google.rpc.Status":{"type":"object","properties":{"code":{"type":"integer","format":"int32"},"details":{"type":"array","items":{"type":"object","$ref":"#/definitions/google.protobuf.Any"}},"message":{"type":"string"}}},"pulsar.pulsar.v1.Params":{"description":"Params defines the parameters for the module.","type":"object"},"pulsar.pulsar.v1.QueryParamsResponse":{"description":"QueryParamsResponse is response type for the Query/Params RPC method.","type":"object","properties":{"params":{"description":"params holds all the parameters of this module.","$ref":"#/definitions/pulsar.pulsar.v1.Params"}}},"pulsarchain.keyregistry.v1.Params":{"description":"Params defines the parameters for the module.","type":"object"},"pulsarchain.keyregistry.v1.QueryGetUserCosmosAddressResponse":{"description":"QueryGetUserCosmosAddressResponse defines the QueryGetUserCosmosAddressResponse message.","type":"object","properties":{"user_cosmos_address":{"type":"string","format":"byte"}}},"pulsarchain.keyregistry.v1.QueryGetUserMinaAddressResponse":{"description":"QueryGetUserMinaAddressResponse defines the QueryGetUserMinaAddressResponse message.","type":"object","properties":{"user_mina_address":{"type":"string","format":"byte"}}},"pulsarchain.keyregistry.v1.QueryGetValidatorCosmosPubKeyResponse":{"description":"QueryGetValidatorCosmosAddressResponse defines the QueryGetValidatorCosmosAddressResponse message.","type":"object","properties":{"validator_cosmos_pub_key":{"type":"string","format":"byte"}}},"pulsarchain.keyregistry.v1.QueryGetValidatorMinaPubKeyResponse":{"description":"QueryGetValidatorMinaAddressResponse defines the QueryGetValidatorMinaAddressResponse message.","type":"object","properties":{"validator_mina_pub_key":{"type":"string","format":"byte"}}},"pulsarchain.keyregistry.v1.QueryParamsResponse":{"description":"QueryParamsResponse is response type for the Query/Params RPC method.","type":"object","properties":{"params":{"description":"params holds all the parameters of this module.","$ref":"#/definitions/pulsarchain.keyregistry.v1.Params"}}},"pulsarchain.votepersistence.v1.Params":{"description":"Params defines the parameters for the module.","type":"object"},"pulsarchain.votepersistence.v1.QueryParamsResponse":{"description":"QueryParamsResponse is response type for the Query/Params RPC method.","type":"object","properties":{"params":{"description":"params holds all the parameters of this module.","$ref":"#/definitions/pulsarchain.votepersistence.v1.Params"}}}},"tags":[{"name":"Query"},{"name":"Msg"}]} +{"id":"github.com/node101-io/pulsar-chain","consumes":["application/json"],"produces":["application/json"],"swagger":"2.0","info":{"description":"Chain github.com/node101-io/pulsar-chain REST API","title":"HTTP API Console","contact":{"name":"github.com/node101-io/pulsar-chain"},"version":"version not set"},"paths":{"/node101-io/pulsar-chain/keyregistry/v1/get_user_cosmos_address/{user_mina_address}":{"get":{"tags":["Query"],"summary":"GetUserCosmosAddress Queries a list of GetUserCosmosAddress items.","operationId":"GithubComnode101IopulsarChainQuery_GetUserCosmosAddress","parameters":[{"type":"string","format":"byte","name":"user_mina_address","in":"path","required":true}],"responses":{"200":{"description":"A successful response.","schema":{"$ref":"#/definitions/pulsarchain.keyregistry.v1.QueryGetUserCosmosAddressResponse"}},"default":{"description":"An unexpected error response.","schema":{"$ref":"#/definitions/google.rpc.Status"}}}}},"/node101-io/pulsar-chain/keyregistry/v1/get_user_mina_address/{user_cosmos_address}":{"get":{"tags":["Query"],"summary":"GetUserMinaAddress Queries a list of GetUserMinaAddress items.","operationId":"GithubComnode101IopulsarChainQuery_GetUserMinaAddress","parameters":[{"type":"string","format":"byte","name":"user_cosmos_address","in":"path","required":true}],"responses":{"200":{"description":"A successful response.","schema":{"$ref":"#/definitions/pulsarchain.keyregistry.v1.QueryGetUserMinaAddressResponse"}},"default":{"description":"An unexpected error response.","schema":{"$ref":"#/definitions/google.rpc.Status"}}}}},"/node101-io/pulsar-chain/keyregistry/v1/get_validator_cosmos_pub_key/{validator_mina_pub_key}":{"get":{"tags":["Query"],"summary":"GetValidatorCosmosAddress Queries a list of GetValidatorCosmosAddress items.","operationId":"GithubComnode101IopulsarChainQuery_GetValidatorCosmosPubKey","parameters":[{"type":"string","format":"byte","name":"validator_mina_pub_key","in":"path","required":true}],"responses":{"200":{"description":"A successful response.","schema":{"$ref":"#/definitions/pulsarchain.keyregistry.v1.QueryGetValidatorCosmosPubKeyResponse"}},"default":{"description":"An unexpected error response.","schema":{"$ref":"#/definitions/google.rpc.Status"}}}}},"/node101-io/pulsar-chain/keyregistry/v1/get_validator_mina_pub_key/{validator_cosmos_pub_key}":{"get":{"tags":["Query"],"summary":"GetValidatorMinaAddress Queries a list of GetValidatorMinaAddress items.","operationId":"GithubComnode101IopulsarChainQuery_GetValidatorMinaPubKey","parameters":[{"type":"string","format":"byte","name":"validator_cosmos_pub_key","in":"path","required":true}],"responses":{"200":{"description":"A successful response.","schema":{"$ref":"#/definitions/pulsarchain.keyregistry.v1.QueryGetValidatorMinaPubKeyResponse"}},"default":{"description":"An unexpected error response.","schema":{"$ref":"#/definitions/google.rpc.Status"}}}}},"/node101-io/pulsar-chain/keyregistry/v1/params":{"get":{"tags":["Query"],"summary":"Parameters queries the parameters of the module.","operationId":"GithubComnode101IopulsarChainQuery_ParamsMixin8","responses":{"200":{"description":"A successful response.","schema":{"$ref":"#/definitions/pulsarchain.keyregistry.v1.QueryParamsResponse"}},"default":{"description":"An unexpected error response.","schema":{"$ref":"#/definitions/google.rpc.Status"}}}}},"/node101-io/pulsar-chain/votepersistence/v1/params":{"get":{"tags":["Query"],"summary":"Parameters queries the parameters of the module.","operationId":"GithubComnode101IopulsarChainQuery_ParamsMixin12","responses":{"200":{"description":"A successful response.","schema":{"$ref":"#/definitions/pulsarchain.votepersistence.v1.QueryParamsResponse"}},"default":{"description":"An unexpected error response.","schema":{"$ref":"#/definitions/google.rpc.Status"}}}}},"/node101-io/pulsar-chain/votepersistence/v1/vote_ext_body_by_height/{block_height}":{"get":{"tags":["Query"],"summary":"VoteExtBodyByHeight Queries a list of VoteExtBodyByHeight items.","operationId":"GithubComnode101IopulsarChainQuery_VoteExtBodyByHeight","parameters":[{"type":"string","format":"int64","name":"block_height","in":"path","required":true}],"responses":{"200":{"description":"A successful response.","schema":{"$ref":"#/definitions/pulsarchain.votepersistence.v1.QueryVoteExtBodyByHeightResponse"}},"default":{"description":"An unexpected error response.","schema":{"$ref":"#/definitions/google.rpc.Status"}}}}},"/pulsar/pulsar/v1/params":{"get":{"tags":["Query"],"summary":"Parameters queries the parameters of the module.","operationId":"GithubComnode101IopulsarChainQuery_Params","responses":{"200":{"description":"A successful response.","schema":{"$ref":"#/definitions/pulsar.pulsar.v1.QueryParamsResponse"}},"default":{"description":"An unexpected error response.","schema":{"$ref":"#/definitions/google.rpc.Status"}}}}}},"definitions":{"google.protobuf.Any":{"type":"object","properties":{"@type":{"type":"string"}},"additionalProperties":{}},"google.rpc.Status":{"type":"object","properties":{"code":{"type":"integer","format":"int32"},"details":{"type":"array","items":{"type":"object","$ref":"#/definitions/google.protobuf.Any"}},"message":{"type":"string"}}},"pulsar.pulsar.v1.Params":{"description":"Params defines the parameters for the module.","type":"object"},"pulsar.pulsar.v1.QueryParamsResponse":{"description":"QueryParamsResponse is response type for the Query/Params RPC method.","type":"object","properties":{"params":{"description":"params holds all the parameters of this module.","$ref":"#/definitions/pulsar.pulsar.v1.Params"}}},"pulsarchain.keyregistry.v1.Params":{"description":"Params defines the parameters for the module.","type":"object"},"pulsarchain.keyregistry.v1.QueryGetUserCosmosAddressResponse":{"description":"QueryGetUserCosmosAddressResponse defines the QueryGetUserCosmosAddressResponse message.","type":"object","properties":{"user_cosmos_address":{"type":"string","format":"byte"}}},"pulsarchain.keyregistry.v1.QueryGetUserMinaAddressResponse":{"description":"QueryGetUserMinaAddressResponse defines the QueryGetUserMinaAddressResponse message.","type":"object","properties":{"user_mina_address":{"type":"string","format":"byte"}}},"pulsarchain.keyregistry.v1.QueryGetValidatorCosmosPubKeyResponse":{"description":"QueryGetValidatorCosmosAddressResponse defines the QueryGetValidatorCosmosAddressResponse message.","type":"object","properties":{"validator_cosmos_pub_key":{"type":"string","format":"byte"}}},"pulsarchain.keyregistry.v1.QueryGetValidatorMinaPubKeyResponse":{"description":"QueryGetValidatorMinaAddressResponse defines the QueryGetValidatorMinaAddressResponse message.","type":"object","properties":{"validator_mina_pub_key":{"type":"string","format":"byte"}}},"pulsarchain.keyregistry.v1.QueryParamsResponse":{"description":"QueryParamsResponse is response type for the Query/Params RPC method.","type":"object","properties":{"params":{"description":"params holds all the parameters of this module.","$ref":"#/definitions/pulsarchain.keyregistry.v1.Params"}}},"pulsarchain.votepersistence.v1.Params":{"description":"Params defines the parameters for the module.","type":"object"},"pulsarchain.votepersistence.v1.QueryParamsResponse":{"description":"QueryParamsResponse is response type for the Query/Params RPC method.","type":"object","properties":{"params":{"description":"params holds all the parameters of this module.","$ref":"#/definitions/pulsarchain.votepersistence.v1.Params"}}},"pulsarchain.votepersistence.v1.QueryVoteExtBodyByHeightResponse":{"description":"QueryVoteExtBodyByHeightResponse defines the QueryVoteExtBodyByHeightResponse message.","type":"object"}},"tags":[{"name":"Query"},{"name":"Msg"}]} diff --git a/proto/pulsarchain/votepersistence/v1/query.proto b/proto/pulsarchain/votepersistence/v1/query.proto index aecc4d2d..6d8ce856 100644 --- a/proto/pulsarchain/votepersistence/v1/query.proto +++ b/proto/pulsarchain/votepersistence/v1/query.proto @@ -1,4 +1,5 @@ syntax = "proto3"; + package pulsarchain.votepersistence.v1; import "amino/amino.proto"; @@ -15,6 +16,11 @@ service Query { rpc Params(QueryParamsRequest) returns (QueryParamsResponse) { option (google.api.http).get = "/node101-io/pulsar-chain/votepersistence/v1/params"; } + + // VoteExtBodyByHeight Queries a list of VoteExtBodyByHeight items. + rpc VoteExtBodyByHeight(QueryVoteExtBodyByHeightRequest) returns (QueryVoteExtBodyByHeightResponse) { + option (google.api.http).get = "/node101-io/pulsar-chain/votepersistence/v1/vote_ext_body_by_height/{block_height}"; + } } // QueryParamsRequest is request type for the Query/Params RPC method. @@ -28,3 +34,15 @@ message QueryParamsResponse { (amino.dont_omitempty) = true ]; } + +// QueryVoteExtBodyByHeightRequest defines the QueryVoteExtBodyByHeightRequest message. +message QueryVoteExtBodyByHeightRequest { + int64 block_height = 1; +} + +// QueryVoteExtBodyByHeightResponse defines the QueryVoteExtBodyByHeightResponse message. +message QueryVoteExtBodyByHeightResponse { + bytes next_validator_set_hash = 1; + bytes current_state_root = 2; + int64 current_block_height = 3; +} diff --git a/x/keyregistry/types/address_pair.pb.go b/x/keyregistry/types/address_pair.pb.go index c421d400..3f5b82ab 100644 --- a/x/keyregistry/types/address_pair.pb.go +++ b/x/keyregistry/types/address_pair.pb.go @@ -5,11 +5,10 @@ package types import ( fmt "fmt" + proto "github.com/cosmos/gogoproto/proto" io "io" math "math" math_bits "math/bits" - - proto "github.com/cosmos/gogoproto/proto" ) // Reference imports to suppress errors if they are not otherwise used. diff --git a/x/keyregistry/types/genesis.pb.go b/x/keyregistry/types/genesis.pb.go index 892df56a..38980463 100644 --- a/x/keyregistry/types/genesis.pb.go +++ b/x/keyregistry/types/genesis.pb.go @@ -5,13 +5,12 @@ package types import ( fmt "fmt" - io "io" - math "math" - math_bits "math/bits" - _ "github.com/cosmos/cosmos-sdk/types/tx/amino" _ "github.com/cosmos/gogoproto/gogoproto" proto "github.com/cosmos/gogoproto/proto" + io "io" + math "math" + math_bits "math/bits" ) // Reference imports to suppress errors if they are not otherwise used. diff --git a/x/keyregistry/types/module.pb.go b/x/keyregistry/types/module.pb.go index 6c939884..c42802f0 100644 --- a/x/keyregistry/types/module.pb.go +++ b/x/keyregistry/types/module.pb.go @@ -4,13 +4,12 @@ package types import ( + _ "cosmossdk.io/api/cosmos/app/v1alpha1" fmt "fmt" + proto "github.com/cosmos/gogoproto/proto" io "io" math "math" math_bits "math/bits" - - _ "cosmossdk.io/api/cosmos/app/v1alpha1" - proto "github.com/cosmos/gogoproto/proto" ) // Reference imports to suppress errors if they are not otherwise used. diff --git a/x/keyregistry/types/params.pb.go b/x/keyregistry/types/params.pb.go index 083d03b5..378f92bb 100644 --- a/x/keyregistry/types/params.pb.go +++ b/x/keyregistry/types/params.pb.go @@ -5,13 +5,12 @@ package types import ( fmt "fmt" - io "io" - math "math" - math_bits "math/bits" - _ "github.com/cosmos/cosmos-sdk/types/tx/amino" _ "github.com/cosmos/gogoproto/gogoproto" proto "github.com/cosmos/gogoproto/proto" + io "io" + math "math" + math_bits "math/bits" ) // Reference imports to suppress errors if they are not otherwise used. diff --git a/x/keyregistry/types/public_key_pair.pb.go b/x/keyregistry/types/public_key_pair.pb.go index 4f1401fb..db1d3fc2 100644 --- a/x/keyregistry/types/public_key_pair.pb.go +++ b/x/keyregistry/types/public_key_pair.pb.go @@ -5,11 +5,10 @@ package types import ( fmt "fmt" + proto "github.com/cosmos/gogoproto/proto" io "io" math "math" math_bits "math/bits" - - proto "github.com/cosmos/gogoproto/proto" ) // Reference imports to suppress errors if they are not otherwise used. diff --git a/x/keyregistry/types/query.pb.go b/x/keyregistry/types/query.pb.go index d45dfd2b..e529ad88 100644 --- a/x/keyregistry/types/query.pb.go +++ b/x/keyregistry/types/query.pb.go @@ -6,10 +6,6 @@ package types import ( context "context" fmt "fmt" - io "io" - math "math" - math_bits "math/bits" - _ "github.com/cosmos/cosmos-sdk/types/query" _ "github.com/cosmos/cosmos-sdk/types/tx/amino" _ "github.com/cosmos/gogoproto/gogoproto" @@ -19,6 +15,9 @@ import ( grpc "google.golang.org/grpc" codes "google.golang.org/grpc/codes" status "google.golang.org/grpc/status" + io "io" + math "math" + math_bits "math/bits" ) // Reference imports to suppress errors if they are not otherwise used. diff --git a/x/keyregistry/types/tx.pb.go b/x/keyregistry/types/tx.pb.go index d94eed74..b0b00dec 100644 --- a/x/keyregistry/types/tx.pb.go +++ b/x/keyregistry/types/tx.pb.go @@ -6,10 +6,6 @@ package types import ( context "context" fmt "fmt" - io "io" - math "math" - math_bits "math/bits" - _ "github.com/cosmos/cosmos-proto" _ "github.com/cosmos/cosmos-sdk/types/msgservice" _ "github.com/cosmos/cosmos-sdk/types/tx/amino" @@ -19,6 +15,9 @@ import ( grpc "google.golang.org/grpc" codes "google.golang.org/grpc/codes" status "google.golang.org/grpc/status" + io "io" + math "math" + math_bits "math/bits" ) // Reference imports to suppress errors if they are not otherwise used. diff --git a/x/pulsar/types/genesis.pb.go b/x/pulsar/types/genesis.pb.go index 65be9de9..acfbe019 100644 --- a/x/pulsar/types/genesis.pb.go +++ b/x/pulsar/types/genesis.pb.go @@ -5,13 +5,12 @@ package types import ( fmt "fmt" - io "io" - math "math" - math_bits "math/bits" - _ "github.com/cosmos/cosmos-sdk/types/tx/amino" _ "github.com/cosmos/gogoproto/gogoproto" proto "github.com/cosmos/gogoproto/proto" + io "io" + math "math" + math_bits "math/bits" ) // Reference imports to suppress errors if they are not otherwise used. diff --git a/x/pulsar/types/module.pb.go b/x/pulsar/types/module.pb.go index eeab9504..b7ffd5c3 100644 --- a/x/pulsar/types/module.pb.go +++ b/x/pulsar/types/module.pb.go @@ -4,13 +4,12 @@ package types import ( + _ "cosmossdk.io/api/cosmos/app/v1alpha1" fmt "fmt" + proto "github.com/cosmos/gogoproto/proto" io "io" math "math" math_bits "math/bits" - - _ "cosmossdk.io/api/cosmos/app/v1alpha1" - proto "github.com/cosmos/gogoproto/proto" ) // Reference imports to suppress errors if they are not otherwise used. diff --git a/x/pulsar/types/params.pb.go b/x/pulsar/types/params.pb.go index e7a05515..0480a17b 100644 --- a/x/pulsar/types/params.pb.go +++ b/x/pulsar/types/params.pb.go @@ -5,13 +5,12 @@ package types import ( fmt "fmt" - io "io" - math "math" - math_bits "math/bits" - _ "github.com/cosmos/cosmos-sdk/types/tx/amino" _ "github.com/cosmos/gogoproto/gogoproto" proto "github.com/cosmos/gogoproto/proto" + io "io" + math "math" + math_bits "math/bits" ) // Reference imports to suppress errors if they are not otherwise used. diff --git a/x/pulsar/types/query.pb.go b/x/pulsar/types/query.pb.go index 8df04fb5..0c09f00a 100644 --- a/x/pulsar/types/query.pb.go +++ b/x/pulsar/types/query.pb.go @@ -6,10 +6,6 @@ package types import ( context "context" fmt "fmt" - io "io" - math "math" - math_bits "math/bits" - _ "github.com/cosmos/cosmos-sdk/types/query" _ "github.com/cosmos/cosmos-sdk/types/tx/amino" _ "github.com/cosmos/gogoproto/gogoproto" @@ -19,6 +15,9 @@ import ( grpc "google.golang.org/grpc" codes "google.golang.org/grpc/codes" status "google.golang.org/grpc/status" + io "io" + math "math" + math_bits "math/bits" ) // Reference imports to suppress errors if they are not otherwise used. diff --git a/x/pulsar/types/tx.pb.go b/x/pulsar/types/tx.pb.go index 2f343e52..e3271589 100644 --- a/x/pulsar/types/tx.pb.go +++ b/x/pulsar/types/tx.pb.go @@ -6,10 +6,6 @@ package types import ( context "context" fmt "fmt" - io "io" - math "math" - math_bits "math/bits" - _ "github.com/cosmos/cosmos-proto" _ "github.com/cosmos/cosmos-sdk/types/msgservice" _ "github.com/cosmos/cosmos-sdk/types/tx/amino" @@ -19,6 +15,9 @@ import ( grpc "google.golang.org/grpc" codes "google.golang.org/grpc/codes" status "google.golang.org/grpc/status" + io "io" + math "math" + math_bits "math/bits" ) // Reference imports to suppress errors if they are not otherwise used. diff --git a/x/votepersistence/keeper/query_vote_ext_body_by_height.go b/x/votepersistence/keeper/query_vote_ext_body_by_height.go new file mode 100644 index 00000000..51cb899a --- /dev/null +++ b/x/votepersistence/keeper/query_vote_ext_body_by_height.go @@ -0,0 +1,17 @@ +package keeper + +import ( + "context" + + "github.com/node101-io/pulsar-chain/x/votepersistence/types" + "google.golang.org/grpc/codes" + "google.golang.org/grpc/status" +) + +func (q queryServer) VoteExtBodyByHeight(ctx context.Context, req *types.QueryVoteExtBodyByHeightRequest) (*types.QueryVoteExtBodyByHeightResponse, error) { + if req == nil { + return nil, status.Error(codes.InvalidArgument, "invalid request") + } + + return &types.QueryVoteExtBodyByHeightResponse{}, nil +} diff --git a/x/votepersistence/module/autocli.go b/x/votepersistence/module/autocli.go index 6fc3fdaf..41ede925 100644 --- a/x/votepersistence/module/autocli.go +++ b/x/votepersistence/module/autocli.go @@ -17,6 +17,13 @@ func (am AppModule) AutoCLIOptions() *autocliv1.ModuleOptions { Use: "params", Short: "Shows the parameters of the module", }, + { + RpcMethod: "VoteExtBodyByHeight", + Use: "vote-ext-body-by-height [block-height]", + Short: "Query vote-ext-body-by-height", + PositionalArgs: []*autocliv1.PositionalArgDescriptor{{ProtoField: "block_height"}}, + }, + // this line is used by ignite scaffolding # autocli/query }, }, diff --git a/x/votepersistence/types/genesis.pb.go b/x/votepersistence/types/genesis.pb.go index 9c48d742..e252c7ba 100644 --- a/x/votepersistence/types/genesis.pb.go +++ b/x/votepersistence/types/genesis.pb.go @@ -5,13 +5,12 @@ package types import ( fmt "fmt" - io "io" - math "math" - math_bits "math/bits" - _ "github.com/cosmos/cosmos-sdk/types/tx/amino" _ "github.com/cosmos/gogoproto/gogoproto" proto "github.com/cosmos/gogoproto/proto" + io "io" + math "math" + math_bits "math/bits" ) // Reference imports to suppress errors if they are not otherwise used. diff --git a/x/votepersistence/types/module.pb.go b/x/votepersistence/types/module.pb.go index 15faa0b1..319820ca 100644 --- a/x/votepersistence/types/module.pb.go +++ b/x/votepersistence/types/module.pb.go @@ -4,13 +4,12 @@ package types import ( + _ "cosmossdk.io/api/cosmos/app/v1alpha1" fmt "fmt" + proto "github.com/cosmos/gogoproto/proto" io "io" math "math" math_bits "math/bits" - - _ "cosmossdk.io/api/cosmos/app/v1alpha1" - proto "github.com/cosmos/gogoproto/proto" ) // Reference imports to suppress errors if they are not otherwise used. diff --git a/x/votepersistence/types/params.pb.go b/x/votepersistence/types/params.pb.go index db7a5855..3d572a3f 100644 --- a/x/votepersistence/types/params.pb.go +++ b/x/votepersistence/types/params.pb.go @@ -5,13 +5,12 @@ package types import ( fmt "fmt" - io "io" - math "math" - math_bits "math/bits" - _ "github.com/cosmos/cosmos-sdk/types/tx/amino" _ "github.com/cosmos/gogoproto/gogoproto" proto "github.com/cosmos/gogoproto/proto" + io "io" + math "math" + math_bits "math/bits" ) // Reference imports to suppress errors if they are not otherwise used. diff --git a/x/votepersistence/types/query.pb.go b/x/votepersistence/types/query.pb.go index 7f0e6273..07721a5a 100644 --- a/x/votepersistence/types/query.pb.go +++ b/x/votepersistence/types/query.pb.go @@ -6,10 +6,6 @@ package types import ( context "context" fmt "fmt" - io "io" - math "math" - math_bits "math/bits" - _ "github.com/cosmos/cosmos-sdk/types/query" _ "github.com/cosmos/cosmos-sdk/types/tx/amino" _ "github.com/cosmos/gogoproto/gogoproto" @@ -19,6 +15,9 @@ import ( grpc "google.golang.org/grpc" codes "google.golang.org/grpc/codes" status "google.golang.org/grpc/status" + io "io" + math "math" + math_bits "math/bits" ) // Reference imports to suppress errors if they are not otherwise used. @@ -115,9 +114,117 @@ func (m *QueryParamsResponse) GetParams() Params { return Params{} } +// QueryVoteExtBodyByHeightRequest defines the QueryVoteExtBodyByHeightRequest message. +type QueryVoteExtBodyByHeightRequest struct { + BlockHeight int64 `protobuf:"varint,1,opt,name=block_height,json=blockHeight,proto3" json:"block_height,omitempty"` +} + +func (m *QueryVoteExtBodyByHeightRequest) Reset() { *m = QueryVoteExtBodyByHeightRequest{} } +func (m *QueryVoteExtBodyByHeightRequest) String() string { return proto.CompactTextString(m) } +func (*QueryVoteExtBodyByHeightRequest) ProtoMessage() {} +func (*QueryVoteExtBodyByHeightRequest) Descriptor() ([]byte, []int) { + return fileDescriptor_2c9976ecef977273, []int{2} +} +func (m *QueryVoteExtBodyByHeightRequest) XXX_Unmarshal(b []byte) error { + return m.Unmarshal(b) +} +func (m *QueryVoteExtBodyByHeightRequest) XXX_Marshal(b []byte, deterministic bool) ([]byte, error) { + if deterministic { + return xxx_messageInfo_QueryVoteExtBodyByHeightRequest.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 *QueryVoteExtBodyByHeightRequest) XXX_Merge(src proto.Message) { + xxx_messageInfo_QueryVoteExtBodyByHeightRequest.Merge(m, src) +} +func (m *QueryVoteExtBodyByHeightRequest) XXX_Size() int { + return m.Size() +} +func (m *QueryVoteExtBodyByHeightRequest) XXX_DiscardUnknown() { + xxx_messageInfo_QueryVoteExtBodyByHeightRequest.DiscardUnknown(m) +} + +var xxx_messageInfo_QueryVoteExtBodyByHeightRequest proto.InternalMessageInfo + +func (m *QueryVoteExtBodyByHeightRequest) GetBlockHeight() int64 { + if m != nil { + return m.BlockHeight + } + return 0 +} + +// QueryVoteExtBodyByHeightResponse defines the QueryVoteExtBodyByHeightResponse message. +type QueryVoteExtBodyByHeightResponse struct { + NextValidatorSetHash []byte `protobuf:"bytes,1,opt,name=next_validator_set_hash,json=nextValidatorSetHash,proto3" json:"next_validator_set_hash,omitempty"` + CurrentStateRoot []byte `protobuf:"bytes,2,opt,name=current_state_root,json=currentStateRoot,proto3" json:"current_state_root,omitempty"` + CurrentBlockHeight int64 `protobuf:"varint,3,opt,name=current_block_height,json=currentBlockHeight,proto3" json:"current_block_height,omitempty"` +} + +func (m *QueryVoteExtBodyByHeightResponse) Reset() { *m = QueryVoteExtBodyByHeightResponse{} } +func (m *QueryVoteExtBodyByHeightResponse) String() string { return proto.CompactTextString(m) } +func (*QueryVoteExtBodyByHeightResponse) ProtoMessage() {} +func (*QueryVoteExtBodyByHeightResponse) Descriptor() ([]byte, []int) { + return fileDescriptor_2c9976ecef977273, []int{3} +} +func (m *QueryVoteExtBodyByHeightResponse) XXX_Unmarshal(b []byte) error { + return m.Unmarshal(b) +} +func (m *QueryVoteExtBodyByHeightResponse) XXX_Marshal(b []byte, deterministic bool) ([]byte, error) { + if deterministic { + return xxx_messageInfo_QueryVoteExtBodyByHeightResponse.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 *QueryVoteExtBodyByHeightResponse) XXX_Merge(src proto.Message) { + xxx_messageInfo_QueryVoteExtBodyByHeightResponse.Merge(m, src) +} +func (m *QueryVoteExtBodyByHeightResponse) XXX_Size() int { + return m.Size() +} +func (m *QueryVoteExtBodyByHeightResponse) XXX_DiscardUnknown() { + xxx_messageInfo_QueryVoteExtBodyByHeightResponse.DiscardUnknown(m) +} + +var xxx_messageInfo_QueryVoteExtBodyByHeightResponse proto.InternalMessageInfo + +func (m *QueryVoteExtBodyByHeightResponse) GetNextValidatorSetHash() []byte { + if m != nil { + return m.NextValidatorSetHash + } + return nil +} + +func (m *QueryVoteExtBodyByHeightResponse) GetCurrentStateRoot() []byte { + if m != nil { + return m.CurrentStateRoot + } + return nil +} + +func (m *QueryVoteExtBodyByHeightResponse) GetCurrentBlockHeight() int64 { + if m != nil { + return m.CurrentBlockHeight + } + return 0 +} + func init() { proto.RegisterType((*QueryParamsRequest)(nil), "pulsarchain.votepersistence.v1.QueryParamsRequest") proto.RegisterType((*QueryParamsResponse)(nil), "pulsarchain.votepersistence.v1.QueryParamsResponse") + proto.RegisterType((*QueryVoteExtBodyByHeightRequest)(nil), "pulsarchain.votepersistence.v1.QueryVoteExtBodyByHeightRequest") + proto.RegisterType((*QueryVoteExtBodyByHeightResponse)(nil), "pulsarchain.votepersistence.v1.QueryVoteExtBodyByHeightResponse") } func init() { @@ -125,29 +232,41 @@ func init() { } var fileDescriptor_2c9976ecef977273 = []byte{ - // 342 bytes of a gzipped FileDescriptorProto - 0x1f, 0x8b, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0xff, 0x94, 0x91, 0xb1, 0x4a, 0x3b, 0x41, - 0x10, 0xc6, 0x6f, 0xff, 0xf0, 0x0f, 0x78, 0x56, 0x9e, 0x29, 0x24, 0xc8, 0x2a, 0x29, 0x44, 0x22, - 0xb9, 0xf5, 0x2e, 0x56, 0x29, 0xd3, 0xd9, 0x69, 0xb0, 0xb2, 0x72, 0xef, 0x1c, 0x2e, 0x0b, 0xb9, - 0x9d, 0xcd, 0xed, 0xde, 0x61, 0x5a, 0x9f, 0x40, 0xf0, 0x25, 0x6c, 0x04, 0x3b, 0x5f, 0x21, 0x65, - 0xc0, 0xc6, 0x4a, 0x24, 0x11, 0x7c, 0x0d, 0xc9, 0xed, 0x15, 0x6a, 0xd0, 0x60, 0xb3, 0x0c, 0xdf, - 0x7e, 0xdf, 0x6f, 0x66, 0x76, 0xdd, 0x96, 0xca, 0x87, 0x9a, 0x67, 0xf1, 0x80, 0x0b, 0xc9, 0x0a, - 0x34, 0xa0, 0x20, 0xd3, 0x42, 0x1b, 0x90, 0x31, 0xb0, 0x22, 0x60, 0xa3, 0x1c, 0xb2, 0xb1, 0xaf, - 0x32, 0x34, 0xe8, 0xd1, 0x4f, 0x5e, 0xff, 0x9b, 0xd7, 0x2f, 0x82, 0xc6, 0x06, 0x4f, 0x85, 0x44, - 0x56, 0x9e, 0x36, 0xd2, 0xa8, 0x27, 0x98, 0x60, 0x59, 0xb2, 0x45, 0x55, 0xa9, 0xdb, 0x09, 0x62, - 0x32, 0x04, 0xc6, 0x95, 0x60, 0x5c, 0x4a, 0x34, 0xdc, 0x08, 0x94, 0xba, 0xba, 0x6d, 0xc5, 0xa8, - 0x53, 0xd4, 0x2c, 0xe2, 0x1a, 0x6c, 0x7f, 0x56, 0x04, 0x11, 0x18, 0x1e, 0x30, 0xc5, 0x13, 0x21, - 0x4b, 0x73, 0xe5, 0x3d, 0x58, 0x31, 0xbe, 0xe2, 0x19, 0x4f, 0x2b, 0x70, 0xb3, 0xee, 0x7a, 0xa7, - 0x0b, 0xdc, 0x49, 0x29, 0xf6, 0x61, 0x94, 0x83, 0x36, 0xcd, 0x0b, 0x77, 0xf3, 0x8b, 0xaa, 0x15, - 0x4a, 0x0d, 0xde, 0xb1, 0x5b, 0xb3, 0xe1, 0x2d, 0xb2, 0x4b, 0xf6, 0xd7, 0xc3, 0x3d, 0xff, 0xf7, - 0xed, 0x7d, 0x9b, 0xef, 0xad, 0x4d, 0x5e, 0x76, 0x9c, 0xbb, 0xf7, 0x87, 0x16, 0xe9, 0x57, 0x80, - 0xf0, 0x91, 0xb8, 0xff, 0xcb, 0x16, 0xde, 0x3d, 0x71, 0x6b, 0xd6, 0xe7, 0x85, 0xab, 0x78, 0xcb, - 0xa3, 0x36, 0x3a, 0x7f, 0xca, 0xd8, 0x45, 0x9a, 0xdd, 0xeb, 0xa7, 0xb7, 0xdb, 0x7f, 0x47, 0x5e, - 0xc8, 0x24, 0x5e, 0x42, 0x70, 0x18, 0xb4, 0x05, 0x32, 0xcb, 0x69, 0xaf, 0x78, 0xb7, 0xde, 0xd9, - 0x64, 0x46, 0xc9, 0x74, 0x46, 0xc9, 0xeb, 0x8c, 0x92, 0x9b, 0x39, 0x75, 0xa6, 0x73, 0xea, 0x3c, - 0xcf, 0xa9, 0x73, 0xde, 0x4d, 0x84, 0x19, 0xe4, 0x91, 0x1f, 0x63, 0xfa, 0x23, 0xf7, 0x6a, 0x89, - 0x6c, 0xc6, 0x0a, 0x74, 0x54, 0x2b, 0xbf, 0xa3, 0xf3, 0x11, 0x00, 0x00, 0xff, 0xff, 0x9b, 0x87, - 0xdc, 0x4b, 0x7c, 0x02, 0x00, 0x00, + // 529 bytes of a gzipped FileDescriptorProto + 0x1f, 0x8b, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0xff, 0x9c, 0x53, 0xc1, 0x6e, 0xd3, 0x40, + 0x10, 0x8d, 0x1b, 0x11, 0x89, 0x6d, 0x0f, 0xb0, 0x8d, 0x44, 0x15, 0x21, 0xb7, 0xe4, 0x80, 0x50, + 0xa0, 0xde, 0x3a, 0x85, 0x4b, 0x2f, 0xa0, 0x08, 0xa4, 0x72, 0x03, 0xb7, 0xea, 0xa1, 0x17, 0xb3, + 0x76, 0x56, 0xb6, 0x45, 0xb2, 0xe3, 0x7a, 0x27, 0x56, 0x2c, 0xc4, 0x85, 0x2f, 0x40, 0xe2, 0x27, + 0xb8, 0x80, 0xb8, 0xf2, 0x07, 0x3d, 0x56, 0xe2, 0xc2, 0x09, 0xa1, 0x04, 0x89, 0x1f, 0xe0, 0x03, + 0x90, 0xd7, 0x1b, 0xd1, 0x52, 0x42, 0x28, 0x97, 0xc8, 0x7a, 0xf3, 0xde, 0x9b, 0x37, 0x33, 0x1b, + 0xd2, 0x49, 0x47, 0x03, 0xc5, 0xb3, 0x30, 0xe6, 0x89, 0x64, 0x39, 0xa0, 0x48, 0x45, 0xa6, 0x12, + 0x85, 0x42, 0x86, 0x82, 0xe5, 0x2e, 0x3b, 0x1a, 0x89, 0xac, 0x70, 0xd2, 0x0c, 0x10, 0xa8, 0x7d, + 0x8a, 0xeb, 0xfc, 0xc6, 0x75, 0x72, 0xb7, 0x75, 0x95, 0x0f, 0x13, 0x09, 0x4c, 0xff, 0x56, 0x92, + 0x56, 0x27, 0x04, 0x35, 0x04, 0xc5, 0x02, 0xae, 0x44, 0xe5, 0xc5, 0x72, 0x37, 0x10, 0xc8, 0x5d, + 0x96, 0xf2, 0x28, 0x91, 0x1c, 0x13, 0x90, 0x86, 0xdb, 0x8c, 0x20, 0x02, 0xfd, 0xc9, 0xca, 0x2f, + 0x83, 0x5e, 0x8f, 0x00, 0xa2, 0x81, 0x60, 0x3c, 0x4d, 0x18, 0x97, 0x12, 0x50, 0x4b, 0x94, 0xa9, + 0xde, 0x5e, 0x10, 0x3f, 0xe5, 0x19, 0x1f, 0x1a, 0x72, 0xbb, 0x49, 0xe8, 0xd3, 0x32, 0xc2, 0x13, + 0x0d, 0x7a, 0xe2, 0x68, 0x24, 0x14, 0xb6, 0x9f, 0x91, 0xd5, 0x33, 0xa8, 0x4a, 0x41, 0x2a, 0x41, + 0x1f, 0x93, 0x46, 0x25, 0x5e, 0xb3, 0x36, 0xac, 0x5b, 0xcb, 0xdd, 0x9b, 0xce, 0xdf, 0xa7, 0x77, + 0x2a, 0x7d, 0xef, 0xf2, 0xf1, 0x97, 0xf5, 0xda, 0xdb, 0xef, 0x1f, 0x3a, 0x96, 0x67, 0x0c, 0xda, + 0x0f, 0xc9, 0xba, 0xee, 0x70, 0x00, 0x28, 0x1e, 0x8d, 0xb1, 0x07, 0xfd, 0xa2, 0x57, 0xec, 0x8a, + 0x24, 0x8a, 0xd1, 0x84, 0xa0, 0x37, 0xc8, 0x4a, 0x30, 0x80, 0xf0, 0xb9, 0x1f, 0x6b, 0x58, 0xf7, + 0xac, 0x7b, 0xcb, 0x1a, 0xab, 0x98, 0xed, 0x8f, 0x16, 0xd9, 0x98, 0x6f, 0x63, 0x52, 0xdf, 0x23, + 0xd7, 0xa4, 0x18, 0xa3, 0x9f, 0xf3, 0x41, 0xd2, 0xe7, 0x08, 0x99, 0xaf, 0x04, 0xfa, 0x31, 0x57, + 0xb1, 0xb6, 0x5c, 0xf1, 0x9a, 0x65, 0xf9, 0x60, 0x56, 0xdd, 0x13, 0xb8, 0xcb, 0x55, 0x4c, 0xef, + 0x10, 0x1a, 0x8e, 0xb2, 0x4c, 0x48, 0xf4, 0x15, 0x72, 0x14, 0x7e, 0x06, 0x80, 0x6b, 0x4b, 0x5a, + 0x71, 0xc5, 0x54, 0xf6, 0xca, 0x82, 0x07, 0x80, 0x74, 0x8b, 0x34, 0x67, 0xec, 0x33, 0xa1, 0xeb, + 0x3a, 0xf4, 0xcc, 0xa9, 0xf7, 0x2b, 0x7b, 0xf7, 0x7d, 0x9d, 0x5c, 0xd2, 0xd9, 0xe9, 0x3b, 0x8b, + 0x34, 0xaa, 0x4d, 0xd1, 0xee, 0xa2, 0x8d, 0x9e, 0x3f, 0x56, 0x6b, 0xfb, 0x42, 0x9a, 0x6a, 0x29, + 0xed, 0x9d, 0x57, 0x9f, 0xbe, 0xbd, 0x59, 0xba, 0x4b, 0xbb, 0x4c, 0x42, 0x5f, 0xb8, 0x5b, 0xee, + 0x66, 0x02, 0xac, 0xf2, 0xd9, 0x5c, 0xf0, 0x72, 0xe8, 0x0f, 0x8b, 0xac, 0xfe, 0x61, 0xe1, 0xf4, + 0xfe, 0x3f, 0x05, 0x99, 0x7f, 0xf1, 0xd6, 0x83, 0xff, 0x37, 0x30, 0x63, 0x1d, 0xea, 0xb1, 0xf6, + 0xa9, 0x77, 0x91, 0xb1, 0x4a, 0xc8, 0x2f, 0x5f, 0x48, 0x00, 0xfd, 0xc2, 0x0f, 0x0a, 0x73, 0x3b, + 0xf6, 0xe2, 0xf4, 0x25, 0x5f, 0xf6, 0xf6, 0x8f, 0x27, 0xb6, 0x75, 0x32, 0xb1, 0xad, 0xaf, 0x13, + 0xdb, 0x7a, 0x3d, 0xb5, 0x6b, 0x27, 0x53, 0xbb, 0xf6, 0x79, 0x6a, 0xd7, 0x0e, 0x77, 0xa2, 0x04, + 0xe3, 0x51, 0xe0, 0x84, 0x30, 0x9c, 0xdb, 0x77, 0x7c, 0xae, 0x33, 0x16, 0xa9, 0x50, 0x41, 0x43, + 0xff, 0x0f, 0xb7, 0x7f, 0x06, 0x00, 0x00, 0xff, 0xff, 0x7d, 0x4c, 0x67, 0xcd, 0x75, 0x04, 0x00, + 0x00, } // Reference imports to suppress errors if they are not otherwise used. @@ -164,6 +283,8 @@ const _ = grpc.SupportPackageIsVersion4 type QueryClient interface { // Parameters queries the parameters of the module. Params(ctx context.Context, in *QueryParamsRequest, opts ...grpc.CallOption) (*QueryParamsResponse, error) + // VoteExtBodyByHeight Queries a list of VoteExtBodyByHeight items. + VoteExtBodyByHeight(ctx context.Context, in *QueryVoteExtBodyByHeightRequest, opts ...grpc.CallOption) (*QueryVoteExtBodyByHeightResponse, error) } type queryClient struct { @@ -183,10 +304,21 @@ func (c *queryClient) Params(ctx context.Context, in *QueryParamsRequest, opts . return out, nil } +func (c *queryClient) VoteExtBodyByHeight(ctx context.Context, in *QueryVoteExtBodyByHeightRequest, opts ...grpc.CallOption) (*QueryVoteExtBodyByHeightResponse, error) { + out := new(QueryVoteExtBodyByHeightResponse) + err := c.cc.Invoke(ctx, "/pulsarchain.votepersistence.v1.Query/VoteExtBodyByHeight", in, out, opts...) + if err != nil { + return nil, err + } + return out, nil +} + // QueryServer is the server API for Query service. type QueryServer interface { // Parameters queries the parameters of the module. Params(context.Context, *QueryParamsRequest) (*QueryParamsResponse, error) + // VoteExtBodyByHeight Queries a list of VoteExtBodyByHeight items. + VoteExtBodyByHeight(context.Context, *QueryVoteExtBodyByHeightRequest) (*QueryVoteExtBodyByHeightResponse, error) } // UnimplementedQueryServer can be embedded to have forward compatible implementations. @@ -196,6 +328,9 @@ type UnimplementedQueryServer struct { func (*UnimplementedQueryServer) Params(ctx context.Context, req *QueryParamsRequest) (*QueryParamsResponse, error) { return nil, status.Errorf(codes.Unimplemented, "method Params not implemented") } +func (*UnimplementedQueryServer) VoteExtBodyByHeight(ctx context.Context, req *QueryVoteExtBodyByHeightRequest) (*QueryVoteExtBodyByHeightResponse, error) { + return nil, status.Errorf(codes.Unimplemented, "method VoteExtBodyByHeight not implemented") +} func RegisterQueryServer(s grpc1.Server, srv QueryServer) { s.RegisterService(&_Query_serviceDesc, srv) @@ -219,6 +354,24 @@ func _Query_Params_Handler(srv interface{}, ctx context.Context, dec func(interf return interceptor(ctx, in, info, handler) } +func _Query_VoteExtBodyByHeight_Handler(srv interface{}, ctx context.Context, dec func(interface{}) error, interceptor grpc.UnaryServerInterceptor) (interface{}, error) { + in := new(QueryVoteExtBodyByHeightRequest) + if err := dec(in); err != nil { + return nil, err + } + if interceptor == nil { + return srv.(QueryServer).VoteExtBodyByHeight(ctx, in) + } + info := &grpc.UnaryServerInfo{ + Server: srv, + FullMethod: "/pulsarchain.votepersistence.v1.Query/VoteExtBodyByHeight", + } + handler := func(ctx context.Context, req interface{}) (interface{}, error) { + return srv.(QueryServer).VoteExtBodyByHeight(ctx, req.(*QueryVoteExtBodyByHeightRequest)) + } + return interceptor(ctx, in, info, handler) +} + var Query_serviceDesc = _Query_serviceDesc var _Query_serviceDesc = grpc.ServiceDesc{ ServiceName: "pulsarchain.votepersistence.v1.Query", @@ -228,6 +381,10 @@ var _Query_serviceDesc = grpc.ServiceDesc{ MethodName: "Params", Handler: _Query_Params_Handler, }, + { + MethodName: "VoteExtBodyByHeight", + Handler: _Query_VoteExtBodyByHeight_Handler, + }, }, Streams: []grpc.StreamDesc{}, Metadata: "pulsarchain/votepersistence/v1/query.proto", @@ -289,6 +446,76 @@ func (m *QueryParamsResponse) MarshalToSizedBuffer(dAtA []byte) (int, error) { return len(dAtA) - i, nil } +func (m *QueryVoteExtBodyByHeightRequest) 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 *QueryVoteExtBodyByHeightRequest) MarshalTo(dAtA []byte) (int, error) { + size := m.Size() + return m.MarshalToSizedBuffer(dAtA[:size]) +} + +func (m *QueryVoteExtBodyByHeightRequest) MarshalToSizedBuffer(dAtA []byte) (int, error) { + i := len(dAtA) + _ = i + var l int + _ = l + if m.BlockHeight != 0 { + i = encodeVarintQuery(dAtA, i, uint64(m.BlockHeight)) + i-- + dAtA[i] = 0x8 + } + return len(dAtA) - i, nil +} + +func (m *QueryVoteExtBodyByHeightResponse) 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 *QueryVoteExtBodyByHeightResponse) MarshalTo(dAtA []byte) (int, error) { + size := m.Size() + return m.MarshalToSizedBuffer(dAtA[:size]) +} + +func (m *QueryVoteExtBodyByHeightResponse) MarshalToSizedBuffer(dAtA []byte) (int, error) { + i := len(dAtA) + _ = i + var l int + _ = l + if m.CurrentBlockHeight != 0 { + i = encodeVarintQuery(dAtA, i, uint64(m.CurrentBlockHeight)) + i-- + dAtA[i] = 0x18 + } + if len(m.CurrentStateRoot) > 0 { + i -= len(m.CurrentStateRoot) + copy(dAtA[i:], m.CurrentStateRoot) + i = encodeVarintQuery(dAtA, i, uint64(len(m.CurrentStateRoot))) + i-- + dAtA[i] = 0x12 + } + if len(m.NextValidatorSetHash) > 0 { + i -= len(m.NextValidatorSetHash) + copy(dAtA[i:], m.NextValidatorSetHash) + i = encodeVarintQuery(dAtA, i, uint64(len(m.NextValidatorSetHash))) + 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 +547,38 @@ func (m *QueryParamsResponse) Size() (n int) { return n } +func (m *QueryVoteExtBodyByHeightRequest) Size() (n int) { + if m == nil { + return 0 + } + var l int + _ = l + if m.BlockHeight != 0 { + n += 1 + sovQuery(uint64(m.BlockHeight)) + } + return n +} + +func (m *QueryVoteExtBodyByHeightResponse) Size() (n int) { + if m == nil { + return 0 + } + var l int + _ = l + l = len(m.NextValidatorSetHash) + if l > 0 { + n += 1 + l + sovQuery(uint64(l)) + } + l = len(m.CurrentStateRoot) + if l > 0 { + n += 1 + l + sovQuery(uint64(l)) + } + if m.CurrentBlockHeight != 0 { + n += 1 + sovQuery(uint64(m.CurrentBlockHeight)) + } + return n +} + func sovQuery(x uint64) (n int) { return (math_bits.Len64(x|1) + 6) / 7 } @@ -459,6 +718,212 @@ func (m *QueryParamsResponse) Unmarshal(dAtA []byte) error { } return nil } +func (m *QueryVoteExtBodyByHeightRequest) 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: QueryVoteExtBodyByHeightRequest: wiretype end group for non-group") + } + if fieldNum <= 0 { + return fmt.Errorf("proto: QueryVoteExtBodyByHeightRequest: illegal tag %d (wire type %d)", fieldNum, wire) + } + switch fieldNum { + case 1: + if wireType != 0 { + return fmt.Errorf("proto: wrong wireType = %d for field BlockHeight", wireType) + } + m.BlockHeight = 0 + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowQuery + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + m.BlockHeight |= int64(b&0x7F) << shift + if b < 0x80 { + break + } + } + 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 *QueryVoteExtBodyByHeightResponse) 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: QueryVoteExtBodyByHeightResponse: wiretype end group for non-group") + } + if fieldNum <= 0 { + return fmt.Errorf("proto: QueryVoteExtBodyByHeightResponse: illegal tag %d (wire type %d)", fieldNum, wire) + } + switch fieldNum { + case 1: + if wireType != 2 { + return fmt.Errorf("proto: wrong wireType = %d for field NextValidatorSetHash", wireType) + } + var byteLen int + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowQuery + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + byteLen |= int(b&0x7F) << shift + if b < 0x80 { + break + } + } + if byteLen < 0 { + return ErrInvalidLengthQuery + } + postIndex := iNdEx + byteLen + if postIndex < 0 { + return ErrInvalidLengthQuery + } + if postIndex > l { + return io.ErrUnexpectedEOF + } + m.NextValidatorSetHash = append(m.NextValidatorSetHash[:0], dAtA[iNdEx:postIndex]...) + if m.NextValidatorSetHash == nil { + m.NextValidatorSetHash = []byte{} + } + iNdEx = postIndex + case 2: + if wireType != 2 { + return fmt.Errorf("proto: wrong wireType = %d for field CurrentStateRoot", wireType) + } + var byteLen int + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowQuery + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + byteLen |= int(b&0x7F) << shift + if b < 0x80 { + break + } + } + if byteLen < 0 { + return ErrInvalidLengthQuery + } + postIndex := iNdEx + byteLen + if postIndex < 0 { + return ErrInvalidLengthQuery + } + if postIndex > l { + return io.ErrUnexpectedEOF + } + m.CurrentStateRoot = append(m.CurrentStateRoot[:0], dAtA[iNdEx:postIndex]...) + if m.CurrentStateRoot == nil { + m.CurrentStateRoot = []byte{} + } + iNdEx = postIndex + case 3: + if wireType != 0 { + return fmt.Errorf("proto: wrong wireType = %d for field CurrentBlockHeight", wireType) + } + m.CurrentBlockHeight = 0 + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowQuery + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + m.CurrentBlockHeight |= int64(b&0x7F) << shift + if b < 0x80 { + break + } + } + 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/votepersistence/types/query.pb.gw.go b/x/votepersistence/types/query.pb.gw.go index 699c42c3..dbc762c5 100644 --- a/x/votepersistence/types/query.pb.gw.go +++ b/x/votepersistence/types/query.pb.gw.go @@ -51,6 +51,60 @@ func local_request_Query_Params_0(ctx context.Context, marshaler runtime.Marshal } +func request_Query_VoteExtBodyByHeight_0(ctx context.Context, marshaler runtime.Marshaler, client QueryClient, req *http.Request, pathParams map[string]string) (proto.Message, runtime.ServerMetadata, error) { + var protoReq QueryVoteExtBodyByHeightRequest + var metadata runtime.ServerMetadata + + var ( + val string + ok bool + err error + _ = err + ) + + val, ok = pathParams["block_height"] + if !ok { + return nil, metadata, status.Errorf(codes.InvalidArgument, "missing parameter %s", "block_height") + } + + protoReq.BlockHeight, err = runtime.Int64(val) + + if err != nil { + return nil, metadata, status.Errorf(codes.InvalidArgument, "type mismatch, parameter: %s, error: %v", "block_height", err) + } + + msg, err := client.VoteExtBodyByHeight(ctx, &protoReq, grpc.Header(&metadata.HeaderMD), grpc.Trailer(&metadata.TrailerMD)) + return msg, metadata, err + +} + +func local_request_Query_VoteExtBodyByHeight_0(ctx context.Context, marshaler runtime.Marshaler, server QueryServer, req *http.Request, pathParams map[string]string) (proto.Message, runtime.ServerMetadata, error) { + var protoReq QueryVoteExtBodyByHeightRequest + var metadata runtime.ServerMetadata + + var ( + val string + ok bool + err error + _ = err + ) + + val, ok = pathParams["block_height"] + if !ok { + return nil, metadata, status.Errorf(codes.InvalidArgument, "missing parameter %s", "block_height") + } + + protoReq.BlockHeight, err = runtime.Int64(val) + + if err != nil { + return nil, metadata, status.Errorf(codes.InvalidArgument, "type mismatch, parameter: %s, error: %v", "block_height", err) + } + + msg, err := server.VoteExtBodyByHeight(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 +134,29 @@ func RegisterQueryHandlerServer(ctx context.Context, mux *runtime.ServeMux, serv }) + mux.Handle("GET", pattern_Query_VoteExtBodyByHeight_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_VoteExtBodyByHeight_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_VoteExtBodyByHeight_0(ctx, mux, outboundMarshaler, w, req, resp, mux.GetForwardResponseOptions()...) + + }) + return nil } @@ -141,13 +218,37 @@ func RegisterQueryHandlerClient(ctx context.Context, mux *runtime.ServeMux, clie }) + mux.Handle("GET", pattern_Query_VoteExtBodyByHeight_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_VoteExtBodyByHeight_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_VoteExtBodyByHeight_0(ctx, mux, outboundMarshaler, w, req, resp, mux.GetForwardResponseOptions()...) + + }) + return nil } var ( pattern_Query_Params_0 = runtime.MustPattern(runtime.NewPattern(1, []int{2, 0, 2, 1, 2, 2, 2, 3, 2, 4}, []string{"node101-io", "pulsar-chain", "votepersistence", "v1", "params"}, "", runtime.AssumeColonVerbOpt(false))) + + pattern_Query_VoteExtBodyByHeight_0 = runtime.MustPattern(runtime.NewPattern(1, []int{2, 0, 2, 1, 2, 2, 2, 3, 2, 4, 1, 0, 4, 1, 5, 5}, []string{"node101-io", "pulsar-chain", "votepersistence", "v1", "vote_ext_body_by_height", "block_height"}, "", runtime.AssumeColonVerbOpt(false))) ) var ( forward_Query_Params_0 = runtime.ForwardResponseMessage + + forward_Query_VoteExtBodyByHeight_0 = runtime.ForwardResponseMessage ) diff --git a/x/votepersistence/types/tx.pb.go b/x/votepersistence/types/tx.pb.go index c72264a0..31772b17 100644 --- a/x/votepersistence/types/tx.pb.go +++ b/x/votepersistence/types/tx.pb.go @@ -6,10 +6,6 @@ package types import ( context "context" fmt "fmt" - io "io" - math "math" - math_bits "math/bits" - _ "github.com/cosmos/cosmos-proto" _ "github.com/cosmos/cosmos-sdk/types/msgservice" _ "github.com/cosmos/cosmos-sdk/types/tx/amino" @@ -19,6 +15,9 @@ import ( grpc "google.golang.org/grpc" codes "google.golang.org/grpc/codes" status "google.golang.org/grpc/status" + io "io" + math "math" + math_bits "math/bits" ) // Reference imports to suppress errors if they are not otherwise used. From dc06113c10765f56c8d328645bbcda897a55f6c6 Mon Sep 17 00:00:00 2001 From: Yusuf Date: Wed, 29 Apr 2026 21:46:50 +0300 Subject: [PATCH 40/62] fix: define errors in vote persistence module to use in abci handler --- abci/helpers.go | 5 +++-- x/votepersistence/types/errors.go | 4 +++- 2 files changed, 6 insertions(+), 3 deletions(-) diff --git a/abci/helpers.go b/abci/helpers.go index 47a190c0..57d61233 100644 --- a/abci/helpers.go +++ b/abci/helpers.go @@ -17,6 +17,7 @@ import ( "github.com/node101-io/mina-signer-go/poseidon" keyregistrykeeper "github.com/node101-io/pulsar-chain/x/keyregistry/keeper" votepersistence "github.com/node101-io/pulsar-chain/x/votepersistence/keeper" + "github.com/node101-io/pulsar-chain/x/votepersistence/types" ) type SecondaryKey struct { @@ -47,7 +48,7 @@ func (h *AbciHandler) verifyVoteExtension(ctx context.Context, txs [][]byte, bod voteExtensionTx := txs[0] if !strings.Contains(string(txs[0]), VoteExtMarker) { - return fmt.Errorf("") + return types.ErrVoteExtMarkerNotFound } voteExtensionTx = voteExtensionTx[len([]byte(VoteExtMarker)):] @@ -80,7 +81,7 @@ func (h *AbciHandler) verifyVoteExtension(ctx context.Context, txs [][]byte, bod } if !MockSignatureVerify(vote, body, minaKey, ActionsReducedRoot) { - return fmt.Errorf("") + return types.ErrInvalidVoteExtension.Wrap("invalid signature") } } diff --git a/x/votepersistence/types/errors.go b/x/votepersistence/types/errors.go index c489914c..f8af82ba 100644 --- a/x/votepersistence/types/errors.go +++ b/x/votepersistence/types/errors.go @@ -8,5 +8,7 @@ import ( // x/votepersistence module sentinel errors var ( - ErrInvalidSigner = errors.Register(ModuleName, 1100, "expected gov account as only signer for proposal message") + ErrInvalidSigner = errors.Register(ModuleName, 1100, "expected gov account as only signer for proposal message") + ErrVoteExtMarkerNotFound = errors.Register(ModuleName, 1101, "vote extension marker not found") + ErrInvalidVoteExtension = errors.Register(ModuleName, 1102, "invalid vote extension") ) From 749789a728c4219b2e4509d72f33f06bcb7cb930 Mon Sep 17 00:00:00 2001 From: Yusuf Date: Thu, 30 Apr 2026 21:12:09 +0300 Subject: [PATCH 41/62] fix: use get validator by cons add instead of get validator, and fix the mina key unmarshalling problem --- abci/helpers.go | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/abci/helpers.go b/abci/helpers.go index 57d61233..c1899838 100644 --- a/abci/helpers.go +++ b/abci/helpers.go @@ -126,7 +126,7 @@ func (h *AbciHandler) calculateValidatorSetRoot(ctx sdk.Context, valInfo []valid for _, validator := range valInfo { input = []*big.Int{} - cosmosValidatorInfo, err := h.stakingKeeper.Validator(ctx, validator.ConsensusAddr) + cosmosValidatorInfo, err := h.stakingKeeper.GetValidatorByConsAddr(ctx, validator.ConsensusAddr) if err != nil { return nil, err } @@ -149,7 +149,8 @@ func (h *AbciHandler) calculateValidatorSetRoot(ctx sdk.Context, valInfo []valid return nil, err } - MinaPublicKey, err := keys.PublicKey{}.FromAddress(string(minaPubKey)) + var MinaPublicKey keys.PublicKey + err = MinaPublicKey.Unmarshal(minaPubKey) if err != nil { return nil, err } @@ -251,7 +252,8 @@ func (h *AbciHandler) constructVoteExtBody(ctx sdk.Context, blockHeight int64) ( } func (h *AbciHandler) getValidatorPublicKey(ctx sdk.Context, validatorAddr []byte) ([]byte, error) { - cosmosValidatorInfo, err := h.stakingKeeper.Validator(ctx, validatorAddr) + + cosmosValidatorInfo, err := h.stakingKeeper.GetValidatorByConsAddr(ctx, validatorAddr) if err != nil { return nil, err } From a450e4cd663cf48bae8f1e7ecb64118961befdd1 Mon Sep 17 00:00:00 2001 From: Yusuf Date: Thu, 30 Apr 2026 21:33:07 +0300 Subject: [PATCH 42/62] fix: seperate vote ext body construct functions --- abci/helpers.go | 70 +++++++++++++++++++++++++++++++++++++--- abci/pre_blocker.go | 2 +- abci/process_proposal.go | 2 +- 3 files changed, 68 insertions(+), 6 deletions(-) diff --git a/abci/helpers.go b/abci/helpers.go index c1899838..cab16eb4 100644 --- a/abci/helpers.go +++ b/abci/helpers.go @@ -11,6 +11,7 @@ import ( abci "github.com/cometbft/cometbft/abci/types" sdk "github.com/cosmos/cosmos-sdk/types" stakingkeeper "github.com/cosmos/cosmos-sdk/x/staking/keeper" + stakingTypes "github.com/cosmos/cosmos-sdk/x/staking/types" "github.com/node101-io/mina-signer-go/constants" "github.com/node101-io/mina-signer-go/field" "github.com/node101-io/mina-signer-go/keys" @@ -89,7 +90,8 @@ func (h *AbciHandler) verifyVoteExtension(ctx context.Context, txs [][]byte, bod return nil } -func (h *AbciHandler) getValidatorSet(ctx sdk.Context, currentBlockHeight int64) ([]validatorInfo, error) { +// Use if you need the validator set of block < N where N is the current block number. +func (h *AbciHandler) getHistoricalValidatorSet(ctx sdk.Context, currentBlockHeight int64) ([]validatorInfo, error) { historicalData, err := h.stakingKeeper.GetHistoricalInfo(ctx, currentBlockHeight) if err != nil { @@ -117,6 +119,37 @@ func (h *AbciHandler) getValidatorSet(ctx sdk.Context, currentBlockHeight int64) return valInfo, nil } +// Use if you need the validator set of the current block +func (h *AbciHandler) getCurrentValidatorSet(ctx sdk.Context) ([]validatorInfo, error) { + + var valInfo []validatorInfo + var iterErr error + + err := h.stakingKeeper.IterateLastValidators(ctx, func(index int64, validator stakingTypes.ValidatorI) (stop bool) { + consAddr, err := validator.GetConsAddr() + if err != nil { + iterErr = err + return true + } + + valInfo = append(valInfo, validatorInfo{ + ConsensusAddr: consAddr, + Power: validator.GetConsensusPower(sdk.DefaultPowerReduction), + }) + + return false + }) + + if err != nil { + return nil, err + } + if iterErr != nil { + return nil, iterErr + } + + return valInfo, nil +} + // TODO: Move this helper to mina-signer-go func (h *AbciHandler) calculateValidatorSetRoot(ctx sdk.Context, valInfo []validatorInfo, poseidonHash *poseidon.Poseidon) (*big.Int, error) { @@ -181,7 +214,7 @@ func (h *AbciHandler) checkStakePower(ctx sdk.Context, blockHeight int64, txs [] valInfoMap := make(map[string]validatorInfo) - currentValidatorSet, err := h.getValidatorSet(ctx, blockHeight-2) + currentValidatorSet, err := h.getHistoricalValidatorSet(ctx, blockHeight-2) if err != nil { return false, err } @@ -224,7 +257,36 @@ func (h *AbciHandler) checkStakePower(ctx sdk.Context, blockHeight int64, txs [] func (h *AbciHandler) constructVoteExtBody(ctx sdk.Context, blockHeight int64) (VoteExtensionBody, error) { - nextValidatorSet, err := h.getValidatorSet(ctx, blockHeight) + nextValidatorSet, err := h.getCurrentValidatorSet(ctx) + if err != nil { + return VoteExtensionBody{}, err + } + + currentBlockInfo, err := h.stakingKeeper.GetHistoricalInfo(ctx, blockHeight-1) + if err != nil { + return VoteExtensionBody{}, err + } + + poseidonHash := poseidon.CreatePoseidon(*field.Fp, constants.PoseidonParamsKimchiFp) + + nextValidatorSetHash, err := h.calculateValidatorSetRoot(ctx, nextValidatorSet, poseidonHash) + if err != nil { + return VoteExtensionBody{}, err + } + if nextValidatorSetHash == nil { + return VoteExtensionBody{}, err + } + + return VoteExtensionBody{ + NextValidatorSetHash: nextValidatorSetHash.Bytes(), + CurrentStateRoot: currentBlockInfo.Header.AppHash, + CurrentBlockHeight: blockHeight - 1, + }, nil +} + +func (h *AbciHandler) reconstructVoteExtBody(ctx sdk.Context, blockHeight int64) (VoteExtensionBody, error) { + + nextValidatorSet, err := h.getHistoricalValidatorSet(ctx, blockHeight) if err != nil { return VoteExtensionBody{}, err } @@ -269,7 +331,7 @@ func (h *AbciHandler) constructPayload(ctx sdk.Context, blockHeight int64, voteE voteExtsForGivenBlock := make(map[string][]byte) currentValidatorSetMap := make(map[string]bool) - currentValidatorSet, err := h.getValidatorSet(ctx, blockHeight-2) + currentValidatorSet, err := h.getHistoricalValidatorSet(ctx, blockHeight-2) if err != nil { return payload{}, err } diff --git a/abci/pre_blocker.go b/abci/pre_blocker.go index 31f31a88..a00365c5 100644 --- a/abci/pre_blocker.go +++ b/abci/pre_blocker.go @@ -33,7 +33,7 @@ func (h *AbciHandler) PreBlocker() sdk.PreBlocker { return nil, err } - currentValidatorSet, err := h.getValidatorSet(ctx, req.GetHeight()-2) + currentValidatorSet, err := h.getHistoricalValidatorSet(ctx, req.GetHeight()-2) if err != nil { return nil, err } diff --git a/abci/process_proposal.go b/abci/process_proposal.go index c3184ea6..6d239e07 100644 --- a/abci/process_proposal.go +++ b/abci/process_proposal.go @@ -16,7 +16,7 @@ func (h *AbciHandler) ProcessProposalHandler() sdk.ProcessProposalHandler { return &abci.ResponseProcessProposal{Status: abci.ResponseProcessProposal_ACCEPT}, nil } - body, err := h.constructVoteExtBody(ctx, req.GetHeight()-1) + body, err := h.reconstructVoteExtBody(ctx, req.GetHeight()-1) if err != nil { return &abci.ResponseProcessProposal{Status: abci.ResponseProcessProposal_REJECT}, err } From 0a8d6f356bac1bdf969444a4862323fa0a0223c9 Mon Sep 17 00:00:00 2001 From: Yusuf Date: Thu, 30 Apr 2026 22:29:14 +0300 Subject: [PATCH 43/62] feat: implement vote extension body query --- x/votepersistence/keeper/keeper.go | 20 ++-- x/votepersistence/keeper/keeper_test.go | 2 + .../keeper/query_vote_ext_body_by_height.go | 105 +++++++++++++++++- x/votepersistence/module/depinject.go | 10 +- x/votepersistence/types/expected_keepers.go | 10 ++ 5 files changed, 137 insertions(+), 10 deletions(-) diff --git a/x/votepersistence/keeper/keeper.go b/x/votepersistence/keeper/keeper.go index 1b43d965..83ac0d67 100644 --- a/x/votepersistence/keeper/keeper.go +++ b/x/votepersistence/keeper/keeper.go @@ -15,9 +15,11 @@ import ( const VoteStorageMapName string = "vote_storage" type Keeper struct { - storeService corestore.KVStoreService - cdc codec.Codec - addressCodec address.Codec + storeService corestore.KVStoreService + cdc codec.Codec + addressCodec address.Codec + stakingKeeper types.StakingKeeper + keyregistryKeeper types.KeyregistryKeeper // Address capable of executing a MsgUpdateParams message. // Typically, this should be the x/gov module account. authority []byte @@ -32,6 +34,8 @@ func NewKeeper( storeService corestore.KVStoreService, cdc codec.Codec, addressCodec address.Codec, + stakingKeeper types.StakingKeeper, + keyregistryKeeper types.KeyregistryKeeper, authority []byte, ) Keeper { @@ -42,10 +46,12 @@ func NewKeeper( sb := collections.NewSchemaBuilder(storeService) k := Keeper{ - storeService: storeService, - cdc: cdc, - addressCodec: addressCodec, - authority: authority, + storeService: storeService, + cdc: cdc, + addressCodec: addressCodec, + stakingKeeper: stakingKeeper, + keyregistryKeeper: keyregistryKeeper, + authority: authority, Params: collections.NewItem(sb, types.ParamsKey, "params", codec.CollValue[types.Params](cdc)), diff --git a/x/votepersistence/keeper/keeper_test.go b/x/votepersistence/keeper/keeper_test.go index 250ed52c..d892a036 100644 --- a/x/votepersistence/keeper/keeper_test.go +++ b/x/votepersistence/keeper/keeper_test.go @@ -40,6 +40,8 @@ func initFixture(t *testing.T) *fixture { storeService, encCfg.Codec, addressCodec, + nil, + nil, authority, ) diff --git a/x/votepersistence/keeper/query_vote_ext_body_by_height.go b/x/votepersistence/keeper/query_vote_ext_body_by_height.go index 51cb899a..5bfcf446 100644 --- a/x/votepersistence/keeper/query_vote_ext_body_by_height.go +++ b/x/votepersistence/keeper/query_vote_ext_body_by_height.go @@ -2,7 +2,16 @@ package keeper import ( "context" + "errors" + "fmt" + "math/big" + sdk "github.com/cosmos/cosmos-sdk/types" + stakingtypes "github.com/cosmos/cosmos-sdk/x/staking/types" + "github.com/node101-io/mina-signer-go/constants" + "github.com/node101-io/mina-signer-go/field" + "github.com/node101-io/mina-signer-go/keys" + "github.com/node101-io/mina-signer-go/poseidon" "github.com/node101-io/pulsar-chain/x/votepersistence/types" "google.golang.org/grpc/codes" "google.golang.org/grpc/status" @@ -13,5 +22,99 @@ func (q queryServer) VoteExtBodyByHeight(ctx context.Context, req *types.QueryVo return nil, status.Error(codes.InvalidArgument, "invalid request") } - return &types.QueryVoteExtBodyByHeightResponse{}, nil + if req.BlockHeight < 4 { + return nil, status.Error(codes.InvalidArgument, "there is no vote extension in blocks smaller than 4") + } + + sdkCtx := sdk.UnwrapSDKContext(ctx) + + if req.BlockHeight == sdkCtx.BlockHeight() { + return nil, status.Error(codes.InvalidArgument, "no vote extensions in this block yet") + } + + if q.k.stakingKeeper == nil || q.k.keyregistryKeeper == nil { + return nil, status.Error(codes.Internal, "vote extension query dependencies are not configured") + } + + return q.constructVoteExtBodyByHeight(ctx, req.BlockHeight) +} + +func (q queryServer) constructVoteExtBodyByHeight(ctx context.Context, blockHeight int64) (*types.QueryVoteExtBodyByHeightResponse, error) { + currentBlockInfo, err := q.k.stakingKeeper.GetHistoricalInfo(ctx, blockHeight-2) + if err != nil { + return nil, wrapHistoricalInfoError(blockHeight, err) + } + + nextBlockInfo, err := q.k.stakingKeeper.GetHistoricalInfo(ctx, blockHeight-1) + if err != nil { + return nil, wrapHistoricalInfoError(blockHeight+1, err) + } + + nextValidatorSetHash, err := q.calculateValidatorSetRoot(ctx, nextBlockInfo.Valset) + if err != nil { + return nil, err + } + + return &types.QueryVoteExtBodyByHeightResponse{ + NextValidatorSetHash: nextValidatorSetHash, + CurrentStateRoot: currentBlockInfo.Header.AppHash, + CurrentBlockHeight: blockHeight - 1, + }, nil +} + +func (q queryServer) calculateValidatorSetRoot(ctx context.Context, validatorSet []stakingtypes.Validator) ([]byte, error) { + + poseidonHash := poseidon.CreatePoseidon(*field.Fp, constants.PoseidonParamsKimchiFp) + merkleRoot := poseidonHash.Hash([]*big.Int{big.NewInt(0)}) + + for _, validator := range validatorSet { + cosmosValidatorPubKey, err := validator.ConsPubKey() + if err != nil { + return nil, status.Error(codes.Internal, "failed to read validator consensus public key") + } + + exists, err := q.k.keyregistryKeeper.ValidatorCosmosToMinaHas(ctx, cosmosValidatorPubKey.Bytes()) + if err != nil { + return nil, status.Error(codes.Internal, "failed to check validator Mina key") + } + if !exists { + return nil, status.Errorf(codes.NotFound, "validator Mina key not found for consensus public key %X", cosmosValidatorPubKey.Bytes()) + } + + minaPubKey, err := q.k.keyregistryKeeper.ValidatorGetCosmosToMina(ctx, cosmosValidatorPubKey.Bytes()) + if err != nil { + return nil, status.Error(codes.Internal, "failed to load validator Mina key") + } + + var minaPublicKey keys.PublicKey + err = minaPublicKey.Unmarshal(minaPubKey) + if err != nil { + return nil, status.Error(codes.Internal, "failed to decode validator Mina public key") + } + + input := []*big.Int{minaPublicKey.X} + if minaPublicKey.IsOdd { + input = append(input, big.NewInt(1)) + } else { + input = append(input, big.NewInt(0)) + } + input = append(input, big.NewInt(validator.ConsensusPower(sdk.DefaultPowerReduction))) + + hashOfValidator := poseidonHash.Hash(input) + merkleRoot = poseidonHash.Hash([]*big.Int{merkleRoot, hashOfValidator}) + } + + if merkleRoot == nil { + return nil, status.Error(codes.Internal, "failed to calculate next validator set hash") + } + + return merkleRoot.Bytes(), nil +} + +func wrapHistoricalInfoError(height int64, err error) error { + if errors.Is(err, stakingtypes.ErrNoHistoricalInfo) { + return status.Errorf(codes.NotFound, "historical info not found for height %d", height) + } + + return status.Error(codes.Internal, fmt.Sprintf("failed to load staking historical info for height %d", height)) } diff --git a/x/votepersistence/module/depinject.go b/x/votepersistence/module/depinject.go index 5a393590..4d6c1c43 100644 --- a/x/votepersistence/module/depinject.go +++ b/x/votepersistence/module/depinject.go @@ -8,6 +8,8 @@ import ( "cosmossdk.io/depinject/appconfig" "github.com/cosmos/cosmos-sdk/codec" authtypes "github.com/cosmos/cosmos-sdk/x/auth/types" + stakingkeeper "github.com/cosmos/cosmos-sdk/x/staking/keeper" + keyregistrykeeper "github.com/node101-io/pulsar-chain/x/keyregistry/keeper" "github.com/node101-io/pulsar-chain/x/votepersistence/keeper" "github.com/node101-io/pulsar-chain/x/votepersistence/types" @@ -33,8 +35,10 @@ type ModuleInputs struct { Cdc codec.Codec AddressCodec address.Codec - AuthKeeper types.AuthKeeper - BankKeeper types.BankKeeper + AuthKeeper types.AuthKeeper + BankKeeper types.BankKeeper + StakingKeeper *stakingkeeper.Keeper + KeyregistryKeeper keyregistrykeeper.Keeper } type ModuleOutputs struct { @@ -54,6 +58,8 @@ func ProvideModule(in ModuleInputs) ModuleOutputs { in.StoreService, in.Cdc, in.AddressCodec, + in.StakingKeeper, + in.KeyregistryKeeper, authority, ) m := NewAppModule(in.Cdc, k, in.AuthKeeper, in.BankKeeper) diff --git a/x/votepersistence/types/expected_keepers.go b/x/votepersistence/types/expected_keepers.go index b175461c..2d71efd9 100644 --- a/x/votepersistence/types/expected_keepers.go +++ b/x/votepersistence/types/expected_keepers.go @@ -5,6 +5,7 @@ import ( "cosmossdk.io/core/address" sdk "github.com/cosmos/cosmos-sdk/types" + stakingtypes "github.com/cosmos/cosmos-sdk/x/staking/types" ) // AuthKeeper defines the expected interface for the Auth module. @@ -20,6 +21,15 @@ type BankKeeper interface { // Methods imported from bank should be defined here } +type StakingKeeper interface { + GetHistoricalInfo(context.Context, int64) (stakingtypes.HistoricalInfo, error) +} + +type KeyregistryKeeper interface { + ValidatorCosmosToMinaHas(context.Context, []byte) (bool, error) + ValidatorGetCosmosToMina(context.Context, []byte) ([]byte, error) +} + // ParamSubspace defines the expected Subspace interface for parameters. type ParamSubspace interface { Get(context.Context, []byte, interface{}) From f2a1cbc268f1a6011283f77cdf07e54c581b4e23 Mon Sep 17 00:00:00 2001 From: Yusuf Date: Thu, 30 Apr 2026 22:37:57 +0300 Subject: [PATCH 44/62] feat: implement a script to run the chain for vote extension to work as expected --- scripts/derive_mina_pub.go | 31 ++++++ scripts/setup_local_testnet.sh | 115 ++++++++++++++++++++++ scripts/setup_local_testnet_helper.py | 132 ++++++++++++++++++++++++++ 3 files changed, 278 insertions(+) create mode 100644 scripts/derive_mina_pub.go create mode 100755 scripts/setup_local_testnet.sh create mode 100644 scripts/setup_local_testnet_helper.py diff --git a/scripts/derive_mina_pub.go b/scripts/derive_mina_pub.go new file mode 100644 index 00000000..a7da84ca --- /dev/null +++ b/scripts/derive_mina_pub.go @@ -0,0 +1,31 @@ +package main + +import ( + "encoding/base64" + "fmt" + "math/big" + "os" + + "github.com/node101-io/mina-signer-go/keys" +) + +func main() { + if len(os.Args) != 2 { + panic("usage: derive_mina_pub.go ") + } + + privB64 := os.Args[1] + keyBytes, err := base64.StdEncoding.DecodeString(privB64) + if err != nil { + panic(err) + } + + priv := keys.PrivateKey{Value: new(big.Int).SetBytes(keyBytes)} + pub := priv.ToPublicKey() + bz, err := pub.Marshal() + if err != nil { + panic(err) + } + + fmt.Print(base64.StdEncoding.EncodeToString(bz)) +} diff --git a/scripts/setup_local_testnet.sh b/scripts/setup_local_testnet.sh new file mode 100755 index 00000000..6873e6e3 --- /dev/null +++ b/scripts/setup_local_testnet.sh @@ -0,0 +1,115 @@ +#!/usr/bin/env bash + +set -euo pipefail + +SCRIPT_DIR="$(cd -- "$(dirname -- "${BASH_SOURCE[0]}")" && pwd)" +REPO_ROOT="$(cd -- "$SCRIPT_DIR/.." && pwd)" +PYTHON_HELPER="$SCRIPT_DIR/setup_local_testnet_helper.py" +GO_HELPER="$SCRIPT_DIR/derive_mina_pub.go" + +CHAIN_HOME="${CHAIN_HOME:-$HOME/.pulsar-chain}" +CHAIN_ID="${CHAIN_ID:-mytestnet}" +MONIKER="${MONIKER:-mynode}" +KEY_NAME="${KEY_NAME:-alice}" +KEYRING_BACKEND="${KEYRING_BACKEND:-test}" +DENOM="${DENOM:-pmina}" +GENESIS_BALANCE="${GENESIS_BALANCE:-1000000000}" +BOND_AMOUNT="${BOND_AMOUNT:-100000000}" +MIN_GAS_PRICE="${MIN_GAS_PRICE:-0.0001pmina}" +VOTE_EXT_ENABLE_HEIGHT="${VOTE_EXT_ENABLE_HEIGHT:-1}" +CONFIG_YML_PATH="${CONFIG_YML_PATH:-$REPO_ROOT/config.yml}" +TMP_BUILD_DIR="$(mktemp -d "${TMPDIR:-/tmp}/pulsar-localnet.XXXXXX")" +BINARY_PATH="$TMP_BUILD_DIR/pulsar-chaind" + +cleanup() { + rm -rf "$TMP_BUILD_DIR" +} + +trap cleanup EXIT + +require_cmd() { + if ! command -v "$1" >/dev/null 2>&1; then + echo "missing required command: $1" >&2 + exit 1 + fi +} + +get_mina_priv_key() { + if [[ -n "${MINA_PRIV_KEY:-}" ]]; then + printf '%s\n' "$MINA_PRIV_KEY" + return + fi + + python3 "$PYTHON_HELPER" read-mina-priv-key --config "$CONFIG_YML_PATH" +} + +derive_mina_pub_key() { + go run "$GO_HELPER" "$1" +} + +require_cmd go +require_cmd python3 + +MINA_PRIV_KEY="$(get_mina_priv_key)" +MINA_PUB_KEY="$(derive_mina_pub_key "$MINA_PRIV_KEY")" + +GENESIS_FILE="$CHAIN_HOME/config/genesis.json" +APP_FILE="$CHAIN_HOME/config/app.toml" + +echo "==> Cleaning previous homes..." +rm -rf "$CHAIN_HOME" "$HOME/.pulsar-node1" "$HOME/.pulsar-node2" + +echo "==> Building temporary binary..." +( + cd "$REPO_ROOT" + go build -o "$BINARY_PATH" ./cmd/pulsard +) + +echo "==> Initializing chain home..." +"$BINARY_PATH" init "$MONIKER" --chain-id "$CHAIN_ID" --home "$CHAIN_HOME" >/dev/null + +echo "==> Setting vote extension enable height..." +python3 "$PYTHON_HELPER" set-vote-extension-height \ + --genesis "$GENESIS_FILE" \ + --height "$VOTE_EXT_ENABLE_HEIGHT" + +echo "==> Creating validator key..." +"$BINARY_PATH" keys add "$KEY_NAME" --home "$CHAIN_HOME" --keyring-backend "$KEYRING_BACKEND" >/dev/null + +VALIDATOR_ADDR="$("$BINARY_PATH" keys show "$KEY_NAME" --address --home "$CHAIN_HOME" --keyring-backend "$KEYRING_BACKEND")" + +echo "==> Adding genesis account for $KEY_NAME..." +"$BINARY_PATH" genesis add-genesis-account "$VALIDATOR_ADDR" "${GENESIS_BALANCE}${DENOM}" --home "$CHAIN_HOME" >/dev/null + +echo "==> Creating gentx..." +"$BINARY_PATH" genesis gentx "$KEY_NAME" "${BOND_AMOUNT}${DENOM}" \ + --chain-id "$CHAIN_ID" \ + --home "$CHAIN_HOME" \ + --keyring-backend "$KEYRING_BACKEND" >/dev/null + +echo "==> Collecting gentxs..." +"$BINARY_PATH" genesis collect-gentxs --home "$CHAIN_HOME" >/dev/null + +echo "==> Patching keyregistry validator key pair from genesis validator pubkey..." +COSMOS_PUB_KEY="$(python3 "$PYTHON_HELPER" patch-keyregistry \ + --genesis "$GENESIS_FILE" \ + --mina-pub-key "$MINA_PUB_KEY")" + +echo "==> Writing vote extension private key to app.toml..." +python3 "$PYTHON_HELPER" update-app-config \ + --app "$APP_FILE" \ + --min-gas-price "$MIN_GAS_PRICE" \ + --mina-priv-key "$MINA_PRIV_KEY" + +echo "==> Validating final genesis..." +"$BINARY_PATH" genesis validate-genesis --home "$CHAIN_HOME" >/dev/null + +echo "" +echo "Setup complete." +echo " home: $CHAIN_HOME" +echo " validator: $KEY_NAME" +echo " cosmos_key: $COSMOS_PUB_KEY" +echo " mina_key: $MINA_PUB_KEY" +echo "" +echo "==> Starting chain..." +"$BINARY_PATH" start --home "$CHAIN_HOME" diff --git a/scripts/setup_local_testnet_helper.py b/scripts/setup_local_testnet_helper.py new file mode 100644 index 00000000..b86818fc --- /dev/null +++ b/scripts/setup_local_testnet_helper.py @@ -0,0 +1,132 @@ +#!/usr/bin/env python3 + +import argparse +import json +import re +import sys +from pathlib import Path + + +def read_text(path_str: str) -> str: + return Path(path_str).read_text(encoding="utf-8") + + +def write_text(path_str: str, content: str) -> None: + Path(path_str).write_text(content, encoding="utf-8") + + +def read_json(path_str: str): + return json.loads(read_text(path_str)) + + +def write_json(path_str: str, payload) -> None: + write_text(path_str, json.dumps(payload, indent=2) + "\n") + + +def read_mina_priv_key(config_path: str) -> int: + content = read_text(config_path) + match = re.search(r'vote_extension:\s*\n\s*priv_key:\s*"([^"]+)"', content) + if not match: + raise SystemExit( + f"could not find validators[].app.vote_extension.priv_key in {config_path}" + ) + + print(match.group(1)) + return 0 + + +def set_vote_extension_height(genesis_path: str, height: str) -> int: + genesis = read_json(genesis_path) + genesis["consensus"]["params"]["abci"]["vote_extensions_enable_height"] = height + write_json(genesis_path, genesis) + return 0 + + +def patch_keyregistry(genesis_path: str, mina_pub_key: str) -> int: + genesis = read_json(genesis_path) + + cosmos_pub_key = ( + genesis["app_state"]["genutil"]["gen_txs"][0]["body"]["messages"][0]["pubkey"]["key"] + ) + + keyregistry = genesis["app_state"].setdefault("keyregistry", {}) + keyregistry["params"] = keyregistry.get("params", {}) + keyregistry["user_key_pairs"] = [] + keyregistry["validator_key_pairs"] = [ + { + "cosmos_key": cosmos_pub_key, + "mina_key": mina_pub_key, + } + ] + + write_json(genesis_path, genesis) + print(cosmos_pub_key) + return 0 + + +def update_app_config(app_path: str, min_gas_price: str, mina_priv_key: str) -> int: + app_toml = read_text(app_path) + app_toml = app_toml.replace( + 'minimum-gas-prices = ""', + f'minimum-gas-prices = "{min_gas_price}"', + 1, + ) + + vote_extension_block = f'[vote_extension]\npriv_key = "{mina_priv_key}"\n' + + if "\n[vote_extension]\n" in app_toml: + start = app_toml.index("\n[vote_extension]\n") + 1 + end = app_toml.find("\n[", start + 1) + if end == -1: + app_toml = app_toml[:start] + vote_extension_block + else: + app_toml = app_toml[:start] + vote_extension_block + app_toml[end + 1 :] + else: + app_toml = app_toml.rstrip() + f"\n\n{vote_extension_block}" + + write_text(app_path, app_toml) + return 0 + + +def build_parser() -> argparse.ArgumentParser: + parser = argparse.ArgumentParser(description="Helpers for local testnet setup.") + subparsers = parser.add_subparsers(dest="command", required=True) + + read_key = subparsers.add_parser("read-mina-priv-key") + read_key.add_argument("--config", required=True) + + set_height = subparsers.add_parser("set-vote-extension-height") + set_height.add_argument("--genesis", required=True) + set_height.add_argument("--height", required=True) + + patch_registry = subparsers.add_parser("patch-keyregistry") + patch_registry.add_argument("--genesis", required=True) + patch_registry.add_argument("--mina-pub-key", required=True) + + update_app = subparsers.add_parser("update-app-config") + update_app.add_argument("--app", required=True) + update_app.add_argument("--min-gas-price", required=True) + update_app.add_argument("--mina-priv-key", required=True) + + return parser + + +def main() -> int: + parser = build_parser() + args = parser.parse_args() + + if args.command == "read-mina-priv-key": + return read_mina_priv_key(args.config) + if args.command == "set-vote-extension-height": + return set_vote_extension_height(args.genesis, args.height) + if args.command == "patch-keyregistry": + return patch_keyregistry(args.genesis, args.mina_pub_key) + if args.command == "update-app-config": + return update_app_config(args.app, args.min_gas_price, args.mina_priv_key) + + parser.print_help(sys.stderr) + return 1 + + +if __name__ == "__main__": + raise SystemExit(main()) From 4e34a4f9774469b3bb20c688c090979a22de8eeb Mon Sep 17 00:00:00 2001 From: Yusuf Date: Thu, 30 Apr 2026 22:39:34 +0300 Subject: [PATCH 45/62] fix: prevent query requests for blocks bigger than the current block --- x/votepersistence/keeper/query_vote_ext_body_by_height.go | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/x/votepersistence/keeper/query_vote_ext_body_by_height.go b/x/votepersistence/keeper/query_vote_ext_body_by_height.go index 5bfcf446..2c599011 100644 --- a/x/votepersistence/keeper/query_vote_ext_body_by_height.go +++ b/x/votepersistence/keeper/query_vote_ext_body_by_height.go @@ -28,8 +28,8 @@ func (q queryServer) VoteExtBodyByHeight(ctx context.Context, req *types.QueryVo sdkCtx := sdk.UnwrapSDKContext(ctx) - if req.BlockHeight == sdkCtx.BlockHeight() { - return nil, status.Error(codes.InvalidArgument, "no vote extensions in this block yet") + if req.BlockHeight >= sdkCtx.BlockHeight() { + return nil, status.Error(codes.InvalidArgument, "no vote extensions in the requested block yet") } if q.k.stakingKeeper == nil || q.k.keyregistryKeeper == nil { From 44574a39b365d6ae3db3c0b27f9bc8175a0c9a4f Mon Sep 17 00:00:00 2001 From: Yusuf Date: Fri, 1 May 2026 16:14:50 +0300 Subject: [PATCH 46/62] chore: add a helper to extract payload and simplify function signatures accordingly --- abci/helpers.go | 31 ++++++++++++------------------- abci/pre_blocker.go | 9 +-------- abci/process_proposal.go | 9 +++++++-- 3 files changed, 20 insertions(+), 29 deletions(-) diff --git a/abci/helpers.go b/abci/helpers.go index cab16eb4..faf792d7 100644 --- a/abci/helpers.go +++ b/abci/helpers.go @@ -44,24 +44,28 @@ func MockSignatureVerify(signature []byte, message VoteExtensionBody, minaKey [] return true } -func (h *AbciHandler) verifyVoteExtension(ctx context.Context, txs [][]byte, body VoteExtensionBody) error { +func extractPayload(txs [][]byte) (payload, error) { voteExtensionTx := txs[0] if !strings.Contains(string(txs[0]), VoteExtMarker) { - return types.ErrVoteExtMarkerNotFound + return payload{}, types.ErrVoteExtMarkerNotFound } voteExtensionTx = voteExtensionTx[len([]byte(VoteExtMarker)):] - var payload payload + var pl payload - err := json.Unmarshal(voteExtensionTx, &payload) + err := json.Unmarshal(voteExtensionTx, &pl) if err != nil { - return err + return payload{}, err } + return pl, nil +} + +func (h *AbciHandler) verifyVoteExtension(ctx context.Context, pl payload, body VoteExtensionBody) error { - for publicKey, vote := range payload.Votes { + for publicKey, vote := range pl.Votes { pk, err := hex.DecodeString(publicKey) if err != nil { @@ -208,7 +212,7 @@ func (h *AbciHandler) calculateValidatorSetRoot(ctx sdk.Context, valInfo []valid } -func (h *AbciHandler) checkStakePower(ctx sdk.Context, blockHeight int64, txs [][]byte) (bool, error) { +func (h *AbciHandler) checkStakePower(ctx sdk.Context, blockHeight int64, pl payload) (bool, error) { var signedStakePower int64 var currentValidatorStakePower int64 @@ -231,18 +235,7 @@ func (h *AbciHandler) checkStakePower(ctx sdk.Context, blockHeight int64, txs [] currentValidatorStakePower += val.Power } - voteExtensionTx := txs[0] - - voteExtensionTx = voteExtensionTx[len([]byte(VoteExtMarker)):] - - var payload payload - - err = json.Unmarshal(voteExtensionTx, &payload) - if err != nil { - return false, err - } - - for addr := range payload.Votes { + for addr := range pl.Votes { validatorInfo, ok := valInfoMap[addr] if ok { signedStakePower += validatorInfo.Power diff --git a/abci/pre_blocker.go b/abci/pre_blocker.go index a00365c5..0bc8264c 100644 --- a/abci/pre_blocker.go +++ b/abci/pre_blocker.go @@ -2,7 +2,6 @@ package vote_ext import ( "encoding/hex" - "encoding/json" "fmt" abci "github.com/cometbft/cometbft/abci/types" @@ -22,13 +21,7 @@ func (h *AbciHandler) PreBlocker() sdk.PreBlocker { return nil, err } - voteExtensionTx := req.Txs[0] - - voteExtensionTx = voteExtensionTx[len([]byte(VoteExtMarker)):] - - var pl payload - - err = json.Unmarshal(voteExtensionTx, &pl) + pl, err := extractPayload(req.Txs) if err != nil { return nil, err } diff --git a/abci/process_proposal.go b/abci/process_proposal.go index 6d239e07..a46b1f5f 100644 --- a/abci/process_proposal.go +++ b/abci/process_proposal.go @@ -21,12 +21,17 @@ func (h *AbciHandler) ProcessProposalHandler() sdk.ProcessProposalHandler { return &abci.ResponseProcessProposal{Status: abci.ResponseProcessProposal_REJECT}, err } - err = h.verifyVoteExtension(ctx, req.Txs, body) + pl, err := extractPayload(req.Txs) if err != nil { return &abci.ResponseProcessProposal{Status: abci.ResponseProcessProposal_REJECT}, err } - isEnoughStakePower, err := h.checkStakePower(ctx, req.GetHeight(), req.Txs) + err = h.verifyVoteExtension(ctx, pl, body) + if err != nil { + return &abci.ResponseProcessProposal{Status: abci.ResponseProcessProposal_REJECT}, err + } + + isEnoughStakePower, err := h.checkStakePower(ctx, req.GetHeight(), pl) if err != nil { return &abci.ResponseProcessProposal{Status: abci.ResponseProcessProposal_REJECT}, err } From a11fd9eea04f7dbea92d979f8415958313ac01ab Mon Sep 17 00:00:00 2001 From: Yusuf Date: Fri, 1 May 2026 16:23:55 +0300 Subject: [PATCH 47/62] chore: rename newvoteextensionhandler to newabcihandler and move it to handler.go --- abci/extend_vote.go | 10 ---------- abci/handler.go | 30 ++++++++++++++++++++++++++++++ abci/helpers.go | 18 ------------------ app/app.go | 2 +- 4 files changed, 31 insertions(+), 29 deletions(-) create mode 100644 abci/handler.go diff --git a/abci/extend_vote.go b/abci/extend_vote.go index 2cf27b64..d7dba24d 100644 --- a/abci/extend_vote.go +++ b/abci/extend_vote.go @@ -3,9 +3,6 @@ package vote_ext import ( abci "github.com/cometbft/cometbft/abci/types" sdk "github.com/cosmos/cosmos-sdk/types" - stakingkeeper "github.com/cosmos/cosmos-sdk/x/staking/keeper" - keyregistrykeeper "github.com/node101-io/pulsar-chain/x/keyregistry/keeper" - votepersistence "github.com/node101-io/pulsar-chain/x/votepersistence/keeper" ) const ActionsReducedRoot string = "pulsar" @@ -21,13 +18,6 @@ type VoteExtensionBody struct { CurrentBlockHeight int64 } -type AbciHandler struct { - secondaryKey SecondaryKey - stakingKeeper stakingkeeper.Keeper - keyregistryKeeper keyregistrykeeper.Keeper - votePersistenceKeeper votepersistence.Keeper -} - func (h *AbciHandler) ExtendVoteHandler() sdk.ExtendVoteHandler { return func(ctx sdk.Context, req *abci.RequestExtendVote) (*abci.ResponseExtendVote, error) { diff --git a/abci/handler.go b/abci/handler.go new file mode 100644 index 00000000..4ce74ec8 --- /dev/null +++ b/abci/handler.go @@ -0,0 +1,30 @@ +package vote_ext + +import ( + stakingkeeper "github.com/cosmos/cosmos-sdk/x/staking/keeper" + "github.com/node101-io/mina-signer-go/keys" + keyregistrykeeper "github.com/node101-io/pulsar-chain/x/keyregistry/keeper" + votepersistence "github.com/node101-io/pulsar-chain/x/votepersistence/keeper" +) + +type SecondaryKey struct { + SecretKey *keys.PrivateKey + PublicKey *keys.PublicKey +} + +type AbciHandler struct { + secondaryKey SecondaryKey + stakingKeeper stakingkeeper.Keeper + keyregistryKeeper keyregistrykeeper.Keeper + votePersistenceKeeper votepersistence.Keeper +} + +func NewABCIHandler(secondaryKey SecondaryKey, stakingKeeper stakingkeeper.Keeper, + keyregistryKeeper keyregistrykeeper.Keeper, votepersistenceKeeper votepersistence.Keeper) *AbciHandler { + return &AbciHandler{ + secondaryKey: secondaryKey, + stakingKeeper: stakingKeeper, + keyregistryKeeper: keyregistryKeeper, + votePersistenceKeeper: votepersistenceKeeper, + } +} diff --git a/abci/helpers.go b/abci/helpers.go index faf792d7..f160d9af 100644 --- a/abci/helpers.go +++ b/abci/helpers.go @@ -10,32 +10,14 @@ import ( abci "github.com/cometbft/cometbft/abci/types" sdk "github.com/cosmos/cosmos-sdk/types" - stakingkeeper "github.com/cosmos/cosmos-sdk/x/staking/keeper" stakingTypes "github.com/cosmos/cosmos-sdk/x/staking/types" "github.com/node101-io/mina-signer-go/constants" "github.com/node101-io/mina-signer-go/field" "github.com/node101-io/mina-signer-go/keys" "github.com/node101-io/mina-signer-go/poseidon" - keyregistrykeeper "github.com/node101-io/pulsar-chain/x/keyregistry/keeper" - votepersistence "github.com/node101-io/pulsar-chain/x/votepersistence/keeper" "github.com/node101-io/pulsar-chain/x/votepersistence/types" ) -type SecondaryKey struct { - SecretKey *keys.PrivateKey - PublicKey *keys.PublicKey -} - -func NewVoteExtHandler(secondaryKey SecondaryKey, stakingKeeper stakingkeeper.Keeper, - keyregistryKeeper keyregistrykeeper.Keeper, votepersistenceKeeper votepersistence.Keeper) *AbciHandler { - return &AbciHandler{ - secondaryKey: secondaryKey, - stakingKeeper: stakingKeeper, - keyregistryKeeper: keyregistryKeeper, - votePersistenceKeeper: votepersistenceKeeper, - } -} - func MockSign(voteExtBody VoteExtensionBody) []byte { return []byte{} } diff --git a/app/app.go b/app/app.go index acc1ab20..122cbc6f 100644 --- a/app/app.go +++ b/app/app.go @@ -221,7 +221,7 @@ func New( PublicKey: &public, } - app.AbciHandler = vote_ext.NewVoteExtHandler( + app.AbciHandler = vote_ext.NewABCIHandler( secondaryKey, *app.StakingKeeper, app.KeyregistryKeeper, From ca6ea489bdf5989c0d0003c2ad1c8eacfd6d5a68 Mon Sep 17 00:00:00 2001 From: Yusuf Date: Fri, 1 May 2026 16:25:51 +0300 Subject: [PATCH 48/62] chore: add actions reduced root field to vote extension body --- abci/extend_vote.go | 1 + abci/helpers.go | 2 ++ 2 files changed, 3 insertions(+) diff --git a/abci/extend_vote.go b/abci/extend_vote.go index d7dba24d..c917422c 100644 --- a/abci/extend_vote.go +++ b/abci/extend_vote.go @@ -16,6 +16,7 @@ type VoteExtensionBody struct { NextValidatorSetHash []byte CurrentStateRoot []byte CurrentBlockHeight int64 + ActionsReducedRoot string } func (h *AbciHandler) ExtendVoteHandler() sdk.ExtendVoteHandler { diff --git a/abci/helpers.go b/abci/helpers.go index f160d9af..a92ff159 100644 --- a/abci/helpers.go +++ b/abci/helpers.go @@ -256,6 +256,7 @@ func (h *AbciHandler) constructVoteExtBody(ctx sdk.Context, blockHeight int64) ( NextValidatorSetHash: nextValidatorSetHash.Bytes(), CurrentStateRoot: currentBlockInfo.Header.AppHash, CurrentBlockHeight: blockHeight - 1, + ActionsReducedRoot: ActionsReducedRoot, }, nil } @@ -285,6 +286,7 @@ func (h *AbciHandler) reconstructVoteExtBody(ctx sdk.Context, blockHeight int64) NextValidatorSetHash: nextValidatorSetHash.Bytes(), CurrentStateRoot: currentBlockInfo.Header.AppHash, CurrentBlockHeight: blockHeight - 1, + ActionsReducedRoot: ActionsReducedRoot, }, nil } From 0313134f9fd77cebe1b08967018ea5b57d361c8f Mon Sep 17 00:00:00 2001 From: Yusuf Date: Fri, 1 May 2026 16:35:01 +0300 Subject: [PATCH 49/62] chore: create types folder and move constants and payload struct to there --- abci/helpers.go | 22 +++++++++++----------- abci/prepare_proposal.go | 7 ------- abci/types.go | 10 ++++++++++ 3 files changed, 21 insertions(+), 18 deletions(-) create mode 100644 abci/types.go diff --git a/abci/helpers.go b/abci/helpers.go index a92ff159..de3a9362 100644 --- a/abci/helpers.go +++ b/abci/helpers.go @@ -26,26 +26,26 @@ func MockSignatureVerify(signature []byte, message VoteExtensionBody, minaKey [] return true } -func extractPayload(txs [][]byte) (payload, error) { +func extractPayload(txs [][]byte) (Payload, error) { voteExtensionTx := txs[0] if !strings.Contains(string(txs[0]), VoteExtMarker) { - return payload{}, types.ErrVoteExtMarkerNotFound + return Payload{}, types.ErrVoteExtMarkerNotFound } voteExtensionTx = voteExtensionTx[len([]byte(VoteExtMarker)):] - var pl payload + var pl Payload err := json.Unmarshal(voteExtensionTx, &pl) if err != nil { - return payload{}, err + return Payload{}, err } return pl, nil } -func (h *AbciHandler) verifyVoteExtension(ctx context.Context, pl payload, body VoteExtensionBody) error { +func (h *AbciHandler) verifyVoteExtension(ctx context.Context, pl Payload, body VoteExtensionBody) error { for publicKey, vote := range pl.Votes { @@ -194,7 +194,7 @@ func (h *AbciHandler) calculateValidatorSetRoot(ctx sdk.Context, valInfo []valid } -func (h *AbciHandler) checkStakePower(ctx sdk.Context, blockHeight int64, pl payload) (bool, error) { +func (h *AbciHandler) checkStakePower(ctx sdk.Context, blockHeight int64, pl Payload) (bool, error) { var signedStakePower int64 var currentValidatorStakePower int64 @@ -304,13 +304,13 @@ func (h *AbciHandler) getValidatorPublicKey(ctx sdk.Context, validatorAddr []byt return cosmosValidatorPubKey.Bytes(), nil } -func (h *AbciHandler) constructPayload(ctx sdk.Context, blockHeight int64, voteExtensions []abci.ExtendedVoteInfo) (payload, error) { +func (h *AbciHandler) constructPayload(ctx sdk.Context, blockHeight int64, voteExtensions []abci.ExtendedVoteInfo) (Payload, error) { voteExtsForGivenBlock := make(map[string][]byte) currentValidatorSetMap := make(map[string]bool) currentValidatorSet, err := h.getHistoricalValidatorSet(ctx, blockHeight-2) if err != nil { - return payload{}, err + return Payload{}, err } for _, currentValidator := range currentValidatorSet { @@ -325,15 +325,15 @@ func (h *AbciHandler) constructPayload(ctx sdk.Context, blockHeight int64, voteE cosmosValidatorPubKey, err := h.getValidatorPublicKey(ctx, vote.Validator.Address) if err != nil { - return payload{}, err + return Payload{}, err } voteExtsForGivenBlock[hex.EncodeToString(cosmosValidatorPubKey)] = voteExtensions[i].VoteExtension } if len(voteExtsForGivenBlock) == 0 { - return payload{}, nil + return Payload{}, nil } - return payload{Height: blockHeight - 1, Votes: voteExtsForGivenBlock}, nil + return Payload{Height: blockHeight - 1, Votes: voteExtsForGivenBlock}, nil } diff --git a/abci/prepare_proposal.go b/abci/prepare_proposal.go index aa6f85ee..5a6a83b8 100644 --- a/abci/prepare_proposal.go +++ b/abci/prepare_proposal.go @@ -7,13 +7,6 @@ import ( sdk "github.com/cosmos/cosmos-sdk/types" ) -var VoteExtMarker string = "VOTEEXT:" - -type payload struct { - Height int64 `json:"height"` - Votes map[string][]byte `json:"votes"` -} - func (h *AbciHandler) PrepareProposalHandler() sdk.PrepareProposalHandler { return func(ctx sdk.Context, req *abci.RequestPrepareProposal) (*abci.ResponsePrepareProposal, error) { diff --git a/abci/types.go b/abci/types.go new file mode 100644 index 00000000..2db9b0ac --- /dev/null +++ b/abci/types.go @@ -0,0 +1,10 @@ +package vote_ext + +const ActionsReducedRoot string = "pulsar" + +var VoteExtMarker string = "VOTEEXT:" + +type Payload struct { + Height int64 `json:"height"` + Votes map[string][]byte `json:"votes"` +} From 00b758773452f3e90a7df6bf2c9209720d431ba2 Mon Sep 17 00:00:00 2001 From: Yusuf Date: Fri, 1 May 2026 17:14:57 +0300 Subject: [PATCH 50/62] chore: unify construct and reconstruct vote ext body functions, and remove reconstruct vote ext body helper --- abci/extend_vote.go | 2 - abci/helpers.go | 100 +++++++++++++-------------------------- abci/pre_blocker.go | 2 +- abci/process_proposal.go | 2 +- 4 files changed, 35 insertions(+), 71 deletions(-) diff --git a/abci/extend_vote.go b/abci/extend_vote.go index c917422c..045d153d 100644 --- a/abci/extend_vote.go +++ b/abci/extend_vote.go @@ -5,8 +5,6 @@ import ( sdk "github.com/cosmos/cosmos-sdk/types" ) -const ActionsReducedRoot string = "pulsar" - type validatorInfo struct { ConsensusAddr []byte Power int64 diff --git a/abci/helpers.go b/abci/helpers.go index de3a9362..a024479d 100644 --- a/abci/helpers.go +++ b/abci/helpers.go @@ -77,7 +77,36 @@ func (h *AbciHandler) verifyVoteExtension(ctx context.Context, pl Payload, body } // Use if you need the validator set of block < N where N is the current block number. -func (h *AbciHandler) getHistoricalValidatorSet(ctx sdk.Context, currentBlockHeight int64) ([]validatorInfo, error) { +func (h *AbciHandler) getValidatorSet(ctx sdk.Context, currentBlockHeight int64) ([]validatorInfo, error) { + + var valInfo []validatorInfo + var iterErr error + + if ctx.BlockHeight() == currentBlockHeight { + err := h.stakingKeeper.IterateLastValidators(ctx, func(index int64, validator stakingTypes.ValidatorI) (stop bool) { + consAddr, err := validator.GetConsAddr() + if err != nil { + iterErr = err + return true + } + + valInfo = append(valInfo, validatorInfo{ + ConsensusAddr: consAddr, + Power: validator.GetConsensusPower(sdk.DefaultPowerReduction), + }) + + return false + }) + + if err != nil { + return nil, err + } + if iterErr != nil { + return nil, iterErr + } + + return valInfo, nil + } historicalData, err := h.stakingKeeper.GetHistoricalInfo(ctx, currentBlockHeight) if err != nil { @@ -86,8 +115,6 @@ func (h *AbciHandler) getHistoricalValidatorSet(ctx sdk.Context, currentBlockHei validatorSet := historicalData.Valset - var valInfo []validatorInfo - for _, validator := range validatorSet { consAddr, err := validator.GetConsAddr() @@ -105,37 +132,6 @@ func (h *AbciHandler) getHistoricalValidatorSet(ctx sdk.Context, currentBlockHei return valInfo, nil } -// Use if you need the validator set of the current block -func (h *AbciHandler) getCurrentValidatorSet(ctx sdk.Context) ([]validatorInfo, error) { - - var valInfo []validatorInfo - var iterErr error - - err := h.stakingKeeper.IterateLastValidators(ctx, func(index int64, validator stakingTypes.ValidatorI) (stop bool) { - consAddr, err := validator.GetConsAddr() - if err != nil { - iterErr = err - return true - } - - valInfo = append(valInfo, validatorInfo{ - ConsensusAddr: consAddr, - Power: validator.GetConsensusPower(sdk.DefaultPowerReduction), - }) - - return false - }) - - if err != nil { - return nil, err - } - if iterErr != nil { - return nil, iterErr - } - - return valInfo, nil -} - // TODO: Move this helper to mina-signer-go func (h *AbciHandler) calculateValidatorSetRoot(ctx sdk.Context, valInfo []validatorInfo, poseidonHash *poseidon.Poseidon) (*big.Int, error) { @@ -200,7 +196,7 @@ func (h *AbciHandler) checkStakePower(ctx sdk.Context, blockHeight int64, pl Pay valInfoMap := make(map[string]validatorInfo) - currentValidatorSet, err := h.getHistoricalValidatorSet(ctx, blockHeight-2) + currentValidatorSet, err := h.getValidatorSet(ctx, blockHeight-2) if err != nil { return false, err } @@ -232,37 +228,7 @@ func (h *AbciHandler) checkStakePower(ctx sdk.Context, blockHeight int64, pl Pay func (h *AbciHandler) constructVoteExtBody(ctx sdk.Context, blockHeight int64) (VoteExtensionBody, error) { - nextValidatorSet, err := h.getCurrentValidatorSet(ctx) - if err != nil { - return VoteExtensionBody{}, err - } - - currentBlockInfo, err := h.stakingKeeper.GetHistoricalInfo(ctx, blockHeight-1) - if err != nil { - return VoteExtensionBody{}, err - } - - poseidonHash := poseidon.CreatePoseidon(*field.Fp, constants.PoseidonParamsKimchiFp) - - nextValidatorSetHash, err := h.calculateValidatorSetRoot(ctx, nextValidatorSet, poseidonHash) - if err != nil { - return VoteExtensionBody{}, err - } - if nextValidatorSetHash == nil { - return VoteExtensionBody{}, err - } - - return VoteExtensionBody{ - NextValidatorSetHash: nextValidatorSetHash.Bytes(), - CurrentStateRoot: currentBlockInfo.Header.AppHash, - CurrentBlockHeight: blockHeight - 1, - ActionsReducedRoot: ActionsReducedRoot, - }, nil -} - -func (h *AbciHandler) reconstructVoteExtBody(ctx sdk.Context, blockHeight int64) (VoteExtensionBody, error) { - - nextValidatorSet, err := h.getHistoricalValidatorSet(ctx, blockHeight) + nextValidatorSet, err := h.getValidatorSet(ctx, blockHeight) if err != nil { return VoteExtensionBody{}, err } @@ -308,7 +274,7 @@ func (h *AbciHandler) constructPayload(ctx sdk.Context, blockHeight int64, voteE voteExtsForGivenBlock := make(map[string][]byte) currentValidatorSetMap := make(map[string]bool) - currentValidatorSet, err := h.getHistoricalValidatorSet(ctx, blockHeight-2) + currentValidatorSet, err := h.getValidatorSet(ctx, blockHeight-2) if err != nil { return Payload{}, err } diff --git a/abci/pre_blocker.go b/abci/pre_blocker.go index 0bc8264c..c9deab13 100644 --- a/abci/pre_blocker.go +++ b/abci/pre_blocker.go @@ -26,7 +26,7 @@ func (h *AbciHandler) PreBlocker() sdk.PreBlocker { return nil, err } - currentValidatorSet, err := h.getHistoricalValidatorSet(ctx, req.GetHeight()-2) + currentValidatorSet, err := h.getValidatorSet(ctx, req.GetHeight()-2) if err != nil { return nil, err } diff --git a/abci/process_proposal.go b/abci/process_proposal.go index a46b1f5f..9f459434 100644 --- a/abci/process_proposal.go +++ b/abci/process_proposal.go @@ -16,7 +16,7 @@ func (h *AbciHandler) ProcessProposalHandler() sdk.ProcessProposalHandler { return &abci.ResponseProcessProposal{Status: abci.ResponseProcessProposal_ACCEPT}, nil } - body, err := h.reconstructVoteExtBody(ctx, req.GetHeight()-1) + body, err := h.constructVoteExtBody(ctx, req.GetHeight()-1) if err != nil { return &abci.ResponseProcessProposal{Status: abci.ResponseProcessProposal_REJECT}, err } From f0e94e88795e23add2cc5c0cd67647018ab45e72 Mon Sep 17 00:00:00 2001 From: Yusuf Date: Fri, 1 May 2026 17:20:49 +0300 Subject: [PATCH 51/62] fix: handle empty block error --- abci/helpers.go | 4 ++++ abci/types.go | 4 ++++ 2 files changed, 8 insertions(+) diff --git a/abci/helpers.go b/abci/helpers.go index a024479d..38972196 100644 --- a/abci/helpers.go +++ b/abci/helpers.go @@ -28,6 +28,10 @@ func MockSignatureVerify(signature []byte, message VoteExtensionBody, minaKey [] func extractPayload(txs [][]byte) (Payload, error) { + if len(txs) == 0 { + return Payload{}, ErrEmptyBlock + } + voteExtensionTx := txs[0] if !strings.Contains(string(txs[0]), VoteExtMarker) { diff --git a/abci/types.go b/abci/types.go index 2db9b0ac..1a76b191 100644 --- a/abci/types.go +++ b/abci/types.go @@ -1,9 +1,13 @@ package vote_ext +import "errors" + const ActionsReducedRoot string = "pulsar" var VoteExtMarker string = "VOTEEXT:" +var ErrEmptyBlock error = errors.New("this block has no transaction") + type Payload struct { Height int64 `json:"height"` Votes map[string][]byte `json:"votes"` From 3c29e68f31db38015fec498d253fcb81f9c20b12 Mon Sep 17 00:00:00 2001 From: Yusuf Date: Fri, 1 May 2026 17:32:15 +0300 Subject: [PATCH 52/62] fix: use vote storage map's clear method instead of remove --- abci/pre_blocker.go | 2 +- x/votepersistence/keeper/keeper.go | 22 ++----------------- x/votepersistence/keeper/vote_storage_test.go | 2 +- 3 files changed, 4 insertions(+), 22 deletions(-) diff --git a/abci/pre_blocker.go b/abci/pre_blocker.go index c9deab13..363f9eff 100644 --- a/abci/pre_blocker.go +++ b/abci/pre_blocker.go @@ -16,7 +16,7 @@ func (h *AbciHandler) PreBlocker() sdk.PreBlocker { return &sdk.ResponsePreBlock{}, nil } - err := h.votePersistenceKeeper.RemoveVotes(ctx) + err := h.votePersistenceKeeper.Clear(ctx) if err != nil { return nil, err } diff --git a/x/votepersistence/keeper/keeper.go b/x/votepersistence/keeper/keeper.go index 83ac0d67..3cf7666b 100644 --- a/x/votepersistence/keeper/keeper.go +++ b/x/votepersistence/keeper/keeper.go @@ -86,26 +86,8 @@ func (k Keeper) RemoveVote(ctx context.Context, blockHeight int64, minaAddress [ return k.voteStorage.Remove(ctx, collections.Join(blockHeight, minaAddress)) } -func (k Keeper) RemoveVotes(ctx context.Context) error { - - iterator, err := k.voteStorage.Iterate(ctx, nil) - if err != nil { - return err - } - defer iterator.Close() - - for iterator.Valid() { - key, err := iterator.Key() - if err != nil { - return err - } - err = k.voteStorage.Remove(ctx, key) - if err != nil { - return err - } - iterator.Next() - } - return nil +func (k Keeper) Clear(ctx context.Context) error { + return k.voteStorage.Clear(ctx, nil) } func (k Keeper) VoteExists(ctx context.Context, blockHeight int64, minaAddress []byte) (bool, error) { diff --git a/x/votepersistence/keeper/vote_storage_test.go b/x/votepersistence/keeper/vote_storage_test.go index f3e9c2f2..84e2f8ff 100644 --- a/x/votepersistence/keeper/vote_storage_test.go +++ b/x/votepersistence/keeper/vote_storage_test.go @@ -83,7 +83,7 @@ func TestVoteStorageRemoveVotes(t *testing.T) { require.NoError(t, err) } - err := f.keeper.RemoveVotes(f.ctx) + err := f.keeper.Clear(f.ctx) require.NoError(t, err) for _, entry := range entries { From 8023085b3304e8dc1517f96a40139460adfcd71d Mon Sep 17 00:00:00 2001 From: Yusuf Date: Fri, 1 May 2026 17:43:44 +0300 Subject: [PATCH 53/62] chore: remove validatorInfo struct and use cosmos sdk's validator struct --- abci/extend_vote.go | 5 ---- abci/helpers.go | 70 +++++++++++++++++++-------------------------- abci/pre_blocker.go | 8 +++++- 3 files changed, 36 insertions(+), 47 deletions(-) diff --git a/abci/extend_vote.go b/abci/extend_vote.go index 045d153d..7dec9fa3 100644 --- a/abci/extend_vote.go +++ b/abci/extend_vote.go @@ -5,11 +5,6 @@ import ( sdk "github.com/cosmos/cosmos-sdk/types" ) -type validatorInfo struct { - ConsensusAddr []byte - Power int64 -} - type VoteExtensionBody struct { NextValidatorSetHash []byte CurrentStateRoot []byte diff --git a/abci/helpers.go b/abci/helpers.go index 38972196..75e3d0e0 100644 --- a/abci/helpers.go +++ b/abci/helpers.go @@ -81,33 +81,19 @@ func (h *AbciHandler) verifyVoteExtension(ctx context.Context, pl Payload, body } // Use if you need the validator set of block < N where N is the current block number. -func (h *AbciHandler) getValidatorSet(ctx sdk.Context, currentBlockHeight int64) ([]validatorInfo, error) { +func (h *AbciHandler) getValidatorSet(ctx sdk.Context, currentBlockHeight int64) ([]stakingTypes.ValidatorI, error) { - var valInfo []validatorInfo - var iterErr error + var valInfo []stakingTypes.ValidatorI if ctx.BlockHeight() == currentBlockHeight { err := h.stakingKeeper.IterateLastValidators(ctx, func(index int64, validator stakingTypes.ValidatorI) (stop bool) { - consAddr, err := validator.GetConsAddr() - if err != nil { - iterErr = err - return true - } - - valInfo = append(valInfo, validatorInfo{ - ConsensusAddr: consAddr, - Power: validator.GetConsensusPower(sdk.DefaultPowerReduction), - }) - + valInfo = append(valInfo, validator) return false }) if err != nil { return nil, err } - if iterErr != nil { - return nil, iterErr - } return valInfo, nil } @@ -116,28 +102,14 @@ func (h *AbciHandler) getValidatorSet(ctx sdk.Context, currentBlockHeight int64) if err != nil { return nil, err } - - validatorSet := historicalData.Valset - - for _, validator := range validatorSet { - - consAddr, err := validator.GetConsAddr() - if err != nil { - return nil, err - } - - consPower := validator.ConsensusPower(sdk.DefaultPowerReduction) - - valInfo = append(valInfo, validatorInfo{ - ConsensusAddr: consAddr, - Power: consPower, - }) + for _, validator := range historicalData.Valset { + valInfo = append(valInfo, validator) } return valInfo, nil } // TODO: Move this helper to mina-signer-go -func (h *AbciHandler) calculateValidatorSetRoot(ctx sdk.Context, valInfo []validatorInfo, poseidonHash *poseidon.Poseidon) (*big.Int, error) { +func (h *AbciHandler) calculateValidatorSetRoot(ctx sdk.Context, valInfo []stakingTypes.ValidatorI, poseidonHash *poseidon.Poseidon) (*big.Int, error) { input := []*big.Int{big.NewInt(0)} merkleRoot := poseidonHash.Hash(input) @@ -145,7 +117,12 @@ func (h *AbciHandler) calculateValidatorSetRoot(ctx sdk.Context, valInfo []valid for _, validator := range valInfo { input = []*big.Int{} - cosmosValidatorInfo, err := h.stakingKeeper.GetValidatorByConsAddr(ctx, validator.ConsensusAddr) + consAddr, err := validator.GetConsAddr() + if err != nil { + continue + } + + cosmosValidatorInfo, err := h.stakingKeeper.GetValidatorByConsAddr(ctx, consAddr) if err != nil { return nil, err } @@ -180,7 +157,7 @@ func (h *AbciHandler) calculateValidatorSetRoot(ctx sdk.Context, valInfo []valid } else { input = append(input, big.NewInt(0)) } - power := new(big.Int).SetInt64(validator.Power) + power := new(big.Int).SetInt64(validator.GetConsensusPower(sdk.DefaultPowerReduction)) input = append(input, power) hashOfAddr := poseidonHash.Hash(input) @@ -198,7 +175,7 @@ func (h *AbciHandler) checkStakePower(ctx sdk.Context, blockHeight int64, pl Pay var signedStakePower int64 var currentValidatorStakePower int64 - valInfoMap := make(map[string]validatorInfo) + valInfoMap := make(map[string]stakingTypes.ValidatorI) currentValidatorSet, err := h.getValidatorSet(ctx, blockHeight-2) if err != nil { @@ -208,19 +185,24 @@ func (h *AbciHandler) checkStakePower(ctx sdk.Context, blockHeight int64, pl Pay // Require at least 2/3 signed power to prevent proposer-side signature withholding. for _, val := range currentValidatorSet { - cosmosValidatorPubKey, err := h.getValidatorPublicKey(ctx, val.ConsensusAddr) + consAddr, err := val.GetConsAddr() + if err != nil { + continue + } + + cosmosValidatorPubKey, err := h.getValidatorPublicKey(ctx, consAddr) if err != nil { return false, err } valInfoMap[hex.EncodeToString(cosmosValidatorPubKey)] = val - currentValidatorStakePower += val.Power + currentValidatorStakePower += val.GetConsensusPower(sdk.DefaultPowerReduction) } for addr := range pl.Votes { validatorInfo, ok := valInfoMap[addr] if ok { - signedStakePower += validatorInfo.Power + signedStakePower += validatorInfo.GetConsensusPower(sdk.DefaultPowerReduction) } } if signedStakePower*3 < currentValidatorStakePower*2 { @@ -284,7 +266,13 @@ func (h *AbciHandler) constructPayload(ctx sdk.Context, blockHeight int64, voteE } for _, currentValidator := range currentValidatorSet { - currentValidatorSetMap[string(currentValidator.ConsensusAddr)] = true + + consAddr, err := currentValidator.GetConsAddr() + if err != nil { + continue + } + + currentValidatorSetMap[string(consAddr)] = true } for i, vote := range voteExtensions { diff --git a/abci/pre_blocker.go b/abci/pre_blocker.go index 363f9eff..aab27f7c 100644 --- a/abci/pre_blocker.go +++ b/abci/pre_blocker.go @@ -34,7 +34,13 @@ func (h *AbciHandler) PreBlocker() sdk.PreBlocker { currentValidatorSetMap := make(map[string][]byte) for _, currentValidator := range currentValidatorSet { - cosmosValidatorPublicKey, err := h.getValidatorPublicKey(ctx, currentValidator.ConsensusAddr) + + consAddr, err := currentValidator.GetConsAddr() + if err != nil { + continue + } + + cosmosValidatorPublicKey, err := h.getValidatorPublicKey(ctx, consAddr) if err != nil { return nil, err } From 1938c0af9a9d2d42bce728d11678b9b2aa23463b Mon Sep 17 00:00:00 2001 From: Yusuf Date: Fri, 1 May 2026 18:02:55 +0300 Subject: [PATCH 54/62] feat: add sorting by validator power to ensure each node gets the same validator set root --- abci/helpers.go | 28 ++++++++++++++++++++++++++++ 1 file changed, 28 insertions(+) diff --git a/abci/helpers.go b/abci/helpers.go index 75e3d0e0..23dccf1d 100644 --- a/abci/helpers.go +++ b/abci/helpers.go @@ -1,11 +1,13 @@ package vote_ext import ( + "bytes" "context" "encoding/hex" "encoding/json" "fmt" "math/big" + "sort" "strings" abci "github.com/cometbft/cometbft/abci/types" @@ -94,6 +96,7 @@ func (h *AbciHandler) getValidatorSet(ctx sdk.Context, currentBlockHeight int64) if err != nil { return nil, err } + sortValidatorsByPower(valInfo) return valInfo, nil } @@ -105,9 +108,34 @@ func (h *AbciHandler) getValidatorSet(ctx sdk.Context, currentBlockHeight int64) for _, validator := range historicalData.Valset { valInfo = append(valInfo, validator) } + + sortValidatorsByPower(valInfo) + return valInfo, nil } +func sortValidatorsByPower(validators []stakingTypes.ValidatorI) { + sort.SliceStable(validators, func(i, j int) bool { + leftPower := validators[i].GetConsensusPower(sdk.DefaultPowerReduction) + rightPower := validators[j].GetConsensusPower(sdk.DefaultPowerReduction) + + if leftPower == rightPower { + leftAddr, err := validators[i].GetConsAddr() + if err != nil { + return false + } + rightAddr, err := validators[j].GetConsAddr() + if err != nil { + return false + } + + return bytes.Compare(leftAddr, rightAddr) == -1 + } + + return leftPower > rightPower + }) +} + // TODO: Move this helper to mina-signer-go func (h *AbciHandler) calculateValidatorSetRoot(ctx sdk.Context, valInfo []stakingTypes.ValidatorI, poseidonHash *poseidon.Poseidon) (*big.Int, error) { From 7eba14b54601986f75ca202dda8f9936e350d68f Mon Sep 17 00:00:00 2001 From: Yusuf Date: Fri, 1 May 2026 19:09:25 +0300 Subject: [PATCH 55/62] chore: build vote ext body with proto, and return that in query --- abci/extend_vote.go | 7 - abci/helpers.go | 19 +- .../votepersistence/v1/query.proto | 10 +- .../votepersistence/v1/vote_ext_body.proto | 12 + .../keeper/query_vote_ext_body_by_height.go | 23 +- x/votepersistence/types/query.pb.go | 342 ++----------- x/votepersistence/types/vote_ext_body.pb.go | 467 ++++++++++++++++++ 7 files changed, 538 insertions(+), 342 deletions(-) create mode 100644 proto/pulsarchain/votepersistence/v1/vote_ext_body.proto create mode 100644 x/votepersistence/types/vote_ext_body.pb.go diff --git a/abci/extend_vote.go b/abci/extend_vote.go index 7dec9fa3..776d3a6d 100644 --- a/abci/extend_vote.go +++ b/abci/extend_vote.go @@ -5,13 +5,6 @@ import ( sdk "github.com/cosmos/cosmos-sdk/types" ) -type VoteExtensionBody struct { - NextValidatorSetHash []byte - CurrentStateRoot []byte - CurrentBlockHeight int64 - ActionsReducedRoot string -} - func (h *AbciHandler) ExtendVoteHandler() sdk.ExtendVoteHandler { return func(ctx sdk.Context, req *abci.RequestExtendVote) (*abci.ResponseExtendVote, error) { diff --git a/abci/helpers.go b/abci/helpers.go index 23dccf1d..2e1c47b2 100644 --- a/abci/helpers.go +++ b/abci/helpers.go @@ -18,13 +18,14 @@ import ( "github.com/node101-io/mina-signer-go/keys" "github.com/node101-io/mina-signer-go/poseidon" "github.com/node101-io/pulsar-chain/x/votepersistence/types" + votepersistenceTypes "github.com/node101-io/pulsar-chain/x/votepersistence/types" ) -func MockSign(voteExtBody VoteExtensionBody) []byte { +func MockSign(voteExtBody votepersistenceTypes.VoteExtBody) []byte { return []byte{} } -func MockSignatureVerify(signature []byte, message VoteExtensionBody, minaKey []byte, reducedRoot string) bool { +func MockSignatureVerify(signature []byte, message votepersistenceTypes.VoteExtBody, minaKey []byte, reducedRoot string) bool { return true } @@ -51,7 +52,7 @@ func extractPayload(txs [][]byte) (Payload, error) { return pl, nil } -func (h *AbciHandler) verifyVoteExtension(ctx context.Context, pl Payload, body VoteExtensionBody) error { +func (h *AbciHandler) verifyVoteExtension(ctx context.Context, pl Payload, body votepersistenceTypes.VoteExtBody) error { for publicKey, vote := range pl.Votes { @@ -240,29 +241,29 @@ func (h *AbciHandler) checkStakePower(ctx sdk.Context, blockHeight int64, pl Pay return true, nil } -func (h *AbciHandler) constructVoteExtBody(ctx sdk.Context, blockHeight int64) (VoteExtensionBody, error) { +func (h *AbciHandler) constructVoteExtBody(ctx sdk.Context, blockHeight int64) (votepersistenceTypes.VoteExtBody, error) { nextValidatorSet, err := h.getValidatorSet(ctx, blockHeight) if err != nil { - return VoteExtensionBody{}, err + return votepersistenceTypes.VoteExtBody{}, err } currentBlockInfo, err := h.stakingKeeper.GetHistoricalInfo(ctx, blockHeight-1) if err != nil { - return VoteExtensionBody{}, err + return votepersistenceTypes.VoteExtBody{}, err } poseidonHash := poseidon.CreatePoseidon(*field.Fp, constants.PoseidonParamsKimchiFp) nextValidatorSetHash, err := h.calculateValidatorSetRoot(ctx, nextValidatorSet, poseidonHash) if err != nil { - return VoteExtensionBody{}, err + return votepersistenceTypes.VoteExtBody{}, err } if nextValidatorSetHash == nil { - return VoteExtensionBody{}, err + return votepersistenceTypes.VoteExtBody{}, err } - return VoteExtensionBody{ + return votepersistenceTypes.VoteExtBody{ NextValidatorSetHash: nextValidatorSetHash.Bytes(), CurrentStateRoot: currentBlockInfo.Header.AppHash, CurrentBlockHeight: blockHeight - 1, diff --git a/proto/pulsarchain/votepersistence/v1/query.proto b/proto/pulsarchain/votepersistence/v1/query.proto index 6d8ce856..215bd80d 100644 --- a/proto/pulsarchain/votepersistence/v1/query.proto +++ b/proto/pulsarchain/votepersistence/v1/query.proto @@ -7,6 +7,8 @@ import "cosmos/base/query/v1beta1/pagination.proto"; import "gogoproto/gogo.proto"; import "google/api/annotations.proto"; import "pulsarchain/votepersistence/v1/params.proto"; +import "pulsarchain/votepersistence/v1/vote_ext_body.proto"; + option go_package = "github.com/node101-io/pulsar-chain/x/votepersistence/types"; @@ -18,7 +20,7 @@ service Query { } // VoteExtBodyByHeight Queries a list of VoteExtBodyByHeight items. - rpc VoteExtBodyByHeight(QueryVoteExtBodyByHeightRequest) returns (QueryVoteExtBodyByHeightResponse) { + rpc VoteExtBodyByHeight(QueryVoteExtBodyByHeightRequest) returns (VoteExtBody) { option (google.api.http).get = "/node101-io/pulsar-chain/votepersistence/v1/vote_ext_body_by_height/{block_height}"; } } @@ -40,9 +42,3 @@ message QueryVoteExtBodyByHeightRequest { int64 block_height = 1; } -// QueryVoteExtBodyByHeightResponse defines the QueryVoteExtBodyByHeightResponse message. -message QueryVoteExtBodyByHeightResponse { - bytes next_validator_set_hash = 1; - bytes current_state_root = 2; - int64 current_block_height = 3; -} diff --git a/proto/pulsarchain/votepersistence/v1/vote_ext_body.proto b/proto/pulsarchain/votepersistence/v1/vote_ext_body.proto new file mode 100644 index 00000000..a7cf3128 --- /dev/null +++ b/proto/pulsarchain/votepersistence/v1/vote_ext_body.proto @@ -0,0 +1,12 @@ +syntax = "proto3"; +package pulsarchain.votepersistence.v1; + +option go_package = "github.com/node101-io/pulsar-chain/x/votepersistence/types"; + +// VoteExtBody defines the VoteExtBody message. +message VoteExtBody { + bytes next_validator_set_hash = 1; + bytes current_state_root = 2; + int64 current_block_height = 3; + string actions_reduced_root = 4; +} diff --git a/x/votepersistence/keeper/query_vote_ext_body_by_height.go b/x/votepersistence/keeper/query_vote_ext_body_by_height.go index 2c599011..b8aea73d 100644 --- a/x/votepersistence/keeper/query_vote_ext_body_by_height.go +++ b/x/votepersistence/keeper/query_vote_ext_body_by_height.go @@ -2,8 +2,6 @@ package keeper import ( "context" - "errors" - "fmt" "math/big" sdk "github.com/cosmos/cosmos-sdk/types" @@ -17,7 +15,9 @@ import ( "google.golang.org/grpc/status" ) -func (q queryServer) VoteExtBodyByHeight(ctx context.Context, req *types.QueryVoteExtBodyByHeightRequest) (*types.QueryVoteExtBodyByHeightResponse, error) { +const ActionsReducedRoot string = "pulsar" + +func (q queryServer) VoteExtBodyByHeight(ctx context.Context, req *types.QueryVoteExtBodyByHeightRequest) (*types.VoteExtBody, error) { if req == nil { return nil, status.Error(codes.InvalidArgument, "invalid request") } @@ -39,15 +39,15 @@ func (q queryServer) VoteExtBodyByHeight(ctx context.Context, req *types.QueryVo return q.constructVoteExtBodyByHeight(ctx, req.BlockHeight) } -func (q queryServer) constructVoteExtBodyByHeight(ctx context.Context, blockHeight int64) (*types.QueryVoteExtBodyByHeightResponse, error) { +func (q queryServer) constructVoteExtBodyByHeight(ctx context.Context, blockHeight int64) (*types.VoteExtBody, error) { currentBlockInfo, err := q.k.stakingKeeper.GetHistoricalInfo(ctx, blockHeight-2) if err != nil { - return nil, wrapHistoricalInfoError(blockHeight, err) + return nil, err } nextBlockInfo, err := q.k.stakingKeeper.GetHistoricalInfo(ctx, blockHeight-1) if err != nil { - return nil, wrapHistoricalInfoError(blockHeight+1, err) + return nil, err } nextValidatorSetHash, err := q.calculateValidatorSetRoot(ctx, nextBlockInfo.Valset) @@ -55,10 +55,11 @@ func (q queryServer) constructVoteExtBodyByHeight(ctx context.Context, blockHeig return nil, err } - return &types.QueryVoteExtBodyByHeightResponse{ + return &types.VoteExtBody{ NextValidatorSetHash: nextValidatorSetHash, CurrentStateRoot: currentBlockInfo.Header.AppHash, CurrentBlockHeight: blockHeight - 1, + ActionsReducedRoot: ActionsReducedRoot, }, nil } @@ -110,11 +111,3 @@ func (q queryServer) calculateValidatorSetRoot(ctx context.Context, validatorSet return merkleRoot.Bytes(), nil } - -func wrapHistoricalInfoError(height int64, err error) error { - if errors.Is(err, stakingtypes.ErrNoHistoricalInfo) { - return status.Errorf(codes.NotFound, "historical info not found for height %d", height) - } - - return status.Error(codes.Internal, fmt.Sprintf("failed to load staking historical info for height %d", height)) -} diff --git a/x/votepersistence/types/query.pb.go b/x/votepersistence/types/query.pb.go index 07721a5a..4fa36cb2 100644 --- a/x/votepersistence/types/query.pb.go +++ b/x/votepersistence/types/query.pb.go @@ -6,6 +6,10 @@ package types import ( context "context" fmt "fmt" + io "io" + math "math" + math_bits "math/bits" + _ "github.com/cosmos/cosmos-sdk/types/query" _ "github.com/cosmos/cosmos-sdk/types/tx/amino" _ "github.com/cosmos/gogoproto/gogoproto" @@ -15,9 +19,6 @@ import ( grpc "google.golang.org/grpc" codes "google.golang.org/grpc/codes" status "google.golang.org/grpc/status" - io "io" - math "math" - math_bits "math/bits" ) // Reference imports to suppress errors if they are not otherwise used. @@ -159,72 +160,10 @@ func (m *QueryVoteExtBodyByHeightRequest) GetBlockHeight() int64 { return 0 } -// QueryVoteExtBodyByHeightResponse defines the QueryVoteExtBodyByHeightResponse message. -type QueryVoteExtBodyByHeightResponse struct { - NextValidatorSetHash []byte `protobuf:"bytes,1,opt,name=next_validator_set_hash,json=nextValidatorSetHash,proto3" json:"next_validator_set_hash,omitempty"` - CurrentStateRoot []byte `protobuf:"bytes,2,opt,name=current_state_root,json=currentStateRoot,proto3" json:"current_state_root,omitempty"` - CurrentBlockHeight int64 `protobuf:"varint,3,opt,name=current_block_height,json=currentBlockHeight,proto3" json:"current_block_height,omitempty"` -} - -func (m *QueryVoteExtBodyByHeightResponse) Reset() { *m = QueryVoteExtBodyByHeightResponse{} } -func (m *QueryVoteExtBodyByHeightResponse) String() string { return proto.CompactTextString(m) } -func (*QueryVoteExtBodyByHeightResponse) ProtoMessage() {} -func (*QueryVoteExtBodyByHeightResponse) Descriptor() ([]byte, []int) { - return fileDescriptor_2c9976ecef977273, []int{3} -} -func (m *QueryVoteExtBodyByHeightResponse) XXX_Unmarshal(b []byte) error { - return m.Unmarshal(b) -} -func (m *QueryVoteExtBodyByHeightResponse) XXX_Marshal(b []byte, deterministic bool) ([]byte, error) { - if deterministic { - return xxx_messageInfo_QueryVoteExtBodyByHeightResponse.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 *QueryVoteExtBodyByHeightResponse) XXX_Merge(src proto.Message) { - xxx_messageInfo_QueryVoteExtBodyByHeightResponse.Merge(m, src) -} -func (m *QueryVoteExtBodyByHeightResponse) XXX_Size() int { - return m.Size() -} -func (m *QueryVoteExtBodyByHeightResponse) XXX_DiscardUnknown() { - xxx_messageInfo_QueryVoteExtBodyByHeightResponse.DiscardUnknown(m) -} - -var xxx_messageInfo_QueryVoteExtBodyByHeightResponse proto.InternalMessageInfo - -func (m *QueryVoteExtBodyByHeightResponse) GetNextValidatorSetHash() []byte { - if m != nil { - return m.NextValidatorSetHash - } - return nil -} - -func (m *QueryVoteExtBodyByHeightResponse) GetCurrentStateRoot() []byte { - if m != nil { - return m.CurrentStateRoot - } - return nil -} - -func (m *QueryVoteExtBodyByHeightResponse) GetCurrentBlockHeight() int64 { - if m != nil { - return m.CurrentBlockHeight - } - return 0 -} - func init() { proto.RegisterType((*QueryParamsRequest)(nil), "pulsarchain.votepersistence.v1.QueryParamsRequest") proto.RegisterType((*QueryParamsResponse)(nil), "pulsarchain.votepersistence.v1.QueryParamsResponse") proto.RegisterType((*QueryVoteExtBodyByHeightRequest)(nil), "pulsarchain.votepersistence.v1.QueryVoteExtBodyByHeightRequest") - proto.RegisterType((*QueryVoteExtBodyByHeightResponse)(nil), "pulsarchain.votepersistence.v1.QueryVoteExtBodyByHeightResponse") } func init() { @@ -232,41 +171,35 @@ func init() { } var fileDescriptor_2c9976ecef977273 = []byte{ - // 529 bytes of a gzipped FileDescriptorProto - 0x1f, 0x8b, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0xff, 0x9c, 0x53, 0xc1, 0x6e, 0xd3, 0x40, - 0x10, 0x8d, 0x1b, 0x11, 0x89, 0x6d, 0x0f, 0xb0, 0x8d, 0x44, 0x15, 0x21, 0xb7, 0xe4, 0x80, 0x50, - 0xa0, 0xde, 0x3a, 0x85, 0x4b, 0x2f, 0xa0, 0x08, 0xa4, 0x72, 0x03, 0xb7, 0xea, 0xa1, 0x17, 0xb3, - 0x76, 0x56, 0xb6, 0x45, 0xb2, 0xe3, 0x7a, 0x27, 0x56, 0x2c, 0xc4, 0x85, 0x2f, 0x40, 0xe2, 0x27, - 0xb8, 0x80, 0xb8, 0xf2, 0x07, 0x3d, 0x56, 0xe2, 0xc2, 0x09, 0xa1, 0x04, 0x89, 0x1f, 0xe0, 0x03, - 0x90, 0xd7, 0x1b, 0xd1, 0x52, 0x42, 0x28, 0x97, 0xc8, 0x7a, 0xf3, 0xde, 0x9b, 0x37, 0x33, 0x1b, - 0xd2, 0x49, 0x47, 0x03, 0xc5, 0xb3, 0x30, 0xe6, 0x89, 0x64, 0x39, 0xa0, 0x48, 0x45, 0xa6, 0x12, - 0x85, 0x42, 0x86, 0x82, 0xe5, 0x2e, 0x3b, 0x1a, 0x89, 0xac, 0x70, 0xd2, 0x0c, 0x10, 0xa8, 0x7d, - 0x8a, 0xeb, 0xfc, 0xc6, 0x75, 0x72, 0xb7, 0x75, 0x95, 0x0f, 0x13, 0x09, 0x4c, 0xff, 0x56, 0x92, - 0x56, 0x27, 0x04, 0x35, 0x04, 0xc5, 0x02, 0xae, 0x44, 0xe5, 0xc5, 0x72, 0x37, 0x10, 0xc8, 0x5d, - 0x96, 0xf2, 0x28, 0x91, 0x1c, 0x13, 0x90, 0x86, 0xdb, 0x8c, 0x20, 0x02, 0xfd, 0xc9, 0xca, 0x2f, - 0x83, 0x5e, 0x8f, 0x00, 0xa2, 0x81, 0x60, 0x3c, 0x4d, 0x18, 0x97, 0x12, 0x50, 0x4b, 0x94, 0xa9, - 0xde, 0x5e, 0x10, 0x3f, 0xe5, 0x19, 0x1f, 0x1a, 0x72, 0xbb, 0x49, 0xe8, 0xd3, 0x32, 0xc2, 0x13, - 0x0d, 0x7a, 0xe2, 0x68, 0x24, 0x14, 0xb6, 0x9f, 0x91, 0xd5, 0x33, 0xa8, 0x4a, 0x41, 0x2a, 0x41, - 0x1f, 0x93, 0x46, 0x25, 0x5e, 0xb3, 0x36, 0xac, 0x5b, 0xcb, 0xdd, 0x9b, 0xce, 0xdf, 0xa7, 0x77, - 0x2a, 0x7d, 0xef, 0xf2, 0xf1, 0x97, 0xf5, 0xda, 0xdb, 0xef, 0x1f, 0x3a, 0x96, 0x67, 0x0c, 0xda, - 0x0f, 0xc9, 0xba, 0xee, 0x70, 0x00, 0x28, 0x1e, 0x8d, 0xb1, 0x07, 0xfd, 0xa2, 0x57, 0xec, 0x8a, - 0x24, 0x8a, 0xd1, 0x84, 0xa0, 0x37, 0xc8, 0x4a, 0x30, 0x80, 0xf0, 0xb9, 0x1f, 0x6b, 0x58, 0xf7, - 0xac, 0x7b, 0xcb, 0x1a, 0xab, 0x98, 0xed, 0x8f, 0x16, 0xd9, 0x98, 0x6f, 0x63, 0x52, 0xdf, 0x23, - 0xd7, 0xa4, 0x18, 0xa3, 0x9f, 0xf3, 0x41, 0xd2, 0xe7, 0x08, 0x99, 0xaf, 0x04, 0xfa, 0x31, 0x57, - 0xb1, 0xb6, 0x5c, 0xf1, 0x9a, 0x65, 0xf9, 0x60, 0x56, 0xdd, 0x13, 0xb8, 0xcb, 0x55, 0x4c, 0xef, - 0x10, 0x1a, 0x8e, 0xb2, 0x4c, 0x48, 0xf4, 0x15, 0x72, 0x14, 0x7e, 0x06, 0x80, 0x6b, 0x4b, 0x5a, - 0x71, 0xc5, 0x54, 0xf6, 0xca, 0x82, 0x07, 0x80, 0x74, 0x8b, 0x34, 0x67, 0xec, 0x33, 0xa1, 0xeb, - 0x3a, 0xf4, 0xcc, 0xa9, 0xf7, 0x2b, 0x7b, 0xf7, 0x7d, 0x9d, 0x5c, 0xd2, 0xd9, 0xe9, 0x3b, 0x8b, - 0x34, 0xaa, 0x4d, 0xd1, 0xee, 0xa2, 0x8d, 0x9e, 0x3f, 0x56, 0x6b, 0xfb, 0x42, 0x9a, 0x6a, 0x29, - 0xed, 0x9d, 0x57, 0x9f, 0xbe, 0xbd, 0x59, 0xba, 0x4b, 0xbb, 0x4c, 0x42, 0x5f, 0xb8, 0x5b, 0xee, - 0x66, 0x02, 0xac, 0xf2, 0xd9, 0x5c, 0xf0, 0x72, 0xe8, 0x0f, 0x8b, 0xac, 0xfe, 0x61, 0xe1, 0xf4, - 0xfe, 0x3f, 0x05, 0x99, 0x7f, 0xf1, 0xd6, 0x83, 0xff, 0x37, 0x30, 0x63, 0x1d, 0xea, 0xb1, 0xf6, - 0xa9, 0x77, 0x91, 0xb1, 0x4a, 0xc8, 0x2f, 0x5f, 0x48, 0x00, 0xfd, 0xc2, 0x0f, 0x0a, 0x73, 0x3b, - 0xf6, 0xe2, 0xf4, 0x25, 0x5f, 0xf6, 0xf6, 0x8f, 0x27, 0xb6, 0x75, 0x32, 0xb1, 0xad, 0xaf, 0x13, - 0xdb, 0x7a, 0x3d, 0xb5, 0x6b, 0x27, 0x53, 0xbb, 0xf6, 0x79, 0x6a, 0xd7, 0x0e, 0x77, 0xa2, 0x04, - 0xe3, 0x51, 0xe0, 0x84, 0x30, 0x9c, 0xdb, 0x77, 0x7c, 0xae, 0x33, 0x16, 0xa9, 0x50, 0x41, 0x43, - 0xff, 0x0f, 0xb7, 0x7f, 0x06, 0x00, 0x00, 0xff, 0xff, 0x7d, 0x4c, 0x67, 0xcd, 0x75, 0x04, 0x00, - 0x00, + // 446 bytes of a gzipped FileDescriptorProto + 0x1f, 0x8b, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0xff, 0x94, 0x52, 0xcf, 0x6a, 0x13, 0x41, + 0x18, 0xcf, 0x58, 0x0c, 0x38, 0xf5, 0xe2, 0xb4, 0x07, 0x09, 0xb2, 0xd5, 0x3d, 0x88, 0xa4, 0x74, + 0xc7, 0xdd, 0x7a, 0xea, 0x45, 0x08, 0x0a, 0x7a, 0xd3, 0x50, 0x3c, 0xf4, 0x12, 0x67, 0x37, 0x1f, + 0x9b, 0xc1, 0x64, 0xbe, 0xe9, 0xce, 0x64, 0xc9, 0x22, 0x5e, 0x7c, 0x02, 0xc1, 0x93, 0x6f, 0xe0, + 0x45, 0xf0, 0x31, 0x7a, 0x2c, 0x78, 0xf1, 0xa4, 0x92, 0x08, 0xbe, 0x86, 0x64, 0x66, 0x85, 0xd4, + 0x5a, 0xb7, 0xb9, 0x2c, 0xc3, 0xb7, 0xbf, 0xbf, 0xf3, 0x0d, 0xed, 0xea, 0xe9, 0xd8, 0x88, 0x22, + 0x1b, 0x09, 0xa9, 0x78, 0x89, 0x16, 0x34, 0x14, 0x46, 0x1a, 0x0b, 0x2a, 0x03, 0x5e, 0xc6, 0xfc, + 0x78, 0x0a, 0x45, 0x15, 0xe9, 0x02, 0x2d, 0xb2, 0x60, 0x05, 0x1b, 0xfd, 0x85, 0x8d, 0xca, 0xb8, + 0x73, 0x43, 0x4c, 0xa4, 0x42, 0xee, 0xbe, 0x9e, 0xd2, 0xe9, 0x66, 0x68, 0x26, 0x68, 0x78, 0x2a, + 0x0c, 0x78, 0x2d, 0x5e, 0xc6, 0x29, 0x58, 0x11, 0x73, 0x2d, 0x72, 0xa9, 0x84, 0x95, 0xa8, 0x6a, + 0xec, 0x76, 0x8e, 0x39, 0xba, 0x23, 0x5f, 0x9e, 0xea, 0xe9, 0xad, 0x1c, 0x31, 0x1f, 0x03, 0x17, + 0x5a, 0x72, 0xa1, 0x14, 0x5a, 0x47, 0x31, 0xf5, 0xdf, 0xdd, 0x86, 0xf8, 0x5a, 0x14, 0x62, 0xf2, + 0x07, 0x9c, 0x34, 0x80, 0x97, 0xa3, 0x01, 0xcc, 0xec, 0x20, 0xc5, 0x61, 0xdd, 0x39, 0xdc, 0xa6, + 0xec, 0xf9, 0x32, 0xf6, 0x33, 0x27, 0xd4, 0x87, 0xe3, 0x29, 0x18, 0x1b, 0xbe, 0xa4, 0x5b, 0x67, + 0xa6, 0x46, 0xa3, 0x32, 0xc0, 0x9e, 0xd2, 0xb6, 0x37, 0xbc, 0x49, 0x6e, 0x93, 0x7b, 0x9b, 0xc9, + 0xdd, 0xe8, 0xff, 0x37, 0x16, 0x79, 0x7e, 0xef, 0xda, 0xc9, 0xb7, 0x9d, 0xd6, 0xc7, 0x5f, 0x9f, + 0xbb, 0xa4, 0x5f, 0x0b, 0x84, 0x8f, 0xe8, 0x8e, 0x73, 0x78, 0x81, 0x16, 0x1e, 0xcf, 0x6c, 0x0f, + 0x87, 0x55, 0xaf, 0x7a, 0x02, 0x32, 0x1f, 0xd9, 0x3a, 0x04, 0xbb, 0x43, 0xaf, 0xa7, 0x63, 0xcc, + 0x5e, 0x0d, 0x46, 0x6e, 0xec, 0x3c, 0x37, 0xfa, 0x9b, 0x6e, 0xe6, 0x91, 0xc9, 0x87, 0x0d, 0x7a, + 0xd5, 0xc9, 0xb0, 0x4f, 0x84, 0xb6, 0xbd, 0x1b, 0x4b, 0x9a, 0x52, 0x9d, 0x2f, 0xdc, 0xd9, 0x5f, + 0x8b, 0xe3, 0xaf, 0x23, 0x3c, 0x78, 0xfb, 0xe5, 0xe7, 0xfb, 0x2b, 0x0f, 0x58, 0xc2, 0x15, 0x0e, + 0x21, 0xbe, 0x1f, 0xef, 0x49, 0xe4, 0x5e, 0x67, 0xaf, 0x61, 0x63, 0xec, 0x3b, 0xa1, 0x5b, 0xff, + 0xe8, 0xce, 0x1e, 0x5e, 0x2a, 0xc8, 0xc5, 0xb7, 0xd6, 0xd9, 0x6d, 0x12, 0x58, 0xe1, 0x86, 0x47, + 0xae, 0xc1, 0x21, 0xeb, 0xaf, 0xd3, 0xe0, 0xcc, 0x33, 0x1a, 0xa4, 0x55, 0xbd, 0x1f, 0xfe, 0x7a, + 0x75, 0x5b, 0x6f, 0x7a, 0x87, 0x27, 0xf3, 0x80, 0x9c, 0xce, 0x03, 0xf2, 0x63, 0x1e, 0x90, 0x77, + 0x8b, 0xa0, 0x75, 0xba, 0x08, 0x5a, 0x5f, 0x17, 0x41, 0xeb, 0xe8, 0x20, 0x97, 0x76, 0x34, 0x4d, + 0xa3, 0x0c, 0x27, 0x17, 0xfa, 0xce, 0xce, 0x39, 0xdb, 0x4a, 0x83, 0x49, 0xdb, 0xee, 0xd9, 0xee, + 0xff, 0x0e, 0x00, 0x00, 0xff, 0xff, 0xaa, 0xa5, 0xd2, 0x62, 0xd8, 0x03, 0x00, 0x00, } // Reference imports to suppress errors if they are not otherwise used. @@ -284,7 +217,7 @@ type QueryClient interface { // Parameters queries the parameters of the module. Params(ctx context.Context, in *QueryParamsRequest, opts ...grpc.CallOption) (*QueryParamsResponse, error) // VoteExtBodyByHeight Queries a list of VoteExtBodyByHeight items. - VoteExtBodyByHeight(ctx context.Context, in *QueryVoteExtBodyByHeightRequest, opts ...grpc.CallOption) (*QueryVoteExtBodyByHeightResponse, error) + VoteExtBodyByHeight(ctx context.Context, in *QueryVoteExtBodyByHeightRequest, opts ...grpc.CallOption) (*VoteExtBody, error) } type queryClient struct { @@ -304,8 +237,8 @@ func (c *queryClient) Params(ctx context.Context, in *QueryParamsRequest, opts . return out, nil } -func (c *queryClient) VoteExtBodyByHeight(ctx context.Context, in *QueryVoteExtBodyByHeightRequest, opts ...grpc.CallOption) (*QueryVoteExtBodyByHeightResponse, error) { - out := new(QueryVoteExtBodyByHeightResponse) +func (c *queryClient) VoteExtBodyByHeight(ctx context.Context, in *QueryVoteExtBodyByHeightRequest, opts ...grpc.CallOption) (*VoteExtBody, error) { + out := new(VoteExtBody) err := c.cc.Invoke(ctx, "/pulsarchain.votepersistence.v1.Query/VoteExtBodyByHeight", in, out, opts...) if err != nil { return nil, err @@ -318,7 +251,7 @@ type QueryServer interface { // Parameters queries the parameters of the module. Params(context.Context, *QueryParamsRequest) (*QueryParamsResponse, error) // VoteExtBodyByHeight Queries a list of VoteExtBodyByHeight items. - VoteExtBodyByHeight(context.Context, *QueryVoteExtBodyByHeightRequest) (*QueryVoteExtBodyByHeightResponse, error) + VoteExtBodyByHeight(context.Context, *QueryVoteExtBodyByHeightRequest) (*VoteExtBody, error) } // UnimplementedQueryServer can be embedded to have forward compatible implementations. @@ -328,7 +261,7 @@ type UnimplementedQueryServer struct { func (*UnimplementedQueryServer) Params(ctx context.Context, req *QueryParamsRequest) (*QueryParamsResponse, error) { return nil, status.Errorf(codes.Unimplemented, "method Params not implemented") } -func (*UnimplementedQueryServer) VoteExtBodyByHeight(ctx context.Context, req *QueryVoteExtBodyByHeightRequest) (*QueryVoteExtBodyByHeightResponse, error) { +func (*UnimplementedQueryServer) VoteExtBodyByHeight(ctx context.Context, req *QueryVoteExtBodyByHeightRequest) (*VoteExtBody, error) { return nil, status.Errorf(codes.Unimplemented, "method VoteExtBodyByHeight not implemented") } @@ -474,48 +407,6 @@ func (m *QueryVoteExtBodyByHeightRequest) MarshalToSizedBuffer(dAtA []byte) (int return len(dAtA) - i, nil } -func (m *QueryVoteExtBodyByHeightResponse) 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 *QueryVoteExtBodyByHeightResponse) MarshalTo(dAtA []byte) (int, error) { - size := m.Size() - return m.MarshalToSizedBuffer(dAtA[:size]) -} - -func (m *QueryVoteExtBodyByHeightResponse) MarshalToSizedBuffer(dAtA []byte) (int, error) { - i := len(dAtA) - _ = i - var l int - _ = l - if m.CurrentBlockHeight != 0 { - i = encodeVarintQuery(dAtA, i, uint64(m.CurrentBlockHeight)) - i-- - dAtA[i] = 0x18 - } - if len(m.CurrentStateRoot) > 0 { - i -= len(m.CurrentStateRoot) - copy(dAtA[i:], m.CurrentStateRoot) - i = encodeVarintQuery(dAtA, i, uint64(len(m.CurrentStateRoot))) - i-- - dAtA[i] = 0x12 - } - if len(m.NextValidatorSetHash) > 0 { - i -= len(m.NextValidatorSetHash) - copy(dAtA[i:], m.NextValidatorSetHash) - i = encodeVarintQuery(dAtA, i, uint64(len(m.NextValidatorSetHash))) - i-- - dAtA[i] = 0xa - } - return len(dAtA) - i, nil -} - func encodeVarintQuery(dAtA []byte, offset int, v uint64) int { offset -= sovQuery(v) base := offset @@ -559,26 +450,6 @@ func (m *QueryVoteExtBodyByHeightRequest) Size() (n int) { return n } -func (m *QueryVoteExtBodyByHeightResponse) Size() (n int) { - if m == nil { - return 0 - } - var l int - _ = l - l = len(m.NextValidatorSetHash) - if l > 0 { - n += 1 + l + sovQuery(uint64(l)) - } - l = len(m.CurrentStateRoot) - if l > 0 { - n += 1 + l + sovQuery(uint64(l)) - } - if m.CurrentBlockHeight != 0 { - n += 1 + sovQuery(uint64(m.CurrentBlockHeight)) - } - return n -} - func sovQuery(x uint64) (n int) { return (math_bits.Len64(x|1) + 6) / 7 } @@ -787,143 +658,6 @@ func (m *QueryVoteExtBodyByHeightRequest) Unmarshal(dAtA []byte) error { } return nil } -func (m *QueryVoteExtBodyByHeightResponse) 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: QueryVoteExtBodyByHeightResponse: wiretype end group for non-group") - } - if fieldNum <= 0 { - return fmt.Errorf("proto: QueryVoteExtBodyByHeightResponse: illegal tag %d (wire type %d)", fieldNum, wire) - } - switch fieldNum { - case 1: - if wireType != 2 { - return fmt.Errorf("proto: wrong wireType = %d for field NextValidatorSetHash", wireType) - } - var byteLen int - for shift := uint(0); ; shift += 7 { - if shift >= 64 { - return ErrIntOverflowQuery - } - if iNdEx >= l { - return io.ErrUnexpectedEOF - } - b := dAtA[iNdEx] - iNdEx++ - byteLen |= int(b&0x7F) << shift - if b < 0x80 { - break - } - } - if byteLen < 0 { - return ErrInvalidLengthQuery - } - postIndex := iNdEx + byteLen - if postIndex < 0 { - return ErrInvalidLengthQuery - } - if postIndex > l { - return io.ErrUnexpectedEOF - } - m.NextValidatorSetHash = append(m.NextValidatorSetHash[:0], dAtA[iNdEx:postIndex]...) - if m.NextValidatorSetHash == nil { - m.NextValidatorSetHash = []byte{} - } - iNdEx = postIndex - case 2: - if wireType != 2 { - return fmt.Errorf("proto: wrong wireType = %d for field CurrentStateRoot", wireType) - } - var byteLen int - for shift := uint(0); ; shift += 7 { - if shift >= 64 { - return ErrIntOverflowQuery - } - if iNdEx >= l { - return io.ErrUnexpectedEOF - } - b := dAtA[iNdEx] - iNdEx++ - byteLen |= int(b&0x7F) << shift - if b < 0x80 { - break - } - } - if byteLen < 0 { - return ErrInvalidLengthQuery - } - postIndex := iNdEx + byteLen - if postIndex < 0 { - return ErrInvalidLengthQuery - } - if postIndex > l { - return io.ErrUnexpectedEOF - } - m.CurrentStateRoot = append(m.CurrentStateRoot[:0], dAtA[iNdEx:postIndex]...) - if m.CurrentStateRoot == nil { - m.CurrentStateRoot = []byte{} - } - iNdEx = postIndex - case 3: - if wireType != 0 { - return fmt.Errorf("proto: wrong wireType = %d for field CurrentBlockHeight", wireType) - } - m.CurrentBlockHeight = 0 - for shift := uint(0); ; shift += 7 { - if shift >= 64 { - return ErrIntOverflowQuery - } - if iNdEx >= l { - return io.ErrUnexpectedEOF - } - b := dAtA[iNdEx] - iNdEx++ - m.CurrentBlockHeight |= int64(b&0x7F) << shift - if b < 0x80 { - break - } - } - 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/votepersistence/types/vote_ext_body.pb.go b/x/votepersistence/types/vote_ext_body.pb.go new file mode 100644 index 00000000..918fd218 --- /dev/null +++ b/x/votepersistence/types/vote_ext_body.pb.go @@ -0,0 +1,467 @@ +// Code generated by protoc-gen-gogo. DO NOT EDIT. +// source: pulsarchain/votepersistence/v1/vote_ext_body.proto + +package types + +import ( + fmt "fmt" + proto "github.com/cosmos/gogoproto/proto" + io "io" + math "math" + math_bits "math/bits" +) + +// Reference imports to suppress errors if they are not otherwise used. +var _ = proto.Marshal +var _ = fmt.Errorf +var _ = math.Inf + +// This is a compile-time assertion to ensure that this generated file +// is compatible with the proto package it is being compiled against. +// A compilation error at this line likely means your copy of the +// proto package needs to be updated. +const _ = proto.GoGoProtoPackageIsVersion3 // please upgrade the proto package + +// VoteExtBody defines the VoteExtBody message. +type VoteExtBody struct { + NextValidatorSetHash []byte `protobuf:"bytes,1,opt,name=next_validator_set_hash,json=nextValidatorSetHash,proto3" json:"next_validator_set_hash,omitempty"` + CurrentStateRoot []byte `protobuf:"bytes,2,opt,name=current_state_root,json=currentStateRoot,proto3" json:"current_state_root,omitempty"` + CurrentBlockHeight int64 `protobuf:"varint,3,opt,name=current_block_height,json=currentBlockHeight,proto3" json:"current_block_height,omitempty"` + ActionsReducedRoot string `protobuf:"bytes,4,opt,name=actions_reduced_root,json=actionsReducedRoot,proto3" json:"actions_reduced_root,omitempty"` +} + +func (m *VoteExtBody) Reset() { *m = VoteExtBody{} } +func (m *VoteExtBody) String() string { return proto.CompactTextString(m) } +func (*VoteExtBody) ProtoMessage() {} +func (*VoteExtBody) Descriptor() ([]byte, []int) { + return fileDescriptor_fc9a8a749a7bb705, []int{0} +} +func (m *VoteExtBody) XXX_Unmarshal(b []byte) error { + return m.Unmarshal(b) +} +func (m *VoteExtBody) XXX_Marshal(b []byte, deterministic bool) ([]byte, error) { + if deterministic { + return xxx_messageInfo_VoteExtBody.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 *VoteExtBody) XXX_Merge(src proto.Message) { + xxx_messageInfo_VoteExtBody.Merge(m, src) +} +func (m *VoteExtBody) XXX_Size() int { + return m.Size() +} +func (m *VoteExtBody) XXX_DiscardUnknown() { + xxx_messageInfo_VoteExtBody.DiscardUnknown(m) +} + +var xxx_messageInfo_VoteExtBody proto.InternalMessageInfo + +func (m *VoteExtBody) GetNextValidatorSetHash() []byte { + if m != nil { + return m.NextValidatorSetHash + } + return nil +} + +func (m *VoteExtBody) GetCurrentStateRoot() []byte { + if m != nil { + return m.CurrentStateRoot + } + return nil +} + +func (m *VoteExtBody) GetCurrentBlockHeight() int64 { + if m != nil { + return m.CurrentBlockHeight + } + return 0 +} + +func (m *VoteExtBody) GetActionsReducedRoot() string { + if m != nil { + return m.ActionsReducedRoot + } + return "" +} + +func init() { + proto.RegisterType((*VoteExtBody)(nil), "pulsarchain.votepersistence.v1.VoteExtBody") +} + +func init() { + proto.RegisterFile("pulsarchain/votepersistence/v1/vote_ext_body.proto", fileDescriptor_fc9a8a749a7bb705) +} + +var fileDescriptor_fc9a8a749a7bb705 = []byte{ + // 298 bytes of a gzipped FileDescriptorProto + 0x1f, 0x8b, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0xff, 0x64, 0xd0, 0x31, 0x4b, 0xc3, 0x40, + 0x14, 0x07, 0xf0, 0x9e, 0x15, 0xc1, 0xe8, 0x20, 0xa1, 0x60, 0xa7, 0xa3, 0x38, 0x75, 0xb0, 0x49, + 0xa3, 0xb8, 0x38, 0x16, 0x84, 0xce, 0xa9, 0x74, 0x70, 0x39, 0x2e, 0x97, 0x47, 0xef, 0xb0, 0xe6, + 0x85, 0xbb, 0x97, 0xd0, 0x7e, 0x0b, 0x3f, 0x96, 0x63, 0x27, 0x71, 0x94, 0xf6, 0x8b, 0xc8, 0x25, + 0x0d, 0x88, 0xae, 0xf7, 0xbb, 0xff, 0xfb, 0xc3, 0x3f, 0xb8, 0x2b, 0xab, 0xb5, 0x93, 0x56, 0x69, + 0x69, 0x8a, 0xb8, 0x46, 0x82, 0x12, 0xac, 0x33, 0x8e, 0xa0, 0x50, 0x10, 0xd7, 0x49, 0xf3, 0x24, + 0x60, 0x43, 0x22, 0xc3, 0x7c, 0x1b, 0x95, 0x16, 0x09, 0x43, 0xfe, 0x2b, 0x13, 0xfd, 0xc9, 0x44, + 0x75, 0x72, 0xf3, 0xc9, 0x82, 0x8b, 0x25, 0x12, 0x3c, 0x6d, 0x68, 0x86, 0xf9, 0x36, 0x7c, 0x08, + 0xae, 0x0b, 0x7f, 0xa2, 0x96, 0x6b, 0x93, 0x4b, 0x42, 0x2b, 0x1c, 0x90, 0xd0, 0xd2, 0xe9, 0x21, + 0x1b, 0xb1, 0xf1, 0x65, 0x3a, 0xf0, 0xbc, 0xec, 0x74, 0x01, 0x34, 0x97, 0x4e, 0x87, 0xb7, 0x41, + 0xa8, 0x2a, 0x6b, 0xa1, 0x20, 0xe1, 0x48, 0x12, 0x08, 0x8b, 0x48, 0xc3, 0x93, 0x26, 0x71, 0x75, + 0x94, 0x85, 0x87, 0x14, 0x91, 0xc2, 0x69, 0x30, 0xe8, 0x7e, 0x67, 0x6b, 0x54, 0xaf, 0x42, 0x83, + 0x59, 0x69, 0x1a, 0xf6, 0x47, 0x6c, 0xdc, 0x4f, 0xbb, 0x4b, 0x33, 0x4f, 0xf3, 0x46, 0x7c, 0x42, + 0x2a, 0x32, 0x58, 0x38, 0x61, 0x21, 0xaf, 0x14, 0xe4, 0x6d, 0xc3, 0xe9, 0x88, 0x8d, 0xcf, 0xd3, + 0xf0, 0x68, 0x69, 0x4b, 0xbe, 0x63, 0xf6, 0xfc, 0xb1, 0xe7, 0x6c, 0xb7, 0xe7, 0xec, 0x7b, 0xcf, + 0xd9, 0xfb, 0x81, 0xf7, 0x76, 0x07, 0xde, 0xfb, 0x3a, 0xf0, 0xde, 0xcb, 0xe3, 0xca, 0x90, 0xae, + 0xb2, 0x48, 0xe1, 0x5b, 0x5c, 0x60, 0x0e, 0xc9, 0x34, 0x99, 0x18, 0x8c, 0xdb, 0xa1, 0x26, 0xed, + 0xba, 0x9b, 0x7f, 0xfb, 0xd2, 0xb6, 0x04, 0x97, 0x9d, 0x35, 0xab, 0xde, 0xff, 0x04, 0x00, 0x00, + 0xff, 0xff, 0xbd, 0xc8, 0x3f, 0x5d, 0x8b, 0x01, 0x00, 0x00, +} + +func (m *VoteExtBody) 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 *VoteExtBody) MarshalTo(dAtA []byte) (int, error) { + size := m.Size() + return m.MarshalToSizedBuffer(dAtA[:size]) +} + +func (m *VoteExtBody) MarshalToSizedBuffer(dAtA []byte) (int, error) { + i := len(dAtA) + _ = i + var l int + _ = l + if len(m.ActionsReducedRoot) > 0 { + i -= len(m.ActionsReducedRoot) + copy(dAtA[i:], m.ActionsReducedRoot) + i = encodeVarintVoteExtBody(dAtA, i, uint64(len(m.ActionsReducedRoot))) + i-- + dAtA[i] = 0x22 + } + if m.CurrentBlockHeight != 0 { + i = encodeVarintVoteExtBody(dAtA, i, uint64(m.CurrentBlockHeight)) + i-- + dAtA[i] = 0x18 + } + if len(m.CurrentStateRoot) > 0 { + i -= len(m.CurrentStateRoot) + copy(dAtA[i:], m.CurrentStateRoot) + i = encodeVarintVoteExtBody(dAtA, i, uint64(len(m.CurrentStateRoot))) + i-- + dAtA[i] = 0x12 + } + if len(m.NextValidatorSetHash) > 0 { + i -= len(m.NextValidatorSetHash) + copy(dAtA[i:], m.NextValidatorSetHash) + i = encodeVarintVoteExtBody(dAtA, i, uint64(len(m.NextValidatorSetHash))) + i-- + dAtA[i] = 0xa + } + return len(dAtA) - i, nil +} + +func encodeVarintVoteExtBody(dAtA []byte, offset int, v uint64) int { + offset -= sovVoteExtBody(v) + base := offset + for v >= 1<<7 { + dAtA[offset] = uint8(v&0x7f | 0x80) + v >>= 7 + offset++ + } + dAtA[offset] = uint8(v) + return base +} +func (m *VoteExtBody) Size() (n int) { + if m == nil { + return 0 + } + var l int + _ = l + l = len(m.NextValidatorSetHash) + if l > 0 { + n += 1 + l + sovVoteExtBody(uint64(l)) + } + l = len(m.CurrentStateRoot) + if l > 0 { + n += 1 + l + sovVoteExtBody(uint64(l)) + } + if m.CurrentBlockHeight != 0 { + n += 1 + sovVoteExtBody(uint64(m.CurrentBlockHeight)) + } + l = len(m.ActionsReducedRoot) + if l > 0 { + n += 1 + l + sovVoteExtBody(uint64(l)) + } + return n +} + +func sovVoteExtBody(x uint64) (n int) { + return (math_bits.Len64(x|1) + 6) / 7 +} +func sozVoteExtBody(x uint64) (n int) { + return sovVoteExtBody(uint64((x << 1) ^ uint64((int64(x) >> 63)))) +} +func (m *VoteExtBody) 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 ErrIntOverflowVoteExtBody + } + 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: VoteExtBody: wiretype end group for non-group") + } + if fieldNum <= 0 { + return fmt.Errorf("proto: VoteExtBody: illegal tag %d (wire type %d)", fieldNum, wire) + } + switch fieldNum { + case 1: + if wireType != 2 { + return fmt.Errorf("proto: wrong wireType = %d for field NextValidatorSetHash", wireType) + } + var byteLen int + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowVoteExtBody + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + byteLen |= int(b&0x7F) << shift + if b < 0x80 { + break + } + } + if byteLen < 0 { + return ErrInvalidLengthVoteExtBody + } + postIndex := iNdEx + byteLen + if postIndex < 0 { + return ErrInvalidLengthVoteExtBody + } + if postIndex > l { + return io.ErrUnexpectedEOF + } + m.NextValidatorSetHash = append(m.NextValidatorSetHash[:0], dAtA[iNdEx:postIndex]...) + if m.NextValidatorSetHash == nil { + m.NextValidatorSetHash = []byte{} + } + iNdEx = postIndex + case 2: + if wireType != 2 { + return fmt.Errorf("proto: wrong wireType = %d for field CurrentStateRoot", wireType) + } + var byteLen int + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowVoteExtBody + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + byteLen |= int(b&0x7F) << shift + if b < 0x80 { + break + } + } + if byteLen < 0 { + return ErrInvalidLengthVoteExtBody + } + postIndex := iNdEx + byteLen + if postIndex < 0 { + return ErrInvalidLengthVoteExtBody + } + if postIndex > l { + return io.ErrUnexpectedEOF + } + m.CurrentStateRoot = append(m.CurrentStateRoot[:0], dAtA[iNdEx:postIndex]...) + if m.CurrentStateRoot == nil { + m.CurrentStateRoot = []byte{} + } + iNdEx = postIndex + case 3: + if wireType != 0 { + return fmt.Errorf("proto: wrong wireType = %d for field CurrentBlockHeight", wireType) + } + m.CurrentBlockHeight = 0 + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowVoteExtBody + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + m.CurrentBlockHeight |= int64(b&0x7F) << shift + if b < 0x80 { + break + } + } + case 4: + if wireType != 2 { + return fmt.Errorf("proto: wrong wireType = %d for field ActionsReducedRoot", wireType) + } + var stringLen uint64 + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowVoteExtBody + } + 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 ErrInvalidLengthVoteExtBody + } + postIndex := iNdEx + intStringLen + if postIndex < 0 { + return ErrInvalidLengthVoteExtBody + } + if postIndex > l { + return io.ErrUnexpectedEOF + } + m.ActionsReducedRoot = string(dAtA[iNdEx:postIndex]) + iNdEx = postIndex + default: + iNdEx = preIndex + skippy, err := skipVoteExtBody(dAtA[iNdEx:]) + if err != nil { + return err + } + if (skippy < 0) || (iNdEx+skippy) < 0 { + return ErrInvalidLengthVoteExtBody + } + if (iNdEx + skippy) > l { + return io.ErrUnexpectedEOF + } + iNdEx += skippy + } + } + + if iNdEx > l { + return io.ErrUnexpectedEOF + } + return nil +} +func skipVoteExtBody(dAtA []byte) (n int, err error) { + l := len(dAtA) + iNdEx := 0 + depth := 0 + for iNdEx < l { + var wire uint64 + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return 0, ErrIntOverflowVoteExtBody + } + if iNdEx >= l { + return 0, io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + wire |= (uint64(b) & 0x7F) << shift + if b < 0x80 { + break + } + } + wireType := int(wire & 0x7) + switch wireType { + case 0: + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return 0, ErrIntOverflowVoteExtBody + } + if iNdEx >= l { + return 0, io.ErrUnexpectedEOF + } + iNdEx++ + if dAtA[iNdEx-1] < 0x80 { + break + } + } + case 1: + iNdEx += 8 + case 2: + var length int + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return 0, ErrIntOverflowVoteExtBody + } + if iNdEx >= l { + return 0, io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + length |= (int(b) & 0x7F) << shift + if b < 0x80 { + break + } + } + if length < 0 { + return 0, ErrInvalidLengthVoteExtBody + } + iNdEx += length + case 3: + depth++ + case 4: + if depth == 0 { + return 0, ErrUnexpectedEndOfGroupVoteExtBody + } + depth-- + case 5: + iNdEx += 4 + default: + return 0, fmt.Errorf("proto: illegal wireType %d", wireType) + } + if iNdEx < 0 { + return 0, ErrInvalidLengthVoteExtBody + } + if depth == 0 { + return iNdEx, nil + } + } + return 0, io.ErrUnexpectedEOF +} + +var ( + ErrInvalidLengthVoteExtBody = fmt.Errorf("proto: negative length found during unmarshaling") + ErrIntOverflowVoteExtBody = fmt.Errorf("proto: integer overflow") + ErrUnexpectedEndOfGroupVoteExtBody = fmt.Errorf("proto: unexpected end of group") +) From 519e5a81f011cc5a25d320e30c7c031c95804fa0 Mon Sep 17 00:00:00 2001 From: Yusuf Date: Fri, 1 May 2026 19:22:48 +0300 Subject: [PATCH 56/62] fix: script was not refreshing based on code changes, fixed --- scripts/setup_local_testnet.sh | 28 +++++++++++++++++----------- 1 file changed, 17 insertions(+), 11 deletions(-) diff --git a/scripts/setup_local_testnet.sh b/scripts/setup_local_testnet.sh index 6873e6e3..6f62c5fa 100755 --- a/scripts/setup_local_testnet.sh +++ b/scripts/setup_local_testnet.sh @@ -7,7 +7,7 @@ REPO_ROOT="$(cd -- "$SCRIPT_DIR/.." && pwd)" PYTHON_HELPER="$SCRIPT_DIR/setup_local_testnet_helper.py" GO_HELPER="$SCRIPT_DIR/derive_mina_pub.go" -CHAIN_HOME="${CHAIN_HOME:-$HOME/.pulsar-chain}" +CHAIN_HOME="${CHAIN_HOME:-$HOME/.pulsar}" CHAIN_ID="${CHAIN_ID:-mytestnet}" MONIKER="${MONIKER:-mynode}" KEY_NAME="${KEY_NAME:-alice}" @@ -18,14 +18,9 @@ BOND_AMOUNT="${BOND_AMOUNT:-100000000}" MIN_GAS_PRICE="${MIN_GAS_PRICE:-0.0001pmina}" VOTE_EXT_ENABLE_HEIGHT="${VOTE_EXT_ENABLE_HEIGHT:-1}" CONFIG_YML_PATH="${CONFIG_YML_PATH:-$REPO_ROOT/config.yml}" -TMP_BUILD_DIR="$(mktemp -d "${TMPDIR:-/tmp}/pulsar-localnet.XXXXXX")" -BINARY_PATH="$TMP_BUILD_DIR/pulsar-chaind" - -cleanup() { - rm -rf "$TMP_BUILD_DIR" -} - -trap cleanup EXIT +BIN_DIR="${BIN_DIR:-$HOME/go/bin}" +BINARY_PATH="${BINARY_PATH:-$BIN_DIR/pulsard}" +COMPAT_BINARY_PATH="${COMPAT_BINARY_PATH:-$BIN_DIR/pulsar-chaind}" require_cmd() { if ! command -v "$1" >/dev/null 2>&1; then @@ -59,12 +54,17 @@ APP_FILE="$CHAIN_HOME/config/app.toml" echo "==> Cleaning previous homes..." rm -rf "$CHAIN_HOME" "$HOME/.pulsar-node1" "$HOME/.pulsar-node2" -echo "==> Building temporary binary..." +echo "==> Building binary..." +mkdir -p "$BIN_DIR" ( cd "$REPO_ROOT" go build -o "$BINARY_PATH" ./cmd/pulsard ) +if [[ "$COMPAT_BINARY_PATH" != "$BINARY_PATH" ]]; then + cp "$BINARY_PATH" "$COMPAT_BINARY_PATH" +fi + echo "==> Initializing chain home..." "$BINARY_PATH" init "$MONIKER" --chain-id "$CHAIN_ID" --home "$CHAIN_HOME" >/dev/null @@ -107,9 +107,15 @@ echo "==> Validating final genesis..." echo "" echo "Setup complete." echo " home: $CHAIN_HOME" +echo " binary: $BINARY_PATH" +echo " compat: $COMPAT_BINARY_PATH" echo " validator: $KEY_NAME" echo " cosmos_key: $COSMOS_PUB_KEY" echo " mina_key: $MINA_PUB_KEY" echo "" +echo "Query example:" +echo " $BINARY_PATH query votepersistence vote-ext-body-by-height 5 --home $CHAIN_HOME" +echo " $COMPAT_BINARY_PATH query votepersistence vote-ext-body-by-height 5 --home $CHAIN_HOME" +echo "" echo "==> Starting chain..." -"$BINARY_PATH" start --home "$CHAIN_HOME" +exec "$BINARY_PATH" start --home "$CHAIN_HOME" From d8c1629f84029390edb33d7db0ad05796aa61279 Mon Sep 17 00:00:00 2001 From: Yusuf Date: Fri, 1 May 2026 20:03:44 +0300 Subject: [PATCH 57/62] refactor: use proto in payload and update the logic accordingly --- abci/helpers.go | 56 +-- abci/pre_blocker.go | 6 +- abci/prepare_proposal.go | 4 +- abci/types.go | 5 - api/pulsarchain/abci/payload.pb.go | 590 +++++++++++++++++++++++++++ proto/pulsarchain/abci/payload.proto | 15 + x/votepersistence/types/query.pb.go | 7 +- 7 files changed, 641 insertions(+), 42 deletions(-) create mode 100644 api/pulsarchain/abci/payload.pb.go create mode 100644 proto/pulsarchain/abci/payload.proto diff --git a/abci/helpers.go b/abci/helpers.go index 2e1c47b2..e26373ff 100644 --- a/abci/helpers.go +++ b/abci/helpers.go @@ -4,11 +4,9 @@ import ( "bytes" "context" "encoding/hex" - "encoding/json" "fmt" "math/big" "sort" - "strings" abci "github.com/cometbft/cometbft/abci/types" sdk "github.com/cosmos/cosmos-sdk/types" @@ -17,6 +15,7 @@ import ( "github.com/node101-io/mina-signer-go/field" "github.com/node101-io/mina-signer-go/keys" "github.com/node101-io/mina-signer-go/poseidon" + abcipb "github.com/node101-io/pulsar-chain/api/pulsarchain/abci" "github.com/node101-io/pulsar-chain/x/votepersistence/types" votepersistenceTypes "github.com/node101-io/pulsar-chain/x/votepersistence/types" ) @@ -29,34 +28,32 @@ func MockSignatureVerify(signature []byte, message votepersistenceTypes.VoteExtB return true } -func extractPayload(txs [][]byte) (Payload, error) { +func extractPayload(txs [][]byte) (abcipb.Payload, error) { if len(txs) == 0 { - return Payload{}, ErrEmptyBlock + return abcipb.Payload{}, ErrEmptyBlock } - voteExtensionTx := txs[0] - - if !strings.Contains(string(txs[0]), VoteExtMarker) { - return Payload{}, types.ErrVoteExtMarkerNotFound + if !bytes.HasPrefix(txs[0], []byte(VoteExtMarker)) { + return abcipb.Payload{}, types.ErrVoteExtMarkerNotFound } - voteExtensionTx = voteExtensionTx[len([]byte(VoteExtMarker)):] + voteExtensionTx := txs[0][len([]byte(VoteExtMarker)):] - var pl Payload + var pl abcipb.Payload - err := json.Unmarshal(voteExtensionTx, &pl) + err := pl.Unmarshal(voteExtensionTx) if err != nil { - return Payload{}, err + return abcipb.Payload{}, err } return pl, nil } -func (h *AbciHandler) verifyVoteExtension(ctx context.Context, pl Payload, body votepersistenceTypes.VoteExtBody) error { +func (h *AbciHandler) verifyVoteExtension(ctx context.Context, pl abcipb.Payload, body votepersistenceTypes.VoteExtBody) error { - for publicKey, vote := range pl.Votes { + for _, vote := range pl.Votes { - pk, err := hex.DecodeString(publicKey) + pk, err := hex.DecodeString(vote.ConsensusPublicKey) if err != nil { return err } @@ -74,7 +71,7 @@ func (h *AbciHandler) verifyVoteExtension(ctx context.Context, pl Payload, body return err } - if !MockSignatureVerify(vote, body, minaKey, ActionsReducedRoot) { + if !MockSignatureVerify(vote.VoteExtension, body, minaKey, ActionsReducedRoot) { return types.ErrInvalidVoteExtension.Wrap("invalid signature") } @@ -200,7 +197,7 @@ func (h *AbciHandler) calculateValidatorSetRoot(ctx sdk.Context, valInfo []staki } -func (h *AbciHandler) checkStakePower(ctx sdk.Context, blockHeight int64, pl Payload) (bool, error) { +func (h *AbciHandler) checkStakePower(ctx sdk.Context, blockHeight int64, pl abcipb.Payload) (bool, error) { var signedStakePower int64 var currentValidatorStakePower int64 @@ -228,8 +225,8 @@ func (h *AbciHandler) checkStakePower(ctx sdk.Context, blockHeight int64, pl Pay currentValidatorStakePower += val.GetConsensusPower(sdk.DefaultPowerReduction) } - for addr := range pl.Votes { - validatorInfo, ok := valInfoMap[addr] + for _, vote := range pl.Votes { + validatorInfo, ok := valInfoMap[vote.ConsensusPublicKey] if ok { signedStakePower += validatorInfo.GetConsensusPower(sdk.DefaultPowerReduction) } @@ -285,13 +282,15 @@ func (h *AbciHandler) getValidatorPublicKey(ctx sdk.Context, validatorAddr []byt return cosmosValidatorPubKey.Bytes(), nil } -func (h *AbciHandler) constructPayload(ctx sdk.Context, blockHeight int64, voteExtensions []abci.ExtendedVoteInfo) (Payload, error) { - voteExtsForGivenBlock := make(map[string][]byte) +func (h *AbciHandler) constructPayload(ctx sdk.Context, blockHeight int64, voteExtensions []abci.ExtendedVoteInfo) (abcipb.Payload, error) { + + var voteExtsForGivenBlock []*abcipb.Votes + currentValidatorSetMap := make(map[string]bool) currentValidatorSet, err := h.getValidatorSet(ctx, blockHeight-2) if err != nil { - return Payload{}, err + return abcipb.Payload{}, err } for _, currentValidator := range currentValidatorSet { @@ -304,7 +303,7 @@ func (h *AbciHandler) constructPayload(ctx sdk.Context, blockHeight int64, voteE currentValidatorSetMap[string(consAddr)] = true } - for i, vote := range voteExtensions { + for _, vote := range voteExtensions { if !currentValidatorSetMap[string(vote.Validator.Address)] { continue @@ -312,15 +311,18 @@ func (h *AbciHandler) constructPayload(ctx sdk.Context, blockHeight int64, voteE cosmosValidatorPubKey, err := h.getValidatorPublicKey(ctx, vote.Validator.Address) if err != nil { - return Payload{}, err + return abcipb.Payload{}, err } - voteExtsForGivenBlock[hex.EncodeToString(cosmosValidatorPubKey)] = voteExtensions[i].VoteExtension + voteExtsForGivenBlock = append(voteExtsForGivenBlock, &abcipb.Votes{ + ConsensusPublicKey: hex.EncodeToString(cosmosValidatorPubKey), + VoteExtension: vote.VoteExtension, + }) } if len(voteExtsForGivenBlock) == 0 { - return Payload{}, nil + return abcipb.Payload{}, nil } - return Payload{Height: blockHeight - 1, Votes: voteExtsForGivenBlock}, nil + return abcipb.Payload{Height: blockHeight - 1, Votes: voteExtsForGivenBlock}, nil } diff --git a/abci/pre_blocker.go b/abci/pre_blocker.go index aab27f7c..5677638b 100644 --- a/abci/pre_blocker.go +++ b/abci/pre_blocker.go @@ -48,9 +48,9 @@ func (h *AbciHandler) PreBlocker() sdk.PreBlocker { currentValidatorSetMap[hex.EncodeToString(cosmosValidatorPublicKey)] = cosmosValidatorPublicKey } - for addr, vote := range pl.Votes { + for _, vote := range pl.Votes { - cosmosValidatorPublicKey, ok := currentValidatorSetMap[addr] + cosmosValidatorPublicKey, ok := currentValidatorSetMap[vote.ConsensusPublicKey] if !ok { continue } @@ -69,7 +69,7 @@ func (h *AbciHandler) PreBlocker() sdk.PreBlocker { return nil, err } - err = h.votePersistenceKeeper.SetVote(ctx, req.GetHeight()-2, minaKey, vote) + err = h.votePersistenceKeeper.SetVote(ctx, req.GetHeight()-2, minaKey, vote.VoteExtension) if err != nil { return nil, err } diff --git a/abci/prepare_proposal.go b/abci/prepare_proposal.go index 5a6a83b8..0cde5942 100644 --- a/abci/prepare_proposal.go +++ b/abci/prepare_proposal.go @@ -1,8 +1,6 @@ package vote_ext import ( - "encoding/json" - abci "github.com/cometbft/cometbft/abci/types" sdk "github.com/cosmos/cosmos-sdk/types" ) @@ -23,7 +21,7 @@ func (h *AbciHandler) PrepareProposalHandler() sdk.PrepareProposalHandler { return &abci.ResponsePrepareProposal{Txs: req.Txs}, err } - bz, err := json.Marshal(pl) + bz, err := pl.Marshal() if err != nil { return nil, err } diff --git a/abci/types.go b/abci/types.go index 1a76b191..43ce10ce 100644 --- a/abci/types.go +++ b/abci/types.go @@ -7,8 +7,3 @@ const ActionsReducedRoot string = "pulsar" var VoteExtMarker string = "VOTEEXT:" var ErrEmptyBlock error = errors.New("this block has no transaction") - -type Payload struct { - Height int64 `json:"height"` - Votes map[string][]byte `json:"votes"` -} diff --git a/api/pulsarchain/abci/payload.pb.go b/api/pulsarchain/abci/payload.pb.go new file mode 100644 index 00000000..6adc1b07 --- /dev/null +++ b/api/pulsarchain/abci/payload.pb.go @@ -0,0 +1,590 @@ +// Code generated by protoc-gen-gogo. DO NOT EDIT. +// source: pulsarchain/abci/payload.proto + +package abcipb + +import ( + fmt "fmt" + proto "github.com/cosmos/gogoproto/proto" + io "io" + math "math" + math_bits "math/bits" +) + +// Reference imports to suppress errors if they are not otherwise used. +var _ = proto.Marshal +var _ = fmt.Errorf +var _ = math.Inf + +// This is a compile-time assertion to ensure that this generated file +// is compatible with the proto package it is being compiled against. +// A compilation error at this line likely means your copy of the +// proto package needs to be updated. +const _ = proto.GoGoProtoPackageIsVersion3 // please upgrade the proto package + +type Payload struct { + Height int64 `protobuf:"varint,1,opt,name=height,proto3" json:"height,omitempty"` + Votes []*Votes `protobuf:"bytes,2,rep,name=votes,proto3" json:"votes,omitempty"` +} + +func (m *Payload) Reset() { *m = Payload{} } +func (m *Payload) String() string { return proto.CompactTextString(m) } +func (*Payload) ProtoMessage() {} +func (*Payload) Descriptor() ([]byte, []int) { + return fileDescriptor_5a138d1c833ef562, []int{0} +} +func (m *Payload) XXX_Unmarshal(b []byte) error { + return m.Unmarshal(b) +} +func (m *Payload) XXX_Marshal(b []byte, deterministic bool) ([]byte, error) { + if deterministic { + return xxx_messageInfo_Payload.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 *Payload) XXX_Merge(src proto.Message) { + xxx_messageInfo_Payload.Merge(m, src) +} +func (m *Payload) XXX_Size() int { + return m.Size() +} +func (m *Payload) XXX_DiscardUnknown() { + xxx_messageInfo_Payload.DiscardUnknown(m) +} + +var xxx_messageInfo_Payload proto.InternalMessageInfo + +func (m *Payload) GetHeight() int64 { + if m != nil { + return m.Height + } + return 0 +} + +func (m *Payload) GetVotes() []*Votes { + if m != nil { + return m.Votes + } + return nil +} + +type Votes struct { + ConsensusPublicKey string `protobuf:"bytes,1,opt,name=consensus_public_key,json=consensusPublicKey,proto3" json:"consensus_public_key,omitempty"` + VoteExtension []byte `protobuf:"bytes,2,opt,name=vote_extension,json=voteExtension,proto3" json:"vote_extension,omitempty"` +} + +func (m *Votes) Reset() { *m = Votes{} } +func (m *Votes) String() string { return proto.CompactTextString(m) } +func (*Votes) ProtoMessage() {} +func (*Votes) Descriptor() ([]byte, []int) { + return fileDescriptor_5a138d1c833ef562, []int{1} +} +func (m *Votes) XXX_Unmarshal(b []byte) error { + return m.Unmarshal(b) +} +func (m *Votes) XXX_Marshal(b []byte, deterministic bool) ([]byte, error) { + if deterministic { + return xxx_messageInfo_Votes.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 *Votes) XXX_Merge(src proto.Message) { + xxx_messageInfo_Votes.Merge(m, src) +} +func (m *Votes) XXX_Size() int { + return m.Size() +} +func (m *Votes) XXX_DiscardUnknown() { + xxx_messageInfo_Votes.DiscardUnknown(m) +} + +var xxx_messageInfo_Votes proto.InternalMessageInfo + +func (m *Votes) GetConsensusPublicKey() string { + if m != nil { + return m.ConsensusPublicKey + } + return "" +} + +func (m *Votes) GetVoteExtension() []byte { + if m != nil { + return m.VoteExtension + } + return nil +} + +func init() { + proto.RegisterType((*Payload)(nil), "pulsarchain.abci.Payload") + proto.RegisterType((*Votes)(nil), "pulsarchain.abci.Votes") +} + +func init() { proto.RegisterFile("pulsarchain/abci/payload.proto", fileDescriptor_5a138d1c833ef562) } + +var fileDescriptor_5a138d1c833ef562 = []byte{ + // 260 bytes of a gzipped FileDescriptorProto + 0x1f, 0x8b, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0xff, 0xe2, 0x92, 0x2b, 0x28, 0xcd, 0x29, + 0x4e, 0x2c, 0x4a, 0xce, 0x48, 0xcc, 0xcc, 0xd3, 0x4f, 0x4c, 0x4a, 0xce, 0xd4, 0x2f, 0x48, 0xac, + 0xcc, 0xc9, 0x4f, 0x4c, 0xd1, 0x2b, 0x28, 0xca, 0x2f, 0xc9, 0x17, 0x12, 0x40, 0x92, 0xd7, 0x03, + 0xc9, 0x2b, 0x05, 0x70, 0xb1, 0x07, 0x40, 0x94, 0x08, 0x89, 0x71, 0xb1, 0x65, 0xa4, 0x66, 0xa6, + 0x67, 0x94, 0x48, 0x30, 0x2a, 0x30, 0x6a, 0x30, 0x07, 0x41, 0x79, 0x42, 0xba, 0x5c, 0xac, 0x65, + 0xf9, 0x25, 0xa9, 0xc5, 0x12, 0x4c, 0x0a, 0xcc, 0x1a, 0xdc, 0x46, 0xe2, 0x7a, 0xe8, 0x86, 0xe8, + 0x85, 0x81, 0xa4, 0x83, 0x20, 0xaa, 0x94, 0x12, 0xb8, 0x58, 0xc1, 0x7c, 0x21, 0x03, 0x2e, 0x91, + 0xe4, 0xfc, 0xbc, 0xe2, 0xd4, 0xbc, 0xe2, 0xd2, 0xe2, 0xf8, 0x82, 0xd2, 0xa4, 0x9c, 0xcc, 0xe4, + 0xf8, 0xec, 0xd4, 0x4a, 0xb0, 0xe9, 0x9c, 0x41, 0x42, 0x70, 0xb9, 0x00, 0xb0, 0x94, 0x77, 0x6a, + 0xa5, 0x90, 0x2a, 0x17, 0x1f, 0xc8, 0x8c, 0xf8, 0xd4, 0x8a, 0x92, 0xd4, 0xbc, 0xe2, 0xcc, 0xfc, + 0x3c, 0x09, 0x26, 0x05, 0x46, 0x0d, 0x9e, 0x20, 0x5e, 0x90, 0xa8, 0x2b, 0x4c, 0xd0, 0x29, 0xe2, + 0xc4, 0x23, 0x39, 0xc6, 0x0b, 0x8f, 0xe4, 0x18, 0x1f, 0x3c, 0x92, 0x63, 0x9c, 0xf0, 0x58, 0x8e, + 0xe1, 0xc2, 0x63, 0x39, 0x86, 0x1b, 0x8f, 0xe5, 0x18, 0xa2, 0xec, 0xd2, 0x33, 0x4b, 0x32, 0x4a, + 0x93, 0xf4, 0x92, 0xf3, 0x73, 0xf5, 0xf3, 0xf2, 0x53, 0x52, 0x0d, 0x0d, 0x0c, 0x75, 0x33, 0xf3, + 0xf5, 0x21, 0x0e, 0xd6, 0x85, 0x06, 0x4b, 0x41, 0xa6, 0x3e, 0x7a, 0x30, 0x59, 0x83, 0x88, 0x82, + 0xa4, 0x24, 0x36, 0x70, 0x30, 0x19, 0x03, 0x02, 0x00, 0x00, 0xff, 0xff, 0x85, 0xf8, 0xb6, 0x21, + 0x48, 0x01, 0x00, 0x00, +} + +func (m *Payload) 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 *Payload) MarshalTo(dAtA []byte) (int, error) { + size := m.Size() + return m.MarshalToSizedBuffer(dAtA[:size]) +} + +func (m *Payload) MarshalToSizedBuffer(dAtA []byte) (int, error) { + i := len(dAtA) + _ = i + var l int + _ = l + if len(m.Votes) > 0 { + for iNdEx := len(m.Votes) - 1; iNdEx >= 0; iNdEx-- { + { + size, err := m.Votes[iNdEx].MarshalToSizedBuffer(dAtA[:i]) + if err != nil { + return 0, err + } + i -= size + i = encodeVarintPayload(dAtA, i, uint64(size)) + } + i-- + dAtA[i] = 0x12 + } + } + if m.Height != 0 { + i = encodeVarintPayload(dAtA, i, uint64(m.Height)) + i-- + dAtA[i] = 0x8 + } + return len(dAtA) - i, nil +} + +func (m *Votes) 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 *Votes) MarshalTo(dAtA []byte) (int, error) { + size := m.Size() + return m.MarshalToSizedBuffer(dAtA[:size]) +} + +func (m *Votes) MarshalToSizedBuffer(dAtA []byte) (int, error) { + i := len(dAtA) + _ = i + var l int + _ = l + if len(m.VoteExtension) > 0 { + i -= len(m.VoteExtension) + copy(dAtA[i:], m.VoteExtension) + i = encodeVarintPayload(dAtA, i, uint64(len(m.VoteExtension))) + i-- + dAtA[i] = 0x12 + } + if len(m.ConsensusPublicKey) > 0 { + i -= len(m.ConsensusPublicKey) + copy(dAtA[i:], m.ConsensusPublicKey) + i = encodeVarintPayload(dAtA, i, uint64(len(m.ConsensusPublicKey))) + i-- + dAtA[i] = 0xa + } + return len(dAtA) - i, nil +} + +func encodeVarintPayload(dAtA []byte, offset int, v uint64) int { + offset -= sovPayload(v) + base := offset + for v >= 1<<7 { + dAtA[offset] = uint8(v&0x7f | 0x80) + v >>= 7 + offset++ + } + dAtA[offset] = uint8(v) + return base +} +func (m *Payload) Size() (n int) { + if m == nil { + return 0 + } + var l int + _ = l + if m.Height != 0 { + n += 1 + sovPayload(uint64(m.Height)) + } + if len(m.Votes) > 0 { + for _, e := range m.Votes { + l = e.Size() + n += 1 + l + sovPayload(uint64(l)) + } + } + return n +} + +func (m *Votes) Size() (n int) { + if m == nil { + return 0 + } + var l int + _ = l + l = len(m.ConsensusPublicKey) + if l > 0 { + n += 1 + l + sovPayload(uint64(l)) + } + l = len(m.VoteExtension) + if l > 0 { + n += 1 + l + sovPayload(uint64(l)) + } + return n +} + +func sovPayload(x uint64) (n int) { + return (math_bits.Len64(x|1) + 6) / 7 +} +func sozPayload(x uint64) (n int) { + return sovPayload(uint64((x << 1) ^ uint64((int64(x) >> 63)))) +} +func (m *Payload) 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 ErrIntOverflowPayload + } + 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: Payload: wiretype end group for non-group") + } + if fieldNum <= 0 { + return fmt.Errorf("proto: Payload: illegal tag %d (wire type %d)", fieldNum, wire) + } + switch fieldNum { + case 1: + if wireType != 0 { + return fmt.Errorf("proto: wrong wireType = %d for field Height", wireType) + } + m.Height = 0 + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowPayload + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + m.Height |= int64(b&0x7F) << shift + if b < 0x80 { + break + } + } + case 2: + if wireType != 2 { + return fmt.Errorf("proto: wrong wireType = %d for field Votes", wireType) + } + var msglen int + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowPayload + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + msglen |= int(b&0x7F) << shift + if b < 0x80 { + break + } + } + if msglen < 0 { + return ErrInvalidLengthPayload + } + postIndex := iNdEx + msglen + if postIndex < 0 { + return ErrInvalidLengthPayload + } + if postIndex > l { + return io.ErrUnexpectedEOF + } + m.Votes = append(m.Votes, &Votes{}) + if err := m.Votes[len(m.Votes)-1].Unmarshal(dAtA[iNdEx:postIndex]); err != nil { + return err + } + iNdEx = postIndex + default: + iNdEx = preIndex + skippy, err := skipPayload(dAtA[iNdEx:]) + if err != nil { + return err + } + if (skippy < 0) || (iNdEx+skippy) < 0 { + return ErrInvalidLengthPayload + } + if (iNdEx + skippy) > l { + return io.ErrUnexpectedEOF + } + iNdEx += skippy + } + } + + if iNdEx > l { + return io.ErrUnexpectedEOF + } + return nil +} +func (m *Votes) 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 ErrIntOverflowPayload + } + 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: Votes: wiretype end group for non-group") + } + if fieldNum <= 0 { + return fmt.Errorf("proto: Votes: illegal tag %d (wire type %d)", fieldNum, wire) + } + switch fieldNum { + case 1: + if wireType != 2 { + return fmt.Errorf("proto: wrong wireType = %d for field ConsensusPublicKey", wireType) + } + var stringLen uint64 + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowPayload + } + 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 ErrInvalidLengthPayload + } + postIndex := iNdEx + intStringLen + if postIndex < 0 { + return ErrInvalidLengthPayload + } + if postIndex > l { + return io.ErrUnexpectedEOF + } + m.ConsensusPublicKey = string(dAtA[iNdEx:postIndex]) + iNdEx = postIndex + case 2: + if wireType != 2 { + return fmt.Errorf("proto: wrong wireType = %d for field VoteExtension", wireType) + } + var byteLen int + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowPayload + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + byteLen |= int(b&0x7F) << shift + if b < 0x80 { + break + } + } + if byteLen < 0 { + return ErrInvalidLengthPayload + } + postIndex := iNdEx + byteLen + if postIndex < 0 { + return ErrInvalidLengthPayload + } + if postIndex > l { + return io.ErrUnexpectedEOF + } + m.VoteExtension = append(m.VoteExtension[:0], dAtA[iNdEx:postIndex]...) + if m.VoteExtension == nil { + m.VoteExtension = []byte{} + } + iNdEx = postIndex + default: + iNdEx = preIndex + skippy, err := skipPayload(dAtA[iNdEx:]) + if err != nil { + return err + } + if (skippy < 0) || (iNdEx+skippy) < 0 { + return ErrInvalidLengthPayload + } + if (iNdEx + skippy) > l { + return io.ErrUnexpectedEOF + } + iNdEx += skippy + } + } + + if iNdEx > l { + return io.ErrUnexpectedEOF + } + return nil +} +func skipPayload(dAtA []byte) (n int, err error) { + l := len(dAtA) + iNdEx := 0 + depth := 0 + for iNdEx < l { + var wire uint64 + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return 0, ErrIntOverflowPayload + } + if iNdEx >= l { + return 0, io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + wire |= (uint64(b) & 0x7F) << shift + if b < 0x80 { + break + } + } + wireType := int(wire & 0x7) + switch wireType { + case 0: + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return 0, ErrIntOverflowPayload + } + if iNdEx >= l { + return 0, io.ErrUnexpectedEOF + } + iNdEx++ + if dAtA[iNdEx-1] < 0x80 { + break + } + } + case 1: + iNdEx += 8 + case 2: + var length int + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return 0, ErrIntOverflowPayload + } + if iNdEx >= l { + return 0, io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + length |= (int(b) & 0x7F) << shift + if b < 0x80 { + break + } + } + if length < 0 { + return 0, ErrInvalidLengthPayload + } + iNdEx += length + case 3: + depth++ + case 4: + if depth == 0 { + return 0, ErrUnexpectedEndOfGroupPayload + } + depth-- + case 5: + iNdEx += 4 + default: + return 0, fmt.Errorf("proto: illegal wireType %d", wireType) + } + if iNdEx < 0 { + return 0, ErrInvalidLengthPayload + } + if depth == 0 { + return iNdEx, nil + } + } + return 0, io.ErrUnexpectedEOF +} + +var ( + ErrInvalidLengthPayload = fmt.Errorf("proto: negative length found during unmarshaling") + ErrIntOverflowPayload = fmt.Errorf("proto: integer overflow") + ErrUnexpectedEndOfGroupPayload = fmt.Errorf("proto: unexpected end of group") +) diff --git a/proto/pulsarchain/abci/payload.proto b/proto/pulsarchain/abci/payload.proto new file mode 100644 index 00000000..e3982816 --- /dev/null +++ b/proto/pulsarchain/abci/payload.proto @@ -0,0 +1,15 @@ +syntax = "proto3"; + +package pulsarchain.abci; + +option go_package = "github.com/node101-io/pulsar-chain/api/pulsarchain/abci;abcipb"; + +message Payload { + int64 height = 1; + repeated Votes votes = 2; +} + +message Votes { + string consensus_public_key = 1; + bytes vote_extension = 2; +} diff --git a/x/votepersistence/types/query.pb.go b/x/votepersistence/types/query.pb.go index 4fa36cb2..8c9a2ecf 100644 --- a/x/votepersistence/types/query.pb.go +++ b/x/votepersistence/types/query.pb.go @@ -6,10 +6,6 @@ package types import ( context "context" fmt "fmt" - io "io" - math "math" - math_bits "math/bits" - _ "github.com/cosmos/cosmos-sdk/types/query" _ "github.com/cosmos/cosmos-sdk/types/tx/amino" _ "github.com/cosmos/gogoproto/gogoproto" @@ -19,6 +15,9 @@ import ( grpc "google.golang.org/grpc" codes "google.golang.org/grpc/codes" status "google.golang.org/grpc/status" + io "io" + math "math" + math_bits "math/bits" ) // Reference imports to suppress errors if they are not otherwise used. From f659b293071d990767ec786722c17610fee9370a Mon Sep 17 00:00:00 2001 From: Yusuf Date: Fri, 1 May 2026 20:19:01 +0300 Subject: [PATCH 58/62] fix: the script now initializes chain with 2 validators, allowing to test verify vote extension --- scripts/setup_local_testnet.sh | 183 ++++++++++++++++++-------- scripts/setup_local_testnet_helper.py | 56 ++++++-- 2 files changed, 178 insertions(+), 61 deletions(-) diff --git a/scripts/setup_local_testnet.sh b/scripts/setup_local_testnet.sh index 6f62c5fa..fc46e10d 100755 --- a/scripts/setup_local_testnet.sh +++ b/scripts/setup_local_testnet.sh @@ -7,17 +7,30 @@ REPO_ROOT="$(cd -- "$SCRIPT_DIR/.." && pwd)" PYTHON_HELPER="$SCRIPT_DIR/setup_local_testnet_helper.py" GO_HELPER="$SCRIPT_DIR/derive_mina_pub.go" -CHAIN_HOME="${CHAIN_HOME:-$HOME/.pulsar}" +LEGACY_CHAIN_HOME="${CHAIN_HOME:-$HOME/.pulsar}" +NODE1_HOME="${NODE1_HOME:-$HOME/.pulsar-node1}" +NODE2_HOME="${NODE2_HOME:-$HOME/.pulsar-node2}" CHAIN_ID="${CHAIN_ID:-mytestnet}" -MONIKER="${MONIKER:-mynode}" -KEY_NAME="${KEY_NAME:-alice}" +NODE1_MONIKER="${NODE1_MONIKER:-node1}" +NODE2_MONIKER="${NODE2_MONIKER:-node2}" +NODE1_KEY_NAME="${NODE1_KEY_NAME:-validator1}" +NODE2_KEY_NAME="${NODE2_KEY_NAME:-validator2}" KEYRING_BACKEND="${KEYRING_BACKEND:-test}" DENOM="${DENOM:-pmina}" -GENESIS_BALANCE="${GENESIS_BALANCE:-1000000000}" +STAKE_AMOUNT="${STAKE_AMOUNT:-1000000000}" BOND_AMOUNT="${BOND_AMOUNT:-100000000}" MIN_GAS_PRICE="${MIN_GAS_PRICE:-0.0001pmina}" -VOTE_EXT_ENABLE_HEIGHT="${VOTE_EXT_ENABLE_HEIGHT:-1}" -CONFIG_YML_PATH="${CONFIG_YML_PATH:-$REPO_ROOT/config.yml}" +VOTE_EXT_ENABLE_HEIGHT="${VOTE_EXT_ENABLE_HEIGHT:-2}" +NODE1_MINA_PRIV_KEY="${NODE1_MINA_PRIV_KEY:-ES17xFroE2/QOa9yCLXsQ9sJMeIUVwr2ZXcdWGjNLlM=}" +NODE2_MINA_PRIV_KEY="${NODE2_MINA_PRIV_KEY:-PKeRXivUb4gZ/nMKxUK5beEnVJwIrzN71mAf7JVKsng=}" +NODE1_P2P_PORT="${NODE1_P2P_PORT:-26656}" +NODE1_RPC_PORT="${NODE1_RPC_PORT:-26657}" +NODE2_P2P_PORT="${NODE2_P2P_PORT:-26666}" +NODE2_RPC_PORT="${NODE2_RPC_PORT:-26667}" +NODE1_GRPC_PORT="${NODE1_GRPC_PORT:-9090}" +NODE2_GRPC_PORT="${NODE2_GRPC_PORT:-9091}" +NODE1_API_PORT="${NODE1_API_PORT:-1317}" +NODE2_API_PORT="${NODE2_API_PORT:-1318}" BIN_DIR="${BIN_DIR:-$HOME/go/bin}" BINARY_PATH="${BINARY_PATH:-$BIN_DIR/pulsard}" COMPAT_BINARY_PATH="${COMPAT_BINARY_PATH:-$BIN_DIR/pulsar-chaind}" @@ -29,30 +42,49 @@ require_cmd() { fi } -get_mina_priv_key() { - if [[ -n "${MINA_PRIV_KEY:-}" ]]; then - printf '%s\n' "$MINA_PRIV_KEY" - return - fi +derive_mina_pub_key() { + go run "$GO_HELPER" "$1" +} - python3 "$PYTHON_HELPER" read-mina-priv-key --config "$CONFIG_YML_PATH" +read_consensus_pub_key() { + python3 "$PYTHON_HELPER" read-consensus-pub-key --priv-validator-key "$1" } -derive_mina_pub_key() { - go run "$GO_HELPER" "$1" +configure_node() { + local home="$1" + local rpc_port="$2" + local p2p_port="$3" + local api_port="$4" + local grpc_port="$5" + local persistent_peers="$6" + local mina_priv_key="$7" + + sed -i.bak "s|laddr = \"tcp://127.0.0.1:26657\"|laddr = \"tcp://0.0.0.0:${rpc_port}\"|" "$home/config/config.toml" + sed -i.bak "s|laddr = \"tcp://0.0.0.0:26656\"|laddr = \"tcp://0.0.0.0:${p2p_port}\"|" "$home/config/config.toml" + sed -i.bak "s|persistent_peers = \"\"|persistent_peers = \"${persistent_peers}\"|" "$home/config/config.toml" + sed -i.bak 's|addr_book_strict = true|addr_book_strict = false|' "$home/config/config.toml" + sed -i.bak 's|allow_duplicate_ip = false|allow_duplicate_ip = true|' "$home/config/config.toml" + + sed -i.bak "s|address = \"tcp://localhost:1317\"|address = \"tcp://localhost:${api_port}\"|" "$home/config/app.toml" + sed -i.bak "s|address = \"localhost:9090\"|address = \"localhost:${grpc_port}\"|" "$home/config/app.toml" + + python3 "$PYTHON_HELPER" update-app-config \ + --app "$home/config/app.toml" \ + --min-gas-price "$MIN_GAS_PRICE" \ + --mina-priv-key "$mina_priv_key" } require_cmd go require_cmd python3 -MINA_PRIV_KEY="$(get_mina_priv_key)" -MINA_PUB_KEY="$(derive_mina_pub_key "$MINA_PRIV_KEY")" +NODE1_MINA_PUB_KEY="$(derive_mina_pub_key "$NODE1_MINA_PRIV_KEY")" +NODE2_MINA_PUB_KEY="$(derive_mina_pub_key "$NODE2_MINA_PRIV_KEY")" -GENESIS_FILE="$CHAIN_HOME/config/genesis.json" -APP_FILE="$CHAIN_HOME/config/app.toml" +NODE1_GENESIS_FILE="$NODE1_HOME/config/genesis.json" +NODE2_GENESIS_FILE="$NODE2_HOME/config/genesis.json" echo "==> Cleaning previous homes..." -rm -rf "$CHAIN_HOME" "$HOME/.pulsar-node1" "$HOME/.pulsar-node2" +rm -rf "$LEGACY_CHAIN_HOME" "$NODE1_HOME" "$NODE2_HOME" echo "==> Building binary..." mkdir -p "$BIN_DIR" @@ -65,57 +97,102 @@ if [[ "$COMPAT_BINARY_PATH" != "$BINARY_PATH" ]]; then cp "$BINARY_PATH" "$COMPAT_BINARY_PATH" fi -echo "==> Initializing chain home..." -"$BINARY_PATH" init "$MONIKER" --chain-id "$CHAIN_ID" --home "$CHAIN_HOME" >/dev/null +echo "==> Initializing nodes..." +"$BINARY_PATH" init "$NODE1_MONIKER" --chain-id "$CHAIN_ID" --home "$NODE1_HOME" >/dev/null 2>&1 +"$BINARY_PATH" init "$NODE2_MONIKER" --chain-id "$CHAIN_ID" --home "$NODE2_HOME" >/dev/null 2>&1 echo "==> Setting vote extension enable height..." python3 "$PYTHON_HELPER" set-vote-extension-height \ - --genesis "$GENESIS_FILE" \ + --genesis "$NODE1_GENESIS_FILE" \ --height "$VOTE_EXT_ENABLE_HEIGHT" -echo "==> Creating validator key..." -"$BINARY_PATH" keys add "$KEY_NAME" --home "$CHAIN_HOME" --keyring-backend "$KEYRING_BACKEND" >/dev/null +echo "==> Creating validator keys..." +"$BINARY_PATH" keys add "$NODE1_KEY_NAME" --home "$NODE1_HOME" --keyring-backend "$KEYRING_BACKEND" >/dev/null 2>&1 +"$BINARY_PATH" keys add "$NODE2_KEY_NAME" --home "$NODE2_HOME" --keyring-backend "$KEYRING_BACKEND" >/dev/null 2>&1 + +NODE1_ADDR="$("$BINARY_PATH" keys show "$NODE1_KEY_NAME" --address --home "$NODE1_HOME" --keyring-backend "$KEYRING_BACKEND")" +NODE2_ADDR="$("$BINARY_PATH" keys show "$NODE2_KEY_NAME" --address --home "$NODE2_HOME" --keyring-backend "$KEYRING_BACKEND")" -VALIDATOR_ADDR="$("$BINARY_PATH" keys show "$KEY_NAME" --address --home "$CHAIN_HOME" --keyring-backend "$KEYRING_BACKEND")" +echo "==> Adding genesis accounts..." +"$BINARY_PATH" genesis add-genesis-account "$NODE1_ADDR" "${STAKE_AMOUNT}${DENOM}" --home "$NODE1_HOME" >/dev/null 2>&1 +"$BINARY_PATH" genesis add-genesis-account "$NODE2_ADDR" "${STAKE_AMOUNT}${DENOM}" --home "$NODE1_HOME" >/dev/null 2>&1 + +echo "==> Creating gentx for ${NODE1_KEY_NAME}..." +"$BINARY_PATH" genesis gentx "$NODE1_KEY_NAME" "${BOND_AMOUNT}${DENOM}" \ + --chain-id "$CHAIN_ID" \ + --home "$NODE1_HOME" \ + --keyring-backend "$KEYRING_BACKEND" >/dev/null 2>&1 -echo "==> Adding genesis account for $KEY_NAME..." -"$BINARY_PATH" genesis add-genesis-account "$VALIDATOR_ADDR" "${GENESIS_BALANCE}${DENOM}" --home "$CHAIN_HOME" >/dev/null +echo "==> Copying shared genesis to node2..." +cp "$NODE1_GENESIS_FILE" "$NODE2_GENESIS_FILE" -echo "==> Creating gentx..." -"$BINARY_PATH" genesis gentx "$KEY_NAME" "${BOND_AMOUNT}${DENOM}" \ +echo "==> Creating gentx for ${NODE2_KEY_NAME}..." +"$BINARY_PATH" genesis gentx "$NODE2_KEY_NAME" "${BOND_AMOUNT}${DENOM}" \ --chain-id "$CHAIN_ID" \ - --home "$CHAIN_HOME" \ - --keyring-backend "$KEYRING_BACKEND" >/dev/null + --home "$NODE2_HOME" \ + --keyring-backend "$KEYRING_BACKEND" >/dev/null 2>&1 echo "==> Collecting gentxs..." -"$BINARY_PATH" genesis collect-gentxs --home "$CHAIN_HOME" >/dev/null +cp "$NODE2_HOME"/config/gentx/*.json "$NODE1_HOME/config/gentx/" +"$BINARY_PATH" genesis collect-gentxs --home "$NODE1_HOME" >/dev/null 2>&1 -echo "==> Patching keyregistry validator key pair from genesis validator pubkey..." -COSMOS_PUB_KEY="$(python3 "$PYTHON_HELPER" patch-keyregistry \ - --genesis "$GENESIS_FILE" \ - --mina-pub-key "$MINA_PUB_KEY")" +NODE1_COSMOS_PUB_KEY="$(read_consensus_pub_key "$NODE1_HOME/config/priv_validator_key.json")" +NODE2_COSMOS_PUB_KEY="$(read_consensus_pub_key "$NODE2_HOME/config/priv_validator_key.json")" -echo "==> Writing vote extension private key to app.toml..." -python3 "$PYTHON_HELPER" update-app-config \ - --app "$APP_FILE" \ - --min-gas-price "$MIN_GAS_PRICE" \ - --mina-priv-key "$MINA_PRIV_KEY" +echo "==> Patching keyregistry validator key pairs..." +python3 "$PYTHON_HELPER" patch-keyregistry \ + --genesis "$NODE1_GENESIS_FILE" \ + --cosmos-key "$NODE1_COSMOS_PUB_KEY" \ + --mina-pub-key "$NODE1_MINA_PUB_KEY" \ + --cosmos-key "$NODE2_COSMOS_PUB_KEY" \ + --mina-pub-key "$NODE2_MINA_PUB_KEY" >/dev/null echo "==> Validating final genesis..." -"$BINARY_PATH" genesis validate-genesis --home "$CHAIN_HOME" >/dev/null +"$BINARY_PATH" genesis validate-genesis --home "$NODE1_HOME" >/dev/null 2>&1 + +echo "==> Copying final genesis to node2..." +cp "$NODE1_GENESIS_FILE" "$NODE2_GENESIS_FILE" + +NODE1_ID="$("$BINARY_PATH" tendermint show-node-id --home "$NODE1_HOME")" +NODE2_ID="$("$BINARY_PATH" tendermint show-node-id --home "$NODE2_HOME")" + +echo "==> Configuring node1..." +configure_node \ + "$NODE1_HOME" \ + "$NODE1_RPC_PORT" \ + "$NODE1_P2P_PORT" \ + "$NODE1_API_PORT" \ + "$NODE1_GRPC_PORT" \ + "$NODE2_ID@127.0.0.1:$NODE2_P2P_PORT" \ + "$NODE1_MINA_PRIV_KEY" + +echo "==> Configuring node2..." +configure_node \ + "$NODE2_HOME" \ + "$NODE2_RPC_PORT" \ + "$NODE2_P2P_PORT" \ + "$NODE2_API_PORT" \ + "$NODE2_GRPC_PORT" \ + "$NODE1_ID@127.0.0.1:$NODE1_P2P_PORT" \ + "$NODE2_MINA_PRIV_KEY" echo "" echo "Setup complete." -echo " home: $CHAIN_HOME" -echo " binary: $BINARY_PATH" -echo " compat: $COMPAT_BINARY_PATH" -echo " validator: $KEY_NAME" -echo " cosmos_key: $COSMOS_PUB_KEY" -echo " mina_key: $MINA_PUB_KEY" +echo " binary: $BINARY_PATH" +echo " compat binary: $COMPAT_BINARY_PATH" +echo " node1 home: $NODE1_HOME" +echo " node2 home: $NODE2_HOME" +echo " node1 address: $NODE1_ADDR" +echo " node2 address: $NODE2_ADDR" +echo " node1 cosmos key: $NODE1_COSMOS_PUB_KEY" +echo " node2 cosmos key: $NODE2_COSMOS_PUB_KEY" +echo " node1 mina key: $NODE1_MINA_PUB_KEY" +echo " node2 mina key: $NODE2_MINA_PUB_KEY" echo "" -echo "Query example:" -echo " $BINARY_PATH query votepersistence vote-ext-body-by-height 5 --home $CHAIN_HOME" -echo " $COMPAT_BINARY_PATH query votepersistence vote-ext-body-by-height 5 --home $CHAIN_HOME" +echo "Start the nodes in separate terminals:" +echo " $BINARY_PATH start --home $NODE1_HOME" +echo " $BINARY_PATH start --home $NODE2_HOME" echo "" -echo "==> Starting chain..." -exec "$BINARY_PATH" start --home "$CHAIN_HOME" +echo "Validation examples:" +echo " curl -s http://localhost:$NODE1_RPC_PORT/validators | python3 -m json.tool | grep total" +echo " $BINARY_PATH query votepersistence vote-ext-body-by-height 5 --home $NODE1_HOME" diff --git a/scripts/setup_local_testnet_helper.py b/scripts/setup_local_testnet_helper.py index b86818fc..a84917d1 100644 --- a/scripts/setup_local_testnet_helper.py +++ b/scripts/setup_local_testnet_helper.py @@ -5,6 +5,7 @@ import re import sys from pathlib import Path +from typing import Optional def read_text(path_str: str) -> str: @@ -42,25 +43,58 @@ def set_vote_extension_height(genesis_path: str, height: str) -> int: return 0 -def patch_keyregistry(genesis_path: str, mina_pub_key: str) -> int: +def read_consensus_pub_key(priv_validator_key_path: str) -> int: + priv_validator_key = read_json(priv_validator_key_path) + print(priv_validator_key["pub_key"]["value"]) + return 0 + + +def extract_gentx_consensus_pub_keys(genesis) -> list[str]: + gentxs = genesis["app_state"]["genutil"]["gen_txs"] + cosmos_keys = [] + + for gentx in gentxs: + messages = gentx.get("body", {}).get("messages", []) + if not messages: + continue + + pub_key = messages[0].get("pubkey", {}).get("key") + if pub_key: + cosmos_keys.append(pub_key) + + return cosmos_keys + + +def patch_keyregistry( + genesis_path: str, mina_pub_keys: list[str], cosmos_keys: Optional[list[str]] = None +) -> int: genesis = read_json(genesis_path) - cosmos_pub_key = ( - genesis["app_state"]["genutil"]["gen_txs"][0]["body"]["messages"][0]["pubkey"]["key"] - ) + if not mina_pub_keys: + raise SystemExit("at least one --mina-pub-key is required") + + if cosmos_keys is None: + cosmos_keys = extract_gentx_consensus_pub_keys(genesis) + + if len(cosmos_keys) != len(mina_pub_keys): + raise SystemExit( + "validator key pair count mismatch: " + f"{len(cosmos_keys)} cosmos keys for {len(mina_pub_keys)} mina keys" + ) keyregistry = genesis["app_state"].setdefault("keyregistry", {}) keyregistry["params"] = keyregistry.get("params", {}) keyregistry["user_key_pairs"] = [] keyregistry["validator_key_pairs"] = [ { - "cosmos_key": cosmos_pub_key, + "cosmos_key": cosmos_key, "mina_key": mina_pub_key, } + for cosmos_key, mina_pub_key in zip(cosmos_keys, mina_pub_keys) ] write_json(genesis_path, genesis) - print(cosmos_pub_key) + print("\n".join(cosmos_keys)) return 0 @@ -95,13 +129,17 @@ def build_parser() -> argparse.ArgumentParser: read_key = subparsers.add_parser("read-mina-priv-key") read_key.add_argument("--config", required=True) + read_consensus_key = subparsers.add_parser("read-consensus-pub-key") + read_consensus_key.add_argument("--priv-validator-key", required=True) + set_height = subparsers.add_parser("set-vote-extension-height") set_height.add_argument("--genesis", required=True) set_height.add_argument("--height", required=True) patch_registry = subparsers.add_parser("patch-keyregistry") patch_registry.add_argument("--genesis", required=True) - patch_registry.add_argument("--mina-pub-key", required=True) + patch_registry.add_argument("--cosmos-key", action="append") + patch_registry.add_argument("--mina-pub-key", action="append", required=True) update_app = subparsers.add_parser("update-app-config") update_app.add_argument("--app", required=True) @@ -117,10 +155,12 @@ def main() -> int: if args.command == "read-mina-priv-key": return read_mina_priv_key(args.config) + if args.command == "read-consensus-pub-key": + return read_consensus_pub_key(args.priv_validator_key) if args.command == "set-vote-extension-height": return set_vote_extension_height(args.genesis, args.height) if args.command == "patch-keyregistry": - return patch_keyregistry(args.genesis, args.mina_pub_key) + return patch_keyregistry(args.genesis, args.mina_pub_key, args.cosmos_key) if args.command == "update-app-config": return update_app_config(args.app, args.min_gas_price, args.mina_priv_key) From d2fe3640da1b545a2ea05d75c8b23bb06f35980f Mon Sep 17 00:00:00 2001 From: Yusuf Date: Fri, 1 May 2026 21:24:14 +0300 Subject: [PATCH 59/62] feat: implement signing/verifying vote extension bodies, using mina-signer-go --- abci/extend_vote.go | 2 +- abci/helpers.go | 49 ++++++++++++++++++++++++++++++++++++----- abci/verify_vote_ext.go | 2 +- 3 files changed, 46 insertions(+), 7 deletions(-) diff --git a/abci/extend_vote.go b/abci/extend_vote.go index 776d3a6d..b2a5e25d 100644 --- a/abci/extend_vote.go +++ b/abci/extend_vote.go @@ -17,7 +17,7 @@ func (h *AbciHandler) ExtendVoteHandler() sdk.ExtendVoteHandler { return nil, err } - bz := MockSign(body) + bz := h.secondaryKey.SignVoteExtBody(body) return &abci.ResponseExtendVote{VoteExtension: bz}, nil } diff --git a/abci/helpers.go b/abci/helpers.go index e26373ff..fbb15009 100644 --- a/abci/helpers.go +++ b/abci/helpers.go @@ -15,17 +15,56 @@ import ( "github.com/node101-io/mina-signer-go/field" "github.com/node101-io/mina-signer-go/keys" "github.com/node101-io/mina-signer-go/poseidon" + minasignature "github.com/node101-io/mina-signer-go/signature" abcipb "github.com/node101-io/pulsar-chain/api/pulsarchain/abci" "github.com/node101-io/pulsar-chain/x/votepersistence/types" votepersistenceTypes "github.com/node101-io/pulsar-chain/x/votepersistence/types" ) -func MockSign(voteExtBody votepersistenceTypes.VoteExtBody) []byte { - return []byte{} +func (s *SecondaryKey) SignVoteExtBody(voteExtBody votepersistenceTypes.VoteExtBody) []byte { + if s == nil || s.SecretKey == nil { + return nil + } + + msg, err := voteExtBody.Marshal() + if err != nil { + return nil + } + + sig, err := s.SecretKey.SignMessage(hex.EncodeToString(msg), "testnet") + if err != nil { + return nil + } + + bz, err := sig.MarshalBytes() + if err != nil { + return nil + } + + return bz } -func MockSignatureVerify(signature []byte, message votepersistenceTypes.VoteExtBody, minaKey []byte, reducedRoot string) bool { - return true +func VerifyVoteExtSig(signature []byte, message votepersistenceTypes.VoteExtBody, minaKey []byte, reducedRoot string) bool { + if message.ActionsReducedRoot != reducedRoot { + return false + } + + var pubKey keys.PublicKey + if err := pubKey.Unmarshal(minaKey); err != nil { + return false + } + + var sig minasignature.Signature + if err := sig.UnmarshalBytes(signature); err != nil { + return false + } + + msg, err := message.Marshal() + if err != nil { + return false + } + + return pubKey.VerifyMessage(&sig, hex.EncodeToString(msg), "testnet") } func extractPayload(txs [][]byte) (abcipb.Payload, error) { @@ -71,7 +110,7 @@ func (h *AbciHandler) verifyVoteExtension(ctx context.Context, pl abcipb.Payload return err } - if !MockSignatureVerify(vote.VoteExtension, body, minaKey, ActionsReducedRoot) { + if !VerifyVoteExtSig(vote.VoteExtension, body, minaKey, ActionsReducedRoot) { return types.ErrInvalidVoteExtension.Wrap("invalid signature") } diff --git a/abci/verify_vote_ext.go b/abci/verify_vote_ext.go index 167f3334..82cf9430 100644 --- a/abci/verify_vote_ext.go +++ b/abci/verify_vote_ext.go @@ -41,7 +41,7 @@ func (h *AbciHandler) VerifyVoteExtensionHandler() sdk.VerifyVoteExtensionHandle return &abci.ResponseVerifyVoteExtension{Status: abci.ResponseVerifyVoteExtension_REJECT}, err } - sigValidity := MockSignatureVerify(req.VoteExtension, body, minaKey, ActionsReducedRoot) + sigValidity := VerifyVoteExtSig(req.VoteExtension, body, minaKey, ActionsReducedRoot) if !sigValidity { return &abci.ResponseVerifyVoteExtension{Status: abci.ResponseVerifyVoteExtension_REJECT}, err } From 3b922cbe53cd29e187f405ee598c7e4655b380f0 Mon Sep 17 00:00:00 2001 From: Yusuf Date: Fri, 1 May 2026 21:27:34 +0300 Subject: [PATCH 60/62] fix: start vote extension at height 3 --- scripts/setup_local_testnet.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/scripts/setup_local_testnet.sh b/scripts/setup_local_testnet.sh index fc46e10d..c31094d9 100755 --- a/scripts/setup_local_testnet.sh +++ b/scripts/setup_local_testnet.sh @@ -20,7 +20,7 @@ DENOM="${DENOM:-pmina}" STAKE_AMOUNT="${STAKE_AMOUNT:-1000000000}" BOND_AMOUNT="${BOND_AMOUNT:-100000000}" MIN_GAS_PRICE="${MIN_GAS_PRICE:-0.0001pmina}" -VOTE_EXT_ENABLE_HEIGHT="${VOTE_EXT_ENABLE_HEIGHT:-2}" +VOTE_EXT_ENABLE_HEIGHT="${VOTE_EXT_ENABLE_HEIGHT:-3}" NODE1_MINA_PRIV_KEY="${NODE1_MINA_PRIV_KEY:-ES17xFroE2/QOa9yCLXsQ9sJMeIUVwr2ZXcdWGjNLlM=}" NODE2_MINA_PRIV_KEY="${NODE2_MINA_PRIV_KEY:-PKeRXivUb4gZ/nMKxUK5beEnVJwIrzN71mAf7JVKsng=}" NODE1_P2P_PORT="${NODE1_P2P_PORT:-26656}" From 1c1c759101d86e7f00bc34cbd5ba1b8a3df43e82 Mon Sep 17 00:00:00 2001 From: Yusuf Date: Fri, 1 May 2026 21:28:21 +0300 Subject: [PATCH 61/62] chore: remove empty block error and let prepare/process proposals start at height 4 --- abci/helpers.go | 2 +- abci/pre_blocker.go | 2 +- abci/prepare_proposal.go | 4 ++-- abci/process_proposal.go | 4 ++-- abci/types.go | 4 ---- 5 files changed, 6 insertions(+), 10 deletions(-) diff --git a/abci/helpers.go b/abci/helpers.go index fbb15009..1760d233 100644 --- a/abci/helpers.go +++ b/abci/helpers.go @@ -70,7 +70,7 @@ func VerifyVoteExtSig(signature []byte, message votepersistenceTypes.VoteExtBody func extractPayload(txs [][]byte) (abcipb.Payload, error) { if len(txs) == 0 { - return abcipb.Payload{}, ErrEmptyBlock + return abcipb.Payload{}, nil } if !bytes.HasPrefix(txs[0], []byte(VoteExtMarker)) { diff --git a/abci/pre_blocker.go b/abci/pre_blocker.go index 5677638b..65ff1e19 100644 --- a/abci/pre_blocker.go +++ b/abci/pre_blocker.go @@ -12,7 +12,7 @@ func (h *AbciHandler) PreBlocker() sdk.PreBlocker { return func(ctx sdk.Context, req *abci.RequestFinalizeBlock) (*sdk.ResponsePreBlock, error) { // If height is smaller than 4, we won't have any votes thus skip the proposal - if req.GetHeight() < 3 { + if req.GetHeight() < 4 { return &sdk.ResponsePreBlock{}, nil } diff --git a/abci/prepare_proposal.go b/abci/prepare_proposal.go index 0cde5942..2a6d1a10 100644 --- a/abci/prepare_proposal.go +++ b/abci/prepare_proposal.go @@ -10,8 +10,8 @@ func (h *AbciHandler) PrepareProposalHandler() sdk.PrepareProposalHandler { return func(ctx sdk.Context, req *abci.RequestPrepareProposal) (*abci.ResponsePrepareProposal, error) { // to construct the payload we need to get the N-2th block's vote extensions. - // Hence, enabling prepare proposal on blocks < 3 will result in error. - if req.Height < 3 { + // Hence, enabling prepare proposal on blocks < 4 will result in error. + if req.Height < 4 { return &abci.ResponsePrepareProposal{Txs: req.Txs}, nil } diff --git a/abci/process_proposal.go b/abci/process_proposal.go index 9f459434..d2ce3343 100644 --- a/abci/process_proposal.go +++ b/abci/process_proposal.go @@ -11,8 +11,8 @@ func (h *AbciHandler) ProcessProposalHandler() sdk.ProcessProposalHandler { return func(ctx sdk.Context, req *abci.RequestProcessProposal) (*abci.ResponseProcessProposal, error) { - // If height is less than 3, we won't have any votes thus skip the proposal - if req.GetHeight() < 3 { + // If height is less than 4, we won't have any votes thus skip the proposal + if req.GetHeight() < 4 { return &abci.ResponseProcessProposal{Status: abci.ResponseProcessProposal_ACCEPT}, nil } diff --git a/abci/types.go b/abci/types.go index 43ce10ce..f2376329 100644 --- a/abci/types.go +++ b/abci/types.go @@ -1,9 +1,5 @@ package vote_ext -import "errors" - const ActionsReducedRoot string = "pulsar" var VoteExtMarker string = "VOTEEXT:" - -var ErrEmptyBlock error = errors.New("this block has no transaction") From b53ebf301478aa9ba59c93ce80b7a2d21699e4ca Mon Sep 17 00:00:00 2001 From: Yusuf Date: Fri, 1 May 2026 22:29:37 +0300 Subject: [PATCH 62/62] chore: minor fixes on returned errors --- abci/helpers.go | 4 ++-- abci/pre_blocker.go | 4 ++-- abci/process_proposal.go | 4 +--- abci/types.go | 4 ++++ 4 files changed, 9 insertions(+), 7 deletions(-) diff --git a/abci/helpers.go b/abci/helpers.go index 1760d233..63a35db4 100644 --- a/abci/helpers.go +++ b/abci/helpers.go @@ -4,7 +4,6 @@ import ( "bytes" "context" "encoding/hex" - "fmt" "math/big" "sort" @@ -17,6 +16,7 @@ import ( "github.com/node101-io/mina-signer-go/poseidon" minasignature "github.com/node101-io/mina-signer-go/signature" abcipb "github.com/node101-io/pulsar-chain/api/pulsarchain/abci" + keyregistryTypes "github.com/node101-io/pulsar-chain/x/keyregistry/types" "github.com/node101-io/pulsar-chain/x/votepersistence/types" votepersistenceTypes "github.com/node101-io/pulsar-chain/x/votepersistence/types" ) @@ -102,7 +102,7 @@ func (h *AbciHandler) verifyVoteExtension(ctx context.Context, pl abcipb.Payload return err } if !exists { - return fmt.Errorf("") + return keyregistryTypes.ErrValidatorNotRegistered } minaKey, err := h.keyregistryKeeper.ValidatorGetCosmosToMina(ctx, pk) diff --git a/abci/pre_blocker.go b/abci/pre_blocker.go index 65ff1e19..d709710e 100644 --- a/abci/pre_blocker.go +++ b/abci/pre_blocker.go @@ -2,10 +2,10 @@ package vote_ext import ( "encoding/hex" - "fmt" abci "github.com/cometbft/cometbft/abci/types" sdk "github.com/cosmos/cosmos-sdk/types" + keyregistryTypes "github.com/node101-io/pulsar-chain/x/keyregistry/types" ) func (h *AbciHandler) PreBlocker() sdk.PreBlocker { @@ -61,7 +61,7 @@ func (h *AbciHandler) PreBlocker() sdk.PreBlocker { } if !exists { - return nil, fmt.Errorf("") + return nil, keyregistryTypes.ErrValidatorNotRegistered } minaKey, err := h.keyregistryKeeper.ValidatorGetCosmosToMina(ctx, cosmosValidatorPublicKey) diff --git a/abci/process_proposal.go b/abci/process_proposal.go index d2ce3343..f640deac 100644 --- a/abci/process_proposal.go +++ b/abci/process_proposal.go @@ -1,8 +1,6 @@ package vote_ext import ( - "fmt" - abci "github.com/cometbft/cometbft/abci/types" sdk "github.com/cosmos/cosmos-sdk/types" ) @@ -37,7 +35,7 @@ func (h *AbciHandler) ProcessProposalHandler() sdk.ProcessProposalHandler { } if !isEnoughStakePower { - return &abci.ResponseProcessProposal{Status: abci.ResponseProcessProposal_REJECT}, fmt.Errorf("") + return &abci.ResponseProcessProposal{Status: abci.ResponseProcessProposal_REJECT}, ErrNotEnoughStakePower } // Vote extension successfully verified diff --git a/abci/types.go b/abci/types.go index f2376329..6cffd353 100644 --- a/abci/types.go +++ b/abci/types.go @@ -1,5 +1,9 @@ package vote_ext +import "errors" + const ActionsReducedRoot string = "pulsar" var VoteExtMarker string = "VOTEEXT:" + +var ErrNotEnoughStakePower error = errors.New("not enough stake power")