Skip to content

Commit

Permalink
Merge pull request #743 from serokell/krendelhoff/#729-improve-tezos-…
Browse files Browse the repository at this point in the history
…vote-prompts

[#729] Introduce better prompts for `tezos-vote`
  • Loading branch information
krendelhoff2 authored Nov 1, 2023
2 parents 8f9199d + d62c604 commit 2488e3f
Show file tree
Hide file tree
Showing 5 changed files with 91 additions and 47 deletions.
25 changes: 22 additions & 3 deletions baking/src/tezos_baking/tezos_voting_wizard.py
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,12 @@
def wait_for_ledger_app(app_name, client_dir):
logging.info(f"Waiting for the ledger {app_name} app to be opened")
print(f"Please make sure the Tezos {app_name} app is open on your ledger.")
print()
print(
color(
f"Waiting for the Tezos {app_name} app to be opened...",
color_green,
)
)
search_string = b"Found a Tezos " + bytes(app_name, "utf8")
output = b""
while re.search(search_string, output) is None:
Expand Down Expand Up @@ -139,7 +144,6 @@ def get_proposal_period_hash(hashes):
def get_node_rpc_endpoint_query(network, default=None):
url_path = "chains/main/blocks/head/header"
node_is_alive = lambda host: url_is_reachable(mk_full_url(host, url_path))
custom_url_validator = validators.reachable_url(url_path)

relevant_nodes = {
url: provider
Expand All @@ -160,7 +164,7 @@ def get_node_rpc_endpoint_query(network, default=None):
validators.required_field,
validators.any_of(
validators.enum_range(relevant_nodes),
validators.custom_url,
validators.reachable_url(url_path),
),
]
),
Expand Down Expand Up @@ -338,6 +342,13 @@ def process_proposal_period(self):
hash_to_submit = self.config["new_proposal_hash"]

logging.info("Submitting proposals")
if self.check_ledger_use():
print(
color(
"Waiting for your response to the prompt on your Ledger Device...",
color_green,
)
)
result = get_proc_output(
f"sudo -u tezos {suppress_warning_text} octez-client {self.config['tezos_client_options']} "
f"submit proposals for {self.config['baker_alias']} {hash_to_submit}"
Expand Down Expand Up @@ -401,6 +412,13 @@ def process_voting_period(self):
self.query_step(ballot_outcome_query)

logging.info("Submitting ballot")
if self.check_ledger_use():
print(
color(
"Waiting for your response to the prompt on your Ledger Device...",
color_green,
)
)
result = get_proc_output(
f"sudo -u tezos {suppress_warning_text} octez-client {self.config['tezos_client_options']} "
f"submit ballot for {self.config['baker_alias']} {self.config['proposal_hashes'][0]} "
Expand Down Expand Up @@ -495,6 +513,7 @@ def run_voting(self):

print()
print("Thank you for voting!")
logging.info("Exiting the Tezos Voting Wizard.")


def main():
Expand Down
1 change: 1 addition & 0 deletions baking/src/tezos_baking/util.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
import re
import urllib.request
import json
import os

# Regexes

Expand Down
3 changes: 2 additions & 1 deletion baking/src/tezos_baking/wizard_structure.py
Original file line number Diff line number Diff line change
Expand Up @@ -313,7 +313,8 @@ def import_key(self, key_mode_query, ledger_app=None):
print("press Ctrl+C to go back to the key import mode selection.")
print(
color(
"Waiting for the Ledger Device to appear...", color_green
f"Waiting for the Tezos {ledger_app} to be opened...",
color_green,
),
end="",
flush=True,
Expand Down
2 changes: 1 addition & 1 deletion docker/package/packages.py
Original file line number Diff line number Diff line change
Expand Up @@ -217,7 +217,7 @@ def mk_node_unit(
part_of=[f"tezos-baking-{dependencies_suffix}.service"],
),
Service(
environment_files=[f"/etc/default/tezos-node-{suffix}"],
environment_files=[f"/etc/default/tezos-node-{dependencies_suffix}"],
exec_start="/usr/bin/tezos-node-start",
exec_start_pre=["/usr/bin/tezos-node-prestart"],
timeout_start_sec="2400s",
Expand Down
107 changes: 65 additions & 42 deletions docs/voting-test.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,79 +11,102 @@ amendment periods.
## Prerequisites

1) Install `tezos-baking` package should on your system.
2) Clone [local-chain repository](https://gitlab.com/morley-framework/local-chain).
2) Create a temporary directory where the node's data directory and the local-chain will reside:

```bash
mkdir -m 777 /tmp/voting
cd /tmp/voting
git clone https://gitlab.com/morley-framework/local-chain
```

## Test scenario workflow

1) Generate a pair of keys associated with `baker` alias:

```bash
sudo -u tezos tezos-client gen keys baker
```
```bash
sudo -u tezos tezos-client gen keys baker
```

If you want to use your ledger device for voting, you should import its encrypted private key instead:

First, run this command:

```
sudo -u tezos tezos-client list connected ledgers
```

This will display some instructions to import the Ledger encrypted private key. Then run

```
sudo -u tezos tezos-client import secret key baker ledger://XXXXXXXXXX
```

And confirm providing the public key using the prompt on the ledger device.

2) In a separate terminal start a [voting scenario script](https://gitlab.com/morley-framework/local-chain#voting-scenario) from the local-chain repo.

This script will provide you a path to the node config that will be used by the custom baking service.
This script will provide you a path to the node config that will be used by the custom baking service.

3) Provide address generated on the first step to the `voting.py` script. This address will receive some amount of XTZ.

4) Create a config for the custom baking service that will be used by the voting wizard:
4) Create environment files for the custom baking service that will be used by the voting wizard:

```bash
sudo cp /etc/default/tezos-baking-custom@ /etc/default/tezos-baking-custom@voting
```
```bash
sudo cp /etc/default/tezos-node-custom@ /etc/default/tezos-node-custom@voting
sudo cp /etc/default/tezos-baking-custom@ /etc/default/tezos-baking-custom@voting
```

Edit with the config provided by the voting script on the second step:
Edit the node environment file with the config provided by the voting script on the second step:

```
DATA_DIR="/var/lib/tezos/.tezos-client"
NODE_RPC_ADDR="http://localhost:8732"
BAKER_ADDRESS_ALIAS="baker"
CUSTOM_NODE_CONFIG="<paste your path to the node config here>"
RESET_ON_STOP=""
LIQUIDITY_BAKING_TOGGLE_VOTE="pass"
```
```
NODE_RPC_ADDR="127.0.0.1:8732"
CERT_PATH=""
KEY_PATH=""
TEZOS_NODE_DIR=/tmp/voting/node-custom
CUSTOM_NODE_CONFIG=/tmp/voting/local-chain/voting-config.json
RESET_ON_STOP=""
```

Additionally, you can set `RESET_ON_STOP="true"` to enable automatic node directory removal which will
be triggered once custom baking service will be stopped.
Additionally, you can set `RESET_ON_STOP="true"` to enable automatic node directory removal which will
be triggered once custom baking service will be stopped.

5) Start custom baking service:

```bash
sudo systemctl start tezos-baking-custom@voting
```
```bash
sudo systemctl start tezos-baking-custom@voting
```

Note that `tezos-node` service may take some time to generate a fresh identity and start.
Note that `tezos-node` service may take some time to generate a fresh identity and start.

To check the status of the node service run:
To check the status of the node service run:

```bash
systemctl status tezos-node-custom@voting
```
```bash
systemctl status tezos-node-custom@voting
```

6) Register `baker` key as delegate once `tezos-node` is up and running:

```bash
sudo -u tezos tezos-client register key baker as delegate
```
```bash
sudo -u tezos tezos-client register key baker as delegate
```

7) After that `voting.py` will start going through the voting cycle.

The script will stop at the beginning of each voting period that requires voting and ask you to vote.
The script will stop at the beginning of each voting period that requires voting and ask you to vote.

Launch the wizard by running:
Launch the wizard by running:

```bash
tezos-vote --network voting
```
```bash
tezos-vote --network voting
```

Under normal conditions, you won't have to adjust any information about your baking service.
Confirm the information and submit your vote.
Under normal conditions, you won't have to adjust any information about your baking service.
Confirm the information and submit your vote.
Once you'll vote, you should prompt the `voting.py` script to continue going through the voting cycle.
Once you'll vote, you should prompt the `voting.py` script to continue going through the voting cycle.

8) Stop custom baking service once voting cycle is over:

```bash
sudo systemctl stop tezos-baking-custom@voting
```
```bash
sudo systemctl stop tezos-baking-custom@voting
```

0 comments on commit 2488e3f

Please sign in to comment.