- stop checking unspent UTXOs for a transaction when txindex is not enabled, as per conversation here: #3220 (comment)
- code contributed by sipa
[RPC] Remove lookup to UTXO set from GetTransaction #15159
pull amitiuttarwar wants to merge 1 commits into bitcoin:master from amitiuttarwar:13931_rebase changing 12 files +35 −28-
amitiuttarwar commented at 11:59 PM on January 13, 2019: contributor
- fanquake added the label RPC/REST/ZMQ on Jan 14, 2019
-
DrahtBot commented at 2:18 AM on January 14, 2019: member
<!--e57a25ab6845829454e8d69fc972939a-->
The following sections might be updated with supplementary metadata relevant to reviewers and maintainers.
<!--174a7506f384e20aa4161008e828411d-->
Conflicts
Reviewers, this pull request conflicts with the following ones:
- #14802 (rpc: faster getblockstats using BlockUndo data by FelixWeis)
- #14053 (Add address-based index (attempt 4?) by marcinja)
- #13903 (Significantly reduce GetTransaction cs_main locking (TheBlueMatt) by MarcoFalke)
If you consider this pull request important, please also help to review the conflicting pull requests. Ideally, start with the one that should be merged first.
-
in src/rpc/rawtransaction.cpp:252 in 51fe3e42f6 outdated
264 | - // Allow txindex to catch up if we need to query it and before we acquire cs_main. 265 | - if (g_txindex && !pblockindex) { 266 | - g_txindex->BlockUntilSyncedToCurrentChain(); 267 | - } 268 | + // Allow txindex to catch up if we need to query it and before we acquire cs_main. 269 | + if (!pblockindex) {
practicalswift commented at 1:42 PM on January 14, 2019:pblockindex == nullptrwill always hold here, right?in test/functional/wallet_basic.py:26 in 51fe3e42f6 outdated
22 | @@ -23,6 +23,7 @@ class WalletTest(BitcoinTestFramework): 23 | def set_test_params(self): 24 | self.num_nodes = 4 25 | self.setup_clean_chain = True 26 | + self.extra_args = [[],[], ["-txindex"], []]
practicalswift commented at 1:43 PM on January 14, 2019:Missing whitespace after
,:-)laanwj commented at 3:37 PM on January 14, 2019: memberConcept ACK
MarcoFalke commented at 3:48 PM on January 14, 2019: memberSlightly tend to NACK. If I am not mistaken, this will force some user to enable
-txindex, which seems unintended. Otherwise they might run into a race condition where they are first notified of a tx in the mempool, then try togetrawtransactionthat tx, which might sometimes fail because it was added to a block in the meantime.in src/rpc/rawtransaction.cpp:70 in 51fe3e42f6 outdated
71 | - "enabled, it also works for blockchain transactions. If the block which contains the transaction\n" 72 | - "is known, its hash can be provided even for nodes without -txindex. Note that if a blockhash is\n" 73 | - "provided, only that block will be searched and if the transaction is in the mempool or other\n" 74 | - "blocks, or if this node does not have the given block available, the transaction will not be found.\n" 75 | - "DEPRECATED: for now, it also works for transactions with unspent outputs.\n" 76 | + "\nNOTE: By default this function only works for mempool transactions. When called with a blockhash\n"
jnewbery commented at 3:50 PM on January 14, 2019:I'd personally remove the
NOTE:here (adding "Note:" or "Note that" almost always adds zero information to a sentence :slightly_smiling_face: )jnewbery commented at 3:50 PM on January 14, 2019: memberThanks for picking this up @amitiuttarwar! Looks good. I have a few high-level comments.
- The PR description (https://github.com/bitcoin/bitcoin/pull/15159#issue-244314271) gets added to the commit log when the PR is merged (see https://github.com/bitcoin/bitcoin/commit/1cfbb16b5da85647441bf84b4120d01e04d813ed for example). For that reason, I try to keep my PR descriptions as pure descriptions of the new/changed functionality, and add contextual notes (eg if this PR is the rebase of commits from another PR) to the first comment in the PR. See #13926 for example.
- We try to make sure that the binary builds and all tests pass on every intermediate commit, so we can use git bisect. That means that if functionality changes and the tests need to change to still pass, then the product and test changes should be in the same commit. For this PR, I suggest you have two commits: one for 'Update getrawtransaction interface' and one for '[RPC] Simplify gettxoutproof method'. If you're worried about losing authorship information in the commit logs, you can always add an extra line to the commit message like "Additional code contributed by <author>" (don't use @ or that user will get annoying notifications in github), although in this case I don't think that matters too much. I'm fine for you to use my code without the authorship data.
- As you've already pointed out to me, the RPC help text for gettxoutproof should be updated.
jnewbery commented at 3:53 PM on January 14, 2019: memberOtherwise they might run into a race condition where they are first notified of a tx in the mempool, then try to getrawtransaction that tx, which might sometimes fail because it was added to a block in the meantime.
Even without this change, that race condition exists (if the tx's outputs are spent in the same block).
I think the race is sufficiently rare that it's not realistically an issue, but we should definitely make sure that the error messages are clear enough in this case - ie it's explicit that the tx was not found in the mempool.
amitiuttarwar force-pushed on Jan 18, 2019amitiuttarwar force-pushed on Jan 18, 2019amitiuttarwar force-pushed on Jan 18, 2019amitiuttarwar force-pushed on Jan 18, 2019amitiuttarwar commented at 7:39 AM on January 18, 2019: contributorthanks for the feedback @jnewbery. LMK if the PR looks okay now.
in src/rpc/rawtransaction.cpp:211 in 3e6c82a785 outdated
206 | @@ -208,10 +207,8 @@ static UniValue gettxoutproof(const JSONRPCRequest& request) 207 | throw std::runtime_error( 208 | RPCHelpMan{"gettxoutproof", 209 | "\nReturns a hex-encoded proof that \"txid\" was included in a block.\n" 210 | - "\nNOTE: By default this function only works sometimes. This is when there is an\n" 211 | - "unspent output in the utxo for this transaction. To make it always work,\n" 212 | - "you need to maintain a transaction index, using the -txindex command line option or\n" 213 | - "specify the block in which the transaction is included manually (by blockhash).\n", 214 | + "You must either manually specify the blockhash of the block including the transaction\n" 215 | + "or maintain a transaction index, using the -txindex command line option."
fanquake commented at 8:13 AM on January 18, 2019:This doesn't currently compile, looks like you are missing a comma here.
amitiuttarwar commented at 3:48 PM on January 18, 2019:oops. fixed.
amitiuttarwar force-pushed on Jan 18, 2019in src/rpc/rawtransaction.cpp:272 in affe684a55 outdated
273 | 274 | - if (pblockindex == nullptr) 275 | - { 276 | CTransactionRef tx; 277 | - if (!GetTransaction(oneTxid, tx, Params().GetConsensus(), hashBlock, false) || hashBlock.IsNull()) 278 | + if (!GetTransaction(oneTxid, tx, Params().GetConsensus(), hashBlock) || hashBlock.IsNull())
jnewbery commented at 4:01 PM on January 18, 2019:Should be part of the first commit.
in test/functional/rpc_txoutproof.py:16 in affe684a55 outdated
12 | @@ -13,7 +13,7 @@ def set_test_params(self): 13 | self.num_nodes = 4 14 | self.setup_clean_chain = True 15 | # Nodes 0/1 are "wallet" nodes, Nodes 2/3 are used for testing 16 | - self.extra_args = [[], [], [], ["-txindex"]] 17 | + self.extra_args = [[], [], ["-txindex"], ["-txindex"]]
jnewbery commented at 4:02 PM on January 18, 2019:changes to this file should be part of the second commit
in test/functional/feature_segwit.py:52 in affe684a55 outdated
47 | @@ -48,17 +48,20 @@ def set_test_params(self): 48 | "-rpcserialversion=0", 49 | "-vbparams=segwit:0:999999999999", 50 | "-addresstype=legacy", 51 | + "-txindex"
jnewbery commented at 4:03 PM on January 18, 2019:I'm still not thrilled about adding
txindexto a bunch of tests. See my comment here: https://github.com/bitcoin/bitcoin/pull/13931/files#r216084729
amitiuttarwar commented at 6:01 AM on January 21, 2019:I added a todo / note on this particular file & am happy to work on updating tests in a future PR. To clarify, this PR adds
txindexto many tests. Are you commenting on the set as a whole, or specifically thesefeature_segwittests?
jnewbery commented at 10:23 PM on January 22, 2019:I would add a short comment to each of the tests. Something like "txindex required for getrawtransaction call"
amitiuttarwar commented at 5:37 AM on January 24, 2019:I added todos to the tests. Not my favorite to be littering the code, but IMO a comment without the todo makes it seem intentional instead of transient.
jnewbery commented at 4:04 PM on January 18, 2019: memberLooking at this again, I recommend you drop the second commit entirely and save it for a follow-up PR.
Currently the first commit doesn't build on its own, since the change here: https://github.com/bitcoin/bitcoin/pull/15159/files#diff-01aa7d1d32f1b9e5a836c9c411978918R259 needs to be part of the first commit. The change to
gettxoutproofshould be removed from the first commit (since the gettxoutproof behaviour only changes in the second commit).amitiuttarwar force-pushed on Jan 21, 2019amitiuttarwar commented at 6:00 AM on January 21, 2019: contributorok updated so this PR focuses solely on changes to
getrawtransaction.laanwj commented at 5:43 PM on January 21, 2019: memberI think this needs mention in the release notes due to changed
getrawtransactionsemantics?in src/rpc/rawtransaction.cpp:210 in 94af589358 outdated
206 | @@ -208,10 +207,8 @@ static UniValue gettxoutproof(const JSONRPCRequest& request) 207 | throw std::runtime_error( 208 | RPCHelpMan{"gettxoutproof", 209 | "\nReturns a hex-encoded proof that \"txid\" was included in a block.\n" 210 | - "\nNOTE: By default this function only works sometimes. This is when there is an\n" 211 | - "unspent output in the utxo for this transaction. To make it always work,\n" 212 | - "you need to maintain a transaction index, using the -txindex command line option or\n" 213 | - "specify the block in which the transaction is included manually (by blockhash).\n", 214 | + "You must either manually specify the blockhash of the block including the transaction\n"
jnewbery commented at 10:22 PM on January 22, 2019:This should be in the follow-up PR (for changing gettxoutproof)
amitiuttarwar commented at 5:31 AM on January 24, 2019:Doesn't this functionality change with this PR because gettxoutproof uses GetTransaction which is no longer checking the unspent utxo set as per the changes here: https://github.com/bitcoin/bitcoin/pull/15159/files/94af589358f2e1ede359263494535cda67313c8d#diff-24efdb00bfbe56b140fb006b562cc70bL1014
jnewbery commented at 4:29 PM on January 24, 2019:no. That's what I thought originally (which prompted my comment here: #13931 (review)). In fact, in
gettxoutproof(),GetTransaction()is currently called withfAllowSlowset tofalseandblockIndexset tonullptr. That means that the change toGetTransaction()makes no change to the behaviour ofgettxoutproof().
amitiuttarwar commented at 12:56 AM on January 27, 2019:ahhh. gotcha
amitiuttarwar force-pushed on Jan 24, 2019amitiuttarwar commented at 6:36 AM on January 24, 2019: contributorAppVeyor build is failing on a test that passes locally. I'll look into it soon, but if anyone cruises through here and has any pointers (first time using AppVeyor), feel free to share :)
jnewbery commented at 2:53 PM on January 24, 2019: memberAppVeyor has a lot of spurious failures. It can be ignored!
in doc/release-notes.md:250 in 91ec543001 outdated
245 | @@ -246,6 +246,11 @@ in the Low-level Changes section below. 246 | 247 | - See the [Mining](#mining) section for changes to `getblocktemplate`. 248 | 249 | +- The `getrawtransaction` RPC no longer checks the unspent UTXO set for 250 | + a transaction by default. It continues to check the mempool, a specific
jnewbery commented at 4:40 PM on January 24, 2019:Remove
by defaulthere. The unspent UTXO set is never checked after this PR.in doc/release-notes.md:251 in 91ec543001 outdated
245 | @@ -246,6 +246,11 @@ in the Low-level Changes section below. 246 | 247 | - See the [Mining](#mining) section for changes to `getblocktemplate`. 248 | 249 | +- The `getrawtransaction` RPC no longer checks the unspent UTXO set for 250 | + a transaction by default. It continues to check the mempool, a specific 251 | + block, or the mempool and tx index based on if a blockhash is passed in
jnewbery commented at 4:44 PM on January 24, 2019:This sentence is a bit imprecise. I think it'd be better to give the exact logic (if called with blockhash: that block is checked; if called without blockhash and txindex disabled: mempool is checked; if called without blockhash and txindex enabled: mempool and txindex is checked)
in test/functional/rpc_psbt.py:22 in 91ec543001 outdated
18 | @@ -19,6 +19,8 @@ class PSBTTest(BitcoinTestFramework): 19 | def set_test_params(self): 20 | self.setup_clean_chain = False 21 | self.num_nodes = 3 22 | + # TODO: remove -txindex. Currently required for getrawtransaction call.
MarcoFalke commented at 11:17 PM on January 24, 2019:getrawtransactionis never called in this test, it seems
MarcoFalke commented at 11:53 PM on January 24, 2019:Also, I don't think those TODOs should be added at all. They get added and never fixed, then get stale.
Regardless, fixing the TODO would require to implement some sort of (in-memory) database for transactions in some tests? Might as well just use the txindex feature of Bitcoin Core, with the benefit that it gets more test exposure.
jnewbery commented at 3:32 PM on January 25, 2019:I disagree.
-txindexis not how we recommend people run bitcoind. It's best that the functional tests reflect the way that we expect bitcoind to be run. Adding unusual options just to make the test run means that we could introduce a regression and it not get caught by the test suite (eggetrawtransactionstops working unless-txindexis set). @amitiuttarwar has already stated that she intends to fix up the tests in a follow-up PR: #15159 (review)
amitiuttarwar commented at 1:25 AM on January 27, 2019:getrawtransactionis never called in this test, it seemsNot directly, but invoked through
test_framework.util#find_output. https://github.com/bitcoin/bitcoin/blob/02021ec65ba65cb36a5412793a8c538936131044/test/functional/rpc_psbt.py#L166 https://github.com/bitcoin/bitcoin/blob/02021ec65ba65cb36a5412793a8c538936131044/test/functional/test_framework/util.py#L418
MarcoFalke commented at 10:58 PM on January 29, 2019:Ah thanks, I guess it is fine to leave as is.
in src/validation.cpp:997 in 91ec543001 outdated
993 | @@ -994,13 +994,11 @@ bool AcceptToMemoryPool(CTxMemPool& pool, CValidationState &state, const CTransa 994 | * Return transaction in txOut, and if it was found inside a block, its hash is placed in hashBlock. 995 | * If blockIndex is provided, the transaction is fetched from the corresponding block. 996 | */ 997 | -bool GetTransaction(const uint256& hash, CTransactionRef& txOut, const Consensus::Params& consensusParams, uint256& hashBlock, bool fAllowSlow, CBlockIndex* blockIndex) 998 | +bool GetTransaction(const uint256& hash, CTransactionRef& txOut, const Consensus::Params& consensusParams, uint256& hashBlock, CBlockIndex* block_index)
Empact commented at 12:51 AM on January 25, 2019:nit:
block_indexcould beconst CBlockIndex* const block_index
amitiuttarwar commented at 2:38 AM on January 27, 2019:👌 updated
amitiuttarwar force-pushed on Jan 27, 2019amitiuttarwar force-pushed on Jan 27, 2019[RPC] Update getrawtransaction interface 04da9f4834amitiuttarwar force-pushed on Jan 27, 2019jnewbery commented at 9:43 PM on January 29, 2019: memberutACK 04da9f4834e1651da65ceb6379950cef9450591c
promag commented at 11:13 PM on January 29, 2019: memberIf
-txindexis enabled then it should be used first? Is there another reason to enable it other than speed up transaction lookup (so it doesn't stress cs_main or mempool.cs under load)? Just asking it now since this PR changes its behavior.amitiuttarwar commented at 1:14 AM on January 30, 2019: contributorhey @promag, can you clarify your questions?
- reason to enable
-txindexfor users running bitcoind? or in the tests? - what changed behavior are you referring to? the way
GetTransactionbehaves when-txindexhas not changed much.
promag commented at 3:24 PM on January 30, 2019: member@amitiuttarwar decided to create an issue with the question #15293.
jnewbery commented at 3:29 PM on January 30, 2019: memberI think the question about whether to try txindex before mempool can be disregarded in this PR, since it doesn't change that behaviour. #15293 can track that question, and the change described there could be merged before or after this PR if it's wanted.
in src/rpc/rawtransaction.cpp:76 in 04da9f4834
77 | + "argument, getrawtransaction will return the transaction if the specified block is available and\n" 78 | + "the transaction is found in that block. When called without a blockhash argument, getrawtransaction\n" 79 | + "will return the transaction if it is in the mempool, or if -txindex is enabled and the transaction\n" 80 | + "is in a block in the blockchain.\n" 81 | 82 | "\nReturn the raw transaction data.\n"
MarcoFalke commented at 3:52 PM on January 30, 2019:nit: Could move this up to the first line, since this is the oneline-summary of what the function does. The paragraph above is the implementation detail and interface documentation. Feel free to ignore, since you dind't introduce the issue.
MarcoFalke commented at 4:15 PM on January 30, 2019:Similarly, you could mention the corresponding raw transaction getter rpcs for the mempool and wallet, but that is another perpendicular doc cleanup fix.
MarcoFalke commented at 3:55 PM on January 30, 2019: memberutACK 04da9f4834e1651da65ceb6379950cef9450591c
MarcoFalke renamed this:[RPC] Update getrawtransaction
[RPC] Remove lookup to UTXO set from GetTransaction
on Jan 30, 2019in doc/release-notes.md:249 in 04da9f4834
245 | @@ -246,6 +246,12 @@ in the Low-level Changes section below. 246 | 247 | - See the [Mining](#mining) section for changes to `getblocktemplate`. 248 | 249 | +- The `getrawtransaction` RPC no longer checks the unspent UTXO set for
MarcoFalke commented at 4:18 PM on January 30, 2019:doc-nit: Change applies to rpc and rest
MarcoFalke referenced this in commit a47319dada on Jan 30, 2019MarcoFalke merged this on Jan 30, 2019MarcoFalke closed this on Jan 30, 2019promag commented at 4:21 PM on January 30, 2019: memberRestarted appveyor, which failed with
2019-01-27T02:59:07.394000Z TestFramework (ERROR): Assertion failed Traceback (most recent call last): File "C:\projects\bitcoin\test\functional\test_framework\test_framework.py", line 173, in main self.run_test() File "C:\projects\bitcoin/test/functional/wallet_txn_doublespend.py", line 114, in run_test sync_blocks(self.nodes) File "C:\projects\bitcoin\test\functional\test_framework\util.py", line 392, in sync_blocks raise AssertionError("Block sync timed out:{}".format("".join("\n {!r}".format(b) for b in best_hash))) AssertionError: Block sync timed out: '3080ca6e61d16e2bd8b236d733076c346d151670c26de9c27660b11771bf916d' '3080ca6e61d16e2bd8b236d733076c346d151670c26de9c27660b11771bf916d' '3f8f4778bbc8d606465fc0aeca065077722935875e3502af994f28bb740bc3ce' '3f8f4778bbc8d606465fc0aeca065077722935875e3502af994f28bb740bc3ce'amitiuttarwar deleted the branch on Jan 30, 2019MarcoFalke referenced this in commit 5c99bb0047 on Feb 1, 2019MarcoFalke referenced this in commit baf125b31d on Feb 5, 2019laanwj referenced this in commit a0d4e79b4d on Feb 27, 2019nikitasius commented at 11:53 AM on June 5, 2019: nonewell thats a most shittiest update you did.
- i obliged to call
gettransactionto get blockhash for tx i need - after this i need to call
getrawtransactionwith blockhash from previous call.
Before i did all in 1 call, not here are 2. What next?
MarcoFalke commented at 8:48 AM on June 9, 2019: member@nikitasius What is in
getrawtransactionthat is not ingettransaction?sipa commented at 10:42 AM on June 9, 2019: member@MarcoFalke I think the only missing thing is that
gettransactiononly returns the hex raw tx, and has no ability to decode it directly. You can of course usedecoderawtransactionon the hex output fromgettransactionto accomplish the same asgetrawtransaction(with txindex, and without knowing the block hash).nikitasius commented at 9:11 AM on June 10, 2019: none@MarcoFalke in my case:
vins here is a tx:
listunspent 3
[ { "txid": "b423b2b22d6d74376de2887c07f7c84ae890a93d541fcc6dbf3686f2923b2753", "vout": 0, "address": "2N4p68W5AfTJiEX6B5DUgp2eBWP1m2d9pSY", "redeemScript": "0014c13a875f4565d9b39cb7898a30e011e7b03d14ad", "scriptPubKey": "a9147ee08cf27aed73648f2ba5df2d6c70a60dc0c74587", "amount": 2.99988992, "confirmations": 22133, "spendable": true, "solvable": true, "desc": "sh(wpkh([4dc444eb/0'/1'/139']028dd079912c6bd68cc9d2872f1d810aece81ac1f5404105b68cefa571e8ecd0cd))#rtxpgrnv", "safe": true } ]gettransaction "b423b2b22d6d74376de2887c07f7c84ae890a93d541fcc6dbf3686f2923b2753"
{ "amount": -2.00000000, "fee": -0.00010746, "confirmations": 22133, "blockhash": "00000000000000409e394d133807fd4f6b0fd27ade24a6e717ee257e825167e1", "blockindex": 4, "blocktime": 1559505152, "txid": "b423b2b22d6d74376de2887c07f7c84ae890a93d541fcc6dbf3686f2923b2753", "walletconflicts": [ ], "time": 1559505089, "timereceived": 1559505089, "bip125-replaceable": "no", "details": [ { "address": "2NAzsxhZUwLEg8ii2tnrUH9wxrPC3edDDaQ", "category": "send", "amount": -2.00000000, "label": "", "vout": 1, "fee": -0.00010746, "abandoned": false } ], "hex": "02000000000101fb78a5db1271cb652e1716a1e00dc23409dc9801deea53da5cde50e11e6877900100000017160014feaec8c89d5f76a80a3c0694ba92a82d2f1bfda8fdffffff020078e1110000000017a9147ee08cf27aed73648f2ba5df2d6c70a60dc0c7458700c2eb0b0000000017a914c2bbb902207a6ea4961ec41da629225a30f95f5a870247304402206f0666187b110c8fd689a08db838150fd919d6df516f8e74b6a7bf632e392d17022023edc46d0cc41e1d98fc5042364a065d7bfb54e2b71d2cf794cc3a17e8daee8701210330e02dbd607553975a833664b9c663a1c1ee81d9f2221b784fe9465bf32db24f7e2f1700" }getrawtransaction b423b2b22d6d74376de2887c07f7c84ae890a93d541fcc6dbf3686f2923b2753 1 00000000000000409e394d133807fd4f6b0fd27ade24a6e717ee257e825167e1
{ "in_active_chain": true, "txid": "b423b2b22d6d74376de2887c07f7c84ae890a93d541fcc6dbf3686f2923b2753", "hash": "8d497a20df578b57a3190c5380816197b78ce92150c1b62a60e3d1ee4d26e7c9", "version": 2, "size": 247, "vsize": 166, "weight": 661, "locktime": 1519486, "vin": [ { "txid": "9077681ee150de5cda53eade0198dc0934c20de0a116172e65cb7112dba578fb", "vout": 1, "scriptSig": { "asm": "0014feaec8c89d5f76a80a3c0694ba92a82d2f1bfda8", "hex": "160014feaec8c89d5f76a80a3c0694ba92a82d2f1bfda8" }, "txinwitness": [ "304402206f0666187b110c8fd689a08db838150fd919d6df516f8e74b6a7bf632e392d17022023edc46d0cc41e1d98fc5042364a065d7bfb54e2b71d2cf794cc3a17e8daee8701", "0330e02dbd607553975a833664b9c663a1c1ee81d9f2221b784fe9465bf32db24f" ], "sequence": 4294967293 } ], "vout": [ { "value": 2.99988992, "n": 0, "scriptPubKey": { "asm": "OP_HASH160 7ee08cf27aed73648f2ba5df2d6c70a60dc0c745 OP_EQUAL", "hex": "a9147ee08cf27aed73648f2ba5df2d6c70a60dc0c74587", "reqSigs": 1, "type": "scripthash", "addresses": [ "2N4p68W5AfTJiEX6B5DUgp2eBWP1m2d9pSY" ] } }, { "value": 2.00000000, "n": 1, "scriptPubKey": { "asm": "OP_HASH160 c2bbb902207a6ea4961ec41da629225a30f95f5a OP_EQUAL", "hex": "a914c2bbb902207a6ea4961ec41da629225a30f95f5a87", "reqSigs": 1, "type": "scripthash", "addresses": [ "2NAzsxhZUwLEg8ii2tnrUH9wxrPC3edDDaQ" ] } } ], "hex": "02000000000101fb78a5db1271cb652e1716a1e00dc23409dc9801deea53da5cde50e11e6877900100000017160014feaec8c89d5f76a80a3c0694ba92a82d2f1bfda8fdffffff020078e1110000000017a9147ee08cf27aed73648f2ba5df2d6c70a60dc0c7458700c2eb0b0000000017a914c2bbb902207a6ea4961ec41da629225a30f95f5a870247304402206f0666187b110c8fd689a08db838150fd919d6df516f8e74b6a7bf632e392d17022023edc46d0cc41e1d98fc5042364a065d7bfb54e2b71d2cf794cc3a17e8daee8701210330e02dbd607553975a833664b9c663a1c1ee81d9f2221b784fe9465bf32db24f7e2f1700", "blockhash": "00000000000000409e394d133807fd4f6b0fd27ade24a6e717ee257e825167e1", "confirmations": 22137, "time": 1559505152, "blocktime": 1559505152 }- then i pick this vin array:
"vin": [ { "txid": "9077681ee150de5cda53eade0198dc0934c20de0a116172e65cb7112dba578fb", "vout": 1, "scriptSig": { "asm": "0014feaec8c89d5f76a80a3c0694ba92a82d2f1bfda8", "hex": "160014feaec8c89d5f76a80a3c0694ba92a82d2f1bfda8" }, "txinwitness": [ "304402206f0666187b110c8fd689a08db838150fd919d6df516f8e74b6a7bf632e392d17022023edc46d0cc41e1d98fc5042364a065d7bfb54e2b71d2cf794cc3a17e8daee8701", "0330e02dbd607553975a833664b9c663a1c1ee81d9f2221b784fe9465bf32db24f" ], "sequence": 4294967293 } ]- and call
getrawtransactionfor9077681ee150de5cda53eade0198dc0934c20de0a116172e65cb7112dba578fb:
{ "result": { "txid": "9077681ee150de5cda53eade0198dc0934c20de0a116172e65cb7112dba578fb", "hash": "58d247d5d571b95271b9b01603ac6283410d8c28d48fe69082431122029a1669", "version": 2, "size": 247, "vsize": 166, "weight": 661, "locktime": 0, "vin": [{ "txid": "ab904f2596bafe5c29110ebe053dbd3d609d238456c7ae97d8c916a1c0a27665", "vout": 0, "scriptSig": { "asm": "0014b56400beea1c0c592f9d89e1f182583c04360743", "hex": "160014b56400beea1c0c592f9d89e1f182583c04360743" }, "txinwitness": ["304402201ba93887222fdaac6001a1c54cea3fd78e1fc5b7d48f22c6ed647a330605746702205c4aaba5673efc4a21235cbbf5d61fd6e9ce83aa2fa25507db84a1ff3abdbca401", "0242adf8c0e977e622db8e2776b02129844fdc5d9fddf5bd963aa85ed87a8ee7ec"], "sequence": 4294967295 }], "vout": [{ "value": 11.90559816, "n": 0, "scriptPubKey": { "asm": "OP_HASH160 cabc590e4c35a02b44f77034cea6fcd823d6d18a OP_EQUAL", "hex": "a914cabc590e4c35a02b44f77034cea6fcd823d6d18a87", "reqSigs": 1, "type": "scripthash", "addresses": ["2NBjC7g1h3FN7oiLH21DRDCoSUyXhK5heGg"] } }, { "value": 4.99999738, "n": 1, "scriptPubKey": { "asm": "OP_HASH160 ec459c516bb17526fd4fffa02448c6b3f581c065 OP_EQUAL", "hex": "a914ec459c516bb17526fd4fffa02448c6b3f581c06587", "reqSigs": 1, "type": "scripthash", "addresses": ["2NEnWrBmNCmtwNQLsifKqkuRNxRtQsvKkd8"] } }], "hex": "020000000001016576a2c0a116c9d897aec75684239d603dbd3d05be0e11295cfeba96254f90ab0000000017160014b56400beea1c0c592f9d89e1f182583c04360743ffffffff024880f6460000000017a914cabc590e4c35a02b44f77034cea6fcd823d6d18a87fa63cd1d0000000017a914ec459c516bb17526fd4fffa02448c6b3f581c065870247304402201ba93887222fdaac6001a1c54cea3fd78e1fc5b7d48f22c6ed647a330605746702205c4aaba5673efc4a21235cbbf5d61fd6e9ce83aa2fa25507db84a1ff3abdbca401210242adf8c0e977e622db8e2776b02129844fdc5d9fddf5bd963aa85ed87a8ee7ec00000000", "blockhash": "0000000000000032d4bfc14d4783bc4269a7c1ffdc5bc41b9b2b7aa92baa82a5", "confirmations": 23389, "time": 1558701822, "blocktime": 1558701822 }, "error": null, "id": "1" }- then i see what vout
n=1from2NEnWrBmNCmtwNQLsifKqkuRNxRtQsvKkd8. - so i know which address sent this tx.
jnewbery commented at 6:22 PM on June 10, 2019: memberDiscussion should move to the issues linked from here rather than on this closed PR.
I would like to make one observation about the last comment (https://github.com/bitcoin/bitcoin/pull/15159#issuecomment-500348023). A lot of the complexity comes from the fact that you're trying to apply a 'from address'. Such a concept doesn't exist in bitcoin. A transaction can have multiple txins, each of which refer to a txout that may have a scriptPubKey that encodes to an address.
Addresses should be seen more as single-use invoice identifiers. Trying to apply a from/to address model doesn't fit with the Bitcoin UTXO model and will only cause you headaches!
deadalnix referenced this in commit b57c44a940 on May 16, 2020kittywhiskers referenced this in commit c778a0570e on Aug 5, 2021kittywhiskers referenced this in commit 23c01d6546 on Aug 5, 2021kittywhiskers referenced this in commit 6588912af1 on Aug 5, 2021kittywhiskers referenced this in commit 26599604e3 on Aug 5, 2021kittywhiskers referenced this in commit e8e48b33bb on Aug 9, 2021UdjinM6 referenced this in commit 7aebf156e9 on Aug 10, 20215tefan referenced this in commit 56b679f21f on Aug 12, 2021pravblockc referenced this in commit ed4727de9e on Aug 13, 2021pravblockc referenced this in commit baa645d774 on Aug 14, 2021pravblockc referenced this in commit 0c15fbe953 on Aug 17, 2021pravblockc referenced this in commit 8226f22efb on Aug 17, 2021Munkybooty referenced this in commit 1c68749b53 on Sep 8, 2021DrahtBot locked this on Dec 16, 2021ContributorsLabelsLinked (view graph)#3220 Getrawtransaction working partially without -txindex is confusing#15247 qa: Use wallet to retrieve raw transactions#15332 [Docs] Small updates to getrawtransaction description#15477 doc: Remove misleading hint in getrawtransaction#16181 wallet: decode raw transaction in gettransaction#16182 [blockchain] make `getrawtransaction` useful again on pruned nodes
github-metadata-mirror
This is a metadata mirror of the GitHub repository bitcoin/bitcoin. This site is not affiliated with GitHub. Content is generated from a GitHub metadata backup.
generated: 2026-04-13 15:15 UTC
This site is hosted by @0xB10C
More mirrored repositories can be found on mirror.b10c.me