-
Notifications
You must be signed in to change notification settings - Fork 51
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
Expand the amount of core-only #45
Conversation
This fails because of missing |
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 haven't looked at all changes yet, the general idea sounds good to me. Discussing the minimum version again would just make this more complicated, so I'd rather use the patch to make the PR 1.22 compatible.
If you set the minimum version of rust to 1.36 you can use the |
@reuvenpo I want to use this on embedded systems like hardware wallets where dynamic allocation is highly discouraged. Not using the alloc crate we very intentional. There is no reason we couldn't do both approaches and have an alloc feature, though. |
That's reasonable, if it were solved well this way we wouldn't mind using it in my own project :)
If it makes sense in the code, sure. My use case required just using bech32 in an environment that has alloc but not std, so i just whipped up #46 (which was the fastest way to achieve that) and we're using that for now. We won't push for this duality if it's a hassle, cause your solution would work well too. |
I adapted this in light of the existing |
Hi @Ericson2314, I just put up a PR that aims to do more or less the same thing as this one, I did it without going back through open PRs so I missed this one. I don't want to seem like I was ignoring this so pinging you now. If you want to pick this work up I can close mine since you were first. |
f2d8845
to
24d76fc
Compare
@tcharding no worries, I haven't touched this stuff in years. Mine does more things than yours, generalizing some interfaces, so why don't we just do yours first and then mine as follow-up? |
24d76fc
to
bdf7f70
Compare
@tcharding I rebased this on top as described, and polished it a bit more. |
bdf7f70
to
79cb499
Compare
Hey @Ericson2314, I'm not exactly sure what this PR is trying to achieve. "allow doing more things without alloc" doesn't give me quite enough context to evaluate the PR, I like the additional embedded test code but the base N stuff seems orthogonal, or am I missing something? Perhaps you could write a PR description justifying the proposed changes and if I'm correct in thinking the base N stuff is unrelated to the embedded test improvements perhaps split it out into a separate commit. Thanks |
To be honest I forget all the details, but see the tests I've enabled, and the new ones I've written. If your PR is merged first, it will be easier both for you all to read the code, and me to write the expanded description! |
Hey @Ericson2314, other PRs merged now so if you are still keen to work on this the path is clear. |
99ad259
to
be4af63
Compare
src/lib.rs
Outdated
/// Interface to write `u5`s into a sink | ||
pub trait WriteBase32 { | ||
/// Interface to write `u(2*n)`s into a sink | ||
pub trait WriteBaseN<T> |
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.
In be4af63:
I find this rename very confusing. It looks like it's generic over the number base, but the write
implementation still calls write_u5
... which now no longer has anything to do with u5s.
I think we should leave this trait alone and make WriteBase256
completely independent (and probably it does not need the single write_u5
method since Rust has decent first-class support for byteslices).
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.
Oops not renaming write_u5
was just an oversight.
I kept it one trait to I can have the polymorphic Vec
and ArrayVec
implementations, but I suppose I could just copy paste them for each trait/type pair.
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 would suggest copy/pasting because I think u8
serialization is "just dumping bytes" and u5
serialization as a nontrivial conversion, so they feel like distinct things to me even though the code is pretty-much the same.
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.
OK
a254de1
to
30028bf
Compare
Looks like we require |
cd68bae
to
5021694
Compare
That is done too. Should be all ready. |
Is the point of this PR to enable encoding a slice of An update to the PR description and title would be super helpful please - took me a while to work out what was going on. |
The arrayvec msrv looks like it's 1.51, which is not crazy far from our MSRV, and it's an optional dep which looks independent of the other alloc stuff. I think it'd be okay to say "if you enable this you con't use our MSRV". |
So, I'd be ready to ACK this PR, but I find @tcharding idea of replacing these I'm okay with keeping an optional |
embedded/no-allocator/Cargo.toml
Outdated
bech32 = { path = "../../", default_features = false } | ||
codegen-units = 1 # better optimizations | ||
debug = true # symbols are nice and they don't increase the size on Flash | ||
lto = true # better optimizations |
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.
Why are these needed? This is just a test, I expect the compilation time to be longer than the run time.
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 think I was just copying what the other test did (or used to do) to try to go with the flow.
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.
Maybe they are intended for benches? Those should have [profile.release]
above these settings.
src/lib.rs
Outdated
/// Like `std::io::Writer`, but because the associated type is no_std compatible. | ||
pub trait WriteBase256 { | ||
/// Write error | ||
type Err: fmt::Debug; |
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.
Most of the Rust ecosystem names associated error types Error
, the only exception being ancient FromStr
. So I'd prefer that name.
src/lib.rs
Outdated
} | ||
|
||
/// Write a single `u8` | ||
fn write_u8(&mut self, data: u8) -> Result<(), Self::Err> { self.write(&[data]) } |
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 infinite recursion by default, I think it's a foot-gun and this method should be required instead.
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 think it's fine, it's a pretty common idiom for a trait to have infinite recursion by default, so that you can implement either one of the methods. If you try to run it, it will crash immediately (actually, I think the compiler will even flag it).
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 still don't like it :D
But sure, if there is no better way...
Bech32Error(Error), | ||
/// Error from `arrayvec`. | ||
CapacityError(CapacityError), | ||
} |
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 think WriteError
would be a clearer name.
.iter() | ||
.map(|x| u5::try_from(*x).map(|_| ()).map_err(Error::TryFrom)) | ||
.find(|r| r.is_err()) | ||
.unwrap_or(Ok(())) |
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 looks like a really convoluted way of checking validity. Where is this needed?
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 think it's exactly as complex as you'd expect for a function that merely checks whether a string contains only valid bech32 characters.
But I agree, the utility of a function that checks this without actually doing the conversion seems unclear to me.
Would it be possible to merge this and then take a stab at the iterators approach? Would like to do it, but I am worried about finding the time for another "creative" investigation, vs the more tasks that are the other review items. I agree it does sound like a good idea. |
@Ericson2314 for sure, let's just merge this for now. I don't think we have a release of this crate coming up anytime soon, and this PR is blocking some other things. But could you first fix the following minor comments from Kix?:
Then later we can explore the iterator thing and revisit the |
No problem @apoelstra, happy to do all those things. Thank you for agreeing to defer the iterator exploration. |
5021694
to
4b0c640
Compare
I renamed Right now, |
Lol, CI is failing, something to do with LTO ..... maybe there was a reason for those flags. |
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.
ACK 4b0c640
4b0c640
to
42b3446
Compare
Yeah CI wasn't actually running the thing as I intended before the previous push. We'll see if I fixed it. Also added a new readme for both weird ARM tests. |
Yay OK the last commit did fix everything! |
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.
ACK 42b3446
Thanks for sticking with it man. |
This is super cool! I didn't know how to use qemu in CI before. We should use this to get a BE system to test rust-secp against. |
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.
ACK 42b3446
embedded/no-allocator/memory.x
Outdated
@@ -0,0 +1 @@ | |||
../with-allocator/memory.x |
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.
Sorry, we can't accept symlinks. Our merge script (which we borrow from Bitcoin Core) will not accept them, even if they point within the repo.
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.
OK I'll just copy the file then no problem.
Co-Authored-By: Sebastian <geisler.sebastian@googlemail.com>
42b3446
to
32c87da
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.
ACK 32c87da
Hooray! That time it was accepted. Thanks for your contribution @Ericson2314 and glad to have you poking at these projects! |
And thanks everyone too for helping me get this over the finish line! |
Nice one man, thank you. |
No description provided.