Skip to content

Commit

Permalink
Use a default checkpoint frequency when not set explicitly
Browse files Browse the repository at this point in the history
  • Loading branch information
2opremio committed Dec 12, 2020
1 parent c6689f1 commit ded7e42
Show file tree
Hide file tree
Showing 5 changed files with 12 additions and 8 deletions.
6 changes: 2 additions & 4 deletions historyarchive/archive.go
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,8 @@ type ConnectOptions struct {
S3Region string
S3Endpoint string
UnsignedRequests bool
// The checkpoint frequency will be 64 unless you are using an exotic test setup.
// CheckpointFrequency is the number of ledgers between checkpoints
// if unset, DefaultCheckpointFrequency will be used
CheckpointFrequency uint32
}

Expand Down Expand Up @@ -284,9 +285,6 @@ func (a *Archive) GetXdrStream(pth string) (*XdrStream, error) {
}

func Connect(u string, opts ConnectOptions) (*Archive, error) {
if opts.CheckpointFrequency == 0 {
return nil, errors.New("uninitialized checkpoint frequency")
}
arch := Archive{
networkPassphrase: opts.NetworkPassphrase,
checkpointFiles: make(map[string](map[uint32]bool)),
Expand Down
8 changes: 8 additions & 0 deletions historyarchive/range.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@ import (
"strings"
)

const DefaultCheckpointFrequency = uint32(64)

type Range struct {
Low uint32
High uint32
Expand All @@ -19,7 +21,13 @@ type CheckpointManager struct {
checkpointFreq uint32
}

// NewCheckpointManager creates a CheckpointManager based on a checkpoint frequency
// (the number of ledgers between ledger checkpoints). If checkpointFrequency is
// 0 DefaultCheckpointFrequency will be used.
func NewCheckpointManager(checkpointFrequency uint32) CheckpointManager {
if checkpointFrequency == 0 {
checkpointFrequency = DefaultCheckpointFrequency
}
return CheckpointManager{checkpointFrequency}
}

Expand Down
1 change: 1 addition & 0 deletions ingest/ledgerbackend/captive_core_backend.go
Original file line number Diff line number Diff line change
Expand Up @@ -109,6 +109,7 @@ type CaptiveCoreConfig struct {
// HistoryArchiveURLs are a list of history archive urls
HistoryArchiveURLs []string
// 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
Expand Down
2 changes: 1 addition & 1 deletion ingest/ledgerbackend/history_archive_backend.go
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ const (

// NewHistoryArchiveBackendFromURL builds a new HistoryArchiveBackend using
// history archive URL.
// The checkpoint frequency will be 64 unless you are using an exotic test setup.
// If unsure, leave checkpointFrequency at 0, the DefaultCheckpointFrequency will be used
func NewHistoryArchiveBackendFromURL(archiveURL string, checkpointFrequency uint32) (*HistoryArchiveBackend, error) {
archive, err := historyarchive.Connect(
archiveURL,
Expand Down
3 changes: 0 additions & 3 deletions services/horizon/internal/ingest/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -157,9 +157,6 @@ type system struct {
}

func NewSystem(config Config) (System, error) {
if config.CheckpointFrequency == 0 {
return nil, errors.New("uninitialized checkpoint frequency")
}
ctx, cancel := context.WithCancel(context.Background())

archive, err := historyarchive.Connect(
Expand Down

0 comments on commit ded7e42

Please sign in to comment.