#tezos

By Laurent Canis

This post is intended for beginners who want to try and understand the Tezos baking process. It will provide you with a script to set up your bakery and useful links to go further.

We highly recommend trying it on Ghostnet, which is a long-running testnet for Tezos. Then you can use it on Mainnet with caution (personally, I am running my baker on mainnet).

The script targets a Linux (Debian-based) environment. It’s 100% written in BASH, deals with systemd and only uses jq (for the configuration file in JSON) and curl (for HTTP interaction).

Recommended Configuration

  • CPU: Running with at least 2 cores is recommended (at least NUC i3)
  • Memory: 8GB recommended
  • Disk: 250 GB SSD (SSD is highly preferred over HDD)
  • A Linux (Debian-based) distribution
  • Ledger Nano S or X

Consensus

Tezos blockchain uses a Liquid Proof of Stake consensus (LPoS). It’s like a standard Proof of Stake (PoS), except that people can delegate the voting power of their tokens to a baker without the risk of losing them, because they remain in their wallet.

Because the voting power stake is also the weight to be selected for operations. The baker will want to attract more delegation. If you hold some XTZ, you can delegate your tokens or become a baker yourself.

Baker responsibilities in Tezos world

To become a baker (here named Delegate), you will need to collect 6000 XTZ to be able to bake.
10% of your stake will be frozen (sensible to slashing). Because delegators can’t be slashed (with delegation, the risk is not shared), you must own at least 10% of the total stake. If you own less than 10%, you will be over-delegated.

There are two solutions:
       - Use your own 6000 XTZ or more.
       - Bring at least a minimal stake (currently 10% of 6000) and obtain delegation to reach at least 6000 XTZ.

To participate in the securisation of the network, a baker has to be registered as a baker on the Tezos network. The Tezos network can elect a registered baker to do some operations. Then it will freeze a part of your stake (deposit).

Registration can be done by using our provided script 🚀

There are 3 possibilities result:

       - Success: You will be rewarded.
       - Failed
: You will not be rewarded (for example, because of a power outage, etc.), and another baker will take your place, but you do not receive the punishment.
       - Cheat
: If you are malicious, a punishment will occur, and some of your deposit will be burned.

Terminology operations meaning:

       - Bake: The act of creating, signing and publishing blocks.
       - Attest (formerly endorse)
: Signing to validate a block.

Baking and attesting are both done by the same baker process. Our provided script will manage it 🚀.

.

Cheating:

       - Double bake: 640 XTZ are slashed.
       - Double Attest (formerly endorse)
: half of the frozen deposits are slashed.

How can they catch me:

There are accusers who act as a guard for the chain. If an accuser proves that you are cheating, your tokens will be slashed, and they will be rewarded with the amount of XTZ from your frozen deposit.

The accuser is a daemon that monitors all blocks received on all chains and looks for:
bakers who signed two blocks at the same level and the same round
bakers who injected more than one pre-attestations or attestation operation for the same level and > round (more details here)
Upon finding such irregularity, it will emit a double-baking, double-pre-attesting, or double-attesting denunciation operation, which will cause the offender to be slashed, that is, to lose part of its security deposit.>

How can I catch others:

By becoming an accuser

You can do that by using our provided script 🚀

For further knowledge we recommend reading this article.

Responsibilities as Baker

       - Keep informed about new protocols, discuss their adoption and vote (have knowledge about governance).
       - Update your baker to the latest protocol version.
       - Be an honest baker.
       - Pay rewards to your delegators.

Understand rewards

For detail about rewards, we recommend you to read this article.

If you want to compare rewards between baking vs staking, we recommend this guide.

How to build your baker

Prepare your ledger

Ledger is a secure way to store your wallet in order to bake on Tezos.

Setting up your ledger:

       - Open a Tezos wallet.
       - Collect tokens for baking (At least 6000 XTZ if you want to be able to bake without delegating).
       - Install the Tezos baking application. We recommend reading configure ledger nano S guide.
       - Configure udev rules to be able to use your ledger. For more information can be found in this README.

Run the script!

The script is available here.

Start by checking the config file (edit it to your configuration, if necessary).

The default config is below:


{
  "baker_user_name": "tezosbaker",
  "octez_binaries_home": "octez_binaries",
  "network": "ghostnet",
  "protocol": "Mumbai",# Have to be the name of the protocol suffixing binaries in serokell repo here Mumbai as current protocol
  "tezos_node": {
    "home": "tezos_node",
    "data_home": "data",
    "rpc_port": 8732,
    "metric_port": 9932,
    "history_mode": "full",
    "snapshot_uri": "https://snapshots.tezos.marigold.dev/api/ghostnet/full"
  },
  "tezos_baker": {
    "home": "tezos_baker",
    "initial_vote": "pass",
    "ledger_pk_name": "ledger_baker"
  },
  "tezos_accuser": {
    "home": "tezos_accuser"
  }
}

The protocol name is used to download binaries. The naming convention is first 8 characters of the protocol hash:

       - Nairobi is truncated to Nairob and prefixed by Pt

https://hackmd-prod-images.s3-ap-northeast-1.amazonaws.com/uploads/upload_f089779819423e81623a63a76fb1a7b3.png?AWSAccessKeyId=AKIA3XSAAW6AWSKNINWO&Expires=1687798776&Signature=4%2FWO72xVG4CTTEHlZHf1ePdxbsQ%3D

⚠️ There are different modes: full, rolling, Archive. It is  recommended to run a baker with full as history mode. For the full mode (it is still possible to run with rolling node): download the snapshot (it can take a lot of time); if you want to do it outside the script, you can do that by replacing snapshot_uri value with a local path to the downloaded binary.

Understand the provided script

To trigger the script, you’ll need to run:


./main_initialize_baker.sh script_conf.json

Below you will find the description of the main steps of the script.

Sometimes using sudo is necessary. If you are not in sudoers, you'll be prompted for a password. For more information, visit this source to trust the process.

Create user

A good practice is to manage your process with another Unix user. It is contrary to your user (this one doesn’t need to be sudoer).


"baker_user_name": "tezosbaker",

⚠️ A manual step is necessary to configure the password of the new user. ⚠️

Download binaries

The script will download the latest pre-built of octez-binaries from tezos-packaging:

       - octez-client: set up your wallet, and register your key as a baker.
       - octez-node: run the daemon node.
       - octez-signer: it is included in octez-client.
       - octez-baker-<protocolN>: run the daemon baker with protocol version N.
       - octez-baker-<protocolN-1>: run the daemon baker with protocol version N-1 (it is useful if you target the mainnet protocol, which can be N-1 or N).
       - octez-accuser-<protocolN>: run the daemon accuser.
       - octez-accuser-<protocolN-1>: run the daemon accuser (it is useful if you target the mainnet protocol, which can be N-1 or N).

Each Octez release come with 2 sets of protocols to be able to do a smooth transition between protocols during adoption period.

For example, on octez v17.0 we got : 
       - octez-baker and octez-accuser for Nairobi
       - octez-baker and octez-accuser for Mumbai

Running Zcash is also necessary. You can use this script fetch-param.

Initialize node configuration

A standard node config is as follows (it is customizable):


  "tezos_node": {
    "home": "tezos_node",
    "data_home": "data",
    "rpc_port": 8732,
    "metric_port": 9932,
    "history_mode": "full",
    ...
  }

For details, you can edit this file: node-conf.json.template.

Initialize node data

We will use a snapshot from a trusted source.

Snapshot is a way to avoid downloading data from the network from the genesis. It's a quick start with some validation on it (so it reduces the risk of corruption compared to when you copy/paste the zip files of an existing folder).

The configuration of the node data can be found in this script initialize_node_data.sh.

To import the snapshot, execute this command:


octez-node snapshot import

Your Tezos node will then contain the context and history of the chain that you are importing.

Start and bootstrap

You will have to wait for your node to be bootstrapped (from the snapshot data to the current head of the chain).

You can survey this progress by using journalctl command:


journalctl -u octez-node.service

Initialize baker and accuser configuration

A standard node config is as follow:


"tezos_baker": {
    "home": "tezos_baker",
    "initial_vote": "pass",
    "ledger_pk_name": "ledger_baker"
  },
  "tezos_accuser": {
    "home": "tezos_accuser"
  }

Similar to the initialize for the node above, you can edit the baker-conf.json.template for baker and accuser-conf.json.template for accuser.

Link and setup your ledger

To link your ledger to the octez configuration, from the script import_ledger.sh execute this command:


octez-client import secret key xxx

To check the secret key is a URI to the ledger, execute this command:


cat .tezos-client/secret_keys

The bridge between the ledger and the configuration is done. We will prepare the ledger to bake this script register_and_setup_to_bake.sh.

To register the key, execute this command:


register key

To set up the ledger to bake, execute this command:


setup ledger to bake

You’ll be prompted onto the ledger to sign for the operation!

To check if you are successfully registered, use one of the Tezos explorers, tzkt.io or on tzkt ghostnet.

Start your baker!

We will use journalctl for starting the baker and accusser. Checking the command journalctl first:


journalctl -u octez-node.service

journalctl -u octez-baker.service

journalctl -u octez-accuser.service

After registering, to begin baking, you will need to be selected by the network, and it can take up to 21 days. You can check the waiting list on the schedule tab of tzkt explorer.

How to upgrade your baker

Upgrading a baker is still manual for the time being, but we are looking to automate it soon.

Our baker is running the script from the last artifacts. The systemd config of each process is on /etc/systemd/system. You will need this information to understand this section.

⚠️ You’ll need the root permission to do it.

When should I upgrade my node?

Ghostnet

On Ghosnet, you can upgrade your node whenever you want. But the sooner, the better, so you can give your feedback to the octez team.

Mainnet

On mainnet, to upgrade, you need to check 3 things:

       - Use stable binaries
       - Be ready before the next protocol upgrade
       - Miss as few operations as possible

For the first 2 points, the best thing you can do is upgrade between 1 and 3 days before the protocol activation. That way, you’ll get all binaries files that carry the last-minute fixes, and the upgrade will be done before the beginning of the next protocol.

To do that, you can run the baker of Protocol N and N+1 simultaneously.

The protocol N+1 will wait with the log:


Waiting for protocol  to start..

when Tezos will upgrade to N+1 this protocol will start baking, and the protocol N will stop baking.

So keep you informed on Tezos Agora.

For the third point: to miss as few operations as possible. There is a way to upgrade the protocol with 0 downtime. But it’s complicated and not so useful if you are a small baker. We advise finding an upgrade scope on tzkt schedule pannel of your baker. If you are not a major baker, you’ll be able to find a scope when your baker won’t attest (formerly endorse) or bake. Upgrade can be prepared, but not executed :).

Understand binaries compatibilities

What you have to understand is a version 17.y.z of a baker and an accuser are compatible with the node version 17.y.z, so you’ll need to update your current node, baker and accuser.

Also, there are 2 versions of baker and accuser: one per protocol. So before the protocol activation, you’ll have 5 processes running in parallel.

From:

  • Node version x.y.z
  • Baker_protocolN version x.y.z
  • Accuser_protocolN version x.y.z

To:

  • Node version x+1.y.z
  • Baker_protocolN version x+1.y.z
  • Baker_protocolN+1 version x+1.y.z
  • Accuser_protocolN version x+1.y.z
  • Accuser_protocolN+1 version x+1.y.z

It’s not possible to have Node version x+1.y.z with Baker_protocolN version x.y.z

Upgrade it

You will need new binaries by building them. Or if they are available on serokell/tezos-packaging repository.

Or you can use the script download_last_tezos_binaries_into.sh.

Start by updating the configuration (here we use Nairobi as protocol version N+1) as follow:


  "octez_binaries_home": "octez_binaries_nairobi", # Change it by prefixing protocol, you don't want to erase running process
  "network": "ghostnet", # target your network
  "protocol": "Nairob", # Have to be the name of the protocol suffixing binaries in serokell repo here Nairob
  

And execute this command:


./initialize/tezos/download_last_tezos_binaries_into.sh script_conf.json

Now you should have all new binaries in the repository:


/home//octez_binaries_nairobi

You will need to:

       - Upgrade the current configuration of accuser baker and node
       - Configure the protocol N+1 baker
       - Configure the protocol N+1 accuser

Upgrade current conf of accuser baker and node

Upgrade your node configuration

Open the file:


/etc/systemd/system/octez-node.service

To change the binary to use the new downloaded one. For example, if you kept thedefault configuration (you’ll need root permission to access):


/home/tezosbaker/octez_binaries_nairobi/octez-node

Configure the protocol N+1 baker

Start by copying the current systemd config with the option -old suffix. This will identify the “old” protocol:


sudo cp /etc/systemd/system/octez-baker.service /etc/systemd/system/octez-baker-old.service

Then open the file and change the binary to use the new downloaded as follow:


/home/tezosbaker/octez_binaries_nairobi/octez-baker-PtNairob

In the end, the result is:

  • Baker_protocolN version x+1.y.z
  • Baker_protocolN+1 version x+1.y.z

Configure the protocol N+1 accuser

Following the same process of baker for accuser:


sudo cp /etc/systemd/system/octez-accuser.service /etc/systemd/system/octez-accuser-old.service

and


/home/tezosbaker/octez_binaries_nairobi/octez-accuser-PtNairob

In the end, the result is:

       - Accuser_protocolN version x+1.y.z
       - Accuser_protocolN+1 version x+1.y.z

Reload the config, stop and start the process

Use the following command to reload the systemd config:


sudo systemctl daemon-reload

And start and restart all the services:


sudo systemctl restart octez-baker-old.service octez-accuser-old.service octez-baker.service octez-accuser.service

The binary of the new protocol (eg, octez-baker-PtNairob) will start and the log will be:


Waiting for protocol PtNairob to start...

After the protocol upgrade

You can remove the configuration of the old baker and accuser. By stopping them and deleting the systemd configuration:


sudo systemctl stop octez-accuser-old.service
sudo systemctl stop octez-baker-old.service

and remove the systemd conf:


sudo rm /etc/systemd/system/octez-baker-old.service /etc/systemd/system/octez-accuser-old.service

How to shutdown and uninstall your baker

Your Node, baker and accuser are managed by systemd.

To stop to bake you can stop your process, delete the created user, and the systemd conf.


sudo systemctl stop octez-node.service octez-baker.service octez-accuser.service
userdel -r 
sudo rm /etc/systemd/system/octez-node.service /etc/systemd/system/octez-baker.service /etc/systemd/system/octez-accuser.service

Conclusion

To set up your node (if you are ready to trust a 3rd party):

       - if you prefer to deal with a UI, using Kiln.
       - if you want a CLI to build your baker, bakebuddy-cli is available.

If you prefer a less user-friendly but transparent code using this script. It is entirely open source, PR are accepted!

⚠️ This post was written in 2023-June and is truthful in the current context. Because the Tezos chain is upgradable through self-amendment it can change. Currently, there is discussion around how delegation works, adaptative inflation and the introduction of a new co-baking operation where co-bake is delegate + risk (to be slashed) and immobilization (freeze).

If necessary, we will follow up the protocol upgrade and write another post.

Useful resources

If you want to know more about Marigold, please follow us on social media (Twitter, Reddit, Linkedin)!

Scroll to top