diff --git a/src/lib_store/unix/test/test_consistency.ml b/src/lib_store/unix/test/test_consistency.ml index d1083d4af6202bf93269632af4cefc724f71db2d..610f9850d6c13ad12d30716c0ccd31b7a88997ae 100644 --- a/src/lib_store/unix/test/test_consistency.ml +++ b/src/lib_store/unix/test/test_consistency.ml @@ -86,7 +86,7 @@ let init_protocols store history_mode = { Test_utils.default_protocol_constants with blocks_per_cycle = Int32.of_int nb_blocks_per_cycle; - preserved_cycles = 1; + blocks_preservation_cycles = 1; } in let* () = diff --git a/src/lib_store/unix/test/test_snapshots.ml b/src/lib_store/unix/test/test_snapshots.ml index 5084c6fb27d638e6d80da2f3c16e18cca645a1ba..c37eb88ac417a5ed6f1bc938ba57f43eacee615c 100644 --- a/src/lib_store/unix/test/test_snapshots.ml +++ b/src/lib_store/unix/test/test_snapshots.ml @@ -197,7 +197,10 @@ let check_baking_continuity ~test_descr ~exported_chain_store let open Lwt_result_syntax in let open Tezos_protocol_alpha.Protocol.Alpha_context in let*! imported_head = Store.Chain.current_head imported_chain_store in - let* {Constants.parametric = {blocks_per_cycle; preserved_cycles; _}; _} = + let* { + Constants.parametric = {blocks_per_cycle; blocks_preservation_cycles; _}; + _; + } = Alpha_utils.get_constants imported_chain_store imported_head in let imported_history_mode = Store.Chain.history_mode imported_chain_store in @@ -212,7 +215,8 @@ let check_baking_continuity ~test_descr ~exported_chain_store let min_nb_blocks_to_bake = Int32.( of_int - (to_int blocks_per_cycle * (preserved_cycles + imported_offset + 2))) + (to_int blocks_per_cycle + * (blocks_preservation_cycles + imported_offset + 2))) in Compare.Int32.( max @@ -387,7 +391,11 @@ let make_tests speed genesis_parameters = let open Tezos_protocol_alpha.Protocol.Alpha_context in let { Parameters.constants = - {Constants.Parametric.blocks_per_cycle; preserved_cycles; _}; + { + Constants.Parametric.blocks_per_cycle; + blocks_preservation_cycles = preserved_cycles; + _; + }; _; } = genesis_parameters diff --git a/src/lib_store/unix/test/test_utils.ml b/src/lib_store/unix/test/test_utils.ml index f0292d9432474dde390ce00afd79942dbec11e2e..29cbdb73fd0b32e4327ba80eb18be2685e6bcd24 100644 --- a/src/lib_store/unix/test/test_utils.ml +++ b/src/lib_store/unix/test/test_utils.ml @@ -392,7 +392,7 @@ let make_raw_block ?min_lafl ?(max_operations_ttl = default_max_operations_ttl) constants.blocks_per_cycle (Compare.Int32.max 0l - (sub current_cycle (of_int constants.preserved_cycles)))) + (sub current_cycle (of_int constants.blocks_preservation_cycles)))) in let last_allowed_fork_level = match min_lafl with diff --git a/src/proto_alpha/lib_protocol/alpha_context.ml b/src/proto_alpha/lib_protocol/alpha_context.ml index c841f7a71af97b0d102b5f99c2fdc5ceec55a9ec..f8383487b87c3d849846e878b85f9266d2050d12 100644 --- a/src/proto_alpha/lib_protocol/alpha_context.ml +++ b/src/proto_alpha/lib_protocol/alpha_context.ml @@ -664,7 +664,7 @@ let finalize ?commit_message:message c fitness = message; max_operations_ttl = (Raw_context.constants c).max_operations_time_to_live; last_allowed_fork_level = - Raw_level.to_int32 @@ Level.last_allowed_fork_level c; + Raw_level.to_int32 @@ Level.last_preserved_block_level c; } let current_context c = Raw_context.recover c diff --git a/src/proto_alpha/lib_protocol/alpha_context.mli b/src/proto_alpha/lib_protocol/alpha_context.mli index e3c6bf9522a1e010060e6f6143ce85911e5761df..14540d7c16615d5432040e9506f1f91535fdeb33 100644 --- a/src/proto_alpha/lib_protocol/alpha_context.mli +++ b/src/proto_alpha/lib_protocol/alpha_context.mli @@ -1207,7 +1207,7 @@ module Level : sig val levels_in_current_cycle : context -> ?offset:int32 -> unit -> level list - val last_allowed_fork_level : context -> Raw_level.t + val last_preserved_block_level : context -> Raw_level.t val dawn_of_a_new_cycle : context -> Cycle.t option diff --git a/src/proto_alpha/lib_protocol/level_storage.ml b/src/proto_alpha/lib_protocol/level_storage.ml index 2bf78176bc83becfa92cc186c5374733144fab53..c8ffb1dfbf660c4d554c6eb5bba7f56d0335449d 100644 --- a/src/proto_alpha/lib_protocol/level_storage.ml +++ b/src/proto_alpha/lib_protocol/level_storage.ml @@ -100,10 +100,12 @@ let levels_with_commitments_in_cycle ctxt c = in loop first [] -let last_allowed_fork_level c = +let last_preserved_block_level c = let level = Raw_context.current_level c in - let preserved_cycles = Constants_storage.preserved_cycles c in - match Cycle_repr.sub level.cycle preserved_cycles with + let block_conservation_cycles = + Constants_storage.blocks_preservation_cycles c + in + match Cycle_repr.sub level.cycle block_conservation_cycles with | None -> Raw_level_repr.root | Some cycle -> (first_level_in_cycle c cycle).level diff --git a/src/proto_alpha/lib_protocol/level_storage.mli b/src/proto_alpha/lib_protocol/level_storage.mli index d5c2f82864ae0f4cea4e4f310a5ccbef53aa1ccd..acc1792e9d7ca6fced13cdd87955274e32a0b5f3 100644 --- a/src/proto_alpha/lib_protocol/level_storage.mli +++ b/src/proto_alpha/lib_protocol/level_storage.mli @@ -62,7 +62,7 @@ val levels_in_current_cycle : val levels_with_commitments_in_cycle : Raw_context.t -> Cycle_repr.t -> Level_repr.t list -val last_allowed_fork_level : Raw_context.t -> Raw_level_repr.t +val last_preserved_block_level : Raw_context.t -> Raw_level_repr.t (** Returns [Some cycle] if the current level represents the last level of [cycle] and [None] if the level is not the last level of a diff --git a/tezt/tests/storage_reconstruction.ml b/tezt/tests/storage_reconstruction.ml index 6b000347b8f6c4a65382f926439f8ad09c92b69f..9e719603fc6f6fce668e2205c0b96b0d4027e49a 100644 --- a/tezt/tests/storage_reconstruction.ml +++ b/tezt/tests/storage_reconstruction.ml @@ -41,12 +41,17 @@ let pp_snapshot_history_mode fmt v = | Node.Rolling_history -> "rolling" | Node.Full_history -> "full") v) -let get_constants client = +let get_constants ~protocol client = let* constants = Client.RPC.call client @@ RPC.get_chain_block_context_constants () in - let* preserved_cycles = - return JSON.(constants |-> "preserved_cycles" |> as_int) + let blocks_preservation_cycles = + let v = + if Protocol.number protocol > Protocol.number Protocol.Oxford then + "blocks_preservation_cycles" + else "preserved_cycles" + in + JSON.(constants |-> v |> as_int) in let* blocks_per_cycle = return JSON.(constants |-> "blocks_per_cycle" |> as_int) @@ -54,7 +59,7 @@ let get_constants client = let* max_op_ttl = return JSON.(constants |-> "max_operations_time_to_live" |> as_int) in - return (preserved_cycles, blocks_per_cycle, max_op_ttl) + return (blocks_preservation_cycles, blocks_per_cycle, max_op_ttl) let export_snapshot node ~export_level ~snapshot_dir ~history_mode ~export_format = @@ -142,9 +147,11 @@ let test_storage_reconstruction = `Client () in - let* preserved_cycles, blocks_per_cycle, max_op_ttl = get_constants client in + let* blocks_preservation_cycles, blocks_per_cycle, max_op_ttl = + get_constants ~protocol client + in Log.info "Baking a few blocks so that the savepoint is still at genesis." ; - let blocks_to_bake_1 = preserved_cycles * blocks_per_cycle in + let blocks_to_bake_1 = blocks_preservation_cycles * blocks_per_cycle in let* () = bake_blocks node client ~blocks_to_bake:blocks_to_bake_1 in Log.info "Terminate the node and start a reconstruction." ; let* () = Node.terminate node in diff --git a/tezt/tests/storage_snapshots.ml b/tezt/tests/storage_snapshots.ml index ef26f17a3eb32077a3c5d2867482c1d4770f523e..c265d16c28e420f8fb5712939500c79e1510b322 100644 --- a/tezt/tests/storage_snapshots.ml +++ b/tezt/tests/storage_snapshots.ml @@ -43,16 +43,23 @@ let pp_snapshot_history_mode fmt v = | Node.Rolling_history -> "rolling" | Node.Full_history -> "full") -let get_constants client = +let get_constants ~protocol client = let* constants = Client.RPC.call client @@ RPC.get_chain_block_context_constants () in - let preserved_cycles = JSON.(constants |-> "preserved_cycles" |> as_int) in + let blocks_preservation_cycles = + let v = + if Protocol.number protocol > Protocol.number Protocol.Oxford then + "blocks_preservation_cycles" + else "preserved_cycles" + in + JSON.(constants |-> v |> as_int) + in let blocks_per_cycle = JSON.(constants |-> "blocks_per_cycle" |> as_int) in let max_op_ttl = JSON.(constants |-> "max_operations_time_to_live" |> as_int) in - return (preserved_cycles, blocks_per_cycle, max_op_ttl) + return (blocks_preservation_cycles, blocks_per_cycle, max_op_ttl) let export_snapshot node ~export_level ~snapshot_dir ~history_mode ~export_format = @@ -277,11 +284,13 @@ let test_export_import_snapshots = let* () = Cluster.start ~public:true cluster in let* client = Client.init ~endpoint:(Node archive_node) () in let* () = Client.activate_protocol_and_wait ~protocol client in - let* preserved_cycles, blocks_per_cycle, max_op_ttl = get_constants client in + let* blocks_preservation_cycles, blocks_per_cycle, max_op_ttl = + get_constants ~protocol client + in (* Bake enough blocks so that the rolling node caboose is not at the genesis anymore. To do so, we need to bake at least 3 cycles, after activating the protocol, i.e 3*8 = 24 blocks. *) - let blocks_to_bake = (preserved_cycles + 1) * blocks_per_cycle in + let blocks_to_bake = (blocks_preservation_cycles + 1) * blocks_per_cycle in let* () = bake_blocks archive_node client ~blocks_to_bake in let* archive_level = Node.get_level archive_node in let* () = sync_all_nodes cluster archive_level in @@ -351,7 +360,9 @@ let test_drag_after_rolling_import = let* () = Cluster.start ~public:true cluster in let* client = Client.init ~endpoint:(Node archive_node) () in let* () = Client.activate_protocol_and_wait ~protocol client in - let* preserved_cycles, blocks_per_cycle, max_op_ttl = get_constants client in + let* blocks_preservation_cycles, blocks_per_cycle, max_op_ttl = + get_constants ~protocol client + in Log.info "Baking a few blocks" (* Baking enough blocks so that the caboose is not the genesis anymore (depending on the max_op_ttl)*) ; @@ -393,7 +404,7 @@ let test_drag_after_rolling_import = deterministic and avoids missing the trigger of a merge as the previous one might not be finished yet. *) let blocks_to_bake = - ((preserved_cycles + additional_cycles) * blocks_per_cycle) - 1 + ((blocks_preservation_cycles + additional_cycles) * blocks_per_cycle) - 1 in let expected_checkpoint, expected_savepoint, expected_caboose = (export_level, export_level, max 0 (export_level - max_op_ttl)) @@ -429,7 +440,7 @@ let test_drag_after_rolling_import = store's invariants. *) let wait_for_merge_at_checkpoint = let expected_checkpoint = - final_head - (preserved_cycles * blocks_per_cycle) + final_head - (blocks_preservation_cycles * blocks_per_cycle) in wait_for_complete_merge fresh_node expected_checkpoint in @@ -443,10 +454,12 @@ let test_drag_after_rolling_import = match history_mode with | Node.Full_history -> Test.fail "testing only rolling mode" | Node.Rolling_history -> - let checkpoint = final_head - (preserved_cycles * blocks_per_cycle) in + let checkpoint = + final_head - (blocks_preservation_cycles * blocks_per_cycle) + in let savepoint = final_head - - ((preserved_cycles + additional_cycles) * blocks_per_cycle) + - ((blocks_preservation_cycles + additional_cycles) * blocks_per_cycle) in (checkpoint, savepoint, min savepoint (checkpoint - max_op_ttl)) in