From 2fbd0b1573a10b2d805ed43b07e61d8514ced7d4 Mon Sep 17 00:00:00 2001 From: "iguerNL@Functori" Date: Wed, 8 Oct 2025 10:22:04 +0200 Subject: [PATCH 1/2] DAL/Plugin: cells_of_level returns the attestation_lag as well --- src/lib_dal_node/block_handler.ml | 2 +- src/lib_dal_node/dal_plugin.ml | 4 +++- src/lib_dal_node/dal_plugin.mli | 4 +++- src/lib_dal_node/slot_manager.ml | 5 +++-- .../lib_dal/dal_plugin_registration.ml | 10 +++++----- .../lib_dal/dal_plugin_registration.ml | 10 +++++----- .../lib_dal/dal_plugin_registration.ml | 10 +++++----- .../lib_dal/dal_plugin_registration.ml | 10 +++++----- src/proto_alpha/lib_dal/dal_plugin_registration.ml | 8 ++++---- 9 files changed, 34 insertions(+), 29 deletions(-) diff --git a/src/lib_dal_node/block_handler.ml b/src/lib_dal_node/block_handler.ml index 1a1ecd50d80d..75eab94b34e4 100644 --- a/src/lib_dal_node/block_handler.ml +++ b/src/lib_dal_node/block_handler.ml @@ -192,7 +192,7 @@ let store_skip_list_cells ctxt cctxt dal_constants ~attested_level in let cells_of_level = List.map - (fun (hash, cell, slot_index) -> + (fun (hash, cell, slot_index, _cell_attestation_lag) -> ( Dal_proto_types.Skip_list_hash.of_proto Plugin.Skip_list.hash_encoding hash, diff --git a/src/lib_dal_node/dal_plugin.ml b/src/lib_dal_node/dal_plugin.ml index 81100c925a1e..d379adfaa9e1 100644 --- a/src/lib_dal_node/dal_plugin.ml +++ b/src/lib_dal_node/dal_plugin.ml @@ -27,6 +27,8 @@ type operation_application_result = Succeeded | Failed type slot_index = int +type attestation_lag = int + type slot_header = { published_level : int32; slot_index : slot_index; @@ -125,7 +127,7 @@ module type T = sig dal_constants:Tezos_dal_node_services.Types.proto_parameters -> pred_publication_level_dal_constants: Tezos_dal_node_services.Types.proto_parameters tzresult Lwt.t Lazy.t -> - (hash * cell * slot_index) list tzresult Lwt.t + (hash * cell * slot_index * attestation_lag) list tzresult Lwt.t val slot_header_of_cell : cell -> slot_header option diff --git a/src/lib_dal_node/dal_plugin.mli b/src/lib_dal_node/dal_plugin.mli index 403338f8f2eb..d09a92f3b7a9 100644 --- a/src/lib_dal_node/dal_plugin.mli +++ b/src/lib_dal_node/dal_plugin.mli @@ -33,6 +33,8 @@ type operation_application_result = type slot_index = int +type attestation_lag = int + (** Information extracted from DAL slots headers operations included in L1 blocks. Each slot header is made of an L1 level for which it is published, the slot's index and commitment. *) @@ -176,7 +178,7 @@ module type T = sig dal_constants:Tezos_dal_node_services.Types.proto_parameters -> pred_publication_level_dal_constants: Tezos_dal_node_services.Types.proto_parameters tzresult Lwt.t Lazy.t -> - (hash * cell * slot_index) list tzresult Lwt.t + (hash * cell * slot_index * attestation_lag) list tzresult Lwt.t (** Extracts and returns the slot header of the given cell if it was published to L1. *) diff --git a/src/lib_dal_node/slot_manager.ml b/src/lib_dal_node/slot_manager.ml index 8cafb68d97e8..c2ad608e72a8 100644 --- a/src/lib_dal_node/slot_manager.ml +++ b/src/lib_dal_node/slot_manager.ml @@ -403,10 +403,11 @@ let _try_get_slot_header_from_L1_skip_list (module Plugin : Dal_plugin.T) ctxt in match List.find_all - (fun (_hash, _cell, cell_slot_index) -> cell_slot_index = slot_index) + (fun (_hash, _cell, cell_slot_index, _cell_attestation_lag) -> + cell_slot_index = slot_index) cells_of_level with - | [(_cell_hash, cell, _slot_index)] -> + | [(_cell_hash, cell, _slot_index, _cell_attestation_lag)] -> Plugin.Skip_list.slot_header_of_cell cell |> return | _ -> (* This should not happen (unless the slot index is not valid). In fact, diff --git a/src/proto_021_PsQuebec/lib_dal/dal_plugin_registration.ml b/src/proto_021_PsQuebec/lib_dal/dal_plugin_registration.ml index 0ab4095079cc..7ba64e712cc0 100644 --- a/src/proto_021_PsQuebec/lib_dal/dal_plugin_registration.ml +++ b/src/proto_021_PsQuebec/lib_dal/dal_plugin_registration.ml @@ -293,11 +293,11 @@ module Plugin = struct ~block:(`Level attested_level) ~operations_metadata:`Never in + let attestation_lag = + dal_constants.Tezos_dal_node_services.Types.attestation_lag + in let published_level = - Int32.sub - attested_level - (Int32.of_int - dal_constants.Tezos_dal_node_services.Types.attestation_lag) + Int32.sub attested_level (Int32.of_int attestation_lag) in (* 1. There are no cells for [published_level = 0]. *) if published_level <= 0l then return [] @@ -434,7 +434,7 @@ module Plugin = struct (* This should never happen: all hashes from [ordered_hashes_by_insertion] must exist in [last_cells_map]. *) assert false - | Some cell -> (hash, cell, slot_index)) + | Some cell -> (hash, cell, slot_index, attestation_lag)) ordered_hashes_by_insertion in return last_cells_ordered_by_insertion diff --git a/src/proto_022_PsRiotum/lib_dal/dal_plugin_registration.ml b/src/proto_022_PsRiotum/lib_dal/dal_plugin_registration.ml index f7f32a11ce97..76fa0002ee46 100644 --- a/src/proto_022_PsRiotum/lib_dal/dal_plugin_registration.ml +++ b/src/proto_022_PsRiotum/lib_dal/dal_plugin_registration.ml @@ -311,11 +311,11 @@ module Plugin = struct ~pred_publication_level_dal_constants:_ = let open Lwt_result_syntax in let cpctxt = new Protocol_client_context.wrap_rpc_context ctxt in + let attestation_lag = + dal_constants.Tezos_dal_node_services.Types.attestation_lag + in let published_level = - Int32.sub - attested_level - (Int32.of_int - dal_constants.Tezos_dal_node_services.Types.attestation_lag) + Int32.sub attested_level (Int32.of_int attestation_lag) in (* 1. There are no cells for [published_level = 0]. *) if published_level <= 0l then return [] @@ -335,7 +335,7 @@ module Plugin = struct Slots_history.(content cell |> content_id).index |> Slot_index.to_int) in - (hash, cell, slot_index)) + (hash, cell, slot_index, attestation_lag)) cells let slot_header_of_cell cell = diff --git a/src/proto_023_PtSeouLo/lib_dal/dal_plugin_registration.ml b/src/proto_023_PtSeouLo/lib_dal/dal_plugin_registration.ml index e826e831e5d9..efdc202b55d3 100644 --- a/src/proto_023_PtSeouLo/lib_dal/dal_plugin_registration.ml +++ b/src/proto_023_PtSeouLo/lib_dal/dal_plugin_registration.ml @@ -352,11 +352,11 @@ module Plugin = struct ~pred_publication_level_dal_constants:_ = let open Lwt_result_syntax in let cpctxt = new Protocol_client_context.wrap_rpc_context ctxt in + let attestation_lag = + dal_constants.Tezos_dal_node_services.Types.attestation_lag + in let published_level = - Int32.sub - attested_level - (Int32.of_int - dal_constants.Tezos_dal_node_services.Types.attestation_lag) + Int32.sub attested_level (Int32.of_int attestation_lag) in (* 1. There are no cells for [published_level = 0]. *) if published_level <= 0l then return [] @@ -376,7 +376,7 @@ module Plugin = struct Slots_history.(content cell |> content_id).index |> Slot_index.to_int) in - (hash, cell, slot_index)) + (hash, cell, slot_index, attestation_lag)) cells let slot_header_of_cell cell = diff --git a/src/proto_024_PsU87LFi/lib_dal/dal_plugin_registration.ml b/src/proto_024_PsU87LFi/lib_dal/dal_plugin_registration.ml index 017ffe36f8bd..5ad1652f187f 100644 --- a/src/proto_024_PsU87LFi/lib_dal/dal_plugin_registration.ml +++ b/src/proto_024_PsU87LFi/lib_dal/dal_plugin_registration.ml @@ -352,11 +352,11 @@ module Plugin = struct ~pred_publication_level_dal_constants:_ = let open Lwt_result_syntax in let cpctxt = new Protocol_client_context.wrap_rpc_context ctxt in + let attestation_lag = + dal_constants.Tezos_dal_node_services.Types.attestation_lag + in let published_level = - Int32.sub - attested_level - (Int32.of_int - dal_constants.Tezos_dal_node_services.Types.attestation_lag) + Int32.sub attested_level (Int32.of_int attestation_lag) in (* 1. There are no cells for [published_level = 0]. *) if published_level <= 0l then return [] @@ -376,7 +376,7 @@ module Plugin = struct Slots_history.(content cell |> content_id).index |> Slot_index.to_int) in - (hash, cell, slot_index)) + (hash, cell, slot_index, attestation_lag)) cells let slot_header_of_cell cell = diff --git a/src/proto_alpha/lib_dal/dal_plugin_registration.ml b/src/proto_alpha/lib_dal/dal_plugin_registration.ml index a9dc8002074f..2b79f6f965a1 100644 --- a/src/proto_alpha/lib_dal/dal_plugin_registration.ml +++ b/src/proto_alpha/lib_dal/dal_plugin_registration.ml @@ -411,10 +411,10 @@ module Plugin = struct let cell_id = H.(content cell |> content_id) in let slot_id = cell_id.H.header_id in let slot_index = Dal.Slot_index.to_int slot_id.index in + let attestation_lag = + H.attestation_lag_value cell_id.attestation_lag + in let* () = - let attestation_lag = - H.attestation_lag_value cell_id.attestation_lag - in let expected_attested_level = Raw_level.( add slot_id.published_level attestation_lag |> to_int32) @@ -424,7 +424,7 @@ module Plugin = struct (Attested_level_mismatch {attested_level; published_level; attestation_lag}) in - return (hash, cell, slot_index)) + return (hash, cell, slot_index, attestation_lag)) cells let slot_header_of_cell cell = -- GitLab From ecdb69f9e46427e8bc3f7ebf67657dd338485fc1 Mon Sep 17 00:00:00 2001 From: "iguerNL@Functori" Date: Thu, 16 Oct 2025 16:59:43 +0200 Subject: [PATCH 2/2] DAL/Node: use the per-cell lag returned by the plugin when indexing the skip list --- src/lib_dal_node/block_handler.ml | 15 ++++----------- src/lib_dal_node/dal_store_sqlite3.ml | 7 +++++-- src/lib_dal_node/dal_store_sqlite3.mli | 17 ++++++++++------- src/lib_dal_node/store.ml | 5 ++--- src/lib_dal_node/store.mli | 9 ++++++--- src/lib_dal_node_services/types.ml | 2 ++ src/lib_dal_node_services/types.mli | 3 +++ 7 files changed, 32 insertions(+), 26 deletions(-) diff --git a/src/lib_dal_node/block_handler.ml b/src/lib_dal_node/block_handler.ml index 75eab94b34e4..cc65cc346b7d 100644 --- a/src/lib_dal_node/block_handler.ml +++ b/src/lib_dal_node/block_handler.ml @@ -192,26 +192,19 @@ let store_skip_list_cells ctxt cctxt dal_constants ~attested_level in let cells_of_level = List.map - (fun (hash, cell, slot_index, _cell_attestation_lag) -> + (fun (hash, cell, slot_index, cell_attestation_lag) -> ( Dal_proto_types.Skip_list_hash.of_proto Plugin.Skip_list.hash_encoding hash, Dal_proto_types.Skip_list_cell.of_proto Plugin.Skip_list.cell_encoding cell, - slot_index )) + slot_index, + cell_attestation_lag )) cells_of_level in let store = Node_context.get_store ctxt in - (* DAL/FIXME: use the lag and published_level returned by the cells_of_level - in https://gitlab.com/tezos/tezos/-/merge_requests/19512 *) - let attestation_lag = dal_constants.Types.attestation_lag in - let published_level = Int32.(sub attested_level (of_int attestation_lag)) in - Store.Skip_list_cells.insert - store - ~published_level - ~attestation_lag - cells_of_level + Store.Skip_list_cells.insert store ~attested_level cells_of_level (* This functions counts, for each slot, the number of shards attested by the bakers. *) let attested_shards_per_slot attestations slot_to_committee ~number_of_slots diff --git a/src/lib_dal_node/dal_store_sqlite3.ml b/src/lib_dal_node/dal_store_sqlite3.ml index 420a9bd4b515..747791abb16f 100644 --- a/src/lib_dal_node/dal_store_sqlite3.ml +++ b/src/lib_dal_node/dal_store_sqlite3.ml @@ -268,11 +268,14 @@ module Skip_list_cells = struct let* () = Sqlite.Db.exec conn Q.delete_skip_list_slot published_level in return_unit - let insert ?conn store ~published_level ~attestation_lag items = + let insert ?conn store ~attested_level items = let open Lwt_result_syntax in with_connection store conn @@ fun conn -> List.iter_es - (fun (cell_hash, cell, slot_index) -> + (fun (cell_hash, cell, slot_index, attestation_lag) -> + let published_level = + Int32.(sub attested_level (of_int attestation_lag)) + in let* () = Sqlite.Db.exec conn diff --git a/src/lib_dal_node/dal_store_sqlite3.mli b/src/lib_dal_node/dal_store_sqlite3.mli index 91c7c722e9fa..2a6d9693fa5b 100644 --- a/src/lib_dal_node/dal_store_sqlite3.mli +++ b/src/lib_dal_node/dal_store_sqlite3.mli @@ -68,16 +68,19 @@ module Skip_list_cells : sig tzresult Lwt.t - (** [insert ?conn store ~published_level ~attestation_lag values] inserts the - given list of [values] associated to the given [published_level] in the - [store]. Any existing value is overridden. Uses the [conn] if provided - (defaults to [None]). *) + (** [insert ?conn store ~attested_level values] inserts the given list of + [values] associated to the given [attested_level] in the [store]. Any + existing value is overridden. Uses the [conn] if provided (defaults to + [None]). *) val insert : ?conn:conn -> t -> - published_level:int32 -> - attestation_lag:int -> - (Skip_list_hash.t * Skip_list_cell.t * Types.slot_index) list -> + attested_level:int32 -> + (Skip_list_hash.t + * Skip_list_cell.t + * Types.slot_index + * Types.attestation_lag) + list -> unit tzresult Lwt.t (** [remove ?conn store ~published_level] removes any data related to diff --git a/src/lib_dal_node/store.ml b/src/lib_dal_node/store.ml index 8d669694f741..39c2a3283e53 100644 --- a/src/lib_dal_node/store.ml +++ b/src/lib_dal_node/store.ml @@ -919,12 +919,11 @@ module Skip_list_cells = struct t.skip_list_cells_store ~published_level - let insert ?conn t ~published_level ~attestation_lag items = + let insert ?conn t ~attested_level items = Dal_store_sqlite3.Skip_list_cells.insert ?conn t.skip_list_cells_store - ~published_level - ~attestation_lag + ~attested_level items let remove ?conn t ~published_level = diff --git a/src/lib_dal_node/store.mli b/src/lib_dal_node/store.mli index 9033be40339d..3f91eb64228d 100644 --- a/src/lib_dal_node/store.mli +++ b/src/lib_dal_node/store.mli @@ -281,9 +281,12 @@ module Skip_list_cells : sig val insert : ?conn:Dal_store_sqlite3.conn -> t -> - published_level:int32 -> - attestation_lag:int -> - (Skip_list_hash.t * Skip_list_cell.t * Types.slot_index) list -> + attested_level:int32 -> + (Skip_list_hash.t + * Skip_list_cell.t + * Types.slot_index + * Types.attestation_lag) + list -> unit tzresult Lwt.t (** [remove ?conn store ~published_level] removes any data related to [published_level] diff --git a/src/lib_dal_node_services/types.ml b/src/lib_dal_node_services/types.ml index f76114b59f52..a8a4cd3f8b32 100644 --- a/src/lib_dal_node_services/types.ml +++ b/src/lib_dal_node_services/types.ml @@ -31,6 +31,8 @@ type slot_index = int type page_index = int +type attestation_lag = int + module Topic = struct type t = {slot_index : int; pkh : Signature.Public_key_hash.t} diff --git a/src/lib_dal_node_services/types.mli b/src/lib_dal_node_services/types.mli index 4c668b155f7f..e09868ce2d07 100644 --- a/src/lib_dal_node_services/types.mli +++ b/src/lib_dal_node_services/types.mli @@ -36,6 +36,9 @@ type slot_index = int (** An index of a DAL page. *) type page_index = int +(** A DAL attestation lag *) +type attestation_lag = int + (** An ID associated to a slot or to its commitment. *) module Slot_id : sig type t = {slot_level : level; slot_index : slot_index} -- GitLab