Move Witness to primitives#3406
Conversation
a0f05ea to
7f8cf85
Compare
|
Note the unconditional dependency on |
|
I'm EOD will debug CI tomorrow. |
|
I think we can pull out several uncontroversial commits from this:
|
|
Thanks for the review man. I'll pull the non-controversial stuff out as suggested.
Another idea is adding to the API a function that will go over to
Drats, that wasn't the aim. |
5fab6b1 Rename iter len unit test (Tobin C. Harding) f6a74ef Refactor the serde Witness unit tests (Tobin C. Harding) 9860453 Improve Witness consensus encode unit test (Tobin C. Harding) 7e2899d Improve Witness::push unit test (Tobin C. Harding) fe96727 Improve witness unit tests for single empty element (Tobin C. Harding) Pull request description: In preparation for moving the `Witness` type over to `primitives` refactor and improve all the unit tests that will be moved, do not touch the ones that will stay behind. The first five patches are from #3406, the last is just a re-name of the test function I tried to refactor in ac6fe3a ACKs for top commit: apoelstra: ACK 5fab6b1 successfully ran local tests Tree-SHA512: bc00f81e3c5cc92ae58dd2fc876d368a487ae6c08cc0735d7227c3a89287e321dbfb5b571b951d0616af0ec7cf9a0ea2d0e724645b1c419933a212ece80a0fbf
7f8cf85 to
3906cb5
Compare
|
I think github is confused, there should not be conflicts for this one because I just rebased it on top of #3432 and there are none for it. |
3f3f30d Use iter instead of accessing content field (Tobin C. Harding) 6389d1c Stop using push_slice (Tobin C. Harding) be163ee Use Witness::len instead of accessing field (Tobin C. Harding) Pull request description: Prepare `Witness` to be moved to `primitives`. This is the first three patches out of #3406. Patch 1 and 2 are internal changes, path 3 is also internal but introduces a slight perf hit by doing multiple writes. ACKs for top commit: apoelstra: ACK 3f3f30d successfully ran local tests Tree-SHA512: 25e2570a22797dbfa15d6e5af9b72938243192ca264bc5fe82c2f327486e52a73993b3b61ee1161e5d17b01a7f9843960cb4031e6550561de4ecafb9f935e375
3906cb5 to
eaeef05
Compare
|
Hey @apoelstra have you any suggestions for how to decouple the /// Returns the number of witness elements and the serialization of the elements.
///
/// This is an incomplete serialization because the number of witness elements must be
/// serialized (in compact form) at the front of the elements in order be consensus valid.
pub fn incomplete_serialization(&self) -> (usize, &[u8]) {
(self.len(), self.content[..self.indices_start])
}But for [0] In 3f3f30d we removed the need for this but it could be added back in so that we don't iterate over the elements. |
|
I think we can use
|
|
Aight, I'll have a go. Thanks |
|
I had a bit of a go, can I clarify that I've understood your suggestion? You mean inside This led me to raise #3464 since I doubt this is going to be the only time that |
Why do we need to know the total length upfront? Are we using variable-length size markers within our internal representation? If so we should stop doing that. (But I don't think we are. IIRC we are using a native-endian u32.) |
|
We allocate the correct size array in |
When In fact probably we should just take the minimum size hint, cap it at the maximum allocation size, and use that. Don't even bother looking at the max size hint. This will cover all the common cases such as decoding from a vector of slices. |
|
Its not just the number of elements though, its size of each element (+ size of varint encoding) and since we use |
|
I did have a go at adding |
|
🚨 API BREAKING CHANGE DETECTED To see the changes click details on "Check semver breaks / PR Semver - stable toolchain" job then expand "Run semver checker script" and scroll to the end of the section. |
I believe you're correct. For now let's stick with the unstable constructor so that we are not messing with the API more than we need to. But before/after this PR I would like to revisit this:
Personally, I would suggest that we implement |
|
Yep lets do it, added #3469. |
17ba251 to
312e5b7
Compare
|
The diff is pretty hard to review even with |
|
🚨 API BREAKING CHANGE DETECTED To see the changes click details on "Check semver breaks / PR Semver - stable toolchain" job then expand "Run semver checker script" and scroll to the end of the section. |
|
During rebase I found that I had moved the deprecated |
312e5b7 to
4260b06
Compare
|
🚨 API BREAKING CHANGE DETECTED To see the changes click details on "Check semver breaks / PR Semver - stable toolchain" job then expand "Run semver checker script" and scroll to the end of the section. |
4260b06 to
d4145a5
Compare
|
🚨 API BREAKING CHANGE DETECTED To see the changes click details on "Check semver breaks / PR Semver - stable toolchain" job then expand "Run semver checker script" and scroll to the end of the section. |
|
In 1c419370c6bc2dc54226dbf89f3b9d506b9102da: Change Also I'd like to stick |
|
d4145a56736a4b0caed2c5ccc0f25e3187b94e26 looks good otherwise. |
In preparation for moving the `Witness` to `primitives` we need a way to construct the `Witness` when decoding. In order to maintain the current performance and not introduce additional allocations we need to be able to construct a `Witness` from the content buffer, this leaks the implementation details of `Witness`. Add a clearly marked unstable constructor to create a `Witness` from parts. This introduces the concept of `foo__unstable` function names; add a section to the README describing unstable functions and semver guarantees.
Move the `Witness` over to `primitives` leaving behind any method that takes or returns a `Script` or a signature. Includes addition of a feature gate to unit test.
d4145a5 to
c1eccfd
Compare
|
Changed as suggested, thanks. |
|
🚨 API BREAKING CHANGE DETECTED To see the changes click details on "Check semver breaks / PR Semver - stable toolchain" job then expand "Run semver checker script" and scroll to the end of the section. |
|
Its Friday afternoon, I do not have the inclination to look into WASM problems right now. We can merge this if it gets past your local CI @apoelstra can't we and ignore the WASM job until next week? |
|
Yeah, for sure. Probably we need to make the wasm test "allow fail" because the whole ecosystem is predicated on downloading random unpinnable bullshit from the Internet, and it's really just not compatible with this project's ethos. I mean, we ought to fix it's straightforward enough or if somebody who needs it shows up to do it. But I wouldn't put too much effort into it. |
|
Gonna one-ACK merge on the basis that this PR is 3 weeks old, and even though there have been substantial changes, nobody else has commented. |
Patch 1 introduces a new policy to the codebase, we use
foo__unstablefor public unstable functions and there are zero semver guarantees if you call these functions.Patch 2 does the move.
Close #3406