Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Codebase refresh #6

Open
wants to merge 19 commits into
base: master
Choose a base branch
from

Conversation

Aareon
Copy link

@Aareon Aareon commented Mar 28, 2024

Resubmitting PR without formatting/linting changes. Only functional changes are present in this request. Please pull, test, run checks, and review before merging.

from os import path
from pprint import pprint
from sys import exc_info

from bismuthcore.helpers import BismuthBase
from bismuthcore.bismuthcore.helpers import BismuthBase
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The top level bismuthcore dir of the repo is an extra dir, not part of the library.
So there is no bismuthcore.bismuthcore in the module and this fix, as other similar imports in other files, adding an extraneous bismuthcore, would break anything requiring bismuthcore.
The pypi config therefore may be wrong as well.
If an IDE suggested that, then its config or lib paths are wrong.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Something is odd with the setup.py, the only suggestion I received from my IDE was that imports could not resolve. Pytest confirmed that fact. I'll address in setup.py.

@@ -87,11 +87,11 @@ def create(db, sql: tuple):

try:
remove('ledger_new.db')
except:
except Exception:
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I do agree a bare "except" is not PEP, but be aware "except Exception" does not catch the same things as except alone. "except BaseException" would catch the same events.
Deciding which except should catch a KeyboardInterrupt or not may be non trivial.
In doubt, I would not change the current working, therefore use BaseException if really the bare except is too hard for some eyes.
A proper exception handling should anyway detail the possible exceptions more in depth, and would bloat the codebase quite a bit so I would not advise it.

Copy link
Author

@Aareon Aareon Mar 29, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Perhaps throwing in BaseException for catching system-exiting exceptions, above the except Exception should address this concern without bloating the codebase too much.

except:
pass
except Exception as e:
print("Unknown error occurred during wallet preview. Error: {}".format(e))
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What is the rationale for prints instead of the self.app_log used everywhere?

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

self.app_log is not an available attribute. Also, I intended to ignore legacy/, but failed to ignore it when I did a search for except: across the codebase. I may look into removing these commits in legacy/ in order to avoid confusion.

except:
pass
except Exception as e:
self.app_log.debug(f"Connection to {pair[0]} {pair[1]} failed: {e}")
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The "pair" info is already logged with info level just above.
So in case of an exception, the short "not connectable" (typo in codebase) message is supposed to refer to the "connection" line just above.
I'm not sure there's a need to duplicate the info.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You're are correct. Will look into removing changes in legacy/

@@ -451,9 +453,9 @@ def consensus_remove(self, peer_ip):
self.app_log.info(f"Consensus opinion list: {self.peer_opinion_dict}")
self.app_log.info(f"Will remove {peer_ip} from consensus pool {self.peer_opinion_dict}")
self.peer_opinion_dict.pop(peer_ip)
except:
except Exception as e:
self.debug(f"Error removing {peer_ip} from consensus pool: {e}")
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

dup log (plus typo likely, self.debug instead of self.app_log.debug)

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

See comments regarding legacy/

tries, timeout = self.tried[host_port] # noqa: F841
except Exception as e:
# unknown host for now, never tried.
self.app_log.debug(f"Error getting tries for {host_port}: {e}")
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is not an error, this is the normal working for an host we don't know yet.
This is ok and should not generate a log.

The pythonic way would be a use a defaultDict with (0,0) or .get(host_port, (0,0)) and get rid of the try /except alltogether.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

See comments regarding legacy/

@@ -54,7 +54,7 @@ def _send(self, data, slen=SLEN, retry=True):
self.sdef.settimeout(LTIMEOUT)
# Make sure the packet is sent in one call
sdata = str(json.dumps(data))
res = self.sdef.sendall(str(len(sdata)).encode("utf-8").zfill(slen)+sdata.encode("utf-8"))
_ = self.sdef.sendall(str(len(sdata)).encode("utf-8").zfill(slen)+sdata.encode("utf-8"))
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I would even remove the _ = for better readability, or check res for added safety, make sure all was indeed sent.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Definitely a check would be optimal. A few improvements could be made to this line altogether.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants