From c3eda23b450fd1e9c9f86928d8b1991a2dffc4e1 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Gr=C3=A9goire=20Henry?= Date: Mon, 16 Apr 2018 00:44:24 +0200 Subject: [PATCH] Shell: add a global watcher for new valid blocks in `State` --- src/lib_shell/state.ml | 10 ++++++++-- src/lib_shell/state.mli | 2 ++ 2 files changed, 10 insertions(+), 2 deletions(-) diff --git a/src/lib_shell/state.ml b/src/lib_shell/state.ml index 818747d04..50ac27296 100644 --- a/src/lib_shell/state.ml +++ b/src/lib_shell/state.ml @@ -24,6 +24,7 @@ type global_state = { global_data: global_data Shared.t ; protocol_store: Store.Protocol.store Shared.t ; main_chain: Chain_id.t ; + block_watcher: block Lwt_watcher.input ; } and global_data = { @@ -588,6 +589,7 @@ module Block = struct end >>= fun () -> let block = { chain_state ; hash ; contents } in Lwt_watcher.notify chain_state.block_watcher block ; + Lwt_watcher.notify chain_state.global_state.block_watcher block ; return (Some block) end end @@ -607,8 +609,8 @@ module Block = struct return true end - let watcher chain_state = - Lwt_watcher.create_stream chain_state.block_watcher + let watcher (state : chain_state) = + Lwt_watcher.create_stream state.block_watcher let operation_hashes { chain_state ; hash ; contents } i = if i < 0 || contents.header.shell.validation_passes <= i then @@ -687,6 +689,9 @@ module Block = struct end +let watcher (state : global_state) = + Lwt_watcher.create_stream state.block_watcher + let read_block { global_data } ?pred hash = Shared.use global_data begin fun { chains } -> Chain_id.Table.fold @@ -833,6 +838,7 @@ let read global_data = Shared.create global_data ; protocol_store = Shared.create @@ Store.Protocol.get global_store ; main_chain ; + block_watcher = Lwt_watcher.create_input () ; } in Chain.read_all state >>=? fun () -> may_create_chain state main_chain genesis >>= fun main_chain_state -> diff --git a/src/lib_shell/state.mli b/src/lib_shell/state.mli index a419d20a8..b9450a544 100644 --- a/src/lib_shell/state.mli +++ b/src/lib_shell/state.mli @@ -156,6 +156,8 @@ val read_block: val read_block_exn: global_state -> ?pred:int -> Block_hash.t -> Block.t Lwt.t +val watcher: t -> Block.t Lwt_stream.t * Lwt_watcher.stopper + val compute_locator: Chain.t -> ?size:int -> Block.t -> Block_locator.seed -> Block_locator.t Lwt.t val fork_testchain: