# Adjust Node.Counter for KES

UPDATED: 11/26/24

{% hint style="info" %}
Credits to <img src="https://earncoinpool.com/images/coin_v3.png" alt="" data-size="line"> [Earn Coin Pool](https://earncoinpool.com/) for documenting the procedure.
{% endhint %}

{% hint style="info" %}
Did you know? \
\
"KES" stands for Key Evolving Signature
{% endhint %}

## Welcome!

There are two method you can use to Rollback your node.counter. Please review and choose the method you prefer.

{% hint style="info" %}
**Good to know:** This was created on July 2022 and process may change over time
{% endhint %}

{% tabs %}
{% tab title="CLI Method" %}

## Step 1 - Look up Operational Certificate Numbers

When it's time to update your KES you can run the following command on your block producer to confirm you have the correct Operational Certificate Numbers

{% hint style="info" %}
Note path to node.cert and adjust if needed. Path in example is based off [Coincashew](https://www.coincashew.com/coins/overview-ada/guide-how-to-build-a-haskell-stakepool-node/) guide for setting up a stake pool.
{% endhint %}

```
cardano-cli conway query kes-period-info --mainnet  \
  --op-cert-file $NODE_HOME/node.cert
```

Results should look similar to the following:

```
✓ The operational certificate counter agrees with the node protocol state counter
✓ Operational certificate's kes period is within the correct KES period interval
{
    "qKesNodeStateOperationalCertificateNumber": 4,
    "qKesCurrentKesPeriod": 505,
    "qKesOnDiskOperationalCertificateNumber": 5,
    "qKesRemainingSlotsInKesPeriod": 6832926,
    "qKesMaxKESEvolutions": 62,
    "qKesKesKeyExpiry": "2022-09-22T21:44:51Z",
    "qKesEndKesInterval": 558,
    "qKesStartKesInterval": 496,
    "qKesSlotsPerKesPeriod": 129600
}
```

{% hint style="info" %}
This line is the Operational Certificate that your pool used to mint its last block\
\
"qKes**NodeState**OperationalCertificateNumber": 4,
{% endhint %}

{% hint style="success" %}
This line is the counter number of your current Operational Certificate:\
"qKes**OnDisk**OperationalCertificateNumber": 5,
{% endhint %}

{% hint style="danger" %}
If these number are **NOT** the same, as for the example above **NodeState**=4 and **OnDisk**=5 then you need to rollback your counter. In this case the node counter would need to be rolled back from 5 to 4\
\
If, for example, **NodeState** and **OnDisk** =4, then you are all set and can proceed to renewing your KES following the normal procedure [here](https://ecp.gitbook.io/how-to-guides-for-coincashew-method-cardano-spos/maintenance-and-daily-operations/how-to-guides-for-spos-using-coincashew-method/renew-kes-keys).<br>

✅Also If you have **never** minted a block since you started your pool, then you will need to rollback your counter back to 0<br>
{% endhint %}

## Step 2 - Check current value of your node.counter

:warning:**ON AIR GAPPED MACHINE**:

navigate to where your node.counter file is. :file\_folder:In this example it's located in our home directory in a folder called: cold-keys. So we run this command to output node.counter information.

```javascript
cat $HOME/cold-keys/node.counter
```

\
:writing\_hand:**Take note that "Next certificate issue number: x"** <br>

{% hint style="info" %}
node.counter MUST be **ONE** greater than "qKes**NodeState**OperationalCertificateNumber" value.
{% endhint %}

For example, "qKes**NodeState**OperationalCertificateNumber": 4, So our node.counter should read "Next certificate issue number: 5"

If your "Next certificate issue number" is one higher you are all set and can continue to normal renew KES process found [here](https://ecp.gitbook.io/how-to-guides-for-coincashew-method-cardano-spos/maintenance-and-daily-operations/how-to-guides-for-spos-using-coincashew-method/renew-kes-keys).

{% hint style="warning" %}
:warning:Only if it's not one higher should you proceed to the next [step](#step-3-kes-rollback)
{% endhint %}

## Step 3 - KES Rollback

If you need to adjust your node.counter navigate to your node.counter file on your Air Gapped Machine.

{% hint style="warning" %}
In this example it is located in our home directory in a folder called: cold-keys. If your file is not located there please adjust file path.
{% endhint %}

{% hint style="danger" %}
:octagonal\_sign: If you have not backed up your node.counter file now is a good time to do that before you proceed.
{% endhint %}

\
:warning:**ON AIR GAPPED MACHINE**:\
Since our "qKes**NodeState**OperationalCertificateNumber": 4, we want it to be "4+1".  Please replace 4 with your "qKes**NodeState**OperationalCertificateNumber":  value. \
\
Edit node.counter using following commands.&#x20;

```
cd $HOME/cold-keys/
cardano-cli conway node new-counter \
--cold-verification-key-file node.vkey \
--counter-value $((4 + 1)) \
--operational-certificate-issue-counter-file node.counter
```

## Final  Step

Now that your node.counter is adjusted you may proceed to renew your KES following the normal procedure [here](https://ecp.gitbook.io/how-to-guides-for-coincashew-method-cardano-spos/maintenance-and-daily-operations/how-to-guides-for-spos-using-coincashew-method/renew-kes-keys).<br>

### Congratulations you did it!

{% endtab %}

{% tab title="Manual Method" %}

## Step 1 - Look up OpcertC

Navigate to your pool on [adapools.org](https://adapools.org/). Once on your pool page click on the blocks tab and look at your last block. Look at the OpCertC column and make note of the number.\
![](https://2549074837-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F8PjW7zFPfe4PgCsPtkZx%2Fuploads%2FzN7JGdXee9Bh5q3W4XLX%2Fada_pools_OpCertC.png?alt=media\&token=175e1439-65ba-454e-a315-0f567bc4fe09)

{% hint style="danger" %}
If you have never made a block then you will need to set your **"Next certificate issue number: 0" and "cborHex" line to 0.** cborHex example: xxx0xxxxx....\
See [Step 3](#step-3-kes-rollback) below for more details
{% endhint %}

## Step 2 - Check current value of your node.counter

:warning:**ON AIR GAPPED MACHINE**:

navigate to where your node.counter file is. :file\_folder:In this example it's located in our home directory in a folder called: cold-keys. So we run this command to output node.counter information.

```javascript
cat $HOME/cold-keys/node.counter
```

\
:writing\_hand:**Take note that "Next certificate issue number: x"** <br>

{% hint style="info" %}
node.counter MUST be **ONE** greater than the most recently created block's OpCertC value.
{% endhint %}

For example, if your OpCertC value is 4 for your last block, then your node.counter should read "Next certificate issue number: 5"

If your "Next certificate issue number" is one higher you are all set and can continue to normal renew KES process found [here](https://ecp.gitbook.io/how-to-guides-for-coincashew-method-cardano-spos/maintenance-and-daily-operations/how-to-guides-for-spos-using-coincashew-method/renew-kes-keys).

{% hint style="warning" %}
:warning:Only if it's not one higher should you proceed to the next [step](#step-3-kes-rollback)
{% endhint %}

## Step 3 - KES Rollback

If you need to adjust your node.counter navigate to your node.counter file on your Air Gapped Machine. In this example it is located in our home directory in a folder called: cold-keys. If your file is not located there please adjust file path.

{% hint style="danger" %}
:octagonal\_sign: If you have not backed up your node.counter file now is a good time to do that before you proceed.
{% endhint %}

\
You can edit node.counter using nano command.

```
cd $home/cold-keys
nano node.counter
```

The file should look similar to the following. (We replaced letters and numbers after four digits just as an example to make easier to read.)

```
{
    "type": "NodeOperationalCertificateIssueCounter",
    "description": "Next certificate issue number: 5",
    "cborHex": "8205xxxxxxxxxxxxxxxxxxxxxxxxxx"
}
```

Navigate to this line: **"description":  "Next certificate issue number: x"**  and change "x" to one number higher than your OpCertC number.<br>

Then navigate to "cborHex" line:

{% hint style="warning" %}
If your desired next certificate issue is 9 or under:

You must change the 4th number to match your next certificate issue number.\
\
For example if your "Next certificate issue number: 5" then the 4th digit in the cborHex should match this number.\
example: xxx5xxxxx.....
{% endhint %}

{% hint style="info" %}
If your desired next certificate issue is 15 or under:

You must change the 4th number to the hex of the number to match your next certificate issue number. \
\
For example the hex for 13 is "d" so the fourth digit should be "d"\
xxxdxxxxx.....\
\
you can use this [converter](https://coolconversion.com/math/binary-octal-hexa-decimal/_decimal____hexadecimal_) to find the hex value\
![](https://2549074837-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F8PjW7zFPfe4PgCsPtkZx%2Fuploads%2FsBEp5mtBGBNflJ3E0iFd%2Fhex_converter.png?alt=media\&token=e55276b7-bcd5-461d-bae9-d6aa3976101e)
{% endhint %}

{% hint style="warning" %}
If your desired next certificate issue is OVER 15:

You must change the 3rd and 4th number to the hex of the number to match your next certificate issue number. \
\
For example the hex for 16 is "10" so the third digit should be"1" and the fourth digit should be "0"\
xx10xxxxx.....\
you can use this [converter](https://coolconversion.com/math/binary-octal-hexa-decimal/_decimal____hexadecimal_) to find the hex value\
![](https://2549074837-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F8PjW7zFPfe4PgCsPtkZx%2Fuploads%2Fb6yiOGD4WhYVQPxVsmnq%2Fhex_converter_16.png?alt=media\&token=f318e75e-fc19-4075-9fd9-648d666597c6)
{% endhint %}

For our example we wanted our counter to be adjusted so the next certificate issue was 5. So it should look similar to this:

```
{
    "type": "NodeOperationalCertificateIssueCounter",
    "description": "Next certificate issue number: 5",
    "cborHex": "8205xxxxxxxxxxxxxxxxxxxxxxxxxx"
}
```

{% hint style="info" %}
(We replaced letters and numbers after four digits just as an example to make easier to read.)
{% endhint %}

## Step 4

Now that your node.counter is adjusted you may proceed to renew your KES following the normal procedure [here](https://ecp.gitbook.io/how-to-guides-for-coincashew-method-cardano-spos/maintenance-and-daily-operations/how-to-guides-for-spos-using-coincashew-method/renew-kes-keys).<br>

### Congratulations you did it!

{% endtab %}
{% endtabs %}

## Contributors&#x20;

Thanks to the following pools for helping to put together these guides. Please consider delegating to their pools to support them.  Are you a pool? Consider buying them a coffee

![](https://img.cexplorer.io/a/5/7/2/1/pool12wpfng6cu7dz38yduaul3ngfm44xhv5xmech68m5fwe4wu77udd.png) [Apex Cardano Pool - Ticker: APEX](https://cexplorer.io/pool/pool12wpfng6cu7dz38yduaul3ngfm44xhv5xmech68m5fwe4wu77udd)

![](https://img.cexplorer.io/7/e/1/9/f/pool16cdtqyk0fvxzfkhjg3esjcuty4tnlpds5lj0lkmqmwdjyzaj7p8.png)  [Earn Coin Pool - Ticker: ECP](https://cexplorer.io/pool/pool16cdtqyk0fvxzfkhjg3esjcuty4tnlpds5lj0lkmqmwdjyzaj7p8)

&#x20;![](https://img.cexplorer.io/9/0/1/d/4/pool1zn4wnk52kmfjy9mw4z85p6wn9kzrn94l9h5gys8r2k2w57mdnhh.png) [Envy Stake Pool - Ticker ENVY](https://cexplorer.io/pool/pool1zn4wnk52kmfjy9mw4z85p6wn9kzrn94l9h5gys8r2k2w57mdnhh)

![](https://2549074837-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F8PjW7zFPfe4PgCsPtkZx%2Fuploads%2FljMQsj8QrPi6cWmKyBZK%2Fpgwad_new_90x50.png?alt=media\&token=cb1ee893-6992-42e4-b480-04067a6ed701) [PGWAD](https://twitter.com/PgwadaS)&#x20;

![xSPO Alliance Logo](https://2549074837-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F8PjW7zFPfe4PgCsPtkZx%2Fuploads%2F0sqzqoHnqVXizi2RHABd%2FxSPO_NFT_64x64.png?alt=media\&token=1c1b130e-26df-4b1e-8e0e-e85fae1ee73e) [xSPO Alliance](http://xspo-alliance.org/discord)
