From #19093 and resolves #19057.
Difference from #19093: return vsize and fees object (similar to getmempoolentry) when the test accept is successful. Updates release-notes.md.
@rajarshimaitra @MarcoFalke @jnewbery as we discussed on #19093 :)
101 | @@ -102,6 +102,9 @@ will trigger BIP 125 (replace-by-fee) opt-in. (#11413) 102 | option `-deprecatedrpc=banscore` is used. The `banscore` field will be fully 103 | removed in the next major release. (#19469) 104 | 105 | +- The `testmempoolaccept` RPC returns `vsize` and a `fee` object with the `base` fee 106 | + if the transaction passes validation. (#19093)
I should update this now that it'd be a different PR number. Will incorporate with any review comments so feel free to nit :)
updated
91 | @@ -91,7 +92,7 @@ def run_test(self): 92 | tx.deserialize(BytesIO(hex_str_to_bytes(raw_tx_0))) 93 | txid_0 = tx.rehash() 94 | self.check_mempool_result( 95 | - result_expected=[{'txid': txid_0, 'allowed': True}], 96 | + result_expected=[{'txid': txid_0, 'allowed': True, 'vsize': 110, 'fees': {'base': Decimal(str(fee))}}],
I'd rather the vsize was computed rather than hard-coded. Should be simple enough to make a helper function to do this in python, and would be nice to use for tests going forward.
104 | @@ -104,7 +105,7 @@ def run_test(self): 105 | ))['hex'] 106 | tx.deserialize(BytesIO(hex_str_to_bytes(raw_tx_final))) 107 | self.check_mempool_result( 108 | - result_expected=[{'txid': tx.rehash(), 'allowed': True}], 109 | + result_expected=[{'txid': tx.rehash(), 'allowed': True, 'vsize': 188, 'fees': { 'base': Decimal(str(int(coin['amount']) - 0.025))}}],
Can we also try to make these fee calculations more programmatic? Otherwise it's a burden on future test writers.
concept ACK, would like less-magical tests
utACK 4943a1392c33cd5ac985e753d9cc728b794c5752 (once release notes have been updated)
877 | @@ -878,6 +878,11 @@ static UniValue testmempoolaccept(const JSONRPCRequest& request) 878 | { 879 | {RPCResult::Type::STR_HEX, "txid", "The transaction hash in hex"}, 880 | {RPCResult::Type::BOOL, "allowed", "If the mempool allows this tx to be inserted"}, 881 | + {RPCResult::Type::NUM, "vsize", "virtual transaction size as defined in BIP 141. This is different from actual serialized size for witness transactions as witness data is discounted."},
nit: Should maybe add a comment that these are not always present. See below for example. Also, capitalize the first letter.
Done
utACK 4943a1392c33cd5ac985e753d9cc728b794c5752
I agree that tests could be better but I would also be fine with merging as is.
Return fee and vsize if tx would pass ATMP.
ACK https://github.com/bitcoin/bitcoin/pull/19940/commits/418958892d22b552c44f7801fd2f233c92b8f5a8
thanks it's a solid improvement for the next contributor wanting to touch it :)
thank you @instagibbs! I'm so sorry but I just realized I forgot to apply it to p2p_segwit.py 😅 need you to take another look oops... @jnewbery @fjahr this is ready for review again - updated release notes + rpc and added a util for getting vsize in test_framework/messages.py
utACK 23c35bf
utACK 23c35bf0059bd6270218e0b732959e9c754f9812
105 | - outputs=[{node.getnewaddress(): 0.025}], 106 | + outputs=[{node.getnewaddress(): output_amount}], 107 | locktime=node.getblockcount() + 2000, # Can be anything 108 | ))['hex'] 109 | tx.deserialize(BytesIO(hex_str_to_bytes(raw_tx_final))) 110 | + fee_expected = int(coin['amount']) - output_amount
why does this need to truncate the digits of the btc amount?
91 | @@ -91,20 +92,22 @@ def run_test(self): 92 | tx.deserialize(BytesIO(hex_str_to_bytes(raw_tx_0))) 93 | txid_0 = tx.rehash() 94 | self.check_mempool_result( 95 | - result_expected=[{'txid': txid_0, 'allowed': True}], 96 | + result_expected=[{'txid': txid_0, 'allowed': True, 'vsize': tx.get_vsize(), 'fees': {'base': Decimal(str(fee))}}],
unrelated nit: What happens if fee was made a Decimal as opposed to float when defined?
108 | ))['hex'] 109 | tx.deserialize(BytesIO(hex_str_to_bytes(raw_tx_final))) 110 | + fee_expected = int(coin['amount']) - output_amount 111 | self.check_mempool_result( 112 | - result_expected=[{'txid': tx.rehash(), 'allowed': True}], 113 | + result_expected=[{'txid': tx.rehash(), 'allowed': True, 'vsize': tx.get_vsize(), 'fees': {'base': Decimal(str(fee_expected))}}],
Same
(This is my fault for using float in the first place, but now that Decimal is imported, might as well use it everywhere)
Nice. Concept ACK! Left some feedback on the tests.