diff --git a/src/node/shell/node.ml b/src/node/shell/node.ml index 4030e0e4b..7275c2adc 100644 --- a/src/node/shell/node.ml +++ b/src/node/shell/node.ml @@ -89,6 +89,16 @@ type config = { p2p: (P2p.config * P2p.limits) option ; } +let may_create_net state ?test_protocol genesis = + State.Net.get state (State.Net_id.Id genesis.State.Net.block) >>= function + | Ok net -> Lwt.return net + | Error _ -> + State.Net.create state + ?test_protocol + ~forked_network_ttl:(48 * 3600) (* 2 days *) + genesis + + let create { genesis ; store_root ; context_root ; test_protocol ; patch_context ; p2p = net_params } = init_p2p net_params >>= fun p2p -> @@ -96,10 +106,7 @@ let create { genesis ; store_root ; context_root ; ~store_root ~context_root ?patch_context () >>=? fun state -> let distributed_db = Distributed_db.create state p2p in let validator = Validator.create_worker state distributed_db in - State.Net.create state - ?test_protocol - ~forked_network_ttl:(48 * 3600) (* 2 days *) - genesis >>= fun mainnet_net -> + may_create_net state ?test_protocol genesis >>= fun mainnet_net -> Validator.activate validator mainnet_net >>= fun mainnet_validator -> let mainnet_db = Validator.net_db mainnet_validator in let shutdown () = diff --git a/src/node/shell/state.ml b/src/node/shell/state.ml index fe6410b9c..0ff3ffc6f 100644 --- a/src/node/shell/state.ml +++ b/src/node/shell/state.ml @@ -929,7 +929,7 @@ module Valid_block = struct } in Shared.use state.global_data begin fun data -> if Net_id.Table.mem data.nets (Net_id.Id hash) then - failwith "...FIXME" + assert false (* This would mean a block is validated twice... *) else Context.init_test_network block.context ~time:genesis.time