From d3c7343477bb6508b34f9a0015c8fdc0dc79d700 Mon Sep 17 00:00:00 2001 From: Valentin Chaboche Date: Fri, 15 Jul 2022 11:45:17 +0200 Subject: [PATCH 1/2] Scoru,Proto: relax dissection distribution's rule --- src/proto_alpha/lib_protocol/sc_rollup_game_repr.ml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) 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 f73448a38410..233a311529cf 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 _; _} :: _ -> -- GitLab From 6628c3f5a15bbf367e0d1ff7b3243487ae5c02a0 Mon Sep 17 00:00:00 2001 From: Valentin Chaboche Date: Fri, 15 Jul 2022 13:27:56 +0200 Subject: [PATCH 2/2] Scoru,Node: more resilient dissection making --- .../bin_sc_rollup_node/refutation_game.ml | 31 +++++++++++++------ 1 file changed, 21 insertions(+), 10 deletions(-) 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 de09964a71e6..d9149c42bfb6 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 -- GitLab