diff --git a/bootstrap/bootstrap.go b/bootstrap/bootstrap.go index 9430603dc..fe9690913 100644 --- a/bootstrap/bootstrap.go +++ b/bootstrap/bootstrap.go @@ -47,6 +47,14 @@ func Start(ctx context.Context, cfg *config.Config) error { logger.Info().Msg("database initialized with 0 evm and cadence heights") } + // this should only be used locally or for testing + if cfg.ForceStartCadenceHeight != 0 { + logger.Warn().Uint64("height", cfg.ForceStartCadenceHeight).Msg("force setting starting Cadence height!!!") + if err := blocks.SetLatestCadenceHeight(cfg.ForceStartCadenceHeight); err != nil { + return err + } + } + go func() { err := startServer( ctx, diff --git a/config/config.go b/config/config.go index d181d5adf..f1fad47e2 100644 --- a/config/config.go +++ b/config/config.go @@ -65,13 +65,15 @@ type Config struct { StreamTimeout time.Duration // FilterExpiry defines the time it takes for an idle filter to expire FilterExpiry time.Duration + // ForceStartCadenceHeight will force set the starting Cadence height, this should be only used for testing or locally. + ForceStartCadenceHeight uint64 } func FromFlags() (*Config, error) { cfg := &Config{} var evmNetwork, coinbase, gas, coa, key, keysPath, flowNetwork, logLevel, filterExpiry string var streamTimeout int - var initHeight uint64 + var initHeight, forceStartHeight uint64 // parse from flags flag.StringVar(&cfg.DatabaseDir, "database-dir", "./db", "Path to the directory for the database") @@ -90,6 +92,7 @@ func FromFlags() (*Config, error) { flag.StringVar(&logLevel, "log-level", "debug", "Define verbosity of the log output ('debug', 'info', 'error')") flag.Float64Var(&cfg.StreamLimit, "stream-limit", 10, "Rate-limits the events sent to the client within one second") flag.IntVar(&streamTimeout, "stream-timeout", 3, "Defines the timeout in seconds the server waits for the event to be sent to the client") + flag.Uint64Var(&forceStartHeight, "force-start-height", 0, "Force set starting Cadence height. This should only be used locally or for testing, never in production.") flag.StringVar(&filterExpiry, "filter-expiry", "5m", "Filter defines the time it takes for an idle filter to expire") flag.Parse() @@ -181,6 +184,10 @@ func FromFlags() (*Config, error) { } cfg.FilterExpiry = exp + if forceStartHeight != 0 { + cfg.ForceStartCadenceHeight = forceStartHeight + } + // todo validate Config values return cfg, nil }