From 4f8aa3a22ddb048e8776592ca529b212f6e154d0 Mon Sep 17 00:00:00 2001 From: Tamir Sen Date: Tue, 8 Dec 2020 11:27:43 +0100 Subject: [PATCH] Clean up stellarCoreRunnerFactory --- ingest/ledgerbackend/captive_core_backend.go | 28 ++++++--------- .../captive_core_backend_test.go | 34 +++++++++---------- 2 files changed, 27 insertions(+), 35 deletions(-) diff --git a/ingest/ledgerbackend/captive_core_backend.go b/ingest/ledgerbackend/captive_core_backend.go index cf19c4f9d4..f51fd9fdee 100644 --- a/ingest/ledgerbackend/captive_core_backend.go +++ b/ingest/ledgerbackend/captive_core_backend.go @@ -76,7 +76,7 @@ type CaptiveStellarCore struct { stellarCoreRunner stellarCoreRunnerInterface // For testing - stellarCoreRunnerFactory func(mode stellarCoreRunnerMode, captiveCoreConfigAppendPath string) (stellarCoreRunnerInterface, error) + stellarCoreRunnerFactory func(mode stellarCoreRunnerMode) (stellarCoreRunnerInterface, error) // Defines if the blocking mode (off by default) is on or off. In blocking mode, // calling GetLedger blocks until the requested ledger is available. This is useful @@ -137,12 +137,8 @@ func NewCaptive(config CaptiveCoreConfig) (*CaptiveStellarCore, error) { waitIntervalPrepareRange: time.Second, ledgerHashStore: config.LedgerHashStore, } - c.stellarCoreRunnerFactory = func(mode stellarCoreRunnerMode, appendConfigPath string) (stellarCoreRunnerInterface, error) { - runner, innerErr := newStellarCoreRunner(config, mode) - if innerErr != nil { - return runner, innerErr - } - return runner, nil + c.stellarCoreRunnerFactory = func(mode stellarCoreRunnerMode) (stellarCoreRunnerInterface, error) { + return newStellarCoreRunner(config, mode) } return c, nil } @@ -177,13 +173,11 @@ func (c *CaptiveStellarCore) openOfflineReplaySubprocess(from, to uint32) error to = latestCheckpointSequence } - if c.stellarCoreRunner == nil { - // configAppendPath is empty in an offline mode because it's generated - c.stellarCoreRunner, err = c.stellarCoreRunnerFactory(stellarCoreRunnerModeOffline, "") - if err != nil { - return errors.Wrap(err, "error creating stellar-core runner") - } + c.stellarCoreRunner, err = c.stellarCoreRunnerFactory(stellarCoreRunnerModeOffline) + if err != nil { + return errors.Wrap(err, "error creating stellar-core runner") } + err = c.stellarCoreRunner.catchup(from, to) if err != nil { return errors.Wrap(err, "error running stellar-core") @@ -230,11 +224,9 @@ func (c *CaptiveStellarCore) openOnlineReplaySubprocess(from uint32) error { ) } - if c.stellarCoreRunner == nil { - c.stellarCoreRunner, err = c.stellarCoreRunnerFactory(stellarCoreRunnerModeOnline, c.configAppendPath) - if err != nil { - return errors.Wrap(err, "error creating stellar-core runner") - } + c.stellarCoreRunner, err = c.stellarCoreRunnerFactory(stellarCoreRunnerModeOnline) + if err != nil { + return errors.Wrap(err, "error creating stellar-core runner") } runFrom, ledgerHash, nextLedger, err := c.runFromParams(from) diff --git a/ingest/ledgerbackend/captive_core_backend_test.go b/ingest/ledgerbackend/captive_core_backend_test.go index e0e270c9df..2e2316db80 100644 --- a/ingest/ledgerbackend/captive_core_backend_test.go +++ b/ingest/ledgerbackend/captive_core_backend_test.go @@ -184,7 +184,7 @@ func TestCaptivePrepareRange(t *testing.T) { captiveBackend := CaptiveStellarCore{ archive: mockArchive, - stellarCoreRunnerFactory: func(_ stellarCoreRunnerMode, _ string) (stellarCoreRunnerInterface, error) { + stellarCoreRunnerFactory: func(_ stellarCoreRunnerMode) (stellarCoreRunnerInterface, error) { return mockRunner, nil }, } @@ -218,7 +218,7 @@ func TestCaptivePrepareRangeCrash(t *testing.T) { captiveBackend := CaptiveStellarCore{ archive: mockArchive, - stellarCoreRunnerFactory: func(_ stellarCoreRunnerMode, _ string) (stellarCoreRunnerInterface, error) { + stellarCoreRunnerFactory: func(_ stellarCoreRunnerMode) (stellarCoreRunnerInterface, error) { return mockRunner, nil }, } @@ -249,7 +249,7 @@ func TestCaptivePrepareRangeTerminated(t *testing.T) { captiveBackend := CaptiveStellarCore{ archive: mockArchive, - stellarCoreRunnerFactory: func(_ stellarCoreRunnerMode, _ string) (stellarCoreRunnerInterface, error) { + stellarCoreRunnerFactory: func(_ stellarCoreRunnerMode) (stellarCoreRunnerInterface, error) { return mockRunner, nil }, } @@ -330,7 +330,7 @@ func TestCaptivePrepareRange_ToIsAheadOfRootHAS(t *testing.T) { captiveBackend := CaptiveStellarCore{ archive: mockArchive, - stellarCoreRunnerFactory: func(_ stellarCoreRunnerMode, _ string) (stellarCoreRunnerInterface, error) { + stellarCoreRunnerFactory: func(_ stellarCoreRunnerMode) (stellarCoreRunnerInterface, error) { return mockRunner, nil }, } @@ -353,7 +353,7 @@ func TestCaptivePrepareRange_ErrCatchup(t *testing.T) { captiveBackend := CaptiveStellarCore{ archive: mockArchive, - stellarCoreRunnerFactory: func(_ stellarCoreRunnerMode, _ string) (stellarCoreRunnerInterface, error) { + stellarCoreRunnerFactory: func(_ stellarCoreRunnerMode) (stellarCoreRunnerInterface, error) { return mockRunner, nil }, } @@ -425,7 +425,7 @@ func TestCaptivePrepareRangeUnboundedRange_ErrRunFrom(t *testing.T) { captiveBackend := CaptiveStellarCore{ archive: mockArchive, configAppendPath: "foo", - stellarCoreRunnerFactory: func(_ stellarCoreRunnerMode, _ string) (stellarCoreRunnerInterface, error) { + stellarCoreRunnerFactory: func(_ stellarCoreRunnerMode) (stellarCoreRunnerInterface, error) { return mockRunner, nil }, } @@ -486,7 +486,7 @@ func TestCaptivePrepareRangeUnboundedRange_ReuseSession(t *testing.T) { captiveBackend := CaptiveStellarCore{ archive: mockArchive, configAppendPath: "foo", - stellarCoreRunnerFactory: func(_ stellarCoreRunnerMode, _ string) (stellarCoreRunnerInterface, error) { + stellarCoreRunnerFactory: func(_ stellarCoreRunnerMode) (stellarCoreRunnerInterface, error) { return mockRunner, nil }, } @@ -528,7 +528,7 @@ func TestGetLatestLedgerSequence(t *testing.T) { captiveBackend := CaptiveStellarCore{ archive: mockArchive, configAppendPath: "foo", - stellarCoreRunnerFactory: func(_ stellarCoreRunnerMode, _ string) (stellarCoreRunnerInterface, error) { + stellarCoreRunnerFactory: func(_ stellarCoreRunnerMode) (stellarCoreRunnerInterface, error) { return mockRunner, nil }, } @@ -584,7 +584,7 @@ func TestCaptiveGetLedger(t *testing.T) { captiveBackend := CaptiveStellarCore{ archive: mockArchive, - stellarCoreRunnerFactory: func(_ stellarCoreRunnerMode, _ string) (stellarCoreRunnerInterface, error) { + stellarCoreRunnerFactory: func(_ stellarCoreRunnerMode) (stellarCoreRunnerInterface, error) { return mockRunner, nil }, } @@ -648,7 +648,7 @@ func TestCaptiveGetLedger_NextLedgerIsDifferentToLedgerFromBuffer(t *testing.T) captiveBackend := CaptiveStellarCore{ archive: mockArchive, - stellarCoreRunnerFactory: func(_ stellarCoreRunnerMode, _ string) (stellarCoreRunnerInterface, error) { + stellarCoreRunnerFactory: func(_ stellarCoreRunnerMode) (stellarCoreRunnerInterface, error) { return mockRunner, nil }, } @@ -678,7 +678,7 @@ func TestCaptiveGetLedger_ErrReadingMetaResult(t *testing.T) { captiveBackend := CaptiveStellarCore{ archive: mockArchive, - stellarCoreRunnerFactory: func(_ stellarCoreRunnerMode, _ string) (stellarCoreRunnerInterface, error) { + stellarCoreRunnerFactory: func(_ stellarCoreRunnerMode) (stellarCoreRunnerInterface, error) { return mockRunner, nil }, } @@ -715,7 +715,7 @@ func TestCaptiveGetLedger_ErrClosingAfterLastLedger(t *testing.T) { captiveBackend := CaptiveStellarCore{ archive: mockArchive, - stellarCoreRunnerFactory: func(_ stellarCoreRunnerMode, _ string) (stellarCoreRunnerInterface, error) { + stellarCoreRunnerFactory: func(_ stellarCoreRunnerMode) (stellarCoreRunnerInterface, error) { return mockRunner, nil }, } @@ -755,7 +755,7 @@ func TestCaptiveGetLedger_BoundedGetLedgerAfterCoreExit(t *testing.T) { captiveBackend := CaptiveStellarCore{ archive: mockArchive, - stellarCoreRunnerFactory: func(_ stellarCoreRunnerMode, _ string) (stellarCoreRunnerInterface, error) { + stellarCoreRunnerFactory: func(_ stellarCoreRunnerMode) (stellarCoreRunnerInterface, error) { return mockRunner, nil }, } @@ -807,7 +807,7 @@ func TestCaptiveGetLedger_CloseBufferFull(t *testing.T) { captiveBackend := CaptiveStellarCore{ archive: mockArchive, configAppendPath: "foo", - stellarCoreRunnerFactory: func(_ stellarCoreRunnerMode, _ string) (stellarCoreRunnerInterface, error) { + stellarCoreRunnerFactory: func(_ stellarCoreRunnerMode) (stellarCoreRunnerInterface, error) { return mockRunner, nil }, } @@ -863,7 +863,7 @@ func TestGetLedgerBoundsCheck(t *testing.T) { captiveBackend := CaptiveStellarCore{ archive: mockArchive, - stellarCoreRunnerFactory: func(_ stellarCoreRunnerMode, _ string) (stellarCoreRunnerInterface, error) { + stellarCoreRunnerFactory: func(_ stellarCoreRunnerMode) (stellarCoreRunnerInterface, error) { return mockRunner, nil }, } @@ -933,7 +933,7 @@ func TestCaptiveGetLedgerTerminated(t *testing.T) { captiveBackend := CaptiveStellarCore{ archive: mockArchive, - stellarCoreRunnerFactory: func(_ stellarCoreRunnerMode, _ string) (stellarCoreRunnerInterface, error) { + stellarCoreRunnerFactory: func(_ stellarCoreRunnerMode) (stellarCoreRunnerInterface, error) { return mockRunner, nil }, } @@ -1161,7 +1161,7 @@ func TestCaptivePreviousLedgerCheck(t *testing.T) { captiveBackend := CaptiveStellarCore{ configAppendPath: "stellar-core.cfg", archive: mockArchive, - stellarCoreRunnerFactory: func(_ stellarCoreRunnerMode, _ string) (stellarCoreRunnerInterface, error) { + stellarCoreRunnerFactory: func(_ stellarCoreRunnerMode) (stellarCoreRunnerInterface, error) { return mockRunner, nil }, ledgerHashStore: mockLedgerHashStore,