Skip to content

Commit d318db3

Browse files
committed
wb | extract keys utils from voting workload
1 parent 60f3c20 commit d318db3

File tree

2 files changed

+130
-114
lines changed

2 files changed

+130
-114
lines changed
Lines changed: 113 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,113 @@
1+
{ coreutils
2+
, jq
3+
, cardano-cli
4+
, testnet_magic
5+
}:
6+
''
7+
################################################################################
8+
# Hack: Why pre-create and pre-share keys when you can create them on demand?
9+
# (ONLY BECAUSE THIS IS A TEST ENVIRONMENT AND WE ARE ALL FRIENDS!)
10+
# Given a prefix and an x, y and z numbers creates always the same address keys.
11+
# The x, y and z are to allow to have different key "levels", for example a key
12+
# for "node-2", "drep 5" and "proposal 22".
13+
# Supports x=[0..99], y=[0..9999] and z=[0..999999] by adding the Hex chars.
14+
# Returns the file path without the extensions (the ".skey" or ".vkey" part).
15+
# No key is created if the file already exists.
16+
################################################################################
17+
function create_x_y_z_key_files {
18+
19+
# Function arguments.
20+
local prefix=$1 # String for the key file name (not for the socket).
21+
local x_i=$2
22+
local y_n=$3
23+
local z_n=$4
24+
25+
local filename=./"''${prefix}"-"''${y_n}"-"''${z_n}"
26+
# Now with the extensions.
27+
local skey="''${filename}".skey
28+
local vkey="''${filename}".vkey
29+
30+
# Only create if not already there!
31+
if ! test -f "''${vkey}"
32+
then
33+
${jq}/bin/jq --null-input \
34+
--argjson x_n "''${x_n}" \
35+
--argjson y_n "''${y_n}" \
36+
--argjson z_n "''${z_n}" \
37+
'
38+
{"type": "PaymentSigningKeyShelley_ed25519",
39+
"description": "Payment Signing Key",
40+
"cborHex": (
41+
"5820b02868d722df021278c78be3b7363759b37f5852b8747b488bab"
42+
+ (if $x_n <= 9
43+
then ("0" + ($x_n | tostring))
44+
elif $x_n >= 10 and $x_n <= 99
45+
then ( $x_n | tostring)
46+
else (error ("Node ID above 99"))
47+
end
48+
)
49+
+ (if $y_n <= 9
50+
then ( "000" + ($y_n | tostring))
51+
elif $y_n >= 10 and $y_n <= 99
52+
then ( "00" + ($y_n | tostring))
53+
elif $y_n >= 100 and $y_n <= 999
54+
then ( "0" + ($y_n | tostring))
55+
elif $y_n >= 1000 and $y_n <= 9999
56+
then ( ($y_n | tostring))
57+
else (error ("Proposal ID above 9999"))
58+
end
59+
)
60+
+ (if $z_n <= 9
61+
then ( "00000" + ($z_n | tostring))
62+
elif $z_n >= 10 and $z_n <= 99
63+
then ( "0000" + ($z_n | tostring))
64+
elif $z_n >= 100 and $z_n <= 999
65+
then ( "000" + ($z_n | tostring))
66+
elif $z_n >= 1000 and $z_n <= 9999
67+
then ( "00" + ($z_n | tostring))
68+
elif $z_n >= 10000 and $z_n <= 99999
69+
then ( "0" + ($z_n | tostring))
70+
elif $z_n >= 100000 and $z_n <= 999999
71+
then ( ($z_n | tostring))
72+
else (error ("DRep ID above 999999"))
73+
end
74+
)
75+
)
76+
}
77+
' \
78+
> "''${skey}"
79+
${cardano-cli}/bin/cardano-cli conway key verification-key \
80+
--signing-key-file "''${skey}" \
81+
--verification-key-file "''${vkey}"
82+
fi
83+
${coreutils}/bin/echo "''${filename}"
84+
}
85+
86+
################################################################################
87+
# Get address of the x-y-z key combination!
88+
# Creates the key if it does not already exist.
89+
################################################################################
90+
function build_x_y_z_address {
91+
92+
# Function arguments.
93+
local prefix=$1
94+
local x_n=$2
95+
local y_n=$3
96+
local z_n=$4
97+
98+
local filename addr
99+
filename="$(create_x_y_z_key_files "''${prefix}" "''${x_n}" "''${y_n}" "''${z_n}")"
100+
addr="''${filename}.addr"
101+
# Only create if not already there!
102+
if ! test -f "''${addr}"
103+
then
104+
local vkey="''${filename}".vkey
105+
${cardano-cli}/bin/cardano-cli address build \
106+
--testnet-magic ${toString testnet_magic} \
107+
--payment-verification-key-file "''${vkey}" \
108+
> "''${addr}"
109+
fi
110+
${coreutils}/bin/cat "''${addr}"
111+
}
112+
''
113+

nix/workbench/workload/voting.nix

Lines changed: 17 additions & 114 deletions
Original file line numberDiff line numberDiff line change
@@ -141,6 +141,11 @@ in ''
141141
# desired_producer_tps: ${toString desired_producer_tps}
142142
# desired_producer_sleep: ${toString desired_producer_sleep}
143143
144+
${import ./utils/keys.nix
145+
{ inherit coreutils jq cardano-cli testnet_magic;
146+
}
147+
}
148+
144149
${import ./utils/utxo.nix
145150
{ inherit coreutils cardano-cli jq testnet_magic;
146151
inherit outs_per_split_transaction funds_submit_tries;
@@ -151,108 +156,6 @@ ${import ./utils/utxo.nix
151156
}
152157
}
153158
154-
################################################################################
155-
# Hack: Given a node "i" and proposal number and a DRep number create always the
156-
# same address keys.
157-
# Only supports up to 99 nodes, 9999 proposals and 999999 DReps by adding the
158-
# missing Hex chars.
159-
# Returns the file path without the extensions (the ".skey" or ".vkey" part).
160-
################################################################################
161-
function create_node_prop_drep_key_files {
162-
163-
# Function arguments.
164-
local node_str=$1 # String for the key file name (not for the socket).
165-
local node_i=$2 # This "i" is part of the node name ("node-i").
166-
local prop_i=$3
167-
local drep_i=$4
168-
169-
local filename=./"''${node_str}"-prop-"''${prop_i}"-drep-"''${drep_i}"
170-
# Now with the extensions.
171-
local skey="''${filename}".skey
172-
local vkey="''${filename}".vkey
173-
174-
# Only create if not already there!
175-
if ! test -f "''${vkey}"
176-
then
177-
${jq}/bin/jq --null-input \
178-
--argjson node_i "''${node_i}" \
179-
--argjson prop_i "''${prop_i}" \
180-
--argjson drep_i "''${drep_i}" \
181-
'
182-
{"type": "PaymentSigningKeyShelley_ed25519",
183-
"description": "Payment Signing Key",
184-
"cborHex": (
185-
"5820b02868d722df021278c78be3b7363759b37f5852b8747b488bab"
186-
+ (if $node_i <= 9
187-
then ("0" + ($node_i | tostring))
188-
elif $node_i >= 10 and $node_i <= 99
189-
then ( $node_i | tostring)
190-
else (error ("Node ID above 99"))
191-
end
192-
)
193-
+ (if $prop_i <= 9
194-
then ( "000" + ($prop_i | tostring))
195-
elif $prop_i >= 10 and $prop_i <= 99
196-
then ( "00" + ($prop_i | tostring))
197-
elif $prop_i >= 100 and $prop_i <= 999
198-
then ( "0" + ($prop_i | tostring))
199-
elif $prop_i >= 1000 and $prop_i <= 9999
200-
then ( ($prop_i | tostring))
201-
else (error ("Proposal ID above 9999"))
202-
end
203-
)
204-
+ (if $drep_i <= 9
205-
then ( "00000" + ($drep_i | tostring))
206-
elif $drep_i >= 10 and $drep_i <= 99
207-
then ( "0000" + ($drep_i | tostring))
208-
elif $drep_i >= 100 and $drep_i <= 999
209-
then ( "000" + ($drep_i | tostring))
210-
elif $drep_i >= 1000 and $drep_i <= 9999
211-
then ( "00" + ($drep_i | tostring))
212-
elif $drep_i >= 10000 and $drep_i <= 99999
213-
then ( "0" + ($drep_i | tostring))
214-
elif $drep_i >= 100000 and $drep_i <= 999999
215-
then ( ($drep_i | tostring))
216-
else (error ("DRep ID above 999999"))
217-
end
218-
)
219-
)
220-
}
221-
' \
222-
> "''${skey}"
223-
${cardano-cli}/bin/cardano-cli conway key verification-key \
224-
--signing-key-file "''${skey}" \
225-
--verification-key-file "''${vkey}"
226-
fi
227-
${coreutils}/bin/echo "''${filename}"
228-
}
229-
230-
################################################################################
231-
# Get address of the node-proposal-drep combination!
232-
################################################################################
233-
function build_node_prop_drep_address {
234-
235-
# Function arguments.
236-
local node_str=$1 # String for the key file name (not for the socket).
237-
local node_i=$2 # This "i" is part of the node name ("node-i").
238-
local prop_i=$3
239-
local drep_i=$4
240-
241-
local filename addr
242-
filename="$(create_node_prop_drep_key_files "''${node_str}" "''${node_i}" "''${prop_i}" "''${drep_i}")"
243-
addr="''${filename}.addr"
244-
# Only create if not already there!
245-
if ! test -f "''${addr}"
246-
then
247-
local vkey="''${filename}".vkey
248-
${cardano-cli}/bin/cardano-cli address build \
249-
--testnet-magic ${toString testnet_magic} \
250-
--payment-verification-key-file "''${vkey}" \
251-
> "''${addr}"
252-
fi
253-
${coreutils}/bin/cat "''${addr}"
254-
}
255-
256159
################################################################################
257160
# Evenly distribute the "utxo_*key" genesis funds to all producer nodes.
258161
# To be called before `governance_funds_producer`.
@@ -289,7 +192,7 @@ function governance_funds_genesis {
289192
)"
290193
local producer_addr
291194
# Drep 0 is No DRep (funds for the node).
292-
producer_addr="$(build_node_prop_drep_address "''${producer_name}" "''${producer_i}" 0 0)"
195+
producer_addr="$(build_x_y_z_address "''${producer_name}" "''${producer_i}" 0 0)"
293196
producers_addrs_array+=("''${producer_addr}")
294197
${coreutils}/bin/echo "governance_funds_genesis: Splitting to: ''${producer_name} - ''${producer_i} - 0 - (''${producer_addr})"
295198
done
@@ -326,9 +229,9 @@ function governance_funds_producer {
326229
../../node-specs.json \
327230
)"
328231
local producer_addr producer_vkey producer_skey
329-
producer_addr="$(build_node_prop_drep_address "''${producer_name}" "''${producer_i}" 0 0)"
330-
producer_vkey="$(create_node_prop_drep_key_files "''${producer_name}" "''${producer_i}" 0 0)".vkey
331-
producer_skey="$(create_node_prop_drep_key_files "''${producer_name}" "''${producer_i}" 0 0)".skey
232+
producer_addr="$(build_x_y_z_address "''${producer_name}" "''${producer_i}" 0 0)"
233+
producer_vkey="$(create_x_y_z_key_files "''${producer_name}" "''${producer_i}" 0 0)".vkey
234+
producer_skey="$(create_x_y_z_key_files "''${producer_name}" "''${producer_i}" 0 0)".skey
332235
333236
# Wait for initial funds to arrive!
334237
${coreutils}/bin/echo "governance_funds_producer: Wait for funds: $(${coreutils}/bin/date --rfc-3339=seconds)"
@@ -349,7 +252,7 @@ function governance_funds_producer {
349252
for prop_i in {1..${toString proposals_count}}
350253
do
351254
local producer_prop_addr
352-
producer_prop_addr="$(build_node_prop_drep_address "''${producer_name}" "''${producer_i}" "''${prop_i}" 0)"
255+
producer_prop_addr="$(build_x_y_z_address "''${producer_name}" "''${producer_i}" "''${prop_i}" 0)"
353256
producer_prop_addr_array+=("''${producer_prop_addr}")
354257
${coreutils}/bin/echo "governance_funds_producer: Splitting to: ''${producer_name} - ''${producer_i} - ''${prop_i} - ''${producer_prop_addr}"
355258
done
@@ -374,8 +277,8 @@ function governance_funds_producer {
374277
do
375278
376279
local producer_prop_vkey producer_prop_skey
377-
producer_prop_vkey="$(create_node_prop_drep_key_files "''${producer_name}" "''${producer_i}" "''${prop_i}" 0)".vkey
378-
producer_prop_skey="$(create_node_prop_drep_key_files "''${producer_name}" "''${producer_i}" "''${prop_i}" 0)".skey
280+
producer_prop_vkey="$(create_x_y_z_key_files "''${producer_name}" "''${producer_i}" "''${prop_i}" 0)".vkey
281+
producer_prop_skey="$(create_x_y_z_key_files "''${producer_name}" "''${producer_i}" "''${prop_i}" 0)".skey
379282
380283
local producer_dreps_addrs_array=()
381284
local drep_step=0
@@ -385,7 +288,7 @@ function governance_funds_producer {
385288
do
386289
local producer_drep_addr
387290
actual_drep="$((drep_step + i))"
388-
producer_drep_addr="$(build_node_prop_drep_address "''${producer_name}" "''${producer_i}" "''${prop_i}" "''${actual_drep}")"
291+
producer_drep_addr="$(build_x_y_z_address "''${producer_name}" "''${producer_i}" "''${prop_i}" "''${actual_drep}")"
389292
producer_dreps_addrs_array+=("''${producer_drep_addr}")
390293
${coreutils}/bin/echo "governance_funds_producer: Splitting to: ''${producer_name} - ''${producer_i} - ''${prop_i} - ''${actual_drep} - ''${producer_drep_addr}"
391294
done
@@ -522,8 +425,8 @@ function governance_create_withdrawal {
522425
socket_path="$(get_socket_path "''${node_str}")"
523426
524427
local node_drep_skey node_drep_addr
525-
node_drep_skey="$(create_node_prop_drep_key_files "''${node_str}" "''${node_i}" 0 "''${drep_i}")".skey
526-
node_drep_addr="$(build_node_prop_drep_address "''${node_str}" "''${node_i}" 0 "''${drep_i}")"
428+
node_drep_skey="$(create_x_y_z_key_files "''${node_str}" "''${node_i}" 0 "''${drep_i}")".skey
429+
node_drep_addr="$(build_x_y_z_address "''${node_str}" "''${node_i}" 0 "''${drep_i}")"
527430
528431
# Funds needed for this governance action ?
529432
local action_deposit
@@ -719,8 +622,8 @@ function governance_vote_proposal {
719622
for drep_i in ''${dreps_array[*]}
720623
do
721624
local node_drep_skey node_drep_addr
722-
node_drep_skey="$(create_node_prop_drep_key_files "''${node_str}" "''${node_i}" "''${prop_i}" "''${drep_i}")".skey
723-
node_drep_addr="$(build_node_prop_drep_address "''${node_str}" "''${node_i}" "''${prop_i}" "''${drep_i}")"
625+
node_drep_skey="$(create_x_y_z_key_files "''${node_str}" "''${node_i}" "''${prop_i}" "''${drep_i}")".skey
626+
node_drep_addr="$(build_x_y_z_address "''${node_str}" "''${node_i}" "''${prop_i}" "''${drep_i}")"
724627
# UTxO are created for 1 vote per transaction so all runs have the same
725628
# number of UTxOs. We grab the funds from the first address/UTxO.
726629
if test -z "''${funds_tx-}"

0 commit comments

Comments
 (0)