Skip to content

Commit ffff755

Browse files
authored
Merge pull request #1431 from input-output-hk/jpraynaud/1428-use-cardano-chain-era-reader-devnet
Use `CardanoChain` era reader in end to end test
2 parents 17c879d + 33b063f commit ffff755

File tree

17 files changed

+375
-60
lines changed

17 files changed

+375
-60
lines changed

Cargo.lock

Lines changed: 2 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

docs/runbook/era-markers/README.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@ $ TX_IN=f0c0345f151f9365fbbb4e7afa217e56b987d9e91fd754ca609d9dfec97275c7#0
4949

5050
Create the initial datum file:
5151
```bash
52-
$ ./mithril-aggregator era generate-tx-datum --current-era-epoch 1 --era-markers-secret-key $ERA_ACTIVATION_SECRET_KEY > $ASSETS_PATH/mithril-era-datum-1.json
52+
$ ./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
5353
```
5454

5555
Now create the bootstrap transaction with datum:
@@ -150,7 +150,7 @@ Create the updated datum file:
150150
: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.
151151

152152
```bash
153-
$ ./mithril-aggregator era generate-tx-datum --current-era-epoch 1 --era-markers-secret-key $ERA_ACTIVATION_SECRET_KEY > $ASSETS_PATH/mithril-era-datum-2.json
153+
$ ./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
154154
```
155155

156156
Now create the update transaction with datum:

docs/website/root/manual/developer-docs/nodes/mithril-aggregator.md

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -300,7 +300,7 @@ You can run 'era generate-tx-datum' to create the transaction datum file that wi
300300
**Case 1**: If there is only one supported era in the code, create the datum file:
301301

302302
```bash
303-
./mithril-aggregator era generate-tx-datum --current-era-epoch **EPOCH_AT_WHICH_CURRENT_ERA_STARTS** --era-markers-secret-key **YOUR_ERA_ACTIVATION_SECRET_KEY**
303+
./mithril-aggregator era generate-tx-datum --current-era-epoch **EPOCH_AT_WHICH_CURRENT_ERA_STARTS** --era-markers-secret-key **YOUR_ERA_ACTIVATION_SECRET_KEY** --target-path **TARGET_PATH**
304304
```
305305

306306
You should see something like:
@@ -312,13 +312,13 @@ You should see something like:
312312
**Case 2**: If there are two supported eras in the code and the activation epoch of the upcoming era is not yet known, run the command:
313313

314314
```bash
315-
./mithril-aggregator era generate-tx-datum --current-era-epoch **EPOCH_AT_WHICH_CURRENT_ERA_STARTS** --era-markers-secret-key **YOUR_ERA_ACTIVATION_SECRET_KEY**
315+
./mithril-aggregator era generate-tx-datum --current-era-epoch **EPOCH_AT_WHICH_CURRENT_ERA_STARTS** --era-markers-secret-key **YOUR_ERA_ACTIVATION_SECRET_KEY** --target-path **TARGET_PATH**
316316
```
317317

318318
**Case 3**: If there are two supported eras in the code and the activation epoch of the era switch is known to be at the following epoch, run the command:
319319

320320
```bash
321-
./mithril-aggregator era generate-tx-datum --current-era-epoch **EPOCH_AT_WHICH_CURRENT_ERA_STARTS** --next-era-epoch **EPOCH_AT_WHICH_NEXT_ERA_STARTS** --era-markers-secret-key **YOUR_ERA_ACTIVATION_SECRET_KEY**
321+
./mithril-aggregator era generate-tx-datum --current-era-epoch **EPOCH_AT_WHICH_CURRENT_ERA_STARTS** --next-era-epoch **EPOCH_AT_WHICH_NEXT_ERA_STARTS** --era-markers-secret-key **YOUR_ERA_ACTIVATION_SECRET_KEY** --target-path **TARGET_PATH**
322322
```
323323

324324
## Release the build and run the binary 'tools' command
@@ -485,5 +485,6 @@ Here is a list of the available parameters:
485485
| `current_era_epoch` | `--current-era-epoch` | - | `CURRENT_ERA_EPOCH` | Epoch at which current era starts. | - | - | - | :heavy_check_mark: |
486486
| `next_era_epoch` | `--next-era-epoch` | - | `NEXT_ERA_EPOCH` | Epoch at which the next era starts. If not specified and an upcoming era is available, it will announce the next era. If specified, it must be strictly greater than `current-epoch-era` | - | - | - | - |
487487
| `era_markers_secret_key` | `--era-markers-secret-key` | - | `ERA_MARKERS_SECRET_KEY` | Era markers secret key that is used to verify the authenticity of the era markers on the chain. | - | - | - | :heavy_check_mark: |
488+
| `target_path` | `--target-path` | - | - | Path of the file to export the payload to. | - | - | - | - |
488489

489490
The `tools recompute-certificates-hash` command has no dedicated parameters.

mithril-aggregator/Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
[package]
22
name = "mithril-aggregator"
3-
version = "0.4.25"
3+
version = "0.4.26"
44
description = "A Mithril Aggregator server"
55
authors = { workspace = true }
66
edition = { workspace = true }

mithril-aggregator/src/commands/era_command.rs

Lines changed: 14 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
use std::{fs::File, io::Write, path::PathBuf};
2+
13
use anyhow::Context;
24
use clap::{Parser, Subcommand};
35
use config::{builder::DefaultState, ConfigBuilder};
@@ -82,6 +84,10 @@ pub struct GenerateTxDatumEraSubCommand {
8284
/// Era Markers Secret Key
8385
#[clap(long, env = "ERA_MARKERS_SECRET_KEY")]
8486
era_markers_secret_key: HexEncodedEraMarkersSecretKey,
87+
88+
/// Target Path
89+
#[clap(long)]
90+
target_path: PathBuf,
8591
}
8692

8793
impl GenerateTxDatumEraSubCommand {
@@ -93,14 +99,14 @@ impl GenerateTxDatumEraSubCommand {
9399
EraMarkersVerifierSecretKey::from_json_hex(&self.era_markers_secret_key)
94100
.with_context(|| "json hex decode of era markers secret key failure")?;
95101
let era_markers_signer = EraMarkersSigner::from_secret_key(era_markers_secret_key);
96-
print!(
97-
"{}",
98-
era_tools.generate_tx_datum(
99-
Epoch(self.current_era_epoch),
100-
self.next_era_epoch.map(Epoch),
101-
&era_markers_signer
102-
)?
103-
);
102+
let tx_datum = era_tools.generate_tx_datum(
103+
Epoch(self.current_era_epoch),
104+
self.next_era_epoch.map(Epoch),
105+
&era_markers_signer,
106+
)?;
107+
108+
let mut target_file = File::create(&self.target_path)?;
109+
target_file.write_all(tx_datum.as_bytes())?;
104110

105111
Ok(())
106112
}
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
0.2.2
1+
0.2.3

mithril-test-lab/mithril-devnet/devnet-mkfiles.sh

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,9 @@ SCRIPT_DIRECTORY=$(dirname $0)
2525
# Generate the pools scripts
2626
. ${SCRIPT_DIRECTORY}/mkfiles/mkfiles-pools.sh
2727

28+
# Generate the Mithril era scripts
29+
. ${SCRIPT_DIRECTORY}/mkfiles/mkfiles-mithril.sh
30+
2831
# Generate the query scripts
2932
. $SCRIPT_DIRECTORY/mkfiles/mkfiles-query.sh
3033

Lines changed: 88 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,88 @@
1+
# Create Mithril era keypair and address
2+
ADDR=mithril-era
3+
4+
## Payment address keys
5+
./cardano-cli address key-gen \
6+
--verification-key-file addresses/${ADDR}.vkey \
7+
--signing-key-file addresses/${ADDR}.skey
8+
9+
## Payment addresses
10+
./cardano-cli address build \
11+
--payment-verification-key-file addresses/${ADDR}.vkey \
12+
--testnet-magic ${NETWORK_MAGIC} \
13+
--out-file addresses/${ADDR}.addr
14+
15+
## Send funds to Mithril era address
16+
N=1
17+
SCRIPT_TX_VALUE=2000000
18+
AMOUNT_TRANSFERRED=$(( SCRIPT_TX_VALUE * 10 ))
19+
cat >> era-mithril.sh <<EOF
20+
#!/usr/bin/env bash
21+
set -e
22+
23+
EOF
24+
25+
cat >> era-mithril.sh <<EOF
26+
# Send funds to Mithril era address
27+
## Get the UTxO of utxo${N}
28+
TX_IN=\$(CARDANO_NODE_SOCKET_PATH=node-pool${N}/ipc/node.sock ./cardano-cli query utxo \\
29+
--testnet-magic ${NETWORK_MAGIC} --address \$(cat addresses/utxo${N}.addr) --out-file /dev/stdout \\
30+
| jq -r 'to_entries | [last] | .[0].key')
31+
32+
## Build the transaction
33+
CARDANO_NODE_SOCKET_PATH=node-pool${N}/ipc/node.sock ./cardano-cli transaction build \\
34+
--tx-in \${TX_IN} \\
35+
--tx-out \$(cat addresses/${ADDR}.addr)+${AMOUNT_TRANSFERRED} \\
36+
--change-address \$(cat addresses/utxo${N}.addr) \\
37+
--testnet-magic ${NETWORK_MAGIC} \\
38+
--invalid-hereafter 100000 \\
39+
--out-file node-pool${N}/tx/tx${N}-era-funds.txbody
40+
41+
## Sign the transaction
42+
CARDANO_NODE_SOCKET_PATH=node-pool${N}/ipc/node.sock ./cardano-cli transaction sign \\
43+
--signing-key-file addresses/utxo${N}.skey \\
44+
--testnet-magic ${NETWORK_MAGIC} \\
45+
--tx-body-file node-pool${N}/tx/tx${N}-era-funds.txbody \\
46+
--out-file node-pool${N}/tx/tx${N}-era-funds.tx
47+
48+
## Submit the transaction
49+
CARDANO_NODE_SOCKET_PATH=node-pool${N}/ipc/node.sock ./cardano-cli transaction submit \\
50+
--tx-file node-pool${N}/tx/tx${N}-era-funds.tx \\
51+
--testnet-magic ${NETWORK_MAGIC}
52+
53+
## Wait for the transaction to be confirmed
54+
sleep 1
55+
56+
# Write the era datum on chain
57+
TX_IN=\$(CARDANO_NODE_SOCKET_PATH=node-pool${N}/ipc/node.sock ./cardano-cli query utxo \\
58+
--testnet-magic ${NETWORK_MAGIC} --address \$(cat addresses/${ADDR}.addr) --out-file /dev/stdout \\
59+
| jq -r 'to_entries | [last] | .[0].key')
60+
61+
## Build the transaction
62+
CARDANO_NODE_SOCKET_PATH=node-pool${N}/ipc/node.sock ./cardano-cli transaction build \\
63+
--tx-in \${TX_IN} \\
64+
--tx-out \$(cat addresses/${ADDR}.addr)+${SCRIPT_TX_VALUE} \\
65+
--tx-out-inline-datum-file \${DATUM_FILE} \\
66+
--change-address \$(cat addresses/${ADDR}.addr) \\
67+
--testnet-magic ${NETWORK_MAGIC} \\
68+
--invalid-hereafter 100000 \\
69+
--out-file node-pool${N}/tx/tx${N}-era-datum.txbody
70+
71+
## Sign the transaction
72+
CARDANO_NODE_SOCKET_PATH=node-pool${N}/ipc/node.sock ./cardano-cli transaction sign \\
73+
--signing-key-file addresses/${ADDR}.skey \\
74+
--testnet-magic ${NETWORK_MAGIC} \\
75+
--tx-body-file node-pool${N}/tx/tx${N}-era-datum.txbody \\
76+
--out-file node-pool${N}/tx/tx${N}-era-datum.tx
77+
78+
## Submit the transaction
79+
CARDANO_NODE_SOCKET_PATH=node-pool${N}/ipc/node.sock ./cardano-cli transaction submit \\
80+
--tx-file node-pool${N}/tx/tx${N}-era-datum.tx \\
81+
--testnet-magic ${NETWORK_MAGIC}
82+
83+
## Wait for the transaction to be confirmed
84+
sleep 2
85+
86+
EOF
87+
88+
chmod u+x era-mithril.sh

mithril-test-lab/mithril-end-to-end/Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
[package]
22
name = "mithril-end-to-end"
3-
version = "0.2.33"
3+
version = "0.2.34"
44
authors = { workspace = true }
55
edition = { workspace = true }
66
documentation = { workspace = true }

mithril-test-lab/mithril-end-to-end/src/assertions/exec.rs

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
use std::path::PathBuf;
2+
13
use crate::{Aggregator, Devnet};
24
use mithril_common::entities::ProtocolParameters;
35
use mithril_common::StdResult;
@@ -16,6 +18,27 @@ pub async fn bootstrap_genesis_certificate(aggregator: &mut Aggregator) -> StdRe
1618
Ok(())
1719
}
1820

21+
pub async fn register_era_marker(
22+
aggregator: &mut Aggregator,
23+
devnet: &Devnet,
24+
mithril_era: &str,
25+
) -> StdResult<()> {
26+
info!("Register era marker");
27+
28+
info!("> generating era marker tx datum...");
29+
let tx_datum_file_path = devnet
30+
.artifacts_dir()
31+
.join(PathBuf::from("era-tx-datum.txt".to_string()));
32+
aggregator
33+
.era_generate_tx_datum(&tx_datum_file_path, mithril_era)
34+
.await?;
35+
36+
info!("> writing era marker on the Cardano chain...");
37+
devnet.write_era_marker(&tx_datum_file_path).await?;
38+
39+
Ok(())
40+
}
41+
1942
pub async fn delegate_stakes_to_pools(devnet: &Devnet, delegation_round: u16) -> StdResult<()> {
2043
info!("Delegate stakes to the cardano pools");
2144

0 commit comments

Comments
 (0)