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

services/horizon: Allow captive core to run with sqlite database #4092

Merged
merged 31 commits into from
Feb 17, 2022
Merged
Show file tree
Hide file tree
Changes from 10 commits
Commits
Show all changes
31 commits
Select commit Hold shift + click to select a range
03dce0f
Skip in-memory flag for catchup with captive core
Nov 29, 2021
0426a49
run a catchup before run, intead of runFrom
Jan 18, 2022
baa254b
remove in-memory from core run
Jan 18, 2022
0f274b0
Remove now-unused ledger hash store
Jan 18, 2022
031cda3
fix govet
Jan 18, 2022
a3496b5
Can't catchup to ledger 1
Jan 19, 2022
f468799
catchup from x-1, not from x
Jan 25, 2022
f1789e8
Add database= flag to the captive core config file
Jan 26, 2022
760ba2f
Have to run stellar-core new-db to initialize the new db
Jan 26, 2022
2053b97
Experiment with pushing the catchup into stellar_core_runner to use t…
Jan 28, 2022
094468a
#4038: fixed unit test in ingest/ledgerbackend to mock for new captiv…
sreuland Jan 31, 2022
e30afe8
Merge remote-tracking branch 'origin/master' into 4038/captive-core-s…
sreuland Jan 31, 2022
ac70788
#4038: fixed unit test after merge conflict
sreuland Jan 31, 2022
2a9f950
Merge pull request #4207 from sreuland/4038/captive-core-sqlite
sreuland Feb 1, 2022
f16f43c
#4038: fixed integration test to not use GenesisState
sreuland Feb 1, 2022
21224eb
Merge pull request #4209 from sreuland/4038/captive-core-sqlite
sreuland Feb 2, 2022
c0968b3
Merge remote-tracking branch 'origin/master' into 4038/captive-core-s…
sreuland Feb 2, 2022
ff41661
Merge pull request #4214 from sreuland/4038/captive-core-sqlite
sreuland Feb 2, 2022
49040a2
Merge remote-tracking branch 'upstream/master' into 4038/captive-core…
sreuland Feb 7, 2022
805ba5f
Merge pull request, merge from master
sreuland Feb 7, 2022
b75964d
Merge remote-tracking branch 'origin/master' into 4038/captive-core-s…
sreuland Feb 8, 2022
31f8e3a
Merge remote-tracking branch 'upstream/4038/captive-core-sqlite' into…
sreuland Feb 8, 2022
c797d23
Merge pull request #4219, updated latest from master
sreuland Feb 8, 2022
a98d1ab
Merge remote-tracking branch 'upstream/master' into 4038/captive-core…
sreuland Feb 10, 2022
c1f4692
Merge pull request #4225 from sreuland/4038/captive-core-sqlite, port…
sreuland Feb 10, 2022
a0ce745
#4038: use --in-memory for cc ingest by default
sreuland Feb 16, 2022
21ca9cf
4038: incorporate PR feedback updates
sreuland Feb 16, 2022
5185fff
#4038: incorporate PR feedback, rename the sqlite db parameter to UseDB
sreuland Feb 17, 2022
f686301
#4038: incorporated UseDB in CaptiveCoreTomlParams and other PR feedback
sreuland Feb 17, 2022
df69623
Merge remote-tracking branch 'upstream/master' into 4038/captive-core…
sreuland Feb 17, 2022
4f825ff
Merge pull request #4235, port latest from master
sreuland Feb 17, 2022
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
23 changes: 1 addition & 22 deletions exp/services/captivecore/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,14 +13,13 @@ import (
"github.com/stellar/go/ingest/ledgerbackend"
"github.com/stellar/go/network"
"github.com/stellar/go/support/config"
"github.com/stellar/go/support/db"
supporthttp "github.com/stellar/go/support/http"
supportlog "github.com/stellar/go/support/log"
)

func main() {
var port int
var networkPassphrase, binaryPath, configPath, dbURL string
var networkPassphrase, binaryPath, configPath string
var captiveCoreTomlParams ledgerbackend.CaptiveCoreTomlParams
var historyArchiveURLs []string
var checkpointFrequency uint32
Expand Down Expand Up @@ -90,14 +89,6 @@ func main() {
},
Usage: "minimum log severity (debug, info, warn, error) to log",
},
&config.ConfigOption{
Name: "db-url",
EnvVar: "DATABASE_URL",
ConfigKey: &dbURL,
OptType: types.String,
Required: false,
Usage: "horizon postgres database to connect with",
},
&config.ConfigOption{
Name: "stellar-captive-core-http-port",
ConfigKey: &captiveCoreTomlParams.HTTPPort,
Expand Down Expand Up @@ -141,15 +132,6 @@ func main() {
Toml: captiveCoreToml,
}

var dbConn *db.Session
if len(dbURL) > 0 {
dbConn, err = db.Open("postgres", dbURL)
if err != nil {
logger.WithError(err).Fatal("Could not create db connection instance")
}
captiveConfig.LedgerHashStore = ledgerbackend.NewHorizonDBLedgerHashStore(dbConn)
}

core, err := ledgerbackend.NewCaptive(captiveConfig)
if err != nil {
logger.WithError(err).Fatal("Could not create captive core instance")
Expand All @@ -166,9 +148,6 @@ func main() {
// TODO: Check this aborts in-progress requests instead of letting
// them finish, to preserve existing behaviour.
api.Shutdown()
if dbConn != nil {
dbConn.Close()
}
},
})
},
Expand Down
40 changes: 5 additions & 35 deletions ingest/ledgerbackend/captive_core_backend.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ package ledgerbackend

import (
"context"
"encoding/hex"
"os"
"sync"

Expand Down Expand Up @@ -69,7 +68,6 @@ func (c *CaptiveStellarCore) roundDownToFirstReplayAfterCheckpointStart(ledger u
type CaptiveStellarCore struct {
archive historyarchive.ArchiveInterface
checkpointManager historyarchive.CheckpointManager
ledgerHashStore TrustedLedgerHashStore

// cancel is the CancelFunc for context which controls the lifetime of a CaptiveStellarCore instance.
// Once it is invoked CaptiveStellarCore will not be able to stream ledgers from Stellar Core or
Expand Down Expand Up @@ -110,8 +108,6 @@ type CaptiveCoreConfig struct {
// CheckpointFrequency is the number of ledgers between checkpoints
// if unset, DefaultCheckpointFrequency will be used
CheckpointFrequency uint32
// LedgerHashStore is an optional store used to obtain hashes for ledger sequences from a trusted source
LedgerHashStore TrustedLedgerHashStore
// Log is an (optional) custom logger which will capture any output from the Stellar Core process.
// If Log is omitted then all output will be printed to stdout.
Log *log.Entry
Expand Down Expand Up @@ -161,7 +157,6 @@ func NewCaptive(config CaptiveCoreConfig) (*CaptiveStellarCore, error) {

c := &CaptiveStellarCore{
archive: &archivePool,
ledgerHashStore: config.LedgerHashStore,
cancel: cancel,
checkpointManager: historyarchive.NewCheckpointManager(config.CheckpointFrequency),
}
Expand Down Expand Up @@ -256,12 +251,12 @@ func (c *CaptiveStellarCore) openOnlineReplaySubprocess(ctx context.Context, fro
c.stellarCoreRunner = runner
}

runFrom, ledgerHash, err := c.runFromParams(ctx, from)
runFrom, err := c.runFromParams(ctx, from)
if err != nil {
return errors.Wrap(err, "error calculating ledger and hash for stellar-core run")
}

err = c.stellarCoreRunner.runFrom(runFrom, ledgerHash)
err = c.stellarCoreRunner.runFrom(runFrom)
if err != nil {
return errors.Wrap(err, "error running stellar-core")
}
Expand All @@ -278,15 +273,14 @@ func (c *CaptiveStellarCore) openOnlineReplaySubprocess(ctx context.Context, fro
return nil
}

// runFromParams receives a ledger sequence and calculates the required values to call stellar-core run with --start-ledger and --start-hash
func (c *CaptiveStellarCore) runFromParams(ctx context.Context, from uint32) (runFrom uint32, ledgerHash string, err error) {
// runFromParams receives a ledger sequence and calculates the required values to start stellar-core catchup from
func (c *CaptiveStellarCore) runFromParams(ctx context.Context, from uint32) (runFrom uint32, err error) {
Copy link
Contributor

Choose a reason for hiding this comment

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

nit: I think it would be better to remove the named return parameters and explicitly return the values for all return paths

if from == 1 {
// Trying to start-from 1 results in an error from Stellar-Core:
// Target ledger 1 is not newer than last closed ledger 1 - nothing to do
// TODO maybe we can fix it by generating 1st ledger meta
// like GenesisLedgerStateReader?
err = errors.New("CaptiveCore is unable to start from ledger 1, start from ledger 2")
return
return 0, errors.New("CaptiveCore is unable to start from ledger 1, start from ledger 2")
}

if from <= 63 {
Expand All @@ -299,24 +293,6 @@ func (c *CaptiveStellarCore) runFromParams(ctx context.Context, from uint32) (ru
}

runFrom = from - 1
if c.ledgerHashStore != nil {
var exists bool
ledgerHash, exists, err = c.ledgerHashStore.GetLedgerHash(ctx, runFrom)
if err != nil {
err = errors.Wrapf(err, "error trying to read ledger hash %d", runFrom)
return
}
if exists {
return
}
}

ledgerHeader, err2 := c.archive.GetLedgerHeader(from)
if err2 != nil {
err = errors.Wrapf(err2, "error trying to read ledger header %d from HAS", from)
return
}
ledgerHash = hex.EncodeToString(ledgerHeader.Header.PreviousLedgerHash[:])
return
}

Expand Down Expand Up @@ -643,12 +619,6 @@ func (c *CaptiveStellarCore) Close() error {
// after the CaptiveStellarCore context is canceled all subsequent calls to PrepareRange() will fail
c.cancel()

// TODO: Sucks to ignore the error here, but no worse than it was before,
// so...
if c.ledgerHashStore != nil {
c.ledgerHashStore.Close()
}

if c.stellarCoreRunner != nil {
return c.stellarCoreRunner.close()
}
Expand Down
Loading