Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions services/horizon/internal/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -124,4 +124,7 @@ type Config struct {
DisableTxSub bool
// SkipTxmeta, when enabled, will not store meta xdr in history transaction table
SkipTxmeta bool
// EmitVerboseMeta, when enabled will include all kinds of events in txMeta - diagnosticEvents/classicEvents
// SkipTxMeta and EmitVerboseMeta dont go hand in hand. i.e EmitVerboseMeta cannot be TRUE if SkipTxMeta is set to TRUE
EmitVerboseMeta bool
}
16 changes: 16 additions & 0 deletions services/horizon/internal/flags.go
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,8 @@ const (
DisableTxSubFlagName = "disable-tx-sub"
// SkipTxmeta is the command line flag for disabling persistence of tx meta in history transaction table
SkipTxmeta = "skip-txmeta"
// EmitVerboseMeta is the command line flag for enabling all kinds of verbose events - diagnosticEvents, classicEvents during ingestion
EmitVerboseMeta = "emit-verbose-meta"

// StellarPubnet is a constant representing the Stellar public network
StellarPubnet = "pubnet"
Expand Down Expand Up @@ -801,6 +803,15 @@ func Flags() (*Config, support.ConfigOptions) {
Usage: "excludes tx meta from persistence on transaction history",
UsedInCommands: IngestionCommands,
},
&support.ConfigOption{
Name: EmitVerboseMeta,
ConfigKey: &config.EmitVerboseMeta,
OptType: types.Bool,
FlagDefault: false,
Required: false,
Usage: "enables all events to be present in txMeta. Do not set SKIP_TXMETA and EMIT_VERBOSE_META to true at the same time.",
UsedInCommands: IngestionCommands,
},
}

return config, flags
Expand Down Expand Up @@ -865,6 +876,7 @@ func setCaptiveCoreConfiguration(config *Config, options ApplyOptions) error {
config.CaptiveCoreTomlParams.CoreBinaryPath = config.CaptiveCoreBinaryPath
config.CaptiveCoreTomlParams.HistoryArchiveURLs = config.HistoryArchiveURLs
config.CaptiveCoreTomlParams.NetworkPassphrase = config.NetworkPassphrase
config.CaptiveCoreTomlParams.EmitVerboseMeta = config.EmitVerboseMeta

if config.CaptiveCoreConfigPath != "" {
config.CaptiveCoreToml, err = ledgerbackend.NewCaptiveCoreTomlFromFile(config.CaptiveCoreConfigPath,
Expand Down Expand Up @@ -923,6 +935,10 @@ func ApplyFlags(config *Config, flags support.ConfigOptions, options ApplyOption
return err
}

if config.SkipTxmeta && config.EmitVerboseMeta {
return fmt.Errorf("invalid config: Only one of SKIP_TXMETA and EMIT_VERBOSE_META can be set to TRUE, not both")
}

if config.Ingest {
// Migrations should be checked as early as possible. Apply and check
// only on ingesting instances which are required to have write-access
Expand Down
60 changes: 60 additions & 0 deletions services/horizon/internal/flags_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package horizon
import (
"fmt"
"os"
"strconv"
"testing"
"time"

Expand Down Expand Up @@ -338,6 +339,65 @@ func horizonEnvVars() map[string]string {
}
}

func TestSkipTxMetaAndEmitVerboseMetaCombination(t *testing.T) {
tests := []struct {
name string
skipTxMeta bool
emitVerboseMeta bool
errStr string
}{
{
name: "Only SKIP_TXMETA enabled",
skipTxMeta: true,
emitVerboseMeta: false,
},
{
name: "Only EMIT_VERBOSE_META enabled",
skipTxMeta: false,
emitVerboseMeta: true,
},
{
name: "SKIP_TXMETA and EMIT_VERBOSE_META enabled",
skipTxMeta: true,
emitVerboseMeta: true,
errStr: "Only one of SKIP_TXMETA and EMIT_VERBOSE_META can be set to TRUE, not both",
},
}

for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
envVars := horizonEnvVars()
envVars["SKIP_TXMETA"] = strconv.FormatBool(tt.skipTxMeta)
envVars["EMIT_VERBOSE_META"] = strconv.FormatBool(tt.emitVerboseMeta)

envManager := test.NewEnvironmentManager()
defer func() {
envManager.Restore()
}()
require.NoError(t, envManager.InitializeEnvironmentVariables(envVars))
config, flags := Flags()
horizonCmd := &cobra.Command{
Use: "horizon",
Short: "Client-facing api server for the Stellar network",
SilenceErrors: true,
SilenceUsage: true,
Long: "Client-facing API server for the Stellar network.",
}
require.NoError(t, flags.Init(horizonCmd))

err := ApplyFlags(config, flags, ApplyOptions{RequireCaptiveCoreFullConfig: true})
if tt.errStr == "" {
assert.NoError(t, err)
assert.Equal(t, config.SkipTxmeta, tt.skipTxMeta)
assert.Equal(t, config.EmitVerboseMeta, tt.emitVerboseMeta)
} else {
assert.Error(t, err)
assert.Contains(t, err.Error(), tt.errStr)
}
})
}
}

func TestRemovedFlags(t *testing.T) {
tests := []struct {
name string
Expand Down
Loading