Mempool_worker: only introduce errors where they are needed

This commit is contained in:
Raphaël Proust 2018-11-08 09:46:28 +08:00 committed by MBourgoin
parent 7e687f8608
commit 5059b6ad4e
No known key found for this signature in database
GPG Key ID: 4B3F7008ABB5B2D0

View File

@ -471,7 +471,7 @@ module Make(Static: STATIC)(Proto: Registered_protocol.T)
(* this function update the internal state of the worker *) (* this function update the internal state of the worker *)
let validate_helper w parsed_op = let validate_helper w parsed_op =
let state = Worker.state w in let state = Worker.state w in
apply_operation state parsed_op >>= fun (validation_state,result) -> apply_operation state parsed_op >>= fun (validation_state, result) ->
begin begin
match validation_state with match validation_state with
| Some validation_state -> state.validation_state <- validation_state | Some validation_state -> state.validation_state <- validation_state
@ -493,12 +493,12 @@ module Make(Static: STATIC)(Proto: Registered_protocol.T)
let state = Worker.state w in let state = Worker.state w in
match Cache.find_validated_opt state.cache parsed_op with match Cache.find_validated_opt state.cache parsed_op with
| None | Some (Branch_delayed _) -> | None | Some (Branch_delayed _) ->
validate_helper w parsed_op >>=? fun result -> validate_helper w parsed_op >>= fun result ->
Cache.add_validated state.cache parsed_op result; Cache.add_validated state.cache parsed_op result;
(* operations are notified only the first time *) (* operations are notified only the first time *)
notify_helper w result parsed_op.raw ; notify_helper w result parsed_op.raw ;
return result Lwt.return result
| Some result -> return result | Some result -> Lwt.return result
let on_parse w raw_op = let on_parse w raw_op =
let state = Worker.state w in let state = Worker.state w in
@ -513,6 +513,7 @@ module Make(Static: STATIC)(Proto: Registered_protocol.T)
let on_request : let on_request :
type r. t -> r Request.t -> r tzresult Lwt.t = fun w request -> type r. t -> r Request.t -> r tzresult Lwt.t = fun w request ->
match request with match request with
| Request.Parse raw_op -> on_parse w raw_op
| Request.Validate parsed_op -> on_validate w parsed_op >>= return | Request.Validate parsed_op -> on_validate w parsed_op >>= return
let on_launch (_ : t) (_ : Name.t) ( { chain_db ; validation_state } as parameters ) = let on_launch (_ : t) (_ : Name.t) ( { chain_db ; validation_state } as parameters ) =