-
Notifications
You must be signed in to change notification settings - Fork 732
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
Split relative locktime error up #2433
Split relative locktime error up #2433
Conversation
I went to move the |
Pull Request Test Coverage Report for Build 8217718201Details
💛 - Coveralls |
I was trying to pull out |
I hadn't tried to move any code out of the locktime modules, I said (at least I meant) that |
b96a638
to
09ea073
Compare
Only change in force push is improvement to the error message printed for two of the new errors. |
Can this go in? We need this if we want to move the locktime types to units which is required to move |
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 09ea073
09ea073
to
f3ce0e3
Compare
Changes in force push:
|
f3ce0e3
to
68d808b
Compare
IncompatibleTime(LockTime, Time), | ||
pub struct IntegerOverflowError { | ||
/// Time value in seconds that overflowed. | ||
pub seconds: u32 |
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.
Well, there's one weird property - one can create the error with funny values like seconds: 0
which is never actually wrong and thus the error is kinda invalid.
So I don't like it much but it's probably 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.
I think we'll have to live with it because Rust doesn't have ranged types (and it is a real PITA to create and maintain your own).
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.
We can just hide the representation leaving the option to add it later. (And have a getter today.)
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.
We can do this but it seems excessive for an error type:
/// Input time in seconds was too large to be encoded to a 16 bit 512 second interval.
#[derive(Debug, Clone, PartialEq, Eq)]
pub struct TimeOverflowError {
/// Time value in seconds that overflowed.
seconds: u32 // We maintain an invariant that this value does indeed overflow.
}
impl TimeOverflowError {
pub fn new(seconds: u32) -> Self {
let overflows = u16::try_from((seconds + 511) / 512).is_ok();
assert!(overflows);
TimeOverflowError { seconds }
}
}
I personally think the error is fine as it is. We are not here to protect every programmer from every single programming mistake they might make.
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.
@tcharding the cool thing is that we don't need new
because users should never be directly constructing our error types.
And internally of course we can just directly construct them.
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.
@tcharding I don't think so. I still see the field as pub
, you didn't address @apoelstra's comment and I agree with his comment.
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.
Oh, damn - I removed the non_exhaustive
thinking the error as stable inadvertently allowing construction, thereby forgetting this discussion thread.
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 made the field pub(crate)
and added a comment so it doesn't get un-privated.
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.
Note also that the constructor has been removed - I believe this thread is resolved.
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 am going to just disable the "resolve conversation" rule.
70d65e1
to
2213cdd
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 2213cdd except for the pub
/accessor thing, which would be OK as a followup PR that defined having accessors as part of our error policy
Please note the new error types in this PR are not hider errors, are returned from functions that are stable, and therefore have public fields and do not use |
IncompatibleTime(LockTime, Time), | ||
pub struct IntegerOverflowError { | ||
/// Time value in seconds that overflowed. | ||
pub seconds: u32 |
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.
@tcharding I don't think so. I still see the field as pub
, you didn't address @apoelstra's comment and I agree with his comment.
FTR, if we want to stabilize sooner maybe we should just hide all errors entirely and we can go back and uncover (parts of) them later. |
I made both incompatible error types
I"m not sure about this. If we do this (and similar change for Your comments did uncover that I was using the errors incorrectly (for how I had meant it to be used) though which is interesting. Now |
2213cdd
to
c45d9f4
Compare
That's not always sufficient.
Firstly, not really, they are mirrored (and we would need a third field to distinguish them). Secondly I think that being imprecise just to avoid the discussion is just lying to ourselves. If the discussion is not worth slowing down stabilization just make them opaque.
The concrete types imply the outer one, so IMO it still is the same thing.
Cool! |
dfe70d2
to
7c0cc02
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 7c0cc02
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 7c0cc02
Both unresolved comments are yours @Kixunil, I believe they are both resolved. |
The `relative` module has a single general error type, we are moving away from this style to specific error types. Split the `relative::Error` up into three error structs. Note the change of parameter `h` to `height`, and using `h` as the pattern matched variable - this makes sense because it gives the variable with large scope the longer name.
7c0cc02
to
3c8edae
Compare
Rebase only, no other changes. |
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.
utACK 3c8edae
Note that a hidden discussion links to issue #2553 about renaming local variables inside some method. |
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 3c8edae
The
relative
module has a single general error type, we are moving away from this style to specific error types.Split the
relative::Error
up into three error structs.I forget the policy on public inner fields.