mirror of
https://github.com/bitcoin/bitcoin.git
synced 2025-11-11 22:50:59 +01:00
wallet: use descriptor satisfaction size to estimate inputs size
Instead of using the dummysigner to compute a placeholder satisfaction, infer a descriptor on the scriptPubKey of the coin being spent and use the estimation of the satisfaction size given by the descriptor directly. Note this (almost, see next paragraph) exactly conserves the previous behaviour. For instance CalculateMaximumSignedInputSize was previously assuming the input to be spent in a transaction that spends at least one Segwit coin, since it was always accounting for the serialization of the number of witness elements. In this commit we use a placeholder for the size of the serialization of the witness stack size (1 byte). Since the logic in this commit is already tricky enough to review, and that it is only a very tiny approximation not observable through the existing tests, it is addressed in the next commit.
This commit is contained in:
@@ -62,57 +62,6 @@ BOOST_FIXTURE_TEST_CASE(SubtractFee, TestChain100Setup)
|
||||
BOOST_CHECK_EQUAL(fee, check_tx(fee + 123));
|
||||
}
|
||||
|
||||
static void TestFillInputToWeight(int64_t additional_weight, std::vector<int64_t> expected_stack_sizes)
|
||||
{
|
||||
static const int64_t EMPTY_INPUT_WEIGHT = GetTransactionInputWeight(CTxIn());
|
||||
|
||||
CTxIn input;
|
||||
int64_t target_weight = EMPTY_INPUT_WEIGHT + additional_weight;
|
||||
BOOST_CHECK(FillInputToWeight(input, target_weight));
|
||||
BOOST_CHECK_EQUAL(GetTransactionInputWeight(input), target_weight);
|
||||
BOOST_CHECK_EQUAL(input.scriptWitness.stack.size(), expected_stack_sizes.size());
|
||||
for (unsigned int i = 0; i < expected_stack_sizes.size(); ++i) {
|
||||
BOOST_CHECK_EQUAL(input.scriptWitness.stack[i].size(), expected_stack_sizes[i]);
|
||||
}
|
||||
}
|
||||
|
||||
BOOST_FIXTURE_TEST_CASE(FillInputToWeightTest, BasicTestingSetup)
|
||||
{
|
||||
{
|
||||
// Less than or equal minimum of 165 should not add any witness data
|
||||
CTxIn input;
|
||||
BOOST_CHECK(!FillInputToWeight(input, -1));
|
||||
BOOST_CHECK_EQUAL(GetTransactionInputWeight(input), 165);
|
||||
BOOST_CHECK_EQUAL(input.scriptWitness.stack.size(), 0);
|
||||
BOOST_CHECK(!FillInputToWeight(input, 0));
|
||||
BOOST_CHECK_EQUAL(GetTransactionInputWeight(input), 165);
|
||||
BOOST_CHECK_EQUAL(input.scriptWitness.stack.size(), 0);
|
||||
BOOST_CHECK(!FillInputToWeight(input, 164));
|
||||
BOOST_CHECK_EQUAL(GetTransactionInputWeight(input), 165);
|
||||
BOOST_CHECK_EQUAL(input.scriptWitness.stack.size(), 0);
|
||||
BOOST_CHECK(FillInputToWeight(input, 165));
|
||||
BOOST_CHECK_EQUAL(GetTransactionInputWeight(input), 165);
|
||||
BOOST_CHECK_EQUAL(input.scriptWitness.stack.size(), 0);
|
||||
}
|
||||
|
||||
// Make sure we can add at least one weight
|
||||
TestFillInputToWeight(1, {0});
|
||||
|
||||
// 1 byte compact size uint boundary
|
||||
TestFillInputToWeight(252, {251});
|
||||
TestFillInputToWeight(253, {83, 168});
|
||||
TestFillInputToWeight(262, {86, 174});
|
||||
TestFillInputToWeight(263, {260});
|
||||
|
||||
// 3 byte compact size uint boundary
|
||||
TestFillInputToWeight(65535, {65532});
|
||||
TestFillInputToWeight(65536, {21842, 43688});
|
||||
TestFillInputToWeight(65545, {21845, 43694});
|
||||
TestFillInputToWeight(65546, {65541});
|
||||
|
||||
// Note: We don't test the next boundary because of memory allocation constraints.
|
||||
}
|
||||
|
||||
BOOST_FIXTURE_TEST_CASE(wallet_duplicated_preset_inputs_test, TestChain100Setup)
|
||||
{
|
||||
// Verify that the wallet's Coin Selection process does not include pre-selected inputs twice in a transaction.
|
||||
|
||||
Reference in New Issue
Block a user