Skip to content

Commit 8cf8661

Browse files
committed
Minor fix for worker config and secondary script switching.
1 parent dba65aa commit 8cf8661

File tree

3 files changed

+39
-27
lines changed

3 files changed

+39
-27
lines changed

bin/config.json

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
{
22
"address": "0x1Bc3a15dfFa205AA24F6386D959334ac1BF27336",
3-
"local": "false",
4-
"trusted": "false",
5-
"mining": "false",
6-
"mining-script": "path/to/mining.executable",
3+
"local": false,
4+
"trusted": false,
5+
"mining": false,
6+
"mining-script": "path/to/mining.executable"
77
}

bin/run_worker.py

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -57,8 +57,19 @@ def start_mining(mining_script, use_sudo=False):
5757
"""
5858
Start the mining process using the specified script.
5959
"""
60-
command = f"sudo {mining_script}" if use_sudo else mining_script
61-
return subprocess.Popen(command, shell=True)
60+
# Convert to absolute path relative to current working directory
61+
if not os.path.isabs(mining_script):
62+
mining_script = os.path.abspath(mining_script)
63+
64+
# Verify script exists
65+
if not os.path.exists(mining_script):
66+
raise FileNotFoundError(f"Mining script not found: {mining_script}")
67+
68+
if use_sudo:
69+
# Use list form for better security
70+
return subprocess.Popen(["sudo", mining_script])
71+
else:
72+
return subprocess.Popen([mining_script])
6273

6374

6475
def stop_mining(mining_process):

tensorlink/nodes/worker.py

Lines changed: 22 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -71,27 +71,28 @@ def __init__(
7171

7272
self.dht.store(hashlib.sha256(b"ADDRESS").hexdigest(), self.public_key)
7373

74-
# if self.local_test is False:
75-
# attempts = 0
76-
#
77-
# self.debug_print("Bootstrapping...", tag="Worker")
78-
# while attempts < 3 and len(self.validators) == 0:
79-
# self.bootstrap()
80-
# if len(self.validators) == 0:
81-
# time.sleep(15)
82-
# self.debug_print(
83-
# "No validators found, trying again...", tag="Worker"
84-
# )
85-
# attempts += 1
86-
#
87-
# if len(self.validators) == 0:
88-
# self.debug_print(
89-
# "No validators found, shutting down...",
90-
# level=logging.CRITICAL,
91-
# tag="Worker",
92-
# )
93-
# self.stop()
94-
# self.terminate_flag.set()
74+
if not self.local_test and not self.off_chain_test:
75+
attempts = 0
76+
77+
self.debug_print("Bootstrapping...", tag="Worker")
78+
while attempts < 3 and len(self.validators) == 0:
79+
self.bootstrap()
80+
if len(self.validators) == 0:
81+
time.sleep(15)
82+
self.debug_print(
83+
"No validators found, trying again...", tag="Worker"
84+
)
85+
attempts += 1
86+
87+
if len(self.validators) == 0:
88+
self.debug_print(
89+
"No validators found, shutting down...",
90+
level=logging.CRITICAL,
91+
tag="Worker",
92+
)
93+
self.stop()
94+
self.terminate_flag.set()
95+
9596
self.keeper.load_previous_state()
9697

9798
def handle_data(self, data: bytes, node: Connection):

0 commit comments

Comments
 (0)