Skip to content

Commit

Permalink
add delay and stop options to wallets
Browse files Browse the repository at this point in the history
  • Loading branch information
dufkan committed Aug 18, 2024
1 parent 0deaea8 commit 271fd0a
Show file tree
Hide file tree
Showing 6 changed files with 45 additions and 23 deletions.
11 changes: 7 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -32,8 +32,8 @@ Scenario definition files can be passed to the simulation script using the `--sc
},
"wallets": [
{"funds": [200000, 50000]},
{"funds": [3000000], "skip_rounds": [0, 1, 2, 3, 4]},
{"funds": [1000000, 50000], "skip_rounds": [3, 5, 6]},
{"funds": [3000000], "delay_rounds": 5},
{"funds": [1000000, 50000], "delay_rounds": 3},
{"funds": [100000, {"value": 200000, "delay_rounds": 5}]},
{"funds": [200000], "version": "2.0.3"},
{"funds": [4000000], "anon_score_target": "25"},
Expand All @@ -55,9 +55,12 @@ The fields are as follows:
- `wallets` field is a list of wallet configurations. Each wallet configuration is a dictionary with the following fields:
- `funds` is a list of funds (`int`s or `dict`s) the wallet will use for coinjoins. In case of a dictionary, the following keys are supported:
- `value` is the amount of funds the wallet will use for coinjoins.
- `delay_rounds` is the number of coinjoin rounds the distributor will wait before sending the corresponding funds to the wallet.
- `delay_blocks` is the number of blocks the distributor will wait before sending the corresponding funds to the wallet.
- `skip_rounds` is a list of coinjoin rounds during which a wallet should not participate.
- `delay_rounds` is the number of coinjoin rounds the distributor will wait before sending the corresponding funds to the wallet.
- `delay_blocks` is the number of blocks the wallet will wait before participating.
- `delay_rounds` is the number of coinjoin rounds the wallet will wait before participating.
- `stop_blocks` is the number of blocks after which the wallet will stop participating.
- `stop_rounds` is the number of rounds after which the wallet will stop participating.
- `version` is the string representation of wallet wasabi version used for client running this wallet.
- `anon_score_target` is the target anon score of the wallet.
- `redcoin_isolation` is a boolean value indicating whether the wallet should use redcoin isolation.
Expand Down
36 changes: 25 additions & 11 deletions manager.py
Original file line number Diff line number Diff line change
Expand Up @@ -157,7 +157,8 @@ def start_infrastructure():
wasabi_client_distributor_ip if args.proxy else args.control_ip,
port=37128 if args.proxy else wasabi_client_distributor_ports[37128],
name="wasabi-client-distributor",
skip_rounds=[],
delay=(0, 0),
stop=(0, 0),
)
if not distributor.wait_wallet(timeout=60):
print(f"- could not start distributor (application timeout)")
Expand All @@ -177,14 +178,15 @@ def fund_distributor(btc_amount):
print(f"- funded (current balance {balance / BTC:.8f} BTC)")


def init_wasabi_client(version, ip, port, name, skip_rounds):
def init_wasabi_client(version, ip, port, name, delay, stop):
return WasabiClient(version)(
host=ip,
port=port,
name=name,
proxy=args.proxy,
version=version,
skip_rounds=skip_rounds,
delay=delay,
stop=stop,
)


Expand Down Expand Up @@ -238,12 +240,15 @@ def start_client(idx, wallet):
print(f"- could not start {name} ({e})")
return None

delay = (wallet.get("delay_blocks", 0), wallet.get("delay_rounds", 0))
stop = (wallet.get("stop_blocks", 0), wallet.get("stop_rounds", 0))
client = init_wasabi_client(
version,
ip if args.proxy else args.control_ip,
37128 if args.proxy else manager_ports[37128],
f"wasabi-client-{idx:03}",
wallet.get("skip_rounds", list()),
delay,
stop,
)

start = time()
Expand Down Expand Up @@ -362,13 +367,22 @@ def stop_coinjoin(client):

def update_coinjoins():
def start_condition(client):
return current_round not in client.skip_rounds

def stop_condition(client):
return current_round in client.skip_rounds

start = list(filter(start_condition, clients))
stop = list(filter(stop_condition, clients))
if client.stop[0] > 0 and current_block >= client.stop[0]:
return False
if client.stop[1] > 0 and current_round >= client.stop[1]:
return False
if current_block < client.delay[0]:
return False
if current_round < client.delay[1]:
return False
return True

start, stop = [], []
for client in clients:
if start_condition(client):
start.append(client)
else:
stop.append(client)

with multiprocessing.pool.ThreadPool() as pool:
pool.starmap(start_coinjoin, ((client,) for client in start))
Expand Down
6 changes: 4 additions & 2 deletions manager/wasabi_clients/wasabi_client_base.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,14 +14,16 @@ def __init__(
name="wasabi-client",
proxy="",
version="2.0.4",
skip_rounds=[],
delay=(0, 0),
stop=(0, 0),
):
self.host = host
self.port = port
self.name = name
self.proxy = proxy
self.version = version
self.skip_rounds = skip_rounds or list()
self.delay = delay
self.stop = stop

def _rpc(self, request, wallet=True, timeout=5, repeat=1):
request["jsonrpc"] = "2.0"
Expand Down
5 changes: 3 additions & 2 deletions manager/wasabi_clients/wasabi_client_v1.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,10 @@ def __init__(
name="wasabi-client",
proxy="",
version="1.1.12.9",
skip_rounds=[],
delay=(0, 0),
stop=(0, 0),
):
super().__init__(host, port, name, proxy, version, skip_rounds)
super().__init__(host, port, name, proxy, version, delay, stop)

def select(self, timeout=5, repeat=10):
request = {"method": "selectwallet", "params": [WALLET_NAME]}
Expand Down
5 changes: 3 additions & 2 deletions manager/wasabi_clients/wasabi_client_v2.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,10 @@ def __init__(
name="wasabi-client",
proxy="",
version="2.0.3",
skip_rounds=[],
delay=(0, 0),
stop=(0, 0),
):
super().__init__(host, port, name, proxy, version, skip_rounds)
super().__init__(host, port, name, proxy, version, delay, stop)

def select(self, timeout=5, repeat=10):
request = {"method": "selectwallet", "params": [WALLET_NAME]}
Expand Down
5 changes: 3 additions & 2 deletions manager/wasabi_clients/wasabi_client_v204.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ def __init__(
name="wasabi-client",
proxy="",
version="2.0.4",
skip_rounds=[],
delay=(0, 0),
stop=(0, 0),
):
super().__init__(host, port, name, proxy, version, skip_rounds)
super().__init__(host, port, name, proxy, version, delay, stop)

0 comments on commit 271fd0a

Please sign in to comment.