Verify debug_witness plugin #431

Closed
opened 2022-09-07 14:38:41 +00:00 by serkixenos · 6 comments
serkixenos commented 2022-09-07 14:38:41 +00:00 (Migrated from gitlab.com)

The debug_witness plugin is an important utility providing debugging API. We need to ensure its functionality.

Plugin code https://gitlab.com/PBSA/peerplays/-/tree/develop/libraries/plugins/debug_witness

Documentation https://github.com/bitshares/bitshares-core/wiki/README-debug_node

(Note that our feature set could be different from the documentation)

The debug_witness plugin is an important utility providing debugging API. We need to ensure its functionality. Plugin code https://gitlab.com/PBSA/peerplays/-/tree/develop/libraries/plugins/debug_witness Documentation https://github.com/bitshares/bitshares-core/wiki/README-debug_node (Note that our feature set could be different from the documentation)
serkixenos commented 2022-09-07 14:38:41 +00:00 (Migrated from gitlab.com)

assigned to @timur.5

assigned to @timur.5
timur.5 commented 2022-09-20 20:36:06 +00:00 (Migrated from gitlab.com)

Testcase:

  1. Have QA environment running.

  2. Go to an empty directory, say <mydir>.
    All the subsequent commands are executed from it.

  3. Copy 'witness_node', 'cli_wallet' executables and 'genesis.json' from the container to <mydir>:

docker cp -L peerplays-qa-environment_peerplays-all-in-one_1:/home/peerplays/peerplays-network/witness_node ./
docker cp -L peerplays-qa-environment_peerplays-all-in-one_1:/home/peerplays/peerplays-network/cli_wallet   ./
docker cp    peerplays-qa-environment_peerplays-all-in-one_1:/home/peerplays/peerplays-network/genesis.json ./
  1. Run your copy of witness_node to have its data dir and default configuration created:
./witness_node

Wait a few seconds until red complaints, then Ctrl-C.

  1. Edit ./witness_node_data_dir/config.ini and point to your genesis file:
genesis-json = <mydir>/genesis.json

Note: use absolute path for <mydir>!

  1. Delete blockchain data:
rm -rf ./witness_node_data_dir/blockchain
  1. Run witness_node again to synchronize with the seed node from QA env.:
./witness_node --p2p-endpoint=0.0.0.0:0 --rpc-endpoint=0.0.0.0:0 --seed-node=127.0.0.1:9777

There must be multiple

In process_dividend_assets...

and some other lines.

Wait for 1 minute, then Ctrl-C.

  1. Make a copy of block database:
cp -Rp ./witness_node_data_dir/blockchain/database/block_num_to_block ./block_db
  1. Delete blockchain data again:
rm -rf ./witness_node_data_dir/blockchain
  1. Create 'api-access.json' in <mydir> with the following contents:
{
   "permission_map" :
   [
      [
         "bytemaster",
         {
            "password_hash_b64" : "9e9GF7ooXVb9k4BoSfNIPTelXeGOZ5DrgOYMj94elaY=",
            "password_salt_b64" : "INDdM6iCi/8=",
            "allowed_apis" : ["database_api", "network_broadcast_api", "history_api", "network_node_api", "debug_api", "bookie_api"]
         }
      ],
      [
         "*",
         {
            "password_hash_b64" : "*",
            "password_salt_b64" : "*",
            "allowed_apis" : ["database_api", "network_broadcast_api", "history_api", "bookie_api"]
         }
      ]
   ]
}
  1. Edit ./witness_node_data_dir/config.ini and point to your api-access file:
api-access = <mydir>/api-access.json

Note: use absolute path for <mydir>!

  1. Run witness_node once more, finally in the debug_witness mode, which is targeted by the ticket:
./witness_node --plugin=debug_witness --p2p-endpoint=0.0.0.0:0 --rpc-endpoint=127.0.0.1:8091

Note: --p2p-endpoint and --rpc-endpoint are supplied for testing purposes, to avoid port conflict with the QA env.

The output must stop soon, it's not expected to scroll indefinitely as usual.
Ensure that one of the last lines is:

Started Peerplays node on a chain with 0 blocks.

Leave it running, you will refer its output later.

  1. Open a new terminal, go to <mydir>,
    and start your copy of the wallet,
    explicitly connecting it to your witness node's RPC:
./cli_wallet -s ws://127.0.0.1:8091 -u bytemaster -p supersecret --chain-id=7c1c72eb738b3ff1870350f85daca27e2d0f5dd25af27df7475fbd92815e421e
  1. In your cli_wallet, load some blocks from your 'block_db' copy:
new >>> dbg_push_blocks block_db 20

After successful execution, look at witness_node output:
there must appear

Loading 20 from block_database block_db

then a couple of other lines, and finally

Completed loading block_database successfully
  1. In the wallet again, generate fake blocks with our own private key:
new >>> dbg_generate_blocks 5KQwrPbwdL6PhXujxW37FSSQZ1JiwsST4cqQzDeyXtP79zkvFD3 1000

Again, switch to witness_node and check:
a few

In process_dividend_assets...

and some other lines must appear.

Note: disregard blue warning

API call execution time limit exceeded

- it's OK.

  1. The above two wallet commands didn't require unlocked state, but the subsequent ones will require it,
    so let's set a password and unlock:
new >>> set_password password
locked >>> unlock password
unlocked >>>
  1. In the wallet again, let's check the initial state of 'nathan' and 'init0' accounts:
unlocked >>> list_account_balances nathan
list_account_balances nathan
5000000000 TEST

unlocked >>> list_account_balances init0
list_account_balances init0
  1. In the wallet, try to transfer 10 coins from "nathan" to "init0":
unlocked >>> transfer nathan init0 10 TEST "" true

This must fail with very wordy exception starting with

missing required active authority

That's because we don't possess nathan's private key.

  1. Now through the wallet we'll invoke special debug_witness commands
    that will fake our control over nathan's account:
unlocked >>> dbg_update_object {"_action":"update", "id":"1.2.18", "active":{"weight_threshold":1,"key_auths":[["BTS6MRyAjQq8ud7hVNYcfnVPJqcVpscN5So8BhtHuGYqET5GDW5CV",1]]}}
unlocked >>> import_key nathan 5KQwrPbwdL6PhXujxW37FSSQZ1JiwsST4cqQzDeyXtP79zkvFD3

The second command will cause at least one line of output containing

backing up wallet wallet.json
  1. Now in the wallet we'll retry the above transfer:
unlocked >>> transfer nathan init0 10 TEST "" true

This time it should succeed.

  1. In the wallet, let's check the resulting state of 'nathan' and 'init0' accounts:
unlocked >>> list_account_balances nathan
list_account_balances nathan
4999999990 TEST

unlocked >>> list_account_balances init0
list_account_balances init0
10 TEST
Testcase: 1) Have QA environment running. 2) Go to an empty directory, say \<mydir\>. All the subsequent commands are executed from it. 3) Copy 'witness_node', 'cli_wallet' executables and 'genesis.json' from the container to \<mydir\>: ``` docker cp -L peerplays-qa-environment_peerplays-all-in-one_1:/home/peerplays/peerplays-network/witness_node ./ docker cp -L peerplays-qa-environment_peerplays-all-in-one_1:/home/peerplays/peerplays-network/cli_wallet ./ docker cp peerplays-qa-environment_peerplays-all-in-one_1:/home/peerplays/peerplays-network/genesis.json ./ ``` 4) Run your copy of witness_node to have its data dir and default configuration created: ``` ./witness_node ``` Wait a few seconds until red complaints, then Ctrl-C. 5) Edit ./witness_node_data_dir/config.ini and point to your genesis file: ``` genesis-json = <mydir>/genesis.json ``` Note: **use absolute path** for \<mydir\>! 6) Delete blockchain data: ``` rm -rf ./witness_node_data_dir/blockchain ``` 7) Run witness_node again to synchronize with the seed node from QA env.: ``` ./witness_node --p2p-endpoint=0.0.0.0:0 --rpc-endpoint=0.0.0.0:0 --seed-node=127.0.0.1:9777 ``` There must be multiple ``` In process_dividend_assets... ``` and some other lines. Wait for 1 minute, then Ctrl-C. 8) Make a copy of block database: ``` cp -Rp ./witness_node_data_dir/blockchain/database/block_num_to_block ./block_db ``` 9) Delete blockchain data again: ``` rm -rf ./witness_node_data_dir/blockchain ``` 10) Create 'api-access.json' in \<mydir\> with the following contents: ``` { "permission_map" : [ [ "bytemaster", { "password_hash_b64" : "9e9GF7ooXVb9k4BoSfNIPTelXeGOZ5DrgOYMj94elaY=", "password_salt_b64" : "INDdM6iCi/8=", "allowed_apis" : ["database_api", "network_broadcast_api", "history_api", "network_node_api", "debug_api", "bookie_api"] } ], [ "*", { "password_hash_b64" : "*", "password_salt_b64" : "*", "allowed_apis" : ["database_api", "network_broadcast_api", "history_api", "bookie_api"] } ] ] } ``` 11) Edit ./witness_node_data_dir/config.ini and point to your api-access file: ``` api-access = <mydir>/api-access.json ``` Note: **use absolute path** for \<mydir\>! 10) Run witness_node once more, finally in the debug_witness mode, which is targeted by the ticket: ``` ./witness_node --plugin=debug_witness --p2p-endpoint=0.0.0.0:0 --rpc-endpoint=127.0.0.1:8091 ``` Note: --p2p-endpoint and --rpc-endpoint are supplied for testing purposes, to avoid port conflict with the QA env. The output must stop soon, it's not expected to scroll indefinitely as usual. Ensure that one of the last lines is: ``` Started Peerplays node on a chain with 0 blocks. ``` Leave it running, you will refer its output later. 11) Open a new terminal, go to \<mydir\>, and start your copy of the wallet, explicitly connecting it to your witness node's RPC: ``` ./cli_wallet -s ws://127.0.0.1:8091 -u bytemaster -p supersecret --chain-id=7c1c72eb738b3ff1870350f85daca27e2d0f5dd25af27df7475fbd92815e421e ``` 12) In your cli_wallet, load some blocks from your 'block_db' copy: ``` new >>> dbg_push_blocks block_db 20 ``` After successful execution, look at witness_node output: there must appear ``` Loading 20 from block_database block_db ``` then a couple of other lines, and finally ``` Completed loading block_database successfully ``` 13) In the wallet again, generate fake blocks with our own private key: ``` new >>> dbg_generate_blocks 5KQwrPbwdL6PhXujxW37FSSQZ1JiwsST4cqQzDeyXtP79zkvFD3 1000 ``` Again, switch to witness_node and check: a few ``` In process_dividend_assets... ``` and some other lines must appear. Note: disregard blue warning ``` API call execution time limit exceeded ``` \- it's OK. 14) The above two wallet commands didn't require unlocked state, but the subsequent ones will require it, so let's set a password and unlock: ``` new >>> set_password password locked >>> unlock password unlocked >>> ``` 15) In the wallet again, let's check the initial state of 'nathan' and 'init0' accounts: ``` unlocked >>> list_account_balances nathan list_account_balances nathan 5000000000 TEST unlocked >>> list_account_balances init0 list_account_balances init0 ``` 16) In the wallet, try to transfer 10 coins from "nathan" to "init0": ``` unlocked >>> transfer nathan init0 10 TEST "" true ``` This must fail with very wordy exception starting with ``` missing required active authority ``` That's because we don't possess nathan's private key. 17) Now through the wallet we'll invoke special debug_witness commands that will fake our control over nathan's account: ``` unlocked >>> dbg_update_object {"_action":"update", "id":"1.2.18", "active":{"weight_threshold":1,"key_auths":[["BTS6MRyAjQq8ud7hVNYcfnVPJqcVpscN5So8BhtHuGYqET5GDW5CV",1]]}} unlocked >>> import_key nathan 5KQwrPbwdL6PhXujxW37FSSQZ1JiwsST4cqQzDeyXtP79zkvFD3 ``` The second command will cause at least one line of output containing ``` backing up wallet wallet.json ``` 18) Now in the wallet we'll retry the above transfer: ``` unlocked >>> transfer nathan init0 10 TEST "" true ``` This time it should succeed. 19) In the wallet, let's check the resulting state of 'nathan' and 'init0' accounts: ``` unlocked >>> list_account_balances nathan list_account_balances nathan 4999999990 TEST unlocked >>> list_account_balances init0 list_account_balances init0 10 TEST ```
timur.5 commented 2022-09-20 21:07:47 +00:00 (Migrated from gitlab.com)

assigned to @prandnum and @wsalloum

assigned to @prandnum and @wsalloum
timur.5 commented 2022-09-20 21:11:58 +00:00 (Migrated from gitlab.com)

created branch 431-verify-debug_witness-plugin to address this issue

created branch [`431-verify-debug_witness-plugin`](/PBSA/peerplays/-/compare/master...431-verify-debug_witness-plugin) to address this issue
timur.5 commented 2022-09-20 21:51:10 +00:00 (Migrated from gitlab.com)
!153
wsalloum commented 2022-09-21 15:15:30 +00:00 (Migrated from gitlab.com)

It is working as explained

  • The balances before the transfer :
unlocked >>> list_account_balances nathan
list_account_balances nathan
1900000000 TEST

unlocked >>> list_account_balances init0
list_account_balances init0
50000000 TEST

  • The balances after the transfer transfer nathan init0 10 TEST "" true

unlocked >>> list_account_balances nathan
list_account_balances nathan
1899999990 TEST

unlocked >>> list_account_balances init0
list_account_balances init0
50000010 TEST

It is working as explained - The balances before the transfer : ``` unlocked >>> list_account_balances nathan list_account_balances nathan 1900000000 TEST unlocked >>> list_account_balances init0 list_account_balances init0 50000000 TEST ``` - The balances after the transfer ` transfer nathan init0 10 TEST "" true` ``` unlocked >>> list_account_balances nathan list_account_balances nathan 1899999990 TEST unlocked >>> list_account_balances init0 list_account_balances init0 50000010 TEST ```
wsalloum (Migrated from gitlab.com) closed this issue 2022-09-22 12:25:52 +00:00
Sign in to join this conversation.
No project
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set.

Reference: Peerplays_Blockchain/peerplays_migrated#431
No description provided.