From 887d44be446fe8bae3d43e439319cb7fdce05335 Mon Sep 17 00:00:00 2001 From: fusion44 Date: Sat, 4 Jun 2022 14:46:03 +0200 Subject: [PATCH] chores: remove unused health messages; Fix typos closes remove confusing "health" message in system_info #95 --- app/main.py | 6 +-- app/models/bitcoind.py | 4 +- app/models/system.py | 54 ------------------- app/repositories/apps.py | 6 +-- app/repositories/bitcoin.py | 2 +- app/repositories/lightning.py | 8 +-- app/repositories/ln_impl/cln_grpc.py | 10 ++-- app/repositories/ln_impl/cln_unix_socket.py | 4 +- app/repositories/ln_impl/lnd_grpc.py | 8 +-- app/repositories/system.py | 8 +-- app/repositories/system_impl/native_python.py | 15 +----- app/repositories/system_impl/raspiblitz.py | 15 +----- app/routers/lightning.py | 4 +- app/routers/setup.py | 12 ++--- app/routers/system.py | 2 +- app/utils.py | 2 +- 16 files changed, 41 insertions(+), 119 deletions(-) diff --git a/app/main.py b/app/main.py index 6710dd5..cef5785 100644 --- a/app/main.py +++ b/app/main.py @@ -177,13 +177,13 @@ register_handlers_finished = False async def check_defer_register_handlers(): """ Special case for RaspiBlitz: Depending on the current setup step - there still isn't a Bitcoin Deamon or Lightning Node running. + there still isn't a Bitcoin Daemon or Lightning Node running. We must defer the registration of all those handlers until later when everything is properly setup. Since there is a final reboot after the setup there is no need to check in the background whether setup is finished. The API server - is restartet anyway. + is restarted anyway. """ platform = APIPlatform.get_current() @@ -198,7 +198,7 @@ async def check_defer_register_handlers(): await register_all_handlers(redis_plugin.redis) else: logging.warning( - f"Setup not finished. Defering handler startup. Current phase: '{setup_phase}'" + f"Setup not finished. Deferring handler startup. Current phase: '{setup_phase}'" ) diff --git a/app/models/bitcoind.py b/app/models/bitcoind.py index 3486f0d..accde55 100644 --- a/app/models/bitcoind.py +++ b/app/models/bitcoind.py @@ -22,7 +22,9 @@ class BlockRpcFunc(str, Enum): elif func == "rawblock": return cls.RAWBLOCK else: - raise ArgumentError("Function name must either be 'hasblock' or 'rawblock'") + raise ArgumentError( + "Function name must either be 'hashblock' or 'rawblock'" + ) class BtcNetwork(BaseModel): diff --git a/app/models/system.py b/app/models/system.py index 6e5d420..9134fbe 100644 --- a/app/models/system.py +++ b/app/models/system.py @@ -17,54 +17,6 @@ class LoginInput(BaseModel): ] = None -class HealthMessagePriority(str, Enum): - INFO = "info" # FYI, can normally be ignored. - WARNING = ( - "warning" # Potential problem might occur, user interaction possibly required. - ) - ERROR = "error" # Something bad happened. User interaction deinitely required. - - -class HealthMessage(BaseModel): - id: int = Query( - None, - description="""ID of the message. -Idea behind the ID is that messages can be replacable on the client. -To prevent spamming the user with multiple messages, message with ID 25 will be replaced with never data of ID 25 - """, - example=""" -```{ - id: 25, - level: "warning", - message: "HDD is 89.3% full" -}``` - """, - ) - - level: HealthMessagePriority = Query( - HealthMessagePriority.INFO, - description="""Priority level of the message. For more info see `message`. - -`INFO`: FYI, can normally be ignored.\n -`WARNING`: Potential problem might occur, user interaction possibly required.\n -`ERROR`: Something bad happened. User interaction definitely required. - -If there are multiple messages with different priorities, the most severe level will be shown. - """, - ) - message: str = Query(..., description="Detailed message description") - - -class HealthState(str, Enum): - # All systems work nominally - GOOD = "good" - # Some event requires users attention (Software update, HDD nearly full) - ATTENTION_REQUIRED = "attention_required" - # An error happened which prevents the node from working properly - # (Hardware failure, DB corruption, Internet connection not available, ...) - STOPPED = "stopped" - - class APIPlatform(str, Enum): RASPIBLITZ = "raspiblitz" NATIVE_PYTHON = "native_python" @@ -97,12 +49,6 @@ class SystemInfo(BaseModel): api_version: str = Query( ..., description="Version of the API software on this system." ) - health: HealthState = Query( - ..., description="General health state of the Raspiblitz" - ) - health_messages: List[HealthMessage] = Query( - [], description="List of all messages regarding node health." - ) tor_web_ui: str = Query("", description="WebUI TOR address") tor_api: str = Query("", description="API TOR address") lan_web_ui: str = Query("", description="WebUI LAN address") diff --git a/app/repositories/apps.py b/app/repositories/apps.py index 400b2ed..e7d500d 100644 --- a/app/repositories/apps.py +++ b/app/repositories/apps.py @@ -114,7 +114,7 @@ async def get_app_status_sub(): while True: status = "online" if switch else "offline" app_list = [ - # Specter is deactivated for now because it uses its own selfsigned HTTPS cert that makes trouble in chome on last test + # Specter is deactivated for now because it uses its own self signed HTTPS cert that makes trouble in Chrome on last test # also see: app/constants.py where specter is deactivated # {"id": "specter", "name": "Specter Desktop", "status": status}, {"id": "sphinx", "name": "Sphinx Chat", "status": status}, @@ -168,7 +168,7 @@ async def uninstall_app_sub(app_id: str, delete_data: bool): async def run_bonus_script(app_id: str, params: str): - # to satisfy CodeQL: test again against pedefined array and dont use 'user value' + # to satisfy CodeQL: test again against predefined array and don't use 'user value' tested_app_id = "" for id in available_app_ids: if id == app_id: @@ -201,7 +201,7 @@ async def run_bonus_script(app_id: str, params: str): logFileName = f"/var/cache/raspiblitz/temp/install.{app_id}.log" logging.info(f"WRITING LONG FILE: {logFileName}") with open(logFileName, "w", encoding="utf-8") as f: - f.write(f"API triggred script: {cmd}\n") + f.write(f"API triggered script: {cmd}\n") f.write(f"###### STDOUT #######\n") if stdout: f.write(stdout.decode()) diff --git a/app/repositories/bitcoin.py b/app/repositories/bitcoin.py index 882540b..cc73562 100644 --- a/app/repositories/bitcoin.py +++ b/app/repositories/bitcoin.py @@ -46,7 +46,7 @@ async def estimate_fee( status.HTTP_500_INTERNAL_SERVER_ERROR, detail=errors[0 : len(errors) - 1] ) - # returned in BTC by Bitcoincoin Core => convert to msat + # returned in BTC by Bitcoin Core => convert to msat rate_btc = result["result"]["feerate"] return rate_btc * 100000000 diff --git a/app/repositories/lightning.py b/app/repositories/lightning.py index 6b2e763..e11a3ea 100644 --- a/app/repositories/lightning.py +++ b/app/repositories/lightning.py @@ -57,9 +57,9 @@ async def get_wallet_balance(): async def list_all_tx( - successfull_only: bool, index_offset: int, max_tx: int, reversed: bool + successful_only: bool, index_offset: int, max_tx: int, reversed: bool ) -> List[GenericTx]: - return await ln.list_all_tx_impl(successfull_only, index_offset, max_tx, reversed) + return await ln.list_all_tx_impl(successful_only, index_offset, max_tx, reversed) async def list_invoices( @@ -189,10 +189,10 @@ async def register_lightning_listener(): """ Unable to connect to LND. Possible reasons: * Node is not reachable (ports, network down, ...) -* Maccaroon is not correct +* Macaroon is not correct * IP is not included in LND tls certificate Add tlsextraip=192.168.1.xxx to lnd.conf and restart LND. - This will recreate the TLS certificate. The .env must be adpted accordingly. + This will recreate the TLS certificate. The .env must be adapted accordingly. * TLS certificate is wrong. (settings changed, ...) To Debug gRPC problems uncomment the following line in app.utils.LightningConfig._init(): diff --git a/app/repositories/ln_impl/cln_grpc.py b/app/repositories/ln_impl/cln_grpc.py index 18d1bd2..0b0383f 100644 --- a/app/repositories/ln_impl/cln_grpc.py +++ b/app/repositories/ln_impl/cln_grpc.py @@ -121,7 +121,7 @@ memo_cache = {} async def list_all_tx_impl( - successfull_only: bool, index_offset: int, max_tx: int, reversed: bool + successful_only: bool, index_offset: int, max_tx: int, reversed: bool ) -> List[GenericTx]: list_invoice_req = ln.ListinvoicesRequest() list_payments_req = ln.ListpaysRequest() @@ -138,14 +138,14 @@ async def list_all_tx_impl( tx = [] for invoice in res[0].invoices: i = GenericTx.from_cln_grpc_invoice(invoice) - if successfull_only and i.status == TxStatus.SUCCEEDED: + if successful_only and i.status == TxStatus.SUCCEEDED: tx.append(i) continue tx.append(i) for transaction in res[1]: t = GenericTx.from_cln_grpc_onchain_tx(transaction, res[3].block_height) - if successfull_only and t.status == TxStatus.SUCCEEDED: + if successful_only and t.status == TxStatus.SUCCEEDED: tx.append(t) continue @@ -162,7 +162,7 @@ async def list_all_tx_impl( memo_cache[pay.bolt11] = pr.description p = GenericTx.from_cln_grpc_payment(pay, comment) - if successfull_only and p.status == TxStatus.SUCCEEDED: + if successful_only and p.status == TxStatus.SUCCEEDED: tx.append(p) continue @@ -511,7 +511,7 @@ async def listen_forward_events() -> ForwardSuccessEvent: interval = config("gather_ln_info_interval", default=2, cast=float) - # make sure we know how many forewards we have + # make sure we know how many forwards we have # we need to calculate the difference between each iteration # status=1 == "settled" req = ln.ListforwardsRequest(status=1) diff --git a/app/repositories/ln_impl/cln_unix_socket.py b/app/repositories/ln_impl/cln_unix_socket.py index 935c033..448a694 100644 --- a/app/repositories/ln_impl/cln_unix_socket.py +++ b/app/repositories/ln_impl/cln_unix_socket.py @@ -140,7 +140,7 @@ def _get_block_time(block_height: int) -> tuple: async def list_all_tx_impl( - successfull_only: bool, index_offset: int, max_tx: int, reversed: bool + successful_only: bool, index_offset: int, max_tx: int, reversed: bool ) -> List[GenericTx]: @force_async def _list_invoices(): @@ -420,7 +420,7 @@ async def listen_forward_events() -> ForwardSuccessEvent: # repository. interval - 0.1 - # make sure we know how many forewards we have + # make sure we know how many forwards we have # we need to calculate the difference between each iteration res = lncfg.cln_sock.listforwards(status="settled") num_fwd_last_poll = len(res["forwards"]) diff --git a/app/repositories/ln_impl/lnd_grpc.py b/app/repositories/ln_impl/lnd_grpc.py index 3288733..2141481 100644 --- a/app/repositories/ln_impl/lnd_grpc.py +++ b/app/repositories/ln_impl/lnd_grpc.py @@ -458,7 +458,7 @@ async def channel_open_impl( target_conf=target_confs, ) async for response in lncfg.lnd_stub.OpenChannel(r): - # TODO: this is still some bytestring that needs correct convertion to a string txid (ok OK for now) + # TODO: this is still some bytestring that needs correct conversion to a string txid (ok OK for now) return str(response.chan_pending.txid.hex()) except grpc.aio._call.AioRpcError as error: @@ -467,12 +467,12 @@ async def channel_open_impl( ) -async def peer_resolve_alias(nodepub: str) -> str: +async def peer_resolve_alias(node_pub: str) -> str: # get fresh list of peers and their aliases try: - request = ln.NodeInfoRequest(pub_key=nodepub, include_channels=False) + request = ln.NodeInfoRequest(pub_key=node_pub, include_channels=False) response = await lncfg.lnd_stub.GetNodeInfo(request) return str(response.node.alias) @@ -528,7 +528,7 @@ async def channel_close_impl(channel_id: int, force_close: bool) -> str: target_conf=6, ) async for response in lncfg.lnd_stub.CloseChannel(request): - # TODO: this is still some bytestring that needs correct convertion to a string txid (ok OK for now) + # TODO: this is still some bytestring that needs correct conversion to a string txid (ok OK for now) return str(response.close_pending.txid.hex()) except grpc.aio._call.AioRpcError as error: diff --git a/app/repositories/system.py b/app/repositories/system.py index 558909b..be3d347 100644 --- a/app/repositories/system.py +++ b/app/repositories/system.py @@ -70,7 +70,7 @@ async def password_change(type: str, old_password: str, new_password: str): if not type in ["a", "b", "c"]: raise HTTPException(status.HTTP_400_BAD_REQUEST, detail="unknown password type") - # check password formattings + # check password formatting if not password_valid(old_password): raise HTTPException( status.HTTP_400_BAD_REQUEST, detail="old password format invalid" @@ -93,13 +93,13 @@ async def password_change(type: str, old_password: str, new_password: str): ) # second set new password - scriptcall = ( + script_call = ( f'/home/admin/config.scripts/blitz.passwords.sh set {type} "{new_password}"' ) if type == "c": # will set password c of both lnd & core lightning if installed/activated - scriptcall = f'/home/admin/config.scripts/blitz.passwords.sh set c "{old_password}" "{new_password}"' - result = await call_script(scriptcall) + script_call = f'/home/admin/config.scripts/blitz.passwords.sh set c "{old_password}" "{new_password}"' + result = await call_script(script_call) data = parse_key_value_text(result) print(str(data)) if "error" in data.keys() and len(data["error"]) > 0: diff --git a/app/repositories/system_impl/native_python.py b/app/repositories/system_impl/native_python.py index 9a3fd20..dc8b148 100644 --- a/app/repositories/system_impl/native_python.py +++ b/app/repositories/system_impl/native_python.py @@ -3,14 +3,7 @@ import logging from decouple import config from app.constants import API_VERSION -from app.models.system import ( - APIPlatform, - ConnectionInfo, - HealthMessage, - HealthMessagePriority, - HealthState, - SystemInfo, -) +from app.models.system import APIPlatform, ConnectionInfo, SystemInfo from app.repositories.lightning import get_ln_info @@ -33,12 +26,6 @@ async def get_system_info_impl() -> SystemInfo: platform=APIPlatform.NATIVE_PYTHON, platform_version=version, api_version=API_VERSION, - health=HealthState.ATTENTION_REQUIRED, - health_messages=[ - HealthMessage( - id=25, level=HealthMessagePriority.WARNING, message="HDD 85% full" - ) - ], tor_web_ui=tor_api_docs, tor_api=tor_api, lan_web_ui=lan_api_docs, diff --git a/app/repositories/system_impl/raspiblitz.py b/app/repositories/system_impl/raspiblitz.py index 4d24213..b01ef29 100644 --- a/app/repositories/system_impl/raspiblitz.py +++ b/app/repositories/system_impl/raspiblitz.py @@ -5,14 +5,7 @@ import os from decouple import config from app.constants import API_VERSION -from app.models.system import ( - APIPlatform, - ConnectionInfo, - HealthMessage, - HealthMessagePriority, - HealthState, - SystemInfo, -) +from app.models.system import APIPlatform, ConnectionInfo, SystemInfo from app.repositories.lightning import get_ln_info from app.utils import ( SSE, @@ -36,12 +29,6 @@ async def get_system_info_impl() -> SystemInfo: platform=APIPlatform.RASPIBLITZ, platform_version=await redis_get("raspiBlitzVersion"), api_version=API_VERSION, - health=HealthState.ATTENTION_REQUIRED, - health_messages=[ - HealthMessage( - id=25, level=HealthMessagePriority.WARNING, message="HDD 85% full" - ) - ], tor_web_ui=tor, tor_api=f"{tor}/api", lan_web_ui=f"http://{lan}/", diff --git a/app/routers/lightning.py b/app/routers/lightning.py index f8b2f2e..b72e2f2 100644 --- a/app/routers/lightning.py +++ b/app/routers/lightning.py @@ -129,7 +129,7 @@ async def get_fee_revenue_path() -> FeeRevenue: responses=responses, ) async def list_all_tx_path( - successfull_only: bool = Query( + successful_only: bool = Query( False, description="If set, only successful transaction will be returned in the response.", ), @@ -147,7 +147,7 @@ async def list_all_tx_path( ), ): try: - return await list_all_tx(successfull_only, index_offset, max_tx, reversed) + return await list_all_tx(successful_only, index_offset, max_tx, reversed) except HTTPException as r: raise except NotImplementedError as r: diff --git a/app/routers/setup.py b/app/routers/setup.py index d979aa1..c0d1bb1 100644 --- a/app/routers/setup.py +++ b/app/routers/setup.py @@ -218,7 +218,7 @@ async def setup_start_done(data: StartDoneData): # hostname=[string] # passwordA=[string] # passwordB=[string] - # passwordC=[string] (might be empty of no lightning was choosen) + # passwordC=[string] (might be empty of no lightning was chosen) # lndrescue=[path] (might be used later if lnd rescue file upload is offered) # clrescue=[path] (might be used later if c-lightning rescue file upload is offered) # seedWords= (might be used later if we offer recover from seed words) @@ -249,10 +249,10 @@ async def setup_final_info(): ) return HTTPException(status.HTTP_405_METHOD_NOT_ALLOWED) - resultlines = [] - with open(setupFilePath, "r") as setupfile: - resultlines = setupfile.readlines() - data = parse_key_value_lines(resultlines) + result_lines = [] + with open(setupFilePath, "r") as setup_file: + result_lines = setup_file.readlines() + data = parse_key_value_lines(result_lines) try: seedwordsNEW = data["seedwordsNEW"] except: @@ -283,7 +283,7 @@ async def get_shutdown(): setupPhase = await redis_get("setupPhase") state = await redis_get("state") if setupPhase == "done": - logging.warning(f"can only be called when node is not setuped yet") + logging.warning(f"can only be called when the nodes is not finalized yet") return HTTPException(status.status.HTTP_405_METHOD_NOT_ALLOWED) if state != "waitsetup": logging.warning(f"can only be called when nodes awaits setup") diff --git a/app/routers/system.py b/app/routers/system.py index 5286e52..646f353 100644 --- a/app/routers/system.py +++ b/app/routers/system.py @@ -122,7 +122,7 @@ async def hw_info() -> map: @router.get( "/connection-info", name=f"{_PREFIX}.connection-info", - summary="Get credential information to connect externbal apps.", + summary="Get credential information to connect external apps.", response_description="Returns a JSON string with credential information.", response_model=ConnectionInfo, dependencies=[Depends(JWTBearer())], diff --git a/app/utils.py b/app/utils.py index 760b5ea..02c23a0 100644 --- a/app/utils.py +++ b/app/utils.py @@ -279,7 +279,7 @@ class _PushID(object): def __init__(self): # Timestamp of last push, used to prevent local collisions if you - # pushtwice in one ms. + # push twice in one ms. self.last_push_time = 0 # We generate 72-bits of randomness which get turned into 12