Merge a70911492f into merged_master (Bitcoin PR bitcoin/bitcoin#26749)

includes a FIXME for rpc_psbt.py that must have happened in the merge of
bitcoin/bitcoin#27200
This commit is contained in:
Byron Hambly 2025-04-11 20:23:28 +02:00
commit e268f3a7eb
8 changed files with 54 additions and 64 deletions

View file

@ -43,7 +43,6 @@ struct FakeCheck {
{
return true;
}
void swap(FakeCheck& x) noexcept {};
};
struct FakeCheckCheckCompletion {
@ -53,7 +52,6 @@ struct FakeCheckCheckCompletion {
n_calls.fetch_add(1, std::memory_order_relaxed);
return true;
}
void swap(FakeCheckCheckCompletion& x) noexcept {};
};
struct FailingCheck {
@ -64,10 +62,6 @@ struct FailingCheck {
{
return !fails;
}
void swap(FailingCheck& x) noexcept
{
std::swap(fails, x.fails);
};
};
struct UniqueCheck {
@ -82,10 +76,6 @@ struct UniqueCheck {
results.insert(check_id);
return true;
}
void swap(UniqueCheck& x) noexcept
{
std::swap(x.check_id, check_id);
};
};
@ -113,19 +103,13 @@ struct MemoryCheck {
{
fake_allocated_memory.fetch_sub(b, std::memory_order_relaxed);
};
void swap(MemoryCheck& x) noexcept
{
std::swap(b, x.b);
};
};
struct FrozenCleanupCheck {
static std::atomic<uint64_t> nFrozen;
static std::condition_variable cv;
static std::mutex m;
// Freezing can't be the default initialized behavior given how the queue
// swaps in default initialized Checks.
bool should_freeze {false};
bool should_freeze{true};
bool operator()() const
{
return true;
@ -140,10 +124,17 @@ struct FrozenCleanupCheck {
cv.wait(l, []{ return nFrozen.load(std::memory_order_relaxed) == 0;});
}
}
void swap(FrozenCleanupCheck& x) noexcept
FrozenCleanupCheck(FrozenCleanupCheck&& other) noexcept
{
std::swap(should_freeze, x.should_freeze);
};
should_freeze = other.should_freeze;
other.should_freeze = false;
}
FrozenCleanupCheck& operator=(FrozenCleanupCheck&& other) noexcept
{
should_freeze = other.should_freeze;
other.should_freeze = false;
return *this;
}
};
// Static Allocations
@ -173,17 +164,19 @@ static void Correct_Queue_range(std::vector<size_t> range)
small_queue->StartWorkerThreads(SCRIPT_CHECK_THREADS);
// Make vChecks here to save on malloc (this test can be slow...)
std::vector<FakeCheckCheckCompletion*> vChecks;
vChecks.reserve(9);
for (const size_t i : range) {
size_t total = i;
FakeCheckCheckCompletion::n_calls = 0;
CCheckQueueControl<FakeCheckCheckCompletion> control(small_queue.get());
while (total) {
vChecks.clear();
vChecks.resize(std::min(total, (size_t) InsecureRandRange(10)));
for (size_t i = 0; i < vChecks.size(); ++i) {
vChecks[i] = new FakeCheckCheckCompletion();
}
total -= vChecks.size();
control.Add(vChecks);
control.Add(std::move(vChecks));
}
BOOST_REQUIRE(control.Wait());
if (FakeCheckCheckCompletion::n_calls != i) {
@ -242,10 +235,11 @@ BOOST_AUTO_TEST_CASE(test_CheckQueue_Catches_Failure)
size_t r = InsecureRandRange(10);
std::vector<FailingCheck*> vChecks;
vChecks.reserve(r);
for (size_t k = 0; k < r && remaining; k++, remaining--) {
vChecks.push_back(new FailingCheck(remaining == 1));
}
control.Add(vChecks);
control.Add(std::move(vChecks));
}
bool success = control.Wait();
if (i > 0) {
@ -273,7 +267,7 @@ BOOST_AUTO_TEST_CASE(test_CheckQueue_Recovers_From_Failure)
}
delete vChecks[99];
vChecks[99] = new FailingCheck(end_fails);
control.Add(vChecks);
control.Add(std::move(vChecks));
}
bool r =control.Wait();
BOOST_REQUIRE(r != end_fails);
@ -300,7 +294,7 @@ BOOST_AUTO_TEST_CASE(test_CheckQueue_UniqueCheck)
for (size_t k = 0; k < r && total; k++) {
vChecks.emplace_back(new UniqueCheck(--total));
}
control.Add(vChecks);
control.Add(std::move(vChecks));
}
}
{
@ -338,7 +332,7 @@ BOOST_AUTO_TEST_CASE(test_CheckQueue_Memory)
// to catch any sort of deallocation failure
vChecks.emplace_back(new MemoryCheck(total == 0 || total == i || total == i/2));
}
control.Add(vChecks);
control.Add(std::move(vChecks));
}
}
BOOST_REQUIRE_EQUAL(MemoryCheck::fake_allocated_memory, 0U);
@ -361,7 +355,7 @@ BOOST_AUTO_TEST_CASE(test_CheckQueue_FrozenCleanup)
// would get called twice).
vChecks.push_back(new FrozenCleanupCheck());
vChecks[0]->should_freeze = true;
control.Add(vChecks);
control.Add(std::move(vChecks));
bool waitResult = control.Wait(); // Hangs here
assert(waitResult);
});