From 825274b80646497920a0d24506d233119ed10d53 Mon Sep 17 00:00:00 2001 From: Matija Salopek Date: Sun, 27 Nov 2022 23:13:49 +0100 Subject: [PATCH] wip checkpoint --- tests/integration/actions.go | 117 ++++++++--- tests/integration/config.go | 20 +- tests/integration/state.go | 1 - tests/integration/step_delegation.go | 195 ++++++++---------- tests/integration/steps_start_chains.go | 45 ++-- .../assign-key-instructions.sh | 34 --- .../testnet-scripts/reconfigure-node.sh | 45 ++++ .../testnet-scripts/start-chain.sh | 30 ++- tests/integration/testnet-scripts/test.sh | 8 + x/ccv/provider/keeper/grpc_query.go | 6 +- 10 files changed, 301 insertions(+), 200 deletions(-) delete mode 100644 tests/integration/testnet-scripts/assign-key-instructions.sh create mode 100755 tests/integration/testnet-scripts/reconfigure-node.sh create mode 100755 tests/integration/testnet-scripts/test.sh diff --git a/tests/integration/actions.go b/tests/integration/actions.go index 4f5335e51a..244d19719c 100644 --- a/tests/integration/actions.go +++ b/tests/integration/actions.go @@ -79,6 +79,10 @@ func (tr TestRun) startChain( PrivValidatorKey string `json:"priv_validator_key"` NodeKey string `json:"node_key"` IpSuffix string `json:"ip_suffix"` + + ConsumerMnemonic string `json:"consumer_mnemonic"` + ConsumerPrivValidatorKey string `json:"consumer_priv_validator_key"` + StartWithConsumerKey bool `json:"start_with_consumer_key"` } var validators []jsonValAttrs @@ -91,7 +95,28 @@ func (tr TestRun) startChain( Allocation: fmt.Sprint(val.allocation) + "stake", Stake: fmt.Sprint(val.stake) + "stake", IpSuffix: tr.validatorConfigs[val.id].ipSuffix, + + ConsumerMnemonic: tr.validatorConfigs[val.id].consumerMnemonic, + ConsumerPrivValidatorKey: tr.validatorConfigs[val.id].consumerPrivValidatorKey, + // if true node will be started with consumer key for each consumer chain + StartWithConsumerKey: tr.validatorConfigs[val.id].useConsumerKey, }) + a := jsonValAttrs{ + Mnemonic: tr.validatorConfigs[val.id].mnemonic, + NodeKey: tr.validatorConfigs[val.id].nodeKey, + ValId: fmt.Sprint(val.id), + PrivValidatorKey: tr.validatorConfigs[val.id].privValidatorKey, + Allocation: fmt.Sprint(val.allocation) + "stake", + Stake: fmt.Sprint(val.stake) + "stake", + IpSuffix: tr.validatorConfigs[val.id].ipSuffix, + + ConsumerMnemonic: tr.validatorConfigs[val.id].consumerMnemonic, + ConsumerPrivValidatorKey: tr.validatorConfigs[val.id].consumerPrivValidatorKey, + // if true node will be started with consumer key for each consumer chain + StartWithConsumerKey: tr.validatorConfigs[val.id].useConsumerKey, + } + m, _ := json.MarshalIndent(a, "", " ") + fmt.Println("#### VALIDATOR", val, "\n", string(m)) } vals, err := json.Marshal(validators) @@ -776,21 +801,26 @@ func (tr TestRun) relayRewardPacketsToProvider( } type delegateTokensAction struct { - chain chainID - from validatorID - to validatorID - amount uint + chain chainID + from validatorID + to validatorID + amount uint + useConsumerKey bool } func (tr TestRun) delegateTokens( action delegateTokensAction, verbose bool, ) { + delegateAddr := tr.validatorConfigs[action.to].valoperAddress + if action.chain != chainID("provi") && action.useConsumerKey { + delegateAddr = tr.validatorConfigs[action.to].consumerValoperAddress + } //#nosec G204 -- Bypass linter warning for spawning subprocess with cmd arguments. cmd := exec.Command("docker", "exec", tr.containerConfig.instanceName, tr.chainConfigs[action.chain].binaryName, "tx", "staking", "delegate", - tr.validatorConfigs[action.to].valoperAddress, + delegateAddr, fmt.Sprint(action.amount)+`stake`, `--from`, `validator`+fmt.Sprint(action.from), @@ -812,21 +842,26 @@ func (tr TestRun) delegateTokens( } type unbondTokensAction struct { - chain chainID - sender validatorID - unbondFrom validatorID - amount uint + chain chainID + sender validatorID + unbondFrom validatorID + amount uint + useFromConsumerKey bool } func (tr TestRun) unbondTokens( action unbondTokensAction, verbose bool, ) { + unbondFrom := tr.validatorConfigs[action.unbondFrom].valoperAddress + if action.chain != chainID("provi") && action.useFromConsumerKey { + unbondFrom = tr.validatorConfigs[action.unbondFrom].consumerValoperAddress + } //#nosec G204 -- Bypass linter warning for spawning subprocess with cmd arguments. cmd := exec.Command("docker", "exec", tr.containerConfig.instanceName, tr.chainConfigs[action.chain].binaryName, "tx", "staking", "unbond", - tr.validatorConfigs[action.unbondFrom].valoperAddress, + unbondFrom, fmt.Sprint(action.amount)+`stake`, `--from`, `validator`+fmt.Sprint(action.sender), @@ -849,22 +884,33 @@ func (tr TestRun) unbondTokens( } type redelegateTokensAction struct { - chain chainID - src validatorID - dst validatorID - txSender validatorID - amount uint + chain chainID + src validatorID + dst validatorID + txSender validatorID + amount uint + useSrcConsumerKey bool + useDestConsumerKey bool } func (tr TestRun) redelegateTokens(action redelegateTokensAction, verbose bool) { + redelegateSrc := tr.validatorConfigs[action.src].valoperAddress + if action.chain != chainID("provi") && action.useSrcConsumerKey { + redelegateSrc = tr.validatorConfigs[action.src].consumerValoperAddress + } + + redelegateDst := tr.validatorConfigs[action.dst].valoperAddress + if action.chain != chainID("provi") && action.useDestConsumerKey { + redelegateDst = tr.validatorConfigs[action.dst].consumerValoperAddress + } //#nosec G204 -- Bypass linter warning for spawning subprocess with cmd arguments. cmd := exec.Command("docker", "exec", tr.containerConfig.instanceName, tr.chainConfigs[action.chain].binaryName, "tx", "staking", "redelegate", - tr.validatorConfigs[action.src].valoperAddress, - tr.validatorConfigs[action.dst].valoperAddress, + redelegateSrc, + redelegateDst, fmt.Sprint(action.amount)+`stake`, `--from`, `validator`+fmt.Sprint(action.txSender), `--chain-id`, string(tr.chainConfigs[action.chain].chainId), @@ -1059,18 +1105,39 @@ func (tr TestRun) invokeDoublesignSlash( type assignConsumerPubKeyAction struct { chain chainID validator validatorID - // obtained using: interchain-security-pd keys add --keyring-backend test - // and copying the 'pubkey' field from terminal output - // {"@type":"/cosmos.crypto.secp256k1.PubKey","key":"AyM+CKzFKY+WwYVYmOShkgshJW4pjwqKVlKKxrQ69yhF"} - consumerPubKey string + // reconfigureNode will change keys the node uses and restart + reconfigureNode bool } func (tr TestRun) assignConsumerPubKey(action assignConsumerPubKeyAction, verbose bool) { - bashCommand := fmt.Sprintf( + valCfg := tr.validatorConfigs[action.validator] + + // node was started with provider key + // we swap the nodes's keys for consumer keys and restart it + if action.reconfigureNode { + //#nosec G204 -- Bypass linter warning for spawning subprocess with cmd arguments. + configureNodeCmd := exec.Command("docker", "exec", tr.containerConfig.instanceName, "/bin/bash", + "/testnet-scripts/reconfigure-node.sh", tr.chainConfigs[action.chain].binaryName, + string(action.validator), string(action.chain), + tr.chainConfigs[action.chain].ipPrefix, valCfg.ipSuffix, + valCfg.consumerMnemonic, valCfg.consumerPrivValidatorKey, + ) + fmt.Println("assignConsumerPubKey - reconfigure node cmd:", configureNodeCmd.String()) + if verbose { + fmt.Println("assignConsumerPubKey - reconfigure node cmd:", configureNodeCmd.String()) + } + + bz, err := configureNodeCmd.CombinedOutput() + if err != nil { + log.Fatal(err, "\n", string(bz)) + } + } + + assignKey := fmt.Sprintf( `%s tx provider assign-consensus-key %s '%s' --from validator%s --chain-id %s --home %s --node %s --gas 900000 --keyring-backend test -b block -y`, tr.chainConfigs[chainID("provi")].binaryName, string(tr.chainConfigs[action.chain].chainId), - action.consumerPubKey, + valCfg.consumerValPubKey, action.validator, tr.chainConfigs[chainID("provi")].chainId, tr.getValidatorHome(chainID("provi"), action.validator), @@ -1080,9 +1147,11 @@ func (tr TestRun) assignConsumerPubKey(action assignConsumerPubKeyAction, verbos cmd := exec.Command("docker", "exec", tr.containerConfig.instanceName, "/bin/bash", "-c", - bashCommand, + assignKey, ) + fmt.Println("assignConsumerPubKey cmd:", cmd.String()) + if verbose { fmt.Println("assignConsumerPubKey cmd:", cmd.String()) } diff --git a/tests/integration/config.go b/tests/integration/config.go index fbdcd99554..ba76b23677 100644 --- a/tests/integration/config.go +++ b/tests/integration/config.go @@ -31,6 +31,7 @@ type ValidatorConfig struct { consumerValPubKey string consumerPrivValidatorKey string consumerNodeKey string + useConsumerKey bool // if true the validator node will start with consumer key } // Attributes that are unique to a chain. Allows us to map (part of) @@ -84,15 +85,6 @@ func getDefaultValidators() map[validatorID]ValidatorConfig { privValidatorKey: `{"address":"99BD3A72EF12CD024E7584B3AC900AE3743C6ADF","pub_key":{"type":"tendermint/PubKeyEd25519","value":"mAN6RXYxSM4MNGSIriYiS7pHuwAcOHDQAy9/wnlSzOI="},"priv_key":{"type":"tendermint/PrivKeyEd25519","value":"QePcwfWtOavNK7pBJrtoLMzarHKn6iBWfWPFeyV+IdmYA3pFdjFIzgw0ZIiuJiJLuke7ABw4cNADL3/CeVLM4g=="}}`, nodeKey: `{"priv_key":{"type":"tendermint/PrivKeyEd25519","value":"TQ4vHcO/vKdzGtWpelkX53WdMQd4kTsWGFrdcatdXFvWyO215Rewn5IRP0FszPLWr2DqPzmuH8WvxYGk5aeOXw=="}}`, ipSuffix: "5", - - // consumer chain assigned key - consumerMnemonic: "clip choose cake west range gun slam cry village receive juice galaxy lend ritual range provide ritual can since verify breeze vacant play dragon", - consumerDelAddress: "cosmos1sx6j9g2rh324a342a5f0rnx7me34r9nwgf0mc7", - consumerValoperAddress: "cosmosvaloper1sx6j9g2rh324a342a5f0rnx7me34r9nwdamw5d", - consumerValconsAddress: "cosmosvalcons1kswr5sq599365kcjmhgufevfps9njf43e4lwdk", - consumerValPubKey: `{"@type":"/cosmos.crypto.ed25519.PubKey","key":"Ui5Gf1+mtWUdH8u3xlmzdKID+F3PK0sfXZ73GZ6q6is="}`, - consumerPrivValidatorKey: `{"address":"B41C3A40142963AA5B12DDD1C4E5890C0B3926B1","pub_key":{"type":"tendermint/PubKeyEd25519","value":"Ui5Gf1+mtWUdH8u3xlmzdKID+F3PK0sfXZ73GZ6q6is="},"priv_key":{"type":"tendermint/PrivKeyEd25519","value":"3YaBAZLA+sl/E73lLfbFbG0u6DYm33ayr/0UpCt/vFBSLkZ/X6a1ZR0fy7fGWbN0ogP4Xc8rSx9dnvcZnqrqKw=="}}`, - consumerNodeKey: `{"priv_key":{"type":"tendermint/PrivKeyEd25519","value":"rxBzFedtD3pqgfJQblbxGusKOr47oBfr8ba0Iz14gobtDRZQZlSZ/UGP4pSHkVf+4vtkrkO1vRHBYJobuiP+7A=="}}`, }, validatorID("carol"): { mnemonic: "sight similar better jar bitter laptop solve fashion father jelly scissors chest uniform play unhappy convince silly clump another conduct behave reunion marble animal", @@ -102,6 +94,16 @@ func getDefaultValidators() map[validatorID]ValidatorConfig { privValidatorKey: `{"address":"C888306A908A217B9A943D1DAD8790044D0947A4","pub_key":{"type":"tendermint/PubKeyEd25519","value":"IHo4QEikWZfIKmM0X+N+BjKttz8HOzGs2npyjiba3Xk="},"priv_key":{"type":"tendermint/PrivKeyEd25519","value":"z08bmSB91uFVpVmR3t2ewd/bDjZ/AzwQpe5rKjWiPG0gejhASKRZl8gqYzRf434GMq23Pwc7MazaenKOJtrdeQ=="}}`, nodeKey: `{"priv_key":{"type":"tendermint/PrivKeyEd25519","value":"WLTcHEjbwB24Wp3z5oBSYTvtGQonz/7IQabOFw85BN0UkkyY5HDf38o8oHlFxVI26f+DFVeICuLbe9aXKGnUeg=="}}`, ipSuffix: "6", + + // consumer chain assigned key + consumerMnemonic: "clip choose cake west range gun slam cry village receive juice galaxy lend ritual range provide ritual can since verify breeze vacant play dragon", + consumerDelAddress: "cosmos1sx6j9g2rh324a342a5f0rnx7me34r9nwgf0mc7", + consumerValoperAddress: "cosmosvaloper1sx6j9g2rh324a342a5f0rnx7me34r9nwdamw5d", + consumerValconsAddress: "cosmosvalcons1kswr5sq599365kcjmhgufevfps9njf43e4lwdk", + consumerValPubKey: `{"@type":"/cosmos.crypto.ed25519.PubKey","key":"Ui5Gf1+mtWUdH8u3xlmzdKID+F3PK0sfXZ73GZ6q6is="}`, + consumerPrivValidatorKey: `{"address":"B41C3A40142963AA5B12DDD1C4E5890C0B3926B1","pub_key":{"type":"tendermint/PubKeyEd25519","value":"Ui5Gf1+mtWUdH8u3xlmzdKID+F3PK0sfXZ73GZ6q6is="},"priv_key":{"type":"tendermint/PrivKeyEd25519","value":"3YaBAZLA+sl/E73lLfbFbG0u6DYm33ayr/0UpCt/vFBSLkZ/X6a1ZR0fy7fGWbN0ogP4Xc8rSx9dnvcZnqrqKw=="}}`, + consumerNodeKey: `{"priv_key":{"type":"tendermint/PrivKeyEd25519","value":"rxBzFedtD3pqgfJQblbxGusKOr47oBfr8ba0Iz14gobtDRZQZlSZ/UGP4pSHkVf+4vtkrkO1vRHBYJobuiP+7A=="}}`, + useConsumerKey: true, }, } } diff --git a/tests/integration/state.go b/tests/integration/state.go index c6c0a58b63..e06c89bff5 100644 --- a/tests/integration/state.go +++ b/tests/integration/state.go @@ -523,7 +523,6 @@ func (tr TestRun) getConsumerAddress(consumerChain chainID, validator validatorI `--node`, tr.getQueryNode(chainID("provi")), `-o`, `json`, ) - bz, err := cmd.CombinedOutput() if err != nil { log.Fatal(err, "\n", string(bz)) diff --git a/tests/integration/step_delegation.go b/tests/integration/step_delegation.go index 3986044df8..f05a9884bf 100644 --- a/tests/integration/step_delegation.go +++ b/tests/integration/step_delegation.go @@ -3,111 +3,96 @@ package main // stepsDelegate tests basic delegation and resulting validator power changes func stepsDelegate(consumerName string) []Step { return []Step{ - // { - // action: delegateTokensAction{ - // chain: chainID("provi"), - // from: validatorID("alice"), - // to: validatorID("alice"), - // amount: 11000000, - // }, - // state: State{ - // chainID("provi"): ChainState{ - // ValPowers: &map[validatorID]uint{ - // validatorID("alice"): 511, - // validatorID("bob"): 500, - // validatorID("carol"): 500, - // }, - // }, - // chainID(consumerName): ChainState{ - // ValPowers: &map[validatorID]uint{ - // validatorID("alice"): 500, - // validatorID("bob"): 500, - // validatorID("carol"): 500, - // }, - // }, - // }, - // }, - // { - // action: SendTokensAction{ - // chain: chainID(consumerName), - // from: validatorID("alice"), - // to: validatorID("bob"), - // amount: 1, - // }, - // state: State{ - // chainID(consumerName): ChainState{ - // // Tx should not go through, ICS channel is not setup until first VSC packet has been relayed to consumer - // ValBalances: &map[validatorID]uint{ - // validatorID("alice"): 10000000000, - // validatorID("bob"): 10000000000, - // }, - // }, - // }, - // }, - // { - // action: relayPacketsAction{ - // chain: chainID("provi"), - // port: "provider", - // channel: 0, - // }, - // state: State{ - // chainID(consumerName): ChainState{ - // ValPowers: &map[validatorID]uint{ - // validatorID("alice"): 511, - // validatorID("bob"): 500, - // validatorID("carol"): 500, - // }, - // }, - // }, - // }, - // { - // action: SendTokensAction{ - // chain: chainID(consumerName), - // from: validatorID("alice"), - // to: validatorID("bob"), - // amount: 1, - // }, - // state: State{ - // chainID(consumerName): ChainState{ - // // Now tx should execute - // ValBalances: &map[validatorID]uint{ - // validatorID("alice"): 9999999999, - // validatorID("bob"): 10000000001, - // }, - // }, - // }, - // }, - // { - // action: assignConsumerPubKeyAction{ - // chain: chainID("consu"), - // validator: validatorID("alice"), - // consumerPubKey: `{"@type":"/cosmos.crypto.ed25519.PubKey","key":"GJuUXISPjcWRIbEdzLTtVHzhnt9T98URH/gOA8KB7fA="}`, - // }, - // state: State{ - // chainID("consu"): ChainState{ - // AssignedKeys: &map[validatorID]string{ - // validatorID("alice"): "cosmosvalcons16q4jna57d07rufql8qtzaqhwf3ud3hdf5yt3y2", - // }, - // }, - // }, - // }, - // { - // // NOTE: at present relaying the key change halts the chain - // action: relayPacketsAction{ - // chain: chainID("provi"), - // port: "provider", - // channel: 0, - // }, - // state: State{ - // chainID(consumerName): ChainState{ - // ValPowers: &map[validatorID]uint{ - // validatorID("alice"): 500, - // validatorID("bob"): 500, - // validatorID("carol"): 500, - // }, - // }, - // }, - // }, + { + action: delegateTokensAction{ + chain: chainID("provi"), + from: validatorID("alice"), + to: validatorID("alice"), + amount: 11000000, + }, + state: State{ + chainID("provi"): ChainState{ + ValPowers: &map[validatorID]uint{ + validatorID("alice"): 511, + validatorID("bob"): 500, + validatorID("carol"): 500, + }, + }, + chainID(consumerName): ChainState{ + ValPowers: &map[validatorID]uint{ + validatorID("alice"): 500, + validatorID("bob"): 500, + validatorID("carol"): 500, + }, + }, + }, + }, + { + action: SendTokensAction{ + chain: chainID(consumerName), + from: validatorID("alice"), + to: validatorID("bob"), + amount: 1, + }, + state: State{ + chainID(consumerName): ChainState{ + // Tx should not go through, ICS channel is not setup until first VSC packet has been relayed to consumer + ValBalances: &map[validatorID]uint{ + validatorID("alice"): 10000000000, + validatorID("bob"): 10000000000, + }, + }, + }, + }, + { + action: relayPacketsAction{ + chain: chainID("provi"), + port: "provider", + channel: 0, + }, + state: State{ + chainID(consumerName): ChainState{ + ValPowers: &map[validatorID]uint{ + validatorID("alice"): 511, + validatorID("bob"): 500, + validatorID("carol"): 500, + }, + }, + }, + }, + { + action: SendTokensAction{ + chain: chainID(consumerName), + from: validatorID("alice"), + to: validatorID("bob"), + amount: 1, + }, + state: State{ + chainID(consumerName): ChainState{ + // Now tx should execute + ValBalances: &map[validatorID]uint{ + validatorID("alice"): 9999999999, + validatorID("bob"): 10000000001, + }, + }, + }, + }, + { + action: relayPacketsAction{ + chain: chainID("provi"), + port: "provider", + channel: 0, + }, + state: State{ + chainID(consumerName): ChainState{ + ValPowers: &map[validatorID]uint{ + validatorID("alice"): 500, + validatorID("bob"): 500, + validatorID("carol"): 500, + }, + }, + }, + }, } } diff --git a/tests/integration/steps_start_chains.go b/tests/integration/steps_start_chains.go index 1e8b444b8f..4714ab8fe3 100644 --- a/tests/integration/steps_start_chains.go +++ b/tests/integration/steps_start_chains.go @@ -10,7 +10,7 @@ func stepStartProviderChain() []Step { action: StartChainAction{ chain: chainID("provi"), validators: []StartChainValidator{ - {id: validatorID("bob"), stake: 400000000, allocation: 10000000000}, + {id: validatorID("bob"), stake: 500000000, allocation: 10000000000}, {id: validatorID("alice"), stake: 500000000, allocation: 10000000000}, {id: validatorID("carol"), stake: 500000000, allocation: 10000000000}, }, @@ -19,7 +19,7 @@ func stepStartProviderChain() []Step { chainID("provi"): ChainState{ ValBalances: &map[validatorID]uint{ validatorID("alice"): 9500000000, - validatorID("bob"): 9600000000, + validatorID("bob"): 9500000000, validatorID("carol"): 9500000000, }, }, @@ -43,7 +43,7 @@ func stepsStartConsumerChain(consumerName string, proposalIndex, chainIndex uint chainID("provi"): ChainState{ ValBalances: &map[validatorID]uint{ validatorID("alice"): 9489999999, - validatorID("bob"): 9600000000, + validatorID("bob"): 9500000000, }, Proposals: &map[uint]Proposal{ proposalIndex: ConsumerAdditionProposal{ @@ -77,25 +77,28 @@ func stepsStartConsumerChain(consumerName string, proposalIndex, chainIndex uint }, ValBalances: &map[validatorID]uint{ validatorID("alice"): 9500000000, - validatorID("bob"): 9600000000, + validatorID("bob"): 9500000000, + }, + }, + }, + }, + { + action: assignConsumerPubKeyAction{ + chain: chainID(consumerName), + validator: validatorID("carol"), + // consumer chain has not started + // we don't need to reconfigure the node + // since it will start with consumer key + reconfigureNode: false, + }, + state: State{ + chainID(consumerName): ChainState{ + AssignedKeys: &map[validatorID]string{ + validatorID("carol"): "cosmosvalcons1kswr5sq599365kcjmhgufevfps9njf43e4lwdk", }, }, }, }, - // { - // action: assignConsumerPubKeyAction{ - // chain: chainID("consu"), - // validator: validatorID("bob"), - // consumerPubKey: `{"@type":"/cosmos.crypto.ed25519.PubKey","key":"5ekRfVUhYeWH0Oi6g5wyQARoDlkyU3k6TUYSFV/XZ2M="}`, - // }, - // state: State{ - // chainID("consu"): ChainState{ - // AssignedKeys: &map[validatorID]string{ - // validatorID("bob"): "cosmosvalcons1ht8qrurx6lpngj4pjns6rdhm7mlga0suun8jwk", - // }, - // }, - // }, - // }, { action: startConsumerChainAction{ consumerChain: chainID(consumerName), @@ -104,20 +107,22 @@ func stepsStartConsumerChain(consumerName string, proposalIndex, chainIndex uint validators: []StartChainValidator{ {id: validatorID("carol"), stake: 500000000, allocation: 10000000000}, {id: validatorID("alice"), stake: 500000000, allocation: 10000000000}, - {id: validatorID("bob"), stake: 400000000, allocation: 10000000000}, + {id: validatorID("bob"), stake: 500000000, allocation: 10000000000}, }, }, state: State{ chainID("provi"): ChainState{ ValBalances: &map[validatorID]uint{ validatorID("alice"): 9500000000, - validatorID("bob"): 9600000000, + validatorID("bob"): 9500000000, + validatorID("carol"): 0, }, }, chainID(consumerName): ChainState{ ValBalances: &map[validatorID]uint{ validatorID("alice"): 10000000000, validatorID("bob"): 10000000000, + validatorID("carol"): 0, // expecting carol to have 0 -> using consumer key }, }, }, diff --git a/tests/integration/testnet-scripts/assign-key-instructions.sh b/tests/integration/testnet-scripts/assign-key-instructions.sh deleted file mode 100644 index 0add0f413e..0000000000 --- a/tests/integration/testnet-scripts/assign-key-instructions.sh +++ /dev/null @@ -1,34 +0,0 @@ -1. start integration tests -2. add new key (gaiad keys) -3. create new tendermint key (gaiad init) -4. stop old node --> swap out keys, reset state --> register new key --> restart - -ARGS="--address tcp://7.7.8.5:26655 --rpc.laddr tcp://7.7.8.5:26658 --grpc.address 7.7.8.5:9091 --log_level trace --p2p.laddr tcp://7.7.8.5:26656 --grpc-web.enable=false" - -# kill on CLI - -# swap valstate -echo '{"height": "0","round": 0,"step": 0,"signature":"","signbytes":""}' > /consu/validatorbob/data/priv_validator_state.json - -# swap private key -# echo "$CONSUMER_NODE_KEY" > /$CHAIN_ID/assignvalidator$VAL_ID/config/node_key.json -echo '{"address":"B41C3A40142963AA5B12DDD1C4E5890C0B3926B1","pub_key":{"type":"tendermint/PubKeyEd25519","value":"Ui5Gf1+mtWUdH8u3xlmzdKID+F3PK0sfXZ73GZ6q6is="},"priv_key":{"type":"tendermint/PrivKeyEd25519","value":"3YaBAZLA+sl/E73lLfbFbG0u6DYm33ayr/0UpCt/vFBSLkZ/X6a1ZR0fy7fGWbN0ogP4Xc8rSx9dnvcZnqrqKw=="}}' > /consu/validatorbob/config/priv_validator_key.json - -# add new key from mnemonic -echo "clip choose cake west range gun slam cry village receive juice galaxy lend ritual range provide ritual can since verify breeze vacant play dragon" | interchain-security-pd keys add consumer-bob --keyring-backend test --home /consu/validatorbob --recover --output json - -# assign key on provider -interchain-security-pd tx provider assign-consensus-key consu '{"@type":"/cosmos.crypto.ed25519.PubKey","key":"Ui5Gf1+mtWUdH8u3xlmzdKID+F3PK0sfXZ73GZ6q6is="}' --from validatorbob --home /consu/validatorbob/ --keyring-backend test --node tcp://7.7.7.253:26658 -y --chain-id provi - -# restart node with new key -ip netns exec consu-bob interchain-security-cd --address tcp://7.7.8.5:26655 --rpc.laddr tcp://7.7.8.5:26658 --grpc.address 7.7.8.5:9091 --log_level trace --p2p.laddr tcp://7.7.8.5:26656 --grpc-web.enable=false --home /consu/validatorbob start &> /consu/validatorbob/logs & - -# checks -interchain-security-cd q tendermint-validator-set --node tcp://7.7.8.253:26658 -hermes clear packets --chain provi --port provider --channel channel-0 - -# kill bob -pkill -f /consu/validatorbob diff --git a/tests/integration/testnet-scripts/reconfigure-node.sh b/tests/integration/testnet-scripts/reconfigure-node.sh new file mode 100755 index 0000000000..9dac6501cb --- /dev/null +++ b/tests/integration/testnet-scripts/reconfigure-node.sh @@ -0,0 +1,45 @@ +#!/bin/bash + +## Key assignment of a previosuly active validator is done as follows: +# - stop node +# - replace config/priv_validator_key.json with keys to use on consumer chain +# - replace config/priv_validator_state.json -> node will need to catch up +# - restart node -> it will use the new key to sign blocks +set -eux + + +BIN=$1 +VAL_ID=$2 +CHAIN_ID=$3 +CHAIN_IP_PREFIX=$4 +VAL_IP_SUFFIX=$5 + +CONSUMER_MNEMONIC=$6 +CONSUMER_PRIVATE_KEY=$7 + +# kill validator node +pkill -f /$CHAIN_ID/validator$VAL_ID +echo "=================== DONE KILL ===================" + +# swap valstate -> validator will sync on restart +echo '{"height": "0","round": 0,"step": 0,"signature":"","signbytes":""}' > /$CHAIN_ID/validator$VAL_ID/data/priv_validator_state.json +echo "=================== DONE STATE ===================" + + +# swap private key +# echo "$CONSUMER_NODE_KEY" > /$CHAIN_ID/assignvalidator$VAL_ID/config/node_key.json +echo "$CONSUMER_PRIVATE_KEY" > /$CHAIN_ID/validator$VAL_ID/config/priv_validator_key.json +echo "=================== DONE KEY ===================" + + +# add new key from mnemonic +echo "$CONSUMER_MNEMONIC" | $BIN keys add $CHAIN_ID-validator$VAL_ID --keyring-backend test --home /$CHAIN_ID/validator$VAL_ID --recover --output json +echo "=================== DONE MNEMO ===================" + + +# restart node with new key +ARGS="--address tcp://$CHAIN_IP_PREFIX.$VAL_IP_SUFFIX:26655 --rpc.laddr tcp://$CHAIN_IP_PREFIX.$VAL_IP_SUFFIX:26658 --grpc.address $CHAIN_IP_PREFIX.$VAL_IP_SUFFIX:9091 --log_level trace --p2p.laddr tcp://$CHAIN_IP_PREFIX.$VAL_IP_SUFFIX:26656 --grpc-web.enable=false" +echo "=================== DONE ARGS ===================" + +ip netns exec $CHAIN_ID-$VAL_ID $BIN $ARGS start &> /$CHAIN_ID/validator$VAL_ID/logs & +echo "=================== DONE RECONFIGURE $VAL_ID ===================" diff --git a/tests/integration/testnet-scripts/start-chain.sh b/tests/integration/testnet-scripts/start-chain.sh index b7b16ef512..ca435083f3 100644 --- a/tests/integration/testnet-scripts/start-chain.sh +++ b/tests/integration/testnet-scripts/start-chain.sh @@ -101,14 +101,23 @@ mv /$CHAIN_ID/edited-genesis.json /$CHAIN_ID/genesis.json for i in $(seq 0 $(($NODES - 1))); do VAL_ID=$(echo "$VALIDATORS" | jq -r ".[$i].val_id") - + START_WITH_CONSUMER_KEY=$(echo "$VALIDATORS" | jq -r ".[$i].start_with_consumer_key") # Generate an application key for each validator # Sets up an arbitrary number of validators on a single machine by manipulating # the --home parameter on gaiad - echo "$VALIDATORS" | jq -r ".[$i].mnemonic" | $BIN keys add validator$VAL_ID \ + # optionally start validator with a key different from provider chain key + if [[ "$CHAIN_ID" != "provi" && "$START_WITH_CONSUMER_KEY" = "true" ]]; then + echo "################################################## $CHAIN_ID STARTING VALIDATOR $VAL_ID WITH CONSUMER KEY" + echo "$VALIDATORS" | jq -r ".[$i].consumer_mnemonic" | $BIN keys add validator$VAL_ID \ + --home /$CHAIN_ID/validator$VAL_ID \ + --keyring-backend test \ + --recover > /dev/null + else + echo "$VALIDATORS" | jq -r ".[$i].mnemonic" | $BIN keys add validator$VAL_ID \ --home /$CHAIN_ID/validator$VAL_ID \ --keyring-backend test \ --recover > /dev/null + fi # Give validators their initial token allocations # move the genesis in @@ -131,15 +140,26 @@ done for i in $(seq 0 $(($NODES - 1))); do VAL_ID=$(echo "$VALIDATORS" | jq -r ".[$i].val_id") + # Copy in the genesis.json cp /$CHAIN_ID/genesis.json /$CHAIN_ID/validator$VAL_ID/config/genesis.json # Copy in validator state file echo '{"height": "0","round": 0,"step": 0}' > /$CHAIN_ID/validator$VAL_ID/data/priv_validator_state.json - PRIV_VALIDATOR_KEY=$(echo "$VALIDATORS" | jq -r ".[$i].priv_validator_key") - if [[ "$PRIV_VALIDATOR_KEY" ]]; then - echo "$PRIV_VALIDATOR_KEY" > /$CHAIN_ID/validator$VAL_ID/config/priv_validator_key.json + START_WITH_CONSUMER_KEY=$(echo "$VALIDATORS" | jq -r ".[$i].start_with_consumer_key") + if [[ "$CHAIN_ID" != "provi" && "$START_WITH_CONSUMER_KEY" = "true" ]]; then + echo "################################################## $CHAIN_ID USING CONSUMER KEY FOR $VAL_ID" + # start with assigned consumer key + PRIV_VALIDATOR_KEY=$(echo "$VALIDATORS" | jq -r ".[$i].consumer_priv_validator_key") + if [[ "$PRIV_VALIDATOR_KEY" ]]; then + echo "$PRIV_VALIDATOR_KEY" > /$CHAIN_ID/validator$VAL_ID/config/priv_validator_key.json + fi + else + PRIV_VALIDATOR_KEY=$(echo "$VALIDATORS" | jq -r ".[$i].priv_validator_key") + if [[ "$PRIV_VALIDATOR_KEY" ]]; then + echo "$PRIV_VALIDATOR_KEY" > /$CHAIN_ID/validator$VAL_ID/config/priv_validator_key.json + fi fi NODE_KEY=$(echo "$VALIDATORS" | jq -r ".[$i].node_key") diff --git a/tests/integration/testnet-scripts/test.sh b/tests/integration/testnet-scripts/test.sh new file mode 100755 index 0000000000..2265f7af59 --- /dev/null +++ b/tests/integration/testnet-scripts/test.sh @@ -0,0 +1,8 @@ +#! /bin/bash +ISTRUE=$(echo '{"var":true}' | jq ".var") + +if [ $ISTRUE == "true" ]; then + echo "was matched to bool true" +else + echo "matched someething else" +fi diff --git a/x/ccv/provider/keeper/grpc_query.go b/x/ccv/provider/keeper/grpc_query.go index d7477b7927..35bd6d2e7a 100644 --- a/x/ccv/provider/keeper/grpc_query.go +++ b/x/ccv/provider/keeper/grpc_query.go @@ -91,7 +91,7 @@ func (k Keeper) QueryValidatorConsumerAddr(goCtx context.Context, req *types.Que consumerKey, found := k.GetValidatorConsumerPubKey(ctx, req.ChainId, providerAddr) if !found { - return nil, types.ErrNoValidatorConsumerAddress + return &types.QueryValidatorConsumerAddrResponse{}, nil } return &types.QueryValidatorConsumerAddrResponse{ @@ -117,7 +117,9 @@ func (k Keeper) QueryValidatorProviderAddr(goCtx context.Context, req *types.Que providerAddr, found := k.GetValidatorByConsumerAddr(ctx, req.ChainId, consumerAddr) if !found { - return nil, types.ErrNoValidatorProviderAddress + return &types.QueryValidatorProviderAddrResponse{ + ProviderAddress: providerAddr.String(), + }, nil } return &types.QueryValidatorProviderAddrResponse{