コード例 #1
0
ファイル: main.cpp プロジェクト: pkrasam/stellar-core
static int
reportLastHistoryCheckpoint(Config const& cfg, std::string const& outputFile)
{
    VirtualClock clock(VirtualClock::REAL_TIME);
    Application::pointer app = Application::create(clock, cfg, false);

    if (!checkInitialized(app))
    {
        return 1;
    }

    auto state = HistoryArchiveState{};
    auto& wm = app->getWorkManager();
    auto getHistoryArchiveStateWork =
        wm.executeWork<GetHistoryArchiveStateWork>(
            true, "get-history-archive-state-work", state);

    auto ok = getHistoryArchiveStateWork->getState() == Work::WORK_SUCCESS;
    if (ok)
    {
        std::string filename = outputFile.empty() ? "-" : outputFile;

        if (filename == "-")
        {
            LOG(INFO) << "*";
            LOG(INFO) << "* Last history checkpoint " << state.toString();
            LOG(INFO) << "*";
        }
        else
        {
            state.save(filename);
            LOG(INFO) << "*";
            LOG(INFO) << "* Wrote last history checkpoint " << filename;
            LOG(INFO) << "*";
        }
    }
    else
    {
        LOG(INFO) << "*";
        LOG(INFO) << "* Fetching last history checkpoint failed.";
        LOG(INFO) << "*";
    }

    app->gracefulStop();
    while (clock.crank(true))
        ;

    return ok ? 0 : 1;
}
コード例 #2
0
ファイル: main.cpp プロジェクト: pkrasam/stellar-core
static int
catchup(Config const& cfg, uint32_t to, uint32_t count,
        Json::Value& catchupInfo)
{
    VirtualClock clock(VirtualClock::REAL_TIME);
    Application::pointer app = Application::create(clock, cfg, false);

    if (!checkInitialized(app))
    {
        return 1;
    }

    auto done = false;
    app->getLedgerManager().loadLastKnownLedger(
        [&done](asio::error_code const& ec) {
            if (ec)
            {
                throw std::runtime_error(
                    "Unable to restore last-known ledger state");
            }

            done = true;
        });
    while (!done && clock.crank(true))
        ;

    try
    {
        app->getLedgerManager().startCatchUp({to, count}, true);
    }
    catch (std::invalid_argument const&)
    {
        LOG(INFO) << "*";
        LOG(INFO) << "* Target ledger " << to
                  << " is not newer than last closed ledger"
                  << " - nothing to do";
        LOG(INFO) << "* If you really want to catchup to " << to
                  << " run stellar-core with --newdb parameter.";
        LOG(INFO) << "*";
        return 2;
    }

    auto& io = clock.getIOService();
    auto synced = false;
    asio::io_service::work mainWork(io);
    done = false;
    while (!done && clock.crank(true))
    {
        switch (app->getLedgerManager().getState())
        {
        case LedgerManager::LM_BOOTING_STATE:
        {
            LOG(INFO) << "*";
            LOG(INFO) << "* Catchup failed.";
            LOG(INFO) << "*";
            done = true;
            break;
        }
        case LedgerManager::LM_SYNCED_STATE:
        {
            LOG(INFO) << "*";
            LOG(INFO) << "* Catchup finished.";
            LOG(INFO) << "*";
            done = true;
            synced = true;
            break;
        }
        case LedgerManager::LM_CATCHING_UP_STATE:
            break;
        }
    }

    catchupInfo = app->getJsonInfo();
    app->gracefulStop();
    while (clock.crank(true))
        ;

    return synced ? 0 : 3;
}