Skip to content

Commit 590a82e

Browse files
committed
implement publish command
Signed-off-by: Rafał Malinowski <rafal.przemyslaw.malinowski@gmail.com>
1 parent 36bc18f commit 590a82e

4 files changed

Lines changed: 74 additions & 0 deletions

File tree

docs/software/commands.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,9 @@ stellar-core can be controlled via the following commands.
6060
controls type used for printing (default: auto).<br>
6161
Option --base64 alters the behavior to work on base64-encoded XDR rather than
6262
raw XDR.
63+
* **publish**: Execute publish of all items remaining in publish queue without
64+
connecting to network. May not publish last checkpoint if last closed ledger
65+
is on checkpoint boundary.
6366
* **report-last-history-checkpoint**: Download and report last history
6467
checkpoint from a history archive.
6568
* **run**: Runs stellar-core service.

src/main/ApplicationUtils.cpp

Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -425,4 +425,54 @@ catchup(Application::pointer app, CatchupConfiguration cc,
425425
catchupInfo = app->getJsonInfo();
426426
return synced ? 0 : 3;
427427
}
428+
429+
int
430+
publish(Application::pointer app)
431+
{
432+
if (!checkInitialized(app))
433+
{
434+
return 1;
435+
}
436+
437+
// set known cursors before starting maintenance job
438+
ExternalQueue ps(*app);
439+
ps.setInitialCursors(app->getConfig().KNOWN_CURSORS);
440+
app->getMaintainer().start();
441+
442+
auto done = false;
443+
app->getLedgerManager().loadLastKnownLedger(
444+
[&done](asio::error_code const& ec) {
445+
if (ec)
446+
{
447+
throw std::runtime_error(
448+
"Unable to restore last-known ledger state");
449+
}
450+
451+
done = true;
452+
});
453+
auto& clock = app->getClock();
454+
while (!done && clock.crank(true))
455+
;
456+
457+
auto& io = clock.getIOService();
458+
asio::io_service::work mainWork(io);
459+
460+
auto lcl = app->getLedgerManager().getLastClosedLedgerNum();
461+
auto isCheckpoint =
462+
lcl == app->getHistoryManager().checkpointContainingLedger(lcl);
463+
auto expectedPublishQueueSize = isCheckpoint ? 1 : 0;
464+
465+
app->getHistoryManager().publishQueuedHistory();
466+
while (app->getHistoryManager().publishQueueLength() !=
467+
expectedPublishQueueSize &&
468+
clock.crank(true))
469+
{
470+
}
471+
472+
LOG(INFO) << "*";
473+
LOG(INFO) << "* Publish finished.";
474+
LOG(INFO) << "*";
475+
476+
return 0;
477+
}
428478
}

src/main/ApplicationUtils.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,4 +25,5 @@ void writeCatchupInfo(Json::Value const& catchupInfo,
2525
std::string const& outputFile);
2626
int catchup(Application::pointer app, CatchupConfiguration cc,
2727
Json::Value& catchupInfo);
28+
int publish(Application::pointer app);
2829
}

src/main/CommandLine.cpp

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -414,6 +414,21 @@ runCatchup(CommandLineArgs const& args)
414414
});
415415
}
416416

417+
int
418+
runPublish(CommandLineArgs const& args)
419+
{
420+
CommandLine::ConfigOption configOption;
421+
422+
return runWithHelp(args, {configurationParser(configOption)}, [&] {
423+
auto config = configOption.getConfig();
424+
config.setNoListen();
425+
426+
VirtualClock clock(VirtualClock::REAL_TIME);
427+
auto app = Application::create(clock, config, false);
428+
return publish(app);
429+
});
430+
}
431+
417432
int
418433
runCheckQuorum(CommandLineArgs const& args)
419434
{
@@ -712,6 +727,11 @@ handleCommandLine(int argc, char* const* argv)
712727
{"offline-info", "return information for an offline instance",
713728
runOfflineInfo},
714729
{"print-xdr", "pretty-print one XDR envelope, then quit", runPrintXdr},
730+
{"publish",
731+
"execute publish of all items remaining in publish queue without "
732+
"connecting to network, may not publish last checkpoint if last "
733+
"closed ledger is on checkpoint boundary",
734+
runPublish},
715735
{"report-last-history-checkpoint",
716736
"report information about last checkpoint available in "
717737
"history archives",

0 commit comments

Comments
 (0)