Nodes: don't connect to out of sync nodes in wsmode

tobtoht-patch-1
tobtoht 4 years ago
parent b66aceccc8
commit 2a03ca9eda

@ -149,7 +149,7 @@ void Nodes::onConnectionTimer() {
QString msg;
Wallet::ConnectionStatus status = m_ctx->currentWallet->connected(true);
NodeSource nodeSource = this->source();
auto wsMode = nodeSource == NodeSource::websocket;
auto wsMode = (nodeSource == NodeSource::websocket);
auto nodes = wsMode ? m_customNodes : m_websocketNodes;
if (wsMode && !m_wsNodesReceived && m_websocketNodes.count() == 0) {
@ -224,6 +224,36 @@ FeatherNode Nodes::pickEligibleNode() {
return rtn;
}
QVector<int> heights;
for (const auto &node: nodes) {
heights.push_back(node.height);
}
std::sort(heights.begin(), heights.end());
// Calculate mode of node heights
int max_count = 1, mode_height = heights[0], count = 1;
for (int i = 1; i < heights.count(); i++) {
if (heights[i] == 0) { // Don't consider 0 height nodes
continue;
}
if (heights[i] == heights[i - 1])
count++;
else {
if (count > max_count) {
max_count = count;
mode_height = heights[i - 1];
}
count = 1;
}
}
if (count > max_count)
{
max_count = count;
mode_height = heights[heights.count() - 1];
}
while(true) {
// keep track of nodes we have previously tried to connect to
if (m_connectionAttempts.count() == nodes.count()) {
@ -240,6 +270,11 @@ FeatherNode Nodes::pickEligibleNode() {
if (wsMode && !node.online)
continue;
// Ignore nodes that are more than 25 blocks behind mode
if (wsMode && node.height < (mode_height - 25))
continue;
return node;
}
}

@ -41,7 +41,7 @@ struct FeatherNode {
_address = spl.at(1);
}
if(!_address.contains(":"))
_address += ":18089";
_address += ":18081";
this->address = _address;
if(this->address.contains(".onion"))
tor = true;

Loading…
Cancel
Save