Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: adds orchestrator address to validator in staking module #112

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 0 additions & 1 deletion cosmovisor/go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,6 @@ github.com/otiai10/mint v1.3.1/go.mod h1:/yxELlJQ0ufhjUwhshSj+wFjZ78CnZ48/1wtmBH
github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM=
github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4=
github.com/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME=
github.com/stretchr/testify v1.2.2 h1:bSDNvY7ZPG5RlJ8otE/7V6gMiyenm9RtJ7IUVIAoJ1w=
github.com/stretchr/testify v1.2.2/go.mod h1:a8OnRcib4nhh0OaRAV+Yts87kKdq0PP7pXfy6kDkUVs=
github.com/stretchr/testify v1.6.1 h1:hDPOHmpOpP40lSULcqw7IrRb/u7w6RpDC9399XyoNd0=
github.com/stretchr/testify v1.6.1/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/h/Wwjteg=
Expand Down
6 changes: 6 additions & 0 deletions docs/core/proto-docs.md
Original file line number Diff line number Diff line change
Expand Up @@ -6573,6 +6573,8 @@ multiplied by exchange rate.
| `unbonding_time` | [google.protobuf.Timestamp](#google.protobuf.Timestamp) | | unbonding_time defines, if unbonding, the min time for the validator to complete unbonding. |
| `commission` | [Commission](#cosmos.staking.v1beta1.Commission) | | commission defines the commission parameters. |
| `min_self_delegation` | [string](#string) | | min_self_delegation is the validator's self declared minimum self delegation. |
| `orchestrator` | [string](#string) | | The orchestrator field is a celes1... string (i.e. sdk.AccAddress) that references the key that is being delegated to |
| `eth_address` | [string](#string) | | This is a hex encoded 0x Ethereum public key that will be used by this validator on Ethereum |



Expand Down Expand Up @@ -7198,6 +7200,8 @@ MsgCreateValidator defines a SDK message for creating a new validator.
| `validator_address` | [string](#string) | | |
| `pubkey` | [google.protobuf.Any](#google.protobuf.Any) | | |
| `value` | [cosmos.base.v1beta1.Coin](#cosmos.base.v1beta1.Coin) | | |
| `orchestrator` | [string](#string) | | The orchestrator field is a celes1... string (i.e. sdk.AccAddress) that references the key that is being delegated to |
| `eth_address` | [string](#string) | | This is a hex encoded 0x Ethereum public key that will be used by this validator on Ethereum |



Expand Down Expand Up @@ -7254,6 +7258,8 @@ MsgEditValidator defines a SDK message for editing an existing validator.
| `validator_address` | [string](#string) | | |
| `commission_rate` | [string](#string) | | We pass a reference to the new commission rate and min self delegation as it's not mandatory to update. If not updated, the deserialized rate will be zero with no way to distinguish if an update was intended. REF: #2373 |
| `min_self_delegation` | [string](#string) | | |
| `orchestrator` | [string](#string) | | |
| `eth_address` | [string](#string) | | |



Expand Down
6 changes: 6 additions & 0 deletions proto/cosmos/staking/v1beta1/staking.proto
Original file line number Diff line number Diff line change
Expand Up @@ -117,6 +117,12 @@ message Validator {
(gogoproto.customtype) = "github.com/cosmos/cosmos-sdk/types.Int",
(gogoproto.nullable) = false
];
// The orchestrator field is a celes1... string (i.e. sdk.AccAddress) that
// references the key that is being delegated to
string orchestrator = 12;
// This is a hex encoded 0x Ethereum public key that will be used by this
// validator on Ethereum
string eth_address = 13;
}

// BondStatus is the status of a validator.
Expand Down
8 changes: 8 additions & 0 deletions proto/cosmos/staking/v1beta1/tx.proto
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,12 @@ message MsgCreateValidator {
string validator_address = 5 [(gogoproto.moretags) = "yaml:\"validator_address\""];
google.protobuf.Any pubkey = 6 [(cosmos_proto.accepts_interface) = "cosmos.crypto.PubKey"];
cosmos.base.v1beta1.Coin value = 7 [(gogoproto.nullable) = false];
// The orchestrator field is a celes1... string (i.e. sdk.AccAddress) that
// references the key that is being delegated to
string orchestrator = 8;
// This is a hex encoded 0x Ethereum public key that will be used by this
// validator on Ethereum
string eth_address = 9;
}

// MsgCreateValidatorResponse defines the Msg/CreateValidator response type.
Expand All @@ -73,6 +79,8 @@ message MsgEditValidator {
(gogoproto.customtype) = "github.com/cosmos/cosmos-sdk/types.Int",
(gogoproto.moretags) = "yaml:\"min_self_delegation\""
];
string orchestrator = 5;
string eth_address = 6;
}

// MsgEditValidatorResponse defines the Msg/EditValidator response type.
Expand Down
6 changes: 5 additions & 1 deletion simapp/simd/cmd/testnet.go
Original file line number Diff line number Diff line change
Expand Up @@ -206,14 +206,18 @@ func InitTestnet(
genBalances = append(genBalances, banktypes.Balance{Address: addr.String(), Coins: coins.Sort()})
genAccounts = append(genAccounts, authtypes.NewBaseAccount(addr, nil, 0, 0))

// TODO make these come from the test command
orchAddr, _ := sdk.AccAddressFromBech32("celes1qktu8009djs6uym9uwj84ead24exkezsaqrmn5")
ethAddr, _ := stakingtypes.NewEthAddress("0x91DEd26b5f38B065FC0204c7929Da6b2A21277Cd")

valTokens := sdk.TokensFromConsensusPower(100, sdk.DefaultPowerReduction)
createValMsg, err := stakingtypes.NewMsgCreateValidator(
sdk.ValAddress(addr),
valPubKeys[i],
sdk.NewCoin(sdk.DefaultBondDenom, valTokens),
stakingtypes.NewDescription(nodeDirName, "", "", "", ""),
stakingtypes.NewCommissionRates(sdk.OneDec(), sdk.OneDec(), sdk.OneDec()),
sdk.OneInt(),
sdk.OneInt(), orchAddr, *ethAddr,
)
if err != nil {
return err
Expand Down
5 changes: 4 additions & 1 deletion testutil/network/network.go
Original file line number Diff line number Diff line change
Expand Up @@ -303,13 +303,16 @@ func New(t *testing.T, cfg Config) *Network {
commission, err := sdk.NewDecFromStr("0.5")
require.NoError(t, err)

orchAddr, _ := sdk.AccAddressFromHex("celes1qktu8009djs6uym9uwj84ead24exkezsaqrmn5")
ethAddr, _ := stakingtypes.NewEthAddress("0x91DEd26b5f38B065FC0204c7929Da6b2A21277Cd")

createValMsg, err := stakingtypes.NewMsgCreateValidator(
sdk.ValAddress(addr),
valPubKeys[i],
sdk.NewCoin(cfg.BondDenom, cfg.BondedTokens),
stakingtypes.NewDescription(nodeDirName, "", "", "", ""),
stakingtypes.NewCommissionRates(commission, sdk.OneDec(), sdk.OneDec()),
sdk.OneInt(),
sdk.OneInt(), orchAddr, *ethAddr,
)
require.NoError(t, err)

Expand Down
7 changes: 6 additions & 1 deletion x/genutil/client/cli/gentx.go
Original file line number Diff line number Diff line change
Expand Up @@ -111,7 +111,12 @@ $ %s gentx my-key-name 1000000stake --home=/path/to/home/dir --keyring-backend=o
}

// set flags for creating a gentx
createValCfg, err := cli.PrepareConfigForTxCreateValidator(cmd.Flags(), moniker, nodeID, genDoc.ChainID, valPubKey)
createValCfg, err := cli.PrepareConfigForTxCreateValidator(
cmd.Flags(), moniker,
nodeID, genDoc.ChainID,
valPubKey, cli.FlagOrchestratorAddress,
cli.FlagEthereumAddress,
)
if err != nil {
return errors.Wrap(err, "error creating configuration to create validator msg")
}
Expand Down
10 changes: 8 additions & 2 deletions x/staking/app_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -63,10 +63,16 @@ func TestStakingMsgs(t *testing.T) {
simapp.CheckBalance(t, app, addr1, sdk.Coins{genCoin})
simapp.CheckBalance(t, app, addr2, sdk.Coins{genCoin})

orchAddr, err := sdk.AccAddressFromBech32(testOrchAddr)
require.NoError(t, err)

evmAddr, err := types.NewEthAddress(testEthAddr)
require.NoError(t, err)

// create validator
description := types.NewDescription("foo_moniker", "", "", "", "")
createValidatorMsg, err := types.NewMsgCreateValidator(
sdk.ValAddress(addr1), valKey.PubKey(), bondCoin, description, commissionRates, sdk.OneInt(),
sdk.ValAddress(addr1), valKey.PubKey(), bondCoin, description, commissionRates, sdk.OneInt(), orchAddr, *evmAddr,
)
require.NoError(t, err)

Expand All @@ -89,7 +95,7 @@ func TestStakingMsgs(t *testing.T) {

// edit the validator
description = types.NewDescription("bar_moniker", "", "", "", "")
editValidatorMsg := types.NewMsgEditValidator(sdk.ValAddress(addr1), description, nil, nil)
editValidatorMsg := types.NewMsgEditValidator(sdk.ValAddress(addr1), description, nil, nil, nil, nil)

header = tmproto.Header{Height: app.LastBlockHeight() + 1}
_, _, err = simapp.SignCheckDeliver(t, txGen, app.BaseApp, header, []sdk.Msg{editValidatorMsg}, "", []uint64{0}, []uint64{1}, true, true, priv1)
Expand Down
17 changes: 17 additions & 0 deletions x/staking/client/cli/flags.go
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,9 @@ const (
FlagGenesisFormat = "genesis-format"
FlagNodeID = "node-id"
FlagIP = "ip"

FlagOrchestratorAddress = "orchestrator-address"
FlagEthereumAddress = "ethereum-address"
)

// common flagsets to add to various functions
Expand Down Expand Up @@ -79,6 +82,20 @@ func FlagSetPublicKey() *flag.FlagSet {
return fs
}

// FlagSetOrchestratorAddress Returns the flagset for Orchestrator address related operations.
func FlagSetOrchestratorAddress() *flag.FlagSet {
fs := flag.NewFlagSet("", flag.ContinueOnError)
fs.String(FlagOrchestratorAddress, "", "The Bech32 celes1 address of the orchestrator")
return fs
}

// FlagSetEthereumAddress Returns the flagset for Ethereum address related operations.
func FlagSetEthereumAddress() *flag.FlagSet {
fs := flag.NewFlagSet("", flag.ContinueOnError)
fs.String(FlagEthereumAddress, "", "The 0x EVM address of the orchestrator")
return fs
}

func flagSetDescriptionEdit() *flag.FlagSet {
fs := flag.NewFlagSet("", flag.ContinueOnError)

Expand Down
81 changes: 77 additions & 4 deletions x/staking/client/cli/tx.go
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,8 @@ func NewCreateValidatorCmd() *cobra.Command {
cmd.Flags().AddFlagSet(flagSetDescriptionCreate())
cmd.Flags().AddFlagSet(FlagSetCommissionCreate())
cmd.Flags().AddFlagSet(FlagSetMinSelfDelegation())
cmd.Flags().AddFlagSet(FlagSetEthereumAddress())
cmd.Flags().AddFlagSet(FlagSetOrchestratorAddress())

cmd.Flags().String(FlagIP, "", fmt.Sprintf("The node's public IP. It takes effect only when used in combination with --%s", flags.FlagGenerateOnly))
cmd.Flags().String(FlagNodeID, "", "The node's ID")
Expand All @@ -84,6 +86,8 @@ func NewCreateValidatorCmd() *cobra.Command {
_ = cmd.MarkFlagRequired(FlagAmount)
_ = cmd.MarkFlagRequired(FlagPubKey)
_ = cmd.MarkFlagRequired(FlagMoniker)
_ = cmd.MarkFlagRequired(FlagEthereumAddress)
_ = cmd.MarkFlagRequired(FlagOrchestratorAddress)

return cmd
}
Expand Down Expand Up @@ -129,7 +133,31 @@ func NewEditValidatorCmd() *cobra.Command {
newMinSelfDelegation = &msb
}

msg := types.NewMsgEditValidator(sdk.ValAddress(valAddr), description, newRate, newMinSelfDelegation)
orchAddrString, _ := cmd.Flags().GetString(FlagOrchestratorAddress)
evmAddrString, _ := cmd.Flags().GetString(FlagEthereumAddress)

var orchAddr *sdk.AccAddress
if orchAddrString != "" {
addr, err := sdk.AccAddressFromBech32(orchAddrString)
if err != nil {
return err
}
orchAddr = &addr
}

var evmAddr *types.EthAddress
if evmAddrString != "" {
evmAddr, err = types.NewEthAddress(evmAddrString)
if err != nil {
return err
}
}

msg := types.NewMsgEditValidator(
sdk.ValAddress(valAddr), description,
newRate, newMinSelfDelegation,
orchAddr, evmAddr,
)

return tx.GenerateOrBroadcastTxCLI(clientCtx, cmd.Flags(), msg)
},
Expand Down Expand Up @@ -326,8 +354,24 @@ func newBuildCreateValidatorMsg(clientCtx client.Context, txf tx.Factory, fs *fl
return txf, nil, sdkerrors.Wrap(sdkerrors.ErrInvalidRequest, "minimum self delegation must be a positive integer")
}

orchAddrString, _ := fs.GetString(FlagOrchestratorAddress)
evmAddrString, _ := fs.GetString(FlagEthereumAddress)

orchAddr, err := sdk.AccAddressFromBech32(orchAddrString)
if err != nil {
return txf, nil, err
}

evmAddr, err := types.NewEthAddress(evmAddrString)
if err != nil {
return txf, nil, err
}

msg, err := types.NewMsgCreateValidator(
sdk.ValAddress(valAddr), pk, amount, description, commissionRates, minSelfDelegation,
sdk.ValAddress(valAddr), pk,
amount, description,
commissionRates, minSelfDelegation,
orchAddr, *evmAddr,
)
if err != nil {
return txf, nil, err
Expand Down Expand Up @@ -364,6 +408,8 @@ func CreateValidatorMsgFlagSet(ipDefault string) (fs *flag.FlagSet, defaultsDesc
fsCreateValidator.AddFlagSet(FlagSetMinSelfDelegation())
fsCreateValidator.AddFlagSet(FlagSetAmount())
fsCreateValidator.AddFlagSet(FlagSetPublicKey())
fsCreateValidator.AddFlagSet(FlagSetEthereumAddress())
fsCreateValidator.AddFlagSet(FlagSetOrchestratorAddress())

defaultsDesc = fmt.Sprintf(`
delegation amount: %s
Expand Down Expand Up @@ -397,9 +443,12 @@ type TxCreateValidatorConfig struct {
SecurityContact string
Details string
Identity string

OrchestratorAddress string
EthereumAddress string
}

func PrepareConfigForTxCreateValidator(flagSet *flag.FlagSet, moniker, nodeID, chainID string, valPubKey cryptotypes.PubKey) (TxCreateValidatorConfig, error) {
func PrepareConfigForTxCreateValidator(flagSet *flag.FlagSet, moniker, nodeID, chainID string, valPubKey cryptotypes.PubKey, orchAddr string, ethAddr string) (TxCreateValidatorConfig, error) {
c := TxCreateValidatorConfig{}

ip, err := flagSet.GetString(FlagIP)
Expand Down Expand Up @@ -490,6 +539,16 @@ func PrepareConfigForTxCreateValidator(flagSet *flag.FlagSet, moniker, nodeID, c
c.MinSelfDelegation = defaultMinSelfDelegation
}

c.EthereumAddress, err = flagSet.GetString(FlagEthereumAddress)
if err != nil {
return c, err
}

c.OrchestratorAddress, err = flagSet.GetString(FlagOrchestratorAddress)
if err != nil {
return c, err
}

return c, nil
}

Expand Down Expand Up @@ -529,9 +588,23 @@ func BuildCreateValidatorMsg(clientCtx client.Context, config TxCreateValidatorC
return txBldr, nil, sdkerrors.Wrap(sdkerrors.ErrInvalidRequest, "minimum self delegation must be a positive integer")
}

orchAddr, err := sdk.AccAddressFromBech32(config.OrchestratorAddress)
if err != nil {
return txBldr, nil, err
}

evmAddr, err := types.NewEthAddress(config.EthereumAddress)
if err != nil {
return txBldr, nil, err
}

msg, err := types.NewMsgCreateValidator(
sdk.ValAddress(valAddr), config.PubKey, amount, description, commissionRates, minSelfDelegation,
sdk.ValAddress(valAddr), config.PubKey,
amount, description,
commissionRates, minSelfDelegation,
orchAddr, *evmAddr,
)

if err != nil {
return txBldr, msg, err
}
Expand Down
20 changes: 12 additions & 8 deletions x/staking/client/cli/tx_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,9 @@ func TestPrepareConfigForTxCreateValidator(t *testing.T) {
privKey := ed25519.GenPrivKey()
valPubKey := privKey.PubKey()
moniker := "DefaultMoniker"
mkTxValCfg := func(amount, commission, commissionMax, commissionMaxChange, minSelfDelegation string) TxCreateValidatorConfig {
testOrchAddr := "celes1qktu8009djs6uym9uwj84ead24exkezsaqrmn5"
testEthAddr := "0x91DEd26b5f38B065FC0204c7929Da6b2A21277Cd"
mkTxValCfg := func(amount, commission, commissionMax, commissionMaxChange, minSelfDelegation string, orchAddr string, ethAddr string) TxCreateValidatorConfig {
return TxCreateValidatorConfig{
IP: ip,
ChainID: chainID,
Expand All @@ -29,6 +31,8 @@ func TestPrepareConfigForTxCreateValidator(t *testing.T) {
CommissionMaxRate: commissionMax,
CommissionMaxChangeRate: commissionMaxChange,
MinSelfDelegation: minSelfDelegation,
OrchestratorAddress: orchAddr,
EthereumAddress: ethAddr,
}
}

Expand All @@ -42,38 +46,38 @@ func TestPrepareConfigForTxCreateValidator(t *testing.T) {
fsModify: func(fs *pflag.FlagSet) {
return
},
expectedCfg: mkTxValCfg(defaultAmount, "0.1", "0.2", "0.01", "1"),
expectedCfg: mkTxValCfg(defaultAmount, "0.1", "0.2", "0.01", "1", testOrchAddr, testEthAddr),
}, {
name: "Custom amount",
fsModify: func(fs *pflag.FlagSet) {
fs.Set(FlagAmount, "2000stake")
},
expectedCfg: mkTxValCfg("2000stake", "0.1", "0.2", "0.01", "1"),
expectedCfg: mkTxValCfg("2000stake", "0.1", "0.2", "0.01", "1", testOrchAddr, testEthAddr),
}, {
name: "Custom commission rate",
fsModify: func(fs *pflag.FlagSet) {
fs.Set(FlagCommissionRate, "0.54")
},
expectedCfg: mkTxValCfg(defaultAmount, "0.54", "0.2", "0.01", "1"),
expectedCfg: mkTxValCfg(defaultAmount, "0.54", "0.2", "0.01", "1", testOrchAddr, testEthAddr),
}, {
name: "Custom commission max rate",
fsModify: func(fs *pflag.FlagSet) {
fs.Set(FlagCommissionMaxRate, "0.89")
},
expectedCfg: mkTxValCfg(defaultAmount, "0.1", "0.89", "0.01", "1"),
expectedCfg: mkTxValCfg(defaultAmount, "0.1", "0.89", "0.01", "1", testOrchAddr, testEthAddr),
}, {
name: "Custom commission max change rate",
fsModify: func(fs *pflag.FlagSet) {
fs.Set(FlagCommissionMaxChangeRate, "0.55")
},
expectedCfg: mkTxValCfg(defaultAmount, "0.1", "0.2", "0.55", "1"),
expectedCfg: mkTxValCfg(defaultAmount, "0.1", "0.2", "0.55", "1", testOrchAddr, testEthAddr),
},
{
name: "Custom min self delegations",
fsModify: func(fs *pflag.FlagSet) {
fs.Set(FlagMinSelfDelegation, "0.33")
},
expectedCfg: mkTxValCfg(defaultAmount, "0.1", "0.2", "0.01", "0.33"),
expectedCfg: mkTxValCfg(defaultAmount, "0.1", "0.2", "0.01", "0.33", testOrchAddr, testEthAddr),
},
}

Expand All @@ -85,7 +89,7 @@ func TestPrepareConfigForTxCreateValidator(t *testing.T) {

tc.fsModify(fs)

cvCfg, err := PrepareConfigForTxCreateValidator(fs, moniker, nodeID, chainID, valPubKey)
cvCfg, err := PrepareConfigForTxCreateValidator(fs, moniker, nodeID, chainID, valPubKey, testOrchAddr, testEthAddr)
require.NoError(t, err)

require.Equal(t, tc.expectedCfg, cvCfg)
Expand Down
Loading