Improve documentation on the all module#1339
Conversation
Kixunil
left a comment
There was a problem hiding this comment.
It's not wrong but if we're explicitly guaranteeing things we should also guarantee beginning with OP_
bitcoin/src/blockdata/opcodes.rs
Outdated
There was a problem hiding this comment.
And all opcode constants are guaranteed to begin with OP_.
bitcoin/src/blockdata/opcodes.rs
Outdated
There was a problem hiding this comment.
I wonder what's the reason though.
There was a problem hiding this comment.
No idea, @apoelstra did you write this originally?
There was a problem hiding this comment.
The reason for not having Ord is that there is no "ordering" of opcodes that makes conceptual sense, and I can't think of a reason to put sets of individual opcodes into ordered data structures (or sorting them directly).
The reason I mentioned this is because Bitcoin Core routinely uses < and > on opcodes to effect consensus logic, something which hides implicit assumptions about the opcodes' byte encoding, in code where the exact behavior is critical, and dresses this up in a skinsuit of mathematical notation.
Probably nobody else is aware of, or as offended by, this particular quirk of Core as I was, so we can drop the comment :). Also like, I'm pretty sure we have the same logic, I just had to add some as u8s before the <s.
There was a problem hiding this comment.
Also like, I'm pretty sure we have the same logic, I just had to add some
as u8s before the<s
Made me laugh :)
d43c65f to
5ccdfc8
Compare
|
Removed code comment as suggested. |
|
CI failure is in master. I will PR to fix it. |
Woops, I missed that comment :) |
5ccdfc8 to
560be81
Compare
|
I forgot about Kix's suggestion about guaranteeing opcodes start with |
|
Oh, I'd like to keep " |
Kixunil
left a comment
There was a problem hiding this comment.
ACK 74c3727fc78b5359d7b3f92f2decc5cbf7a8f98c
(Correct, I'm not ACKing removal of the comment.)
560be81 to
c9b0c1d
Compare
|
Added new patch using text from comment above by @apoelstra |
Kixunil
left a comment
There was a problem hiding this comment.
ACK c9b0c1d87766b840ea81a1c242cff095b7e8fce7
|
Rebased on master, no other changes. |
c9b0c1d to
c56e54a
Compare
Kixunil
left a comment
There was a problem hiding this comment.
ACK c56e54a1b4b9c22d9d4d8a73d7696b9c9544a3d4
bitcoin/src/blockdata/opcodes.rs
Outdated
There was a problem hiding this comment.
In c56e54a1b4b9c22d9d4d8a73d7696b9c9544a3d4:
I'm happy to ACK this but TBH I don't think it belongs in a doccomment. Core's logic is hidden inside Core, so I think if you care about this you're probably reading the source code, not the API docs, and a regular comment will suffice.
There was a problem hiding this comment.
Demoted it back to a code comment. This PR wins this months prize for most iterations on a totally trivial PR :)
There was a problem hiding this comment.
I think the part about deliberately not implementing Ord is fine in doc comments so that the users will not ask us to implement it (or find the comment too late). For notes about Core a normal comment is fine. Notice that I wrote only the first part in my suggestion.
@tcharding perhaps you can save some time by waiting for resolution of our discussions before implementing changes when there are different opinions.
There was a problem hiding this comment.
@tcharding perhaps you can save some time by waiting for resolution of our discussions before implementing changes when there are different opinions.
Yes, I'll try this and no be so trigger happy, cheers.
There was a problem hiding this comment.
@Kixunil what if we said "We do not implement Ord on this type because there is no natural ordering on opcodes, but there may appear to be one (e.g. because all the push opcodes appear in a consecutive block) and we don't want to encourage subtly buggy code. Please use the associated methods on Opcode to distinguish different types of opcodes."
If we wanted to mention Core, we could also point out that Bitcoin Core's IsPushOnly considers OP_RESERVED to be a "push opcode", allowing this opcodes in contexts where only pushes are supposed to be allowed, because of exactly this category of mistakes.
There was a problem hiding this comment.
Yes, I like that wording. The core example is a good one but not sure if we should add it to doc comment. Maybe hide it in <details><summary>Example of Core bug caused by assuming ordering</summary> ... </details>.
c56e54a to
f492c1d
Compare
apoelstra
left a comment
There was a problem hiding this comment.
ACK f492c1d57fbcce0fb79f3eff9ef9fae6d115f349
The `all` module enables usage of a wildcard import statement without
muddying the scope with any other types defined in `opcodes`, in other
words if one wants to use the `All` type `opcodes::All` is the most
clear way to use it, however usage of naked `OP_FOO` types is perfectly
clear.
Add documentation stating that we guarantee to never put anything else
in the `all` module so folks are confident using a wildcard import will
not bring any rubbish into scope.
Expected usage in downstream applications that need types in `opcodes`
as well as the opcodes:
```
use bitcoin::opcodes::all::*;
use bitcoin::opcodes;
```
Also, we do no implement `Ord` or `PartialOrd`, document this including
HTML tags hiding an example bug from Bitcoin Core that shows why not.
f492c1d to
2157e69
Compare
|
I've force pushed changes that hopefully implement review suggestions. Please review carefully because the Core bug described is totally unknown to me and I did not go digging in Core source code looking for it. Also I re-worded the suggestion to mention |
|
I'm happy with this. I think maybe Core developers might dispute this being a "bug" but I think it is :) and anyway I don't think it'd be a big deal if we had to change it later. |
Improve documentation on the
allmodule by doing:allwill only ever contain opcode constantsDone as follow up to #1295