Changeset View
Changeset View
Standalone View
Standalone View
src/net_processing.cpp
- This file is larger than 256 KB, so syntax highlighting is disabled by default.
| Show First 20 Lines • Show All 922 Lines • ▼ Show 20 Lines | struct CNodeState { | ||||
| ChainSyncTimeoutState m_chain_sync; | ChainSyncTimeoutState m_chain_sync; | ||||
| //! Time of last new block announcement | //! Time of last new block announcement | ||||
| int64_t m_last_block_announcement; | int64_t m_last_block_announcement; | ||||
| struct AvalancheState { | struct AvalancheState { | ||||
| std::chrono::time_point<std::chrono::steady_clock> last_poll; | std::chrono::time_point<std::chrono::steady_clock> last_poll; | ||||
| std::chrono::time_point<std::chrono::steady_clock> next_quorum_check_at; | |||||
| bool quorum_available; | |||||
| }; | }; | ||||
| AvalancheState m_avalanche_state; | AvalancheState m_avalanche_state; | ||||
| //! Whether this peer is an inbound connection | //! Whether this peer is an inbound connection | ||||
| bool m_is_inbound; | bool m_is_inbound; | ||||
| //! A rolling bloom filter of all announced tx CInvs to this peer. | //! A rolling bloom filter of all announced tx CInvs to this peer. | ||||
| ▲ Show 20 Lines • Show All 4,056 Lines • ▼ Show 20 Lines | if (msg_type == NetMsgType::AVAHELLO) { | ||||
| return; | return; | ||||
| } | } | ||||
| if (msg_type == NetMsgType::AVAPOLL) { | if (msg_type == NetMsgType::AVAPOLL) { | ||||
| auto now = std::chrono::steady_clock::now(); | auto now = std::chrono::steady_clock::now(); | ||||
| int64_t cooldown = | int64_t cooldown = | ||||
| gArgs.GetArg("-avacooldown", AVALANCHE_DEFAULT_COOLDOWN); | gArgs.GetArg("-avacooldown", AVALANCHE_DEFAULT_COOLDOWN); | ||||
| bool quorum_available = false; | |||||
| bool need_quorum_check = false; | |||||
| { | { | ||||
| LOCK(cs_main); | LOCK(cs_main); | ||||
| auto &node_state = State(pfrom.GetId())->m_avalanche_state; | auto &node_state = State(pfrom.GetId())->m_avalanche_state; | ||||
| if (now < | if (now < | ||||
| node_state.last_poll + std::chrono::milliseconds(cooldown)) { | node_state.last_poll + std::chrono::milliseconds(cooldown)) { | ||||
| Misbehaving(pfrom, 20, "avapool-cooldown"); | Misbehaving(pfrom, 20, "avapool-cooldown"); | ||||
| } | } | ||||
| node_state.last_poll = now; | node_state.last_poll = now; | ||||
| // Get the currently known quorum availability and decide if we need | |||||
| // to check again | |||||
| quorum_available = node_state.quorum_available; | |||||
| need_quorum_check = now > node_state.next_quorum_check_at; | |||||
| } | |||||
| // If it's after our quorum check timeout, re-check the quorum and save | |||||
| // it to the cache | |||||
| if (need_quorum_check) { | |||||
| quorum_available = g_avalanche && g_avalanche->isQuorumAvailable(); | |||||
| { | |||||
| LOCK(cs_main); | |||||
| auto &node_state = State(pfrom.GetId())->m_avalanche_state; | |||||
| node_state.next_quorum_check_at = | |||||
| now + quorumCheckInterval(gArgs); | |||||
| node_state.quorum_available = quorum_available; | |||||
| } | |||||
| } | } | ||||
| uint64_t round; | uint64_t round; | ||||
| Unserialize(vRecv, round); | Unserialize(vRecv, round); | ||||
| unsigned int nCount = ReadCompactSize(vRecv); | unsigned int nCount = ReadCompactSize(vRecv); | ||||
| if (nCount > AVALANCHE_MAX_ELEMENT_POLL) { | if (nCount > AVALANCHE_MAX_ELEMENT_POLL) { | ||||
| Misbehaving( | Misbehaving( | ||||
| Show All 10 Lines | if (msg_type == NetMsgType::AVAPOLL) { | ||||
| for (unsigned int n = 0; n < nCount; n++) { | for (unsigned int n = 0; n < nCount; n++) { | ||||
| CInv inv; | CInv inv; | ||||
| vRecv >> inv; | vRecv >> inv; | ||||
| // Default vote for unknown inv type | // Default vote for unknown inv type | ||||
| uint32_t vote = -1; | uint32_t vote = -1; | ||||
| // We don't vote definitively until we have an available quorum | |||||
| if (!quorum_available) { | |||||
| votes.emplace_back(vote, inv.hash); | |||||
| continue; | |||||
| } | |||||
| // If inv's type is known, get a vote for its hash | // If inv's type is known, get a vote for its hash | ||||
| switch (inv.type) { | switch (inv.type) { | ||||
| case MSG_BLOCK: { | case MSG_BLOCK: { | ||||
| vote = WITH_LOCK(cs_main, return getAvalancheVoteForBlock( | vote = WITH_LOCK(cs_main, return getAvalancheVoteForBlock( | ||||
| BlockHash(inv.hash))); | BlockHash(inv.hash))); | ||||
| } break; | } break; | ||||
| case MSG_AVA_PROOF: { | case MSG_AVA_PROOF: { | ||||
| vote = | vote = | ||||
| ▲ Show 20 Lines • Show All 1,891 Lines • Show Last 20 Lines | |||||