-
Notifications
You must be signed in to change notification settings - Fork 501
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
Changes from 1 commit
e9da0e6
4469aac
8902fd1
3faaff2
fc33126
a3bf665
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -24,31 +24,31 @@ var ingestVerifyFrom, ingestVerifyTo, ingestVerifyDebugServerPort uint32 | |
var ingestVerifyState bool | ||
|
||
var ingestVerifyRangeCmdOpts = []*support.ConfigOption{ | ||
&support.ConfigOption{ | ||
{ | ||
Name: "from", | ||
ConfigKey: &ingestVerifyFrom, | ||
OptType: types.Uint32, | ||
Required: true, | ||
FlagDefault: uint32(0), | ||
Usage: "first ledger of the range to ingest", | ||
}, | ||
&support.ConfigOption{ | ||
{ | ||
Name: "to", | ||
ConfigKey: &ingestVerifyTo, | ||
OptType: types.Uint32, | ||
Required: true, | ||
FlagDefault: uint32(0), | ||
Usage: "last ledger of the range to ingest", | ||
}, | ||
&support.ConfigOption{ | ||
{ | ||
Name: "verify-state", | ||
ConfigKey: &ingestVerifyState, | ||
OptType: types.Bool, | ||
Required: false, | ||
FlagDefault: false, | ||
Usage: "[optional] verifies state at the last ledger of the range when true", | ||
}, | ||
&support.ConfigOption{ | ||
{ | ||
Name: "debug-server-port", | ||
ConfigKey: &ingestVerifyDebugServerPort, | ||
OptType: types.Uint32, | ||
|
@@ -83,11 +83,6 @@ var ingestVerifyRangeCmd = &cobra.Command{ | |
}() | ||
} | ||
|
||
coreSession, err := db.Open("postgres", config.StellarCoreDatabaseURL) | ||
if err != nil { | ||
log.Fatalf("cannot open Core DB: %v", err) | ||
} | ||
|
||
horizonSession, err := db.Open("postgres", config.DatabaseURL) | ||
if err != nil { | ||
log.Fatalf("cannot open Horizon DB: %v", err) | ||
|
@@ -102,13 +97,22 @@ var ingestVerifyRangeCmd = &cobra.Command{ | |
} | ||
|
||
ingestConfig := expingest.Config{ | ||
CoreSession: coreSession, | ||
NetworkPassphrase: config.NetworkPassphrase, | ||
HistorySession: horizonSession, | ||
HistoryArchiveURL: config.HistoryArchiveURLs[0], | ||
} | ||
if config.EnableCaptiveCoreIngestion { | ||
ingestConfig.StellarCorePath = config.StellarCoreBinaryPath | ||
} else { | ||
if config.StellarCoreDatabaseURL == "" { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @abuiles something like this is done in if config.EnableCaptiveCoreIngestion && config.StellarCoreBinaryPath == "" {
stdLog.Fatalf("--stellar-core-binary-path must be set when --enable-captive-core-ingestion is set")
} |
||
log.Fatalf("flag --%s cannot be empty", stellarCoreDBURLFlagName) | ||
} | ||
|
||
coreSession, err := db.Open("postgres", config.StellarCoreDatabaseURL) | ||
if err != nil { | ||
log.Fatalf("cannot open Core DB: %v", err) | ||
} | ||
ingestConfig.CoreSession = coreSession | ||
} | ||
|
||
system, err := expingest.NewSystem(ingestConfig) | ||
|
@@ -132,15 +136,15 @@ var ingestVerifyRangeCmd = &cobra.Command{ | |
var stressTestNumTransactions, stressTestChangesPerTransaction int | ||
|
||
var stressTestCmdOpts = []*support.ConfigOption{ | ||
&support.ConfigOption{ | ||
{ | ||
Name: "transactions", | ||
ConfigKey: &stressTestNumTransactions, | ||
OptType: types.Int, | ||
Required: false, | ||
FlagDefault: int(1000), | ||
Usage: "total number of transactions to ingest (at most 1000)", | ||
}, | ||
&support.ConfigOption{ | ||
{ | ||
Name: "changes", | ||
ConfigKey: &stressTestChangesPerTransaction, | ||
OptType: types.Int, | ||
|
@@ -162,11 +166,6 @@ var ingestStressTestCmd = &cobra.Command{ | |
|
||
initRootConfig() | ||
|
||
coreSession, err := db.Open("postgres", config.StellarCoreDatabaseURL) | ||
if err != nil { | ||
log.Fatalf("cannot open Core DB: %v", err) | ||
} | ||
|
||
horizonSession, err := db.Open("postgres", config.DatabaseURL) | ||
if err != nil { | ||
log.Fatalf("cannot open Horizon DB: %v", err) | ||
|
@@ -181,13 +180,23 @@ var ingestStressTestCmd = &cobra.Command{ | |
} | ||
|
||
ingestConfig := expingest.Config{ | ||
CoreSession: coreSession, | ||
NetworkPassphrase: config.NetworkPassphrase, | ||
HistorySession: horizonSession, | ||
HistoryArchiveURL: config.HistoryArchiveURLs[0], | ||
} | ||
|
||
if config.EnableCaptiveCoreIngestion { | ||
ingestConfig.StellarCorePath = config.StellarCoreBinaryPath | ||
} else { | ||
if config.StellarCoreDatabaseURL == "" { | ||
log.Fatalf("flag --%s cannot be empty", stellarCoreDBURLFlagName) | ||
} | ||
|
||
coreSession, err := db.Open("postgres", config.StellarCoreDatabaseURL) | ||
if err != nil { | ||
log.Fatalf("cannot open Core DB: %v", err) | ||
} | ||
ingestConfig.CoreSession = coreSession | ||
} | ||
|
||
system, err := expingest.NewSystem(ingestConfig) | ||
|
There was a problem hiding this comment.
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, ...).There was a problem hiding this comment.
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).
There was a problem hiding this comment.
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 onEnableCaptiveCoreIngestion
which is already present ininitRootConfig
. The only thing we need to check isStellarCoreDatabaseURL
and we can actually do it in root command.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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 was a problem hiding this comment.
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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.
There's a mistake in my comment I meant:
Sorry! So to be more clear:
StellarCoreDatabaseURL
checks toinitRootCommand
because we needEnableCaptiveCoreIngestion
andIngest
values for proper validation and they are already there.StellarCoreDatabaseURL
right now is only used in ingestion (ledger backend).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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
But ... isn't
StellarCoreDatabaseURL
required for online ingestion even ifEnableCaptiveCoreIngestion
isn't defined?There was a problem hiding this comment.
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 theserve
command.But then ...
horizon db reingest range
andhorizon expingest {stress-test, verify-range}
need to check thatStellarCoreDatabaseURL
orCaptiveCore
are enabled regardless of the value ofIngest
(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.
There was a problem hiding this comment.
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.