Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions docs/software/commands.md
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,9 @@ stellar-core can be controlled via the following commands.
controls type used for printing (default: auto).<br>
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.
Expand Down
50 changes: 50 additions & 0 deletions src/main/ApplicationUtils.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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);

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

it would be cleaner to just set the right config elements so that app->start() does what you want (in this case, I think you just need to set STANDALONE to true)

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

STANDALONE is set before - in CommandLine.cpp:runPublish function, by calling to Config::setNoListen.

Maintenance job is normally started in ApplicationImpl::start, which we don't use in command-line catchup and publish. I think we could move calling maintenance to the end of catchup/publish process, or just ignore that and postpone the maintenance itself to normal stellar-core runs (but we can't be sure there will be no instances of stellar-core used only for command-line catchup and publish).

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You didn't understand my question: why not calling start if standalone is already set?

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;
}
}
1 change: 1 addition & 0 deletions src/main/ApplicationUtils.h
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
20 changes: 20 additions & 0 deletions src/main/CommandLine.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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)
{
Expand Down Expand Up @@ -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",
Expand Down