From fa6fe432075df5e0eceb1ccd85038159cc820ccc Mon Sep 17 00:00:00 2001 From: MarcoFalke <*~=`'#}+{/-|&$^_@721217.xyz> Date: Fri, 9 Aug 2024 13:43:36 +0200 Subject: [PATCH] net: Clarify that m_addr_local is only set once Includes a rename from addrLocal to m_addr_local to match the name of its corresponding Mutex. --- src/net.cpp | 8 +++----- src/net.h | 2 +- src/test/fuzz/net.cpp | 12 +++++------- 3 files changed, 9 insertions(+), 13 deletions(-) diff --git a/src/net.cpp b/src/net.cpp index acd78a3505a84..e1206745a425d 100644 --- a/src/net.cpp +++ b/src/net.cpp @@ -576,16 +576,14 @@ CService CNode::GetAddrLocal() const { AssertLockNotHeld(m_addr_local_mutex); LOCK(m_addr_local_mutex); - return addrLocal; + return m_addr_local; } void CNode::SetAddrLocal(const CService& addrLocalIn) { AssertLockNotHeld(m_addr_local_mutex); LOCK(m_addr_local_mutex); - if (addrLocal.IsValid()) { - LogError("Addr local already set for node: %i. Refusing to change from %s to %s\n", id, addrLocal.ToStringAddrPort(), addrLocalIn.ToStringAddrPort()); - } else { - addrLocal = addrLocalIn; + if (Assume(!m_addr_local.IsValid())) { // Addr local can only be set once during version msg processing + m_addr_local = addrLocalIn; } } diff --git a/src/net.h b/src/net.h index 8449a90b72237..beec58c389872 100644 --- a/src/net.h +++ b/src/net.h @@ -963,7 +963,7 @@ class CNode size_t m_msg_process_queue_size GUARDED_BY(m_msg_process_queue_mutex){0}; // Our address, as reported by the peer - CService addrLocal GUARDED_BY(m_addr_local_mutex); + CService m_addr_local GUARDED_BY(m_addr_local_mutex); mutable Mutex m_addr_local_mutex; mapMsgTypeSize mapSendBytesPerMsgType GUARDED_BY(cs_vSend); diff --git a/src/test/fuzz/net.cpp b/src/test/fuzz/net.cpp index e8b1480c5b04c..4cec96274e7a2 100644 --- a/src/test/fuzz/net.cpp +++ b/src/test/fuzz/net.cpp @@ -33,6 +33,11 @@ FUZZ_TARGET(net, .init = initialize_net) SetMockTime(ConsumeTime(fuzzed_data_provider)); CNode node{ConsumeNode(fuzzed_data_provider)}; node.SetCommonVersion(fuzzed_data_provider.ConsumeIntegral()); + if (const auto service_opt = + ConsumeDeserializable(fuzzed_data_provider, ConsumeDeserializationParams(fuzzed_data_provider))) + { + node.SetAddrLocal(*service_opt); + } LIMITED_WHILE(fuzzed_data_provider.ConsumeBool(), 10000) { CallOneOf( fuzzed_data_provider, @@ -52,13 +57,6 @@ FUZZ_TARGET(net, .init = initialize_net) node.Release(); } }, - [&] { - const std::optional service_opt = ConsumeDeserializable(fuzzed_data_provider, ConsumeDeserializationParams(fuzzed_data_provider)); - if (!service_opt) { - return; - } - node.SetAddrLocal(*service_opt); - }, [&] { const std::vector b = ConsumeRandomLengthByteVector(fuzzed_data_provider); bool complete;