diff --git a/src/proto_alpha/lib_protocol/bounded_history_repr.ml b/src/proto_alpha/lib_protocol/bounded_history_repr.ml index c3d6a3daaf8d1934a3b0dc82720b13c783450fa1..b32d1d6d9f8020e6f1134738a3fa32b5d51dd166 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 7195bb86169c796a5956390e47988de294f948ba..5da12bf3a3f541fadd0ecd9c0f59bdc2df3e0af6 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 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 c8d9c7c2b4a7b525674823cdc2a246934d4b5f73..3d9e72457d2e4b969c018c174b10197355fceb7b 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 fbb435cba3b71757ebdba34e5bb49e56d869b01a..737e263e18e03030b084ec6e397a175b3969289b 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