Skip to content

Commit c8edd78

Browse files
authored
Merge pull request #15456 from MinaProtocol/georgeee/fixes-to-migration-script
Fixes to migration script
2 parents 3596e67 + b228412 commit c8edd78

File tree

4 files changed

+38
-49
lines changed

4 files changed

+38
-49
lines changed

scripts/archive/migration/README.md

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -100,15 +100,15 @@ Since berkeley migration script supports all berkeley migration phases. We need
100100
#### Initial migration
101101

102102
```
103-
./scripts/archive/migration/berkeley_migration.sh initial -g ../../umt_testing/o1labs-umt-pre-fork-run-1-ledger.json -s postgres://postgres:postgres@localhost:5432/umt_testing_initial -t postgres://postgres:postgres@localhost:5432/migrated -b mina_network_block_data -bs 1000 -n o1labs-umt-pre-fork-run-1
103+
mina-berkeley-migration-script initial -g ../../umt_testing/o1labs-umt-pre-fork-run-1-ledger.json -s postgres://postgres:postgres@localhost:5432/umt_testing_initial -t postgres://postgres:postgres@localhost:5432/migrated -b mina_network_block_data -bs 1000 -n o1labs-umt-pre-fork-run-1
104104
```
105105

106106
this command should output migration-replayer-XXX.json which should be used in next run
107107

108108
#### Incremental migration
109109

110110
```
111-
./scripts/archive/migration/berkeley_migration.sh incremental -g ../../umt_testing/o1labs-umt-pre-fork-run-1-ledger.json -s postgres://postgres:postgres@localhost:5432/umt_testing_increment -t postgres://postgres:postgres@localhost:5432/migrated -b mina_network_block_data -bs 50 -n o1labs-umt-pre-fork-run-1 -r migration-checkpoint-597.json
111+
mina-berkeley-migration-script incremental -g ../../umt_testing/o1labs-umt-pre-fork-run-1-ledger.json -s postgres://postgres:postgres@localhost:5432/umt_testing_increment -t postgres://postgres:postgres@localhost:5432/migrated -b mina_network_block_data -bs 50 -n o1labs-umt-pre-fork-run-1 -r migration-checkpoint-597.json
112112
```
113113

114114
where:
@@ -118,7 +118,7 @@ migration-checkpoint-597.json - is a last checkpoint from initial run
118118
#### Final migration
119119

120120
```
121-
./scripts/archive/migration/berkeley_migration.sh final -g ../../umt_testing/o1labs-umt-pre-fork-run-1-ledger.json -s postgres://postgres:postgres@localhost:5432/umt_testing_final -t postgres://postgres:postgres@localhost:5432/migrated -b mina_network_block_data -bs 50 -n o1labs-umt-pre-fork-run-1 -r migration-checkpoint-2381.json -fc ../../umt_testing/fork-umt-02-29-2024.json -f 3NLnD1Yp4MS9LtMXikD1YyySZNVgCXA82b5eQVpmYZ5kyTo4Xsr7
121+
mina-berkeley-migration-script final -g ../../umt_testing/o1labs-umt-pre-fork-run-1-ledger.json -s postgres://postgres:postgres@localhost:5432/umt_testing_final -t postgres://postgres:postgres@localhost:5432/migrated -b mina_network_block_data -bs 50 -n o1labs-umt-pre-fork-run-1 -r migration-checkpoint-2381.json -fc ../../umt_testing/fork-umt-02-29-2024.json
122122
```
123123

124124
where `3NLnD1Yp4MS9LtMXikD1YyySZNVgCXA82b5eQVpmYZ5kyTo4Xsr7` was extracted from fork config file:

scripts/archive/migration/mina-berkeley-migration-script

Lines changed: 14 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -209,7 +209,7 @@ function initial(){
209209
function check_log_for_error() {
210210
local __log=$1;
211211

212-
grep Error "$__log";
212+
grep '"level":"Error"' "$__log";
213213
local __have_errors=$?;
214214

215215
if [ $__have_errors -eq 0 ]; then
@@ -537,19 +537,18 @@ function final_help(){
537537
echo ""
538538
printf " %-25s %s\n" "-h | --help" "show help";
539539
printf " %-25s %s\n" "-r | --replayer-checkpoint" "[file] path to genesis ledger file";
540-
printf " %-25s %s\n" "-f | --fork-state-hash" "[hash] fork state hash";
541540
printf " %-25s %s\n" "-s | --source-db" "[connection_str] connection string to database to be migrated";
542541
printf " %-25s %s\n" "-t | --target-db" "[connection_str] connection string to database which will hold migrated data";
543542
printf " %-25s %s\n" "-b | --blocks-bucket" "[string] name of precomputed blocks bucket. NOTICE: there is an assumption that precomputed blocks are named with format: {network}-{height}-{state_hash}.json";
544543
printf " %-25s %s\n" "-bs | --blocks-batch-size" "[int] number of precomputed blocks to be fetch at once from Gcloud. Bigger number like 1000 can help speed up migration process";
545544
printf " %-25s %s\n" "-n | --network" "[string] network name when determining precomputed blocks. NOTICE: there is an assumption that precomputed blocks are named with format: {network}-{height}-{state_hash}.json";
546-
printf " %-25s %s\n" "-fc | --fork-config" "[file] Fork-state config file is dump file in form of json containing fork block and ledger file. It should be provied by MF or O(1)Labs team after fork block is announced";
545+
printf " %-25s %s\n" "-fc | --fork-genesis-config" "[file] Genesis config file for the fork network. It should be provied by MF or O(1)Labs team after fork block is announced";
547546
printf " %-25s %s\n" "-d | --delete-blocks" "delete blocks after they are processed (saves space with -sb)"
548547
printf " %-25s %s\n" "-p | --prefetch-blocks" "downloads all blocks at once instead of incrementally"
549548
echo ""
550549
echo "Example:"
551550
echo ""
552-
echo " " $CLI_NAME final --replayer-checkpoint migration-replayer-checkpoint-1233.json --fork-state-hash 3NLnD1Yp4MS9LtMXikD1YyySZNVgCXA82b5eQVpmYZ5kyTo4Xsr7 --genesis-ledger "genesis_ledgers/mainnet.json" --source-db "postgres://postgres:pass@localhost:5432/archive_balances_migrated" --target-db "postgres://postgres:pass@localhost:5432/migrated" --blocks-batch-size 10 --blocks-bucket "mina_network_block_data" --network "mainnet" --fork-config fork_config.json
551+
echo " " $CLI_NAME final --replayer-checkpoint migration-replayer-checkpoint-1233.json --genesis-ledger "genesis_ledgers/mainnet.json" --source-db "postgres://postgres:pass@localhost:5432/archive_balances_migrated" --target-db "postgres://postgres:pass@localhost:5432/migrated" --blocks-batch-size 10 --blocks-bucket "mina_network_block_data" --network "mainnet" --fork-genesis-config fork_genesis_config.json
553552
echo ""
554553
echo "Notes:"
555554
echo " 1. After run migrated data will be filled with migrated blocks till last block in source db"
@@ -574,8 +573,7 @@ function final(){
574573
local __stream_blocks=true
575574
local __network=''
576575
local __checkpoint_interval=1000
577-
local __fork_state_hash=''
578-
local __fork_config=''
576+
local __fork_genesis_config=''
579577

580578
while [ ${#} -gt 0 ]; do
581579
error_message="Error: a value is needed for '$1'";
@@ -587,12 +585,8 @@ function final(){
587585
__genesis_ledger=${2:?$error_message}
588586
shift 2;
589587
;;
590-
-f | --fork-state-hash )
591-
__fork_state_hash=${2:?$error_message}
592-
shift 2;
593-
;;
594-
-fc | --fork-config )
595-
__fork_config=${2:?$error_message}
588+
-fc | --fork-genesis-config )
589+
__fork_genesis_config=${2:?$error_message}
596590
shift 2;
597591
;;
598592
-r | --replayer-checkpoint )
@@ -662,15 +656,9 @@ function final(){
662656
echo "Genesis ledger not defined"
663657
exit 1
664658
fi
665-
if [ -z "$__fork_state_hash" ]; then
659+
if [ -z "$__fork_genesis_config" ]; then
666660
echo ""
667-
echo "Fork state hash not defined. Please refer to mina or o(1) Labs team announcements regarding fork block state hash"
668-
echo "which is required to run final migration"
669-
exit 1
670-
fi
671-
if [ -z "$__fork_config" ]; then
672-
echo ""
673-
echo "Fork config file is not defined. Please refer to mina or o(1) Labs team announcements regarding fork block state hash"
661+
echo "Fork genesis config file is not defined. Please refer to mina or o(1) Labs team announcements regarding fork block state hash"
674662
echo "which is required to run final migration"
675663
exit 1
676664
fi
@@ -694,10 +682,9 @@ function final(){
694682
"$__keep_precomputed_blocks" \
695683
"$__stream_blocks" \
696684
"$__network" \
697-
"$__fork_state_hash" \
698685
"$__checkpoint_interval" \
699686
"$__replayer_checkpoint" \
700-
"$__fork_config"
687+
"$__fork_genesis_config"
701688
}
702689

703690
function run_final_migration() {
@@ -709,12 +696,11 @@ function run_final_migration() {
709696
local __keep_precomputed_blocks=$6
710697
local __stream_blocks=$7
711698
local __network=$8
712-
local __fork_state_hash=$9
713-
local __checkpoint_interval=${10}
714-
local __replayer_checkpoint=${11}
715-
local __fork_config=${12}
716-
699+
local __checkpoint_interval=$9
700+
local __replayer_checkpoint=${10}
701+
local __fork_genesis_config=${11}
717702

703+
local __fork_state_hash="$(jq -r .proof.fork.state_hash "$__fork_genesis_config")"
718704
local __date=$(date '+%Y-%m-%d_%H%M')
719705
local __berkely_migration_log="berkeley_migration_$__date.log"
720706
local __replayer_log="replayer_$__date.log"
@@ -758,7 +744,7 @@ function run_final_migration() {
758744
mina-berkeley-migration-verifier post-fork \
759745
--mainnet-archive-uri "$__mainnet_archive_uri" \
760746
--migrated-archive-uri "$__migrated_archive_uri" \
761-
--fork-config-file "$__fork_config" \
747+
--fork-genesis-config "$__fork_genesis_config" \
762748
--migrated-replayer-output "$migrated_replayer_output"
763749

764750
}

src/app/berkeley_migration_verifier/Readme.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,15 +12,15 @@ Application for validating migrated archive schema content. Performed checks rel
1212
Basic usage :
1313

1414
```
15-
mina-berkeley-migration-verifier --mainnet-archive-uri postgres://postgres:postgres@localhost:5432/source_archive --migrated-archive-uri postgres://postgres:postgres@localhost:5432/archive_migrated --migrated-replayer-output migrated_replayer.json --fork-config-file fork_config_fixed.json
15+
mina-berkeley-migration-verifier --mainnet-archive-uri postgres://postgres:postgres@localhost:5432/source_archive --migrated-archive-uri postgres://postgres:postgres@localhost:5432/archive_migrated --migrated-replayer-output migrated_replayer.json --fork-genesis-config fork_config_fixed.json
1616
```
1717

1818
where:
1919

2020
- **mainnet-archive-uri** is a connection string to original schema
2121
- **migrated-archive-uri** is a connection string to already migrated schema
2222
- **migrated-replayer-output** is an output for replayer on migrated schema
23-
- **fork-config-file** is a state dump with forked ledger
23+
- **fork-genesis-config** is a genesis config for the fork network
2424

2525
### Dependencies
2626

src/app/berkeley_migration_verifier/berkeley_migration_verifier.ml

Lines changed: 19 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -255,14 +255,14 @@ let compare_internal_commands migrated_pool mainnet_pool ~work_dir =
255255
in
256256
diff_files internal_commands_berk internal_commands_main
257257

258-
let compare_ledger_hash ~migrated_replayer_output ~fork_config_file =
258+
let compare_ledger_hash ~migrated_replayer_output ~fork_genesis_config_file =
259259
let checkpoint_ledger_hash =
260260
Yojson.Basic.from_file migrated_replayer_output
261261
|> member "genesis_ledger" |> member "hash" |> to_string
262262
|> Ledger_hash.of_base58_check_exn
263263
in
264264
let fork_ledger_hash =
265-
Yojson.Basic.from_file fork_config_file
265+
Yojson.Basic.from_file fork_genesis_config_file
266266
|> member "ledger" |> member "hash" |> to_string
267267
|> Ledger_hash.of_base58_check_exn
268268
in
@@ -353,24 +353,26 @@ let pre_fork_validations ~mainnet_archive_uri ~migrated_archive_uri () =
353353
Deferred.Or_error.errorf
354354
"Some tests failed. Please refer to above output for details"
355355

356-
let fork_config_exn ~fork_config_file =
357-
Yojson.Basic.from_file fork_config_file |> member "proof" |> member "fork"
356+
let fork_config_exn ~fork_genesis_config_file =
357+
Yojson.Basic.from_file fork_genesis_config_file
358+
|> member "proof" |> member "fork"
358359

359-
let fork_block_state_hash_exn ~fork_config_file =
360-
fork_config_exn ~fork_config_file |> member "state_hash" |> to_string
360+
let fork_block_state_hash_exn ~fork_genesis_config_file =
361+
fork_config_exn ~fork_genesis_config_file |> member "state_hash" |> to_string
361362

362-
let fork_block_height_exn ~fork_config_file =
363-
fork_config_exn ~fork_config_file |> member "blockchain_length" |> to_int
363+
let fork_block_height_exn ~fork_genesis_config_file =
364+
fork_config_exn ~fork_genesis_config_file
365+
|> member "blockchain_length" |> to_int
364366

365367
let post_fork_validations ~mainnet_archive_uri ~migrated_archive_uri
366-
~migrated_replayer_output ~fork_config_file () =
368+
~migrated_replayer_output ~fork_genesis_config_file () =
367369
Async.printf
368370
"Running verifications for incremental migration between '%s' and '%s' \
369371
schemas. It may take a couple of minutes... \n"
370372
mainnet_archive_uri migrated_archive_uri ;
371373

372-
let fork_height = fork_block_height_exn ~fork_config_file in
373-
let fork_state_hash = fork_block_state_hash_exn ~fork_config_file in
374+
let fork_height = fork_block_height_exn ~fork_genesis_config_file in
375+
let fork_state_hash = fork_block_state_hash_exn ~fork_genesis_config_file in
374376

375377
let mainnet_archive_uri = Uri.of_string mainnet_archive_uri in
376378
let migrated_archive_uri = Uri.of_string migrated_archive_uri in
@@ -451,7 +453,7 @@ let post_fork_validations ~mainnet_archive_uri ~migrated_archive_uri
451453
|> Test.eval ;
452454

453455
let check =
454-
compare_ledger_hash ~migrated_replayer_output ~fork_config_file
456+
compare_ledger_hash ~migrated_replayer_output ~fork_genesis_config_file
455457
in
456458
Test.of_check check ~name:"Verify fork config vs migrated replayer output"
457459
~idx:8 ~prefix:"A10.3" test_count
@@ -494,14 +496,15 @@ let post_fork_migration_command =
494496
~aliases:[ "-migrated-replayer-output" ]
495497
Command.Param.(required string)
496498
~doc:"Path Path to migrated replayer output"
497-
and fork_config_file =
498-
Command.Param.flag "--fork-config-file" ~aliases:[ "-fork-config-file" ]
499+
and fork_genesis_config_file =
500+
Command.Param.flag "--fork-genesis-config"
501+
~aliases:[ "-fork-genesis-config" ]
499502
Command.Param.(required string)
500-
~doc:"String Path to fork config file"
503+
~doc:"String Path to config file of the fork network"
501504
in
502505

503506
post_fork_validations ~mainnet_archive_uri ~migrated_archive_uri
504-
~migrated_replayer_output ~fork_config_file)
507+
~migrated_replayer_output ~fork_genesis_config_file)
505508

506509
let commands =
507510
[ ("pre-fork", incremental_migration_command)

0 commit comments

Comments
 (0)