-
Notifications
You must be signed in to change notification settings - Fork 364
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
Upgrade bech32 dependency (iterative) #3270
Conversation
9372141
to
b677ddb
Compare
Codecov ReportAttention: Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## main #3270 +/- ##
==========================================
- Coverage 89.68% 89.63% -0.05%
==========================================
Files 126 127 +1
Lines 103306 106126 +2820
Branches 103306 106126 +2820
==========================================
+ Hits 92651 95128 +2477
- Misses 7936 8287 +351
+ Partials 2719 2711 -8 ☔ View full report in Codecov by Sentry. |
8eb0c4b
to
1fa1e99
Compare
CI: A few misses in iterative-mutants on the |
55e4259
to
5fa337a
Compare
CI: All builds OK. Iterative mutants is satisfied now, but the build was interrupted (?) after the tests (verified the logs + locally). |
9abd92e
to
ca0e089
Compare
Added a minor cleanup: |
A note regarding bech32->bytes conversion with padding: I've raised an issue to I also realized padding can be done in an iterator adapter (counts the elements and and the end optionally outputs padding), so this padding can be applied nicely in the chained iterators approach (as discusses above). |
Awaiting (re)review, @TheBlueMatt . Thx. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is shaping up nicely. We took this opportunity to avoid allocations in the serialization pipeline (sadly with allocations to avoid GATs...) but there's also a ton of really useless allocations in the deserialization pipeline, some of which we can trivially remove. We certainly don't have to fix it all in one go, but it'd be nice to reduce them where its easy here.
In any case, please feel free to go ahead and rewrite the commit history to have a logical progression so its easy to review :)
440fd35
to
1a69ccc
Compare
Commits squashed |
1852781
to
89a6cec
Compare
We should get a second reviewer on this. |
89a6cec
to
7da1b51
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I cannot find any issues with the bech32 conversion in either direction.
Besides the nits I pointed out, I have two thoughts where other reviewers may disagree, bit I'll throw it out there: to_fes
(as in bytes_to_fes
looks like a misspelling of fees
, so given that names are free, I wonder if to_finite_elements
or to_fe_32s
might slightly simplify legibility for future readers.
On a similar note, SIGNATURE_LEN5
also looks like "signature lens." Perhaps an underscore or a base_5 or something might help?
But these thoughts aside, looks good!
btw, if you rebase, the linting CI error should go away |
7da1b51
to
3f4d5b7
Compare
Addressed minor nit's, rebased |
3f4d5b7
to
aa2f6b4
Compare
This naming is not the best... Firstly, I don't think the 'finite element' (of algebraic group) is a relevant property of this thing at all, for our purpose it's just a 5-bit value. I think simply To the |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for all the work here! Gonna go ahead and land this and we can reduce allocations more later.
type Err = Bolt11ParseError; | ||
|
||
fn from_base32(field_data: &[Fe32]) -> Result<Self, Self::Err> { | ||
if field_data.len() != 52 { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This check is redundant with the one in [u8; 32]::from_base32
, no?
let curr_in_as_u8 = curr_in.to_u8(); | ||
if carry_bits >= 3 { | ||
// we have a new full byte -- 3, 4 or 5 carry bits, plus 5 new ones | ||
// For combining with carry '|', '^', or '+' can be used (disjoint bit positions) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
nit: then prefer the bitop versions - means the CPU doesn't have to do any carries (not that it matters much - an 8 bit add should be one cycle basically all the time).
if hrp != Self::BECH32_HRP { | ||
let parsed = CheckedHrpstring::new::<NoChecksum>(encoded.as_ref())?; | ||
let hrp = parsed.hrp(); | ||
if hrp.to_string() != Self::BECH32_HRP { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
No need to allocate here.
if hrp.to_string() != Self::BECH32_HRP { | |
if hrp.as_str() != Self::BECH32_HRP { |
Continuation of #3244 . Fixes #3176 .
Changes summary:
bech32
dependency to0.11.0
(from0.9
)bech32::u5
can be replaced bybech32::Fe32
, mostly as a drop-in replacement.u5::try_from_u8
is nowFe32::try_from
bech32::Error
is mostly replaced bybech32::primitives::decode::CheckedHrpstringError
ToBase32
(andBase32Len
) traits are discontinued inbech32
, they have been reimplemented in iterative style asBase32Iterable
. The implementations (Bolt11InvoiceFeatures/Payment*/...) have been moved tolightning-invoice
crate (as the trait is defined there)FromBase32
trait is discontinued inbech32
, it has been taken over tolighning-invoice
crate. The implementations have been moved tolightning-invoice
crate (as the trait is defined there)Here are some minor issues identified
Fe32
does not haveOrd
, so it had to be explicitly implemented forRawTaggedField
Fe32
does not haveDefault
, for which some workaround was needed. This will be added in nextbech32 0.12
release (see Add Ord trait to Fe32 (derived) rust-bitcoin/rust-bech32#186)bech32
error types are not always optimalbech32
crate)TODO:
fuzz
target