Shell: add a global watcher for new valid blocks in State

This commit is contained in:
Grégoire Henry 2018-04-16 00:44:24 +02:00
parent 3ba30fa468
commit c3eda23b45
2 changed files with 10 additions and 2 deletions

View File

@ -24,6 +24,7 @@ type global_state = {
global_data: global_data Shared.t ; global_data: global_data Shared.t ;
protocol_store: Store.Protocol.store Shared.t ; protocol_store: Store.Protocol.store Shared.t ;
main_chain: Chain_id.t ; main_chain: Chain_id.t ;
block_watcher: block Lwt_watcher.input ;
} }
and global_data = { and global_data = {
@ -588,6 +589,7 @@ module Block = struct
end >>= fun () -> end >>= fun () ->
let block = { chain_state ; hash ; contents } in let block = { chain_state ; hash ; contents } in
Lwt_watcher.notify chain_state.block_watcher block ; Lwt_watcher.notify chain_state.block_watcher block ;
Lwt_watcher.notify chain_state.global_state.block_watcher block ;
return (Some block) return (Some block)
end end
end end
@ -607,8 +609,8 @@ module Block = struct
return true return true
end end
let watcher chain_state = let watcher (state : chain_state) =
Lwt_watcher.create_stream chain_state.block_watcher Lwt_watcher.create_stream state.block_watcher
let operation_hashes { chain_state ; hash ; contents } i = let operation_hashes { chain_state ; hash ; contents } i =
if i < 0 || contents.header.shell.validation_passes <= i then if i < 0 || contents.header.shell.validation_passes <= i then
@ -687,6 +689,9 @@ module Block = struct
end end
let watcher (state : global_state) =
Lwt_watcher.create_stream state.block_watcher
let read_block { global_data } ?pred hash = let read_block { global_data } ?pred hash =
Shared.use global_data begin fun { chains } -> Shared.use global_data begin fun { chains } ->
Chain_id.Table.fold Chain_id.Table.fold
@ -833,6 +838,7 @@ let read
global_data = Shared.create global_data ; global_data = Shared.create global_data ;
protocol_store = Shared.create @@ Store.Protocol.get global_store ; protocol_store = Shared.create @@ Store.Protocol.get global_store ;
main_chain ; main_chain ;
block_watcher = Lwt_watcher.create_input () ;
} in } in
Chain.read_all state >>=? fun () -> Chain.read_all state >>=? fun () ->
may_create_chain state main_chain genesis >>= fun main_chain_state -> may_create_chain state main_chain genesis >>= fun main_chain_state ->

View File

@ -156,6 +156,8 @@ val read_block:
val read_block_exn: val read_block_exn:
global_state -> ?pred:int -> Block_hash.t -> Block.t Lwt.t 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 compute_locator: Chain.t -> ?size:int -> Block.t -> Block_locator.seed -> Block_locator.t Lwt.t
val fork_testchain: val fork_testchain: