diff options
| author | Estevan Castilho <tevo@riajuu.net> | 2026-08-23 03:52:08 +0000 |
|---|---|---|
| committer | Estevan Castilho <tevo@riajuu.net> | 2026-08-23 03:52:08 +0000 |
| commit | 8f87d272038ddea11c366d9a14079666daf6628b (patch) | |
| tree | bbecb53f35452cc3caecf6fb85994629d67ce3af | |
| parent | 1d0b73b051cff4b14919808c51acbdd1c3e11767 (diff) | |
| download | RNT-8f87d272038ddea11c366d9a14079666daf6628b.tar.gz RNT-8f87d272038ddea11c366d9a14079666daf6628b.zip | |
The branch manager should persist changes to the root
Diffstat (limited to '')
| -rw-r--r-- | lib/concepts/Hash.ml | 5 | ||||
| -rw-r--r-- | lib/concepts/Hash.mli | 3 | ||||
| -rw-r--r-- | lib/kernel/BranchManager.ml | 8 |
3 files changed, 14 insertions, 2 deletions
diff --git a/lib/concepts/Hash.ml b/lib/concepts/Hash.ml index ae0a178..b2ed4b2 100644 --- a/lib/concepts/Hash.ml +++ b/lib/concepts/Hash.ml @@ -11,6 +11,10 @@ let hash_of_bytes bytes = Digestif.SHA256.digest_bytes bytes let hash_of_blob blob = Blob.bytes_of_blob blob |> Digestif.SHA256.digest_bytes +let bytes_of_hash (h : hash) = Bytes.of_string (Digestif.SHA256.to_raw_string h) + +let blob_of_hash h = bytes_of_hash h |> Blob.blob_of_bytes + let to_raw_string hash = Digestif.SHA256.to_raw_string hash let of_raw_string str = Digestif.SHA256.of_raw_string str @@ -18,7 +22,6 @@ let of_raw_string str = Digestif.SHA256.of_raw_string str let to_hum_string hash = Digestif.SHA256.to_hex hash let hash_equals = Digestif.SHA256.equal -let bytes_of_hash (h : hash) = Bytes.of_string (Digestif.SHA256.to_raw_string h) let power_of_two p = let b = Bytes.make 32 '\x00' in diff --git a/lib/concepts/Hash.mli b/lib/concepts/Hash.mli index b3ae2dc..0e71fda 100644 --- a/lib/concepts/Hash.mli +++ b/lib/concepts/Hash.mli @@ -28,5 +28,8 @@ val hash_equals : hash -> hash -> bool (** given a hash, return a `bytes` representation of it *) val bytes_of_hash : hash -> bytes +(** given a hash, return a `blob` representation of it *) +val blob_of_hash : hash -> Blob.t + (** pick one every 1/2^n hashes *) val pick : int -> hash -> bool diff --git a/lib/kernel/BranchManager.ml b/lib/kernel/BranchManager.ml index a698a87..bdc461e 100644 --- a/lib/kernel/BranchManager.ml +++ b/lib/kernel/BranchManager.ml @@ -26,6 +26,10 @@ module Make (S : Abstract.Storage.STORAGE) = struct let label = Option.map Concepts.Hash.hash_of_blob label in Ok label + let persist_root tx label addr = + let data = Concepts.Hash.blob_of_hash addr in + S.put tx (S.Label label) data + class manager storage label head = object (self) inherit Lifecycle.null @@ -46,6 +50,7 @@ module Make (S : Abstract.Storage.STORAGE) = struct |> fmap (Option.to_result ~none:(Error.no_such_branch branch_name)) in if branch = reference then let* new_head = M.insert tx label new_branch head in + let* _ = persist_root tx label (M.hash_of new_head) in Ok new_head else Error (Error.branch_head_mismatch branch_name reference branch))) @@ -63,7 +68,8 @@ module Make (S : Abstract.Storage.STORAGE) = struct SI.with_transaction storage (fun tx -> let* addr = root_for tx label in match addr with - | None -> failwith "TODO" + | None -> + Ok (new manager storage label M.empty |> Protocols.Handle.make) | Some addr -> let* head = M.find tx addr in let* head = Option.to_result ~none:(Error.invalid_root addr) head in |
