Skip to content

Commit a693fe7

Browse files
committed
tank: handle bitcoin conf args in tank instead of backends
1 parent 4410200 commit a693fe7

File tree

5 files changed

+33
-70
lines changed

5 files changed

+33
-70
lines changed

src/backends/compose/compose_backend.py

+5-20
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,6 @@
1616
from warnet.status import RunningStatus
1717
from warnet.tank import Tank
1818
from warnet.utils import (
19-
default_bitcoin_conf_args,
2019
get_architecture,
2120
parse_raw_messages,
2221
)
@@ -340,24 +339,6 @@ def generate_deployment_file(self, warnet):
340339
dirs_exist_ok=True,
341340
)
342341

343-
def config_args(self, tank: Tank):
344-
args = self.default_config_args(tank)
345-
if tank.bitcoin_config is not None:
346-
args = f"{args} -{tank.bitcoin_config.replace(',', ' -')}"
347-
return args
348-
349-
def default_config_args(self, tank):
350-
defaults = default_bitcoin_conf_args()
351-
defaults += f" -rpcuser={tank.rpc_user}"
352-
defaults += f" -rpcpassword={tank.rpc_password}"
353-
defaults += f" -rpcport={tank.rpc_port}"
354-
defaults += f" -zmqpubrawblock=tcp://0.0.0.0:{tank.zmqblockport}"
355-
defaults += f" -zmqpubrawtx=tcp://0.0.0.0:{tank.zmqtxport}"
356-
# connect to initial peers as defined in graph file
357-
for dst_index in tank.init_peers:
358-
defaults += f" -addnode={self.get_container_name(dst_index, ServiceType.BITCOIN)}"
359-
return defaults
360-
361342
def add_services(self, tank: Tank, compose):
362343
services = compose["services"]
363344
assert tank.index is not None
@@ -385,13 +366,17 @@ def add_services(self, tank: Tank, compose):
385366
# Pre-built regular release
386367
image = f"{DOCKER_REGISTRY}:{tank.version}"
387368
services[container_name]["image"] = image
369+
370+
peers = [self.get_container_name(dst_index, ServiceType.BITCOIN) for dst_index in tank.init_peers]
371+
args = tank.get_bitcoin_conf(peers)
372+
388373
# Add common bitcoind service details
389374
services[container_name].update(
390375
{
391376
"container_name": container_name,
392377
# logging with json-file to support log shipping with promtail into loki
393378
"logging": {"driver": "json-file", "options": {"max-size": "10m"}},
394-
"environment": {"BITCOIN_ARGS": self.config_args(tank)},
379+
"environment": {"BITCOIN_ARGS": args},
395380
"networks": {
396381
tank.network_name: {
397382
"ipv4_address": f"{tank.ipv4}",

src/backends/kubernetes/kubernetes_backend.py

+3-15
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@
1717
from kubernetes.stream import stream
1818
from warnet.status import RunningStatus
1919
from warnet.tank import Tank
20-
from warnet.utils import default_bitcoin_conf_args, parse_raw_messages
20+
from warnet.utils import parse_raw_messages
2121

2222
DOCKER_REGISTRY_CORE = "bitcoindevproject/bitcoin"
2323
LOCAL_REGISTRY = "warnet/bitcoin-core"
@@ -313,18 +313,6 @@ def generate_deployment_file(self, warnet):
313313
"""
314314
pass
315315

316-
def default_bitcoind_config_args(self, tank):
317-
defaults = default_bitcoin_conf_args()
318-
defaults += f" -rpcuser={tank.rpc_user}"
319-
defaults += f" -rpcpassword={tank.rpc_password}"
320-
defaults += f" -rpcport={tank.rpc_port}"
321-
defaults += f" -zmqpubrawblock=tcp://0.0.0.0:{tank.zmqblockport}"
322-
defaults += f" -zmqpubrawtx=tcp://0.0.0.0:{tank.zmqtxport}"
323-
# connect to initial peers as defined in graph file
324-
for dst_index in tank.init_peers:
325-
defaults += f" -addnode={self.get_service_name(dst_index)}"
326-
return defaults
327-
328316
def create_bitcoind_container(self, tank: Tank) -> client.V1Container:
329317
self.log.debug(f"Creating bitcoind container for tank {tank.index}")
330318
container_name = BITCOIN_CONTAINER_NAME
@@ -356,8 +344,8 @@ def create_bitcoind_container(self, tank: Tank) -> client.V1Container:
356344
else:
357345
container_image = f"{DOCKER_REGISTRY_CORE}:{tank.version}"
358346

359-
bitcoind_options = self.default_bitcoind_config_args(tank)
360-
bitcoind_options += f" {tank.bitcoin_config}"
347+
peers = [self.get_service_name(dst_index) for dst_index in tank.init_peers]
348+
bitcoind_options = tank.get_bitcoin_conf(peers)
361349
container_env = [client.V1EnvVar(name="BITCOIN_ARGS", value=bitcoind_options)]
362350

363351
bitcoind_container = client.V1Container(

src/templates/bitcoin.conf

-17
This file was deleted.

src/warnet/tank.py

+25-1
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,19 @@
1919

2020
logger = logging.getLogger("tank")
2121

22+
CONFIG_BASE = " ".join([
23+
"-regtest=1",
24+
"-checkmempool=0",
25+
"-acceptnonstdtxn=1",
26+
"-debuglogfile=0",
27+
"-logips=1",
28+
"-logtimemicros=1",
29+
"-capturemessages=1",
30+
"-rpcallowip=0.0.0.0/0",
31+
"-rpcbind=0.0.0.0",
32+
"-fallbackfee=0.00001000",
33+
"-listen=1"
34+
])
2235

2336
class Tank:
2437
DEFAULT_BUILD_ARGS = "--disable-tests --with-incompatible-bdb --without-gui --disable-bench --disable-fuzz-binary --enable-suppress-external-warnings --enable-debug "
@@ -31,7 +44,6 @@ def __init__(self, index: int, warnet):
3144
self.version: str = ""
3245
self.image: str = ""
3346
self.bitcoin_config = ""
34-
self.conf_file = None
3547
self.netem = None
3648
self.exporter = False
3749
self.collect_logs = False
@@ -123,6 +135,18 @@ def status(self) -> RunningStatus:
123135
def exec(self, cmd: str):
124136
return self.warnet.container_interface.exec_run(self.index, ServiceType.BITCOIN, cmd=cmd)
125137

138+
def get_bitcoin_conf(self, nodes: list[str]) -> str:
139+
conf = CONFIG_BASE
140+
conf += f" -rpcuser={self.rpc_user}"
141+
conf += f" -rpcpassword={self.rpc_password}"
142+
conf += f" -rpcport={self.rpc_port}"
143+
conf += f" -zmqpubrawblock=tcp://0.0.0.0:{self.zmqblockport}"
144+
conf += f" -zmqpubrawtx=tcp://0.0.0.0:{self.zmqtxport}"
145+
conf += self.bitcoin_config
146+
for node in nodes:
147+
conf += f" -addnode={node}"
148+
return conf
149+
126150
def apply_network_conditions(self):
127151
if self.netem is None:
128152
return

src/warnet/utils.py

-17
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,6 @@
1515
import networkx as nx
1616
from jsonschema import validate
1717
from schema import SCHEMA
18-
from templates import TEMPLATES
1918
from test_framework.messages import ser_uint256
2019
from test_framework.p2p import MESSAGEMAP
2120

@@ -388,22 +387,6 @@ def set_execute_permission(file_path):
388387
os.chmod(file_path, current_permissions | stat.S_IXUSR | stat.S_IXGRP | stat.S_IXOTH)
389388

390389

391-
def default_bitcoin_conf_args() -> str:
392-
default_conf: Path = TEMPLATES / "bitcoin.conf"
393-
394-
with default_conf.open("r") as f:
395-
defaults = parse_bitcoin_conf(f.read())
396-
397-
conf_args = []
398-
399-
for kvs in defaults.values():
400-
# Skip section names, just focus on key-value pairs
401-
for key, value in kvs:
402-
conf_args.append(f"-{key}={value}")
403-
404-
return " ".join(conf_args)
405-
406-
407390
def create_cycle_graph(n: int, version: str, bitcoin_conf: str | None, random_version: bool):
408391
try:
409392
# Use nx.DiGraph() as base otherwise edges not always made in specific directions

0 commit comments

Comments
 (0)