Skip to content

Conversation

theStack
Copy link
Contributor

@theStack theStack commented Oct 15, 2021

Rather than subsequently calling gettransaction and decoderawtransaction to get the decoded information for a specific tx-id, we can simply use the verbose version of gettransaction, which returns this in a 'decoded' key. I.e.

node.decoderawtransaction(node.gettransaction(txid)['hex'])

can simply be replaced by:

node.gettransaction(txid=txid, verbose=True)['decoded']

Rationale: shorter code, shorter test logs, less RPC calls.

@fanquake fanquake added the Tests label Oct 15, 2021
@amadeuszpawlik
Copy link
Contributor

amadeuszpawlik commented Oct 15, 2021

Tested ACK c045207. Ran the tests and reviewed the changes.

@brunoerg
Copy link
Contributor

Concept ACK

I think mempool_packages.py (line 68 and 69) could be also included here, couldn't it?

Copy link
Contributor

@promag promag left a comment

Choose a reason for hiding this comment

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

Code review ACK c045207. Didn't check if same approach could be applied in other places.

Copy link
Contributor

@shaavan shaavan left a comment

Choose a reason for hiding this comment

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

Concept ACK

This PR simplifies the code and RPC calls around getting a transaction and decoding it. I was able to successfully compile the PR on Ubuntu 20.04 without any errors. Nice catch, @theStack!

I think mempool_packages.py (line 68 and 69) could be also included here, couldn't it?

I think this is a valid suggestion. I tried to implement this myself while testing, and I was able to successfully do so in the following way:

# We need the wtxids to check P2P announcements
-            fulltx = self.nodes[0].getrawtransaction(txid)
-            witnesstx = self.nodes[0].decoderawtransaction(fulltx, True)
+            witnesstx = self.nodes[0].gettransaction(txid=txid, verbose=True)['decoded']
             witness_chain.append(witnesstx['hash'])

Copy link
Contributor

@brunoerg brunoerg left a comment

Choose a reason for hiding this comment

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

tACK c045207

@brunoerg
Copy link
Contributor

I think mempool_packages.py (line 68 and 69) could be also included here, couldn't it?

I think this is a valid suggestion. I tried to implement this myself while testing, and I was able to successfully do so in the following way:

# We need the wtxids to check P2P announcements
-            fulltx = self.nodes[0].getrawtransaction(txid)
-            witnesstx = self.nodes[0].decoderawtransaction(fulltx, True)
+            witnesstx = self.nodes[0].gettransaction(txid=txid, verbose=True)['decoded']
             witness_chain.append(witnesstx['hash'])

Great! I am gonna check if there are other places it could be applied

Copy link
Contributor

@stratospher stratospher left a comment

Choose a reason for hiding this comment

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

Tested ACK c045207

Verified that the output dictionary produced for a specific tx-id in both the master and PR are the same. There’s 1 more instance where this change can be applied:

In test/functional/rpc_rawtransaction.py:

Rather than subsequently calling `gettransaction` and
`decoderawtransaction` to get the decoded information  for a specific
tx-id, we can simply use the verbose version of `gettransaction`, which
returns this in a 'decoded' key. I.e.

node.decoderawtransaction(node.gettransaction(txid)['hex'])

can be replaced by:

node.gettransaction(txid=txid, verbose=True)['decoded']
@theStack theStack force-pushed the 202110-test-fetch_and_decode_tx_with_single_RPC_call branch from c045207 to 130ee48 Compare October 17, 2021 16:11
@theStack
Copy link
Contributor Author

Thanks for all the reviews!
Force-pushed with the substitution also done in mempool_packages.py, as suggested by @brunoerg and @shaavan (#23287 (comment), #23287 (review)).

@stratospher: Note that I intentionally didn't change anything in rpc_rawtransaction.py, as I think this test's focus are RPCs that cope with raw transactions (like decoderawtransaction).

@stratospher
Copy link
Contributor

tested ACK 130ee48

@stratospher: Note that I intentionally didn't change anything in rpc_rawtransaction.py, as I think this test's focus are RPCs that cope with raw transactions (like decoderawtransaction).

@theStack, Thanks for clarifying. That makes total sense!

Copy link
Contributor

@lsilva01 lsilva01 left a comment

Choose a reason for hiding this comment

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

Tested ACK 130ee48 on Ubuntu 20.04.

Copy link
Contributor

@shaavan shaavan left a comment

Choose a reason for hiding this comment

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

ACK 130ee48

@amadeuszpawlik
Copy link
Contributor

tACK 130ee48

@@ -65,8 +65,7 @@ def run_test(self):
value = sent_value
chain.append(txid)
# We need the wtxids to check P2P announcements
fulltx = self.nodes[0].getrawtransaction(txid)
witnesstx = self.nodes[0].decoderawtransaction(fulltx, True)
witnesstx = self.nodes[0].gettransaction(txid=txid, verbose=True)['decoded']
Copy link
Member

Choose a reason for hiding this comment

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

this is a wallet rpc and eventually the mempool tests shouldn't depend on bdb or sqlite

@maflcko maflcko merged commit 9aa4ddb into bitcoin:master Oct 21, 2021
sidhujag pushed a commit to syscoin/syscoin that referenced this pull request Oct 21, 2021
…ction` RPC call

130ee48 test: get and decode tx with a single `gettransaction` RPC call (Sebastian Falbesoner)

Pull request description:

  Rather than subsequently calling `gettransaction` and `decoderawtransaction` to get the decoded information  for a specific tx-id, we can simply use the verbose version of `gettransaction`, which returns this in a 'decoded' key. I.e.

  ```
  node.decoderawtransaction(node.gettransaction(txid)['hex'])
  ```

  can simply be replaced by:

  ```
  node.gettransaction(txid=txid, verbose=True)['decoded']
  ```

  Rationale: shorter code, shorter test logs, less RPC calls.

ACKs for top commit:
  stratospher:
    tested ACK 130ee48
  amadeuszpawlik:
    tACK 130ee48
  lsilva01:
    Tested ACK 130ee48 on Ubuntu 20.04.
  shaavan:
    ACK 130ee48

Tree-SHA512: cf0bd26e1e21b8022fb8062857906e0706f0ee32d3277f985c461e2519405afe445ab005f5f763fb268c7b4d6e48b2d47eda7af8621b3bce67cece8dfc9bc153
@bitcoin bitcoin locked and limited conversation to collaborators Oct 30, 2022
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

9 participants