Skip to content

Commit 6116b06

Browse files
committed
docs: enhance the era markers runbook
1 parent 6ad37fc commit 6116b06

File tree

1 file changed

+128
-52
lines changed

1 file changed

+128
-52
lines changed

docs/runbook/era-markers/README.md

Lines changed: 128 additions & 52 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,8 @@
44

55
This is the process for storing Mithril activation eras markers on the Cardano chain (bootstrap and update operations).
66

7-
:warning: The process described in this document can lead to disturbed service of the associated Mihtril network. Thus it should be manipulated by experts only.
7+
> [!IMPORTANT]
8+
> :fire: The process described in this document can lead to disturbed service of the associated Mihtril network. Thus it should be manipulated by experts only.
89
910
## Pre-requisites
1011

@@ -16,36 +17,119 @@ This is the process for storing Mithril activation eras markers on the Cardano c
1617

1718
## Setup
1819

20+
### Setup environment variables
21+
1922
Export the environment variables needed to complete the process:
2023

2124
```bash
22-
$ export CARDANO_NODE_SOCKET_PATH=**PATH_TO_YOUR_NODE_SOCKET**
23-
$ export CARDANO_TESTNET_MAGIC=**YOUR_TESTNET_MAGIC**
24-
$ export CARDANO_WALLET_PATH=**PATH_TO_YOUR_KEYPAIRS**
25-
$ export ERA_ACTIVATION_SECRET_KEY=**YOUR_ERA_ACTIVATION_SECRET_KEY**
26-
$ export ASSETS_PATH=**YOUR_ASSETS_PATH**
25+
export CARDANO_CLI=**CARDANO_CLI_COMMAND**
26+
export CARDANO_NODE_SOCKET_PATH=**PATH_TO_YOUR_NODE_SOCKET**
27+
export CARDANO_WALLET_PATH=**PATH_TO_YOUR_KEYPAIRS**
28+
export ERA_ACTIVATION_SECRET_KEY=**YOUR_ERA_ACTIVATION_SECRET_KEY**
29+
export ASSETS_PATH=**YOUR_ASSETS_PATH**
30+
export SCRIPT_TX_VALUE=**MINIUM_SCRIPT_TX_VALUE**
31+
```
32+
33+
A common value for the transaction amount used when a script transaction is made is:
34+
35+
```bash
36+
export SCRIPT_TX_VALUE=2000000
37+
```
38+
39+
Compute the network magic parameter that handles both the Cardano mainnet and Cardano test networks:
40+
41+
- If this is for a testing network
42+
43+
```bash
44+
export CARDANO_TESTNET_MAGIC=**YOUR_TESTNET_MAGIC**
45+
export CARDANO_NETWORK_MAGIC="--testnet-magic $CARDANO_TESTNET_MAGIC"
46+
```
47+
48+
- If this is for the `mainnet`
49+
50+
```bash
51+
export CARDANO_NETWORK_MAGIC="--mainnet"
2752
```
2853

2954
Compute the current Cardano era:
3055

3156
```bash
32-
CARDANO_ERA=$(cardano-cli query tip --testnet-magic $CARDANO_TESTNET_MAGIC | jq -r '.era |= ascii_downcase | .era')
57+
export CARDANO_ERA=$($CARDANO_CLI query tip $CARDANO_NETWORK_MAGIC --socket-path $CARDANO_NODE_SOCKET_PATH | jq -r '.era |= ascii_downcase | .era')
58+
```
59+
60+
### Prepare era markers
61+
62+
> [!IMPORTANT]
63+
> :fire: A misconfiguration of the era markers can cause disturbed service on a Mithril network. The `CURRENT_ERA_EPOCH` and `NEXT_ERA_EPOCH` must be selected very cautiously.
64+
65+
#### If there is only one supported era
66+
67+
Set the epoch at which the era is active:
68+
69+
```bash
70+
export CURRENT_ERA_EPOCH=**ERA_FIRST_ACTIVATION_EPOCH**
71+
```
72+
73+
Create the datum file for a unique era:
74+
75+
```bash
76+
./mithril-aggregator era generate-tx-datum --current-era-epoch $CURRENT_ERA_EPOCH --era-markers-secret-key $ERA_ACTIVATION_SECRET_KEY --target-path $ASSETS_PATH/mithril-era-datum.json
3377
```
3478

35-
Set the transaction amount used when a script transaction is made:
79+
#### If there are two supported era
80+
81+
Set the epoch at which the current era and the next era are active (the `CURRENT_ERA_EPOCH` must be lower than the current epoch and the `NEXT_ERA_EPOCH` must be set to a strictly greater epoch than the current epoch):
3682

3783
```bash
38-
$ export SCRIPT_TX_VALUE=2000000
84+
export CURRENT_ERA_EPOCH=**CURRENT_ERA_FIRST_ACTIVATION_EPOCH**
85+
export NEXT_ERA_EPOCH=**NEXT_ERA_FIRST_ACTIVATION_EPOCH**
86+
```
87+
88+
Create the datum file for two eras:
89+
90+
```bash
91+
./mithril-aggregator era generate-tx-datum --current-era-epoch $CURRENT_ERA_EPOCH --next-era-epoch $NEXT_ERA_EPOCH --era-markers-secret-key $ERA_ACTIVATION_SECRET_KEY --target-path $ASSETS_PATH/mithril-era-datum.json
92+
```
93+
94+
#### Verify the produced era marker
95+
96+
> [!IMPORTANT]
97+
> :fire: The `mithril-aggregator` binary used to create the era markers must imperatively be compiled with all the targeted supported eras.
98+
99+
Verify that the produced era markers are exactly what is expected with the following command:
100+
101+
```bash
102+
cat $ASSETS_PATH/mithril-era-datum.json| jq -r '.fields[].bytes' | tr '\n' ' ' | xxd -r -p | jq
103+
```
104+
105+
An example output of the command is:
106+
107+
```json
108+
{
109+
"markers": [
110+
{
111+
"name": "thales",
112+
"epoch": 1
113+
},
114+
{
115+
"name": "pythagoras",
116+
"epoch": 723
117+
}
118+
],
119+
"signature": "fdcd45debabc148ef11c0bf71e42b7e583102dd5b8e486cd621a18e56136a57ff4f7bf9d036aed6148328a30a20eb6e79422ea4d1cc613e0bf97e14da64a5f00"
120+
}
39121
```
40122

41123
## Bootstrap Era Markers: Write a transaction with the first version of datum on chain
42124

43-
:warning: This step must be done only once for an address
125+
> [!IMPORTANT]
126+
> :fire: This step must be done only once for an address when no prior datum has been written in a UTxO.
127+
> Otherwise, you need to refer to this [section](#update-era-markers-write-a-new-version-of-datum-on-chain)
44128
45129
Verify that the payment address has funds:
46130

47131
```bash
48-
$ cardano-cli query utxo --address $(cat $CARDANO_WALLET_PATH/payment.addr) --testnet-magic $CARDANO_TESTNET_MAGIC
132+
$CARDANO_CLI query utxo --address $(cat $CARDANO_WALLET_PATH/payment.addr) $CARDANO_NETWORK_MAGIC --socket-path $CARDANO_NODE_SOCKET_PATH
49133
TxHash TxIx Amount
50134
--------------------------------------------------------------------------------------
51135
f0c0345f151f9365fbbb4e7afa217e56b987d9e91fd754ca609d9dfec97275c7 0 10000000000 lovelace + TxOutDatumNone
@@ -54,57 +138,53 @@ f0c0345f151f9365fbbb4e7afa217e56b987d9e91fd754ca609d9dfec97275c7 0 10
54138
And create the variable `TX_IN={TxHash}#{TxIn}` by replacing with values from the previous command:
55139

56140
```bash
57-
$ TX_IN=f0c0345f151f9365fbbb4e7afa217e56b987d9e91fd754ca609d9dfec97275c7#0
58-
```
59-
60-
Create the initial datum file:
61-
62-
```bash
63-
$ ./mithril-aggregator era generate-tx-datum --current-era-epoch 1 --era-markers-secret-key $ERA_ACTIVATION_SECRET_KEY --target-path $ASSETS_PATH/mithril-era-datum-1.json
141+
TX_IN=f0c0345f151f9365fbbb4e7afa217e56b987d9e91fd754ca609d9dfec97275c7#0
64142
```
65143

66144
Now create the bootstrap transaction with datum:
67145

68146
```bash
69-
$ cardano-cli $CARDANO_ERA transaction build --testnet-magic $CARDANO_TESTNET_MAGIC \
147+
$CARDANO_CLI $CARDANO_ERA transaction build $CARDANO_NETWORK_MAGIC \
70148
--tx-in $TX_IN \
71149
--tx-out $(cat $CARDANO_WALLET_PATH/payment.addr)+$SCRIPT_TX_VALUE \
72-
--tx-out-inline-datum-file $ASSETS_PATH/mithril-era-datum-1.json \
150+
--tx-out-inline-datum-file $ASSETS_PATH/mithril-era-datum.json \
73151
--change-address $(cat $CARDANO_WALLET_PATH/payment.addr) \
74-
--out-file $ASSETS_PATH/tx.raw
152+
--out-file $ASSETS_PATH/tx.raw \
153+
--socket-path $CARDANO_NODE_SOCKET_PATH
75154
Estimated transaction fee: Lovelace 168669
76155
```
77156

78157
Then sign the transaction:
79158

80159
```bash
81-
$ cardano-cli $CARDANO_ERA transaction sign \
160+
$CARDANO_CLI $CARDANO_ERA transaction sign \
82161
--tx-body-file $ASSETS_PATH/tx.raw \
83162
--signing-key-file $CARDANO_WALLET_PATH/payment.skey \
84-
--testnet-magic $CARDANO_TESTNET_MAGIC \
163+
$CARDANO_NETWORK_MAGIC \
85164
--out-file $ASSETS_PATH/tx.signed
86165
```
87166

88167
And submit it:
89168

90169
```bash
91-
$ cardano-cli $CARDANO_ERA transaction submit \
92-
--testnet-magic $CARDANO_TESTNET_MAGIC \
93-
--tx-file $ASSETS_PATH/tx.signed
170+
$CARDANO_CLI $CARDANO_ERA transaction submit \
171+
$CARDANO_NETWORK_MAGIC \
172+
--tx-file $ASSETS_PATH/tx.signed \
173+
--socket-path $CARDANO_NODE_SOCKET_PATH
94174
Transaction successfully submitted.
95175
```
96176

97177
Also get the transaction id:
98178

99179
```bash
100-
$ cardano-cli transaction txid --tx-file $ASSETS_PATH/tx.signed
180+
$CARDANO_CLI transaction txid --tx-file $ASSETS_PATH/tx.signed
101181
6518b3cea0b49b55746ec61148e7c60ab042959d534f6bb6e8f6a844d4af69fb
102182
```
103183

104184
We need to wait a few seconds before the transaction is available and we can see the initial datum for the script address:
105185

106186
```bash
107-
$ cardano-cli query utxo --address $(cat $CARDANO_WALLET_PATH/payment.addr) --testnet-magic $CARDANO_TESTNET_MAGIC
187+
$CARDANO_CLI query utxo --address $(cat $CARDANO_WALLET_PATH/payment.addr) $CARDANO_NETWORK_MAGIC --socket-path $CARDANO_NODE_SOCKET_PATH
108188
TxHash TxIx Amount
109189
--------------------------------------------------------------------------------------
110190
6518b3cea0b49b55746ec61148e7c60ab042959d534f6bb6e8f6a844d4af69fb 0 1500000 lovelace + TxOutDatumInline ReferenceTxInsScriptsInlineDatumsInBabbageEra (ScriptDataConstructor 0 [ScriptDataBytes "[{\"n\":\"thales\",\"e\":1}]",ScriptDataBytes "\165\143\232\227\&6\244e\222\211\187\167\197\167\175\229\181\162o/\182[|Nnt.h\ACKE\241=\242\139\242\182:a\204r\217\200&\190I\SO,\US\DLE\152\217U\223P5\128\164\232\153\181\ETB8\132\227\SO"])
@@ -116,7 +196,7 @@ Optional: We can retrieve the initial value stored in the datum with the cardano
116196
The full utxo json representation:
117197

118198
```bash
119-
$ cardano-cli query utxo --address $(cat $CARDANO_WALLET_PATH/payment.addr) --testnet-magic $CARDANO_TESTNET_MAGIC --out-file temp.json && cat temp.json | jq '. [] | select(.inlineDatum | . != null and . != "")'
199+
$CARDANO_CLI query utxo --address $(cat $CARDANO_WALLET_PATH/payment.addr) $CARDANO_NETWORK_MAGIC --socket-path $CARDANO_NODE_SOCKET_PATH --out-file temp.json && cat temp.json | jq '. [] | select(.inlineDatum | . != null and . != "")'
120200
{
121201
"address": "addr_test1qzzngukkj9ydjemqjlgfn42sevy2xnvauay46weushlpuq9thd4ray00csjssf4sxftv04xeequ3xfx72nujg9y4d5ysgkxxlh",
122202
"datum": null,
@@ -141,12 +221,14 @@ $ cardano-cli query utxo --address $(cat $CARDANO_WALLET_PATH/payment.addr) --te
141221

142222
## Update Era Markers: Write a new version of datum on chain
143223

144-
:warning: This step must be used anytime the era markers must be updated on chain
224+
> [!IMPORTANT]
225+
> :fire: This step must be used anytime the era markers must be updated on chain for an address when prior datum has already been written in a UTxO.
226+
> Otherwise, you need to refer to this [section](#bootstrap-era-markers-write-a-transaction-with-the-first-version-of-datum-on-chain)
145227
146228
Retrieve the utxo of the payment address:
147229

148230
```bash
149-
$ cardano-cli query utxo --address $(cat $CARDANO_WALLET_PATH/payment.addr) --testnet-magic $CARDANO_TESTNET_MAGIC
231+
$CARDANO_CLI query utxo --address $(cat $CARDANO_WALLET_PATH/payment.addr) $CARDANO_NETWORK_MAGIC --socket-path $CARDANO_NODE_SOCKET_PATH
150232
TxHash TxIx Amount
151233
--------------------------------------------------------------------------------------
152234
6518b3cea0b49b55746ec61148e7c60ab042959d534f6bb6e8f6a844d4af69fb 0 1500000 lovelace + TxOutDatumInline ReferenceTxInsScriptsInlineDatumsInBabbageEra (ScriptDataConstructor 0 [ScriptDataBytes "[{\"n\":\"thales\",\"e\":1}]",ScriptDataBytes "\165\143\232\227\&6\244e\222\211\187\167\197\167\175\229\181\162o/\182[|Nnt.h\ACKE\241=\242\139\242\182:a\204r\217\200&\190I\SO,\US\DLE\152\217U\223P5\128\164\232\153\181\ETB8\132\227\SO"])
@@ -156,66 +238,60 @@ $ cardano-cli query utxo --address $(cat $CARDANO_WALLET_PATH/payment.addr) --te
156238
And create the variable `TX_IN_DATUM={TxHash}#{TxIn}` by replacing with values from the previous command (where inline datumn are available):
157239

158240
```bash
159-
$ TX_IN_DATUM=6518b3cea0b49b55746ec61148e7c60ab042959d534f6bb6e8f6a844d4af69fb#0
241+
TX_IN_DATUM=6518b3cea0b49b55746ec61148e7c60ab042959d534f6bb6e8f6a844d4af69fb#0
160242
```
161243

162244
And create the variable `TX_IN_NO_DATUM={TxHash}#{TxIn}` by replacing with values from the previous command (where inline datumn are not available):
163245

164246
```bash
165-
$ TX_IN_NO_DATUM=6518b3cea0b49b55746ec61148e7c60ab042959d534f6bb6e8f6a844d4af69fb#1
166-
```
167-
168-
Create the updated datum file:
169-
170-
:warning: The options provided in the following command are for example only, you need to use adequately the options of the `era generate-tx-datum` command, which will depend on the operation you want to execute: announce an upcoming era or activate an upcoming era. This operation should be done very cautiously as a misconfiguration can lead to disturbed service of the network.
171-
172-
```bash
173-
$ ./mithril-aggregator era generate-tx-datum --current-era-epoch 1 --era-markers-secret-key $ERA_ACTIVATION_SECRET_KEY --target-path $ASSETS_PATH/mithril-era-datum-2.json
247+
TX_IN_NO_DATUM=6518b3cea0b49b55746ec61148e7c60ab042959d534f6bb6e8f6a844d4af69fb#1
174248
```
175249

176250
Now create the update transaction with datum:
177251

178252
```bash
179-
$ cardano-cli $CARDANO_ERA transaction build --testnet-magic $CARDANO_TESTNET_MAGIC \
253+
$CARDANO_CLI $CARDANO_ERA transaction build $CARDANO_NETWORK_MAGIC \
180254
--tx-in $TX_IN_DATUM \
181255
--tx-in $TX_IN_NO_DATUM \
182256
--tx-out $(cat $CARDANO_WALLET_PATH/payment.addr)+$SCRIPT_TX_VALUE \
183-
--tx-out-inline-datum-file $ASSETS_PATH/mithril-era-datum-2.json \
257+
--tx-out-inline-datum-file $ASSETS_PATH/mithril-era-datum.json \
184258
--change-address $(cat $CARDANO_WALLET_PATH/payment.addr) \
185-
--out-file $ASSETS_PATH/tx.raw
259+
--out-file $ASSETS_PATH/tx.raw \
260+
--socket-path $CARDANO_NODE_SOCKET_PATH
186261
Estimated transaction fee: Lovelace 179889
187262
```
188263

189264
Then sign the transaction:
190265

191266
```bash
192-
$ cardano-cli $CARDANO_ERA transaction sign \
267+
$CARDANO_CLI $CARDANO_ERA transaction sign \
193268
--tx-body-file $ASSETS_PATH/tx.raw \
194269
--signing-key-file $CARDANO_WALLET_PATH/payment.skey \
195-
--testnet-magic $CARDANO_TESTNET_MAGIC \
270+
$CARDANO_NETWORK_MAGIC \
196271
--out-file $ASSETS_PATH/tx.signed
197272
```
198273

199274
And submit it:
200275

201276
```bash
202-
$ cardano-cli $CARDANO_ERA transaction submit \
203-
--testnet-magic $CARDANO_TESTNET_MAGIC \
204-
--tx-file $ASSETS_PATH/tx.signed
277+
$CARDANO_CLI $CARDANO_ERA transaction submit \
278+
$CARDANO_NETWORK_MAGIC \
279+
--tx-file $ASSETS_PATH/tx.signed \
280+
--socket-path $CARDANO_NODE_SOCKET_PATH
205281
Transaction successfully submitted.
206282
```
207283

208284
Also get the transaction id:
209285

210286
```bash
211-
$ cardano-cli transaction txid --tx-file $ASSETS_PATH/tx.signed
287+
$CARDANO_CLI transaction txid --tx-file $ASSETS_PATH/tx.signed
212288
1fd4d3e131afe3c8b212772a3f3083d2fbc6b2a7b20e54e4ff08e001598818d8
213289
```
214290

215291
We need to wait a few seconds before the transaction is available and we can see the updated datum for the script address:
216292

217293
```bash
218-
$ cardano-cli query utxo --address $(cat $CARDANO_WALLET_PATH/payment.addr) --testnet-magic $CARDANO_TESTNET_MAGIC
294+
$CARDANO_CLI query utxo --address $(cat $CARDANO_WALLET_PATH/payment.addr) $CARDANO_NETWORK_MAGIC --socket-path $CARDANO_NODE_SOCKET_PATH
219295
TxHash TxIx Amount
220296
--------------------------------------------------------------------------------------
221297
1f139b47017c9c90d4622ac768e249d25d37ad4461db44a20486b7da72a78915 0 2000000 lovelace + TxOutDatumInline ReferenceTxInsScriptsInlineDatumsInBabbageEra (ScriptDataConstructor 0 [ScriptDataBytes "[{\"n\":\"thales\",\"e\":1},{\"n\":\"pythagoras\",\"e\":null}]",ScriptDataBytes "^P\EOT\248k3\196/\139\tU\173H\138\FS\194MD\240\153\227\142z\181\134\213\168\&2\222\219i1\246\NAK\\]\247\154U\143-^vmtq\204\207#\236\213\f\201\&1\152\145(\161\ETX;\183\128\195\r"])
@@ -227,7 +303,7 @@ We can retrieve the updated value stored in the datum with the cardano cli:
227303
The full utxo json representation:
228304

229305
```bash
230-
$ cardano-cli query utxo --address $(cat $CARDANO_WALLET_PATH/payment.addr) --testnet-magic $CARDANO_TESTNET_MAGIC --out-file temp.json && cat temp.json | jq '. [] | select(.inlineDatum | . != null and . != "")'
306+
$CARDANO_CLI query utxo --address $(cat $CARDANO_WALLET_PATH/payment.addr) $CARDANO_NETWORK_MAGIC --socket-path $CARDANO_NODE_SOCKET_PATH --out-file temp.json && cat temp.json | jq '. [] | select(.inlineDatum | . != null and . != "")'
231307
{
232308
"address": "addr_test1qzzngukkj9ydjemqjlgfn42sevy2xnvauay46weushlpuq9thd4ray00csjssf4sxftv04xeequ3xfx72nujg9y4d5ysgkxxlh",
233309
"datum": null,

0 commit comments

Comments
 (0)