From 42e29c8f4ad78d11147e58eb62668b5ea02315c7 Mon Sep 17 00:00:00 2001 From: Milo Davis Date: Tue, 31 Oct 2017 17:59:02 +0100 Subject: [PATCH] Node: allow invalid block errors to be stored --- src/node/db/store.ml | 8 ++++---- src/node/db/store.mli | 2 +- src/node/shell/distributed_db.ml | 4 ++-- src/node/shell/state.ml | 8 ++++++-- src/node/shell/state.mli | 2 ++ 5 files changed, 15 insertions(+), 9 deletions(-) diff --git a/src/node/db/store.ml b/src/node/db/store.ml index 69ccb4718..e06221b1a 100644 --- a/src/node/db/store.ml +++ b/src/node/db/store.ml @@ -152,7 +152,7 @@ module Block = struct type invalid_block = { level: int32 ; - (* errors: Error_monad.error list ; *) + errors: Error_monad.error list ; } module Invalid_block = @@ -166,9 +166,9 @@ module Block = struct let encoding = let open Data_encoding in conv - (fun { level } -> (level)) - (fun (level) -> { level }) - int32 + (fun { level ; errors } -> (level, errors)) + (fun (level, errors) -> { level ; errors }) + (tup2 int32 (list Error_monad.error_encoding)) end)) let register s = diff --git a/src/node/db/store.mli b/src/node/db/store.mli index d71725b1b..a3cf2e93d 100644 --- a/src/node/db/store.mli +++ b/src/node/db/store.mli @@ -115,7 +115,7 @@ module Block : sig type invalid_block = { level: int32 ; - (* errors: Error_monad.error list ; *) + errors: Error_monad.error list ; } module Invalid_block : MAP_STORE diff --git a/src/node/shell/distributed_db.ml b/src/node/shell/distributed_db.ml index f4a39334b..6723c7118 100644 --- a/src/node/shell/distributed_db.ml +++ b/src/node/shell/distributed_db.ml @@ -792,9 +792,9 @@ let commit_block net_db hash header operations result = clear_block net_db hash header.shell.validation_passes ; return res -let commit_invalid_block net_db hash header _err = +let commit_invalid_block net_db hash header errors = assert (Block_hash.equal hash (Block_header.hash header)) ; - State.Block.store_invalid net_db.net_state header >>=? fun res -> + State.Block.store_invalid net_db.net_state header errors >>=? fun res -> clear_block net_db hash header.shell.validation_passes ; return res diff --git a/src/node/shell/state.ml b/src/node/shell/state.ml index fb9377a50..808a73d8f 100644 --- a/src/node/shell/state.ml +++ b/src/node/shell/state.ml @@ -376,6 +376,10 @@ module Block = struct Shared.use net_state.block_store begin fun store -> Store.Block.Invalid_block.known store hash end + let read_invalid net_state hash = + Shared.use net_state.block_store begin fun store -> + Store.Block.Invalid_block.read_opt store hash + end let known net_state hash = Shared.use net_state.block_store begin fun store -> @@ -478,7 +482,7 @@ module Block = struct end end - let store_invalid net_state block_header = + let store_invalid net_state block_header errors = let bytes = Block_header.to_bytes block_header in let hash = Block_header.hash_raw bytes in Shared.use net_state.block_store begin fun store -> @@ -489,7 +493,7 @@ module Block = struct return false else Store.Block.Invalid_block.store store hash - { level = block_header.shell.level } >>= fun () -> + { level = block_header.shell.level ; errors } >>= fun () -> return true end diff --git a/src/node/shell/state.mli b/src/node/shell/state.mli index 094f864a4..e593d96cd 100644 --- a/src/node/shell/state.mli +++ b/src/node/shell/state.mli @@ -97,6 +97,7 @@ module Block : sig val known: Net.t -> Block_hash.t -> bool Lwt.t val known_valid: Net.t -> Block_hash.t -> bool Lwt.t val known_invalid: Net.t -> Block_hash.t -> bool Lwt.t + val read_invalid: Net.t -> Block_hash.t -> Store.Block.invalid_block option Lwt.t val read: Net.t -> Block_hash.t -> block tzresult Lwt.t val read_opt: Net.t -> Block_hash.t -> block option Lwt.t @@ -112,6 +113,7 @@ module Block : sig val store_invalid: Net.t -> Block_header.t -> + error list -> bool tzresult Lwt.t val compare: t -> t -> int