Shell: Avoid recomputing rpc_directory for each flush

This commit is contained in:
Pierre Chambart 2018-06-27 02:38:26 +02:00 committed by Grégoire Henry
parent 892c91e3ac
commit 7fcd986b93

View File

@ -45,7 +45,7 @@ module Types = struct
mutable validation_result : error Preapply_result.t ; mutable validation_result : error Preapply_result.t ;
mutable validation_state : Prevalidation.prevalidation_state tzresult ; mutable validation_state : Prevalidation.prevalidation_state tzresult ;
mutable advertisement : [ `Pending of Mempool.t | `None ] ; mutable advertisement : [ `Pending of Mempool.t | `None ] ;
mutable rpc_directory : state RPC_directory.t tzresult Lwt.t ; mutable rpc_directory : state RPC_directory.t tzresult Lwt.t lazy_t ;
} }
type parameters = limits * Distributed_db.chain_db type parameters = limits * Distributed_db.chain_db
@ -94,8 +94,7 @@ let empty_rpc_directory : unit RPC_directory.t =
unprocessed = Operation_hash.Map.empty ; unprocessed = Operation_hash.Map.empty ;
}) })
let rpc_directory block : Types.state RPC_directory.t tzresult Lwt.t = let rpc_directory protocol =
State.Block.protocol_hash block >>= fun protocol ->
begin begin
match Registered_protocol.get protocol with match Registered_protocol.get protocol with
| None -> | None ->
@ -401,6 +400,8 @@ let on_flush w pv predecessor =
end >>= fun (validation_state, validation_result) -> end >>= fun (validation_state, validation_result) ->
debug w "%d operations were not washed by the flush" debug w "%d operations were not washed by the flush"
(Operation_hash.Map.cardinal pending) ; (Operation_hash.Map.cardinal pending) ;
State.Block.protocol_hash pv.predecessor >>= fun old_protocol ->
State.Block.protocol_hash predecessor >>= fun new_protocol ->
pv.predecessor <- predecessor ; pv.predecessor <- predecessor ;
pv.live_blocks <- new_live_blocks ; pv.live_blocks <- new_live_blocks ;
pv.live_operations <- new_live_operations ; pv.live_operations <- new_live_operations ;
@ -410,7 +411,8 @@ let on_flush w pv predecessor =
pv.in_mempool <- Operation_hash.Set.empty ; pv.in_mempool <- Operation_hash.Set.empty ;
pv.validation_result <- validation_result ; pv.validation_result <- validation_result ;
pv.validation_state <- validation_state ; pv.validation_state <- validation_state ;
pv.rpc_directory <- rpc_directory predecessor ; if not (Protocol_hash.equal old_protocol new_protocol) then
pv.rpc_directory <- lazy (rpc_directory new_protocol) ;
return () return ()
let on_advertise pv = let on_advertise pv =
@ -459,6 +461,7 @@ let on_launch w _ (limits, chain_db) =
Chain.data chain_state >>= fun Chain.data chain_state >>= fun
{ current_head = predecessor ; current_mempool = mempool ; { current_head = predecessor ; current_mempool = mempool ;
live_blocks ; live_operations } -> live_blocks ; live_operations } ->
State.Block.protocol_hash predecessor >>= fun protocol ->
let timestamp = Time.now () in let timestamp = Time.now () in
Prevalidation.start_prevalidation Prevalidation.start_prevalidation
~predecessor ~timestamp () >>= fun validation_state -> ~predecessor ~timestamp () >>= fun validation_state ->
@ -485,7 +488,7 @@ let on_launch w _ (limits, chain_db) =
in_mempool = Operation_hash.Set.empty ; in_mempool = Operation_hash.Set.empty ;
validation_result ; validation_state ; validation_result ; validation_state ;
advertisement = `None ; advertisement = `None ;
rpc_directory = rpc_directory predecessor ; rpc_directory = lazy (rpc_directory protocol) ;
} in } in
List.iter List.iter
(fun oph -> Lwt.ignore_result (fetch_operation w pv oph)) (fun oph -> Lwt.ignore_result (fetch_operation w pv oph))
@ -571,7 +574,7 @@ let rpc_directory : t option RPC_directory.t =
(RPC_directory.map (fun _ -> Lwt.return_unit) empty_rpc_directory) (RPC_directory.map (fun _ -> Lwt.return_unit) empty_rpc_directory)
| Some w -> | Some w ->
let pv = Worker.state w in let pv = Worker.state w in
pv.rpc_directory >>= function Lazy.force pv.rpc_directory >>= function
| Error _ -> | Error _ ->
Lwt.return RPC_directory.empty Lwt.return RPC_directory.empty
| Ok rpc_directory -> | Ok rpc_directory ->