From 77bd0af3d1c29c2eb9d5872e9aa469e8f1ea4ec3 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Gr=C3=A9goire=20Henry?= Date: Mon, 12 Feb 2018 16:36:24 +0100 Subject: [PATCH] Shell/test: add option to not enforce context hash in block header --- src/lib_shell/state.ml | 16 ++++++++++++++-- src/lib_shell/state.mli | 1 + 2 files changed, 15 insertions(+), 2 deletions(-) diff --git a/src/lib_shell/state.ml b/src/lib_shell/state.ml index 12ab06481..df556f436 100644 --- a/src/lib_shell/state.ml +++ b/src/lib_shell/state.ml @@ -556,6 +556,11 @@ module Block = struct ~description: "When commiting the context of a block, the announced context \ hash was not the one computed at commit time." + ~pp: (fun ppf (got, exp) -> + Format.fprintf ppf + "@[Inconsistant hash:@ got: %a@ expected: %a" + Context_hash.pp got + Context_hash.pp exp) Data_encoding.(obj2 (req "wrong_context_hash" Context_hash.encoding) (req "expected_context_hash" Context_hash.encoding)) @@ -563,6 +568,7 @@ module Block = struct (fun (got, exp) -> Inconsistent_hash (got, exp)) let store + ?(dont_enforce_context_hash = false) net_state block_header operations { Updater.context ; message ; max_operations_ttl ; max_operation_data_length } = @@ -579,10 +585,16 @@ module Block = struct Context.commit ~time:block_header.shell.timestamp ?message context >>= fun commit -> fail_unless - (Context_hash.equal block_header.shell.context commit) + (dont_enforce_context_hash + || Context_hash.equal block_header.shell.context commit) (Inconsistent_hash (commit, block_header.shell.context)) >>=? fun () -> let contents = { - Store.Block.header = block_header ; + Store.Block.header = + if dont_enforce_context_hash then + { block_header + with shell = { block_header.shell with context = commit } } + else + block_header ; message ; max_operations_ttl ; max_operation_data_length ; diff --git a/src/lib_shell/state.mli b/src/lib_shell/state.mli index 813459552..cfee2f603 100644 --- a/src/lib_shell/state.mli +++ b/src/lib_shell/state.mli @@ -108,6 +108,7 @@ module Block : sig type error += Inconsistent_hash of Context_hash.t * Context_hash.t val store: + ?dont_enforce_context_hash:bool -> Net.t -> Block_header.t -> Operation.t list list ->