mirror of
https://github.com/bitcoin/bitcoin.git
synced 2026-09-13 22:41:25 +02:00
Merge bitcoin/bitcoin#35228: wallet: use outpoint when estimating input size
cd8d3bd937wallet: use outpoint when estimating input size (Lőrinc) Pull request description: ### Problem `CalculateMaximumSignedInputSize()` is passed the outpoint being sized, but a previous refactor stopped using that context when estimating the signed input size. This could make externally selected inputs look slightly smaller than they really are. ### Fix Pass the outpoint through again when estimating the signed input size. Add a regression test for the external-input case. > [!NOTE] > the branch name still reflects the previous state of this PR, where the unused parameter was removed instead of wired back in ACKs for top commit: achow101: ACKcd8d3bd937pablomartin4btc: ACKcd8d3bd937Tree-SHA512: 6089ae65ae12677c32be0556d704f8c179f1ff5a017690846ae495644890526f85d8c0d75d4ec4c3c9ac5b519251169009484623340b8bc3a87fa9a3be27fefd
This commit is contained in:
@@ -94,7 +94,7 @@ int CalculateMaximumSignedInputSize(const CTxOut& txout, const COutPoint outpoin
|
||||
if (!provider) return -1;
|
||||
|
||||
if (const auto desc = InferDescriptor(txout.scriptPubKey, *provider)) {
|
||||
if (const auto weight = MaxInputWeight(*desc, {}, coin_control, true, can_grind_r)) {
|
||||
if (const auto weight = MaxInputWeight(*desc, CTxIn{outpoint}, coin_control, true, can_grind_r)) {
|
||||
return static_cast<int>(GetVirtualTransactionSize(*weight, 0, 0));
|
||||
}
|
||||
}
|
||||
|
||||
@@ -3,6 +3,7 @@
|
||||
// file COPYING or http://www.opensource.org/licenses/mit-license.php.
|
||||
|
||||
#include <consensus/amount.h>
|
||||
#include <key.h>
|
||||
#include <policy/fees/block_policy_estimator.h>
|
||||
#include <script/solver.h>
|
||||
#include <validation.h>
|
||||
@@ -16,6 +17,22 @@
|
||||
namespace wallet {
|
||||
BOOST_FIXTURE_TEST_SUITE(spend_tests, WalletTestingSetup)
|
||||
|
||||
BOOST_AUTO_TEST_CASE(max_signed_input_size_uses_external_outpoint)
|
||||
{
|
||||
const CKey key{GenerateRandomKey()};
|
||||
FillableSigningProvider provider;
|
||||
BOOST_REQUIRE(provider.AddKey(key));
|
||||
|
||||
const CTxOut txout{COIN, GetScriptForDestination(PKHash{key.GetPubKey()})};
|
||||
const COutPoint outpoint{Txid{}, 0};
|
||||
CCoinControl coin_control;
|
||||
coin_control.Select(outpoint).SetTxOut(txout);
|
||||
|
||||
const int low_r{CalculateMaximumSignedInputSize(txout, COutPoint{}, &provider, /*can_grind_r=*/true, &coin_control)};
|
||||
const int high_r{CalculateMaximumSignedInputSize(txout, outpoint, &provider, /*can_grind_r=*/true, &coin_control)};
|
||||
BOOST_CHECK_EQUAL(high_r, low_r + 1);
|
||||
}
|
||||
|
||||
BOOST_FIXTURE_TEST_CASE(SubtractFee, TestChain100Setup)
|
||||
{
|
||||
CreateAndProcessBlock({}, GetScriptForRawPubKey(coinbaseKey.GetPubKey()));
|
||||
|
||||
Reference in New Issue
Block a user