Skip to content
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

Rename txid to compute_txid #2366

Merged

Conversation

yancyribbens
Copy link
Contributor

@yancyribbens yancyribbens commented Jan 20, 2024

Rename txid to compute_txid and mark txid as deprecated.

Closes #2363

@coveralls
Copy link

coveralls commented Jan 20, 2024

Pull Request Test Coverage Report for Build 7630482955

  • 0 of 0 changed or added relevant lines in 0 files are covered.
  • No unchanged relevant lines lost coverage.
  • Overall coverage decreased (-0.01%) to 84.252%

Totals Coverage Status
Change from base Build 7628173765: -0.01%
Covered Lines: 19222
Relevant Lines: 22815

💛 - Coveralls

}

#[deprecated(since = "0.31.0", note = "use compute_txid() instead")]
#[doc(alias = "compute_txid")]
Copy link
Contributor

Choose a reason for hiding this comment

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

I thought we should add alias = "txid" on the compute_txid, so when someone types tx.txid the LSP will suggest compute_txid? But I might be wrong. @Kixunil might know better.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

ah oops, yeah that's an easy change. I don't currently use LSP so I don't care either way.

Copy link
Collaborator

Choose a reason for hiding this comment

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

@dpc yes, needs to be the other way around.

}

#[deprecated(since = "0.31.0", note = "use compute_txid() instead")]
#[doc(alias = "compute_txid")]
#[doc(hidden)]
Copy link
Contributor

Choose a reason for hiding this comment

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

doc(hidden) seems unnecessary and might just confuse people. Deprecation message seems like enough. A docstring explaining to use new name seem more helpful.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

There's a lint that fails without doc(hidden)

Copy link
Collaborator

Choose a reason for hiding this comment

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

Yes, doc(hidden) is wrong and so is the lint. Which lint is that? Just turn it off and I'll happily complain at the repo of whoever came up with such nonsense..

Copy link
Contributor Author

Choose a reason for hiding this comment

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

The lint is defined here: https://github.com/rust-bitcoin/rust-bitcoin/blob/master/bitcoin/src/lib.rs#L36

#![warn(missing_docs)]

I could change the lint level, but I assumed it was put in place for a reason to ensure a good level of documentation. Ideally this lint wouldn't complain if there's a deprecated attribute..

Copy link
Collaborator

Choose a reason for hiding this comment

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

Oh, I didn't notice you didn't write the documentation. You have to add documentation even when it's deprecated. Or maybe especially because people will read it to understand deprecation better, so write a good explanation there.

@@ -773,7 +773,7 @@ impl Transaction {
#[inline]
Copy link
Collaborator

Choose a reason for hiding this comment

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

Why this commit? We have a CI job for this.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Running cargo +nightly fmt before the CI weekly job runs formats all files yet to be formatted by the CI job.

Copy link
Collaborator

Choose a reason for hiding this comment

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

Then just don't do it or only commit relevant changes.

bitcoin/src/blockdata/transaction.rs Outdated Show resolved Hide resolved
}

#[deprecated(since = "0.31.0", note = "use compute_txid() instead")]
#[doc(alias = "compute_txid")]
Copy link
Collaborator

Choose a reason for hiding this comment

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

@dpc yes, needs to be the other way around.

}

#[deprecated(since = "0.31.0", note = "use compute_txid() instead")]
#[doc(alias = "compute_txid")]
#[doc(hidden)]
Copy link
Collaborator

Choose a reason for hiding this comment

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

Yes, doc(hidden) is wrong and so is the lint. Which lint is that? Just turn it off and I'll happily complain at the repo of whoever came up with such nonsense..

@Kixunil
Copy link
Collaborator

Kixunil commented Jan 20, 2024

Oh, one more thing: the same applies to wtxid which should be renamed accordingly as well.

@Kixunil Kixunil added the 1.0 Issues and PRs required or helping to stabilize the API label Jan 20, 2024
@Kixunil Kixunil changed the title Rename txid to compute txid Rename txid to compute_txid Jan 22, 2024
@Kixunil Kixunil added the C-bitcoin PRs modifying the bitcoin crate label Jan 22, 2024
@github-actions github-actions bot added the C-internals PRs modifying the internals crate label Jan 23, 2024
@yancyribbens
Copy link
Contributor Author

Renamed ntxid and wtxid as well in this PR.

yancy added 2 commits January 23, 2024 15:57
Computing the txid is computationally expensive, so rename the method
accordingly.
Computing the wtxid is computationally expensive, so rename the method
accordingly.
Copy link
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.

One last typo, the rest looks good.

@@ -679,11 +679,21 @@ impl Transaction {
/// Maximum transaction weight for Bitcoin Core 25.0.
pub const MAX_STANDARD_WEIGHT: Weight = Weight::from_wu(400_000);

/// Computes a "normalized TXID" which does not include any signatures.
///
/// This method is deprecated. Use `ntxid` instead.
Copy link
Collaborator

Choose a reason for hiding this comment

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

Use compute_ntxid

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Thanks, good catch.

Computing the ntxid is computationally expensive, so rename the method
accordingly.
Copy link
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 7af3a58

@apoelstra
Copy link
Member

BTW we could arguably drop ntxid entirely. This is a pre-segwit thing that lets you emulate segwit in one important way (identifying transactions independent of witness data, which pre-segwit means "hashing the transaction without the scriptSigs).

On the one hand it's an obscure non-standardized legacy thing. But on the other hand, when you are using pre-segwit transactions, it comes in handy.

In any case, out of scope for this PR.

Copy link
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 7af3a58

@Kixunil
Copy link
Collaborator

Kixunil commented Jan 23, 2024

But on the other hand, when you are using pre-segwit transactions, it comes in handy.

Looks useful enough to me.

Copy link
Member

@tcharding tcharding left a comment

Choose a reason for hiding this comment

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

ACK 7af3a58

@apoelstra apoelstra merged commit cf3a7bb into rust-bitcoin:master Jan 24, 2024
31 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
1.0 Issues and PRs required or helping to stabilize the API C-bitcoin PRs modifying the bitcoin crate C-internals PRs modifying the internals crate ci
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Consider renaming txid to compute_txid or similar.
6 participants