From 500b894261e20bbe50ddd663586fb4f320907b3e Mon Sep 17 00:00:00 2001 From: Alain Mebsout Date: Fri, 15 Dec 2023 10:40:23 +0100 Subject: [PATCH 1/2] Rollup node: expose get_history_mode function --- src/lib_smart_rollup_node/node_context.ml | 5 +++++ src/lib_smart_rollup_node/node_context.mli | 4 ++++ 2 files changed, 9 insertions(+) diff --git a/src/lib_smart_rollup_node/node_context.ml b/src/lib_smart_rollup_node/node_context.ml index 72f59bcb68cd..5006d5b63585 100644 --- a/src/lib_smart_rollup_node/node_context.ml +++ b/src/lib_smart_rollup_node/node_context.ml @@ -218,6 +218,11 @@ module Lwt_result_option_syntax = struct match a with None -> return_none | Some a -> f a end +let get_history_mode {store; _} = + let open Lwt_result_syntax in + let+ mode = Store.History_mode.read store.history_mode in + Option.value mode ~default:Configuration.default_history_mode + let hash_of_level_opt {store; cctxt; _} level = let open Lwt_result_syntax in let* hash = Store.Levels_to_hashes.find store.levels_to_hashes level in diff --git a/src/lib_smart_rollup_node/node_context.mli b/src/lib_smart_rollup_node/node_context.mli index f401527c8e4e..d941bf9bcc3d 100644 --- a/src/lib_smart_rollup_node/node_context.mli +++ b/src/lib_smart_rollup_node/node_context.mli @@ -200,6 +200,10 @@ type 'a delayed_write = ('a, rw) Delayed_write_monad.t (** {2 Abstraction over store} *) +(** [get_history_mode t] returns the current history mode for the rollup + node. *) +val get_history_mode : _ t -> Configuration.history_mode tzresult Lwt.t + (** {3 Layer 2 blocks} *) (** [is_processed store hash] returns [true] if the block with [hash] has -- GitLab From 036b6d30651f7d53e4fcf4b279cf7efb8af123d1 Mon Sep 17 00:00:00 2001 From: Alain Mebsout Date: Wed, 29 Nov 2023 09:50:34 +0100 Subject: [PATCH 2/2] Rollup node: split context irmin suffix on commitment This allows for a faster GC. --- src/lib_smart_rollup_node/context.ml | 4 ++++ src/lib_smart_rollup_node/context.mli | 5 +++++ src/lib_smart_rollup_node/context_sigs.ml | 5 +++++ src/lib_smart_rollup_node/irmin_context.ml | 2 ++ src/lib_smart_rollup_node/irmin_context.mli | 5 +++++ src/lib_smart_rollup_node/rollup_node_daemon.ml | 5 +++++ 6 files changed, 26 insertions(+) diff --git a/src/lib_smart_rollup_node/context.ml b/src/lib_smart_rollup_node/context.ml index 7c711c3224a4..787827625c16 100644 --- a/src/lib_smart_rollup_node/context.ml +++ b/src/lib_smart_rollup_node/context.ml @@ -113,6 +113,10 @@ let is_gc_finished [> `Write] t) = Pvm_Context_Impl.is_gc_finished index +let split (type a) + (Context {pvm_context_impl = (module Pvm_Context_Impl); index; _} : a t) = + Pvm_Context_Impl.split index + let gc (Context {pvm_context_impl = (module Pvm_Context_Impl); index; _} : [> `Write] t) ?callback hash = diff --git a/src/lib_smart_rollup_node/context.mli b/src/lib_smart_rollup_node/context.mli index 7b87caad0d3a..9954ac44ad11 100644 --- a/src/lib_smart_rollup_node/context.mli +++ b/src/lib_smart_rollup_node/context.mli @@ -105,6 +105,11 @@ val commit : ?message:string -> [`Read | `Write] t -> hash Lwt.t if a GC is running for [index]. *) val is_gc_finished : [`Read | `Write] t -> bool +(** [split ctxt] creates a new suffix file, also called "chunk", into the + irmin's file hierarchy. This split function is expected to be called after + committing a commit that will be a future candidate for a GC target. *) +val split : _ t -> unit + (** [gc index ?callback hash] removes all data older than [hash] from disk. If passed, [callback] will be executed when garbage collection finishes. *) val gc : diff --git a/src/lib_smart_rollup_node/context_sigs.ml b/src/lib_smart_rollup_node/context_sigs.ml index 38249dd6b406..d5c9d70dfa24 100644 --- a/src/lib_smart_rollup_node/context_sigs.ml +++ b/src/lib_smart_rollup_node/context_sigs.ml @@ -120,6 +120,11 @@ module type S = sig if a GC is running for [index]. *) val is_gc_finished : [> `Write] index -> bool + (** [split ctxt] splits the current context in order to chunk the file if the + backend supports it. This split function is expected to be called after + committing a commit that will be a future candidate for a GC target. *) + val split : _ index -> unit + (** [gc index ?callback hash] removes all data older than [hash] from disk. If passed, [callback] will be executed when garbage collection finishes. *) val gc : diff --git a/src/lib_smart_rollup_node/irmin_context.ml b/src/lib_smart_rollup_node/irmin_context.ml index 676829e1b2e4..d3a500c2a35e 100644 --- a/src/lib_smart_rollup_node/irmin_context.ml +++ b/src/lib_smart_rollup_node/irmin_context.ml @@ -125,6 +125,8 @@ let empty index = {index; tree = IStore.Tree.empty ()} let is_empty ctxt = IStore.Tree.is_empty ctxt.tree +let split ctxt = IStore.split ctxt.repo + (* adapted from lib_context/disk/context.ml *) let gc index ?(callback : unit -> unit Lwt.t = fun () -> Lwt.return ()) (hash : hash) = diff --git a/src/lib_smart_rollup_node/irmin_context.mli b/src/lib_smart_rollup_node/irmin_context.mli index 68bf5eb55091..028a62a43df0 100644 --- a/src/lib_smart_rollup_node/irmin_context.mli +++ b/src/lib_smart_rollup_node/irmin_context.mli @@ -98,6 +98,11 @@ val empty : 'a index -> 'a t empty. *) val is_empty : _ t -> bool +(** [split ctxt] creates a new suffix file, also called "chunk", into the + irmin's file hierarchy. This split function is expected to be called after + committing a commit that will be a future candidate for a GC target. *) +val split : _ index -> unit + (** [gc index ?callback hash] removes all data older than [hash] from disk. If passed, [callback] will be executed when garbage collection finishes. *) val gc : diff --git a/src/lib_smart_rollup_node/rollup_node_daemon.ml b/src/lib_smart_rollup_node/rollup_node_daemon.ml index f9d330713751..90fbb4a2b046 100644 --- a/src/lib_smart_rollup_node/rollup_node_daemon.ml +++ b/src/lib_smart_rollup_node/rollup_node_daemon.ml @@ -123,6 +123,11 @@ let process_unseen_head ({node_ctxt; _} as state) ~catching_up ~predecessor head ctxt in + let* history_mode = Node_context.get_history_mode node_ctxt in + let commit_is_gc_candidate = + history_mode <> Archive && Option.is_some commitment_hash + in + if commit_is_gc_candidate then Context.split node_ctxt.context ; let* () = unless (catching_up && Option.is_none commitment_hash) @@ fun () -> Plugin.Inbox.same_as_layer_1 node_ctxt head.hash inbox -- GitLab