Merge bitcoin/bitcoin#34511: test: fully reset the state of CConnman in tests
2cb7e99deetest: also reset CConnman::m_private_broadcast in tests (Vasil Dimov)91b7c874e2test: add ConnmanTestMsg convenience method Reset() (Vasil Dimov) Pull request description: Member variables of `CConnman::m_private_broadcast` (introduced in https://github.com/bitcoin/bitcoin/pull/29415) could influence the tests which creates non-determinism if the same instance of `CConnman` is used for repeated test iterations. So, reset the state of `CConnman::m_private_broadcast` from `ConnmanTestMsg::Reset()`. Currently this affects the fuzz tests `process_message` and `process_messages`. Reported in https://github.com/bitcoin/bitcoin/issues/34476#issuecomment-3849088794 ACKs for top commit: maflcko: review ACK2cb7e99dee🚙 Crypt-iQ: tACK2cb7e99deefrankomosh: Code Review ACK2cb7e99deebrunoerg: code review ACK2cb7e99deeTree-SHA512: 0f4b114542da8dc611689457ce67034c15cbfe409b006b2db72bc74078ee9513f5ce3d0e6e67d37c127cfa0a5170fe72fe3ea45ce2a61d45a358dd11bd1881f8
This commit is contained in:
5 files changed
+15
-5
No files matched your search
@@ -1241,7 +1241,7 @@ public:
|
|||||||
/// Wait for the number of needed connections to become greater than 0.
|
/// Wait for the number of needed connections to become greater than 0.
|
||||||
void NumToOpenWait() const;
|
void NumToOpenWait() const;
|
||||||
|
|
||||||
private:
|
protected:
|
||||||
/**
|
/**
|
||||||
* Check if private broadcast can be done to IPv4 or IPv6 peers and if so via which proxy.
|
* Check if private broadcast can be done to IPv4 or IPv6 peers and if so via which proxy.
|
||||||
* If private broadcast connections should not be opened to IPv4 or IPv6, then this will
|
* If private broadcast connections should not be opened to IPv4 or IPv6, then this will
|
||||||
@@ -1251,6 +1251,8 @@ public:
|
|||||||
|
|
||||||
/// Number of `ConnectionType::PRIVATE_BROADCAST` connections to open.
|
/// Number of `ConnectionType::PRIVATE_BROADCAST` connections to open.
|
||||||
std::atomic_size_t m_num_to_open{0};
|
std::atomic_size_t m_num_to_open{0};
|
||||||
|
|
||||||
|
friend struct ConnmanTestMsg;
|
||||||
} m_private_broadcast;
|
} m_private_broadcast;
|
||||||
|
|
||||||
bool CheckIncomingNonce(uint64_t nonce);
|
bool CheckIncomingNonce(uint64_t nonce);
|
||||||
|
|||||||
@@ -72,8 +72,7 @@ FUZZ_TARGET(process_message, .init = initialize_process_message)
|
|||||||
|
|
||||||
auto& node{g_setup->m_node};
|
auto& node{g_setup->m_node};
|
||||||
auto& connman{static_cast<ConnmanTestMsg&>(*node.connman)};
|
auto& connman{static_cast<ConnmanTestMsg&>(*node.connman)};
|
||||||
connman.ResetAddrCache();
|
connman.Reset();
|
||||||
connman.ResetMaxOutboundCycle();
|
|
||||||
auto& chainman{static_cast<TestChainstateManager&>(*node.chainman)};
|
auto& chainman{static_cast<TestChainstateManager&>(*node.chainman)};
|
||||||
const auto block_index_size{WITH_LOCK(chainman.GetMutex(), return chainman.BlockIndex().size())};
|
const auto block_index_size{WITH_LOCK(chainman.GetMutex(), return chainman.BlockIndex().size())};
|
||||||
SetMockTime(1610000000); // any time to successfully reset ibd
|
SetMockTime(1610000000); // any time to successfully reset ibd
|
||||||
|
|||||||
@@ -62,8 +62,7 @@ FUZZ_TARGET(process_messages, .init = initialize_process_messages)
|
|||||||
|
|
||||||
auto& node{g_setup->m_node};
|
auto& node{g_setup->m_node};
|
||||||
auto& connman{static_cast<ConnmanTestMsg&>(*node.connman)};
|
auto& connman{static_cast<ConnmanTestMsg&>(*node.connman)};
|
||||||
connman.ResetAddrCache();
|
connman.Reset();
|
||||||
connman.ResetMaxOutboundCycle();
|
|
||||||
auto& chainman{static_cast<TestChainstateManager&>(*node.chainman)};
|
auto& chainman{static_cast<TestChainstateManager&>(*node.chainman)};
|
||||||
const auto block_index_size{WITH_LOCK(chainman.GetMutex(), return chainman.BlockIndex().size())};
|
const auto block_index_size{WITH_LOCK(chainman.GetMutex(), return chainman.BlockIndex().size())};
|
||||||
SetMockTime(1610000000); // any time to successfully reset ibd
|
SetMockTime(1610000000); // any time to successfully reset ibd
|
||||||
|
|||||||
@@ -80,6 +80,14 @@ void ConnmanTestMsg::ResetMaxOutboundCycle()
|
|||||||
nMaxOutboundTotalBytesSentInCycle = 0;
|
nMaxOutboundTotalBytesSentInCycle = 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void ConnmanTestMsg::Reset()
|
||||||
|
{
|
||||||
|
ResetAddrCache();
|
||||||
|
ResetMaxOutboundCycle();
|
||||||
|
m_private_broadcast.m_outbound_tor_ok_at_least_once.store(false);
|
||||||
|
m_private_broadcast.m_num_to_open.store(0);
|
||||||
|
}
|
||||||
|
|
||||||
void ConnmanTestMsg::NodeReceiveMsgBytes(CNode& node, std::span<const uint8_t> msg_bytes, bool& complete) const
|
void ConnmanTestMsg::NodeReceiveMsgBytes(CNode& node, std::span<const uint8_t> msg_bytes, bool& complete) const
|
||||||
{
|
{
|
||||||
assert(node.ReceiveMsgBytes(msg_bytes, complete));
|
assert(node.ReceiveMsgBytes(msg_bytes, complete));
|
||||||
|
|||||||
@@ -49,6 +49,8 @@ struct ConnmanTestMsg : public CConnman {
|
|||||||
|
|
||||||
void ResetAddrCache();
|
void ResetAddrCache();
|
||||||
void ResetMaxOutboundCycle();
|
void ResetMaxOutboundCycle();
|
||||||
|
/// Reset the internal state.
|
||||||
|
void Reset();
|
||||||
|
|
||||||
std::vector<CNode*> TestNodes()
|
std::vector<CNode*> TestNodes()
|
||||||
{
|
{
|
||||||
|
|||||||
Reference in new issue
Block a user