-
Notifications
You must be signed in to change notification settings - Fork 38
Replace custom hex parsing with hex-conservative crate #259
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
Conversation
| /// Hex fixed parsing errors | ||
| HexFixedError(DecodeFixedLengthBytesError), | ||
| /// Hex variable parsing errors | ||
| HexVariableError(DecodeVariableLengthBytesError), |
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.
Not really sure if it's okay to keep both this way. We can alternatively keep only one variant as before HexError(), add hex::Error which is merge of DecodeFixedLengthBytesError and DecodeVariableLengthBytesError and add From implementations
| actual-serde = { package = "serde", version = "1.0.103", features = [ | ||
| "derive", | ||
| ], optional = true } | ||
| hex-conservative = "1.0.0" |
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.
Hi @Velnbur thanks for the PR, could you please regenerate the Cargo.lock file and include it as Cargo-latest.lock ?
|
Please run |
|
This is clearly a LLM and it's not even running the tests. Let's not waste our time on this. |
|
Fixed tests, missed a part that blinding factors have reverse order of bytes. And yeah, I forgot to run tests as in corner of my mind I relied on CI which is the real source of truth that checks different versions of Rust, and was expecting to receive a notification from it where I broke something (also the fact that you store binaries of Elements and Bitcoin nodes in repo is really confusing). So, totally my fault
What made you think so? I made this changes without any AI tools. Except commit messages, I use automation tools to write them, shouldn't be a sin nowadays . May be some words like "for more robust hexadecimal encoding/decoding" sound AI-ish, kind of understand that Also that's really mean that you just closed this PR without any time for me to response. I'm in different timezone, doing this in my free time and have relatively often electricity (and so network) shortages. |
I apologize -- and for what it's worth, I don't mind the use of AI tools or even majority-LLM-authored PRs. What's a problem is that Github is now full of unsupervised agents which open broken PRs and then respond to any comments or requests by closing their PR and moving on. It's extremely irksome to be scammed by a machine into doing pointless work. (There are some technical limitations keeping us on Github but I hope to abandon it entirely within the next year or two because of this.) For future reference -- what triggered me was mostly the "Overview" heading in your PR comment, which looks like LLM output (humans don't usually write PR descriptions in structured markdown), combined with the unit tests not passing (though humans do this all the time :P). |
|
It's fine, I understand the issue now. Thanks for feedback.
Seems that I've learned that from LLMs :) . Originally I planned to describe there alternative approaches how to handle different errors from Also, what we would do with this PR? Do I need to recreate it or you can do that? |
|
Hi @Velnbur reopened, please address feedback |
|
@delta1 Check please latest commits, I added |
|
Okay, I see tests failing, working on it |
| where | ||
| <B as FromHex>::Err: std::fmt::Display, |
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.
Added bounds here for associated Err type, as compiler suggested
|
@delta1 I finally regenerated it correctly, sorry for inconveniences :) |
|
Can you please squash/rebase these commits so that they compile by themselves? You need to update the lockfile in the same commit as you change Cargo.toml. Also, please don't make changes in one commit which are reverted in another commit. Also, please don't update unrelated dependencies. You can do that in a separate PR if you want but it will require separate review. |
Add `hex-conservative` crate as a dependency for more robust hexadecimal encoding/decoding. Replace custom hex parsing logic with the library's implementation across the codebase. Update error types to use `hex-conservative`'s error variants instead of custom `hex::Error`. Implement `TweakHexDecodeError` to handle hex and tweak validation errors for blinding factors. Add Display bound to FromHex error type in serde_util.
|
Got it, done! Squashed commits
My bad, created Cargo.lock from scratch, not from from existing |
| } | ||
|
|
||
| #[doc(hidden)] | ||
| impl From<hex_conservative::DecodeFixedLengthBytesError> for TweakHexDecodeError { |
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 775d7cd:
We don't have to fix this here (it's a problem throughout the crate) but I would like to get rid of these From impls since they increase the API surface and encourage unthinking error promotion.
| impl std::error::Error for TweakHexDecodeError { | ||
| fn source(&self) -> Option<&(dyn std::error::Error + 'static)> { | ||
| match self { | ||
| TweakHexDecodeError::InvalidHex(err) => Some(err), |
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 775d7cd:
Also don't need to fix it here but we should use Self:: instead of writing TweakHexDecodeError:: all over the place.
| } | ||
| } | ||
|
|
||
| impl hex::FromHex for AssetBlindingFactor { |
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 775d7cd:
I don't think we should keep the FromHex trait. Where is it used? Can we replace it with FromStr or with a special-purpose utility trait?
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 see, it's used for the serde hex_bytes module.
It seems to me that we can replace it with FromStr, introduce a sealed trait if we really want to limit its scope (but do we? I don't think so), and then we can drop hex-conservative 0.2 entirely.
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.
Shouldn't than all fmt::Display implementations use hex as well? Asking cause it isn't so for Script at least:
Line 58 in f6ffc78
| fmt::Debug::fmt(self, f) |
Ohh, right, hex-conservative 1.0 doesn't have encoding yet. Ok, I guess we're stuck with 0.x for now. This PR is good as-is, given the circumstance. Thanks for your patience and continued iterating! |
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 775d7cd; successfully ran local tests
Overview
Add hex-conservative as a dependency and refactor hex parsing code to use it instead of the custom implementation. Update FromHex trait to use associated error types and standardize hex decoding across the codebase.
Closes: #258