Skip to content

Commit

Permalink
refactor mina nodes to use a base config when generating docker defin…
Browse files Browse the repository at this point in the history
…itions
  • Loading branch information
MartinMinkov committed Dec 23, 2023
1 parent 8cf3062 commit 1acd4e2
Show file tree
Hide file tree
Showing 3 changed files with 77 additions and 80 deletions.
16 changes: 0 additions & 16 deletions src/lib/integration_test_local_engine/docker_compose.ml
Original file line number Diff line number Diff line change
Expand Up @@ -9,27 +9,11 @@ module Dockerfile = struct
[@@deriving to_yojson]

let create source target = { type_ = "bind"; source; target }

let write_config docker_dir ~filename ~data =
Out_channel.with_file ~fail_if_exists:false
(docker_dir ^ "/" ^ filename)
~f:(fun ch -> data |> Out_channel.output_string ch) ;
ignore (Util.run_cmd_exn docker_dir "chmod" [ "600"; filename ])
end

module Environment = struct
type t = (string * string) list

let default =
[ ("DAEMON_REST_PORT", "3085")
; ("DAEMON_CLIENT_PORT", "8301")
; ("DAEMON_METRICS_PORT", "10001")
; ("DAEMON_EXTERNAL_PORT", "10101")
; ("MINA_PRIVKEY_PASS", "naughty blue worm")
; ("MINA_LIBP2P_PASS", "")
; ("RAYON_NUM_THREADS", "6")
]

let to_yojson env = `Assoc (List.map env ~f:(fun (k, v) -> (k, `String v)))
end

Expand Down
105 changes: 55 additions & 50 deletions src/lib/integration_test_local_engine/docker_node_config.ml
Original file line number Diff line number Diff line change
Expand Up @@ -122,20 +122,30 @@ module Base_node_config = struct
}

let default ?(runtime_config_path = None) ?(peer = None) =
{ log_snark_work_gossip = true
{ runtime_config_path
; peer
; log_snark_work_gossip = true
; log_txn_pool_gossip = true
; generate_genesis_proof = true
; log_level = "Debug"
; client_port = PortManager.mina_internal_client_port |> Int.to_string
; rest_port = PortManager.mina_internal_rest_port |> Int.to_string
; metrics_port = PortManager.mina_internal_metrics_port |> Int.to_string
; external_port = PortManager.mina_internal_external_port |> Int.to_string
; runtime_config_path
; libp2p_key_path = container_libp2p_key_path
; libp2p_secret = ""
; peer
}

let to_docker_env_vars t =
[ ("DAEMON_REST_PORT", t.rest_port)
; ("DAEMON_CLIENT_PORT", t.client_port)
; ("DAEMON_METRICS_PORT", t.metrics_port)
; ("DAEMON_EXTERNAL_PORT", t.external_port)
; ("RAYON_NUM_THREADS", "8")
; ("MINA_PRIVKEY_PASS", "naughty blue worm")
; ("MINA_LIBP2P_PASS", "")
]

let to_list t =
let base_args =
[ "-log-level"
Expand Down Expand Up @@ -181,9 +191,7 @@ module Block_producer_config = struct
; priv_key_path : string
; enable_flooding : bool
; enable_peer_exchange : bool
; peer : string option
; libp2p_secret : string
; runtime_config_path : string
; base_config : Base_node_config.t
}
[@@deriving to_yojson]

Expand All @@ -195,12 +203,7 @@ module Block_producer_config = struct
[@@deriving to_yojson]

let create_cmd config =
let base_args =
Base_node_config.to_list
(Base_node_config.default
~runtime_config_path:(Some config.runtime_config_path)
~peer:config.peer )
in
let base_args = Base_node_config.to_list config.base_config in
let block_producer_args =
[ "daemon"
; "-block-producer-key"
Expand All @@ -225,9 +228,10 @@ module Block_producer_config = struct

let create ~service_name ~image ~ports ~volumes ~config =
let entrypoint = Some [ "/root/entrypoint.sh" ] in
let environment = Base_node_config.to_docker_env_vars config.base_config in
let docker_config =
create_docker_config ~image ~ports ~volumes
~environment:Dockerfile.Service.Environment.default ~entrypoint ~config
create_docker_config ~image ~ports ~volumes ~environment ~entrypoint
~config
in
{ service_name; config; docker_config }
end
Expand All @@ -242,10 +246,7 @@ module Seed_config = struct
Printf.sprintf "/dns4/%s/tcp/%d/p2p/%s" peer_name external_port peer_id

type config =
{ archive_address : string option
; peer : string option
; runtime_config_path : string
}
{ archive_address : string option; base_config : Base_node_config.t }
[@@deriving to_yojson]

type t =
Expand All @@ -262,12 +263,7 @@ module Seed_config = struct
}

let create_cmd config =
let base_args =
Base_node_config.to_list
(Base_node_config.default
~runtime_config_path:(Some config.runtime_config_path)
~peer:config.peer )
in
let base_args = Base_node_config.to_list config.base_config in
let seed_args =
match config.archive_address with
| Some archive_address ->
Expand All @@ -289,16 +285,21 @@ module Seed_config = struct

let create ~service_name ~image ~ports ~volumes ~config =
let entrypoint = Some [ "/root/entrypoint.sh" ] in
let environment = Base_node_config.to_docker_env_vars config.base_config in
let docker_config =
create_docker_config ~image ~ports ~volumes
~environment:Dockerfile.Service.Environment.default ~entrypoint ~config
create_docker_config ~image ~ports ~volumes ~environment ~entrypoint
~config
in
{ service_name; config; docker_config }
end

module Snark_worker_config = struct
type config =
{ daemon_address : string; daemon_port : string; proof_level : string }
{ daemon_address : string
; daemon_port : string
; proof_level : string
; base_config : Base_node_config.t
}
[@@deriving to_yojson]

type t =
Expand Down Expand Up @@ -331,9 +332,10 @@ module Snark_worker_config = struct

let create ~service_name ~image ~ports ~volumes ~config =
let entrypoint = Some [ "/root/entrypoint.sh" ] in
let environment = Base_node_config.to_docker_env_vars config.base_config in
let docker_config =
create_docker_config ~image ~ports ~volumes
~environment:Dockerfile.Service.Environment.default ~entrypoint ~config
create_docker_config ~image ~ports ~volumes ~environment ~entrypoint
~config
in
{ service_name; config; docker_config }
end
Expand All @@ -344,8 +346,7 @@ module Snark_coordinator_config = struct
; snark_worker_fee : string
; work_selection : string
; worker_nodes : Snark_worker_config.t list
; peer : string option
; runtime_config_path : string
; base_config : Base_node_config.t
}
[@@deriving to_yojson]

Expand All @@ -365,12 +366,7 @@ module Snark_coordinator_config = struct
]

let create_cmd config =
let base_args =
Base_node_config.to_list
(Base_node_config.default
~runtime_config_path:(Some config.runtime_config_path)
~peer:config.peer )
in
let base_args = Base_node_config.to_list config.base_config in
let snark_coordinator_args =
[ "daemon"
; "-run-snark-coordinator"
Expand Down Expand Up @@ -400,7 +396,7 @@ module Snark_coordinator_config = struct
~snark_coordinator_key:config.snark_coordinator_key
~snark_worker_fee:config.snark_worker_fee
~work_selection:config.work_selection
@ Dockerfile.Service.Environment.default
@ Base_node_config.to_docker_env_vars config.base_config
in
let docker_config =
create_docker_config ~image ~ports ~volumes ~environment ~entrypoint
Expand Down Expand Up @@ -508,7 +504,7 @@ module Archive_node_config = struct
type config =
{ postgres_config : Postgres_config.t
; server_port : int
; runtime_config_path : string
; base_config : Base_node_config.t
}
[@@deriving to_yojson]

Expand All @@ -520,15 +516,23 @@ module Archive_node_config = struct
[@@deriving to_yojson]

let create_cmd config =
[ "mina-archive"
; "run"
; "-postgres-uri"
; Postgres_config.to_connection_uri config.postgres_config.config
; "-server-port"
; Int.to_string config.server_port
; "-config-file"
; config.runtime_config_path
]
let base_args =
[ "mina-archive"
; "run"
; "-postgres-uri"
; Postgres_config.to_connection_uri config.postgres_config.config
; "-server-port"
; Int.to_string config.server_port
]
in
let runtime_config_path =
match config.base_config.runtime_config_path with
| Some path ->
[ "-config-file"; path ]
| None ->
[]
in
List.concat [ base_args; runtime_config_path ]

let create_docker_config ~image ~entrypoint ~ports ~volumes ~environment
~config =
Expand All @@ -542,9 +546,10 @@ module Archive_node_config = struct

let create ~service_name ~image ~ports ~volumes ~config =
let entrypoint = None in
let environment = Base_node_config.to_docker_env_vars config.base_config in
let docker_config =
create_docker_config ~image ~ports ~volumes
~environment:Dockerfile.Service.Environment.default ~entrypoint ~config
create_docker_config ~image ~ports ~volumes ~environment ~entrypoint
~config
in
{ service_name; config; docker_config }
end
36 changes: 22 additions & 14 deletions src/lib/integration_test_local_engine/mina_docker.ml
Original file line number Diff line number Diff line change
Expand Up @@ -290,8 +290,10 @@ module Network_config = struct
let seed_config =
let config : Seed_config.config =
{ archive_address = None
; peer = None
; runtime_config_path = Base_node_config.container_runtime_config_path
; base_config =
Base_node_config.default ~peer:None
~runtime_config_path:
(Some Base_node_config.container_runtime_config_path)
}
in
Seed_config.create
Expand Down Expand Up @@ -340,8 +342,10 @@ module Network_config = struct
let config : Archive_node_config.config =
{ postgres_config
; server_port = archive_server_port.target
; runtime_config_path =
Base_node_config.container_runtime_config_path
; base_config =
Base_node_config.default ~peer:None
~runtime_config_path:
(Some Base_node_config.container_runtime_config_path)
}
in
let archive_rest_port =
Expand All @@ -364,9 +368,10 @@ module Network_config = struct
Some
(sprintf "%s:%d" archive_config.service_name
PortManager.mina_internal_server_port )
; peer = seed_config_peer
; runtime_config_path =
Base_node_config.container_runtime_config_path
; base_config =
Base_node_config.default ~peer:seed_config_peer
~runtime_config_path:
(Some Base_node_config.container_runtime_config_path)
}
in
Seed_config.create
Expand Down Expand Up @@ -407,13 +412,13 @@ module Network_config = struct
in
let block_producer_config : Block_producer_config.config =
{ keypair
; runtime_config_path =
Base_node_config.container_runtime_config_path
; peer = seed_config_peer
; priv_key_path
; enable_peer_exchange = true
; enable_flooding = true
; libp2p_secret = ""
; base_config =
Base_node_config.default ~peer:seed_config_peer
~runtime_config_path:
(Some Base_node_config.container_runtime_config_path)
}
in
Block_producer_config.create ~service_name:node.node_name
Expand Down Expand Up @@ -462,6 +467,8 @@ module Network_config = struct
{ daemon_address = snark_node_service_name
; daemon_port = Int.to_string daemon_port.target
; proof_level = "full"
; base_config =
Base_node_config.default ~peer:None ~runtime_config_path:None
}
in
let worker_nodes =
Expand All @@ -479,11 +486,12 @@ module Network_config = struct
let snark_coordinator_config : Snark_coordinator_config.config =
{ worker_nodes
; snark_worker_fee
; runtime_config_path =
Base_node_config.container_runtime_config_path
; snark_coordinator_key = public_key
; peer = seed_config_peer
; work_selection = "seq"
; base_config =
Base_node_config.default ~peer:seed_config_peer
~runtime_config_path:
(Some Base_node_config.container_runtime_config_path)
}
in
Some
Expand Down

0 comments on commit 1acd4e2

Please sign in to comment.