From 40a26759fc0d777189fcb5160d1e28b6fa47cccd Mon Sep 17 00:00:00 2001 From: Benjamin Canou Date: Fri, 23 Feb 2018 18:32:26 +0100 Subject: [PATCH] Node: fix error handling in block validator --- src/lib_shell/block_validator.ml | 28 ++++++++++++---------------- src/lib_shell/peer_validator.ml | 2 +- 2 files changed, 13 insertions(+), 17 deletions(-) diff --git a/src/lib_shell/block_validator.ml b/src/lib_shell/block_validator.ml index 70334fd55..94fda74bd 100644 --- a/src/lib_shell/block_validator.ml +++ b/src/lib_shell/block_validator.ml @@ -244,24 +244,20 @@ let on_request protect ?canceler begin fun () -> apply_block (Distributed_db.chain_state chain_db) - pred proto hash header operations + pred proto hash header operations >>=? fun result -> + Distributed_db.commit_block + chain_db hash header operations result >>=? function + | None -> assert false (* should not happen *) + | Some block -> return block end end >>= function - | Ok result -> begin - Worker.protect w begin fun () -> - Distributed_db.commit_block - chain_db hash header operations result - end >>=? function - | None -> - assert false (* should not happen *) - | Some block -> - Protocol_validator.prefetch_and_compile_protocols - bv.protocol_validator - ?peer ~timeout:bv.limits.protocol_timeout - block ; - notify_new_block block ; - return (Ok block) - end + | Ok block -> + Protocol_validator.prefetch_and_compile_protocols + bv.protocol_validator + ?peer ~timeout:bv.limits.protocol_timeout + block ; + notify_new_block block ; + return (Ok block) (* TODO catch other temporary error (e.g. system errors) and do not 'commit' them on disk... *) | Error [Canceled | Unavailable_protocol _] as err -> diff --git a/src/lib_shell/peer_validator.ml b/src/lib_shell/peer_validator.ml index 142048090..302d5edf2 100644 --- a/src/lib_shell/peer_validator.ml +++ b/src/lib_shell/peer_validator.ml @@ -276,8 +276,8 @@ let on_error w r st errs = let on_close w = let pv = Worker.state w in - pv.parameters.notify_termination () ; Distributed_db.disconnect pv.parameters.chain_db pv.peer_id >>= fun () -> + pv.parameters.notify_termination () ; Lwt.return () let on_launch _ name parameters =