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: merge the QGB v0.46.x branch to the default one #276

Merged
merged 12 commits into from
Sep 19, 2022
Merged
Next Next commit
feat!: update edit validator
  • Loading branch information
rach-id committed Aug 4, 2022
commit 0e10ae1a0b39f5756233fb48bf78c2a919fee87d
1,657 changes: 30 additions & 1,627 deletions cosmovisor/go.sum

Large diffs are not rendered by default.

6 changes: 6 additions & 0 deletions proto/cosmos/staking/v1beta1/staking.proto
Original file line number Diff line number Diff line change
Expand Up @@ -124,6 +124,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;
Comment on lines +127 to +132
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

it's not possible to start a chain without these, correct?

if so, we'll need to collect this info from validators before the upgrade and include it in the genesis celestiaorg/celestia-app#608

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

yes, we will need them.

}

// BondStatus is the status of a validator.
Expand Down
10 changes: 9 additions & 1 deletion proto/cosmos/staking/v1beta1/tx.proto
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,12 @@ message MsgCreateValidator {
string validator_address = 5 [(cosmos_proto.scalar) = "cosmos.AddressString"];
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 @@ -85,6 +91,8 @@ message MsgEditValidator {
[(cosmos_proto.scalar) = "cosmos.Dec", (gogoproto.customtype) = "github.com/cosmos/cosmos-sdk/types.Dec"];
string min_self_delegation = 4
[(cosmos_proto.scalar) = "cosmos.Int", (gogoproto.customtype) = "github.com/cosmos/cosmos-sdk/types.Int"];
string orchestrator = 5;
string eth_address = 6;
}

// MsgEditValidatorResponse defines the Msg/EditValidator response type.
Expand Down Expand Up @@ -153,7 +161,7 @@ message MsgCancelUnbondingDelegation{

string delegator_address = 1 [(cosmos_proto.scalar) = "cosmos.AddressString"];
string validator_address = 2 [(cosmos_proto.scalar) = "cosmos.AddressString"];
// amount is always less than or equal to unbonding delegation entry balance
// amount is always less than or equal to unbonding delegation entry balance
cosmos.base.v1beta1.Coin amount = 3 [(gogoproto.nullable) = false];
// creation_height is the height which the unbonding took place.
int64 creation_height = 4;
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 @@ -288,14 +288,18 @@ func initTestnetFiles(
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 @@ -399,13 +399,16 @@ func New(l Logger, baseDir string, cfg Config) (*Network, error) {
return nil, 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,
)
if err != nil {
return nil, 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 @@ -110,7 +110,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 @@ -62,10 +62,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 @@ -88,7 +94,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 @@ -31,6 +31,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 @@ -80,6 +83,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 @@ -78,6 +78,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 @@ -87,6 +89,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 @@ -133,7 +137,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 @@ -384,8 +412,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 @@ -422,6 +466,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 @@ -455,9 +501,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 @@ -548,6 +597,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 @@ -585,9 +644,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,42 +46,42 @@ 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 @@ -89,7 +93,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
3 changes: 3 additions & 0 deletions x/staking/common_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,9 @@ var (
commissionRates = types.NewCommissionRates(sdk.ZeroDec(), sdk.ZeroDec(), sdk.ZeroDec())

PKs = simapp.CreateTestPubKeys(500)

testOrchAddr = "celes1qktu8009djs6uym9uwj84ead24exkezsaqrmn5"
testEthAddr = "0x91DEd26b5f38B065FC0204c7929Da6b2A21277Cd"
)

// getBaseSimappWithCustomKeeper Returns a simapp with custom StakingKeeper
Expand Down
Loading