Skip to content

rpc: add wtxid to mempool entry output#11203

Merged
laanwj merged 2 commits intobitcoin:masterfrom
sdaftuar:2017-08-add-wtxid-to-mempool-entry
Sep 6, 2017
Merged

rpc: add wtxid to mempool entry output#11203
laanwj merged 2 commits intobitcoin:masterfrom
sdaftuar:2017-08-add-wtxid-to-mempool-entry

Conversation

@sdaftuar
Copy link
Member

We already cache this information in the mempool, so including it in the output of rpc calls is basically free.

@promag
Copy link
Contributor

promag commented Aug 31, 2017

Ideally this change should affect some functional tests. IMO there should be a test that asserts the entry keys.

@instagibbs
Copy link
Member

utACK 7e5d596

@sdaftuar
Copy link
Member Author

@promag Added a test.

Copy link
Member

@luke-jr luke-jr left a comment

Choose a reason for hiding this comment

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

Should be "hash" (not "wxtxid") to be clear and consistent with the rest of the RPC interface.

@sdaftuar
Copy link
Member Author

sdaftuar commented Sep 2, 2017

wtxid is defined in BIP 141. Perhaps we should fix the rest of the RPC interface instead (how many places do we return this currently?); hash seems less informative to me...

@luke-jr
Copy link
Member

luke-jr commented Sep 2, 2017

It's a hash of the transaction. It's not a transaction id. wtxid makes no sense.

@sipa
Copy link
Member

sipa commented Sep 2, 2017

@luke-jr Imagine that at some point a new piece of extra witness data gets added in a softfork way. At that point there will be 3 hashes; the txid, the hash-with-witness-but-not-witness2, and the hash-of-everything. If we have a field for "overall hash, with everything included", it will break software that knows about witnesses but not witness2.

So, while I don't care much about hash vs txid nomenclature, it makes sense to have a name that is segwit-specific. Just "hash" sets the wrong expectation going further, and given that BIP141 calls it wtxid, I think that's perfectly good choice.

@jonasschnelli
Copy link
Contributor

utACK 617c459.

@luke-jr
Copy link
Member

luke-jr commented Sep 3, 2017

@sipa It would seem there are two things right now: txid and hash of the entire tx. If we add a third state, both of these things would remain the same. Hashes are opaque, so it's not like software can see it and fail to try to decode it...? What use case(s) do you have in mind?

@meshcollider
Copy link
Contributor

utACK 617c459, agree with sipa on the hash v. wtxid because I think consistency with BIP 141 is clearer

@sipa
Copy link
Member

sipa commented Sep 3, 2017

@luke-jr My point is that a "hash of all the data, regardless of what you think it contains" is not useful to anyone. It arbitrarily changes meaning as witnesses are added (if ever).

@promag
Copy link
Contributor

promag commented Sep 4, 2017

Still missing tests for getrawmempool, getmempooldescendants and getmempoolancestors (with verbose=true) as these also use entryToJSON().

@sdaftuar
Copy link
Member Author

sdaftuar commented Sep 5, 2017

@promag If you think that's important then I think it'd make more sense to have a separate test that checks the output of those rpc's to ensure they are consistent; I'm going to leave this PR alone.

info.push_back(Pair("ancestorcount", e.GetCountWithAncestors()));
info.push_back(Pair("ancestorsize", e.GetSizeWithAncestors()));
info.push_back(Pair("ancestorfees", e.GetModFeesWithAncestors()));
info.push_back(Pair("wtxid", mempool.vTxHashes[e.vTxHashesIdx].first.ToString()));
Copy link
Member

@laanwj laanwj Sep 5, 2017

Choose a reason for hiding this comment

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

Is it guaranteed that the entry exists in mempool.vTxHashes? if not, using [] will potentially cause a leak by adding an empty record.

Copy link
Member Author

@sdaftuar sdaftuar Sep 6, 2017

Choose a reason for hiding this comment

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

Yes, it's guaranteed -- this is used in compact block reconstruction.

See CTxMemPool::removeUnchecked() and ::addUnchecked() for the code that keeps this in sync with the mempool entries.

Copy link
Member

Choose a reason for hiding this comment

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

Thanks for the explanation, that makes sense.
Maybe we could add an assertion here assert(mempool.vTxHashes.count(e.vTxHashesIdx)), just in case. But I don't insist.

Copy link
Member

Choose a reason for hiding this comment

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

@laanwj vTxHashes is a vector - calling [] out of bounds doesn't add an empty record, it's just undefined behaviour.

Copy link
Member

Choose a reason for hiding this comment

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

Oh, oops, never mind.

@laanwj laanwj changed the title RPC: add wtxid to mempool entry output rpc: add wtxid to mempool entry output Sep 6, 2017
@laanwj laanwj merged commit 617c459 into bitcoin:master Sep 6, 2017
laanwj added a commit that referenced this pull request Sep 6, 2017
617c459 qa: rpc test for wtxid in mempool entry (Suhas Daftuar)
7e5d596 RPC: add wtxid to mempool entry output (Suhas Daftuar)

Pull request description:

  We already cache this information in the mempool, so including it in the output of rpc calls is basically free.

Tree-SHA512: 2757e1bfca028103937e4b76ce1a5d805846bad5d3d9dd631dcc5f87721bcc0e9d19e437e02053ef1dd3b38b503f0fca8c0b8492cac37dfbd70256a3665f704c
luke-jr pushed a commit to bitcoinknots/bitcoin that referenced this pull request Nov 11, 2017
luke-jr pushed a commit to bitcoinknots/bitcoin that referenced this pull request Nov 11, 2017
@bitcoin bitcoin locked as resolved and limited conversation to collaborators Sep 8, 2021
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

9 participants