diff --git a/src/proto_alpha/bin_sc_rollup_node/refutation_game.ml b/src/proto_alpha/bin_sc_rollup_node/refutation_game.ml index de09964a71e63e71361dca7f49890a0009286833..d9149c42bfb6701a27aac66f28c27459d75f7ee3 100644 --- a/src/proto_alpha/bin_sc_rollup_node/refutation_game.ml +++ b/src/proto_alpha/bin_sc_rollup_node/refutation_game.ml @@ -150,26 +150,34 @@ module Make (PVM : Pvm.S) : S with module PVM = PVM = struct let new_dissection node_ctxt store last_level ok our_view = let open Lwt_result_syntax in - let _start_hash, start_tick = ok in + let start_hash, start_tick = ok in let our_state, stop_tick = our_view in let Node_context.{protocol_constants; _} = node_ctxt in - (* TODO: #3200 - We should not rely on an hard-coded constant here but instead - introduce a protocol constant for the maximum number of sections - in a dissection. - *) let max_number_of_sections = Z.of_int protocol_constants.parametric.sc_rollup.number_of_sections_in_dissection in let trace_length = Z.succ (Sc_rollup.Tick.distance stop_tick start_tick) in let number_of_sections = Z.min max_number_of_sections trace_length in - let section_length = - Z.(max (of_int 1) (div trace_length number_of_sections)) + let rem = Z.(rem trace_length number_of_sections) in + let first_section_length, section_length = + if Z.Compare.(trace_length < max_number_of_sections) then + (* In this case, every section is of length one. *) + Z.(one, one) + else + let section_length = + Z.(max one (div trace_length number_of_sections)) + in + if Z.Compare.(section_length = Z.one) && not Z.Compare.(rem = Z.zero) + then + (* If we put [section_length] in this situation, we will most likely + have a very long last section. *) + (rem, section_length) + else (section_length, section_length) in (* [k] is the number of sections in [rev_dissection]. *) let rec make rev_dissection k tick = - if Z.equal k (Z.pred number_of_sections) then + if Z.(equal k (pred number_of_sections)) then return @@ List.rev ({state_hash = our_state; tick = stop_tick} :: rev_dissection) @@ -179,7 +187,10 @@ module Make (PVM : Pvm.S) : S with module PVM = PVM = struct let next_tick = Sc_rollup.Tick.jump tick section_length in make ({state_hash; tick} :: rev_dissection) (Z.succ k) next_tick in - make [] Z.zero start_tick + make + [{state_hash = Some start_hash; tick = start_tick}] + Z.one + (Sc_rollup.Tick.jump start_tick first_section_length) (** [generate_from_dissection node_ctxt store game] traverses the current [game.dissection] and returns a move which diff --git a/src/proto_alpha/lib_protocol/sc_rollup_game_repr.ml b/src/proto_alpha/lib_protocol/sc_rollup_game_repr.ml index f73448a384107de8d29c2c80e76011413122e3d3..233a311529cf5e099a43068b5a6d1275dc050b99 100644 --- a/src/proto_alpha/lib_protocol/sc_rollup_game_repr.ml +++ b/src/proto_alpha/lib_protocol/sc_rollup_game_repr.ml @@ -771,7 +771,7 @@ let check_dissection ~default_number_of_sections ~start_chunk ~stop_chunk [Dissection_invalid_number_of_sections] returned above *) invalid_move (Dissection_invalid_number_of_sections len) in - let half_dist = Z.(div dist (of_int 2)) in + let half_dist = Z.(div dist (of_int 2) |> succ) in let rec traverse states = match states with | {state_hash = None; _} :: {state_hash = Some _; _} :: _ ->