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: add challenger address and rename bls key of validators #177

Merged
merged 7 commits into from
Apr 13, 2023
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,049 changes: 1,049 additions & 0 deletions api/cosmos/crypto/eth/bls/keys.pulsar.go

Large diffs are not rendered by default.

1,054 changes: 1,054 additions & 0 deletions api/cosmos/crypto/eth/ethsecp256k1/keys.pulsar.go

Large diffs are not rendered by default.

659 changes: 369 additions & 290 deletions api/cosmos/staking/v1beta1/staking.pulsar.go

Large diffs are not rendered by default.

679 changes: 415 additions & 264 deletions api/cosmos/staking/v1beta1/tx.pulsar.go

Large diffs are not rendered by default.

8 changes: 5 additions & 3 deletions proto/cosmos/staking/v1beta1/staking.proto
Original file line number Diff line number Diff line change
Expand Up @@ -137,10 +137,12 @@ message Validator {

// self_del_address defines the address of the validator for self delegation.
string self_del_address = 14 [(cosmos_proto.scalar) = "cosmos.AddressString"];
// relayer_address defines the address of the validator's authorized relayer/operator;.
// relayer_address defines the address of the validator's authorized relayer;.
string relayer_address = 15 [(cosmos_proto.scalar) = "cosmos.AddressString"];
// relayer_bls_key defines the bls pubkey of the validator's authorized relayer/operator;
bytes relayer_bls_key = 16;
// challenger_address defines the address of the validator's authorized challenger;.
string challenger_address = 16 [(cosmos_proto.scalar) = "cosmos.AddressString"];
// bls_key defines the bls pubkey of the validator's authorized relayer/challenger/operator;
bytes bls_key = 17;
}

// BondStatus is the status of a validator.
Expand Down
12 changes: 7 additions & 5 deletions proto/cosmos/staking/v1beta1/tx.proto
Original file line number Diff line number Diff line change
Expand Up @@ -68,9 +68,10 @@ message MsgCreateValidator {
google.protobuf.Any pubkey = 6 [(cosmos_proto.accepts_interface) = "cosmos.crypto.PubKey"];
cosmos.base.v1beta1.Coin value = 7 [(gogoproto.nullable) = false, (amino.dont_omitempty) = true];

string from = 8 [(cosmos_proto.scalar) = "cosmos.AddressString"];
string relayer_address = 9 [(cosmos_proto.scalar) = "cosmos.AddressString"];
string relayer_bls_key = 10;
string from = 8 [(cosmos_proto.scalar) = "cosmos.AddressString"];
string relayer_address = 9 [(cosmos_proto.scalar) = "cosmos.AddressString"];
string challenger_address = 10 [(cosmos_proto.scalar) = "cosmos.AddressString"];
string bls_key = 11;
}

// MsgCreateValidatorResponse defines the Msg/CreateValidator response type.
Expand All @@ -96,8 +97,9 @@ message MsgEditValidator {
string min_self_delegation = 4
[(cosmos_proto.scalar) = "cosmos.Int", (gogoproto.customtype) = "github.com/cosmos/cosmos-sdk/types.Int"];

string relayer_address = 5 [(cosmos_proto.scalar) = "cosmos.AddressString"];
string relayer_bls_key = 6; // The BLS pubkey for the authorized relayer
string relayer_address = 5 [(cosmos_proto.scalar) = "cosmos.AddressString"];
string challenger_address = 6 [(cosmos_proto.scalar) = "cosmos.AddressString"];
string bls_key = 7; // The BLS pubkey for the authorized relayer/challenger
}

// MsgEditValidatorResponse defines the Msg/EditValidator response type.
Expand Down
7 changes: 3 additions & 4 deletions simapp/simd/cmd/testnet.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@ import (
"github.com/spf13/cobra"
"github.com/spf13/pflag"

"cosmossdk.io/math"
"cosmossdk.io/math/unsafe"
"cosmossdk.io/simapp"

Expand Down Expand Up @@ -306,9 +305,9 @@ func initTestnetFiles(
valPubKeys[i],
sdk.NewCoin(sdk.DefaultBondDenom, valTokens),
stakingtypes.NewDescription(nodeDirName, "", "", "", ""),
stakingtypes.NewCommissionRates(math.LegacyOneDec(), math.LegacyOneDec(), math.LegacyOneDec()),
math.OneInt(),
addr, addr, addr, blsPk,
stakingtypes.NewCommissionRates(sdk.OneDec(), sdk.OneDec(), sdk.OneDec()),
sdk.OneInt(),
addr, addr, addr, addr, blsPk,
)
if err != nil {
return err
Expand Down
6 changes: 4 additions & 2 deletions tests/integration/genutil/gentx_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -87,13 +87,15 @@ func initFixture(t assert.TestingT) *fixture {
blsPk1 := hex.EncodeToString(blsSecretKey1.PublicKey().Marshal())

f.msg1, err = stakingtypes.NewMsgCreateValidator(
sdk.ValAddress(pk1.Address()), pk1, amount, desc, comm, one, sdk.AccAddress(pk1.Address()), sdk.AccAddress(pk1.Address()), sdk.AccAddress(pk1.Address()), blsPk1)
sdk.ValAddress(pk1.Address()), pk1, amount, desc, comm, one, sdk.AccAddress(pk1.Address()),
sdk.AccAddress(pk1.Address()), sdk.AccAddress(pk1.Address()), sdk.AccAddress(pk1.Address()), blsPk1)
assert.NilError(t, err)

blsSecretKey2, _ := bls.RandKey()
blsPk2 := hex.EncodeToString(blsSecretKey2.PublicKey().Marshal())
f.msg2, err = stakingtypes.NewMsgCreateValidator(
sdk.ValAddress(pk2.Address()), pk1, amount, desc, comm, one, sdk.AccAddress(pk2.Address()), sdk.AccAddress(pk2.Address()), sdk.AccAddress(pk2.Address()), blsPk2)
sdk.ValAddress(pk2.Address()), pk1, amount, desc, comm, one, sdk.AccAddress(pk2.Address()),
sdk.AccAddress(pk2.Address()), sdk.AccAddress(pk2.Address()), sdk.AccAddress(pk1.Address()), blsPk2)
assert.NilError(t, err)

return f
Expand Down
6 changes: 3 additions & 3 deletions testutil/network/network.go
Original file line number Diff line number Diff line change
Expand Up @@ -526,9 +526,9 @@ func New(l Logger, baseDir string, cfg Config) (*Network, error) {
valPubKeys[i],
sdk.NewCoin(cfg.BondDenom, cfg.BondedTokens),
stakingtypes.NewDescription(nodeDirName, "", "", "", ""),
stakingtypes.NewCommissionRates(commission, sdkmath.LegacyOneDec(), sdkmath.LegacyOneDec()),
sdkmath.OneInt(),
addr, addr, addr, blsPubKey,
stakingtypes.NewCommissionRates(commission, sdk.OneDec(), sdk.OneDec()),
sdk.OneInt(),
addr, addr, addr, addr, blsPubKey,
)
if err != nil {
return nil, err
Expand Down
3 changes: 0 additions & 3 deletions x/bank/simulation/operations_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,6 @@ import (
cmtproto "github.com/cometbft/cometbft/proto/tendermint/types"
"github.com/stretchr/testify/suite"

authzkeeper "github.com/cosmos/cosmos-sdk/x/authz/keeper"

"github.com/cosmos/cosmos-sdk/codec"
"github.com/cosmos/cosmos-sdk/runtime"
"github.com/cosmos/cosmos-sdk/testutil/configurator"
Expand All @@ -34,7 +32,6 @@ type SimTestSuite struct {

ctx sdk.Context
accountKeeper types.AccountKeeper
authzKeeper authzkeeper.Keeper
bankKeeper keeper.Keeper
cdc codec.Codec
app *runtime.App
Expand Down
17 changes: 11 additions & 6 deletions x/genutil/client/cli/gentx.go
Original file line number Diff line number Diff line change
Expand Up @@ -32,9 +32,9 @@ func GenTxCmd(mbm module.BasicManager, txEncCfg client.TxEncodingConfig, genBalI
fsCreateValidator, defaultsDesc := cli.CreateValidatorMsgFlagSet(ipDefault)

cmd := &cobra.Command{
Use: "gentx [key_name] [amount] [validator] [relayer] [relayer_blskey]",
Use: "gentx [key_name] [amount] [validator] [relayer] [challenger] [blskey]",
Short: "Generate a genesis tx carrying a self delegation",
Args: cobra.ExactArgs(5),
Args: cobra.ExactArgs(6),
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 Bech32 consensus
pubkey may optionally be provided. If they are omitted, they will be retrieved from the priv_validator.json
Expand Down Expand Up @@ -155,23 +155,28 @@ $ %s gentx my-key-name 1000000stake \
// ref: https://github.com/cosmos/cosmos-sdk/issues/8177
createValCfg.Amount = amount

validator, err := sdk.ValAddressFromHex(args[2])
validator, err := sdk.AccAddressFromHexUnsafe(args[2])
if err != nil {
return err
}
relayer, err := sdk.AccAddressFromHexUnsafe(args[3])
if err != nil {
return err
}
blsPk := args[4]
challenger, err := sdk.AccAddressFromHexUnsafe(args[4])
if err != nil {
return err
}
blsPk := args[5]
if len(blsPk) != 2*sdk.BLSPubKeyLength {
return fmt.Errorf("invalid relayer bls pubkey")
return fmt.Errorf("invalid bls pubkey")
}

createValCfg.Validator = validator
createValCfg.Delegator = addr
createValCfg.Relayer = relayer
createValCfg.RelayerBlsKey = blsPk
createValCfg.Challenger = challenger
createValCfg.BlsKey = blsPk

// create a 'create-validator' message
txBldr, msg, err := cli.BuildCreateValidatorMsg(clientCtx, createValCfg, txFactory, true)
Expand Down
6 changes: 4 additions & 2 deletions x/genutil/gentx_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -71,12 +71,14 @@ func (suite *GenTxTestSuite) SetupTest() {
suite.msg1, err = stakingtypes.NewMsgCreateValidator(
sdk.ValAddress(pk1.Address()), pk1,
amount, desc, comm, one,
sdk.AccAddress(pk1.Address()), sdk.AccAddress(pk1.Address()), sdk.AccAddress(pk1.Address()), blsPk)
sdk.AccAddress(pk1.Address()), sdk.AccAddress(pk1.Address()),
sdk.AccAddress(pk1.Address()), sdk.AccAddress(pk1.Address()), blsPk)
suite.NoError(err)
suite.msg2, err = stakingtypes.NewMsgCreateValidator(
sdk.ValAddress(pk2.Address()), pk1,
amount, desc, comm, one,
sdk.AccAddress(pk2.Address()), sdk.AccAddress(pk2.Address()), sdk.AccAddress(pk2.Address()), blsPk)
sdk.AccAddress(pk2.Address()), sdk.AccAddress(pk2.Address()),
sdk.AccAddress(pk2.Address()), sdk.AccAddress(pk1.Address()), blsPk)
suite.NoError(err)
}

Expand Down
14 changes: 8 additions & 6 deletions x/genutil/types/genesis_state_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -46,17 +46,17 @@ func TestValidateGenesisMultipleMessages(t *testing.T) {
msg1, err := stakingtypes.NewMsgCreateValidator(
sdk.ValAddress(pk1.Address()), pk1,
sdk.NewInt64Coin(sdk.DefaultBondDenom, 50), desc, comm, sdk.OneInt(),
sdk.AccAddress(pk1.Address()), sdk.AccAddress(pk1.Address()), sdk.AccAddress(pk1.Address()), blsPk1)

sdk.AccAddress(pk1.Address()), sdk.AccAddress(pk1.Address()),
sdk.AccAddress(pk1.Address()), sdk.AccAddress(pk1.Address()), blsPk1)
require.NoError(t, err)

blsSecretKey2, _ := bls.RandKey()
blsPk2 := hex.EncodeToString(blsSecretKey2.PublicKey().Marshal())
msg2, err := stakingtypes.NewMsgCreateValidator(
sdk.ValAddress(pk2.Address()), pk2,
sdk.NewInt64Coin(sdk.DefaultBondDenom, 50), desc, comm, sdk.OneInt(),
sdk.AccAddress(pk2.Address()), sdk.AccAddress(pk2.Address()), sdk.AccAddress(pk2.Address()), blsPk2)

sdk.AccAddress(pk2.Address()), sdk.AccAddress(pk2.Address()),
sdk.AccAddress(pk2.Address()), sdk.AccAddress(pk2.Address()), blsPk2)
require.NoError(t, err)

txConfig := moduletestutil.MakeTestEncodingConfig(staking.AppModuleBasic{}, genutil.AppModuleBasic{}).TxConfig
Expand All @@ -72,11 +72,13 @@ func TestValidateGenesisMultipleMessages(t *testing.T) {

func TestValidateGenesisBadMessage(t *testing.T) {
desc := stakingtypes.NewDescription("testname", "", "", "", "")

blsSecretKey1, _ := bls.RandKey()
blsPk1 := hex.EncodeToString(blsSecretKey1.PublicKey().Marshal())

msg1 := stakingtypes.NewMsgEditValidator(sdk.ValAddress(pk1.Address()), desc, nil, nil, sdk.AccAddress(pk1.Address()), blsPk1)
msg1 := stakingtypes.NewMsgEditValidator(
sdk.ValAddress(pk1.Address()), desc, nil, nil,
sdk.AccAddress(pk1.Address()), sdk.AccAddress(pk1.Address()), blsPk1,
)

txConfig := moduletestutil.MakeTestEncodingConfig(staking.AppModuleBasic{}, genutil.AppModuleBasic{}).TxConfig
txBuilder := txConfig.NewTxBuilder()
Expand Down
6 changes: 3 additions & 3 deletions x/gov/abci_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -669,9 +669,9 @@ func createValidators(t *testing.T, stakingMsgSvr stakingtypes.MsgServer, ctx sd
blsPk := hex.EncodeToString(blsSecretKey.PublicKey().Marshal())
valCreateMsg, err := stakingtypes.NewMsgCreateValidator(
addrs[i], pubkeys[i], sdk.NewCoin(sdk.DefaultBondDenom, valTokens),
TestDescription, TestCommissionRates, math.OneInt(),
sdk.AccAddress(addrs[i]), sdk.AccAddress(addrs[i]), sdk.AccAddress(addrs[i]), blsPk,
)
TestDescription, TestCommissionRates, sdk.OneInt(),
sdk.AccAddress(addrs[i]), sdk.AccAddress(addrs[i]),
sdk.AccAddress(addrs[i]), sdk.AccAddress(addrs[i]), blsPk)
require.NoError(t, err)
res, err := stakingMsgSvr.CreateValidator(ctx, valCreateMsg)
require.NoError(t, err)
Expand Down
6 changes: 3 additions & 3 deletions x/oracle/keeper/keeper.go
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,7 @@ func (k Keeper) IsRelayerValid(ctx sdk.Context, relayer sdk.AccAddress, validato
return false, err
}

if bytes.Equal(inturnRelayerBlsKey, vldr.RelayerBlsKey) {
if bytes.Equal(inturnRelayerBlsKey, vldr.BlsKey) {
return true, nil
}

Expand Down Expand Up @@ -153,7 +153,7 @@ func (k Keeper) CheckClaim(ctx sdk.Context, claim *types.MsgClaim) (sdk.AccAddre

signedRelayers = append(signedRelayers, sdk.MustAccAddressFromHex(val.RelayerAddress))

votePubKey, err := bls.PublicKeyFromBytes(val.RelayerBlsKey)
votePubKey, err := bls.PublicKeyFromBytes(val.BlsKey)
if err != nil {
return sdk.AccAddress{}, nil, sdkerrors.Wrapf(types.ErrBlsPubKey, "BLS public key converts failed: %v", err)
}
Expand Down Expand Up @@ -213,7 +213,7 @@ func (k Keeper) getInturnRelayer(ctx sdk.Context, relayerInterval uint64) ([]byt

inturnRelayer := validators[inTurnRelayerIndex]

return inturnRelayer.RelayerBlsKey, &types.RelayInterval{
return inturnRelayer.BlsKey, &types.RelayInterval{
Start: start,
End: end,
}, nil
Expand Down
8 changes: 4 additions & 4 deletions x/oracle/keeper/keeper_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -169,7 +169,7 @@ func (s *TestSuite) TestKeeper_IsRelayerValid() {

val := newValidator(s.T(), sdk.AccAddress(pk.Address()), pk)
privKey, _ := blst.RandKey()
val.RelayerBlsKey = privKey.PublicKey().Marshal()
val.BlsKey = privKey.PublicKey().Marshal()
vals[i] = val
}

Expand Down Expand Up @@ -286,13 +286,13 @@ func createValidators(t *testing.T) ([]stakingtypes.Validator, []bls.SecretKey)
blsKeys := []bls.SecretKey{privKey1, privKey2, privKey3}

val1 := newValidator(t, sdk.AccAddress(valAddrs[0]), pks[0])
val1.RelayerBlsKey = privKey1.PublicKey().Marshal()
val1.BlsKey = privKey1.PublicKey().Marshal()

val2 := newValidator(t, sdk.AccAddress(valAddrs[1]), pks[1])
val2.RelayerBlsKey = privKey2.PublicKey().Marshal()
val2.BlsKey = privKey2.PublicKey().Marshal()

val3 := newValidator(t, sdk.AccAddress(valAddrs[2]), pks[2])
val3.RelayerBlsKey = privKey3.PublicKey().Marshal()
val3.BlsKey = privKey3.PublicKey().Marshal()

vals := []stakingtypes.Validator{val1, val2, val3}

Expand Down
5 changes: 3 additions & 2 deletions x/slashing/app_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -80,8 +80,9 @@ func TestSlashingMsgs(t *testing.T) {
blsPk := hex.EncodeToString(blsSecretKey.PublicKey().Marshal())

createValidatorMsg, err := stakingtypes.NewMsgCreateValidator(
sdk.ValAddress(addr1), valKey.PubKey(), bondCoin, description, commission, math.OneInt(),
sdk.AccAddress(addr1), sdk.AccAddress(addr1), sdk.AccAddress(addr1), blsPk,
sdk.ValAddress(addr1), valKey.PubKey(),
bondCoin, description, commission, sdk.OneInt(),
addr1, addr1, addr1, addr1, blsPk,
)
require.NoError(t, err)

Expand Down
4 changes: 2 additions & 2 deletions x/staking/app_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ func TestStakingMsgs(t *testing.T) {
createValidatorMsg, err := types.NewMsgCreateValidator(
sdk.ValAddress(addr1), valKey.PubKey(),
bondCoin, description, commissionRates, sdk.OneInt(),
addr1, addr1, addr1, blsPubKey,
addr1, addr1, addr1, addr1, blsPubKey,
)
require.NoError(t, err)

Expand All @@ -99,7 +99,7 @@ func TestStakingMsgs(t *testing.T) {
description = types.NewDescription("bar_moniker", "", "", "", "")
editValidatorMsg := types.NewMsgEditValidator(
sdk.ValAddress(addr1), description, nil, nil,
sdk.AccAddress(""), "",
sdk.AccAddress(""), sdk.AccAddress(""), "",
)
header = cmtproto.Header{Height: app.LastBlockHeight() + 1}
_, _, err = simtestutil.SignCheckDeliver(t, txConfig, app.BaseApp, header, []sdk.Msg{editValidatorMsg}, "", []uint64{0}, []uint64{1}, true, true, []cryptotypes.PrivKey{priv1})
Expand Down
18 changes: 13 additions & 5 deletions x/staking/client/cli/flags.go
Original file line number Diff line number Diff line change
Expand Up @@ -33,8 +33,9 @@ const (
FlagIP = "ip"
FlagP2PPort = "p2p-port"

FlagAddressRelayer = "addr-relayer"
FlagBlsKeyRelayer = "bls-key-relayer"
FlagAddressRelayer = "addr-relayer"
FlagAddressChallenger = "addr-challenger"
FlagBlsKey = "bls-key"
)

// common flagsets to add to various functions
Expand Down Expand Up @@ -91,10 +92,17 @@ func FlagSetRelayerAddress() *flag.FlagSet {
return fs
}

// FlagSetRelayerBlsKey Returns the flagset for relayer bls pubkey related operations.
func FlagSetRelayerBlsKey() *flag.FlagSet {
// FlagSetBlsKey Returns the flagset for bls pubkey related operations.
func FlagSetBlsKey() *flag.FlagSet {
fs := flag.NewFlagSet("", flag.ContinueOnError)
fs.String(FlagBlsKeyRelayer, "", "The relayer bls pubkey of the validator")
fs.String(FlagBlsKey, "", "The bls pubkey of the validator")
return fs
}

// FlagSetChallengerAddress Returns the flagset for challenger address related operations.
func FlagSetChallengerAddress() *flag.FlagSet {
fs := flag.NewFlagSet("", flag.ContinueOnError)
fs.String(FlagAddressChallenger, "", "The challenger address of the validator")
return fs
}

Expand Down
Loading