Skip to content

Commit

Permalink
Merge pull request #232 from onflow/gregor/force-skip
Browse files Browse the repository at this point in the history
Add force set height flag
  • Loading branch information
sideninja authored May 7, 2024
2 parents 8fa4dbc + 05f9341 commit ff040b3
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 1 deletion.
8 changes: 8 additions & 0 deletions bootstrap/bootstrap.go
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
9 changes: 8 additions & 1 deletion config/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -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")
Expand All @@ -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()

Expand Down Expand Up @@ -181,6 +184,10 @@ func FromFlags() (*Config, error) {
}
cfg.FilterExpiry = exp

if forceStartHeight != 0 {
cfg.ForceStartCadenceHeight = forceStartHeight
}

// todo validate Config values
return cfg, nil
}

0 comments on commit ff040b3

Please sign in to comment.