77multiple lean nodes.
88
99Usage:
10- python3 convert-validator-config.py [validator-config.yaml] [output.json]
10+ python3 convert-validator-config.py [validator-config.yaml] [output.json] [--docker]
1111
12- Example:
13- python3 convert-validator-config.py \
14- ../lean-quickstart/local-devnet/genesis/validator-config.yaml \
12+ Options:
13+ --docker Use host.docker.internal so leanpoint running in Docker can
14+ reach a devnet on the host (e.g. upstreams-local-docker.json).
15+
16+ Examples:
17+ python3 convert-validator-config.py \\
18+ ../lean-quickstart/local-devnet/genesis/validator-config.yaml \\
1519 upstreams.json
20+
21+ python3 convert-validator-config.py \\
22+ ../lean-quickstart/local-devnet/genesis/validator-config.yaml \\
23+ upstreams-local-docker.json --docker
1624"""
1725
1826import sys
1927import json
2028import yaml
2129
2230
23- def convert_validator_config (yaml_path : str , output_path : str , base_port : int = 8081 ):
31+ def convert_validator_config (
32+ yaml_path : str ,
33+ output_path : str ,
34+ base_port : int = 8081 ,
35+ docker_host : bool = False ,
36+ ):
2437 """
2538 Convert validator-config.yaml to upstreams.json.
26-
39+
2740 Args:
2841 yaml_path: Path to validator-config.yaml
2942 output_path: Path to output upstreams.json
30- base_port: Base HTTP port for beacon API (default: 5052)
43+ base_port: Base HTTP port for beacon API (default: 8081)
44+ docker_host: If True, use host.docker.internal so leanpoint in Docker
45+ can reach a devnet running on the host (Docker Desktop/Orbstack).
3146 """
3247 with open (yaml_path , 'r' ) as f :
3348 config = yaml .safe_load (f )
34-
49+
3550 if 'validators' not in config :
3651 print ("Error: No 'validators' key found in config" , file = sys .stderr )
3752 sys .exit (1 )
38-
53+
3954 upstreams = []
40-
55+
4156 for idx , validator in enumerate (config ['validators' ]):
4257 name = validator .get ('name' , f'validator_{ idx } ' )
43-
58+
4459 # Try to get IP from enrFields, default to localhost
4560 ip = "127.0.0.1"
4661 if 'enrFields' in validator and 'ip' in validator ['enrFields' ]:
4762 ip = validator ['enrFields' ]['ip' ]
48-
49- # Calculate HTTP port (base_port + index)
50- # This is a reasonable default; adjust if your setup differs
51- http_port = base_port + idx
52-
63+ if docker_host :
64+ ip = "host.docker.internal"
65+
66+ # Use metricsPort from config when present (validator-config uses it for API)
67+ http_port = validator .get ('metricsPort' , base_port + idx )
68+
5369 upstream = {
5470 "name" : name ,
5571 "url" : f"http://{ ip } :{ http_port } " ,
5672 "path" : "/v0/health" # Health check endpoint
5773 }
58-
74+
5975 upstreams .append (upstream )
6076
6177 output = {"upstreams" : upstreams }
@@ -72,20 +88,24 @@ def convert_validator_config(yaml_path: str, output_path: str, base_port: int =
7288
7389
7490def main ():
75- if len (sys .argv ) < 2 :
76- print (__doc__ )
77- print ("\n Using default paths..." )
78- yaml_path = "../lean-quickstart/local-devnet/genesis/validator-config.yaml"
79- output_path = "upstreams.json"
80- elif len (sys .argv ) == 2 :
81- yaml_path = sys .argv [1 ]
82- output_path = "upstreams.json"
91+ args = [a for a in sys .argv [1 :] if a != "--docker" ]
92+ docker_host = "--docker" in sys .argv
93+
94+ if len (args ) < 2 :
95+ if len (args ) == 0 :
96+ print (__doc__ )
97+ print ("\n Using default paths..." )
98+ yaml_path = "../lean-quickstart/local-devnet/genesis/validator-config.yaml"
99+ output_path = "upstreams.json"
100+ else :
101+ yaml_path = args [0 ]
102+ output_path = "upstreams-local-docker.json" if docker_host else "upstreams.json"
83103 else :
84- yaml_path = sys . argv [ 1 ]
85- output_path = sys . argv [ 2 ]
86-
104+ yaml_path = args [ 0 ]
105+ output_path = args [ 1 ]
106+
87107 try :
88- convert_validator_config (yaml_path , output_path )
108+ convert_validator_config (yaml_path , output_path , docker_host = docker_host )
89109 except FileNotFoundError as e :
90110 print (f"Error: File not found: { e } " , file = sys .stderr )
91111 sys .exit (1 )
0 commit comments