From 71c8e02b4167c2d573f5645deae32b72fc587550 Mon Sep 17 00:00:00 2001 From: Pietro Abate Date: Thu, 14 Dec 2017 18:46:55 +0100 Subject: [PATCH] Node: properly restore the current head after a node reboot Together With Benjamin and Vincent (teamwork !) --- lib_node_shell/chain.ml | 10 +++++++++- lib_node_shell/chain.mli | 3 +++ lib_node_shell/net_validator.ml | 2 +- 3 files changed, 13 insertions(+), 2 deletions(-) diff --git a/lib_node_shell/chain.ml b/lib_node_shell/chain.ml index f7accd40f..45c423e07 100644 --- a/lib_node_shell/chain.ml +++ b/lib_node_shell/chain.ml @@ -73,7 +73,9 @@ let locked_set_head chain_store data block = Lwt_list.fold_left_s push_block ancestor path >>= fun _ -> Store.Chain.Current_head.store chain_store (Block.hash block) >>= fun () -> (* TODO more optimized updated of live_{blocks/operations} when the - new head is a direct successor of the current head... *) + new head is a direct successor of the current head... + Make sure to do the live blocks computation in `init_head` + when this TODO is resolved. *) Chain_traversal.live_blocks block (State.Block.max_operations_ttl block) >>= fun (live_blocks, live_operations) -> @@ -98,3 +100,9 @@ let test_and_set_head net_state ~old block = locked_set_head chain_store data block >>= fun new_chain_data -> Lwt.return (Some new_chain_data, true) end + +let init_head net_state = + head net_state >>= fun block -> + set_head net_state block >>= fun _ -> + Lwt.return_unit + diff --git a/lib_node_shell/chain.mli b/lib_node_shell/chain.mli index 5cafd6eb9..f5ffffcfd 100644 --- a/lib_node_shell/chain.mli +++ b/lib_node_shell/chain.mli @@ -45,3 +45,6 @@ val set_head: Net.t -> Block.t -> Block.t Lwt.t val test_and_set_head: Net.t -> old:Block.t -> Block.t -> bool Lwt.t +(** Restores the data about the current head at startup + (recomputes the sets of live blocks and operations). *) +val init_head: Net.t -> unit Lwt.t diff --git a/lib_node_shell/net_validator.ml b/lib_node_shell/net_validator.ml index 03c13d287..37f29c297 100644 --- a/lib_node_shell/net_validator.ml +++ b/lib_node_shell/net_validator.ml @@ -117,12 +117,12 @@ let broadcast_head nv ~previous block = end end - let rec create ?max_child_ttl ?parent ?(bootstrap_threshold = 1) timeout block_validator global_valid_block_input db net_state = + Chain.init_head net_state >>= fun () -> let net_db = Distributed_db.activate db net_state in Prevalidator.create ~max_operations:2000 (* FIXME temporary constant *)