Client/Test: fix sandbox detection

This commit is contained in:
Grégoire Henry 2018-07-17 09:19:44 +02:00 committed by Benjamin Canou
parent e264e325f8
commit 122a2421a6
4 changed files with 23 additions and 9 deletions

View File

@ -98,6 +98,9 @@ let check_network ctxt =
Lwt.return_none Lwt.return_none
| Ok versions -> | Ok versions ->
match String.split_on_char '_' (List.hd versions).name with match String.split_on_char '_' (List.hd versions).name with
| "SANDBOXED" :: _ ->
sandbox () ;
Lwt.return_some `Sandbox
| "TEZOS" :: "ZERONET" :: _date :: [] -> | "TEZOS" :: "ZERONET" :: _date :: [] ->
zeronet () ; zeronet () ;
Lwt.return_some `Zeronet Lwt.return_some `Zeronet
@ -107,9 +110,6 @@ let check_network ctxt =
| "TEZOS" :: "BETANET" :: _date :: [] -> | "TEZOS" :: "BETANET" :: _date :: [] ->
betanet () ; betanet () ;
Lwt.return_some `Betanet Lwt.return_some `Betanet
| "TEZOS" :: _date :: [] ->
sandbox () ;
Lwt.return_some `Sandbox
| _ -> | _ ->
default () ; default () ;
Lwt.return_none Lwt.return_none

View File

@ -200,6 +200,7 @@ let init_node ?sandbox ?checkpoint (config : Node_config_file.t) =
checkpoint ; checkpoint ;
} in } in
Node.create Node.create
~sandboxed:(sandbox <> None)
node_config node_config
config.shell.peer_validator_limits config.shell.peer_validator_limits
config.shell.block_validator_limits config.shell.block_validator_limits

View File

@ -58,7 +58,7 @@ let init_connection_metadata opt =
{ disable_mempool = c.P2p.disable_mempool ; { disable_mempool = c.P2p.disable_mempool ;
private_node = c.P2p.private_mode } private_node = c.P2p.private_mode }
let init_p2p p2p_params = let init_p2p ?(sandboxed = false) p2p_params =
match p2p_params with match p2p_params with
| None -> | None ->
let c_meta = init_connection_metadata None in let c_meta = init_connection_metadata None in
@ -70,11 +70,21 @@ let init_p2p p2p_params =
let conn_metadata_cfg = connection_metadata_cfg c_meta in let conn_metadata_cfg = connection_metadata_cfg c_meta in
lwt_log_notice Tag.DSL.(fun f -> lwt_log_notice Tag.DSL.(fun f ->
f "bootstrapping chain..." -% t event "bootstrapping_chain") >>= fun () -> f "bootstrapping chain..." -% t event "bootstrapping_chain") >>= fun () ->
let message_cfg =
if sandboxed then
{ Distributed_db_message.cfg with
versions =
List.map
(fun v -> { v with P2p_version.name =
"SANDBOXED_" ^ v.P2p_version.name })
Distributed_db_message.cfg.versions }
else
Distributed_db_message.cfg in
P2p.create P2p.create
~config ~limits ~config ~limits
peer_metadata_cfg peer_metadata_cfg
conn_metadata_cfg conn_metadata_cfg
Distributed_db_message.cfg >>=? fun p2p -> message_cfg >>=? fun p2p ->
Lwt.async (fun () -> P2p.maintain p2p) ; Lwt.async (fun () -> P2p.maintain p2p) ;
return p2p return p2p
@ -163,7 +173,9 @@ let may_update_checkpoint chain_state checkpoint =
Chain.set_head chain_state new_head >>= fun _old_head -> Chain.set_head chain_state new_head >>= fun _old_head ->
State.Chain.set_checkpoint chain_state checkpoint State.Chain.set_checkpoint chain_state checkpoint
let create { genesis ; store_root ; context_root ; let create
?(sandboxed = false)
{ genesis ; store_root ; context_root ;
patch_context ; p2p = p2p_params ; patch_context ; p2p = p2p_params ;
test_chain_max_tll = max_child_ttl ; checkpoint } test_chain_max_tll = max_child_ttl ; checkpoint }
peer_validator_limits peer_validator_limits
@ -174,7 +186,7 @@ let create { genesis ; store_root ; context_root ;
match p2p_params with match p2p_params with
| Some (config, _limits) -> not config.P2p.disable_mempool | Some (config, _limits) -> not config.P2p.disable_mempool
| None -> true in | None -> true in
init_p2p p2p_params >>=? fun p2p -> init_p2p ~sandboxed p2p_params >>=? fun p2p ->
State.read State.read
~store_root ~context_root ?patch_context genesis >>=? fun (state, mainchain_state) -> ~store_root ~context_root ?patch_context genesis >>=? fun (state, mainchain_state) ->
may_update_checkpoint mainchain_state checkpoint >>= fun () -> may_update_checkpoint mainchain_state checkpoint >>= fun () ->

View File

@ -62,6 +62,7 @@ val default_block_validator_limits: block_validator_limits
val default_chain_validator_limits: chain_validator_limits val default_chain_validator_limits: chain_validator_limits
val create: val create:
?sandboxed:bool ->
config -> config ->
peer_validator_limits -> peer_validator_limits ->
block_validator_limits -> block_validator_limits ->