Skip to content

Prepare moving script types to primitives#3194

Merged
apoelstra merged 6 commits intorust-bitcoin:masterfrom
tcharding:08-21-mv-script
Sep 13, 2024
Merged

Prepare moving script types to primitives#3194
apoelstra merged 6 commits intorust-bitcoin:masterfrom
tcharding:08-21-mv-script

Conversation

@tcharding
Copy link
Copy Markdown
Member

@tcharding tcharding commented Aug 21, 2024

Move the Script and ScriptBuf types to primitives. There were still a few preparations required, things we had missed while creating the extension traits.

Note also please, in the last patch, we enable hex from the serder feature. This is not the final state we want but like we did for alloc it is a step to reduce the size of the diff.

@github-actions github-actions bot added C-bitcoin PRs modifying the bitcoin crate test C-primitives labels Aug 21, 2024
@tcharding tcharding force-pushed the 08-21-mv-script branch 6 times, most recently from 15d7d50 to 1044774 Compare August 21, 2024 02:29
@github-actions
Copy link
Copy Markdown

🚨 API BREAKING CHANGE DETECTED

@github-actions github-actions bot added the API break This PR requires a version bump for the next release label Aug 21, 2024
@tcharding tcharding marked this pull request as draft August 21, 2024 02:50
@github-actions
Copy link
Copy Markdown

🚨 API BREAKING CHANGE DETECTED

@github-actions
Copy link
Copy Markdown

🚨 API BREAKING CHANGE DETECTED

@github-actions
Copy link
Copy Markdown

🚨 API BREAKING CHANGE DETECTED

@github-actions
Copy link
Copy Markdown

🚨 API BREAKING CHANGE DETECTED

@tcharding tcharding mentioned this pull request Aug 21, 2024
@tcharding tcharding marked this pull request as ready for review August 21, 2024 06:49
@tcharding tcharding marked this pull request as draft August 21, 2024 06:50
@tcharding tcharding force-pushed the 08-21-mv-script branch 3 times, most recently from 729cea4 to 126cfcf Compare August 27, 2024 00:15
@github-actions
Copy link
Copy Markdown

🚨 API BREAKING CHANGE DETECTED

1 similar comment
@github-actions
Copy link
Copy Markdown

🚨 API BREAKING CHANGE DETECTED

In preparation for moving the `Script` type to `primitives` stop
accessing the inner field before doing slice operations, use `as_bytes`
to first get at the slice.
In preparation for moving the `ScriptBuf` type to `primitives` stop
accessing the inner field when encoding/decoding, use `as_script`
and `from_bytes` instead.
The `Builder` is staying in `bitcoin` while the `ScriptBuf` is moving to
`primitives`, so we cannot access the inner field of `ScriptBuf`.

Use the new `as_byte_vec` hack to mutate the inner `ScriptBuf` field.
The optional dependencies are ordered and separated by whitspace in a
manner that may not be obvious (or even have a reason).

Some of this is because since use of `?` deps changed name.

Put all the optional deps together in alphabetic order.
@github-actions github-actions bot removed the C-internals PRs modifying the internals crate label Sep 11, 2024
@tcharding
Copy link
Copy Markdown
Member Author

I'm not exactly sure how you guys are supposed to review this without just trusting that I did indeed cutn'pasta the script impl blocks. I guess you could copy the impl blocks from master locally and check you git index is dirty/clean as expected.

@github-actions
Copy link
Copy Markdown

🚨 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.

@tcharding tcharding marked this pull request as ready for review September 11, 2024 01:01
@tcharding tcharding changed the title Move script types to primitives priority: Move script types to primitives Sep 11, 2024
@Kixunil
Copy link
Copy Markdown
Collaborator

Kixunil commented Sep 11, 2024

without just trusting that I did indeed cutn'pasta the script impl blocks

Here's a secret trick for you and anyone else who wants to review such things:

  1. git config --global diff.colorMoved zebra
  2. git show ...
Speaking of tricks, this is my entire git configuration

~/.gitconfig

[merge]
	conflictstyle = diff3
[diff]
	colorMoved = zebra
[rerere]
	enabled = true
[merge "rust-merge"]
	name = Rust merge
	driver = rust-merge %O %A %B %A

~/.gitattributes

*.rs	merge=rust-merge,diff=rust

@apoelstra
Copy link
Copy Markdown
Member

@Kixunil there is an additional option I learned recently. In [diff] you can add

colorMovedWs = allow-indentation-change

and this will even do the move-coloring when the indentation has changed (which would eliminate the need for the silly "dummy module" commits in these PRs).

I don't know when this option was added. I don't think it existed a few years ago.

apoelstra
apoelstra previously approved these changes Sep 12, 2024
Copy link
Copy Markdown
Member

@apoelstra apoelstra left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ACK e234ab6f5d2f5369d1811d539ef595b1df8181de successfully ran local tests

@tcharding
Copy link
Copy Markdown
Member Author

I can't come up with the quite the expression right now, but those config options are a total game changer. I haven't worked out exactly what all the colors mean yet but this is massive. The machine is now doing most of the review instead of us having to do it. Massive.

Copy link
Copy Markdown
Collaborator

@Kixunil Kixunil left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

NACK putting anything deprecated into primitives (&co) at all.

@tcharding suggestion for making the process more efficient: once you see this, immediately drop the top commit and force push the branch without changing hashes, rename the PR to "Prepare moving script types to primitives. Then I'll immediately ACK 8f2f4cb without any review because all those commits are fine. You can then in parallel address the requested changes and make a new PR that only moves (non-deprecated) stuff.

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nope, these two functions should no longer exists in primitives. They are a relic from the time when Script was Sized. Everything these do can and should be achieved using Display.

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think/hope pub(crate) won't be needed long term...

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In this case pub(super) would have been sufficient.

But even that isn't necessary because the two places that script.0 are called can be replaced with script.as_bytes.

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Oh, yeah, Box casting uses unsafe anyway.

@Kixunil
Copy link
Copy Markdown
Collaborator

Kixunil commented Sep 12, 2024

Also this doesn't compile with cargo test --features=serde --no-default-feature but for a different reason than I expected. Which makes me wonder if we should activate hex from serde or rather make it so that things will fail to parse human-readable encodings without hex.

@apoelstra
Copy link
Copy Markdown
Member

apoelstra commented Sep 12, 2024

Which makes me wonder if we should activate hex from serde or rather make it so that things will fail to parse human-readable encodings without hex.

I think we should just activate hex from serde. It's hard for me to imagine somebody being willing to take a massive macro-filled serde dep but unwilling to take a hex-conservative dep, and it makes our lives much easier to eliminate feature combinations.

I should investigate though why my local CI failed to catch this. It should be testing all single-feature combinations. Which crate doesn't compile? I tried bitcoin, primitives and the root and they seem to be ok.

@Kixunil
Copy link
Copy Markdown
Collaborator

Kixunil commented Sep 12, 2024

There's another reason to activate hex: almost-silently failing serialization because of accidentally missing feature is kinda foot-gun. It's not as terrible as some other things but it is concerning at least.

Oh, crap, I had primitives/src/script.rs lying around and didn't notice this error is unlike others.

But now I see deprecation warnings.

@github-actions github-actions bot removed the test label Sep 12, 2024
@tcharding tcharding changed the title priority: Move script types to primitives priority: Prepare moving script types to primitives Sep 12, 2024
@tcharding
Copy link
Copy Markdown
Member Author

Removed final patch as suggested, thanks for putting thought into how we can speed up the process @Kixunil

Copy link
Copy Markdown
Collaborator

@Kixunil Kixunil left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ACK 8f2f4cb

Copy link
Copy Markdown
Member

@apoelstra apoelstra left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ACK 8f2f4cb successfully ran local tests

@apoelstra apoelstra merged commit 60e15b8 into rust-bitcoin:master Sep 13, 2024
@tcharding tcharding deleted the 08-21-mv-script branch September 18, 2024 01:57
apoelstra added a commit that referenced this pull request Oct 14, 2024
d649c06 Move script types to primitives (Tobin C. Harding)
ec46359 Inline bytes_to_asm_fmt into Script::Display impl (Tobin C. Harding)

Pull request description:

  First patch removes `bytes_to_asm_fmt` as requested by Kix here: #3194 (comment)

  Second patch does the move. The move is minimal but there is quite a bit of code moved in `script/mod.rs` - I believe it is as minimal as required as well.

ACKs for top commit:
  apoelstra:
    ACK d649c06 successfully ran local tests

Tree-SHA512: 329a23948ac5617402a724b734d81cde8ab1f57ddd4860f858880618e260ea8b5cc89315de1fd93ae32787d5e8508fd604a41f003b1f5772a773b5b1648d382c
@tcharding tcharding changed the title priority: Prepare moving script types to primitives Prepare moving script types to primitives Dec 4, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

API break This PR requires a version bump for the next release C-bitcoin PRs modifying the bitcoin crate C-primitives P-high High priority

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants