Skip to content

Commit

Permalink
feat: generate vrf key in create-validator-vrf cli
Browse files Browse the repository at this point in the history
  • Loading branch information
hacheigriega committed Jan 5, 2024
1 parent ec8a186 commit aed9eb6
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 27 deletions.
11 changes: 6 additions & 5 deletions cmd/seda-chaind/gentx/gentx.go
Original file line number Diff line number Diff line change
Expand Up @@ -56,12 +56,13 @@ func GenTxCmd(mbm module.BasicManager, txEncCfg client.TxEncodingConfig, genBalI

cmd := &cobra.Command{
Use: "gentx [key_name] [amount]",
Short: "Generate a genesis tx carrying a self delegation",
Short: "Generate a genesis tx carrying a self delegation and VRF public key",
Args: cobra.ExactArgs(2),
Long: fmt.Sprintf(`Generate a genesis transaction that creates a validator with a self-delegation,
that is signed by the key in the Keyring referenced by a given name. A node ID and consensus
pubkey may optionally be provided. If they are omitted, they will be retrieved from the priv_validator.json
file. The following default parameters are included:
Long: fmt.Sprintf(`Generate a genesis transaction that creates a validator with a self-delegation and
VRF public key. The transaction is signed by the key in the Keyring referenced by a given name. A VRF key pair
is generated and stored in the configuration directory during the process. A node ID and consensus pubkey may
optionally be provided. If they are omitted, they will be retrieved from the priv_validator.json file.
The following default parameters are included:
%s
Example:
Expand Down
13 changes: 9 additions & 4 deletions x/staking/client/cli/tx.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,19 +8,22 @@ import (
flag "github.com/spf13/pflag"

"cosmossdk.io/core/address"
"cosmossdk.io/errors"
errorsmod "cosmossdk.io/errors"
"cosmossdk.io/math"

"github.com/cosmos/cosmos-sdk/client"
"github.com/cosmos/cosmos-sdk/client/flags"
"github.com/cosmos/cosmos-sdk/client/tx"
cryptotypes "github.com/cosmos/cosmos-sdk/crypto/types"
"github.com/cosmos/cosmos-sdk/server"
sdk "github.com/cosmos/cosmos-sdk/types"
sdkerrors "github.com/cosmos/cosmos-sdk/types/errors"
"github.com/cosmos/cosmos-sdk/version"
stakingcli "github.com/cosmos/cosmos-sdk/x/staking/client/cli"
"github.com/cosmos/cosmos-sdk/x/staking/types"

"github.com/sedaprotocol/seda-chain/app/utils"
customtypes "github.com/sedaprotocol/seda-chain/x/staking/types"
)

Expand Down Expand Up @@ -74,10 +77,6 @@ Where validator.json contains:
"@type":"/cosmos.crypto.ed25519.PubKey",
"key":"oWg2ISpLF405Jcm2vXV+2v4fnjodh6aafuIdeoW+rUw="
},
"vrf_pubkey": {
"type": "tendermint/PubKeySecp256k1",
"value": "At4W/CxKrv8C6HqLFC9ybTPSJgtAkWvF2+Uj4hQLiJcM"
},
"amount": "1000000stake",
"moniker": "myvalidator",
"identity": "optional identity signature (ex. UPort or Keybase)",
Expand All @@ -93,6 +92,7 @@ Where validator.json contains:
where we can get the pubkey using "%s tendermint show-validator"
`, version.AppName, version.AppName)),
RunE: func(cmd *cobra.Command, args []string) error {
serverCtx := server.GetServerContextFromCmd(cmd)
clientCtx, err := client.GetClientTxContext(cmd)
if err != nil {
return err
Expand All @@ -108,6 +108,11 @@ where we can get the pubkey using "%s tendermint show-validator"
return err
}

validator.VRFPubKey, err = utils.InitializeVRFKey(serverCtx.Config)
if err != nil {
return errors.Wrap(err, "failed to initialize VRF key")
}

txf, msg, err := newBuildCreateValidatorWithVRFMsg(clientCtx, txf, cmd.Flags(), validator, ac)
if err != nil {
return err
Expand Down
18 changes: 0 additions & 18 deletions x/staking/client/cli/utils.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,7 @@ import (
errorsmod "cosmossdk.io/errors"
"cosmossdk.io/math"

"github.com/cometbft/cometbft/crypto"
cmtjson "github.com/cometbft/cometbft/libs/json"
"github.com/cosmos/cosmos-sdk/codec"
cryptocodec "github.com/cosmos/cosmos-sdk/crypto/codec"
cryptotypes "github.com/cosmos/cosmos-sdk/crypto/types"
sdk "github.com/cosmos/cosmos-sdk/types"
sdkerrors "github.com/cosmos/cosmos-sdk/types/errors"
Expand Down Expand Up @@ -76,20 +73,6 @@ func parseAndValidateValidatorJSON(cdc codec.Codec, path string) (validator, err
return validator{}, err
}

if v.VRFPubKey == nil {
return validator{}, fmt.Errorf("must specify the JSON encoded VRF pubkey")
}

var cmtVRFPubKey crypto.PubKey
err = cmtjson.Unmarshal(v.VRFPubKey, &cmtVRFPubKey)
if err != nil {
return validator{}, fmt.Errorf("error unmarshalling VRF key %w", err)
}
vrfPk, err := cryptocodec.FromCmtPubKeyInterface(cmtVRFPubKey)
if err != nil {
return validator{}, fmt.Errorf("failed to convert VRF key type from Comet to SDK %w", err)
}

if v.Moniker == "" {
return validator{}, fmt.Errorf("must specify the moniker name")
}
Expand All @@ -110,7 +93,6 @@ func parseAndValidateValidatorJSON(cdc codec.Codec, path string) (validator, err
return validator{
Amount: amount,
PubKey: pk,
VRFPubKey: vrfPk,
Moniker: v.Moniker,
Identity: v.Identity,
Website: v.Website,
Expand Down

0 comments on commit aed9eb6

Please sign in to comment.