Skip to content

Commit 9b8fc10

Browse files
authored
Merge pull request #17511 from MinaProtocol/dkijania/regenerate_archive_data
Regenerate archive test data + script fixes
2 parents f38387e + a90e7ba commit 9b8fc10

File tree

6 files changed

+1543
-1409
lines changed

6 files changed

+1543
-1409
lines changed

scripts/mina-local-network/split_precomputed_log.sh

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,16 +5,18 @@ if [[ $# -lt 1 ]]; then
55
exit 1
66
fi
77

8-
9-
108
ARCHIVE_URI=${ARCHIVE_URI:-postgres://postgres@localhost:5432/archive}
119
PRECOMPUTED_LOG_FILE=$1
1210
OUTPUT_FOLDER=${2:precomputed_blocks}
1311
cd "$OUTPUT_FOLDER" || exit
1412

1513
while IFS= read -r line; do
1614
LEDGER_HASH=$(echo $line | jq -r '.data.protocol_state.body.blockchain_state.staged_ledger_hash.non_snark.ledger_hash')
17-
FILE_NAME=$(psql $ARCHIVE_URI -t -c "SELECT 'mainnet-' || height || '-' ||state_hash || '.json' FROM blocks WHERE ledger_hash = '$LEDGER_HASH'")
15+
FILE_NAME=$(psql $ARCHIVE_URI -t -c "SELECT 'mainnet-' || height || '-' ||state_hash || '.json' FROM blocks WHERE ledger_hash = '$LEDGER_HASH'" | xargs)
16+
if [[ -z "$FILE_NAME" ]] || [[ "$FILE_NAME" == "NULL" ]]; then
17+
echo "WARNING: No block found in db for ledger hash: $LEDGER_HASH"
18+
continue
19+
fi
1820
echo $line > $FILE_NAME
1921
done < $PRECOMPUTED_LOG_FILE
2022

scripts/regenerate-archive.sh

Lines changed: 14 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ set -e
44
TOTAL_BLOCKS=25
55

66
# go to root of mina repo
7-
cd $(dirname -- "${BASH_SOURCE[0]}")/..
7+
cd "$(dirname -- "${BASH_SOURCE[0]}")"/..
88

99
# Prepare the database
1010
sudo -u postgres dropdb archive || true # fails when db doesn't exist which is fine
@@ -20,13 +20,15 @@ psql -U postgres -c "ALTER USER postgres WITH PASSWORD 'postgres';"
2020
-tf 1 --override-slot-time 30000 \
2121
-zt -vt -lp &
2222

23+
LOCAL_NETWORK_DATA_FOLDER="${HOME}"/.mina-network/mina-local-network-2-1-1
24+
2325
trap "pkill -f mina-local-network" EXIT
2426

2527
# stop mina-local-network once enough blocks have been produced
2628
while true; do
2729
sleep 10s
2830
# psql outputs " " until there are blocks in the db, the +0 defaults that to 0
29-
BLOCKS="$(( $(psql -U postgres archive -t -c "select MAX(global_slot_since_genesis) from blocks" 2> /dev/null) +0))"
31+
BLOCKS="$(( $(psql -U postgres archive -t -c "select MAX(height) from blocks" 2> /dev/null) +0))"
3032
echo Generated $BLOCKS/$TOTAL_BLOCKS blocks
3133
if [ "$((BLOCKS+0))" -ge $TOTAL_BLOCKS ] ; then
3234
pkill -f mina-local-network
@@ -37,26 +39,29 @@ done
3739
echo Converting canonical blocks
3840
source ./src/test/archive/sample_db/convert_chain_to_canonical.sh postgres://postgres:postgres@localhost:5432/archive
3941

40-
echo Regenerateing precomputed_blocks.tar.xz
42+
echo Regenerating precomputed_blocks.tar.xz
4143
rm -rf precomputed_blocks || true
4244
mkdir precomputed_blocks
4345
find ~/.mina-network -name 'precomputed_blocks.log' | xargs -I ! ./scripts/mina-local-network/split_precomputed_log.sh ! precomputed_blocks
4446
rm ./src/test/archive/sample_db/precomputed_blocks.tar.xz || true
45-
tar cvf ./src/test/archive/sample_db/precomputed_blocks.tar.xz precomputed_blocks
47+
tar -C precomputed_blocks -cvf ./src/test/archive/sample_db/precomputed_blocks.tar.xz .
4648
rm -rf precomputed_blocks
4749

48-
echo Regenerateing archive_db.sql
50+
echo Regenerating archive_db.sql
4951
pg_dump -U postgres -d archive > ./src/test/archive/sample_db/archive_db.sql
5052

5153

52-
echo Regenerateing input file
54+
echo Regenerating input file
5355
cp ./scripts/mina-local-network/annotated_ledger.json _tmp.json
54-
echo '{ "genesis_ledger": { "accounts": '$(cat _tmp.json | jq '.accounts')', "num_accounts": '$(cat _tmp.json | jq '.num_accounts')' }}' \
56+
echo '{ "genesis_ledger": { "accounts": '"$(cat _tmp.json | jq '.accounts')"', "num_accounts": '"$(cat _tmp.json | jq '.num_accounts')"' }}' \
5557
| jq -c > ./src/test/archive/sample_db/replayer_input_file.json
5658
rm _tmp.json
5759

58-
echo Regenerateing genesis_ledger
59-
cat src/test/archive/sample_db/genesis.json | jq ".ledger=$(cat ~/.mina-network/mina-local-network-2-1-1/genesis_ledger.json | jq -c)" > _tmp.json
60+
echo Regenerating genesis_ledger
61+
cat src/test/archive/sample_db/genesis.json | jq ".ledger=$(cat $LOCAL_NETWORK_DATA_FOLDER/genesis_ledger.json | jq -c)" > _tmp.json
62+
#update genesis_state_timestamp to the one from daemon.json
63+
jq --arg timestamp "$(cat $LOCAL_NETWORK_DATA_FOLDER/daemon.json | jq -r '.genesis.genesis_state_timestamp')" '.genesis.genesis_state_timestamp = $timestamp' _tmp.json > _tmp2.json && mv _tmp2.json _tmp.json
64+
6065
mv _tmp.json src/test/archive/sample_db/genesis.json
6166

6267
echo finished regenerate testing replay

0 commit comments

Comments
 (0)