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

Create types for unmined transactions and their IDs #2634

Merged
merged 8 commits into from
Aug 18, 2021

Conversation

teor2345
Copy link
Contributor

@teor2345 teor2345 commented Aug 16, 2021

Motivation

Zebra's mempool needs to handle unmined v4 and v5 transactions.

These transactions have different unique identifiers.

Specifications

The transaction ID of a version 4 or earlier transaction is the SHA-256d hash of the transaction encoding in the
pre-v5 format described above.

The transaction ID of a version 5 transaction is as defined in [ZIP-244].

A v5 transaction also has a wtxid (used for example in the peer-to-peer protocol) as defined in [ZIP-239].

https://zips.z.cash/protocol/protocol.pdf#txnidentifiers
https://zips.z.cash/zip-0239
https://zips.z.cash/zip-0244

Solution

  • Create an UnminedTxId enum, which holds a narrow or wide transaction ID, depending on version
    • Add accessor methods for the parts of an UnminedTxId
  • Create an UnminedTx struct, which holds a transaction and its unmined ID

Review

This PR blocks merging other mempool PRs that handle transaction IDs.

It's based on PR #2618, so it might need a rebase on main when that PR merges.

Reviewer Checklist

  • Code implements Specs
  • Code makes sense

We'll test this code when we use these types in zebra-network and in zebrad's mempool.

Follow Up Work

Use these types in internal protocol messages in zebra-network.


This change is Reviewable

@teor2345 teor2345 added C-design Category: Software design work A-rust Area: Updates to Rust code C-enhancement Category: This is an improvement NU-5 Network Upgrade: NU5 specific tasks P-Medium labels Aug 16, 2021
@teor2345 teor2345 requested a review from a team August 16, 2021 04:48
@teor2345 teor2345 self-assigned this Aug 16, 2021
Base automatically changed from wtxid-struct-network to main August 16, 2021 21:26
@teor2345 teor2345 requested a review from dconnolly August 16, 2021 22:01
@teor2345 teor2345 force-pushed the unmined-transaction-wtx-ids branch from fca3cfb to a9f649f Compare August 16, 2021 22:30
@teor2345 teor2345 force-pushed the unmined-transaction-wtx-ids branch from d081e20 to 724c076 Compare August 17, 2021 04:16
Comment on lines 39 to 49
pub enum UnminedTxId {
/// A narrow unmined transaction identifier.
///
/// Used to uniquely identify transaction versions 1-4.
Narrow(Hash),

/// A wide unmined transaction identifier.
///
/// Used to uniquely identify transaction version 5.
Wide(WtxId),
}
Copy link
Contributor

Choose a reason for hiding this comment

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

These TxIds still apply post-mining though, right? They are not exclusively for un-mined transactions

Copy link
Contributor Author

@teor2345 teor2345 Aug 17, 2021

Choose a reason for hiding this comment

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

For v1-v4 transactions, the transaction::Hash is a unique identifier pre-mining (mempool and client) and post-mining (blockchain).

For v5 transactions, the WtxId uniquely identifies a pre-mined transaction.
But post-mining, only the transaction::Hash in their WtxId.id is required for unique identification.

This is because v5 transactions have a non-malleable transaction::Hash, which only covers the effects of the transaction (transparent and shielded spends and outputs). The authorizing data (proofs, signatures, and scripts) can change without changing the ID.

I've tried to update the documentation to clarify.
What do you think?

Suggested change
pub enum UnminedTxId {
/// A narrow unmined transaction identifier.
///
/// Used to uniquely identify transaction versions 1-4.
Narrow(Hash),
/// A wide unmined transaction identifier.
///
/// Used to uniquely identify transaction version 5.
Wide(WtxId),
}
pub enum UnminedTxId {
/// A narrow unmined transaction identifier.
///
/// Used to uniquely identify unmined version 1-4 transactions.
/// (After v1-4 transactions are mined, they can be uniquely identified using the same [`transaction::Hash`].)
Narrow(Hash),
/// A wide unmined transaction identifier.
///
/// Used to uniquely identify unmined version 5 transactions.
/// (After v5 transactions are mined, they can be uniquely identified using only their `WtxId.id`.)
///
/// For more details, see [`WtxId`].
Wide(WtxId),
}

Copy link
Contributor Author

@teor2345 teor2345 left a comment

Choose a reason for hiding this comment

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

Doc updates to clarify wide vs narrow transaction IDs.

zebra-chain/src/transaction/hash.rs Outdated Show resolved Hide resolved
zebra-chain/src/transaction/unmined.rs Outdated Show resolved Hide resolved
Comment on lines 39 to 49
pub enum UnminedTxId {
/// A narrow unmined transaction identifier.
///
/// Used to uniquely identify transaction versions 1-4.
Narrow(Hash),

/// A wide unmined transaction identifier.
///
/// Used to uniquely identify transaction version 5.
Wide(WtxId),
}
Copy link
Contributor Author

@teor2345 teor2345 Aug 17, 2021

Choose a reason for hiding this comment

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

For v1-v4 transactions, the transaction::Hash is a unique identifier pre-mining (mempool and client) and post-mining (blockchain).

For v5 transactions, the WtxId uniquely identifies a pre-mined transaction.
But post-mining, only the transaction::Hash in their WtxId.id is required for unique identification.

This is because v5 transactions have a non-malleable transaction::Hash, which only covers the effects of the transaction (transparent and shielded spends and outputs). The authorizing data (proofs, signatures, and scripts) can change without changing the ID.

I've tried to update the documentation to clarify.
What do you think?

Suggested change
pub enum UnminedTxId {
/// A narrow unmined transaction identifier.
///
/// Used to uniquely identify transaction versions 1-4.
Narrow(Hash),
/// A wide unmined transaction identifier.
///
/// Used to uniquely identify transaction version 5.
Wide(WtxId),
}
pub enum UnminedTxId {
/// A narrow unmined transaction identifier.
///
/// Used to uniquely identify unmined version 1-4 transactions.
/// (After v1-4 transactions are mined, they can be uniquely identified using the same [`transaction::Hash`].)
Narrow(Hash),
/// A wide unmined transaction identifier.
///
/// Used to uniquely identify unmined version 5 transactions.
/// (After v5 transactions are mined, they can be uniquely identified using only their `WtxId.id`.)
///
/// For more details, see [`WtxId`].
Wide(WtxId),
}

jvff
jvff previously approved these changes Aug 17, 2021
zebra-chain/src/transaction/unmined.rs Show resolved Hide resolved
zebra-chain/src/transaction/unmined.rs Show resolved Hide resolved
zebra-chain/src/transaction/unmined.rs Outdated Show resolved Hide resolved
Copy link
Contributor Author

@teor2345 teor2345 left a comment

Choose a reason for hiding this comment

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

Some comment clarifications about v5 transactions

zebra-chain/src/transaction/hash.rs Show resolved Hide resolved
zebra-chain/src/transaction/unmined.rs Show resolved Hide resolved
zebra-chain/src/transaction/unmined.rs Outdated Show resolved Hide resolved
zebra-chain/src/transaction/unmined.rs Outdated Show resolved Hide resolved
@teor2345 teor2345 requested review from jvff and dconnolly August 17, 2021 22:17
@teor2345 teor2345 merged commit 84c5f61 into main Aug 18, 2021
@teor2345 teor2345 deleted the unmined-transaction-wtx-ids branch August 18, 2021 05:52
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-rust Area: Updates to Rust code C-design Category: Software design work C-enhancement Category: This is an improvement NU-5 Network Upgrade: NU5 specific tasks
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants