diff --git a/src/lib_smart_rollup_node/context.ml b/src/lib_smart_rollup_node/context.ml index 7c711c3224a43c4c8d5a639f33bb29db392e6f8c..787827625c167d98e8dc4f312c55e9eaee08a959 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 7b87caad0d3aa3e5cfca7ba13df4ef3dec51e560..9954ac44ad112598f3bfa9e4ae362b1e7909f237 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 38249dd6b406ab0d996f467fa82f8c839d2b27d0..d5c9d70dfa24307aea02a3321fa710db96224117 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 676829e1b2e4b391fd8c979db7046103b16a0d4f..d3a500c2a35eccf33781184036f7bc96b89c8671 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 68bf5eb55091de181074111886cbc0960e0daacd..028a62a43df0ff992ebc5d3e2dd0a7f0bb408c29 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/node_context.ml b/src/lib_smart_rollup_node/node_context.ml index 72f59bcb68cd5fce45ecf9f18d0e9baf0dff08ae..5006d5b635859af071ae0cb34d06036fa8cdd69d 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 f401527c8e4ef5a4011062ce9f7c11d27e77fad3..d941bf9bcc3df98705799cd9cc95ddcd82835f98 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 diff --git a/src/lib_smart_rollup_node/rollup_node_daemon.ml b/src/lib_smart_rollup_node/rollup_node_daemon.ml index f9d330713751e916f845faea275f0cd0755dc87a..90fbb4a2b046ee66f3e838578b21aa3912953102 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