From 590a82e0d8316f422fe215fef4e11f20042c2d66 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Rafa=C5=82=20Malinowski?= Date: Thu, 8 Nov 2018 13:21:46 +0100 Subject: [PATCH 1/2] implement publish command MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Rafał Malinowski --- docs/software/commands.md | 3 +++ src/main/ApplicationUtils.cpp | 50 +++++++++++++++++++++++++++++++++++ src/main/ApplicationUtils.h | 1 + src/main/CommandLine.cpp | 20 ++++++++++++++ 4 files changed, 74 insertions(+) diff --git a/docs/software/commands.md b/docs/software/commands.md index 954de1b831..105c52601f 100644 --- a/docs/software/commands.md +++ b/docs/software/commands.md @@ -60,6 +60,9 @@ stellar-core can be controlled via the following commands. controls type used for printing (default: auto).
Option --base64 alters the behavior to work on base64-encoded XDR rather than raw XDR. +* **publish**: Execute publish of all items remaining in publish queue without + connecting to network. May not publish last checkpoint if last closed ledger + is on checkpoint boundary. * **report-last-history-checkpoint**: Download and report last history checkpoint from a history archive. * **run**: Runs stellar-core service. diff --git a/src/main/ApplicationUtils.cpp b/src/main/ApplicationUtils.cpp index d6c86e8c6f..88123d6583 100644 --- a/src/main/ApplicationUtils.cpp +++ b/src/main/ApplicationUtils.cpp @@ -425,4 +425,54 @@ catchup(Application::pointer app, CatchupConfiguration cc, catchupInfo = app->getJsonInfo(); return synced ? 0 : 3; } + +int +publish(Application::pointer app) +{ + if (!checkInitialized(app)) + { + return 1; + } + + // set known cursors before starting maintenance job + ExternalQueue ps(*app); + ps.setInitialCursors(app->getConfig().KNOWN_CURSORS); + app->getMaintainer().start(); + + 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; + }); + auto& clock = app->getClock(); + while (!done && clock.crank(true)) + ; + + auto& io = clock.getIOService(); + asio::io_service::work mainWork(io); + + auto lcl = app->getLedgerManager().getLastClosedLedgerNum(); + auto isCheckpoint = + lcl == app->getHistoryManager().checkpointContainingLedger(lcl); + auto expectedPublishQueueSize = isCheckpoint ? 1 : 0; + + app->getHistoryManager().publishQueuedHistory(); + while (app->getHistoryManager().publishQueueLength() != + expectedPublishQueueSize && + clock.crank(true)) + { + } + + LOG(INFO) << "*"; + LOG(INFO) << "* Publish finished."; + LOG(INFO) << "*"; + + return 0; +} } diff --git a/src/main/ApplicationUtils.h b/src/main/ApplicationUtils.h index 5077b6b504..5616288ad9 100644 --- a/src/main/ApplicationUtils.h +++ b/src/main/ApplicationUtils.h @@ -25,4 +25,5 @@ void writeCatchupInfo(Json::Value const& catchupInfo, std::string const& outputFile); int catchup(Application::pointer app, CatchupConfiguration cc, Json::Value& catchupInfo); +int publish(Application::pointer app); } diff --git a/src/main/CommandLine.cpp b/src/main/CommandLine.cpp index d34d7b5cac..098b17d45b 100644 --- a/src/main/CommandLine.cpp +++ b/src/main/CommandLine.cpp @@ -414,6 +414,21 @@ runCatchup(CommandLineArgs const& args) }); } +int +runPublish(CommandLineArgs const& args) +{ + CommandLine::ConfigOption configOption; + + return runWithHelp(args, {configurationParser(configOption)}, [&] { + auto config = configOption.getConfig(); + config.setNoListen(); + + VirtualClock clock(VirtualClock::REAL_TIME); + auto app = Application::create(clock, config, false); + return publish(app); + }); +} + int runCheckQuorum(CommandLineArgs const& args) { @@ -712,6 +727,11 @@ handleCommandLine(int argc, char* const* argv) {"offline-info", "return information for an offline instance", runOfflineInfo}, {"print-xdr", "pretty-print one XDR envelope, then quit", runPrintXdr}, + {"publish", + "execute publish of all items remaining in publish queue without " + "connecting to network, may not publish last checkpoint if last " + "closed ledger is on checkpoint boundary", + runPublish}, {"report-last-history-checkpoint", "report information about last checkpoint available in " "history archives", From ce473a1eef95308aaefa1b0b4dbe03fb3a98796d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Rafa=C5=82=20Malinowski?= Date: Tue, 4 Dec 2018 12:02:43 +0100 Subject: [PATCH 2/2] use Application::start in catchup and publish commands MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Rafał Malinowski --- src/main/ApplicationUtils.cpp | 42 ++++------------------------------- 1 file changed, 4 insertions(+), 38 deletions(-) diff --git a/src/main/ApplicationUtils.cpp b/src/main/ApplicationUtils.cpp index 88123d6583..cf99f75d29 100644 --- a/src/main/ApplicationUtils.cpp +++ b/src/main/ApplicationUtils.cpp @@ -331,25 +331,7 @@ catchup(Application::pointer app, CatchupConfiguration cc, return 1; } - // set known cursors before starting maintenance job - ExternalQueue ps(*app); - ps.setInitialCursors(app->getConfig().KNOWN_CURSORS); - app->getMaintainer().start(); - - 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; - }); - auto& clock = app->getClock(); - while (!done && clock.crank(true)) - ; + app->start(); try { @@ -367,10 +349,11 @@ catchup(Application::pointer app, CatchupConfiguration cc, return 2; } + auto& clock = app->getClock(); auto& io = clock.getIOService(); auto synced = false; asio::io_service::work mainWork(io); - done = false; + auto done = false; while (!done && clock.crank(true)) { switch (app->getLedgerManager().getState()) @@ -434,26 +417,9 @@ publish(Application::pointer app) return 1; } - // set known cursors before starting maintenance job - ExternalQueue ps(*app); - ps.setInitialCursors(app->getConfig().KNOWN_CURSORS); - app->getMaintainer().start(); - - 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"); - } + app->start(); - done = true; - }); auto& clock = app->getClock(); - while (!done && clock.crank(true)) - ; - auto& io = clock.getIOService(); asio::io_service::work mainWork(io);