diff --git a/src/lib_storage/context.ml b/src/lib_storage/context.ml index c166337d4b857c8eba8a7ea18e6abb8787852aa4..d5f5c3a8c5931d71b91c15d5979c972f12926892 100644 --- a/src/lib_storage/context.ml +++ b/src/lib_storage/context.ml @@ -140,14 +140,12 @@ module Node = struct type entry = {kind : kind; name : M.step; node : Hash.t} - let s = Irmin.Type.(string_of `Int64) + (* Irmin 1.4 uses int8 to store filename lengths. - let pre_hash_v = Irmin.Type.(unstage (pre_hash s)) - - (* Irmin 1.4 uses int64 to store string lengths *) - let step_t = - let pre_hash = Irmin.Type.(stage @@ fun x -> pre_hash_v x) in - Irmin.Type.like M.step_t ~pre_hash + Irmin 2 use a variable-size encoding for strings; this is using int8 + for strings of size stricly less than 128 (e.g. 2^7) which happen to + be the case for all filenames ever produced by Irmin 1.4. *) + let step_t = Irmin.Type.string let metadata_t = let some = "\255\000\000\000\000\000\000\000" in diff --git a/src/lib_storage/test/assert.ml b/src/lib_storage/test/assert.ml index f644002686b4c2aec339cee0de9a5a0868a98c79..0d05047a48c2eee4e9a5ddbf9c9ed291746f82e1 100644 --- a/src/lib_storage/test/assert.ml +++ b/src/lib_storage/test/assert.ml @@ -100,6 +100,9 @@ let equal_key_dir_list ?msg l1 l2 = l1 l2 +let equal_context_hash ?msg l1 l2 = + equal ?msg ~eq:Context_hash.( = ) ~prn:Context_hash.to_b58check l1 l2 + let equal_context_hash_list ?msg l1 l2 = let pr_persist hash = Printf.sprintf "[%s]" @@ Context_hash.to_string hash in make_equal_list ?msg Context_hash.( = ) pr_persist l1 l2 diff --git a/src/lib_storage/test/test_context.ml b/src/lib_storage/test/test_context.ml index 5643e5ee1530a90e27f33fce55fe0a7df51247c6..1594c0b68e8097d3e8600245ddd66351999a37e5 100644 --- a/src/lib_storage/test/test_context.ml +++ b/src/lib_storage/test/test_context.ml @@ -457,6 +457,46 @@ let test_raw {idx; genesis; _} = Assert.equal_raw_tree ~msg:__LOC__ e raw ; Lwt.return () +let string n = String.make n 'a' + +let test_encoding {idx; genesis; _} = + checkout idx genesis + >>= function + | None -> + Assert.fail_msg "checkout genesis_block" + | Some ctxt -> + let foo1 = Bytes.of_string "foo1" in + let foo2 = Bytes.of_string "foo2" in + add ctxt ["a"; string 7] foo1 + >>= fun ctxt -> + add ctxt ["a"; string 8] foo2 + >>= fun ctxt -> + add ctxt [string 16] foo2 + >>= fun ctxt -> + add ctxt [string 32] foo2 + >>= fun ctxt -> + add ctxt [string 64] foo2 + >>= fun ctxt -> + add ctxt [string 127] foo2 + >>= fun ctxt -> + commit ctxt + >>= fun h -> + Assert.equal_context_hash + ~msg:__LOC__ + (Context_hash.of_b58check_exn + "CoWJsL2ehZ39seTr8inBCJb5tVjW8KGNweJ5cvuVq51mAASrRmim") + h ; + add ctxt [string 255] foo2 + >>= fun ctxt -> + commit ctxt + >>= fun h -> + Assert.equal_context_hash + ~msg:__LOC__ + (Context_hash.of_b58check_exn + "CoVexcEHMXmSA2k42aNc5MCDtVJFRs3CC6vcQWYwFoj7EFsBPw1c") + h ; + Lwt.return () + let test_dump {idx; block3b; _} = Lwt_utils_unix.with_tempdir "tezos_test_" (fun base_dir2 -> let dumpfile = base_dir2 // "dump" in @@ -534,7 +574,8 @@ let tests : (string * (t -> unit Lwt.t)) list = ("fold", test_fold); ("trees", test_trees); ("raw", test_raw); - ("dump", test_dump) ] + ("dump", test_dump); + ("encoding", test_encoding) ] let tests = List.map