Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ingest/ledgerbackend: Clean up stellarCoreRunnerFactory #3272

Merged
merged 2 commits into from
Dec 8, 2020
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
28 changes: 10 additions & 18 deletions ingest/ledgerbackend/captive_core_backend.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
}
Expand Down Expand Up @@ -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")
}
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

it's not necessary to check c.stellarCoreRunner == nil because when c.Close() is called a few lines above it sets c.stellarCoreRunner to nil

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")
Expand Down Expand Up @@ -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)
Expand Down
34 changes: 17 additions & 17 deletions ingest/ledgerbackend/captive_core_backend_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
},
}
Expand Down Expand Up @@ -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
},
}
Expand Down Expand Up @@ -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
},
}
Expand Down Expand Up @@ -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
},
}
Expand All @@ -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
},
}
Expand Down Expand Up @@ -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
},
}
Expand Down Expand Up @@ -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
},
}
Expand Down Expand Up @@ -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
},
}
Expand Down Expand Up @@ -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
},
}
Expand Down Expand Up @@ -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
},
}
Expand Down Expand Up @@ -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
},
}
Expand Down Expand Up @@ -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
},
}
Expand Down Expand Up @@ -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
},
}
Expand Down Expand Up @@ -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
},
}
Expand Down Expand Up @@ -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
},
}
Expand Down Expand Up @@ -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
},
}
Expand Down Expand Up @@ -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,
Expand Down