mirror of
https://github.com/bitcoin/bitcoin.git
synced 2025-08-25 20:41:21 +02:00
Merge bitcoin/bitcoin#28944: wallet, rpc: add anti-fee-sniping to send
and sendall
aac0b6dd79
test: test sendall and send do anti-fee-sniping (ishaanam)20802c7b65
wallet, rpc: add anti-fee-sniping to `send` and `sendall` (ishaanam) Pull request description: Currently, `send` and `sendall` don't do anti-fee-sniping because they don't use `CreateTransaction`. This PR adds anti-fee-sniping to these RPCs by calling `DiscourageFeeSniping` from `FinishTransaction` when the user does not specify a locktime. ACKs for top commit: achow101: ACKaac0b6dd79
murchandamus: ACKaac0b6dd79
glozow: ACKaac0b6dd79
Tree-SHA512: d4f1b43b5bda489bdba46b0af60e50bff0de604a35670e6ea6e1de2b539f16b3f68805492f51d6d2078d421b63432ca22a561a5721d1a37686f2e48284e1e646
This commit is contained in:
@@ -53,7 +53,7 @@ class WalletRescanUnconfirmed(BitcoinTestFramework):
|
||||
# The only UTXO available to spend is tx_parent_to_reorg.
|
||||
assert_equal(len(w0_utxos), 1)
|
||||
assert_equal(w0_utxos[0]["txid"], tx_parent_to_reorg["txid"])
|
||||
tx_child_unconfirmed_sweep = w0.sendall([ADDRESS_BCRT1_UNSPENDABLE])
|
||||
tx_child_unconfirmed_sweep = w0.sendall(recipients=[ADDRESS_BCRT1_UNSPENDABLE], options={"locktime":0})
|
||||
assert tx_child_unconfirmed_sweep["txid"] in node.getrawmempool()
|
||||
node.syncwithvalidationinterfacequeue()
|
||||
|
||||
|
@@ -144,7 +144,12 @@ class WalletSendTest(BitcoinTestFramework):
|
||||
return
|
||||
|
||||
if locktime:
|
||||
assert_equal(from_wallet.gettransaction(txid=res["txid"], verbose=True)["decoded"]["locktime"], locktime)
|
||||
return res
|
||||
else:
|
||||
if add_to_wallet:
|
||||
decoded_tx = from_wallet.gettransaction(txid=res["txid"], verbose=True)["decoded"]
|
||||
assert_greater_than(decoded_tx["locktime"], from_wallet.getblockcount() - 100)
|
||||
|
||||
if expect_sign:
|
||||
assert_equal(res["complete"], True)
|
||||
|
@@ -6,6 +6,7 @@
|
||||
|
||||
from decimal import Decimal, getcontext
|
||||
|
||||
from test_framework.messages import SEQUENCE_FINAL
|
||||
from test_framework.test_framework import BitcoinTestFramework
|
||||
from test_framework.util import (
|
||||
assert_equal,
|
||||
@@ -430,6 +431,26 @@ class SendallTest(BitcoinTestFramework):
|
||||
|
||||
assert_greater_than(higher_parent_feerate_amount, lower_parent_feerate_amount)
|
||||
|
||||
@cleanup
|
||||
def sendall_anti_fee_sniping(self):
|
||||
self.log.info("Testing sendall does anti-fee-sniping when locktime is not specified")
|
||||
self.add_utxos([10,11])
|
||||
tx_from_wallet = self.test_sendall_success(sendall_args = [self.remainder_target])
|
||||
|
||||
assert_greater_than(tx_from_wallet["decoded"]["locktime"], tx_from_wallet["blockheight"] - 100)
|
||||
|
||||
self.log.info("Testing sendall does not do anti-fee-sniping when locktime is specified")
|
||||
self.add_utxos([10,11])
|
||||
txid = self.wallet.sendall(recipients=[self.remainder_target], options={"locktime":0})["txid"]
|
||||
assert_equal(self.wallet.gettransaction(txid=txid, verbose=True)["decoded"]["locktime"], 0)
|
||||
|
||||
self.log.info("Testing sendall does not do anti-fee-sniping when even one of the sequences is final")
|
||||
self.add_utxos([10, 11])
|
||||
utxos = self.wallet.listunspent()
|
||||
utxos[0]["sequence"] = SEQUENCE_FINAL
|
||||
txid = self.wallet.sendall(recipients=[self.remainder_target], inputs=utxos)["txid"]
|
||||
assert_equal(self.wallet.gettransaction(txid=txid, verbose=True)["decoded"]["locktime"], 0)
|
||||
|
||||
# This tests needs to be the last one otherwise @cleanup will fail with "Transaction too large" error
|
||||
def sendall_fails_with_transaction_too_large(self):
|
||||
self.log.info("Test that sendall fails if resulting transaction is too large")
|
||||
@@ -511,6 +532,9 @@ class SendallTest(BitcoinTestFramework):
|
||||
# Sendall only uses outputs with less than a given number of confirmation when using minconf
|
||||
self.sendall_with_maxconf()
|
||||
|
||||
# Sendall discourages fee-sniping when a locktime is not specified
|
||||
self.sendall_anti_fee_sniping()
|
||||
|
||||
# Sendall spends unconfirmed change
|
||||
self.sendall_spends_unconfirmed_change()
|
||||
|
||||
|
Reference in New Issue
Block a user