Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

services/horizon: Relax requirement on Core URL flags #2780

Merged
merged 6 commits into from
Jul 3, 2020

Conversation

2opremio
Copy link
Contributor

@2opremio 2opremio commented Jul 2, 2020

They shouldn't be required when captive core is used

PR Checklist

PR Structure

  • This PR has reasonably narrow scope (if not, break it down into smaller PRs).
  • This PR avoids mixing refactoring changes with feature changes (split into two PRs
    otherwise).
  • [ x This PR's title starts with name of package that is most changed in the PR, ex.
    services/friendbot, or all or doc if the changes are broad or impact many
    packages.

Thoroughness

  • This PR adds tests for the most critical parts of the new functionality or fixes.
  • I've updated any docs (developer docs, .md
    files, etc... affected by this change). Take a look in the docs folder for a given service,
    like this one.

Release planning

  • I've updated the relevant CHANGELOG (here for Horizon) if
    needed with deprecations, added features, breaking changes, and DB schema changes.
  • I've decided if this PR requires a new major/minor version according to
    semver, or if it's mainly a patch change. The PR is targeted at the next
    release branch if it's not a patch change.

What

Only require --stellar-core-db-url and --stellar-core-url explicitly when they are really needed.

Fixes #2779

Why

An external Core instance is not required when using Captive Core, imposing artificial restrictions

Known limitations

The message printed out won't be identical to the one printed by Cobra.

They shouldn't be required when captive core is used
@2opremio 2opremio requested a review from a team July 2, 2020 15:10
@cla-bot cla-bot bot added the cla: yes label Jul 2, 2020
@2opremio 2opremio mentioned this pull request Jul 2, 2020
7 tasks
Comment on lines +223 to +225
if config.StellarCoreDatabaseURL == "" {
log.Fatalf("flag --%s cannot be empty", stellarCoreDBURLFlagName)
}
Copy link
Contributor

Choose a reason for hiding this comment

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

The problem with the current solution is that duplicates code. Another possibility would be to move this check inside initRootConfig and add a param that explains the config context (normal run, reingestion, verify-range, ...).

Copy link
Contributor Author

@2opremio 2opremio Jul 2, 2020

Choose a reason for hiding this comment

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

I don't think we should worry too much about duplicated code since the Core dependency is going away medium-term.

Also, as I understand, the solution you propose needs to consider what command is being run, which is prone to error and handles command options far away from the command itself (I would rather do the check where the flag is used, for readibility).

Copy link
Contributor

Choose a reason for hiding this comment

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

I don't think the old database backend will be removed right after we move captive out of experimental mode. There are many Horizon deployments out there and they will definitely need time to migrate.

As for duplication, actually we don't need to add params. Checking StellarCoreDatabaseURL depends on EnableCaptiveCoreIngestion which is already present in initRootConfig. The only thing we need to check is StellarCoreDatabaseURL and we can actually do it in root command.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

As for duplication, actually we don't need to add params. Checking StellarCoreDatabaseURL depends on EnableCaptiveCoreIngestion which is already present in initRootConfig. The only thing we need to check is StellarCoreDatabaseURL and we can actually do it in root command.

That's not really the case, because right now the root command (and serve) need to use the Core URLs when ingestion is enabled regardless of the value of EnableCaptiveCoreIngestion

Copy link
Contributor Author

@2opremio 2opremio Jul 2, 2020

Choose a reason for hiding this comment

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

I don't think the old database backend will be removed right after we move captive out of experimental mode.

I didn't assume that, I said it will be removed medium-term.

Copy link
Contributor

@bartekn bartekn Jul 2, 2020

Choose a reason for hiding this comment

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

I didn't assume that, I said it will be removed medium-term.

I mean, the duplication wouldn't be a problem if we were to remove it in the next or following release but it's likely it will stay in the codebase for at least a couple months.

That's not really the case, because right now the root command (and serve) need to use the Core URLs when ingestion is enabled regardless of the value of EnableCaptiveCoreIngestion

There's a mistake in my comment I meant:

The only thing we need to check is StellarCoreURL and we can actually do it in root command.

Sorry! So to be more clear:

  1. We move all the duplicated StellarCoreDatabaseURL checks to initRootCommand because we need EnableCaptiveCoreIngestion and Ingest values for proper validation and they are already there. StellarCoreDatabaseURL right now is only used in ingestion (ledger backend).
  2. We only check for StellarCoreURL in webserver and ingestion (but not when reingesting because we don't update the cursor). So we just validate it in serve because this is when it's really needed.

Sorry if I'm missing something but doing this will remove 4 x if config.StellarCoreDatabaseURL == "" { ... } so I guess it's worth a try.

Giving 👍 because I'm leaving soon and don't want to block this if there's really a mistake in my thinking.

Copy link
Contributor Author

@2opremio 2opremio Jul 3, 2020

Choose a reason for hiding this comment

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

1. We move all the duplicated `StellarCoreDatabaseURL` checks to `initRootCommand` because we need `EnableCaptiveCoreIngestion` and `Ingest` values for proper validation and they are already there. `StellarCoreDatabaseURL` right now is only used in ingestion (ledger backend).

But ... isn't StellarCoreDatabaseURL required for online ingestion even if EnableCaptiveCoreIngestion isn't defined?

Copy link
Contributor Author

@2opremio 2opremio Jul 3, 2020

Choose a reason for hiding this comment

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

OK. That is solvable by enforcing StellarCoreDatabaseURL in the serve command.

But then ... horizon db reingest range and horizon expingest {stress-test, verify-range} need to check that StellarCoreDatabaseURL or CaptiveCore are enabled regardless of the value of Ingest (because isn't checked), which isn't the case for the rest of the commands.

I don't see a way to to generalize it in the root initialization without checking what command is invoked.

Copy link
Contributor Author

@2opremio 2opremio Jul 3, 2020

Choose a reason for hiding this comment

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

So, I think I will merge as is. If you think you can generalize it in an elegant way without breaking existing behavior, I will be more than happy to change it.

NetworkPassphrase: config.NetworkPassphrase,
HistorySession: horizonSession,
HistoryArchiveURL: config.HistoryArchiveURLs[0],
}
if config.EnableCaptiveCoreIngestion {
ingestConfig.StellarCorePath = config.StellarCoreBinaryPath
} else {
if config.StellarCoreDatabaseURL == "" {
Copy link
Contributor

Choose a reason for hiding this comment

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

@2opremio is there maybe a way to specify conditional requirements in cobra? Like, this is only required if EnableCaptiveCoreIngestion is empty.

Copy link
Contributor

Choose a reason for hiding this comment

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

@abuiles something like this is done in initRootConfig, we already have a similar code there:

	if config.EnableCaptiveCoreIngestion && config.StellarCoreBinaryPath == "" {
		stdLog.Fatalf("--stellar-core-binary-path must be set when --enable-captive-core-ingestion is set")
	}

Copy link
Contributor

@bartekn bartekn left a comment

Choose a reason for hiding this comment

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

👍 but please check my last comment about duplication and #2780 (comment).

@2opremio
Copy link
Contributor Author

2opremio commented Jul 3, 2020

Only require --stellar-core-db-url and --stellar-core-url explicitly when they are really needed.

An external Core instance is not required when using Captive Core, imposing artificial restrictions

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants