Skip to content

Commit

Permalink
Validator improvements (#4)
Browse files Browse the repository at this point in the history
* scaffolded ProposeDisableValidator
and ApproveDisableValidator types

* updated cli commands

* added ProposedDisableValidator

* scaffolded DisabledValidator

* corrected REST endpoints

* improved NotFound error processing

* msg_server updated

* refactoring

* linted

* query commands improved

* tests updated

* disable validator msg added

* msg_server updated

* scaffolded EnableValidator

* tx's improved

* msg_server updated

* compilation errors and test errors fixed

* handler tests updated

* scripts fixed

* ProposedDisableValidator and DisabledValidator

* bugs fixed

* linted

* validations for validator msgs added

* message validations updated

* tests updated

* validations added

* docs updated

* grant added

* Grant support added

* Jailing added

* updated query

* roles refactoring

* messages enable/disable validator updated

* validator message ValidateBasic updated

* bug fixed

* added more checks

* tests updated

* msg_server updated

* tests updated

* msg_server updated

* handler_test updated

* validation added

* redundant code removed

* added integration test

* integration tests for validators added

* added validator tests

* fixed address convertation

* cli commands updated

* integration tests added

* docs updated

* validator cli integration tests updated
  • Loading branch information
abdulla-ashurov committed Apr 4, 2022
1 parent eed7a7a commit 58e4c3f
Show file tree
Hide file tree
Showing 75 changed files with 9,116 additions and 414 deletions.
44 changes: 18 additions & 26 deletions docs/transactions.md
Expand Up @@ -1247,64 +1247,56 @@ Updates the Validator node by the owner.
- Who can send:
- NodeAdmin; owner

#### REMOVE_VALIDATOR_NODE
#### DISABLE_VALIDATOR_NODE

**Status: Not Implemented**
**Status: Implemented**

Deletes the Validator node (removes from the validator set) by the owner.
Disables the Validator node (removes from the validator set) by the owner.

- Parameters:
- address: `string` - Bech32 encoded validator address or owner account
- Who can send:
- NodeAdmin; owner

#### PROPOSE_REMOVE_VALIDATOR_NODE
#### PROPOSE_DISABLE_VALIDATOR_NODE

**Status: Not Implemented**
**Status: Implemented**

Proposes removing the Validator node from the validator set by a Trustee.
Proposes disabling of the Validator node from the validator set by a Trustee.

If more than 1 Trustee signature is required to remove a node, the removal
If more than 1 Trustee signature is required to disable a node, the disable
will be in a pending state until sufficient number of approvals is received.

- Parameters:
- address: `string` - Bech32 encoded validator address or owner account
- info: `optional(string)` - information/notes for the proposal
- Who can send:
- Trustee

#### APPROVE_REMOVE_VALIDATOR_NODE
#### APPROVE_DISABLE_VALIDATOR_NODE

**Status: Not Implemented**
**Status: Implemented**

Approves removing of the Validator node by a Trustee.
Approves disabling of the Validator node by a Trustee.

The account is not removed until sufficient number of Trustees approve it.
The validator node is not disabled until sufficient number of Trustees approve it.

- Parameters:
- address: `string` - Bech32 encoded validator address or owner account
- info: `optional(string)` - information/notes for the approval
- Who can send:
- Trustee
- Number of required approvals:
- 2/3 of Trustees

#### UNJAIL_VALIDATOR_NODE
#### ENABLE_VALIDATOR_NODE

**Status: Not Implemented**

Approves unjail of the Validator node from jailed state and returning to the active validator state.
**Status: Implemented**

If more than 1 Trustee approval is required to unjail a node, the node still
will be in a jailed state until sufficient number of approvals is received.
Enables the Validator node (returns to the validator set) by the owner.

If 1 Trustee approval is required to unjail a nod or sufficient number of approvals is received,
the node will be unjailed and returned to the active validator set.
the node will be enabled and returned to the active validator set.

- Parameters:
- address: `string` - Bech32 encoded validator address or owner account
- Who can send:
- Trustee
- Number of required approvals:
- 2/3 of Trustees
- NodeAdmin; owner

## UPGRADE

Expand Down
5 changes: 3 additions & 2 deletions go.mod
Expand Up @@ -23,8 +23,9 @@ require (
github.com/tendermint/spm v0.1.9
github.com/tendermint/tendermint v0.34.14
github.com/tendermint/tm-db v0.6.4
google.golang.org/genproto v0.0.0-20220118154757-00ab72f36ad5
google.golang.org/grpc v1.43.0
golang.org/x/net v0.0.0-20220127200216-cd36cc0744dd // indirect
google.golang.org/genproto v0.0.0-20220302033224-9aa15565e42a
google.golang.org/grpc v1.44.0
google.golang.org/protobuf v1.27.1
sigs.k8s.io/yaml v1.3.0
)
Expand Down
16 changes: 10 additions & 6 deletions go.sum
Expand Up @@ -1199,8 +1199,9 @@ golang.org/x/net v0.0.0-20210316092652-d523dce5a7f4/go.mod h1:RBQZq4jEuRlivfhVLd
golang.org/x/net v0.0.0-20210405180319-a5a99cb37ef4/go.mod h1:p54w0d4576C0XHj96bSt6lcn1PtDYWL6XObtHCRCNQM=
golang.org/x/net v0.0.0-20210428140749-89ef3d95e781/go.mod h1:OJAsFXCWl8Ukc7SiCT/9KSuxbyM7479/AVlXFRxuMCk=
golang.org/x/net v0.0.0-20210525063256-abc453219eb5/go.mod h1:9nx3DQGgdP8bBQD5qxJ1jj9UTztislL4KSBs9R2vV5Y=
golang.org/x/net v0.0.0-20210903162142-ad29c8ab022f h1:w6wWR0H+nyVpbSAQbzVEIACVyr/h8l/BEkY6Sokc7Eg=
golang.org/x/net v0.0.0-20210903162142-ad29c8ab022f/go.mod h1:9nx3DQGgdP8bBQD5qxJ1jj9UTztislL4KSBs9R2vV5Y=
golang.org/x/net v0.0.0-20220127200216-cd36cc0744dd h1:O7DYs+zxREGLKzKoMQrtrEacpb0ZVXA5rIwylE2Xchk=
golang.org/x/net v0.0.0-20220127200216-cd36cc0744dd/go.mod h1:CfG3xpIq0wQ8r1q4Su4UZFWDARRcnwPjda9FqA0JpMk=
golang.org/x/oauth2 v0.0.0-20180821212333-d2e6202438be/go.mod h1:N/0e6XlmueqKjAGxoOufVs8QHGRruUQn6yWY3a++T0U=
golang.org/x/oauth2 v0.0.0-20190226205417-e64efc72b421/go.mod h1:gOpvHmFTYa4IltrdGE7lF6nIHvwfUNPOp7c8zoXwtLw=
golang.org/x/oauth2 v0.0.0-20190604053449-0f29369cfe45/go.mod h1:gOpvHmFTYa4IltrdGE7lF6nIHvwfUNPOp7c8zoXwtLw=
Expand Down Expand Up @@ -1307,20 +1308,23 @@ golang.org/x/sys v0.0.0-20210615035016-665e8c7367d1/go.mod h1:oPkhp1MJrh7nUepCBc
golang.org/x/sys v0.0.0-20210616094352-59db8d763f22/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
golang.org/x/sys v0.0.0-20210630005230-0f9fa26af87c/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
golang.org/x/sys v0.0.0-20210806184541-e5e7981a1069/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
golang.org/x/sys v0.0.0-20210903071746-97244b99971b h1:3Dq0eVHn0uaQJmPO+/aYPI/fRMqdrVDbu7MQcku54gg=
golang.org/x/sys v0.0.0-20210903071746-97244b99971b/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
golang.org/x/sys v0.0.0-20211216021012-1d35b9e2eb4e h1:fLOSk5Q00efkSvAm+4xcoXD+RRmLmmulPn5I3Y9F2EM=
golang.org/x/sys v0.0.0-20211216021012-1d35b9e2eb4e/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
golang.org/x/term v0.0.0-20201117132131-f5c789dd3221/go.mod h1:Nr5EML6q2oocZ2LXRh80K7BxOlk5/8JxuGnuhpl+muw=
golang.org/x/term v0.0.0-20201126162022-7de9c90e9dd1 h1:v+OssWQX+hTHEmOBgwxdZxK4zHq3yOs8F9J7mk0PY8E=
golang.org/x/term v0.0.0-20201126162022-7de9c90e9dd1/go.mod h1:bj7SfCRtBDWHUb9snDiAeCFNEtKQo2Wmx5Cou7ajbmo=
golang.org/x/term v0.0.0-20210927222741-03fcf44c2211 h1:JGgROgKl9N8DuW20oFS5gxc+lE67/N3FcwmBPMe7ArY=
golang.org/x/term v0.0.0-20210927222741-03fcf44c2211/go.mod h1:jbD1KX2456YbFQfuXm/mYQcufACuNUgVhRMnK/tPxf8=
golang.org/x/text v0.0.0-20170915032832-14c0d48ead0c/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ=
golang.org/x/text v0.3.0/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ=
golang.org/x/text v0.3.1-0.20180807135948-17ff2d5776d2/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ=
golang.org/x/text v0.3.2/go.mod h1:bEr9sfX3Q8Zfm5fL9x+3itogRgK3+ptLWKqgva+5dAk=
golang.org/x/text v0.3.3/go.mod h1:5Zoc/QRtKVWzQhOtBMvqHzDpF6irO9z98xDceosuGiQ=
golang.org/x/text v0.3.4/go.mod h1:5Zoc/QRtKVWzQhOtBMvqHzDpF6irO9z98xDceosuGiQ=
golang.org/x/text v0.3.5/go.mod h1:5Zoc/QRtKVWzQhOtBMvqHzDpF6irO9z98xDceosuGiQ=
golang.org/x/text v0.3.6 h1:aRYxNxv6iGQlyVaZmk6ZgYEDa+Jg18DxebPSrd6bg1M=
golang.org/x/text v0.3.6/go.mod h1:5Zoc/QRtKVWzQhOtBMvqHzDpF6irO9z98xDceosuGiQ=
golang.org/x/text v0.3.7 h1:olpwvP2KacW1ZWvsR7uQhoyTYvKAupfQrRGBFM352Gk=
golang.org/x/text v0.3.7/go.mod h1:u+2+/6zg+i71rQMx5EYifcz6MCKuco9NR6JIITiCfzQ=
golang.org/x/time v0.0.0-20180412165947-fbb02b2291d2/go.mod h1:tRJNPiyCQ0inRvYxbN9jk5I+vvW/OXSQhTDSoE431IQ=
golang.org/x/time v0.0.0-20181108054448-85acf8d2951c/go.mod h1:tRJNPiyCQ0inRvYxbN9jk5I+vvW/OXSQhTDSoE431IQ=
golang.org/x/time v0.0.0-20190308202827-9d24e82272b4/go.mod h1:tRJNPiyCQ0inRvYxbN9jk5I+vvW/OXSQhTDSoE431IQ=
Expand Down Expand Up @@ -1513,8 +1517,8 @@ google.golang.org/genproto v0.0.0-20210319143718-93e7006c17a6/go.mod h1:FWY/as6D
google.golang.org/genproto v0.0.0-20210402141018-6c239bbf2bb1/go.mod h1:9lPAdzaEmUacj36I+k7YKbEc5CXzPIeORRgDAUOu28A=
google.golang.org/genproto v0.0.0-20210602131652-f16073e35f0c/go.mod h1:UODoCrxHCcBojKKwX1terBiRUaqAsFqJiF615XL43r0=
google.golang.org/genproto v0.0.0-20210828152312-66f60bf46e71/go.mod h1:eFjDcFEctNawg4eG61bRv87N7iHBWyVhJu7u1kqDUXY=
google.golang.org/genproto v0.0.0-20220118154757-00ab72f36ad5 h1:zzNejm+EgrbLfDZ6lu9Uud2IVvHySPl8vQzf04laR5Q=
google.golang.org/genproto v0.0.0-20220118154757-00ab72f36ad5/go.mod h1:5CzLGKJ67TSI2B9POpiiyGha0AjJvZIUgRMt1dSmuhc=
google.golang.org/genproto v0.0.0-20220302033224-9aa15565e42a h1:uqouglH745GoGeZ1YFZbPBiu961tgi/9Qm5jaorajjQ=
google.golang.org/genproto v0.0.0-20220302033224-9aa15565e42a/go.mod h1:kGP+zUP2Ddo0ayMi4YuN7C3WZyJvGLZRh8Z5wnAqvEI=
google.golang.org/grpc v1.33.2 h1:EQyQC3sa8M+p6Ulc8yy9SWSS2GVwyRc83gAbG8lrl4o=
google.golang.org/grpc v1.33.2/go.mod h1:JMHMWHQWaTccqQQlmk3MJZS+GWXOdAesneDmEnv2fbc=
google.golang.org/protobuf v0.0.0-20200109180630-ec00e32a8dfd/go.mod h1:DFci5gLYBciE7Vtevhsrf46CRTquxDuWsQurQQe4oz8=
Expand Down
12 changes: 6 additions & 6 deletions integration_tests/cli/common.sh
Expand Up @@ -137,16 +137,16 @@ create_new_vendor_account(){
local _vid="$2"

echo $passphrase | dcld keys add "$_name"
address=$(echo $passphrase | dcld keys show $_name -a)
pubkey=$(echo $passphrase | dcld keys show $_name -p)
_address=$(echo $passphrase | dcld keys show $_name -a)
_pubkey=$(echo $passphrase | dcld keys show $_name -p)

echo "Jack proposes account for \"$_name\" with Vendor role"
result=$(echo $passphrase | dcld tx auth propose-add-account --address="$address" --pubkey="$pubkey" --roles=Vendor --vid=$_vid --from jack --yes)
check_response "$result" "\"code\": 0"
_result=$(echo $passphrase | dcld tx auth propose-add-account --address="$_address" --pubkey="$_pubkey" --roles=Vendor --vid=$_vid --from jack --yes)
check_response "$_result" "\"code\": 0"

echo "Alice approves account for \"$_name\" with Vendor role"
result=$(echo $passphrase | dcld tx auth approve-add-account --address="$address" --from alice --yes)
check_response "$result" "\"code\": 0"
_result=$(echo $passphrase | dcld tx auth approve-add-account --address="$_address" --from alice --yes)
check_response "$_result" "\"code\": 0"

}

Expand Down
115 changes: 114 additions & 1 deletion integration_tests/cli/validator-demo.sh
Expand Up @@ -83,12 +83,14 @@ docker exec $container /bin/sh -c "$cmd"

address="$(docker exec $container /bin/sh -c "echo $passphrase | ./dcld keys show $account -a")"
pubkey="$(docker exec $container /bin/sh -c "echo $passphrase | ./dcld keys show $account -p")"
alice_address="$(dcld keys show alice -a)"
bob_address="$(dcld keys show bob -a)"
echo "Create account for $account and Assign NodeAdmin role"
echo $passphrase | dcld tx auth propose-add-account --address="$address" --pubkey="$pubkey" --roles="NodeAdmin" --from jack --yes
echo $passphrase | dcld tx auth approve-add-account --address="$address" --from alice --yes

test_divider

test_divider
vaddress=$(docker exec $container ./dcld tendermint show-address)
vpubkey=$(docker exec $container ./dcld tendermint show-validator)

Expand All @@ -109,8 +111,10 @@ result="$(docker exec "$container" /bin/sh -c "echo test1234 | ./dcld tx validat
check_response "$result" "\"code\": 0"
echo "$result"


test_divider


echo "Locating the app to $DCL_DIR/cosmovisor/genesis/bin directory"
docker exec $container mkdir -p "$DCL_DIR"/cosmovisor/genesis/bin
docker exec $container cp -f ./dcld "$DCL_DIR"/cosmovisor/genesis/bin/
Expand All @@ -119,6 +123,7 @@ echo "$account Start Node \"$node_name\""
docker exec -d $container cosmovisor start
sleep 10


test_divider

echo "Check node \"$node_name\" is in the validator set"
Expand All @@ -128,6 +133,10 @@ check_response "$result" "\"moniker\": \"$node_name\""
check_response "$result" "\"pubKey\":$vpubkey" raw
echo "$result"

result=$(dcld query validator node --address "$address")
echo "$result"


test_divider

echo "Connect CLI to node \"$node_name\" and check status"
Expand All @@ -136,6 +145,7 @@ result=$(dcld status)
check_response "$result" "\"moniker\": \"$node_name\""
echo "$result"


test_divider

echo "Sent transactions using node \"$node_name\""
Expand All @@ -144,6 +154,7 @@ pid=$RANDOM
vendor_account=vendor_account_$vid
create_new_vendor_account $vendor_account $vid


test_divider

echo "Publish Model"
Expand All @@ -154,6 +165,7 @@ result=$(echo 'test1234' | dcld tx model add-model --vid=$vid --pid=$pid --devic
check_response "$result" "\"code\": 0"
echo "$result"


test_divider

sleep 5
Expand All @@ -167,6 +179,7 @@ result=$(dcld status)
check_response "$result" "\"id\": \"$node0id\""
echo "$result"


test_divider

echo "Query Model using node0 node"
Expand All @@ -177,6 +190,106 @@ check_response "$result" "\"pid\": $pid"
check_response "$result" "\"productLabel\": \"$productName\""
echo "$result"


test_divider


echo "node admin disables validator"
result=$(docker exec "$container" /bin/sh -c "echo test1234 | dcld tx validator disable-validator --from "$account" --yes")
check_response "$result" "\"code\": 0"
echo "$result"


test_divider

echo "Get a validator $address from disabled-validator query"
result=$(docker exec "$container" /bin/sh -c "echo test1234 | dcld query validator disabled-validator --address=$address")
check_response "$result" "\"approvals\": \[\]"
check_response "$result" "\"disabledByNodeAdmin\": true"
echo "$result"

test_divider


echo "node admin enables validator"
result=$(docker exec "$container" /bin/sh -c "echo test1234 | dcld tx validator enable-validator --from "$account" --yes")
check_response "$result" "\"code\": 0"
echo "$result"


test_divider


echo "Get a validator $address from disabled-validator query"
result=$(docker exec "$container" /bin/sh -c "echo test1234 | dcld query validator disabled-validator --address="$address"")
check_response "$result" "Not Found"
echo "$result"


test_divider


echo "Alice proposes to disable validator $address"
result=$(dcld tx validator propose-disable-validator --address="$address" --from alice --yes)
check_response "$result" "\"code\": 0"
echo "$result"


test_divider


echo "Get all proposed validators to disable. $address in the list"
result=$(docker exec "$container" /bin/sh -c "echo test1234 | dcld query validator all-proposed-disable-validators")
check_response "$result" "\"approvals\":\[{\"address\":\"$alice_address\"" raw
echo "$result"

test_divider


echo "Get a proposed validator to disable $address"
result=$(docker exec "$container" /bin/sh -c "echo test1234 | dcld query validator proposed-disable-validator --address="$address"")
check_response "$result" "\"approvals\":\[{\"address\":\"$alice_address\"" raw
echo "$result"


test_divider


echo "Bob approves to disable validator $address"
result=$(dcld tx validator approve-disable-validator --address="$address" --from bob --yes)
check_response "$result" "\"code\": 0"
echo "$result"


test_divider


echo "Get all proposed validators to disable. $address not in the list"
result=$(docker exec "$container" /bin/sh -c "echo test1234 | dcld query validator all-proposed-disable-validators")
echo "$result"


test_divider


echo "Get a validator $address from disabled-validator query"
result=$(docker exec "$container" /bin/sh -c "echo test1234 | dcld query validator disabled-validator --address="$address"")
check_response "$result" "\"creator\": \"$alice_address\""
check_response "$result" "\"disabledByNodeAdmin\": false"
echo "$result"


test_divider


echo "Get $address"
result=$(docker exec "$container" /bin/sh -c "echo test1234 | dcld query validator node --address=$address")
check_response "$result" "\"jailed\": true"
echo "$result"


test_divider

echo "PASSED"

cleanup
4 changes: 2 additions & 2 deletions integration_tests/constants/constants.go
Expand Up @@ -140,8 +140,8 @@ var (
`{"@type":"/cosmos.crypto.ed25519.PubKey","key":"NB8hcdxKYDCaPWR67OiUXUSltZfYYOWYryPDUdbWRlA="}`,
defEncConfig.Marshaler,
)
ValidatorAddress1 = "cosmosvalcons1uks7yvlwqsfyp730w6da64g5fw20d9ynh00k53"
ValidatorAddress2 = "cosmosvalcons12tg2p3rjsaczddufmsjjrw9nvhg8wkc4hcz3zw"
ValidatorAddress1 = "cosmosvaloper156dzj776tf3lmsahgmtnrphflaqf7n58kug5qe"
ValidatorAddress2 = "cosmosvaloper12tg2p3rjsaczddufmsjjrw9nvhg8wkc4hcz3zw"
ValidHTTPSURL = "https://valid.url.com"
ValidHTTPURL = "http://valid.url.com"
NotAValidURL = "not a valid url"
Expand Down
28 changes: 28 additions & 0 deletions integration_tests/grpc_rest/validator/grpc_test.go
@@ -0,0 +1,28 @@
// Copyright 2020 DSR Corporation
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.

package validator_test

import (
"testing"

testconstants "github.com/zigbee-alliance/distributed-compliance-ledger/integration_tests/constants"
"github.com/zigbee-alliance/distributed-compliance-ledger/integration_tests/grpc_rest/validator"
"github.com/zigbee-alliance/distributed-compliance-ledger/integration_tests/utils"
)

func TestValidatorDemoGRPC(t *testing.T) {
suite := utils.SetupTest(t, testconstants.ChainID, false)
validator.ValidatorDemo(&suite)
}

0 comments on commit 58e4c3f

Please sign in to comment.