feat: Add better status check for internal nodes and error logging
All checks were successful
Tests and Linting / Tests-Linting (3.10) (push) Successful in 27s
Tests and Linting / Tests-Linting (3.11) (push) Successful in 28s
Tests and Linting / Tests-Linting (3.13) (push) Successful in 28s
Build Docker / Build Images (map[dockerfile:Dockerfile tag_suffix: target:default]) (push) Successful in 46s
Build Docker / Build Images (map[dockerfile:Dockerfile.hsd tag_suffix:-hsd target:hsd]) (push) Successful in 46s
All checks were successful
Tests and Linting / Tests-Linting (3.10) (push) Successful in 27s
Tests and Linting / Tests-Linting (3.11) (push) Successful in 28s
Tests and Linting / Tests-Linting (3.13) (push) Successful in 28s
Build Docker / Build Images (map[dockerfile:Dockerfile tag_suffix: target:default]) (push) Successful in 46s
Build Docker / Build Images (map[dockerfile:Dockerfile.hsd tag_suffix:-hsd target:hsd]) (push) Successful in 46s
This commit is contained in:
33
account.py
33
account.py
@@ -95,6 +95,7 @@ def hsdConnected():
|
||||
def hsdVersion(format=True):
|
||||
info = hsd.getInfo()
|
||||
if 'error' in info:
|
||||
logger.error(f"HSD connection error: {info.get('error', 'Unknown error')}")
|
||||
return -1
|
||||
|
||||
# Check if SPV mode is enabled
|
||||
@@ -121,6 +122,7 @@ def check_account(cookie: str | None):
|
||||
# Check if the account is valid
|
||||
info = hsw.getAccountInfo(account, 'default')
|
||||
if 'error' in info:
|
||||
logger.error(f"HSW error checking account {account}: {info.get('error', 'Unknown error')}")
|
||||
return False
|
||||
return account
|
||||
|
||||
@@ -583,6 +585,7 @@ def getTransactions(account, page=1, limit=100):
|
||||
return []
|
||||
info = hsw.getWalletTxHistory(account)
|
||||
if 'error' in info:
|
||||
logger.error(f"Error getting transactions for account {account}: {info['error']}")
|
||||
return []
|
||||
return info[::-1]
|
||||
|
||||
@@ -916,6 +919,7 @@ def register(account, domain):
|
||||
def getNodeSync():
|
||||
response = hsd.getInfo()
|
||||
if 'error' in response:
|
||||
logger.error(f"Error getting node sync status: {response['error']}")
|
||||
return 0
|
||||
|
||||
sync = response['chain']['progress']*100
|
||||
@@ -1941,13 +1945,17 @@ def hsdStart():
|
||||
cmd.append(flag)
|
||||
|
||||
# Launch process
|
||||
HSD_PROCESS = subprocess.Popen(
|
||||
cmd,
|
||||
cwd=os.getcwd(),
|
||||
text=True
|
||||
)
|
||||
try:
|
||||
HSD_PROCESS = subprocess.Popen(
|
||||
cmd,
|
||||
cwd=os.getcwd(),
|
||||
text=True
|
||||
)
|
||||
|
||||
logger.info(f"HSD started with PID {HSD_PROCESS.pid}")
|
||||
logger.info(f"HSD started with PID {HSD_PROCESS.pid}")
|
||||
except Exception as e:
|
||||
logger.error(f"Failed to start HSD: {str(e)}", exc_info=True)
|
||||
return
|
||||
|
||||
atexit.register(hsdStop)
|
||||
|
||||
@@ -1959,6 +1967,19 @@ def hsdStart():
|
||||
logger.error(f"Failed to set signal handlers: {str(e)}", exc_info=True)
|
||||
pass
|
||||
|
||||
def hsdRunning() -> bool:
|
||||
global HSD_PROCESS
|
||||
if not HSD_INTERNAL_NODE:
|
||||
return False
|
||||
if HSD_PROCESS is None:
|
||||
return False
|
||||
|
||||
# Check if process has terminated
|
||||
poll_result = HSD_PROCESS.poll()
|
||||
if poll_result is not None:
|
||||
logger.error(f"HSD process has terminated with exit code: {poll_result}")
|
||||
return False
|
||||
return True
|
||||
|
||||
def hsdStop():
|
||||
global HSD_PROCESS
|
||||
|
||||
33
main.py
33
main.py
@@ -1868,9 +1868,36 @@ def api_icon(account):
|
||||
def api_status():
|
||||
# This doesn't require a login
|
||||
# Check if the node is connected
|
||||
if not account_module.hsdConnected():
|
||||
return jsonify({"status":503,"error": "Node not connected"}), 503
|
||||
return jsonify({"status": 200,"result": "FireWallet is running"})
|
||||
node_status = {
|
||||
"connected": account_module.hsdConnected(),
|
||||
"internal": account_module.HSD_INTERNAL_NODE,
|
||||
"internal_running": False,
|
||||
"version": "N/A"
|
||||
}
|
||||
status = 200
|
||||
error = None
|
||||
node_status['version'] = account_module.hsdVersion(False) # type: ignore
|
||||
|
||||
if node_status['internal']:
|
||||
node_status['internal_running'] = account_module.hsdRunning()
|
||||
|
||||
# If the node is not connected, return an error
|
||||
if not node_status['connected']:
|
||||
error = "Node not connected"
|
||||
status = 503
|
||||
if node_status['version'] == -1:
|
||||
error = "Error connecting to HSD"
|
||||
status = 503
|
||||
if node_status['internal'] and not node_status['internal_running']:
|
||||
error = "Internal node not running"
|
||||
status = 503
|
||||
|
||||
|
||||
return jsonify({
|
||||
"node": node_status,
|
||||
"error": error,
|
||||
"status": status
|
||||
}), status
|
||||
|
||||
|
||||
#endregion
|
||||
|
||||
Reference in New Issue
Block a user