Node: properly restore the current head after a node reboot

Together With Benjamin and Vincent (teamwork !)
This commit is contained in:
Pietro Abate 2017-12-14 18:46:55 +01:00 committed by Benjamin Canou
parent ac93872b2c
commit 71c8e02b41
3 changed files with 13 additions and 2 deletions

View File

@ -73,7 +73,9 @@ let locked_set_head chain_store data block =
Lwt_list.fold_left_s push_block ancestor path >>= fun _ -> Lwt_list.fold_left_s push_block ancestor path >>= fun _ ->
Store.Chain.Current_head.store chain_store (Block.hash block) >>= fun () -> Store.Chain.Current_head.store chain_store (Block.hash block) >>= fun () ->
(* TODO more optimized updated of live_{blocks/operations} when the (* 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 Chain_traversal.live_blocks
block (State.Block.max_operations_ttl block) >>= fun (live_blocks, block (State.Block.max_operations_ttl block) >>= fun (live_blocks,
live_operations) -> 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 -> locked_set_head chain_store data block >>= fun new_chain_data ->
Lwt.return (Some new_chain_data, true) Lwt.return (Some new_chain_data, true)
end end
let init_head net_state =
head net_state >>= fun block ->
set_head net_state block >>= fun _ ->
Lwt.return_unit

View File

@ -45,3 +45,6 @@ val set_head: Net.t -> Block.t -> Block.t Lwt.t
val test_and_set_head: val test_and_set_head:
Net.t -> old:Block.t -> Block.t -> bool Lwt.t 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

View File

@ -117,12 +117,12 @@ let broadcast_head nv ~previous block =
end end
end end
let rec create let rec create
?max_child_ttl ?parent ?max_child_ttl ?parent
?(bootstrap_threshold = 1) ?(bootstrap_threshold = 1)
timeout block_validator timeout block_validator
global_valid_block_input db net_state = global_valid_block_input db net_state =
Chain.init_head net_state >>= fun () ->
let net_db = Distributed_db.activate db net_state in let net_db = Distributed_db.activate db net_state in
Prevalidator.create Prevalidator.create
~max_operations:2000 (* FIXME temporary constant *) ~max_operations:2000 (* FIXME temporary constant *)