Skip to content

Commit

Permalink
Fix adjustLedgerRange()
Browse files Browse the repository at this point in the history
  • Loading branch information
tamirms committed May 29, 2024
1 parent afd526d commit 61e6608
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 9 deletions.
5 changes: 1 addition & 4 deletions exp/services/ledgerexporter/internal/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -182,10 +182,7 @@ func (config *Config) adjustLedgerRange() {

// Align the end ledger (for bounded cases) to the nearest "LedgersPerFile" boundary.
if config.EndLedger != 0 {
// Add an extra batch only if "LedgersPerFile" is greater than 1 and the end ledger doesn't fall on the boundary.
if config.LedgerBatchConfig.LedgersPerFile > 1 && config.EndLedger%config.LedgerBatchConfig.LedgersPerFile != 0 {
config.EndLedger = (config.EndLedger/config.LedgerBatchConfig.LedgersPerFile + 1) * config.LedgerBatchConfig.LedgersPerFile
}
config.EndLedger = config.LedgerBatchConfig.GetSequenceNumberEndBoundary(config.EndLedger)
}

logger.Infof("Computed effective export boundary ledger range: start=%d, end=%d", config.StartLedger, config.EndLedger)
Expand Down
11 changes: 6 additions & 5 deletions exp/services/ledgerexporter/internal/config_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,9 @@ import (
"fmt"
"testing"

"github.com/stellar/go/historyarchive"
"github.com/stretchr/testify/require"

"github.com/stellar/go/historyarchive"
)

func TestNewConfigResumeEnabled(t *testing.T) {
Expand Down Expand Up @@ -154,31 +155,31 @@ func TestAdjustedLedgerRangeBoundedMode(t *testing.T) {
start: 0,
end: 1,
expectedStart: 2,
expectedEnd: 10,
expectedEnd: 9,
},
{
name: "Round down start ledger and round up end ledger, 15 ledgers per file ",
configFile: "test/15perfile.toml",
start: 4,
end: 10,
expectedStart: 2,
expectedEnd: 15,
expectedEnd: 14,
},
{
name: "Round down start ledger and round up end ledger, 64 ledgers per file ",
configFile: "test/64perfile.toml",
start: 400,
end: 500,
expectedStart: 384,
expectedEnd: 512,
expectedEnd: 511,
},
{
name: "No change, 64 ledger per file",
configFile: "test/64perfile.toml",
start: 64,
end: 128,
expectedStart: 64,
expectedEnd: 128,
expectedEnd: 191,
},
}

Expand Down

0 comments on commit 61e6608

Please sign in to comment.