Skip to content

Commit

Permalink
Allow captive core backend to start at any ledger.
Browse files Browse the repository at this point in the history
  • Loading branch information
abuiles committed Oct 26, 2020
1 parent 8b3a263 commit 560a216
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 9 deletions.
8 changes: 6 additions & 2 deletions ingest/ledgerbackend/captive_core_backend.go
Original file line number Diff line number Diff line change
Expand Up @@ -290,14 +290,18 @@ func (c *CaptiveStellarCore) runFromParams(from uint32) (runFrom uint32, ledgerH
// ledger and then fast-forward to the desire ledger
//
//
runFrom = roundDownToFirstReplayAfterCheckpointStart(from) - 1
runFrom = from - 1
ledgerHeader, err2 := c.archive.GetLedgerHeader(runFrom)
if err2 != nil {
err = errors.Wrapf(err2, "error trying to read ledger header %d from HAS", runFrom)
return
}
ledgerHash = hex.EncodeToString(ledgerHeader.Hash[:])
nextLedger = runFrom + 1
if historyarchive.IsCheckpoint(runFrom) {
nextLedger = runFrom + 1
} else {
nextLedger = roundDownToFirstReplayAfterCheckpointStart(runFrom)
}
}

return
Expand Down
20 changes: 13 additions & 7 deletions ingest/ledgerbackend/captive_core_backend_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -439,7 +439,7 @@ func TestCaptivePrepareRangeUnboundedRange_ReuseSession(t *testing.T) {
}

mockRunner := &stellarCoreRunnerMock{}
mockRunner.On("runFrom", uint32(63), "0000000000000000000000000000000000000000000000000000000000000000").Return(nil).Once()
mockRunner.On("runFrom", uint32(64), "0000000000000000000000000000000000000000000000000000000000000000").Return(nil).Once()
mockRunner.On("getMetaPipe").Return(&buf)
mockRunner.On("close").Return(nil)

Expand All @@ -450,7 +450,7 @@ func TestCaptivePrepareRangeUnboundedRange_ReuseSession(t *testing.T) {
CurrentLedger: uint32(129),
}, nil)
mockArchive.
On("GetLedgerHeader", uint32(63)).
On("GetLedgerHeader", uint32(64)).
Return(xdr.LedgerHeaderHistoryEntry{}, nil)

captiveBackend := CaptiveStellarCore{
Expand Down Expand Up @@ -799,7 +799,7 @@ func TestCaptiveRunFromParams(t *testing.T) {
mockRunner := &stellarCoreRunnerMock{}
mockArchive := &historyarchive.MockArchive{}
mockArchive.
On("GetLedgerHeader", uint32(63)).
On("GetLedgerHeader", uint32(69)).
Return(xdr.LedgerHeaderHistoryEntry{
Hash: xdr.Hash{1, 1, 1, 1},
}, nil)
Expand All @@ -812,14 +812,20 @@ func TestCaptiveRunFromParams(t *testing.T) {

runFrom, ledgerHash, nextLedger, err := captiveBackend.runFromParams(70)
tt.NoError(err)
tt.Equal(uint32(63), runFrom)
tt.Equal(uint32(69), runFrom)
tt.Equal("0101010100000000000000000000000000000000000000000000000000000000", ledgerHash)
tt.Equal(uint32(64), nextLedger)

mockArchive.
On("GetLedgerHeader", uint32(63)).
Return(xdr.LedgerHeaderHistoryEntry{
Hash: xdr.Hash{1, 1, 0, 0},
}, nil)

runFrom, ledgerHash, nextLedger, err = captiveBackend.runFromParams(64)
tt.NoError(err)
tt.Equal(uint32(63), runFrom)
tt.Equal("0101010100000000000000000000000000000000000000000000000000000000", ledgerHash)
tt.Equal("0101000000000000000000000000000000000000000000000000000000000000", ledgerHash)
tt.Equal(uint32(64), nextLedger)

mockArchive.
Expand Down Expand Up @@ -848,13 +854,13 @@ func TestCaptiveRunFromParams(t *testing.T) {
tt.EqualError(err, "error trying to read ledger header 319 from HAS: missing ledger checkpoint")

mockArchive.
On("GetLedgerHeader", uint32(191)).
On("GetLedgerHeader", uint32(194)).
Return(xdr.LedgerHeaderHistoryEntry{
Header: xdr.LedgerHeader{
PreviousLedgerHash: xdr.Hash{1},
},
}, errors.New("missing ledger checkpoint"))

runFrom, ledgerHash, nextLedger, err = captiveBackend.runFromParams(195)
tt.EqualError(err, "error trying to read ledger header 191 from HAS: missing ledger checkpoint")
tt.EqualError(err, "error trying to read ledger header 194 from HAS: missing ledger checkpoint")
}

0 comments on commit 560a216

Please sign in to comment.