Skip to content

Commit 52801fc

Browse files
committed
add: addrman-observer support
1 parent f2fedc0 commit 52801fc

File tree

6 files changed

+53
-5
lines changed

6 files changed

+53
-5
lines changed

MANIFEST.in

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
include src/schema/*.json
22
include src/templates/bitcoin.conf
33
include src/templates/fork_observer_config.toml
4+
include src/templates/addrman_observer_config.toml
45
include src/templates/addrman.patch
56
include src/templates/isroutable.patch
67
graft src/templates/k8s
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
# addrman-observer base configuration file
2+
3+
# path to the location of the static www files
4+
www_path = "./www"
5+
6+
# webserver listen address
7+
address = "0.0.0.0:3882"
8+

src/warnet/services.py

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
FO_CONF_NAME = "fork_observer_config.toml"
2+
AO_CONF_NAME = "addrman_observer_config.toml"
23
GRAFANA_PROVISIONING = "grafana-provisioning"
34
PROM_CONF_NAME = "prometheus.yml"
45

@@ -33,6 +34,14 @@
3334
"container_port": "2323",
3435
"config_files": [f"{FO_CONF_NAME}:/app/config.toml"],
3536
},
37+
"addrmanobserver": {
38+
"backends": ["compose"],
39+
"image": "b10c/addrman-observer:latest",
40+
"container_name_suffix": "addrman-observer",
41+
"warnet_port": "23005",
42+
"container_port": "3882",
43+
"config_files": [f"{AO_CONF_NAME}:/app/config.toml"],
44+
},
3645
"grafana": {
3746
"backends": ["compose"],
3847
"image": "grafana/grafana:latest",

src/warnet/warnet.py

Lines changed: 24 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212
import yaml
1313
from backends import ComposeBackend, KubernetesBackend
1414
from templates import TEMPLATES
15-
from warnet.services import FO_CONF_NAME, GRAFANA_PROVISIONING, PROM_CONF_NAME
15+
from warnet.services import AO_CONF_NAME, FO_CONF_NAME, GRAFANA_PROVISIONING, PROM_CONF_NAME
1616
from warnet.tank import Tank
1717
from warnet.utils import gen_config_dir, load_schema, validate_graph_schema
1818

@@ -181,8 +181,10 @@ def generate_deployment(self):
181181
self.container_interface.generate_deployment_file(self)
182182
if "forkobserver" in self.services:
183183
self.write_fork_observer_config()
184+
if "addrmanobserver" in self.services:
185+
self.write_addrman_observer_config()
184186
if "grafana" in self.services:
185-
self.write_grafna_config()
187+
self.write_grafana_config()
186188
if "prometheus" in self.services:
187189
self.write_prometheus_config()
188190

@@ -205,8 +207,27 @@ def write_fork_observer_config(self):
205207
"""
206208
)
207209
logger.info(f"Wrote file: {dst}")
210+
211+
def write_addrman_observer_config(self):
212+
src = TEMPLATES / AO_CONF_NAME
213+
dst = self.config_dir / AO_CONF_NAME
214+
shutil.copy(src, dst)
215+
with open(dst, "a") as f:
216+
for tank in self.tanks:
217+
f.write(
218+
f"""
219+
[[nodes]]
220+
id = {tank.index}
221+
name = "Node {tank.index}"
222+
rpc_host = "{tank.ipv4}"
223+
rpc_port = {tank.rpc_port}
224+
rpc_user = "{tank.rpc_user}"
225+
rpc_password = "{tank.rpc_password}"
226+
"""
227+
)
228+
logger.info(f"Wrote file: {dst}")
208229

209-
def write_grafna_config(self):
230+
def write_grafana_config(self):
210231
src = TEMPLATES / GRAFANA_PROVISIONING
211232
dst = self.config_dir / GRAFANA_PROVISIONING
212233
shutil.copytree(src, dst, dirs_exist_ok=True)

test/data/services.graphml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,12 +15,12 @@
1515
<key id="source_policy" attr.name="source_policy" attr.type="string" for="edge" />
1616
<key id="target_policy" attr.name="target_policy" attr.type="string" for="edge" />
1717
<graph edgedefault="directed">
18-
<data key="services">cadvisor forkobserver grafana nodeexporter prometheus</data>
18+
<data key="services">cadvisor forkobserver addrmanobserver grafana nodeexporter prometheus</data>
1919
<node id="0">
2020
<data key="version">26.0</data>
2121
<data key="bitcoin_config">-uacomment=w0 -debug=validation</data>
2222
<data key="exporter">true</data>
2323
<data key="ln">lnd</data>
2424
</node>
2525
</graph>
26-
</graphml>
26+
</graphml>

test/graph_test.py

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -70,6 +70,15 @@
7070
else:
7171
raise Exception("forkobserver not OK")
7272

73+
node_id = 0
74+
ao_res = requests.get(f"http://localhost:23005/{node_id}")
75+
assert ao_res.status_code == 200
76+
addrman = ao_res.json()
77+
if "new" in addrman and "tried" in addrman:
78+
print("forkobserver OK")
79+
else:
80+
raise Exception("addrmanobserver not OK")
81+
7382
grafana_res = requests.get("http://localhost:23002/api/datasources/uid/prometheusdatasource/health")
7483
assert grafana_res.status_code == 200
7584
health = grafana_res.json()

0 commit comments

Comments
 (0)