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: Reject bounded ledger ranges that have ledgers after latest checkpoint #3738

Merged
merged 3 commits into from
Jul 1, 2021
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
8 changes: 6 additions & 2 deletions ingest/ledgerbackend/captive_core_backend.go
Original file line number Diff line number Diff line change
Expand Up @@ -192,14 +192,18 @@ func (c *CaptiveStellarCore) openOfflineReplaySubprocess(from, to uint32) error

if from > latestCheckpointSequence {
return errors.Errorf(
"sequence: %d is greater than max available in history archives: %d",
"from sequence: %d is greater than max available in history archives: %d",
from,
latestCheckpointSequence,
)
}

if to > latestCheckpointSequence {
to = latestCheckpointSequence
return errors.Errorf(
"to sequence: %d is greater than max available in history archives: %d",
to,
latestCheckpointSequence,
)
}

var runner stellarCoreRunnerInterface
Expand Down
24 changes: 4 additions & 20 deletions ingest/ledgerbackend/captive_core_backend_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -319,7 +319,7 @@ func TestCaptivePrepareRange_FromIsAheadOfRootHAS(t *testing.T) {
}

err := captiveBackend.PrepareRange(ctx, BoundedRange(100, 200))
assert.EqualError(t, err, "error starting prepare range: opening subprocess: sequence: 100 is greater than max available in history archives: 64")
assert.EqualError(t, err, "error starting prepare range: opening subprocess: from sequence: 100 is greater than max available in history archives: 64")

err = captiveBackend.PrepareRange(ctx, UnboundedRange(100))
assert.EqualError(t, err, "error starting prepare range: opening subprocess: trying to start online mode too far (latest checkpoint=64), only two checkpoints in the future allowed")
Expand All @@ -328,23 +328,7 @@ func TestCaptivePrepareRange_FromIsAheadOfRootHAS(t *testing.T) {
}

func TestCaptivePrepareRange_ToIsAheadOfRootHAS(t *testing.T) {
metaChan := make(chan metaResult, 100)

// Core will actually start with the last checkpoint before the from ledger
// and then rewind to the `from` ledger.
for i := 64; i <= 100; i++ {
meta := buildLedgerCloseMeta(testLedgerHeader{sequence: uint32(i)})
metaChan <- metaResult{
LedgerCloseMeta: &meta,
}
}

ctx := context.Background()
mockRunner := &stellarCoreRunnerMock{}
mockRunner.On("catchup", uint32(100), uint32(192)).Return(nil).Once()
mockRunner.On("getMetaPipe").Return((<-chan metaResult)(metaChan))
mockRunner.On("context").Return(ctx)

mockArchive := &historyarchive.MockArchive{}
mockArchive.
On("GetRootHAS").
Expand All @@ -360,8 +344,8 @@ func TestCaptivePrepareRange_ToIsAheadOfRootHAS(t *testing.T) {
checkpointManager: historyarchive.NewCheckpointManager(64),
}

err := captiveBackend.PrepareRange(ctx, BoundedRange(100, 200))
assert.NoError(t, err)
err := captiveBackend.PrepareRange(context.Background(), BoundedRange(100, 200))
assert.EqualError(t, err, "error starting prepare range: opening subprocess: to sequence: 200 is greater than max available in history archives: 192")

mockArchive.AssertExpectations(t)
mockRunner.AssertExpectations(t)
Expand Down Expand Up @@ -391,7 +375,7 @@ func TestCaptivePrepareRange_ErrCatchup(t *testing.T) {
}),
}

err := captiveBackend.PrepareRange(ctx, BoundedRange(100, 200))
err := captiveBackend.PrepareRange(ctx, BoundedRange(100, 192))
assert.EqualError(t, err, "error starting prepare range: opening subprocess: error running stellar-core: transient error")

// make sure we can Close without errors
Expand Down
1 change: 1 addition & 0 deletions services/horizon/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ file. This project adheres to [Semantic Versioning](http://semver.org/).
## Unreleased

* Fix a bug in `fee_account_muxed` and `fee_account_muxed_id` fields (the fields were incorrectly populated with the source account details). ([3735](https://github.com/stellar/go/pull/3735))
* Validate ledger range when calling `horizon db reingest range` so that we respond with an error when attempting to ingest ledgers which are not available in the history archives. ([3738](https://github.com/stellar/go/pull/3738))

## v2.5.2

Expand Down