Skip to content

Making globals part of PSBT struct. Closes #652#654

Merged
sanket1729 merged 1 commit intorust-bitcoin:masterfrom
BP-WG:psbt/global
Nov 12, 2021
Merged

Making globals part of PSBT struct. Closes #652#654
sanket1729 merged 1 commit intorust-bitcoin:masterfrom
BP-WG:psbt/global

Conversation

@dr-orlovsky
Copy link
Copy Markdown
Collaborator

@dr-orlovsky dr-orlovsky commented Sep 15, 2021

I took the most non-invasive approach to reduce diff size. Many parts of the code can be improved in style or further refactored (like some functions are not necessary and can be just moved to be part of other functions), but I'd prefer to do that as a separate PR once this will be merged.

My approach with this PR:

  1. Remove Global struct by moving its fields right into PartiallySignedTransaction - but keep the util/psbt/map/global.rs file with all its logic
  2. Keep existing Map for Global implementation in the same file, but just change it to Map for PartiallySignedTransaction
  3. With serialization, convert Global deserialization into crate-private function and use it from PartiallySignedTransaction deserialization
  4. Refactor the tests and imports as required to get the thing compile and pass tests

The refactoring will be followed by PR(s) adding support for Taproot

@dr-orlovsky dr-orlovsky added the API break This PR requires a version bump for the next release label Sep 15, 2021
@dr-orlovsky dr-orlovsky added this to the 0.28.0 milestone Sep 15, 2021
@dr-orlovsky dr-orlovsky linked an issue Sep 15, 2021 that may be closed by this pull request
Copy link
Copy Markdown
Member

@sanket1729 sanket1729 left a comment

Choose a reason for hiding this comment

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

cr-ACK ac0c9087dead86bc5fccdcc49c527f36578e6920.

I don't like it if we have to call verify() type functions after creating an object. I guess the user can edit the unsigned tx and we need to guard against that.

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.

I don't like the verify name for the API. Maybe sanity_check is better. or perhaps unsigned_tx_checks

But I think this check should be private and should also be checked when we decode into a PartiallySignedTransaction.

@dr-orlovsky
Copy link
Copy Markdown
Collaborator Author

@sanket1729 addressed your comment. As for the user ability to modify unsigned tx, this is a separate problem which was present before this PR. I think it should be addresses in some other PR (since there might be multiple ways of doing that). I think that we need to make the field private and provide a read-only getter for it.

@apoelstra
Copy link
Copy Markdown
Member

Agreed that the unsigned tx should be private and accessed through a getter. In PSBT2 there will not even necessarily be an unsigned tx, and we may need to compute it on the fly and/or cache it.

Agreed also that this change belongs in another PR.

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 55c6277

I kinda think this stuff should live in psbt/mod.rs rather than psbt/global.rs, but I don't feel strongly about it.

@dr-orlovsky
Copy link
Copy Markdown
Collaborator Author

@apoelstra I do agree that the stuff belongs to mod, I just wanted to reduce diff as much as possible and simplift revieweing of the actual code changes line by line, not in large blocks moved between files. We will get rid of global.rs as a part of further PSBT refactoring and/or splitting of this crate into a multiple crates

@dr-orlovsky
Copy link
Copy Markdown
Collaborator Author

@sanket1729 pls re-review this PR, such that we can go forward with it and merge

Copy link
Copy Markdown
Member

@sanket1729 sanket1729 left a comment

Choose a reason for hiding this comment

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

ACK 55c6277 . Reviewed range diff with ac0c908 that I previously ACKed

@sanket1729 sanket1729 merged commit abc242d into rust-bitcoin:master Nov 12, 2021
@JeremyRubin
Copy link
Copy Markdown
Contributor

is there a reason this PR deletes the PSBT merge function?

@dr-orlovsky
Copy link
Copy Markdown
Collaborator Author

It does not, it just now uses merge function which is a part of Map trait.

@apoelstra
Copy link
Copy Markdown
Member

@dr-orlovsky there used to be a publicly exposed Psbt::merge function which implemented the Combiner role. It looks like, since this PR, there is no such function.

We should restore it -- though I'd prefer it be called combine to match the PSBT naming.

@tcharding
Copy link
Copy Markdown
Member

FTR fixed in #842

sander2 added a commit to sander2/polkabtc-clients that referenced this pull request Oct 6, 2022
sander2 added a commit to sander2/polkabtc-clients that referenced this pull request Oct 6, 2022
sander2 added a commit to sander2/polkabtc-clients that referenced this pull request Oct 7, 2022
moonman889 added a commit to moonman889/interbtc-clients that referenced this pull request Sep 15, 2025
neon-rider578 added a commit to neon-rider578/interbtc-clients that referenced this pull request Sep 30, 2025
stack-sage7291 added a commit to stack-sage7291/interbtc-clients that referenced this pull request Dec 11, 2025
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

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Why PSBT needs separate Global struct?

5 participants