Skip to content

Commit 84b8f36

Browse files
authored
fix: backport mithril script changes to 1.35.7 (#154)
Signed-off-by: Chris Gianelloni <[email protected]>
1 parent 1bf8005 commit 84b8f36

File tree

8 files changed

+70
-31
lines changed

8 files changed

+70
-31
lines changed

bin/run-network

Lines changed: 28 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -14,21 +14,41 @@ esac
1414

1515
# Mithril
1616
if ! test -e /data/db/protocolMagicId; then
17-
if [[ ${NETWORK} != preview ]]; then
18-
__base=https://raw.githubusercontent.com/input-output-hk/mithril/main/mithril-infra/configuration
19-
__url=${__base}/release-${NETWORK}
20-
export GENESIS_VERIFICATION_KEY=$(curl ${__url}/genesis.vkey 2> /dev/null)
21-
export AGGREGATOR_ENDPOINT=https://aggregator.release-${NETWORK}.api.mithril.network/aggregator
17+
RESTORE_NETWORK=${RESTORE_NETWORK:-true}
18+
if [[ ${RESTORE_NETWORK} != true ]]; then
19+
__skip=true
20+
fi
21+
case ${NETWORK} in
22+
mainnet|preprod) __path=release-${NETWORK} ;;
23+
preview) __path=pre-release-${NETWORK} ;;
24+
sanchonet) __path=testing-${NETWORK} ;;
25+
*) echo "Mithril not supported on ${NETWORK}... skipping"; __skip=true ;;
26+
esac
27+
if [[ ${__skip} != true ]]; then
28+
export GENESIS_VERIFICATION_KEY=$(</opt/cardano/config/${NETWORK}-genesis.vkey)
29+
export AGGREGATOR_ENDPOINT=https://aggregator.${__path}.api.mithril.network/aggregator
2230
export SNAPSHOT_DIGEST=$(mithril-client snapshot list --json | jq -r '.[0].digest')
2331
mkdir -p /data
2432
cd /data
2533
echo "Starting: /usr/local/bin/mithril-client snapshot download ${SNAPSHOT_DIGEST}"
26-
mithril-client snapshot download ${SNAPSHOT_DIGEST}
27-
else
28-
echo "Mithril not supported on preview... skipping"
34+
# Handle SIGTERM during initial sync
35+
trap 'kill -TERM $(pidof mithril-client)' TERM
36+
# Run mithril-client in the background so we can capture the PID and wait
37+
mithril-client snapshot download ${SNAPSHOT_DIGEST} &
38+
_mithril_pid=$!
39+
wait $_mithril_pid || exit $?
40+
# Reset signal handler and wait again (to avoid race condition)
41+
trap - TERM
42+
wait $_mithril_pid || exit $?
2943
fi
3044
fi
3145

46+
# Enable TraceMempool and PeerSharing
47+
sed -i \
48+
-e 's/"PeerSharing": false/"PeerSharing": true/' \
49+
-e 's/"TraceMempool": false/"TraceMempool": true/' \
50+
/opt/cardano/config/${NETWORK}-config.json
51+
3252
echo "Starting: /usr/local/bin/cardano-node run"
3353
echo "--config /opt/cardano/config/${NETWORK}-config.json"
3454
echo "--database-path /data/db"

bin/run-node

Lines changed: 28 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -43,8 +43,16 @@ CARDANO_RTS_OPTS=${CARDANO_RTS_OPTS:--N2 -A64m -I0 -qg -qb --disable-delayed-os-
4343
CARDANO_SOCKET_PATH=${CARDANO_SOCKET_PATH:-/opt/cardano/ipc/socket}
4444
CARDANO_TOPOLOGY=${CARDANO_TOPOLOGY:-${CARDANO_CONFIG_BASE}/${CARDANO_NETWORK}-topology.json}
4545
# mithril
46-
AGGREGATOR_ENDPOINT=${AGGREGATOR_ENDPOINT:-https://aggregator.release-${CARDANO_NETWORK}.api.mithril.network/aggregator}
47-
GENESIS_VERIFICATION_KEY=${GENESIS_VERIFICATION_KEY:-$(<${CARDANO_CONFIG_BASE}/${CARDANO_NETWORK}-genesis.vkey)}
46+
case ${CARDANO_NETWORK} in
47+
mainnet|preprod) __path=release-${CARDANO_NETWORK} ;;
48+
preview) __path=pre-release-${CARDANO_NETWORK} ;;
49+
sanchonet) __path=testing-${CARDANO_NETWORK} ;;
50+
esac
51+
AGGREGATOR_ENDPOINT=${AGGREGATOR_ENDPOINT:-https://aggregator.${__path}.api.mithril.network/aggregator}
52+
GENESIS_VERIFICATION_KEY_PATH=${GENESIS_VERIFICATION_KEY_PATH:-${CARDANO_CONFIG_BASE}/${CARDANO_NETWORK}-genesis.vkey}
53+
if [[ -z $GENESIS_VERIFICATION_KEY && -f $GENESIS_VERIFICATION_KEY_PATH ]]; then
54+
GENESIS_VERIFICATION_KEY=$(<${GENESIS_VERIFICATION_KEY_PATH})
55+
fi
4856
SNAPSHOT_DIGEST=${SNAPSHOT_DIGEST:-latest}
4957
RESTORE_SNAPSHOT=${RESTORE_SNAPSHOT:-true}
5058

@@ -67,13 +75,11 @@ if [[ ${CARDANO_BLOCK_PRODUCER} == true ]]; then
6775
echo CARDANO_SHELLEY_KES_KEY=${CARDANO_SHELLEY_KES_KEY}
6876
echo CARDANO_SHELLEY_VRF_KEY=${CARDANO_SHELLEY_VRF_KEY}
6977
echo CARDANO_SHELLEY_OPERATIONAL_CERTIFICATE=${CARDANO_SHELLEY_OPERATIONAL_CERTIFICATE}
70-
fi
71-
72-
if [[ ${CARDANO_NETWORK} == preview ]]; then
73-
if [[ ${RESTORE_SNAPSHOT} == true ]]; then
74-
echo "Mithril not supported on preview... skipping"
75-
fi
76-
RESTORE_SNAPSHOT=false
78+
else
79+
sed -i \
80+
-e 's/"PeerSharing": false/"PeerSharing": true/' \
81+
-e 's/"TraceMempool": false/"TraceMempool": true/' \
82+
${CARDANO_CONFIG}
7783
fi
7884

7985
echo AGGREGATOR_ENDPOINT=${AGGREGATOR_ENDPOINT}
@@ -87,11 +93,22 @@ mkdir -p $(dirname ${CARDANO_SOCKET_PATH})
8793
if ! test -e ${CARDANO_DATABASE_PATH}/protocolMagicId; then
8894
echo "Detected empty ${CARDANO_DATABASE_PATH}"
8995
if [[ ${RESTORE_SNAPSHOT} == true ]]; then
90-
mkdir -p ${CARDANO_DATABASE_PATH}
96+
mkdir -p $(dirname ${CARDANO_DATABASE_PATH})
9197
cd $(dirname ${CARDANO_DATABASE_PATH})
9298
export AGGREGATOR_ENDPOINT GENESIS_VERIFICATION_KEY SNAPSHOT_DIGEST
9399
echo "Starting: /usr/local/bin/mithril-client snapshot download ${SNAPSHOT_DIGEST}"
94-
mithril-client snapshot download ${SNAPSHOT_DIGEST}
100+
if [[ $(cd ${CARDANO_DATABASE_PATH}; pwd -P) != $(pwd -P)/db ]]; then
101+
rm -rf db/*
102+
fi
103+
# Handle SIGTERM during initial sync
104+
trap 'kill -TERM $(pidof mithril-client)' TERM
105+
# Run mithril-client in the background so we can capture the PID and wait
106+
mithril-client snapshot download ${SNAPSHOT_DIGEST} &
107+
_mithril_pid=$!
108+
wait $_mithril_pid || exit $?
109+
# Reset signal handler and wait again (to avoid race condition)
110+
trap - TERM
111+
wait $_mithril_pid || exit $?
95112
if [[ $(cd ${CARDANO_DATABASE_PATH}; pwd -P) != $(pwd -P)/db ]]; then
96113
mv -f db/* ${CARDANO_DATABASE_PATH}/
97114
fi

config/mainnet-config.json

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,17 @@
11
{
2-
"AlonzoGenesisFile": "/opt/cardano/config/mainnet-alonzo-genesis.json",
2+
"AlonzoGenesisFile": "mainnet-alonzo-genesis.json",
33
"AlonzoGenesisHash": "7e94a15f55d1e82d10f09203fa1d40f8eede58fd8066542cf6566008068ed874",
44
"ApplicationName": "cardano-sl",
55
"ApplicationVersion": 1,
6-
"ByronGenesisFile": "/opt/cardano/config/mainnet-byron-genesis.json",
6+
"ByronGenesisFile": "mainnet-byron-genesis.json",
77
"ByronGenesisHash": "5f20df933584822601f9e3f8c024eb5eb252fe8cefb24d1317dc3d432e940ebb",
88
"LastKnownBlockVersion-Alt": 0,
99
"LastKnownBlockVersion-Major": 3,
1010
"LastKnownBlockVersion-Minor": 0,
1111
"MaxKnownMajorProtocolVersion": 2,
1212
"Protocol": "Cardano",
1313
"RequiresNetworkMagic": "RequiresNoMagic",
14-
"ShelleyGenesisFile": "/opt/cardano/config/mainnet-shelley-genesis.json",
14+
"ShelleyGenesisFile": "mainnet-shelley-genesis.json",
1515
"ShelleyGenesisHash": "1a3be38bcbb7911969283716ad7aa550250226b76a61fc51cc9a9a35d9276d81",
1616
"TraceAcceptPolicy": true,
1717
"TraceBlockFetchClient": false,

config/mainnet-p2p-config.json

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
11
{
2-
"AlonzoGenesisFile": "/opt/cardano/config/mainnet-alonzo-genesis.json",
2+
"AlonzoGenesisFile": "mainnet-alonzo-genesis.json",
33
"AlonzoGenesisHash": "7e94a15f55d1e82d10f09203fa1d40f8eede58fd8066542cf6566008068ed874",
44
"ApplicationName": "cardano-sl",
55
"ApplicationVersion": 1,
6-
"ByronGenesisFile": "/opt/cardano/config/mainnet-byron-genesis.json",
6+
"ByronGenesisFile": "mainnet-byron-genesis.json",
77
"ByronGenesisHash": "5f20df933584822601f9e3f8c024eb5eb252fe8cefb24d1317dc3d432e940ebb",
88
"EnableP2P": true,
99
"LastKnownBlockVersion-Alt": 0,
@@ -12,7 +12,7 @@
1212
"MaxKnownMajorProtocolVersion": 2,
1313
"Protocol": "Cardano",
1414
"RequiresNetworkMagic": "RequiresNoMagic",
15-
"ShelleyGenesisFile": "/opt/cardano/config/mainnet-shelley-genesis.json",
15+
"ShelleyGenesisFile": "mainnet-shelley-genesis.json",
1616
"ShelleyGenesisHash": "1a3be38bcbb7911969283716ad7aa550250226b76a61fc51cc9a9a35d9276d81",
1717
"TargetNumberOfActivePeers": 20,
1818
"TargetNumberOfEstablishedPeers": 50,

config/preprod-config.json

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,17 @@
11
{
2-
"AlonzoGenesisFile": "/opt/cardano/config/preprod-alonzo-genesis.json",
2+
"AlonzoGenesisFile": "preprod-alonzo-genesis.json",
33
"AlonzoGenesisHash": "7e94a15f55d1e82d10f09203fa1d40f8eede58fd8066542cf6566008068ed874",
44
"ApplicationName": "cardano-sl",
55
"ApplicationVersion": 0,
6-
"ByronGenesisFile": "/opt/cardano/config/preprod-byron-genesis.json",
6+
"ByronGenesisFile": "preprod-byron-genesis.json",
77
"ByronGenesisHash": "d4b8de7a11d929a323373cbab6c1a9bdc931beffff11db111cf9d57356ee1937",
88
"EnableP2P": true,
99
"LastKnownBlockVersion-Alt": 0,
1010
"LastKnownBlockVersion-Major": 2,
1111
"LastKnownBlockVersion-Minor": 0,
1212
"Protocol": "Cardano",
1313
"RequiresNetworkMagic": "RequiresMagic",
14-
"ShelleyGenesisFile": "/opt/cardano/config/preprod-shelley-genesis.json",
14+
"ShelleyGenesisFile": "preprod-shelley-genesis.json",
1515
"ShelleyGenesisHash": "162d29c4e1cf6b8a84f2d692e67a3ac6bc7851bc3e6e4afe64d15778bed8bd86",
1616
"TargetNumberOfActivePeers": 20,
1717
"TargetNumberOfEstablishedPeers": 50,

config/preprod-genesis.vkey

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
5b3132372c37332c3132342c3136312c362c3133372c3133312c3231332c3230372c3131372c3139382c38352c3137362c3139392c3136322c3234312c36382c3132332c3131392c3134352c31332c3233322c3234332c34392c3232392c322c3234392c3230352c3230352c33392c3233352c34345d

config/preview-config.json

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,17 @@
11
{
2-
"AlonzoGenesisFile": "/opt/cardano/config/preview-alonzo-genesis.json",
2+
"AlonzoGenesisFile": "preview-alonzo-genesis.json",
33
"AlonzoGenesisHash": "7e94a15f55d1e82d10f09203fa1d40f8eede58fd8066542cf6566008068ed874",
44
"ApplicationName": "cardano-sl",
55
"ApplicationVersion": 0,
6-
"ByronGenesisFile": "/opt/cardano/config/preview-byron-genesis.json",
6+
"ByronGenesisFile": "preview-byron-genesis.json",
77
"ByronGenesisHash": "83de1d7302569ad56cf9139a41e2e11346d4cb4a31c00142557b6ab3fa550761",
88
"EnableP2P": true,
99
"LastKnownBlockVersion-Alt": 0,
1010
"LastKnownBlockVersion-Major": 3,
1111
"LastKnownBlockVersion-Minor": 1,
1212
"Protocol": "Cardano",
1313
"RequiresNetworkMagic": "RequiresMagic",
14-
"ShelleyGenesisFile": "/opt/cardano/config/preview-shelley-genesis.json",
14+
"ShelleyGenesisFile": "preview-shelley-genesis.json",
1515
"ShelleyGenesisHash": "363498d1024f84bb39d3fa9593ce391483cb40d479b87233f868d6e57c3a400d",
1616
"TargetNumberOfActivePeers": 20,
1717
"TargetNumberOfEstablishedPeers": 50,

config/preview-genesis.vkey

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
5b3132372c37332c3132342c3136312c362c3133372c3133312c3231332c3230372c3131372c3139382c38352c3137362c3139392c3136322c3234312c36382c3132332c3131392c3134352c31332c3233322c3234332c34392c3232392c322c3234392c3230352c3230352c33392c3233352c34345d

0 commit comments

Comments
 (0)