Navigation Menu

Skip to content

Commit

Permalink
Add daemon delay and fetching data from offline lookup nodes.
Browse files Browse the repository at this point in the history
  • Loading branch information
ckyang committed Nov 21, 2018
1 parent f99a4e5 commit 3882bcc
Show file tree
Hide file tree
Showing 4 changed files with 39 additions and 9 deletions.
11 changes: 10 additions & 1 deletion daemon/ZilliqaDaemon_AWS.cpp
Expand Up @@ -52,6 +52,8 @@ unordered_map<int, string> Path;

const string logName = "epochinfo-00001-log.txt";

static uint32_t launchDelay = 0;

enum SyncType : unsigned int {
NO_SYNC = 0,
NEW_SYNC,
Expand Down Expand Up @@ -262,6 +264,9 @@ void MonitorProcess(unordered_map<string, vector<pid_t>>& pids,
pids[name].erase(it);
}

log << "Sleep " << launchDelay
<< " seconds before re-launch a new process..." << endl;
sleep(launchDelay);
StartNewProcess(PubKey[pid], PrivKey[pid], Port[pid],
to_string(getRestartValue(pid)), Path[pid], log);
died.erase(pid);
Expand All @@ -273,7 +278,11 @@ void MonitorProcess(unordered_map<string, vector<pid_t>>& pids,
}
}

int main() {
int main(int argc, const char* argv[]) {
if (argc > 1) {
launchDelay = stoull(argv[1]);
}

pid_t pid_parent, sid;
ofstream log;
log.open("daemon-log.txt", fstream::out | fstream::trunc);
Expand Down
7 changes: 6 additions & 1 deletion daemon/run.sh
Expand Up @@ -16,5 +16,10 @@
# src/depends and tests/depends and which include a reference to GPLv3 in their
# program files.

if [ "$#" -ne 1 ]; then
echo "Usage: bash run.sh delay"
return 1
fi

pkill ZilliqaDaemon_AWS
ZilliqaDaemon_AWS
ZilliqaDaemon_AWS $1
3 changes: 2 additions & 1 deletion src/libLookup/Lookup.cpp
Expand Up @@ -2677,7 +2677,8 @@ bool Lookup::ToBlockMessage(unsigned char ins_byte) {
ins_byte != LookupInstructionType::SETTXBLOCKFROMSEED &&
ins_byte != LookupInstructionType::SETSTATEFROMSEED &&
ins_byte != LookupInstructionType::SETLOOKUPOFFLINE &&
ins_byte != LookupInstructionType::SETLOOKUPONLINE);
ins_byte != LookupInstructionType::SETLOOKUPONLINE &&
ins_byte != LookupInstructionType::SETSTATEDELTAFROMSEED);
}

std::vector<unsigned char> Lookup::ComposeGetOfflineLookupNodes() {
Expand Down
27 changes: 21 additions & 6 deletions src/libNode/Node.cpp
Expand Up @@ -300,23 +300,34 @@ bool Node::StartRetrieveHistory(bool& wakeupForUpgrade,
}

/// Retrieve lacked Tx blocks from lookup nodes
if (!LOOKUP_NODE_MODE && !ARCHIVAL_NODE) {
if (!ARCHIVAL_NODE && SyncType::NO_SYNC == m_mediator.m_lookup->m_syncType) {
uint64_t oldTxNum = m_mediator.m_txBlockChain.GetBlockCount();
if (!GetOfflineLookups()) {
LOG_GENERAL(WARNING, "Cannot fetch data from lookup node!");
return false;

if (LOOKUP_NODE_MODE) {
if (!m_mediator.m_lookup->GetMyLookupOffline()) {
LOG_GENERAL(WARNING, "Cannot fetch data from off-line lookup node!");
return false;
}
} else {
if (!GetOfflineLookups()) {
LOG_GENERAL(WARNING, "Cannot fetch data from lookup node!");
return false;
}
}
{
unique_lock<mutex> lock(m_mediator.m_lookup->m_MutexCVSetTxBlockFromSeed);
m_mediator.m_lookup->m_syncType = SyncType::LOOKUP_SYNC;

do {
m_synchronizer.FetchLatestTxBlocks(
m_mediator.m_lookup, m_mediator.m_txBlockChain.GetBlockCount());
m_mediator.m_lookup->GetTxBlockFromLookupNodes(
m_mediator.m_txBlockChain.GetBlockCount(), 0);
LOG_GENERAL(INFO,
"Retrieve final block from lookup node, please wait...");
} while (m_mediator.m_lookup->cv_setTxBlockFromSeed.wait_for(
lock, chrono::seconds(RECOVERY_SYNC_TIMEOUT)) ==
cv_status::timeout);

m_mediator.m_lookup->m_syncType = SyncType::NO_SYNC;
}

if (m_mediator.m_txBlockChain.GetBlockCount() > oldTxNum + 1) {
Expand All @@ -330,6 +341,7 @@ bool Node::StartRetrieveHistory(bool& wakeupForUpgrade,
if (m_mediator.m_txBlockChain.GetBlockCount() > oldTxNum) {
unique_lock<mutex> lock(
m_mediator.m_lookup->m_MutexCVSetStateDeltaFromSeed);
m_mediator.m_lookup->m_syncType = SyncType::LOOKUP_SYNC;

do {
m_mediator.m_lookup->GetStateDeltaFromLookupNodes(
Expand All @@ -340,12 +352,15 @@ bool Node::StartRetrieveHistory(bool& wakeupForUpgrade,
} while (m_mediator.m_lookup->cv_setStateDeltaFromSeed.wait_for(
lock, chrono::seconds(RECOVERY_SYNC_TIMEOUT)) ==
cv_status::timeout);

m_mediator.m_lookup->m_syncType = SyncType::NO_SYNC;
}
}

/// If recovery mode with vacuous epoch or less than 1 DS epoch, apply re-join
/// process instead of node recovery
if (!wakeupForUpgrade && !LOOKUP_NODE_MODE &&
SyncType::NO_SYNC == m_mediator.m_lookup->m_syncType &&
(m_mediator.m_txBlockChain.GetLastBlock().GetHeader().GetBlockNum() <
NUM_FINAL_BLOCK_PER_POW ||
m_mediator.GetIsVacuousEpoch(
Expand Down

0 comments on commit 3882bcc

Please sign in to comment.