Skip to content

Commit

Permalink
mainnet service node detect and exit bad state
Browse files Browse the repository at this point in the history
If a node is deregistered while running (or is started before being registered),
it can fail to properly connect to the network once registered (again).  This does
not *fix* that, but these symptoms should be sufficient to detect such a state and
the node should recover upon restart.
  • Loading branch information
tewinget committed Oct 3, 2024
1 parent 438eb60 commit ab1ac70
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 0 deletions.
11 changes: 11 additions & 0 deletions llarp/router/router.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -634,6 +634,7 @@ namespace llarp
log::debug(logcat, "Network ID set to {}", conf.router.m_netId);
if (!conf.router.m_netId.empty() && strcmp(conf.router.m_netId.c_str(), llarp::DEFAULT_NETID))
{
is_default_netID = false;
const auto& netid = conf.router.m_netId;
llarp::LogWarn(
"!!!! you have manually set netid to be '",
Expand Down Expand Up @@ -928,6 +929,16 @@ namespace llarp
return;
// LogDebug("tick router");
const auto now = Now();

// If a node is deregistered while running (or is started before being registered),
// it can fail to properly connect to the network once registered (again). This does
// not *fix* that, but these symptoms should be sufficient to detect such a state and
// the node should recover upon restart.
if (is_default_netID and IsServiceNode() and uptime() > 1h and nodedb()->NumLoaded() < 10) {
Stop();
return;
}

if (const auto delta = now - _lastTick; _lastTick != 0s and delta > TimeskipDetectedDuration)
{
// we detected a time skip into the futre, thaw the network
Expand Down
1 change: 1 addition & 0 deletions llarp/router/router.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,7 @@ namespace llarp
{
llarp_time_t _lastPump = 0s;
bool ready;
bool is_default_netID{true};
// transient iwp encryption key
fs::path transport_keyfile;

Expand Down
1 change: 1 addition & 0 deletions llarp/util/thread/queue_manager.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
#include <algorithm>
#include <atomic>
#include <cassert>
#include <cstdint>
#include <iostream>
#include <limits>
#include <string>
Expand Down

0 comments on commit ab1ac70

Please sign in to comment.