1717from services .grafana import Grafana
1818from services .tor import Tor
1919from services .fork_observer import ForkObserver
20- from services .dns_seed import DnsSeed
20+ from services .dns_seed import DnsSeed , ZONE_FILE_NAME , DNS_SEED_NAME
2121from warnet .tank import Tank
22- from warnet .utils import parse_bitcoin_conf , gen_config_dir
22+ from warnet .utils import parse_bitcoin_conf , gen_config_dir , bubble_exception_str
2323
24- logger = logging .getLogger ("Warnet " )
24+ logger = logging .getLogger ("warnet " )
2525FO_CONF_NAME = "fork_observer_config.toml"
26- ZONE_FILE_NAME = "dns-seed.zone"
2726logging .getLogger ("docker.utils.config" ).setLevel (logging .WARNING )
2827logging .getLogger ("docker.auth" ).setLevel (logging .WARNING )
2928
@@ -60,6 +59,7 @@ def __str__(self) -> str:
6059 )
6160
6261 @classmethod
62+ @bubble_exception_str
6363 def from_graph_file (
6464 cls , graph_file : str , config_dir : Path , network : str = "warnet"
6565 ):
@@ -74,6 +74,7 @@ def from_graph_file(
7474 return self
7575
7676 @classmethod
77+ @bubble_exception_str
7778 def from_graph (cls , graph ):
7879 self = cls (Path ())
7980 self .graph = graph
@@ -82,6 +83,7 @@ def from_graph(cls, graph):
8283 return self
8384
8485 @classmethod
86+ @bubble_exception_str
8587 def from_network (
8688 cls , config_dir : Path = Path (), network : str = "warnet" , tanks = True
8789 ):
@@ -95,6 +97,7 @@ def from_network(
9597 return self
9698
9799 @classmethod
100+ @bubble_exception_str
98101 def from_docker_env (cls , network_name ):
99102 config_dir = gen_config_dir (network_name )
100103 self = cls (config_dir )
@@ -113,9 +116,11 @@ def from_docker_env(cls, network_name):
113116 return self
114117
115118 @property
119+ @bubble_exception_str
116120 def zone_file_path (self ):
117121 return self .config_dir / ZONE_FILE_NAME
118122
123+ @bubble_exception_str
119124 def tanks_from_graph (self ):
120125 for node_id in self .graph .nodes ():
121126 if int (node_id ) != len (self .tanks ):
@@ -125,17 +130,20 @@ def tanks_from_graph(self):
125130 self .tanks .append (Tank .from_graph_node (node_id , self ))
126131 logger .info (f"Imported { len (self .tanks )} tanks from graph" )
127132
133+ @bubble_exception_str
128134 def write_bitcoin_confs (self ):
129135 with open (TEMPLATES / "bitcoin.conf" , "r" ) as file :
130136 text = file .read ()
131137 base_bitcoin_conf = parse_bitcoin_conf (text )
132138 for tank in self .tanks :
133139 tank .write_bitcoin_conf (base_bitcoin_conf )
134140
141+ @bubble_exception_str
135142 def apply_network_conditions (self ):
136143 for tank in self .tanks :
137144 tank .apply_network_conditions ()
138145
146+ @bubble_exception_str
139147 def generate_zone_file_from_tanks (self ):
140148 records_list = [
141149 f"seed.dns-seed. 300 IN A { tank .ipv4 } " for tank in self .tanks
@@ -152,11 +160,12 @@ def generate_zone_file_from_tanks(self):
152160 with open (self .config_dir / ZONE_FILE_NAME , "w" ) as f :
153161 f .write (content_str )
154162
163+ @bubble_exception_str
155164 def apply_zone_file (self ):
156165 """
157166 Sync the dns seed list served by dns-seed with currently active Tanks.
158167 """
159- seeder = self .docker .containers .get ("dns-seed " )
168+ seeder = self .docker .containers .get (f" { self . docker_network } _ { DNS_SEED_NAME } " )
160169
161170 # Read the content from the generated zone file
162171 with open (self .config_dir / ZONE_FILE_NAME , "r" ) as f :
@@ -171,6 +180,7 @@ def apply_zone_file(self):
171180 # Reload that single zone only
172181 seeder .exec_run ("rndc reload dns-seed" )
173182
183+ @bubble_exception_str
174184 def connect_edges (self ):
175185 for edge in self .graph .edges ():
176186 (src , dst ) = edge
@@ -180,6 +190,7 @@ def connect_edges(self):
180190 cmd = f"bitcoin-cli addpeeraddress { dst_ip } 18444"
181191 src_tank .exec (cmd = cmd , user = "bitcoin" )
182192
193+ @bubble_exception_str
183194 def docker_compose_build_up (self ):
184195 command = ["docker-compose" , "-p" , self .docker_network , "up" , "-d" , "--build" ]
185196 try :
@@ -196,6 +207,7 @@ def docker_compose_build_up(self):
196207 f"An error occurred while executing `{ ' ' .join (command )} ` in { self .config_dir } : { e } "
197208 )
198209
210+ @bubble_exception_str
199211 def docker_compose_up (self ):
200212 command = ["docker-compose" , "-p" , self .docker_network , "up" , "-d" ]
201213 try :
@@ -212,6 +224,7 @@ def docker_compose_up(self):
212224 f"An error occurred while executing `{ ' ' .join (command )} ` in { self .config_dir } : { e } "
213225 )
214226
227+ @bubble_exception_str
215228 def docker_compose_down (self ):
216229 command = ["docker-compose" , "down" ]
217230 try :
@@ -228,6 +241,7 @@ def docker_compose_down(self):
228241 f"An error occurred while executing `{ ' ' .join (command )} ` in { self .config_dir } : { e } "
229242 )
230243
244+ @bubble_exception_str
231245 def write_docker_compose (self , dns = True ):
232246 compose = {
233247 "version" : "3.8" ,
@@ -270,6 +284,7 @@ def write_docker_compose(self, dns=True):
270284 f"An error occurred while writing to { docker_compose_path } : { e } "
271285 )
272286
287+ @bubble_exception_str
273288 def write_prometheus_config (self ):
274289 config = {
275290 "global" : {"scrape_interval" : "15s" },
0 commit comments