From 0f2cf33a486d0424ae8422415e4deacd2ae8461f Mon Sep 17 00:00:00 2001 From: "iguerNL@Functori" Date: Fri, 16 Feb 2024 18:53:32 +0100 Subject: [PATCH 1/2] Proto: export a view type/function in bounded_cache.ml --- src/proto_alpha/lib_protocol/bounded_history_repr.ml | 10 ++++++++++ src/proto_alpha/lib_protocol/bounded_history_repr.mli | 7 +++++++ 2 files changed, 17 insertions(+) diff --git a/src/proto_alpha/lib_protocol/bounded_history_repr.ml b/src/proto_alpha/lib_protocol/bounded_history_repr.ml index c3d6a3daaf8d..b32d1d6d9f80 100644 --- a/src/proto_alpha/lib_protocol/bounded_history_repr.ml +++ b/src/proto_alpha/lib_protocol/bounded_history_repr.ml @@ -54,8 +54,14 @@ module type S = sig type value + module Map : Map.S with type key = key + + type view = value Map.t + val empty : capacity:int64 -> t + val view : t -> view + val encoding : t Data_encoding.t val pp : Format.formatter -> t -> unit @@ -87,6 +93,8 @@ module Make (Name : NAME) (Key : KEY) (Value : VALUE) : module Int64_map = Map.Make (Int64) module Map = Map.Make (Key) + type view = value Map.t + type t = { events : value Map.t; (** Values stored in the structure, indexes with the keys. *) @@ -107,6 +115,8 @@ module Make (Name : NAME) (Key : KEY) (Value : VALUE) : satisfies the invariant: `0 <= size <= capacity` *) } + let view t = t.events + let encoding : t Data_encoding.t = let open Data_encoding in let events_encoding = diff --git a/src/proto_alpha/lib_protocol/bounded_history_repr.mli b/src/proto_alpha/lib_protocol/bounded_history_repr.mli index 7195bb86169c..5da12bf3a3f5 100644 --- a/src/proto_alpha/lib_protocol/bounded_history_repr.mli +++ b/src/proto_alpha/lib_protocol/bounded_history_repr.mli @@ -66,11 +66,18 @@ module type S = sig type key + module Map : Map.S with type key = key + type value + type view = value Map.t + (** [empty ~capacity] returns a new table whose maximum capacity is given. *) val empty : capacity:int64 -> t + (** Export a view of the given bounded cache *) + val view : t -> view + (** Encoding for values of type {!t} *) val encoding : t Data_encoding.t -- GitLab From fdd0aef956d74241fc50c18e015f0b8e3f304795 Mon Sep 17 00:00:00 2001 From: "iguerNL@Functori" Date: Fri, 16 Feb 2024 19:19:55 +0100 Subject: [PATCH 2/2] Proto/Dal: use Bounded_cache's view in produce_proof's get_history fct --- .../lib_protocol/test/helpers/dal_helpers.ml | 3 ++- .../refutation_game_helpers.ml | 18 ++++++++++++------ 2 files changed, 14 insertions(+), 7 deletions(-) diff --git a/src/proto_alpha/lib_protocol/test/helpers/dal_helpers.ml b/src/proto_alpha/lib_protocol/test/helpers/dal_helpers.ml index c8d9c7c2b4a7..3d9e72457d2e 100644 --- a/src/proto_alpha/lib_protocol/test/helpers/dal_helpers.ml +++ b/src/proto_alpha/lib_protocol/test/helpers/dal_helpers.ml @@ -87,7 +87,8 @@ struct (* Helper functions. *) - let get_history cache h = Hist.History_cache.find h cache |> Lwt.return + let get_history cache h = + Hist.History_cache.(Map.find h (view cache)) |> Lwt.return let dal_mk_polynomial_from_slot slot_data = let open Result_syntax in diff --git a/src/proto_alpha/lib_sc_rollup_node/refutation_game_helpers.ml b/src/proto_alpha/lib_sc_rollup_node/refutation_game_helpers.ml index fbb435cba3b7..737e263e18e0 100644 --- a/src/proto_alpha/lib_sc_rollup_node/refutation_game_helpers.ml +++ b/src/proto_alpha/lib_sc_rollup_node/refutation_game_helpers.ml @@ -168,12 +168,16 @@ let generate_proof (node_ctxt : _ Node_context.t) Dal_slots_tracker.slots_history_of_hash node_ctxt snapshot_head else return Dal.Slots_history.genesis in - let* dal_slots_history_cache = - if Node_context.dal_supported node_ctxt then - let* snapshot_head = get_snapshot_head () in - Dal_slots_tracker.slots_history_cache_of_hash node_ctxt snapshot_head - else return (Dal.Slots_history.History_cache.empty ~capacity:0L) + let* dal_slots_history_cache_view = + let* dal_slots_history_cache = + if Node_context.dal_supported node_ctxt then + let* snapshot_head = get_snapshot_head () in + Dal_slots_tracker.slots_history_cache_of_hash node_ctxt snapshot_head + else return (Dal.Slots_history.History_cache.empty ~capacity:0L) + in + Dal.Slots_history.History_cache.view dal_slots_history_cache |> return in + (* We fetch the value of protocol constants at block snapshot level where the game started. *) let* constants = @@ -260,7 +264,9 @@ let generate_proof (node_ctxt : _ Node_context.t) let confirmed_slots_history = dal_slots_history let get_history ptr = - Dal.Slots_history.History_cache.find ptr dal_slots_history_cache + Dal.Slots_history.History_cache.Map.find + ptr + dal_slots_history_cache_view |> Lwt.return let dal_attestation_lag = dal_attestation_lag -- GitLab