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
parent f593677e99
commit 481772fc98
No known key found for this signature in database
GPG Key ID: F4B685504488CEC0

View File

@ -481,13 +481,13 @@ module Make(Proto: Registered_protocol.T) : T with module Proto = Proto = struct
(* 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
| None -> () | None -> ()
end ; end ;
return result Lwt.return result
let notify_helper w result { Operation.shell ; proto } = let notify_helper w result { Operation.shell ; proto } =
let state = Worker.state w in let state = Worker.state w in
@ -503,12 +503,12 @@ module Make(Proto: Registered_protocol.T) : T with module Proto = Proto = struct
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
@ -524,7 +524,7 @@ module Make(Proto: Registered_protocol.T) : T with module Proto = Proto = struct
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.Parse raw_op -> on_parse w raw_op
| Request.Validate parsed_op -> on_validate w parsed_op | 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 ) =
let chain_state = Distributed_db.chain_state chain_db in let chain_state = Distributed_db.chain_state chain_db in