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

node-data: change hash method on transaction to digest #3014

Open
Neotamandua opened this issue Nov 18, 2024 · 0 comments
Open

node-data: change hash method on transaction to digest #3014

Neotamandua opened this issue Nov 18, 2024 · 0 comments

Comments

@Neotamandua
Copy link
Member

Summary

Transaction hash and transaction ID are often used as semantically equivalent terms in the crypto/blockchain world. To avoid any ambiguity, we should refrain from employing the terms "hash" and "id" in a manner that result in their denotations having different meanings (different hashes/values).

Relevant Context

  • The value of hash(&self) is only being used in the Merkle tree.
  • The value of id(&self) is the actual transaction identifier being used in the explorer, wallet, to identify transactions etc. - This is the equivalent of the txID/txHash terminology on other chains.

impl Transaction {
/// Computes the hash of the transaction.
///
/// This method returns the hash of the entire
/// transaction in its serialized form
///
/// ### Returns
/// An array of 32 bytes representing the hash of the transaction.
pub fn hash(&self) -> [u8; 32] {
sha3::Sha3_256::digest(self.inner.to_var_bytes()).into()
}
/// Computes the transaction ID.
///
/// The transaction ID is a unique identifier for the transaction.
/// Unlike the [`hash()`](#method.hash) method, which is computed over the
/// entire transaction, the transaction ID is derived from specific
/// fields of the transaction and serves as a unique identifier of the
/// transaction itself.
///
/// ### Returns
/// An array of 32 bytes representing the transaction ID.
pub fn id(&self) -> [u8; 32] {
self.inner.hash().to_bytes()
}

Possible Solution (optional)

As hash(&self) is rarely used and is not really needed by end-users or integrators, we should introduce another name for it (potentially digest) so that the value of id(&self) can be safely referred to as TxID or TxHash.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant