Skip to content

Commit

Permalink
Merge pull request #478 from serokell/ixahedron/#464-support-liquidit…
Browse files Browse the repository at this point in the history
…y-toggle

[#464] Support liquidity baking toggle vote
  • Loading branch information
pasqu4le authored Jun 21, 2022
2 parents ce7a16d + 7047eee commit 23c3b5d
Show file tree
Hide file tree
Showing 7 changed files with 95 additions and 14 deletions.
23 changes: 20 additions & 3 deletions docker/package/model.py
Original file line number Diff line number Diff line change
Expand Up @@ -494,7 +494,7 @@ class TezosBakingServicesPackage(AbstractPackage):
# native releases, so we append an extra letter to the version of
# the package.
# This should be reset to "" whenever the native version is bumped.
letter_version = ""
letter_version = "a"

buildfile = "setup.py"

Expand Down Expand Up @@ -577,7 +577,11 @@ def __init__(
custom_unit.poststop_script = "tezos-baking-custom-poststop"
custom_unit.instances = []
self.systemd_units.append(custom_unit)
self.postinst_steps = ""
# TODO: we will likely need to remove this once toggle vote isn't new anymore
self.postinst_steps = """echo "Please note that the liquidity baking toggle vote option"
echo "is now mandatory when baking. You can read more about it here:"
echo "https://tezos.gitlab.io/jakarta/liquidity_baking.html#toggle-vote"
"""
self.postrm_steps = ""

def fetch_sources(self, out_dir):
Expand Down Expand Up @@ -665,7 +669,7 @@ def gen_buildfile(self, out):
setup(
name='tezos-baking',
packages=['tezos_baking'],
version={self.meta.version},
version='{self.meta.version}',
entry_points=dict(
console_scripts=[
'tezos-setup-wizard=tezos_baking.tezos_setup_wizard:main',
Expand All @@ -684,3 +688,16 @@ def gen_rules(self, out):

def gen_license(self, out):
shutil.copy(f"{os.path.dirname(__file__)}/../../LICENSE", out)

def gen_postinst(self, out):
postinst_contents = f"""#!/bin/sh
set -e
#DEBHELPER#
{self.postinst_steps}
"""
postinst_contents = postinst_contents.replace(self.name, self.name.lower())
with open(out, "w") as f:
f.write(postinst_contents)
2 changes: 1 addition & 1 deletion docker/package/packages.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
"jakartanet": "jakartanet",
}
networks_protos = {
"mainnet": ["012-Psithaca"],
"mainnet": ["012-Psithaca", "013-PtJakart"],
"ithacanet": ["012-Psithaca"],
"jakartanet": ["013-PtJakart"],
}
Expand Down
35 changes: 33 additions & 2 deletions docker/package/tezos_setup_wizard.py
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,12 @@
"archive": "Store all the chain data, very storage-demanding",
}

toggle_vote_modes = {
"pass": "Abstain from voting",
"off": "Request to end the subsidy",
"on": "Request to continue or restart the subsidy",
}


TMP_SNAPSHOT_LOCATION = "/tmp/tezos_node.snapshot"

Expand Down Expand Up @@ -126,6 +132,17 @@ def is_full_snapshot(import_mode):
validator=Validator(enum_range_validator(systemd_enable)),
)

liquidity_toggle_vote_query = Step(
id="liquidity_toggle_vote",
prompt="Would you like to request to end the Liquidity Baking subsidy?",
help="Tezos chain offers a Liquidity Baking subsidy mechanism to incentivise exchange\n"
"between tez and tzBTC. You can ask to end this subsidy, ask to continue it, or abstain.\n"
"\nYou can read more about this in the here:\n"
"https://tezos.gitlab.io/jakarta/liquidity_baking.html",
options=toggle_vote_modes,
validator=Validator(enum_range_validator(toggle_vote_modes)),
)

# We define this step as a function to better tailor snapshot options to the chosen history mode
def get_snapshot_mode_query(modes):
return Step(
Expand Down Expand Up @@ -333,7 +350,7 @@ def bootstrap_node(self):
"time, as the node needs a node identity to be generated."
)

self.systemctl_start_action("node")
self.systemctl_simple_action("start", "node")

print("Waiting for the node service to start...")

Expand Down Expand Up @@ -408,8 +425,20 @@ def register_baker(self):
"to see the baker status and baking rights of your account."
)

# There is no changing the toggle vote option at a glance,
# so we need to change the config every time
def set_liquidity_toggle_vote(self):
self.query_step(liquidity_toggle_vote_query)

config_filepath = self.get_baking_config_filepath()
replace_in_service_config(
config_filepath,
"LIQUIDITY_BAKING_TOGGLE_VOTE",
f"\"{self.config['liquidity_toggle_vote']}\"",
)

def start_baking(self):
self.systemctl_start_action("baking")
self.systemctl_simple_action("restart", "baking")

def run_setup(self):

Expand Down Expand Up @@ -447,6 +476,8 @@ def run_setup(self):
continue
executed = True

self.set_liquidity_toggle_vote()

print()
print("Starting the baking instance")
self.start_baking()
Expand Down
26 changes: 19 additions & 7 deletions docker/package/wizard_structure.py
Original file line number Diff line number Diff line change
Expand Up @@ -363,6 +363,18 @@ def search_json_with_default(json_filepath, field, default):
return json_dict.pop(field, default)


def replace_in_service_config(config_filepath, field, value):
with open(config_filepath, "r") as f:
config_contents = f.read()

old = re.search(f"{field}=.*", config_contents)
if old is None:
return None
else:
new = f"{field}={value}"
proc_call(f"sudo sed -i 's/{old.group(0)}/{new}/' {config_filepath}")


class Step:
def __init__(
self,
Expand Down Expand Up @@ -548,9 +560,9 @@ def query_step(self, step: Step):
validated = True
self.config[step.id] = answer

def systemctl_start_action(self, service):
def systemctl_simple_action(self, action, service):
proc_call(
f"sudo systemctl start tezos-{service}-{self.config['network']}.service"
f"sudo systemctl {action} tezos-{service}-{self.config['network']}.service"
)

def systemctl_enable(self):
Expand All @@ -560,10 +572,7 @@ def systemctl_enable(self):
self.config["mode"], self.config["network"]
)
)
proc_call(
f"sudo systemctl enable tezos-{self.config['mode']}-"
f"{self.config['network']}.service"
)
self.systemctl_simple_action("enable", self.config["mode"])
else:
print("The services won't restart on boot.")

Expand All @@ -584,7 +593,7 @@ def query_and_update_config(self, query):
f"{self.config['tezos_client_options']} config update"
)

def fill_baking_config(self):
def get_baking_config_filepath(self):
net = self.config["network"]
output = get_proc_output(f"systemctl show tezos-baking-{net}.service").stdout
config_filepath = re.search(b"EnvironmentFiles=(.*) ", output)
Expand All @@ -596,7 +605,10 @@ def fill_baking_config(self):
config_filepath = f"/etc/default/tezos-baking-{net}"
else:
config_filepath = config_filepath.group(1).decode().strip()
return config_filepath

def fill_baking_config(self):
config_filepath = self.get_baking_config_filepath()
with open(config_filepath, "r") as f:
config_contents = f.read()
self.config["client_data_dir"] = search_baking_service_config(
Expand Down
20 changes: 20 additions & 0 deletions docs/baking.md
Original file line number Diff line number Diff line change
Expand Up @@ -155,6 +155,26 @@ sudo -u tezos tezos-client bootstrapped
By default `tezos-baking-<network>.service` will use the `baker` alias for the
key that will be used for baking and endorsing.

### Setting the Liquidity Baking toggle vote option

Since `013-PtJakart`, the `--liquidity-baking-toggle-vote` command line option for
`tezos-baker` is now mandatory. In our systemd services, it is set to `pass` by
default. You can change it as desired in the service config file at
`/etc/defaults/tezos-baking-<network>`.

If the baking service is running already, changing this options requires a restart.
You can do so manually by running:
```bash
sudo systemctl restart tezos-baking-<network>.service
```

If using this option on Ithaca, the format in our configuration files stays the same
but is transformed to the Ithaca-specific format: `off` is transformed to the
`--liquidity-baking-escape-vote` command line options, whereas `pass` and `on` result
in no command line argument and will only affect baking upon switching to Jakarta.

You can also use the [Setup Wizard](#using-the-wizard) which will handle everything for you.

<a name="import"></a>
### Importing the baker key

Expand Down
1 change: 1 addition & 0 deletions docs/tests/voting.md
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@ NODE_RPC_ENDPOINT="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"
```

Additionally, you can set `RESET_ON_STOP="true"` to enable automatic node directory removal which will
Expand Down
2 changes: 1 addition & 1 deletion meta.json
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
{
"release": "1",
"release": "2",
"maintainer": "Serokell <[email protected]>"
}

0 comments on commit 23c3b5d

Please sign in to comment.