diff --git a/src/cryptonote_core/cryptonote_core.cpp b/src/cryptonote_core/cryptonote_core.cpp index 447b50c05..fd8a3aae6 100644 --- a/src/cryptonote_core/cryptonote_core.cpp +++ b/src/cryptonote_core/cryptonote_core.cpp @@ -1665,7 +1665,7 @@ namespace cryptonote auto quorum_votes = m_quorum_cop.get_relayable_votes(height, hf_version, true); auto p2p_votes = m_quorum_cop.get_relayable_votes(height, hf_version, false); - if (!quorum_votes.empty()) + if (!quorum_votes.empty() && m_quorumnet_obj && m_service_node_keys) quorumnet_relay_obligation_votes(m_quorumnet_obj, quorum_votes); if (!p2p_votes.empty()) diff --git a/src/cryptonote_protocol/quorumnet.cpp b/src/cryptonote_protocol/quorumnet.cpp index 4f575b1b1..31e8b0457 100644 --- a/src/cryptonote_protocol/quorumnet.cpp +++ b/src/cryptonote_protocol/quorumnet.cpp @@ -89,6 +89,11 @@ struct SNNWrapper { template SNNWrapper(cryptonote::core &core, Args &&...args) : snn{std::forward(args)...}, core{core} {} + + static SNNWrapper &from(void* obj) { + assert(obj); + return *reinterpret_cast(obj); + } }; template @@ -477,13 +482,10 @@ quorum_vote_t deserialize_vote(const bt_value &v) { } void relay_obligation_votes(void *obj, const std::vector &votes) { - assert(obj); - if (!obj) return; - auto &snw = *reinterpret_cast(obj); + auto &snw = SNNWrapper::from(obj); auto my_keys_ptr = snw.core.get_service_node_keys(); assert(my_keys_ptr); - if (!my_keys_ptr) return; const auto &my_keys = *my_keys_ptr; MDEBUG("Starting relay of " << votes.size() << " votes"); @@ -523,9 +525,7 @@ void relay_obligation_votes(void *obj, const std::vector(self); - assert(self); - if (!self) return; + auto &snw = SNNWrapper::from(self); MDEBUG("Received a relayed obligation vote from " << as_hex(m.pubkey)); @@ -816,9 +816,7 @@ void process_blink_signatures(SNNWrapper &snw, const std::shared_ptr & /// submission will fail immediately if it does not). /// void handle_blink(SNNetwork::message &m, void *self) { - auto &snw = *reinterpret_cast(self); - assert(self); - if (!self) return; + auto &snw = SNNWrapper::from(self); // TODO: if someone sends an invalid tx (i.e. one that doesn't get to the distribution stage) // then put a timeout on that IP during which new submissions from them are dropped for a short @@ -1107,9 +1105,7 @@ void copy_signature_values(std::list &signatures, const bt_va /// /// Signatures will be forwarded if new; known signatures will be ignored. void handle_blink_signature(SNNetwork::message &m, void *self) { - auto &snw = *reinterpret_cast(self); - assert(self); - if (!self) return; + auto &snw = SNNWrapper::from(self); MDEBUG("Received a blink tx signature from SN " << as_hex(m.pubkey)); @@ -1292,7 +1288,7 @@ std::future> send_blink(void *o if (!blink_tag) return future; try { - auto &snw = *reinterpret_cast(obj); + auto &snw = SNNWrapper::from(obj); uint64_t height = snw.core.get_current_blockchain_height(); uint64_t checksum; auto quorums = get_blink_quorums(height, snw.core.get_service_node_list(), nullptr, &checksum);