Skip to content

Commit 8107ece

Browse files
authored
Merge pull request #1826 from vogel/publish-command
Publish command Reviewed-by: MonsieurNicolas
2 parents 9239485 + ce473a1 commit 8107ece

4 files changed

Lines changed: 60 additions & 20 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: 36 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -331,25 +331,7 @@ catchup(Application::pointer app, CatchupConfiguration cc,
331331
return 1;
332332
}
333333

334-
// set known cursors before starting maintenance job
335-
ExternalQueue ps(*app);
336-
ps.setInitialCursors(app->getConfig().KNOWN_CURSORS);
337-
app->getMaintainer().start();
338-
339-
auto done = false;
340-
app->getLedgerManager().loadLastKnownLedger(
341-
[&done](asio::error_code const& ec) {
342-
if (ec)
343-
{
344-
throw std::runtime_error(
345-
"Unable to restore last-known ledger state");
346-
}
347-
348-
done = true;
349-
});
350-
auto& clock = app->getClock();
351-
while (!done && clock.crank(true))
352-
;
334+
app->start();
353335

354336
try
355337
{
@@ -367,10 +349,11 @@ catchup(Application::pointer app, CatchupConfiguration cc,
367349
return 2;
368350
}
369351

352+
auto& clock = app->getClock();
370353
auto& io = clock.getIOService();
371354
auto synced = false;
372355
asio::io_service::work mainWork(io);
373-
done = false;
356+
auto done = false;
374357
while (!done && clock.crank(true))
375358
{
376359
switch (app->getLedgerManager().getState())
@@ -425,4 +408,37 @@ catchup(Application::pointer app, CatchupConfiguration cc,
425408
catchupInfo = app->getJsonInfo();
426409
return synced ? 0 : 3;
427410
}
411+
412+
int
413+
publish(Application::pointer app)
414+
{
415+
if (!checkInitialized(app))
416+
{
417+
return 1;
418+
}
419+
420+
app->start();
421+
422+
auto& clock = app->getClock();
423+
auto& io = clock.getIOService();
424+
asio::io_service::work mainWork(io);
425+
426+
auto lcl = app->getLedgerManager().getLastClosedLedgerNum();
427+
auto isCheckpoint =
428+
lcl == app->getHistoryManager().checkpointContainingLedger(lcl);
429+
auto expectedPublishQueueSize = isCheckpoint ? 1 : 0;
430+
431+
app->getHistoryManager().publishQueuedHistory();
432+
while (app->getHistoryManager().publishQueueLength() !=
433+
expectedPublishQueueSize &&
434+
clock.crank(true))
435+
{
436+
}
437+
438+
LOG(INFO) << "*";
439+
LOG(INFO) << "* Publish finished.";
440+
LOG(INFO) << "*";
441+
442+
return 0;
443+
}
428444
}

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)