Skip to content

Commit 0b25d55

Browse files
committed
Fix stake delegation in devnet
1 parent 8cc25af commit 0b25d55

File tree

3 files changed

+89
-32
lines changed

3 files changed

+89
-32
lines changed

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

Lines changed: 51 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -149,4 +149,54 @@ for N in ${POOL_NODES_N}; do
149149
cp ${ARTIFACTS_DIR_TEMP}/pools/kes${N}.vkey node-pool${N}/shelley/kes.vkey
150150
cp ${ARTIFACTS_DIR_TEMP}/pools/opcert${N}.counter node-pool${N}/shelley/opcert.counter
151151
cp ${ARTIFACTS_DIR_TEMP}/pools/opcert${N}.cert node-pool${N}/shelley/opcert.cert
152-
done
152+
done
153+
154+
# Prepare staking
155+
cp -r ${ARTIFACTS_DIR_TEMP}/utxo-keys/* addresses
156+
157+
for ADDR in ${UTXO_ADDRS}; do
158+
# Payment addresses
159+
./cardano-cli address build \
160+
--payment-verification-key-file addresses/${ADDR}.vkey \
161+
--testnet-magic ${NETWORK_MAGIC} \
162+
--out-file addresses/${ADDR}.addr
163+
done
164+
165+
for ADDR in ${USER_ADDRS}; do
166+
# Payment address keys
167+
./cardano-cli address key-gen \
168+
--verification-key-file addresses/${ADDR}.vkey \
169+
--signing-key-file addresses/${ADDR}.skey
170+
171+
# Stake address keys
172+
./cardano-cli stake-address key-gen \
173+
--verification-key-file addresses/${ADDR}-stake.vkey \
174+
--signing-key-file addresses/${ADDR}-stake.skey
175+
176+
# Payment addresses
177+
./cardano-cli address build \
178+
--payment-verification-key-file addresses/${ADDR}.vkey \
179+
--stake-verification-key-file addresses/${ADDR}-stake.vkey \
180+
--testnet-magic ${NETWORK_MAGIC} \
181+
--out-file addresses/${ADDR}.addr
182+
183+
# Stake addresses
184+
./cardano-cli stake-address build \
185+
--stake-verification-key-file addresses/${ADDR}-stake.vkey \
186+
--testnet-magic ${NETWORK_MAGIC} \
187+
--out-file addresses/${ADDR}-stake.addr
188+
189+
# Stake addresses registration certs
190+
./cardano-cli stake-address registration-certificate \
191+
--stake-verification-key-file addresses/${ADDR}-stake.vkey \
192+
--out-file addresses/${ADDR}-stake.reg.cert
193+
done
194+
195+
# User N will delegate to pool N
196+
for N in ${POOL_NODES_N}; do
197+
# Stake address delegation certs
198+
./cardano-cli stake-address delegation-certificate \
199+
--stake-verification-key-file addresses/user${N}-stake.vkey \
200+
--cold-verification-key-file node-pool${N}/shelley/cold.vkey \
201+
--out-file addresses/user${N}-stake.deleg.cert
202+
done

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

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -65,4 +65,8 @@ fi
6565
cp cardano-cli ${ARTIFACTS_DIR}/cardano-cli
6666
cp cardano-node ${ARTIFACTS_DIR}/cardano-node
6767

68-
pushd ${ARTIFACTS_DIR} > /dev/null
68+
# Switch to artifacts directory
69+
pushd ${ARTIFACTS_DIR} > /dev/null
70+
71+
# Create addresses sub-directory
72+
mkdir addresses

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

Lines changed: 33 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -39,48 +39,51 @@ CURRENT_EPOCH=\$(CARDANO_NODE_SOCKET_PATH=node-pool${N}/ipc/node.sock ./cardano-
3939
echo ">>>> Current Epoch: \${CURRENT_EPOCH}"
4040
EOF
4141

42-
# Prepare transactions for activating stake pools
42+
# Prepare transactions for delegating to stake pools
4343
for N in ${POOL_NODES_N}; do
44-
45-
# We'll transfer funds to the user1, which delegates to pool1
46-
# We'll register certs to:
47-
# 1. delegate from the user1 stake address to the stake pool
4844
cat >> delegate.sh <<EOF
49-
5045
AMOUNT_STAKED=\$(( $N*1000000 + DELEGATION_ROUND*1 ))
5146
47+
# Get the UTxO
5248
TX_IN=\$(CARDANO_NODE_SOCKET_PATH=node-pool${N}/ipc/node.sock ./cardano-cli query utxo \\
53-
--testnet-magic ${NETWORK_MAGIC} --address \$(cat addresses/utxo${N}.addr) --out-file tmp.txt \\
54-
&& cat tmp.txt | jq -r 'to_entries | [last] | .[0].key' \\
55-
&& rm -f tmp.txt)
56-
57-
CARDANO_NODE_SOCKET_PATH=node-pool${N}/ipc/node.sock ./cardano-cli transaction build \\
58-
--alonzo-era \\
59-
--tx-in \${TX_IN} \\
60-
--tx-out \$(cat addresses/user${N}.addr)+\${AMOUNT_STAKED} \\
61-
--change-address \$(cat addresses/utxo${N}.addr) \\
62-
--testnet-magic ${NETWORK_MAGIC} \\
63-
--certificate-file addresses/user${N}-stake.deleg.cert \\
64-
--invalid-hereafter 100000 \\
65-
--out-file node-pool${N}/tx/tx${N}-\${DELEGATION_ROUND}.txbody \\
66-
--witness-override 2
67-
68-
EOF
69-
70-
# So we'll need to sign this with a the following keys:
71-
# 1. the user1 stake address key, due to the delegation cert
72-
cat >> delegate.sh <<EOF
49+
--testnet-magic ${NETWORK_MAGIC} --address \$(cat addresses/utxo${N}.addr) --out-file /dev/stdout \\
50+
| jq -r 'to_entries | [last] | .[0].key')
51+
52+
# Build the transaction
53+
if [ "\$DELEGATION_ROUND" -eq 1 ]; then
54+
# First delegation round, we need to include registration certificate and delegation certificate
55+
CARDANO_NODE_SOCKET_PATH=node-pool${N}/ipc/node.sock ./cardano-cli transaction build \\
56+
--tx-in \${TX_IN} \\
57+
--tx-out \$(cat addresses/user${N}.addr)+\${AMOUNT_STAKED} \\
58+
--change-address \$(cat addresses/utxo${N}.addr) \\
59+
--testnet-magic ${NETWORK_MAGIC} \\
60+
--certificate-file addresses/user${N}-stake.reg.cert \\
61+
--certificate-file addresses/user${N}-stake.deleg.cert \\
62+
--invalid-hereafter 100000 \\
63+
--out-file node-pool${N}/tx/tx${N}-\${DELEGATION_ROUND}.txbody \\
64+
--witness-override 2
65+
else
66+
# All other delegation rounds, we need to include only delegation certificate
67+
CARDANO_NODE_SOCKET_PATH=node-pool${N}/ipc/node.sock ./cardano-cli transaction build \\
68+
--tx-in \${TX_IN} \\
69+
--tx-out \$(cat addresses/user${N}.addr)+\${AMOUNT_STAKED} \\
70+
--change-address \$(cat addresses/utxo${N}.addr) \\
71+
--testnet-magic ${NETWORK_MAGIC} \\
72+
--certificate-file addresses/user${N}-stake.deleg.cert \\
73+
--invalid-hereafter 100000 \\
74+
--out-file node-pool${N}/tx/tx${N}-\${DELEGATION_ROUND}.txbody \\
75+
--witness-override 2
76+
fi
77+
78+
# Sign the transaction
7379
CARDANO_NODE_SOCKET_PATH=node-pool${N}/ipc/node.sock ./cardano-cli transaction sign \\
7480
--signing-key-file addresses/utxo${N}.skey \\
7581
--signing-key-file addresses/user${N}-stake.skey \\
7682
--testnet-magic ${NETWORK_MAGIC} \\
7783
--tx-body-file node-pool${N}/tx/tx${N}-\${DELEGATION_ROUND}.txbody \\
7884
--out-file node-pool${N}/tx/tx${N}-\${DELEGATION_ROUND}.tx
7985
80-
EOF
81-
82-
# Copy submit transaction to delegate.sh script
83-
cat >> delegate.sh <<EOF
86+
# Submit the transaction
8487
CARDANO_NODE_SOCKET_PATH=node-pool${N}/ipc/node.sock ./cardano-cli transaction submit \\
8588
--tx-file node-pool${N}/tx/tx${N}-\${DELEGATION_ROUND}.tx \\
8689
--testnet-magic ${NETWORK_MAGIC}

0 commit comments

Comments
 (0)