Fix snapshot import and reconstruction edge cases
This MR aims to fix an inaccurate assumptions made in the snapshot import that was introducing accurate metadata values, on edge cases, while importing a snapshot and reconstructing a storage from full to archive. Indeed, the value of the max_operations_ttl was approximated, resulting in a coarse grain max operations ttl adjustment.
The fix simply rely on using the predecessor's max_op_ttl of the imported head when needed. To do so, we now export the pred_max_op_ttl in the block_data field of a snapshot.
This requires a snapshot format update but, as v23 is still rc, we can avoid dealing with a snapshot version bump
Fixes: #1430 (closed)
Manually testing the MR
Testing it is a bit complicated as you need to import and reconstruct a storage next to a protocol activation that changes the max_op_ttl.
To do so, you can use this recipe https://docs.google.com/document/d/1WTgZWmH8QabxvWgOO9oyPNeLHAFsBXYM4vdgjrur9UI/edit?tab=t.0 or simply:
-
apply this patch
commit 5eba2548ba44f898a45cd8c139a0903be485d8c1 (HEAD -> vicall@max_op) Author: Victor Allombert <victor.allombert@nomadic-labs.com> Date: Wed Jul 9 15:54:44 2025 +0200 WIP sandbox simu diff --git a/src/lib_node_config/config_file.ml b/src/lib_node_config/config_file.ml index d4381c5f21..d0ad6d7a65 100644 --- a/src/lib_node_config/config_file.ml +++ b/src/lib_node_config/config_file.ml @@ -203,13 +203,13 @@ let blockchain_network_sandbox = make_blockchain_network ~alias:"sandbox" { - time = Time.Protocol.of_notation_exn "2018-06-30T16:07:32Z"; + time = Time.Protocol.of_notation_exn "2022-01-25T15:00:00Z"; block = Block_hash.of_b58check_exn - "BLockGenesisGenesisGenesisGenesisGenesisf79b5d1CoW2"; + "BLockGenesisGenesisGenesisGenesisGenesis1db77eJNeJ9"; protocol = Protocol_hash.of_b58check_exn - "ProtoGenesisGenesisGenesisGenesisGenesisGenesk612im"; + "Ps9mPmXaRzmzk35gbAYNCAw6UXdE2qoABTHbN2oEEc1qM7CwT9P"; } ~genesis_parameters: (* Genesis public key corresponds to the following private key: diff --git a/src/proto_alpha/lib_protocol/raw_context.ml b/src/proto_alpha/lib_protocol/raw_context.ml index 919dcfc69a..a5d3b4d2dd 100644 --- a/src/proto_alpha/lib_protocol/raw_context.ml +++ b/src/proto_alpha/lib_protocol/raw_context.ml @@ -982,6 +982,10 @@ let get_previous_protocol_constants ctxt = context." | Some constants -> return constants) +let update_block_time_related_constants (c : Constants_parametric_repr.t) = + let max_operations_time_to_live = c.max_operations_time_to_live * 10 in + {c with max_operations_time_to_live} + (* Start of code to remove at next automatic protocol snapshot *) (* Please add here any code that should be removed at the next automatic protocol snapshot *) @@ -1602,8 +1606,10 @@ let prepare_first_block ~level ~timestamp chain_id ctxt = all_bakers_attest_activation_level; } in + let (constants : Constants_parametric_repr.t) = + update_block_time_related_constants constants + in let*! ctxt = add_constants ctxt constants in - return (ctxt, Some c) (* End of alpha predecessor stitching. Comment used for automatic snapshot *) in -
make
-
use a snapshot that I've crafted for you
TEZOS-BKyhY1n6hLoi83qrAoV6tT47cCEbYKhGjPbeMysmhRsjgTXRBVM-170.full.tar.gz
-
Extract the snapshot
-
init a sandbox data-dir
./octez-node config init --network sandbox --data-dir ./sandbox_reconstructed -
import the snapshot
./octez-node snapshot import <sansphot_file> --data-dir ./sandbox_reconstructed --reconstruct
Then, run the node over that data dir DATA_DIR=./sandbox_reconstructed ./src/bin_node/octez-sandboxed-node.sh 1 --connections 0 --rpc-addr 127.0.0.1:18731 and observe that
vicall@wombat ~/Documents/Tezos/Nomadic_DEV/tezos ↱ vicall@max_op ./octez-client --endpoint http://127.0.0.1:18731 rpc get /chains/main/blocks/63/metadata | jq | grep "max_operations_ttl"
"max_operations_ttl": 8,
vicall@wombat ~/Documents/Tezos/Nomadic_DEV/tezos ↱ vicall@max_op ./octez-client --endpoint http://127.0.0.1:18731 rpc get /chains/main/blocks/64/metadata | jq | grep "max_operations_ttl"
"max_operations_ttl": 9,
vicall@wombat ~/Documents/Tezos/Nomadic_DEV/tezos ↱ vicall@max_op ./octez-client --endpoint http://127.0.0.1:18731 rpc get /chains/main/blocks/65/metadata | jq | grep "max_operations_ttl"
"max_operations_ttl": 10,
vicall@wombat ~/Documents/Tezos/Nomadic_DEV/tezos ↱ vicall@max_op ./octez-client --endpoint http://127.0.0.1:18731 rpc get /chains/main/blocks/134/metadata | jq | grep "max_operations_ttl"
"max_operations_ttl": 79,
vicall@wombat ~/Documents/Tezos/Nomadic_DEV/tezos ↱ vicall@max_op ./octez-client --endpoint http://127.0.0.1:18731 rpc get /chains/main/blocks/135/metadata | jq | grep "max_operations_ttl"
"max_operations_ttl": 80,
vicall@wombat ~/Documents/Tezos/Nomadic_DEV/tezos ↱ vicall@max_op ./octez-client --endpoint http://127.0.0.1:18731 rpc get /chains/main/blocks/136/metadata | jq | grep "max_operations_ttl"
"max_operations_ttl": 80,
If you run a similar scenario on master -- keeping the above patch.diff -- and that you import this snapshot (it is basically the snapshot sanpsoht exported from master), you will observe:
TEZOS-BKyhY1n6hLoi83qrAoV6tT47cCEbYKhGjPbeMysmhRsjgTXRBVM-170.full-over-master.tar.gz
✘ vicall@wombat ~/Documents/Tezos/Nomadic_DEV/tezos ↱ vicall@max_op ./octez-client --endpoint http://127.0.0.1:18731 rpc get /chains/main/blocks/63/metadata | jq | grep "max_operations_ttl"
"max_operations_ttl": 8,
vicall@wombat ~/Documents/Tezos/Nomadic_DEV/tezos ↱ vicall@max_op ./octez-client --endpoint http://127.0.0.1:18731 rpc get /chains/main/blocks/64/metadata | jq | grep "max_operations_ttl"
"max_operations_ttl": 64,
vicall@wombat ~/Documents/Tezos/Nomadic_DEV/tezos ↱ vicall@max_op ./octez-client --endpoint http://127.0.0.1:18731 rpc get /chains/main/blocks/65/metadata | jq | grep "max_operations_ttl"
"max_operations_ttl": 65,
vicall@wombat ~/Documents/Tezos/Nomadic_DEV/tezos ↱ vicall@max_op ./octez-client --endpoint http://127.0.0.1:18731 rpc get /chains/main/blocks/134/metadata | jq | grep "max_operations_ttl"
"max_operations_ttl": 80,
vicall@wombat ~/Documents/Tezos/Nomadic_DEV/tezos ↱ vicall@max_op ./octez-client --endpoint http://127.0.0.1:18731 rpc get /chains/main/blocks/135/metadata | jq | grep "max_operations_ttl"
"max_operations_ttl": 80,
As testing this is quite complicated, feel free to ask for help.
Checklist
-
Document the interface of any function added or modified (see the coding guidelines) -
Document any change to the user interface, including configuration parameters (see node configuration) -
Provide automatic testing (see the testing guide). -
For new features and bug fixes, add an item in the appropriate changelog ( docs/protocols/alpha.rstfor the protocol and the environment,CHANGES.rstat the root of the repository for everything else). -
Select suitable reviewers using the Reviewersfield below. -
Select as Assigneethe next person who should take action on that MR