-
Notifications
You must be signed in to change notification settings - Fork 877
Remove PackedLockTime
in favor of absolute::LockTime
#1330
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
Remove PackedLockTime
in favor of absolute::LockTime
#1330
Conversation
7605f57
to
8a6d5a7
Compare
Can you hack up a branch in |
Regarding optimization being kinda pointless I both agree with it and dislike it. :D
This sounds reasonable, let me sleep on it first but I'm leaning towards ACK here now. |
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.
It's sad we would have to change the API again. I guess it proves the value of my "didn't change for a while" requirement for 1.0.
.then(self.input.cmp(&other.input)) | ||
.then(self.output.cmp(&other.output)) | ||
} | ||
} |
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.
One thing I just realized: the fields are not ordered in the same order they are on the wire. Could it be a problem?
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.
It's been this way since the beginning of this library and nobody has complained, but I'm happy to change this to match the wire ordering just in case.
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.
Hard question since we could break someone's code by changing it. There isn't any standardized sort order of transactions, is there?
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, there isn't. If I had to guess, the only specific sort order that anybody is using is one based on TXIDs, for indexing purposes.
Our Ord
impl is purely here to make supporting ordered collections easy.
write!(f, "{:X}", self.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.
Is #[deprecated] type PackedLockTime = LockTime;
missing here?
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, sure, I can add this (if this is one of the cases where deprecation works..)
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.
FWIW the resulting type will not quite have the same API as the old one .. though they will match in a lot of cases.
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, yes, at least Ord
will be missing which was originally one of the main points of having the type... The deprecation message would still help I guess. I think it works on type
but I may be misremembering.
OK, I think it's concept ACK from me. But I do want some doc explaining all this. :) Will review after rebase. |
I am in the process of rebasing this, but FYI we have explicit tests right now about serde de/serialization, and in particular we test that Since these will become the same type, I will need to unify them somehow, which is an unfortunate breaking change. |
8a6d5a7
to
e4f6fc6
Compare
Rebased. Watch out for the new commit 1b26aac5dd0cce544f357126c5c459ad38ac5710 which unifies the serde impls, breakingly. |
e4f6fc6
to
d446105
Compare
This will be tested in a later commit, when `PackedLockTime` is folded into this type so all its tests apply to `LockTime`.
The next commit will be a mechanical s/PackedLockTime/LockTime/; this commit seemed like the easiest way to facilitate that.
This can be replicated by deleting the `type PackedLockTime = LockTime' line, and then running find . -type f | xargs sed -i 's/PackedLockTime/LockTime/g at the root of the repo.
d446105
to
74ee243
Compare
The code looks good to me, I wanted to mention that with this applied deriving |
Sounds like a job for a macro? (I'm low on time rn so reviewing will take a while :( ) |
Yes, we can macro-ize it, or just remove the impl entirely in favor of Good to be aware of, but this seems like a problem that's both solvable and not the responsibility of this library. |
Cool, I'm happy with that. |
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 the packed_lock_time
comment because I'm requesting changes to remove Ord
.
@@ -179,8 +62,7 @@ impl fmt::UpperHex for PackedLockTime { | |||
/// ``` | |||
#[allow(clippy::derive_ord_xor_partial_ord)] | |||
#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)] | |||
#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))] | |||
#[cfg_attr(feature = "serde", serde(crate = "actual_serde"))] | |||
#[derive(Ord)] // will be removed in next commit |
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 never gets removed, claimed as part of 51f8b9a3 drop Ord on absolute::LockTime; add Ord to Transaction
but not done.
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, sorry! I rebased this like 20 times and must have lost it.
let packed_lock_time = crate::parse::hex_u32(s)?; | ||
Ok(Self::from_consensus(packed_lock_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.
Perhaps this local variable could be better name, packed_lock_time
is an artifact of PackedLockTime
, right?
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, I think it's fine ... we are parsing a u32
, which can reasonably be described as a "packed locktime" then we're unpacking it into an enum type.
This still has the line let lock_time = absolute::LockTime::from_height(psbt.unsigned_tx.lock_time.to_consensus_u32() + lock_time_delta).unwrap(); I'm unsure whether this "adding height to a locktime" concept is a meaningful thing or just the sort of thing that shows up in example code. Maybe we should have first-class support for it. Note that the line, as written, depends on the fact that the original locktime was a small blockheight. A proper function for this would handle the exceptional case gracefully.
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.
concept ACK and code review ACK. modulo Tobin's comment about removal of Ord
Rebased to remove the |
74ee243
to
1b15a13
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.
code review ACK 1b15a13
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 1b15a13
@Kixunil can you say more about what documentation you want for this? I'm going to merge this as-is, I"m happy to do a followup documenting things. But the |
ooooooo yeah, that was all me, writing docs like its my job :) |
@apoelstra something in the changelog to help people understand it and some paragraph in both |
@Kixunil there is no byte-based ordering. I'm not sure what you want me to add to I will add a changelog entry, yes. |
Huh? How are transactions ordered then? |
@Kixunil ah, yes, transactions are ordered using the locktime as sort field and in this case the locktimes are compared using their consensus encoding. I'm happy to document this, but this is the same ordering that |
Basically I just want to have a heads up along the lines "this contains a non- |
…shenanigans in #1330 02c1cd6 add some documentation clarifying the locktime ordering shenanigans in #1330 (Andrew Poelstra) Pull request description: Updates the CHANGELOG and also the doccomment on `Transaction`. ACKs for top commit: tcharding: ACK 02c1cd6 Kixunil: ACK 02c1cd6 sanket1729: ACK 02c1cd6 Tree-SHA512: e2d23a90fb1e53758449fe49a3db7ae1497a260ce7efcade4b50265fa70840db273609019590d9d0a69e1272607a6bcf37924b805b4f09909487eb0c3b91a3cd
This is potentially a controversial PR, but hear me out. My argument is that right now
absolute::LockTime
andPackedLockTime
are basically identical types; they can be converted between each other withFrom
and they have exactly the same semantics except thatPackedLockTime
hasOrd
on it. This makes it very confusing to tell which one should be used, for example in PSBT2 where there are now extra locktime-related fields.The motivation for having
PackedLockTime
independent ofLockTime
are:PackedLockTime
is theoretically more efficient because you don't need to unpack the field, don't need to store a enum discriminate, etc. I don't buy this. If you are trying to save individual bytes in your transaction-parsing there are lots of places you'd look before messing around with locktimes, so we shouldn't privilege this specific thing.PackedLockTIme
has anOrd
impl, and removing that will have a cascading effect on transactions, blocks, etc., preventing them from being held inBTreeMaps
etc. My proposal, implemented here, is to just manually implOrd
onTransaction
and don't impl it onLockTime
.I recall some argument that we need to be able to sort miniscripts, and miniscripts might have locktimes in them, but I think this is wrong -- miniscripts always have explicitly either a
Height
or aTime
, and there is no problem ordering these.Closes #1455