From 7685e08fb4c835f4771090dbf97cced1391a0a44 Mon Sep 17 00:00:00 2001 From: Christian Jonas Date: Wed, 6 May 2026 23:33:57 -0400 Subject: [PATCH 1/5] added config embedding, options takes config []byte --- ingest/loadtest/apply_load.go | 37 +++++++++++-------- ingest/loadtest/apply_load_test.go | 13 ++----- .../default-apply-load.cfg | 0 3 files changed, 26 insertions(+), 24 deletions(-) rename ingest/loadtest/{testdata => configs}/default-apply-load.cfg (100%) diff --git a/ingest/loadtest/apply_load.go b/ingest/loadtest/apply_load.go index d69730f030..198b1d44a1 100644 --- a/ingest/loadtest/apply_load.go +++ b/ingest/loadtest/apply_load.go @@ -2,6 +2,7 @@ package loadtest import ( "context" + _ "embed" "fmt" "io" "os" @@ -23,9 +24,18 @@ import ( "github.com/stellar/go-stellar-sdk/xdr" ) +//go:embed configs/default-apply-load.cfg +var defaultConfig []byte + +// DefaultConfig returns the contents of the default apply-load configuration +// shipped with this package. +func DefaultConfig() []byte { + return defaultConfig +} + type Options struct { // inputs - ConfigPath string + Config []byte // raw bytes of config OutputPath string FixturesPath string CoreBinaryPath string // optional, will be looked up in PATH if not set @@ -60,7 +70,7 @@ func ApplyLoad(ctx context.Context, opts Options) (Results, error) { } }() } - cfg, err := parseConfig(opts.ConfigPath) + cfg, err := parseConfig(opts.Config) if err != nil { return Results{}, fmt.Errorf("failed to parse config: %w", err) } @@ -93,11 +103,8 @@ func ApplyLoad(ctx context.Context, opts Options) (Results, error) { // resolveOptions checks that required options are set and valid, and fills in defaults for optional ones. func resolveOptions(opts *Options) error { - if opts.ConfigPath == "" { - return fmt.Errorf("configPath is required") - } if opts.OutputPath == "" || opts.FixturesPath == "" { - return fmt.Errorf("both outputPath and fixturesPath are required") + return fmt.Errorf("outputPath and fixturesPath are required") } if opts.CoreBinaryPath == "" { @@ -118,9 +125,12 @@ func resolveOptions(opts *Options) error { if opts.Logger == nil { opts.Logger = log.New() } + if opts.Config == nil { + opts.Config = DefaultConfig() + opts.Logger.Infof("no config provided, using default config") + } opts.Logger.Infof("Using stellar-core: %s %s", opts.CoreBinaryPath, coreVersion) - opts.Logger.Infof("Using config: %s", opts.ConfigPath) if opts.WorkDirPath == "" { var err error @@ -136,7 +146,7 @@ func resolveOptions(opts *Options) error { func run(ctx context.Context, opts Options, cfg applyLoadConfig) (uint32, error) { // Copy config to work dir (apply-load writes files relative to config location) destConfigPath := filepath.Join(opts.WorkDirPath, "apply-load.cfg") - if err := copyFile(opts.ConfigPath, destConfigPath); err != nil { + if err := os.WriteFile(destConfigPath, opts.Config, 0o644); err != nil { return 0, err } @@ -484,15 +494,12 @@ type applyLoadConfig struct { HistoryArchiveName string } -func parseConfig(configPath string) (applyLoadConfig, error) { - data, err := os.ReadFile(configPath) - if err != nil { - return applyLoadConfig{}, err +func parseConfig(config []byte) (applyLoadConfig, error) { + if config == nil { + return applyLoadConfig{}, fmt.Errorf("config is required") } - var raw map[string]any - err = toml.Unmarshal(data, &raw) - if err != nil { + if err := toml.Unmarshal(config, &raw); err != nil { return applyLoadConfig{}, err } diff --git a/ingest/loadtest/apply_load_test.go b/ingest/loadtest/apply_load_test.go index bca3f073e5..91b8267d4b 100644 --- a/ingest/loadtest/apply_load_test.go +++ b/ingest/loadtest/apply_load_test.go @@ -1,8 +1,6 @@ package loadtest import ( - "os" - "path/filepath" "strings" "testing" @@ -59,7 +57,7 @@ func TestParsePreBenchmarkCheckpoint(t *testing.T) { // shipped with this package. Updating default-apply-load.cfg without // updating the expected values here will fail this test. func TestParseConfig_DefaultCfg(t *testing.T) { - got, err := parseConfig("testdata/default-apply-load.cfg") + got, err := parseConfig(DefaultConfig()) require.NoError(t, err) assert.Equal(t, applyLoadConfig{ NetworkPassphrase: "load test network", @@ -115,10 +113,7 @@ get = "cp history/{0} {1}" } for _, tt := range tests { t.Run(tt.name, func(t *testing.T) { - path := filepath.Join(t.TempDir(), "apply-load.cfg") - require.NoError(t, os.WriteFile(path, []byte(tt.contents), 0o644)) - - _, err := parseConfig(path) + _, err := parseConfig([]byte(tt.contents)) require.Error(t, err) if tt.wantErr != "" { assert.Contains(t, err.Error(), tt.wantErr) @@ -127,7 +122,7 @@ get = "cp history/{0} {1}" } } -func TestParseConfig_FileNotFound(t *testing.T) { - _, err := parseConfig(filepath.Join(t.TempDir(), "does-not-exist.cfg")) +func TestParseConfig_NoConfigFound(t *testing.T) { + _, err := parseConfig([]byte{}) require.Error(t, err) } diff --git a/ingest/loadtest/testdata/default-apply-load.cfg b/ingest/loadtest/configs/default-apply-load.cfg similarity index 100% rename from ingest/loadtest/testdata/default-apply-load.cfg rename to ingest/loadtest/configs/default-apply-load.cfg From 606d96c50460d303dcdb85d880edbe2a77471fbf Mon Sep 17 00:00:00 2001 From: Christian Jonas Date: Wed, 6 May 2026 23:38:04 -0400 Subject: [PATCH 2/5] make config optional --- ingest/loadtest/apply_load.go | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/ingest/loadtest/apply_load.go b/ingest/loadtest/apply_load.go index 198b1d44a1..79708d6f07 100644 --- a/ingest/loadtest/apply_load.go +++ b/ingest/loadtest/apply_load.go @@ -52,8 +52,8 @@ type Results struct { // ApplyLoad runs stellar-core's apply-load against the supplied config and writes // benchmark ledgers + fixture entries to OutputPath / FixturesPath. // -// Required: ConfigPath, OutputPath, FixturesPath. Optional: CoreBinaryPath -// (looked up in PATH), Logger, WorkDirPath (temp dir if unspecified). +// Required: OutputPath, FixturesPath. Optional: CoreBinaryPath (looked up in PATH), +// Logger, WorkDirPath (temp dir if unspecified), Config (defaultConfig if unspecified). // The supplied config's [HISTORY] commands must publish to a `history/` // subdirectory of the work dir. func ApplyLoad(ctx context.Context, opts Options) (Results, error) { From 7db83f43efd7f1cab3d13a9f0b2122cd5be2771f Mon Sep 17 00:00:00 2001 From: Christian Jonas Date: Wed, 6 May 2026 23:51:43 -0400 Subject: [PATCH 3/5] fix empty config check --- ingest/loadtest/apply_load.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/ingest/loadtest/apply_load.go b/ingest/loadtest/apply_load.go index 79708d6f07..6f0f4ffe41 100644 --- a/ingest/loadtest/apply_load.go +++ b/ingest/loadtest/apply_load.go @@ -495,7 +495,7 @@ type applyLoadConfig struct { } func parseConfig(config []byte) (applyLoadConfig, error) { - if config == nil { + if len(config) == 0 { return applyLoadConfig{}, fmt.Errorf("config is required") } var raw map[string]any From 9a55309004f51957ec5136acd3a2b8f24f1cae13 Mon Sep 17 00:00:00 2001 From: Christian Jonas Date: Thu, 7 May 2026 00:00:25 -0400 Subject: [PATCH 4/5] make config accessor return copy of defaultConfig --- ingest/loadtest/apply_load.go | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/ingest/loadtest/apply_load.go b/ingest/loadtest/apply_load.go index 6f0f4ffe41..4b2b1c7602 100644 --- a/ingest/loadtest/apply_load.go +++ b/ingest/loadtest/apply_load.go @@ -30,7 +30,7 @@ var defaultConfig []byte // DefaultConfig returns the contents of the default apply-load configuration // shipped with this package. func DefaultConfig() []byte { - return defaultConfig + return append([]byte(nil), defaultConfig...) } type Options struct { @@ -125,7 +125,7 @@ func resolveOptions(opts *Options) error { if opts.Logger == nil { opts.Logger = log.New() } - if opts.Config == nil { + if len(opts.Config) == 0 { opts.Config = DefaultConfig() opts.Logger.Infof("no config provided, using default config") } From a7589a3374d58c816c70bdb23d5cfe3b44181a3b Mon Sep 17 00:00:00 2001 From: Christian Jonas Date: Thu, 7 May 2026 00:01:20 -0400 Subject: [PATCH 5/5] remove unused copyFile helper --- ingest/loadtest/apply_load.go | 11 ----------- 1 file changed, 11 deletions(-) diff --git a/ingest/loadtest/apply_load.go b/ingest/loadtest/apply_load.go index 4b2b1c7602..e5985cccf3 100644 --- a/ingest/loadtest/apply_load.go +++ b/ingest/loadtest/apply_load.go @@ -556,14 +556,3 @@ func openCheckpointReader( return checkpointReader, nil } - -func copyFile(src, dst string) error { - data, err := os.ReadFile(src) - if err != nil { - return err - } - if err := os.WriteFile(dst, data, 0o644); err != nil { - return err - } - return nil -}