2016-09-08 21:13:10 +04:00
|
|
|
(**************************************************************************)
|
|
|
|
(* *)
|
2017-11-14 03:36:14 +04:00
|
|
|
(* Copyright (c) 2014 - 2017. *)
|
2016-09-08 21:13:10 +04:00
|
|
|
(* Dynamic Ledger Solutions, Inc. <contact@tezos.com> *)
|
|
|
|
(* *)
|
|
|
|
(* All rights reserved. No warranty, explicit or implicit, provided. *)
|
|
|
|
(* *)
|
|
|
|
(**************************************************************************)
|
|
|
|
|
2017-02-17 22:12:06 +04:00
|
|
|
open Lwt.Infix
|
2016-09-08 21:13:10 +04:00
|
|
|
open Logging.Node.Worker
|
|
|
|
|
2017-11-23 19:39:33 +04:00
|
|
|
let inject_operation validator ?net_id bytes =
|
2016-09-08 21:13:10 +04:00
|
|
|
let t =
|
2017-04-19 21:21:23 +04:00
|
|
|
match Data_encoding.Binary.of_bytes Operation.encoding bytes with
|
2016-09-08 21:13:10 +04:00
|
|
|
| None -> failwith "Can't parse the operation"
|
2017-11-14 05:41:37 +04:00
|
|
|
| Some op ->
|
2017-11-23 19:39:33 +04:00
|
|
|
Validator.inject_operation validator ?net_id op
|
2017-11-14 05:41:37 +04:00
|
|
|
in
|
2016-09-08 21:13:10 +04:00
|
|
|
let hash = Operation_hash.hash_bytes [bytes] in
|
|
|
|
Lwt.return (hash, t)
|
|
|
|
|
2016-10-21 16:01:20 +04:00
|
|
|
let inject_protocol state ?force:_ proto =
|
2017-02-24 20:17:53 +04:00
|
|
|
let proto_bytes =
|
2017-04-19 21:21:23 +04:00
|
|
|
Data_encoding.Binary.to_bytes Protocol.encoding proto in
|
2016-10-21 16:01:20 +04:00
|
|
|
let hash = Protocol_hash.hash_bytes [proto_bytes] in
|
2017-02-24 20:17:53 +04:00
|
|
|
let validation =
|
|
|
|
Updater.compile hash proto >>= function
|
|
|
|
| false ->
|
|
|
|
failwith
|
|
|
|
"Compilation failed (%a)"
|
|
|
|
Protocol_hash.pp_short hash
|
2016-10-24 16:10:17 +04:00
|
|
|
| true ->
|
2017-04-19 23:46:10 +04:00
|
|
|
State.Protocol.store state proto >>= function
|
|
|
|
| None ->
|
2017-02-24 20:17:53 +04:00
|
|
|
failwith
|
|
|
|
"Previously registred protocol (%a)"
|
|
|
|
Protocol_hash.pp_short hash
|
2017-04-19 23:46:10 +04:00
|
|
|
| Some _ -> return ()
|
2016-10-24 16:10:17 +04:00
|
|
|
in
|
|
|
|
Lwt.return (hash, validation)
|
2016-10-21 16:01:20 +04:00
|
|
|
|
2017-11-14 06:14:26 +04:00
|
|
|
let inject_block validator ?force ?net_id bytes operations =
|
2017-11-13 22:06:30 +04:00
|
|
|
Validator.validate_block
|
2017-11-14 06:14:26 +04:00
|
|
|
validator ?force ?net_id bytes operations >>=? fun (hash, block) ->
|
2017-02-24 20:17:53 +04:00
|
|
|
return (hash, (block >>=? fun _ -> return ()))
|
2016-10-21 16:01:20 +04:00
|
|
|
|
2016-09-08 21:13:10 +04:00
|
|
|
type t = {
|
|
|
|
state: State.t ;
|
2017-02-24 20:17:53 +04:00
|
|
|
distributed_db: Distributed_db.t ;
|
2017-09-29 20:43:13 +04:00
|
|
|
validator: Validator.t ;
|
2017-11-11 06:34:12 +04:00
|
|
|
mainnet_validator: Net_validator.t ;
|
2016-09-08 21:13:10 +04:00
|
|
|
inject_block:
|
2017-03-30 15:16:21 +04:00
|
|
|
?force:bool ->
|
2017-11-14 06:14:26 +04:00
|
|
|
?net_id:Net_id.t ->
|
2017-11-14 02:27:19 +04:00
|
|
|
MBytes.t -> Operation.t list list ->
|
2017-02-24 20:17:53 +04:00
|
|
|
(Block_hash.t * unit tzresult Lwt.t) tzresult Lwt.t ;
|
2016-09-08 21:13:10 +04:00
|
|
|
inject_operation:
|
2017-11-23 19:39:33 +04:00
|
|
|
?net_id:Net_id.t -> MBytes.t ->
|
2017-02-24 20:17:53 +04:00
|
|
|
(Operation_hash.t * unit tzresult Lwt.t) Lwt.t ;
|
2016-10-21 16:01:20 +04:00
|
|
|
inject_protocol:
|
2017-04-19 21:21:23 +04:00
|
|
|
?force:bool -> Protocol.t ->
|
2017-02-24 20:17:53 +04:00
|
|
|
(Protocol_hash.t * unit tzresult Lwt.t) Lwt.t ;
|
|
|
|
p2p: Distributed_db.p2p ; (* For P2P RPCs *)
|
2016-09-08 21:13:10 +04:00
|
|
|
shutdown: unit -> unit Lwt.t ;
|
|
|
|
}
|
|
|
|
|
|
|
|
let init_p2p net_params =
|
|
|
|
match net_params with
|
|
|
|
| None ->
|
|
|
|
lwt_log_notice "P2P layer is disabled" >>= fun () ->
|
2017-04-18 20:13:46 +04:00
|
|
|
Error_monad.return (P2p.faked_network Distributed_db_metadata.cfg)
|
2016-09-08 21:13:10 +04:00
|
|
|
| Some (config, limits) ->
|
|
|
|
lwt_log_notice "bootstraping network..." >>= fun () ->
|
2017-02-24 20:17:53 +04:00
|
|
|
P2p.create
|
|
|
|
~config ~limits
|
|
|
|
Distributed_db_metadata.cfg
|
2017-04-18 20:13:46 +04:00
|
|
|
Distributed_db_message.cfg >>=? fun p2p ->
|
2017-02-24 20:17:53 +04:00
|
|
|
Lwt.async (fun () -> P2p.maintain p2p) ;
|
2017-04-18 20:13:46 +04:00
|
|
|
Error_monad.return p2p
|
2017-01-23 14:10:02 +04:00
|
|
|
|
2017-01-23 14:10:07 +04:00
|
|
|
type config = {
|
2017-02-24 20:17:53 +04:00
|
|
|
genesis: State.Net.genesis ;
|
2017-01-23 14:10:07 +04:00
|
|
|
store_root: string ;
|
|
|
|
context_root: string ;
|
|
|
|
patch_context: (Context.t -> Context.t Lwt.t) option ;
|
|
|
|
p2p: (P2p.config * P2p.limits) option ;
|
2017-04-10 23:14:17 +04:00
|
|
|
test_network_max_tll: int option ;
|
2017-11-11 06:34:12 +04:00
|
|
|
bootstrap_threshold: int ;
|
2017-01-23 14:10:07 +04:00
|
|
|
}
|
2016-09-08 21:13:10 +04:00
|
|
|
|
2017-11-13 17:25:02 +04:00
|
|
|
and timeout = Net_validator.timeout = {
|
|
|
|
block_header: float ;
|
|
|
|
block_operations: float ;
|
|
|
|
protocol: float ;
|
|
|
|
new_head_request: float ;
|
|
|
|
}
|
|
|
|
|
2017-11-29 16:51:06 +04:00
|
|
|
and prevalidator_limits = Prevalidator.limits = {
|
|
|
|
max_refused_operations: int ;
|
2017-11-30 21:34:22 +04:00
|
|
|
operation_timeout: float ;
|
|
|
|
worker_limits : Worker_types.limits ;
|
2017-11-29 16:51:06 +04:00
|
|
|
}
|
|
|
|
|
2018-01-26 16:10:20 +04:00
|
|
|
and block_validator_limits = Block_validator.limits = {
|
|
|
|
protocol_timeout: float ;
|
|
|
|
worker_limits : Worker_types.limits ;
|
|
|
|
}
|
|
|
|
|
2017-04-10 23:14:17 +04:00
|
|
|
let may_create_net state genesis =
|
2017-03-31 15:04:05 +04:00
|
|
|
State.Net.get state (Net_id.of_block_hash genesis.State.Net.block) >>= function
|
2017-03-02 18:08:42 +04:00
|
|
|
| Ok net -> Lwt.return net
|
|
|
|
| Error _ ->
|
2017-04-10 23:14:17 +04:00
|
|
|
State.Net.create state genesis
|
2017-03-02 18:08:42 +04:00
|
|
|
|
2017-01-23 14:10:07 +04:00
|
|
|
let create { genesis ; store_root ; context_root ;
|
2017-04-10 23:14:17 +04:00
|
|
|
patch_context ; p2p = net_params ;
|
2017-11-11 06:34:12 +04:00
|
|
|
test_network_max_tll = max_child_ttl ;
|
2017-11-29 16:51:06 +04:00
|
|
|
bootstrap_threshold }
|
2018-01-26 16:10:20 +04:00
|
|
|
timeout
|
|
|
|
block_validator_limits
|
|
|
|
prevalidator_limits =
|
2017-04-18 20:13:46 +04:00
|
|
|
init_p2p net_params >>=? fun p2p ->
|
2016-09-08 21:13:10 +04:00
|
|
|
State.read
|
2017-02-24 20:17:53 +04:00
|
|
|
~store_root ~context_root ?patch_context () >>=? fun state ->
|
|
|
|
let distributed_db = Distributed_db.create state p2p in
|
2018-01-26 16:10:20 +04:00
|
|
|
Validator.create state distributed_db timeout
|
|
|
|
block_validator_limits prevalidator_limits >>= fun validator ->
|
2017-11-11 06:34:12 +04:00
|
|
|
may_create_net state genesis >>= fun mainnet_state ->
|
2017-09-29 20:43:13 +04:00
|
|
|
Validator.activate validator
|
2017-11-11 06:34:12 +04:00
|
|
|
~bootstrap_threshold
|
|
|
|
?max_child_ttl mainnet_state >>= fun mainnet_validator ->
|
2016-09-08 21:13:10 +04:00
|
|
|
let shutdown () =
|
2017-02-24 20:17:53 +04:00
|
|
|
P2p.shutdown p2p >>= fun () ->
|
|
|
|
Validator.shutdown validator >>= fun () ->
|
2017-11-28 17:44:22 +04:00
|
|
|
State.close state >>= fun () ->
|
2017-02-24 20:17:53 +04:00
|
|
|
Lwt.return_unit
|
2016-09-08 21:13:10 +04:00
|
|
|
in
|
|
|
|
return {
|
|
|
|
state ;
|
2017-02-24 20:17:53 +04:00
|
|
|
distributed_db ;
|
2016-09-08 21:13:10 +04:00
|
|
|
validator ;
|
2017-02-28 03:48:22 +04:00
|
|
|
mainnet_validator ;
|
2017-02-24 20:17:53 +04:00
|
|
|
inject_block = inject_block validator ;
|
2016-09-08 21:13:10 +04:00
|
|
|
inject_operation = inject_operation validator ;
|
2016-10-21 16:01:20 +04:00
|
|
|
inject_protocol = inject_protocol state ;
|
2017-02-17 22:12:06 +04:00
|
|
|
p2p ;
|
2016-09-08 21:13:10 +04:00
|
|
|
shutdown ;
|
|
|
|
}
|
|
|
|
|
|
|
|
let shutdown node = node.shutdown ()
|
|
|
|
|
|
|
|
module RPC = struct
|
|
|
|
|
|
|
|
type block = Node_rpc_services.Blocks.block
|
|
|
|
type block_info = Node_rpc_services.Blocks.block_info = {
|
|
|
|
hash: Block_hash.t ;
|
2017-04-10 19:06:11 +04:00
|
|
|
net_id: Net_id.t ;
|
2017-04-10 15:01:22 +04:00
|
|
|
level: Int32.t ;
|
2017-04-12 20:22:40 +04:00
|
|
|
proto_level: int ; (* uint8 *)
|
2016-09-08 21:13:10 +04:00
|
|
|
predecessor: Block_hash.t ;
|
|
|
|
timestamp: Time.t ;
|
2017-09-29 20:43:13 +04:00
|
|
|
validation_passes: int ; (* uint8 *)
|
2017-03-30 15:16:21 +04:00
|
|
|
operations_hash: Operation_list_list_hash.t ;
|
2017-04-10 19:06:11 +04:00
|
|
|
fitness: MBytes.t list ;
|
2017-12-05 18:19:22 +04:00
|
|
|
context: Context_hash.t ;
|
2017-04-10 19:06:11 +04:00
|
|
|
data: MBytes.t ;
|
2017-11-14 02:27:19 +04:00
|
|
|
operations: (Operation_hash.t * Operation.t) list list option ;
|
2017-04-10 19:06:11 +04:00
|
|
|
protocol: Protocol_hash.t ;
|
2017-11-27 09:13:12 +04:00
|
|
|
test_network: Test_network_status.t ;
|
2017-11-13 19:34:00 +04:00
|
|
|
}
|
2016-09-08 21:13:10 +04:00
|
|
|
|
2017-04-19 23:46:10 +04:00
|
|
|
let convert (block: State.Block.t) =
|
|
|
|
let hash = State.Block.hash block in
|
|
|
|
let header = State.Block.header block in
|
2017-11-14 02:27:19 +04:00
|
|
|
State.Block.all_operations block >>= fun operations ->
|
|
|
|
let operations =
|
|
|
|
List.map (List.map (fun op -> (Operation.hash op, op))) operations in
|
2017-04-19 23:46:10 +04:00
|
|
|
State.Block.context block >>= fun context ->
|
|
|
|
Context.get_protocol context >>= fun protocol ->
|
|
|
|
Context.get_test_network context >>= fun test_network ->
|
2017-04-14 02:05:36 +04:00
|
|
|
Lwt.return {
|
2017-04-19 23:46:10 +04:00
|
|
|
hash ;
|
2017-11-14 06:14:26 +04:00
|
|
|
net_id = State.Block.net_id block ;
|
2017-04-19 23:46:10 +04:00
|
|
|
level = header.shell.level ;
|
|
|
|
proto_level = header.shell.proto_level ;
|
|
|
|
predecessor = header.shell.predecessor ;
|
|
|
|
timestamp = header.shell.timestamp ;
|
2017-09-29 20:43:13 +04:00
|
|
|
validation_passes = header.shell.validation_passes ;
|
2017-04-19 23:46:10 +04:00
|
|
|
operations_hash = header.shell.operations_hash ;
|
|
|
|
fitness = header.shell.fitness ;
|
2017-12-05 18:19:22 +04:00
|
|
|
context = header.shell.context ;
|
2017-04-19 23:46:10 +04:00
|
|
|
data = header.proto ;
|
2017-04-14 02:05:36 +04:00
|
|
|
operations = Some operations ;
|
2017-04-19 23:46:10 +04:00
|
|
|
protocol ;
|
|
|
|
test_network ;
|
2017-04-14 02:05:36 +04:00
|
|
|
}
|
2016-09-08 21:13:10 +04:00
|
|
|
|
|
|
|
let inject_block node = node.inject_block
|
|
|
|
let inject_operation node = node.inject_operation
|
2016-10-21 16:01:20 +04:00
|
|
|
let inject_protocol node = node.inject_protocol
|
2016-09-08 21:13:10 +04:00
|
|
|
|
|
|
|
let raw_block_info node hash =
|
2017-04-19 23:46:10 +04:00
|
|
|
State.read_block node.state hash >>= function
|
|
|
|
| Some block ->
|
2017-04-14 02:05:36 +04:00
|
|
|
convert block
|
2017-02-24 20:17:53 +04:00
|
|
|
| None ->
|
|
|
|
Lwt.fail Not_found
|
2016-09-08 21:13:10 +04:00
|
|
|
|
|
|
|
let prevalidation_hash =
|
2017-04-05 11:54:21 +04:00
|
|
|
Block_hash.of_b58check_exn
|
2017-02-19 21:22:32 +04:00
|
|
|
"BLockPrevaLidationPrevaLidationPrevaLidationPrZ4mr6"
|
2016-09-08 21:13:10 +04:00
|
|
|
|
2017-02-24 20:17:53 +04:00
|
|
|
let get_validator node = function
|
2017-02-28 03:48:22 +04:00
|
|
|
| `Genesis | `Head _ | `Prevalidation -> node.mainnet_validator
|
2017-02-24 20:17:53 +04:00
|
|
|
| `Test_head _ | `Test_prevalidation ->
|
2017-11-11 06:34:12 +04:00
|
|
|
match Net_validator.child node.mainnet_validator with
|
2017-02-24 20:17:53 +04:00
|
|
|
| None -> raise Not_found
|
2017-11-11 06:34:12 +04:00
|
|
|
| Some v -> v
|
2017-02-24 20:17:53 +04:00
|
|
|
|
|
|
|
let get_validator_per_hash node hash =
|
2017-04-19 23:46:10 +04:00
|
|
|
State.read_block_exn node.state hash >>= fun block ->
|
2017-11-14 06:14:26 +04:00
|
|
|
let net_id = State.Block.net_id block in
|
|
|
|
if Net_id.equal (Net_validator.net_id node.mainnet_validator) net_id then
|
2017-11-11 06:34:12 +04:00
|
|
|
Lwt.return (Some node.mainnet_validator)
|
2017-02-24 20:17:53 +04:00
|
|
|
else
|
2017-11-11 06:34:12 +04:00
|
|
|
match Net_validator.child node.mainnet_validator with
|
|
|
|
| Some test_validator ->
|
2017-11-14 06:14:26 +04:00
|
|
|
if Net_id.equal (Net_validator.net_id test_validator) net_id then
|
2017-11-11 06:34:12 +04:00
|
|
|
Lwt.return_some test_validator
|
|
|
|
else
|
|
|
|
Lwt.return_none
|
2017-02-24 20:17:53 +04:00
|
|
|
| _ -> Lwt.return_none
|
|
|
|
|
|
|
|
let read_valid_block node h =
|
2017-04-19 23:46:10 +04:00
|
|
|
State.read_block node.state h
|
2017-02-24 20:17:53 +04:00
|
|
|
|
|
|
|
let read_valid_block_exn node h =
|
2017-04-19 23:46:10 +04:00
|
|
|
State.read_block_exn node.state h
|
|
|
|
|
|
|
|
let rec predecessor net_db n v =
|
2017-02-24 20:17:53 +04:00
|
|
|
if n <= 0 then
|
|
|
|
Lwt.return v
|
|
|
|
else
|
2017-04-19 23:46:10 +04:00
|
|
|
State.Block.predecessor v >>= function
|
2017-04-20 10:49:14 +04:00
|
|
|
| None -> Lwt.return v
|
2017-04-19 23:46:10 +04:00
|
|
|
| Some v -> predecessor net_db (n-1) v
|
2016-09-08 21:13:10 +04:00
|
|
|
|
|
|
|
let block_info node (block: block) =
|
|
|
|
match block with
|
2017-02-24 20:17:53 +04:00
|
|
|
| `Genesis ->
|
2017-11-11 06:34:12 +04:00
|
|
|
let net_state = Net_validator.net_state node.mainnet_validator in
|
|
|
|
Chain.genesis net_state >>= convert
|
2016-09-08 21:13:10 +04:00
|
|
|
| ( `Head n | `Test_head n ) as block ->
|
2017-02-24 20:17:53 +04:00
|
|
|
let validator = get_validator node block in
|
2017-11-11 06:34:12 +04:00
|
|
|
let net_db = Net_validator.net_db validator in
|
|
|
|
let net_state = Net_validator.net_state validator in
|
2017-04-19 23:46:10 +04:00
|
|
|
Chain.head net_state >>= fun head ->
|
|
|
|
predecessor net_db n head >>= convert
|
2017-02-24 20:17:53 +04:00
|
|
|
| `Hash h ->
|
2017-04-14 02:05:36 +04:00
|
|
|
read_valid_block_exn node h >>= convert
|
2016-09-08 21:13:10 +04:00
|
|
|
| ( `Prevalidation | `Test_prevalidation ) as block ->
|
2017-02-24 20:17:53 +04:00
|
|
|
let validator = get_validator node block in
|
2017-11-11 06:34:12 +04:00
|
|
|
let pv = Net_validator.prevalidator validator in
|
|
|
|
let net_state = Net_validator.net_state validator in
|
2017-04-19 23:46:10 +04:00
|
|
|
Chain.head net_state >>= fun head ->
|
|
|
|
let head_header = State.Block.header head in
|
|
|
|
let head_hash = State.Block.hash head in
|
2017-11-14 06:14:26 +04:00
|
|
|
let head_net_id = State.Block.net_id head in
|
2017-04-19 23:46:10 +04:00
|
|
|
State.Block.context head >>= fun head_context ->
|
|
|
|
Context.get_protocol head_context >>= fun head_protocol ->
|
2016-10-20 20:54:16 +04:00
|
|
|
Prevalidator.context pv >>= function
|
|
|
|
| Error _ -> Lwt.fail Not_found
|
2017-04-10 14:14:11 +04:00
|
|
|
| Ok { context ; fitness } ->
|
|
|
|
Context.get_protocol context >>= fun protocol ->
|
2017-04-10 19:06:11 +04:00
|
|
|
Context.get_test_network context >>= fun test_network ->
|
2017-04-12 20:22:40 +04:00
|
|
|
let proto_level =
|
2017-04-19 23:46:10 +04:00
|
|
|
if Protocol_hash.equal protocol head_protocol then
|
|
|
|
head_header.shell.proto_level
|
2017-04-12 20:22:40 +04:00
|
|
|
else
|
2017-04-19 23:46:10 +04:00
|
|
|
((head_header.shell.proto_level + 1) mod 256) in
|
2016-10-20 20:54:16 +04:00
|
|
|
let operations =
|
|
|
|
let pv_result, _ = Prevalidator.operations pv in
|
2017-04-10 15:01:22 +04:00
|
|
|
[ pv_result.applied ] in
|
2016-10-20 20:54:16 +04:00
|
|
|
Lwt.return
|
2017-04-10 15:01:22 +04:00
|
|
|
{ hash = prevalidation_hash ;
|
2017-04-19 23:46:10 +04:00
|
|
|
level = Int32.succ head_header.shell.level ;
|
2017-04-12 20:22:40 +04:00
|
|
|
proto_level ;
|
2017-04-19 23:46:10 +04:00
|
|
|
predecessor = head_hash ;
|
2017-04-10 15:01:22 +04:00
|
|
|
fitness ;
|
|
|
|
timestamp = Prevalidator.timestamp pv ;
|
2017-04-10 19:06:11 +04:00
|
|
|
protocol ;
|
2017-09-29 20:43:13 +04:00
|
|
|
validation_passes = List.length operations ;
|
2017-04-10 15:01:22 +04:00
|
|
|
operations_hash =
|
|
|
|
Operation_list_list_hash.compute
|
2017-11-14 02:27:19 +04:00
|
|
|
(List.map
|
|
|
|
(fun ops -> Operation_list_hash.compute (List.map fst ops))
|
|
|
|
operations) ;
|
2017-04-10 15:01:22 +04:00
|
|
|
operations = Some operations ;
|
2017-12-05 18:19:22 +04:00
|
|
|
context = Context_hash.zero ;
|
2017-04-10 19:06:11 +04:00
|
|
|
data = MBytes.of_string "" ;
|
2017-11-14 06:14:26 +04:00
|
|
|
net_id = head_net_id ;
|
2017-04-10 19:06:11 +04:00
|
|
|
test_network ;
|
2017-04-10 15:01:22 +04:00
|
|
|
}
|
2016-09-08 21:13:10 +04:00
|
|
|
|
2017-04-19 23:46:10 +04:00
|
|
|
let rpc_context block : Updater.rpc_context Lwt.t =
|
|
|
|
let block_hash = State.Block.hash block in
|
|
|
|
let block_header = State.Block.header block in
|
|
|
|
State.Block.context block >|= fun context ->
|
|
|
|
{ Updater.block_hash ;
|
|
|
|
block_header ;
|
|
|
|
operation_hashes = (fun () -> State.Block.all_operation_hashes block) ;
|
|
|
|
operations = (fun () -> State.Block.all_operations block) ;
|
|
|
|
context ;
|
2017-04-14 02:07:01 +04:00
|
|
|
}
|
2017-04-10 14:14:11 +04:00
|
|
|
|
|
|
|
let get_rpc_context node block =
|
2016-09-08 21:13:10 +04:00
|
|
|
match block with
|
|
|
|
| `Genesis ->
|
2017-11-11 06:34:12 +04:00
|
|
|
let net_state = Net_validator.net_state node.mainnet_validator in
|
|
|
|
Chain.genesis net_state >>= fun block ->
|
2017-04-19 23:46:10 +04:00
|
|
|
rpc_context block >>= fun ctxt ->
|
|
|
|
Lwt.return (Some ctxt)
|
2017-02-24 20:17:53 +04:00
|
|
|
| ( `Head n | `Test_head n ) as block ->
|
|
|
|
let validator = get_validator node block in
|
2017-11-11 06:34:12 +04:00
|
|
|
let net_state = Net_validator.net_state validator in
|
|
|
|
let net_db = Net_validator.net_db validator in
|
2017-04-19 23:46:10 +04:00
|
|
|
Chain.head net_state >>= fun head ->
|
|
|
|
predecessor net_db n head >>= fun block ->
|
|
|
|
rpc_context block >>= fun ctxt ->
|
|
|
|
Lwt.return (Some ctxt)
|
2016-09-08 21:13:10 +04:00
|
|
|
| `Hash hash-> begin
|
2017-04-19 23:46:10 +04:00
|
|
|
read_valid_block node hash >>= function
|
|
|
|
| None ->
|
|
|
|
Lwt.return_none
|
|
|
|
| Some block ->
|
|
|
|
rpc_context block >>= fun ctxt ->
|
|
|
|
Lwt.return (Some ctxt)
|
2016-09-08 21:13:10 +04:00
|
|
|
end
|
|
|
|
| ( `Prevalidation | `Test_prevalidation ) as block ->
|
2017-11-11 06:34:12 +04:00
|
|
|
let validator = get_validator node block in
|
|
|
|
let pv = Net_validator.prevalidator validator in
|
|
|
|
let net_state = Net_validator.net_state validator in
|
2017-04-19 23:46:10 +04:00
|
|
|
Chain.head net_state >>= fun head ->
|
|
|
|
let head_header = State.Block.header head in
|
|
|
|
let head_hash = State.Block.hash head in
|
|
|
|
State.Block.context head >>= fun head_context ->
|
|
|
|
Context.get_protocol head_context >>= fun head_protocol ->
|
2016-10-20 20:54:16 +04:00
|
|
|
Prevalidator.context pv >>= function
|
|
|
|
| Error _ -> Lwt.fail Not_found
|
2017-04-10 14:14:11 +04:00
|
|
|
| Ok { context ; fitness } ->
|
2017-04-14 02:07:01 +04:00
|
|
|
Context.get_protocol context >>= fun protocol ->
|
|
|
|
let proto_level =
|
2017-04-19 23:46:10 +04:00
|
|
|
if Protocol_hash.equal protocol head_protocol then
|
|
|
|
head_header.shell.proto_level
|
2017-04-14 02:07:01 +04:00
|
|
|
else
|
2017-04-19 23:46:10 +04:00
|
|
|
((head_header.shell.proto_level + 1) mod 256) in
|
2017-11-14 02:27:19 +04:00
|
|
|
let operation_hashes, operations =
|
2017-04-14 02:07:01 +04:00
|
|
|
let pv_result, _ = Prevalidator.operations pv in
|
2017-11-14 02:27:19 +04:00
|
|
|
[ List.map fst pv_result.applied ],
|
|
|
|
[ List.map snd pv_result.applied ] in
|
2017-04-14 02:07:01 +04:00
|
|
|
let operations_hash =
|
|
|
|
Operation_list_list_hash.compute
|
|
|
|
(List.map Operation_list_hash.compute operation_hashes) in
|
|
|
|
Lwt.return (Some {
|
|
|
|
Updater.block_hash = prevalidation_hash ;
|
|
|
|
block_header = {
|
|
|
|
shell = {
|
2017-04-19 23:46:10 +04:00
|
|
|
level = Int32.succ head_header.shell.level ;
|
2017-04-14 02:07:01 +04:00
|
|
|
proto_level ;
|
2017-04-19 23:46:10 +04:00
|
|
|
predecessor = head_hash ;
|
2017-04-14 02:07:01 +04:00
|
|
|
timestamp = Prevalidator.timestamp pv ;
|
2017-09-29 20:43:13 +04:00
|
|
|
validation_passes = List.length operation_hashes ;
|
2017-04-14 02:07:01 +04:00
|
|
|
operations_hash ;
|
|
|
|
fitness ;
|
2017-12-05 18:19:22 +04:00
|
|
|
context = Context_hash.zero ;
|
2017-04-14 02:07:01 +04:00
|
|
|
} ;
|
|
|
|
proto = MBytes.create 0 ;
|
|
|
|
} ;
|
|
|
|
operation_hashes = (fun () -> Lwt.return operation_hashes) ;
|
2017-11-14 02:27:19 +04:00
|
|
|
operations = (fun () -> Lwt.return operations) ;
|
2017-04-14 02:07:01 +04:00
|
|
|
context ;
|
|
|
|
})
|
2016-09-08 21:13:10 +04:00
|
|
|
|
2017-04-19 23:46:10 +04:00
|
|
|
let operation_hashes node block =
|
2016-09-08 21:13:10 +04:00
|
|
|
match block with
|
2017-04-19 23:46:10 +04:00
|
|
|
| `Genesis -> Lwt.return []
|
2016-09-08 21:13:10 +04:00
|
|
|
| ( `Head n | `Test_head n ) as block ->
|
2017-02-24 20:17:53 +04:00
|
|
|
let validator = get_validator node block in
|
2017-11-11 06:34:12 +04:00
|
|
|
let net_state = Net_validator.net_state validator in
|
|
|
|
let net_db = Net_validator.net_db validator in
|
2017-04-19 23:46:10 +04:00
|
|
|
Chain.head net_state >>= fun head ->
|
|
|
|
predecessor net_db n head >>= fun block ->
|
|
|
|
State.Block.all_operation_hashes block
|
2016-09-08 21:13:10 +04:00
|
|
|
| (`Prevalidation | `Test_prevalidation) as block ->
|
2017-11-11 06:34:12 +04:00
|
|
|
let validator = get_validator node block in
|
|
|
|
let pv = Net_validator.prevalidator validator in
|
2017-11-27 09:13:12 +04:00
|
|
|
let { Preapply_result.applied }, _ = Prevalidator.operations pv in
|
2017-11-14 02:27:19 +04:00
|
|
|
Lwt.return [List.map fst applied]
|
2016-10-20 20:54:16 +04:00
|
|
|
| `Hash hash ->
|
2017-04-14 02:05:36 +04:00
|
|
|
read_valid_block node hash >>= function
|
|
|
|
| None -> Lwt.return_nil
|
2017-04-19 23:46:10 +04:00
|
|
|
| Some block ->
|
|
|
|
State.Block.all_operation_hashes block
|
2016-09-08 21:13:10 +04:00
|
|
|
|
2017-04-19 23:46:10 +04:00
|
|
|
let operations node block =
|
|
|
|
match block with
|
|
|
|
| `Genesis -> Lwt.return []
|
|
|
|
| ( `Head n | `Test_head n ) as block ->
|
|
|
|
let validator = get_validator node block in
|
2017-11-11 06:34:12 +04:00
|
|
|
let net_state = Net_validator.net_state validator in
|
|
|
|
let net_db = Net_validator.net_db validator in
|
2017-04-19 23:46:10 +04:00
|
|
|
Chain.head net_state >>= fun head ->
|
|
|
|
predecessor net_db n head >>= fun block ->
|
|
|
|
State.Block.all_operations block
|
|
|
|
| (`Prevalidation | `Test_prevalidation) as block ->
|
2017-11-11 06:34:12 +04:00
|
|
|
let validator = get_validator node block in
|
|
|
|
let pv = Net_validator.prevalidator validator in
|
2017-11-27 09:13:12 +04:00
|
|
|
let { Preapply_result.applied }, _ = Prevalidator.operations pv in
|
2017-11-14 02:27:19 +04:00
|
|
|
Lwt.return [List.map snd applied]
|
2017-04-19 23:46:10 +04:00
|
|
|
| `Hash hash ->
|
|
|
|
read_valid_block node hash >>= function
|
|
|
|
| None -> Lwt.return_nil
|
|
|
|
| Some block ->
|
|
|
|
State.Block.all_operations block
|
2016-09-08 21:13:10 +04:00
|
|
|
|
2017-02-24 20:17:53 +04:00
|
|
|
let pending_operations node (block: block) =
|
2016-09-08 21:13:10 +04:00
|
|
|
match block with
|
|
|
|
| ( `Head 0 | `Prevalidation
|
|
|
|
| `Test_head 0 | `Test_prevalidation ) as block ->
|
2017-11-11 06:34:12 +04:00
|
|
|
let validator = get_validator node block in
|
|
|
|
let pv = Net_validator.prevalidator validator in
|
2016-09-08 21:13:10 +04:00
|
|
|
Lwt.return (Prevalidator.operations pv)
|
|
|
|
| ( `Head n | `Test_head n ) as block ->
|
2017-02-24 20:17:53 +04:00
|
|
|
let validator = get_validator node block in
|
2017-11-11 06:34:12 +04:00
|
|
|
let prevalidator = Net_validator.prevalidator validator in
|
|
|
|
let net_state = Net_validator.net_state validator in
|
|
|
|
let net_db = Net_validator.net_db validator in
|
2017-04-19 23:46:10 +04:00
|
|
|
Chain.head net_state >>= fun head ->
|
|
|
|
predecessor net_db n head >>= fun b ->
|
2017-02-24 20:17:53 +04:00
|
|
|
Prevalidator.pending ~block:b prevalidator >|= fun ops ->
|
2017-11-27 09:13:12 +04:00
|
|
|
Preapply_result.empty, ops
|
2016-09-08 21:13:10 +04:00
|
|
|
| `Genesis ->
|
2017-11-11 06:34:12 +04:00
|
|
|
let net_state = Net_validator.net_state node.mainnet_validator in
|
|
|
|
let prevalidator =
|
|
|
|
Net_validator.prevalidator node.mainnet_validator in
|
|
|
|
Chain.genesis net_state >>= fun b ->
|
2017-02-24 20:17:53 +04:00
|
|
|
Prevalidator.pending ~block:b prevalidator >|= fun ops ->
|
2017-11-27 09:13:12 +04:00
|
|
|
Preapply_result.empty, ops
|
2017-02-24 20:17:53 +04:00
|
|
|
| `Hash h -> begin
|
|
|
|
get_validator_per_hash node h >>= function
|
2016-09-08 21:13:10 +04:00
|
|
|
| None ->
|
2017-11-27 09:13:12 +04:00
|
|
|
Lwt.return (Preapply_result.empty, Operation_hash.Map.empty)
|
2017-11-11 06:34:12 +04:00
|
|
|
| Some validator ->
|
|
|
|
let net_state = Net_validator.net_state validator in
|
|
|
|
let prevalidator = Net_validator.prevalidator validator in
|
2017-04-19 23:46:10 +04:00
|
|
|
State.Block.read_exn net_state h >>= fun block ->
|
2017-02-24 20:17:53 +04:00
|
|
|
Prevalidator.pending ~block prevalidator >|= fun ops ->
|
2017-11-27 09:13:12 +04:00
|
|
|
Preapply_result.empty, ops
|
2017-02-24 20:17:53 +04:00
|
|
|
end
|
2016-09-08 21:13:10 +04:00
|
|
|
|
2017-02-24 20:17:53 +04:00
|
|
|
let protocols { state } =
|
|
|
|
State.Protocol.list state >>= fun set ->
|
|
|
|
Lwt.return (Protocol_hash.Set.elements set)
|
2016-10-21 16:01:20 +04:00
|
|
|
|
|
|
|
let protocol_content node hash =
|
|
|
|
State.Protocol.read node.state hash
|
|
|
|
|
2017-04-27 03:01:05 +04:00
|
|
|
let preapply
|
|
|
|
node block
|
|
|
|
~timestamp ~proto_header ~sort_operations:sort ops =
|
2016-09-08 21:13:10 +04:00
|
|
|
begin
|
|
|
|
match block with
|
|
|
|
| `Genesis ->
|
2017-11-11 06:34:12 +04:00
|
|
|
let net_state = Net_validator.net_state node.mainnet_validator in
|
|
|
|
Chain.genesis net_state >>= return
|
2016-09-08 21:13:10 +04:00
|
|
|
| ( `Head 0 | `Prevalidation
|
|
|
|
| `Test_head 0 | `Test_prevalidation ) as block ->
|
2017-02-24 20:17:53 +04:00
|
|
|
let validator = get_validator node block in
|
2017-11-11 06:34:12 +04:00
|
|
|
let net_state = Net_validator.net_state validator in
|
2017-04-19 23:46:10 +04:00
|
|
|
Chain.head net_state >>= return
|
2016-09-08 21:13:10 +04:00
|
|
|
| `Head n | `Test_head n as block -> begin
|
2017-02-24 20:17:53 +04:00
|
|
|
let validator = get_validator node block in
|
2017-11-11 06:34:12 +04:00
|
|
|
let net_state = Net_validator.net_state validator in
|
|
|
|
let net_db = Net_validator.net_db validator in
|
2017-04-19 23:46:10 +04:00
|
|
|
Chain.head net_state >>= fun head ->
|
|
|
|
predecessor net_db n head >>= return
|
2016-09-08 21:13:10 +04:00
|
|
|
end
|
2017-02-24 20:17:53 +04:00
|
|
|
| `Hash hash ->
|
|
|
|
read_valid_block node hash >>= function
|
2016-09-08 21:13:10 +04:00
|
|
|
| None -> Lwt.return (error_exn Not_found)
|
2017-02-24 20:17:53 +04:00
|
|
|
| Some data -> return data
|
2016-10-20 20:54:16 +04:00
|
|
|
end >>=? fun predecessor ->
|
|
|
|
Prevalidation.start_prevalidation
|
2017-04-27 03:01:05 +04:00
|
|
|
~proto_header ~predecessor ~timestamp () >>=? fun validation_state ->
|
2017-12-05 18:17:57 +04:00
|
|
|
let ops = List.map (List.map (fun x -> Operation.hash x, x)) ops in
|
|
|
|
Lwt_list.fold_left_s
|
|
|
|
(fun (validation_state, rs) ops ->
|
|
|
|
Prevalidation.prevalidate
|
|
|
|
validation_state ~sort ops >>= fun (validation_state, r) ->
|
|
|
|
Lwt.return (validation_state, rs @ [r]))
|
|
|
|
(validation_state, []) ops >>= fun (validation_state, rs) ->
|
2017-04-27 03:01:05 +04:00
|
|
|
let operations_hash =
|
|
|
|
Operation_list_list_hash.compute
|
2017-12-05 18:17:57 +04:00
|
|
|
(List.map
|
|
|
|
(fun r ->
|
|
|
|
Operation_list_hash.compute
|
|
|
|
(List.map fst r.Preapply_result.applied))
|
|
|
|
rs) in
|
2017-04-27 03:01:05 +04:00
|
|
|
Prevalidation.end_prevalidation
|
2017-12-05 18:19:22 +04:00
|
|
|
validation_state >>=? fun { fitness ; context ; message } ->
|
2017-04-27 03:01:05 +04:00
|
|
|
let pred_shell_header = State.Block.shell_header predecessor in
|
|
|
|
State.Block.protocol_hash predecessor >>= fun pred_protocol ->
|
|
|
|
Context.get_protocol context >>= fun protocol ->
|
|
|
|
let proto_level =
|
|
|
|
if Protocol_hash.equal protocol pred_protocol then
|
|
|
|
pred_shell_header.proto_level
|
|
|
|
else
|
|
|
|
((pred_shell_header.proto_level + 1) mod 256) in
|
2017-12-05 18:19:22 +04:00
|
|
|
Context.commit ?message ~time:timestamp context >>= fun context ->
|
2017-04-27 03:01:05 +04:00
|
|
|
let shell_header : Block_header.shell_header = {
|
|
|
|
level = Int32.succ pred_shell_header.level ;
|
|
|
|
proto_level ;
|
|
|
|
predecessor = State.Block.hash predecessor ;
|
|
|
|
timestamp ;
|
2017-12-05 18:17:57 +04:00
|
|
|
validation_passes = List.length rs ;
|
2017-04-27 03:01:05 +04:00
|
|
|
operations_hash ;
|
|
|
|
fitness ;
|
2017-12-05 18:19:22 +04:00
|
|
|
context ;
|
2017-04-27 03:01:05 +04:00
|
|
|
} in
|
2017-12-05 18:17:57 +04:00
|
|
|
return (shell_header, rs)
|
2016-09-08 21:13:10 +04:00
|
|
|
|
2016-11-14 19:26:34 +04:00
|
|
|
let complete node ?block str =
|
|
|
|
match block with
|
|
|
|
| None ->
|
2017-02-19 21:22:32 +04:00
|
|
|
Base58.complete str
|
2016-11-14 19:26:34 +04:00
|
|
|
| Some block ->
|
2017-04-10 14:14:11 +04:00
|
|
|
get_rpc_context node block >>= function
|
2016-11-14 19:26:34 +04:00
|
|
|
| None -> Lwt.fail Not_found
|
2017-04-10 14:14:11 +04:00
|
|
|
| Some { context = ctxt } ->
|
2016-11-14 19:26:34 +04:00
|
|
|
Context.get_protocol ctxt >>= fun protocol_hash ->
|
2017-10-09 12:55:12 +04:00
|
|
|
let (module Proto) = State.Registred_protocol.get_exn protocol_hash in
|
2017-02-19 21:22:32 +04:00
|
|
|
Base58.complete str >>= fun l1 ->
|
|
|
|
Proto.complete_b58prefix ctxt str >>= fun l2 ->
|
2016-11-14 19:26:34 +04:00
|
|
|
Lwt.return (l1 @ l2)
|
|
|
|
|
2016-09-08 21:13:10 +04:00
|
|
|
let context_dir node block =
|
2017-04-10 14:14:11 +04:00
|
|
|
get_rpc_context node block >>= function
|
2016-09-08 21:13:10 +04:00
|
|
|
| None -> Lwt.return None
|
2017-04-10 14:14:11 +04:00
|
|
|
| Some rpc_context ->
|
|
|
|
Context.get_protocol rpc_context.context >>= fun protocol_hash ->
|
2017-10-09 12:55:12 +04:00
|
|
|
let (module Proto) = State.Registred_protocol.get_exn protocol_hash in
|
2017-12-09 06:51:58 +04:00
|
|
|
let dir = RPC_directory.map (fun () -> rpc_context) Proto.rpc_services in
|
|
|
|
Lwt.return (Some (RPC_directory.map (fun _ -> ()) dir))
|
2016-09-08 21:13:10 +04:00
|
|
|
|
|
|
|
let heads node =
|
2017-11-11 06:34:12 +04:00
|
|
|
let net_state = Net_validator.net_state node.mainnet_validator in
|
|
|
|
Chain.known_heads net_state >>= fun heads ->
|
2017-02-24 20:17:53 +04:00
|
|
|
begin
|
2017-11-11 06:34:12 +04:00
|
|
|
match Net_validator.child node.mainnet_validator with
|
2017-02-24 20:17:53 +04:00
|
|
|
| None -> Lwt.return_nil
|
2017-11-11 06:34:12 +04:00
|
|
|
| Some test_validator ->
|
|
|
|
let net_state = Net_validator.net_state test_validator in
|
|
|
|
Chain.known_heads net_state
|
2017-02-24 20:17:53 +04:00
|
|
|
end >>= fun test_heads ->
|
2017-04-14 02:05:36 +04:00
|
|
|
Lwt_list.fold_left_s
|
|
|
|
(fun map block ->
|
|
|
|
convert block >|= fun bi ->
|
|
|
|
Block_hash.Map.add
|
2017-04-19 23:46:10 +04:00
|
|
|
(State.Block.hash block) bi map)
|
2017-04-14 02:05:36 +04:00
|
|
|
Block_hash.Map.empty (test_heads @ heads)
|
2017-02-24 20:17:53 +04:00
|
|
|
|
2017-02-15 23:38:00 +04:00
|
|
|
let predecessors node len head =
|
2017-04-19 23:46:10 +04:00
|
|
|
let rec loop acc len block =
|
|
|
|
if len = 0 then
|
2017-02-15 23:38:00 +04:00
|
|
|
Lwt.return (List.rev acc)
|
2017-04-19 23:46:10 +04:00
|
|
|
else
|
|
|
|
State.Block.predecessor block >>= function
|
|
|
|
| None -> Lwt.return (List.rev acc)
|
|
|
|
| Some block ->
|
|
|
|
loop (State.Block.hash block :: acc) (len-1) block
|
|
|
|
in
|
2017-02-15 23:38:00 +04:00
|
|
|
try
|
2017-04-19 23:46:10 +04:00
|
|
|
State.read_block_exn node.state head >>= fun block ->
|
|
|
|
loop [] len block
|
2017-02-15 23:38:00 +04:00
|
|
|
with Not_found -> Lwt.return_nil
|
|
|
|
|
2017-04-19 23:46:10 +04:00
|
|
|
let predecessors_bi ignored len head =
|
2016-09-08 21:13:10 +04:00
|
|
|
try
|
2017-04-19 23:46:10 +04:00
|
|
|
let rec loop acc len block =
|
2017-04-14 02:05:36 +04:00
|
|
|
convert block >>= fun bi ->
|
2017-04-19 23:46:10 +04:00
|
|
|
State.Block.predecessor block >>= function
|
|
|
|
| None ->
|
|
|
|
Lwt.return (List.rev (bi :: acc))
|
|
|
|
| Some pred ->
|
|
|
|
if len = 0 ||
|
|
|
|
Block_hash.Set.mem (State.Block.hash block) ignored then
|
|
|
|
Lwt.return (List.rev acc)
|
|
|
|
else
|
|
|
|
loop (bi :: acc) (len-1) pred
|
|
|
|
in
|
2016-09-08 21:13:10 +04:00
|
|
|
loop [] len head
|
|
|
|
with Not_found -> Lwt.return_nil
|
|
|
|
|
|
|
|
let list node len heads =
|
|
|
|
Lwt_list.fold_left_s
|
|
|
|
(fun (ignored, acc) head ->
|
2017-04-19 23:46:10 +04:00
|
|
|
State.read_block_exn node.state head >>= fun block ->
|
|
|
|
predecessors_bi ignored len block >>= fun predecessors ->
|
2016-09-08 21:13:10 +04:00
|
|
|
let ignored =
|
|
|
|
List.fold_right
|
2017-02-24 20:17:53 +04:00
|
|
|
(fun x s -> Block_hash.Set.add x.hash s)
|
2016-09-08 21:13:10 +04:00
|
|
|
predecessors ignored in
|
2017-04-14 02:05:36 +04:00
|
|
|
Lwt.return (ignored, predecessors :: acc)
|
2016-09-08 21:13:10 +04:00
|
|
|
)
|
2017-02-24 20:17:53 +04:00
|
|
|
(Block_hash.Set.empty, [])
|
2017-02-15 23:38:00 +04:00
|
|
|
heads >>= fun (_, blocks) ->
|
|
|
|
Lwt.return (List.rev blocks)
|
2016-09-08 21:13:10 +04:00
|
|
|
|
2017-11-27 01:21:56 +04:00
|
|
|
let list_invalid node =
|
|
|
|
State.Block.list_invalid (Net_validator.net_state node.mainnet_validator)
|
|
|
|
|
2018-01-13 02:57:08 +04:00
|
|
|
let unmark_invalid node block =
|
|
|
|
State.Block.unmark_invalid (Net_validator.net_state node.mainnet_validator) block
|
|
|
|
|
2017-04-19 23:46:10 +04:00
|
|
|
let block_header_watcher node =
|
|
|
|
Distributed_db.watch_block_header node.distributed_db
|
2016-09-08 21:13:10 +04:00
|
|
|
|
2017-04-19 23:46:10 +04:00
|
|
|
let block_watcher node =
|
2017-11-11 06:34:12 +04:00
|
|
|
let stream, shutdown = Validator.watcher node.validator in
|
2017-04-14 02:05:36 +04:00
|
|
|
Lwt_stream.map_s (fun block -> convert block) stream,
|
2016-09-08 21:13:10 +04:00
|
|
|
shutdown
|
|
|
|
|
|
|
|
let operation_watcher node =
|
2017-02-24 20:17:53 +04:00
|
|
|
Distributed_db.watch_operation node.distributed_db
|
2016-09-08 21:13:10 +04:00
|
|
|
|
2016-10-21 16:01:20 +04:00
|
|
|
let protocol_watcher node =
|
2017-11-13 22:06:30 +04:00
|
|
|
Distributed_db.Protocol.watch node.distributed_db
|
2016-10-21 16:01:20 +04:00
|
|
|
|
2017-02-28 03:48:22 +04:00
|
|
|
let bootstrapped node =
|
|
|
|
let block_stream, stopper =
|
2017-11-11 06:34:12 +04:00
|
|
|
Net_validator.new_head_watcher node.mainnet_validator in
|
2017-02-28 03:48:22 +04:00
|
|
|
let first_run = ref true in
|
2017-11-13 17:29:28 +04:00
|
|
|
let next () =
|
2017-02-28 03:48:22 +04:00
|
|
|
if !first_run then begin
|
|
|
|
first_run := false ;
|
2017-11-11 06:34:12 +04:00
|
|
|
let net_state = Net_validator.net_state node.mainnet_validator in
|
|
|
|
Chain.head net_state >>= fun head ->
|
2017-04-19 23:46:10 +04:00
|
|
|
let head_hash = State.Block.hash head in
|
|
|
|
let head_header = State.Block.header head in
|
|
|
|
Lwt.return (Some (head_hash, head_header.shell.timestamp))
|
2017-02-28 03:48:22 +04:00
|
|
|
end else begin
|
|
|
|
Lwt.pick [
|
|
|
|
( Lwt_stream.get block_stream >|=
|
2017-11-27 09:13:12 +04:00
|
|
|
Option.map ~f:(fun b ->
|
2017-04-19 23:46:10 +04:00
|
|
|
(State.Block.hash b, (State.Block.header b).shell.timestamp)) ) ;
|
2017-11-11 06:34:12 +04:00
|
|
|
(Net_validator.bootstrapped node.mainnet_validator >|= fun () -> None) ;
|
2017-02-28 03:48:22 +04:00
|
|
|
]
|
|
|
|
end in
|
2017-11-27 09:13:12 +04:00
|
|
|
let shutdown () = Lwt_watcher.shutdown stopper in
|
2017-12-09 06:51:58 +04:00
|
|
|
RPC_answer.{ next ; shutdown }
|
2017-02-28 03:48:22 +04:00
|
|
|
|
2017-02-17 22:12:06 +04:00
|
|
|
module Network = struct
|
2017-02-28 03:48:22 +04:00
|
|
|
|
2017-02-17 22:12:06 +04:00
|
|
|
let stat (node : t) =
|
2017-02-24 20:17:53 +04:00
|
|
|
P2p.RPC.stat node.p2p
|
2017-02-17 22:12:06 +04:00
|
|
|
|
|
|
|
let watch (node : t) =
|
2017-02-24 20:17:53 +04:00
|
|
|
P2p.RPC.watch node.p2p
|
2017-02-17 22:12:06 +04:00
|
|
|
|
|
|
|
let connect (node : t) =
|
2017-02-24 20:17:53 +04:00
|
|
|
P2p.RPC.connect node.p2p
|
2017-02-17 22:12:06 +04:00
|
|
|
|
|
|
|
module Connection = struct
|
2017-02-28 03:48:22 +04:00
|
|
|
|
2017-02-17 22:12:06 +04:00
|
|
|
let info (node : t) =
|
2017-02-24 20:17:53 +04:00
|
|
|
P2p.RPC.Connection.info node.p2p
|
2017-02-17 22:12:06 +04:00
|
|
|
|
|
|
|
let kick (node : t) =
|
2017-02-24 20:17:53 +04:00
|
|
|
P2p.RPC.Connection.kick node.p2p
|
2017-02-17 22:12:06 +04:00
|
|
|
|
|
|
|
let list (node : t) =
|
2017-02-24 20:17:53 +04:00
|
|
|
P2p.RPC.Connection.list node.p2p
|
2017-02-17 22:12:06 +04:00
|
|
|
|
|
|
|
let count (node : t) =
|
2017-02-24 20:17:53 +04:00
|
|
|
P2p.RPC.Connection.count node.p2p
|
2017-02-28 03:48:22 +04:00
|
|
|
|
2017-02-17 22:12:06 +04:00
|
|
|
end
|
|
|
|
|
|
|
|
module Point = struct
|
2017-02-28 03:48:22 +04:00
|
|
|
|
2017-02-17 22:12:06 +04:00
|
|
|
let info (node : t) =
|
2017-02-24 20:17:53 +04:00
|
|
|
P2p.RPC.Point.info node.p2p
|
2017-02-17 22:12:06 +04:00
|
|
|
|
2017-11-27 09:13:12 +04:00
|
|
|
let list ?restrict (node : t) =
|
|
|
|
P2p.RPC.Point.list ?restrict node.p2p
|
2017-02-17 22:12:06 +04:00
|
|
|
|
2017-11-27 09:13:12 +04:00
|
|
|
let events ?max ?rev (node : t) =
|
|
|
|
P2p.RPC.Point.events node.p2p ?max ?rev
|
2017-02-17 22:12:06 +04:00
|
|
|
|
|
|
|
let watch (node : t) =
|
2017-02-24 20:17:53 +04:00
|
|
|
P2p.RPC.Point.watch node.p2p
|
2017-02-28 03:48:22 +04:00
|
|
|
|
2017-02-17 22:12:06 +04:00
|
|
|
end
|
|
|
|
|
2017-02-24 06:50:33 +04:00
|
|
|
module Peer_id = struct
|
2017-02-28 03:48:22 +04:00
|
|
|
|
2017-02-17 22:12:06 +04:00
|
|
|
let info (node : t) =
|
2017-02-24 20:17:53 +04:00
|
|
|
P2p.RPC.Peer_id.info node.p2p
|
2017-02-17 22:12:06 +04:00
|
|
|
|
2017-11-27 09:13:12 +04:00
|
|
|
let list ?restrict (node : t) =
|
|
|
|
P2p.RPC.Peer_id.list ?restrict node.p2p
|
2017-02-17 22:12:06 +04:00
|
|
|
|
2017-11-27 09:13:12 +04:00
|
|
|
let events ?max ?rev (node : t) =
|
|
|
|
P2p.RPC.Peer_id.events node.p2p ?max ?rev
|
2017-02-17 22:12:06 +04:00
|
|
|
|
|
|
|
let watch (node : t) =
|
2017-02-24 20:17:53 +04:00
|
|
|
P2p.RPC.Peer_id.watch node.p2p
|
2017-02-28 03:48:22 +04:00
|
|
|
|
2017-02-17 22:12:06 +04:00
|
|
|
end
|
2017-02-28 03:48:22 +04:00
|
|
|
|
2017-02-17 22:12:06 +04:00
|
|
|
end
|
2017-02-28 03:48:22 +04:00
|
|
|
|
2016-09-08 21:13:10 +04:00
|
|
|
end
|