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

checksum module needs some love #610

Open
tcharding opened this issue Oct 10, 2023 · 1 comment
Open

checksum module needs some love #610

tcharding opened this issue Oct 10, 2023 · 1 comment

Comments

@tcharding
Copy link
Member

tcharding commented Oct 10, 2023

After working on #608 I noticed a few things:

  • We seem to be using fmt::Write::write_str with the implied suggestion that we avoid allocation of a string but I think that fmt::Argumenst::as_str() gets called and only avoids allocation for static strings (no uses of placeholders {}), since we always use {} I'm reasonably confident that this is allocating.
  • There are some optimisation possibilities by using iterator adapters instead of strings, ie take an iterarator of chars and yield the chars + # + the checksum.
  • The public API is a bit messy:
    • checksum::Formatter should not be public because it is not really a general purpose formatter, it is specifically for writing a descriptor to a formatter and overriding the use of alternate to control the addition of the checksum.
    • descriptor::checksum::desc_checksum could be better named as could descriptor::checksum::verify_checksum to use Rust naming convention (ie., users should be using a single path on functions so checksum::verify seems better, not sure about the other one.
  • Error handling could be improved if/when we start to do errors elsewhere

Related:

@apoelstra
Copy link
Member

Yeah, I agree with all these things. Confirmed that elements-miniscript is not using the checksum::Formatter type (it has its own).

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

No branches or pull requests

2 participants