Skip to content

Commit

Permalink
add fork_observer graph property
Browse files Browse the repository at this point in the history
  • Loading branch information
willcl-ark committed Mar 27, 2024
1 parent e381cc5 commit 571774f
Show file tree
Hide file tree
Showing 4 changed files with 29 additions and 14 deletions.
7 changes: 7 additions & 0 deletions src/graphs/default.graphml
Original file line number Diff line number Diff line change
Expand Up @@ -5,35 +5,41 @@
<key attr.name="build_args" attr.type="string" for="node" id="build_args"/>
<key attr.name="exporter" attr.type="boolean" for="node" id="exporter"/>
<key attr.name="collect_logs" attr.type="boolean" for="node" id="collect_logs"/>
<key attr.name="fork_observer" attr.type="boolean" for="node" id="fork_observer"/>
<key attr.name="image" attr.type="string" for="node" id="image"/>
<graph edgedefault="directed">
<node id="0">
<data key="version">26.0</data>
<data key="bitcoin_config">-uacomment=w0</data>
<data key="exporter">true</data>
<data key="collect_logs">true</data>
<data key="fork_observer">true</data>
</node>
<node id="1">
<data key="version">26.0</data>
<data key="bitcoin_config">-uacomment=w1</data>
<data key="exporter">true</data>
<data key="collect_logs">true</data>
<data key="fork_observer">true</data>
</node>
<node id="2">
<data key="image">bitcoindevproject/bitcoin:26.0</data>
<data key="bitcoin_config">-uacomment=w2 -debug=mempool</data>
<data key="exporter">true</data>
<data key="collect_logs">true</data>
<data key="fork_observer">true</data>
</node>
<node id="3">
<data key="version">26.0</data>
<data key="bitcoin_config">-uacomment=w3</data>
<data key="exporter">true</data>
<data key="fork_observer">true</data>
</node>
<node id="4">
<data key="version">26.0</data>
<data key="bitcoin_config">-uacomment=w4</data>
<data key="exporter">true</data>
<data key="fork_observer">true</data>
</node>
<node id="5">
<data key="version">26.0</data>
Expand Down Expand Up @@ -63,6 +69,7 @@
<node id="11">
<data key="version">26.0</data>
<data key="bitcoin_config">-uacomment=w11</data>
<data key="fork_observer">true</data>
</node>
<!-- connect the nodes in a ring to start -->
<edge id="1" source="0" target="1"></edge>
Expand Down
4 changes: 4 additions & 0 deletions src/schema/graph_schema.json
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,10 @@
"type": "boolean",
"default": false,
"comment": "Whether to collect Bitcoin Core debug logs with Promtail"},
"fork_observer": {
"type": "boolean",
"default": false,
"comment": "Whether it should be monitored with Fork Observer."},
"build_args": {
"type": "string",
"default": "",
Expand Down
7 changes: 5 additions & 2 deletions src/warnet/tank.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,8 +30,7 @@
"-rpcallowip=0.0.0.0/0",
"-rpcbind=0.0.0.0",
"-fallbackfee=0.00001000",
"-listen=1",
"-rest"
"-listen=1"
])

class Tank:
Expand Down Expand Up @@ -61,6 +60,7 @@ def __init__(self, index: int, warnet):
# index of integers imported from graph file
# indicating which tanks to initially connect to
self.init_peers = []
self.fork_observer = False

def _parse_version(self, version):
if not version:
Expand Down Expand Up @@ -96,6 +96,9 @@ def parse_graph_node(self, node):
}
self.lnnode = LNNode(self.warnet, self, self.warnet.container_interface, options)

if self.fork_observer:
self.bitcoin_config += " -rest"

logger.debug(
f"Parsed graph node: {self.index} with attributes: {[f'{key}={value}' for key, value in graph_properties.items()]}"
)
Expand Down
25 changes: 13 additions & 12 deletions src/warnet/warnet.py
Original file line number Diff line number Diff line change
Expand Up @@ -181,18 +181,19 @@ def write_fork_observer_config(self):
shutil.copy(TEMPLATES / FO_CONF_NAME, self.fork_observer_config)
with open(self.fork_observer_config, "a") as f:
for tank in self.tanks:
f.write(
f"""
[[networks.nodes]]
id = {tank.index}
name = "Node {tank.index}"
description = "Warnet tank {tank.index}"
rpc_host = "{tank.ipv4}"
rpc_port = {tank.rpc_port}
rpc_user = "{tank.rpc_user}"
rpc_password = "{tank.rpc_password}"
"""
)
if tank.fork_observer:
f.write(
f"""
[[networks.nodes]]
id = {tank.index}
name = "Node {tank.index}"
description = "Warnet tank {tank.index}"
rpc_host = "{tank.ipv4}"
rpc_port = {tank.rpc_port}
rpc_user = "{tank.rpc_user}"
rpc_password = "{tank.rpc_password}"
"""
)
logger.info(f"Wrote file: {self.fork_observer_config}")

def export(self, subdir):
Expand Down

0 comments on commit 571774f

Please sign in to comment.