diff --git a/CHANGELOG.md b/CHANGELOG.md index 90b3a95..6822114 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -5,6 +5,12 @@ All notable changes to this project will be documented in this file. The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/), and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html). +## Unreleased + +### Fixed + +* Fixed typo in flag name `--on-module-hash-mistmatch` → `--on-module-hash-mismatch`. The old flag name is still supported for backward compatibility but is deprecated and will be removed in a future version. A deprecation warning will be logged if the old flag is used. + ## v4.12.0 ### DatabaseChanges mode improvements diff --git a/cmd/substreams-sink-sql/common_flags.go b/cmd/substreams-sink-sql/common_flags.go index d948526..4759498 100644 --- a/cmd/substreams-sink-sql/common_flags.go +++ b/cmd/substreams-sink-sql/common_flags.go @@ -4,9 +4,11 @@ import ( "context" "time" + "github.com/spf13/cobra" "github.com/spf13/pflag" "github.com/streamingfast/bstream" "github.com/streamingfast/cli" + "github.com/streamingfast/cli/sflags" "github.com/streamingfast/shutter" sink "github.com/streamingfast/substreams-sink" pbsubstreams "github.com/streamingfast/substreams/pb/sf/substreams/v1" @@ -14,7 +16,8 @@ import ( ) var ( - onModuleHashMistmatchFlag = "on-module-hash-mistmatch" + onModuleHashMismatchFlag = "on-module-hash-mismatch" // new, correct spelling + onModuleHashMistmatchFlagDeprecated = "on-module-hash-mistmatch" // old, typo (deprecated) ) var supportedOutputTypes = "sf.substreams.sink.database.v1.DatabaseChanges,sf.substreams.database.v1.DatabaseChanges" @@ -22,7 +25,7 @@ var supportedOutputTypes = "sf.substreams.sink.database.v1.DatabaseChanges,sf.su // AddCommonSinkerFlags adds the flags common to all command that needs to create a sinker, // namely the `run` and `generate-csv` commands. func AddCommonSinkerFlags(flags *pflag.FlagSet) { - flags.String(onModuleHashMistmatchFlag, "error", cli.FlagDescription(` + flags.String(onModuleHashMismatchFlag, "error", cli.FlagDescription(` What to do when the module hash in the manifest does not match the one in the database, can be 'error', 'warn' or 'ignore' - If 'error' is used (default), it will exit with an error explaining the problem and how to fix it. @@ -30,6 +33,9 @@ func AddCommonSinkerFlags(flags *pflag.FlagSet) { - If 'ignore' is set, we pick the cursor at the highest block number and use it as the starting point. Subsequent updates to the cursor will overwrite the module hash in the database. `)) + // Register deprecated flag for backward compatibility + flags.String(onModuleHashMistmatchFlagDeprecated, "error", "(deprecated) use --on-module-hash-mismatch instead") + flags.Lookup(onModuleHashMistmatchFlagDeprecated).Deprecated = "use --on-module-hash-mismatch instead" } func AddCommonDatabaseChangesFlags(flags *pflag.FlagSet) { @@ -81,3 +87,14 @@ func (a *cliApplication) WaitForTermination(logger *zap.Logger, unreadyPeriodAft logger.Info("run terminated gracefully") return nil } + +// resolveOnModuleHashMismatchFlag resolves the on-module-hash-mismatch flag with deprecation support. +func resolveOnModuleHashMismatchFlag(cmd *cobra.Command) string { + // Use deprecated value if set by provider + if value, provided := sflags.MustGetStringProvided(cmd, onModuleHashMistmatchFlagDeprecated); provided { + return value + } + + // Deprecated flag wasn't explicitly set, return default from correct flag + return sflags.MustGetString(cmd, onModuleHashMismatchFlag) +} diff --git a/cmd/substreams-sink-sql/generate_csv.go b/cmd/substreams-sink-sql/generate_csv.go index 63835ec..195c34c 100644 --- a/cmd/substreams-sink-sql/generate_csv.go +++ b/cmd/substreams-sink-sql/generate_csv.go @@ -124,7 +124,7 @@ func generateCsvE(cmd *cobra.Command, args []string) error { historyTableName, sflags.MustGetString(cmd, "clickhouse-cluster"), 0, 0, 0, - sflags.MustGetString(cmd, onModuleHashMistmatchFlag), + resolveOnModuleHashMismatchFlag(cmd), &handleReorgs, zlog, tracer, ) diff --git a/cmd/substreams-sink-sql/run.go b/cmd/substreams-sink-sql/run.go index d84d267..db73c61 100644 --- a/cmd/substreams-sink-sql/run.go +++ b/cmd/substreams-sink-sql/run.go @@ -109,7 +109,7 @@ func sinkRunE(cmd *cobra.Command, args []string) error { BatchBlockFlushInterval: batchBlockFlushInterval, BatchRowFlushInterval: batchRowFlushInterval, LiveBlockFlushInterval: liveBlockFlushInterval, - OnModuleHashMismatch: sflags.MustGetString(cmd, onModuleHashMistmatchFlag), + OnModuleHashMismatch: resolveOnModuleHashMismatchFlag(cmd), HandleReorgs: handleReorgs, FlushRetryCount: flushRetryCount, FlushRetryDelay: flushRetryDelay, diff --git a/cmd/substreams-sink-sql/setup.go b/cmd/substreams-sink-sql/setup.go index d043611..883fdd9 100644 --- a/cmd/substreams-sink-sql/setup.go +++ b/cmd/substreams-sink-sql/setup.go @@ -44,7 +44,7 @@ func sinkSetupE(cmd *cobra.Command, args []string) error { CursorTableName: sflags.MustGetString(cmd, "cursors-table"), HistoryTableName: sflags.MustGetString(cmd, "history-table"), ClickhouseCluster: sflags.MustGetString(cmd, "clickhouse-cluster"), - OnModuleHashMismatch: sflags.MustGetString(cmd, onModuleHashMistmatchFlag), + OnModuleHashMismatch: resolveOnModuleHashMismatchFlag(cmd), SystemTablesOnly: sflags.MustGetBool(cmd, "system-tables-only"), IgnoreDuplicateTableErrors: sflags.MustGetBool(cmd, "ignore-duplicate-table-errors"), Postgraphile: sflags.MustGetBool(cmd, "postgraphile"), diff --git a/cmd/substreams-sink-sql/tools.go b/cmd/substreams-sink-sql/tools.go index d6f8869..ef0dca1 100644 --- a/cmd/substreams-sink-sql/tools.go +++ b/cmd/substreams-sink-sql/tools.go @@ -183,7 +183,7 @@ func toolsCreateLoader(cmd *cobra.Command) (*db2.Loader, error) { historyTableName, sflags.MustGetString(cmd, "clickhouse-cluster"), 0, 0, 0, - sflags.MustGetString(cmd, onModuleHashMistmatchFlag), + resolveOnModuleHashMismatchFlag(cmd), &handleReorgs, zlog, tracer, ) diff --git a/db_changes/db/cursor.go b/db_changes/db/cursor.go index 9bd050c..94ac097 100644 --- a/db_changes/db/cursor.go +++ b/db_changes/db/cursor.go @@ -46,7 +46,7 @@ func (l *Loader) GetAllCursors(ctx context.Context) (out map[string]*sink.Cursor return out, nil } -func (l *Loader) GetCursor(ctx context.Context, outputModuleHash string) (cursor *sink.Cursor, mistmatchDetected bool, err error) { +func (l *Loader) GetCursor(ctx context.Context, outputModuleHash string) (cursor *sink.Cursor, mismatchDetected bool, err error) { cursors, err := l.GetAllCursors(ctx) if err != nil { return nil, false, fmt.Errorf("get cursor: %w", err) @@ -71,7 +71,7 @@ func (l *Loader) GetCursor(ctx context.Context, outputModuleHash string) (cursor case OnModuleHashMismatchWarn: l.logger.Warn( - fmt.Sprintf("cursor module hash mismatch, continuing using cursor at highest block %s, this warning can be made silent by using '--on-module-hash-mistmatch=ignore'", activeCursor.Block()), + fmt.Sprintf("cursor module hash mismatch, continuing using cursor at highest block %s, this warning can be made silent by using '--on-module-hash-mismatch=ignore'", activeCursor.Block()), zap.String("expected_module_hash", outputModuleHash), zap.String("actual_module_hash", actualOutputModuleHash), ) @@ -79,7 +79,7 @@ func (l *Loader) GetCursor(ctx context.Context, outputModuleHash string) (cursor return activeCursor, true, err case OnModuleHashMismatchError: - return nil, true, fmt.Errorf("cursor module hash mismatch, refusing to continue because flag '--on-module-hash-mistmatch=error' (defaults) is set, you can change to 'warn' or 'ignore': your module's hash is %q but cursor with highest block (%d) module hash is actually %q in the database", + return nil, true, fmt.Errorf("cursor module hash mismatch, refusing to continue because flag '--on-module-hash-mismatch=error' (defaults) is set, you can change to 'warn' or 'ignore': your module's hash is %q but cursor with highest block (%d) module hash is actually %q in the database", outputModuleHash, activeCursor.Block().Num(), actualOutputModuleHash,