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/internal/ingest: Add missing tables to TruncateIngestStateTables() #5253

Merged
merged 3 commits into from
Mar 22, 2024
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
2 changes: 2 additions & 0 deletions services/horizon/internal/db2/history/ingestion.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,8 @@ func (q *Q) TruncateIngestStateTables(ctx context.Context) error {
"claimable_balances",
"claimable_balance_claimants",
"exp_asset_stats",
"contract_asset_balances",
"contract_asset_stats",
tamirms marked this conversation as resolved.
Show resolved Hide resolved
"liquidity_pools",
"offers",
"trust_lines",
Expand Down
79 changes: 48 additions & 31 deletions services/horizon/internal/ingest/verify_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -283,6 +283,32 @@ func ttlForContractData(tt *test.T, gen randxdr.Generator, contractData xdr.Ledg
return ttl
}

func TestTruncateIngestStateTables(t *testing.T) {
tt := test.Start(t)
defer tt.Finish()
test.ResetHorizonDB(t, tt.HorizonDB)
q := &history.Q{&db.Session{DB: tt.HorizonDB}}

tt.Assert.NoError(q.BeginTx(tt.Ctx, &sql.TxOptions{}))
checkpointLedger := uint32(63)
changeProcessor := buildChangeProcessor(q, &ingest.StatsChangeProcessor{}, ledgerSource, checkpointLedger, "")
for _, change := range ingest.GetChangesFromLedgerEntryChanges(generateRandomLedgerEntries(tt)) {
tt.Assert.NoError(changeProcessor.ProcessChange(tt.Ctx, change))
}
tt.Assert.NoError(changeProcessor.Commit(tt.Ctx))
tt.Assert.NoError(q.Commit())

q.TruncateIngestStateTables(tt.Ctx)

tt.Assert.NoError(q.BeginTx(tt.Ctx, &sql.TxOptions{}))
changeProcessor = buildChangeProcessor(q, &ingest.StatsChangeProcessor{}, ledgerSource, checkpointLedger, "")
for _, change := range ingest.GetChangesFromLedgerEntryChanges(generateRandomLedgerEntries(tt)) {
tt.Assert.NoError(changeProcessor.ProcessChange(tt.Ctx, change))
}
tt.Assert.NoError(changeProcessor.Commit(tt.Ctx))
tt.Assert.NoError(q.Commit())
}

func TestStateVerifierLockBusy(t *testing.T) {
tt := test.Start(t)
defer tt.Finish()
Expand All @@ -294,19 +320,7 @@ func TestStateVerifierLockBusy(t *testing.T) {
checkpointLedger := uint32(63)
changeProcessor := buildChangeProcessor(q, &ingest.StatsChangeProcessor{}, ledgerSource, checkpointLedger, "")

gen := randxdr.NewGenerator()
var changes []xdr.LedgerEntryChange
for i := 0; i < 10; i++ {
changes = append(changes,
genLiquidityPool(tt, gen),
genClaimableBalance(tt, gen),
genOffer(tt, gen),
genTrustLine(tt, gen),
genAccount(tt, gen),
genAccountData(tt, gen),
)
}
for _, change := range ingest.GetChangesFromLedgerEntryChanges(changes) {
for _, change := range ingest.GetChangesFromLedgerEntryChanges(generateRandomLedgerEntries(tt)) {
tt.Assert.NoError(changeProcessor.ProcessChange(tt.Ctx, change))
}
tt.Assert.NoError(changeProcessor.Commit(tt.Ctx))
Expand Down Expand Up @@ -353,25 +367,8 @@ func TestStateVerifier(t *testing.T) {
changeProcessor := buildChangeProcessor(q, &ingest.StatsChangeProcessor{}, ledgerSource, checkpointLedger, "")
mockChangeReader := &ingest.MockChangeReader{}

gen := randxdr.NewGenerator()
var changes []xdr.LedgerEntryChange
for i := 0; i < 100; i++ {
changes = append(changes,
genLiquidityPool(tt, gen),
genClaimableBalance(tt, gen),
genOffer(tt, gen),
genTrustLine(tt, gen),
genAccount(tt, gen),
genAccountData(tt, gen),
genContractCode(tt, gen),
genConfigSetting(tt, gen),
genTTL(tt, gen),
)
changes = append(changes, genAssetContractMetadata(tt, gen)...)
}

coverage := map[xdr.LedgerEntryType]int{}
for _, change := range ingest.GetChangesFromLedgerEntryChanges(changes) {
for _, change := range ingest.GetChangesFromLedgerEntryChanges(generateRandomLedgerEntries(tt)) {
mockChangeReader.On("Read").Return(change, nil).Once()
tt.Assert.NoError(changeProcessor.ProcessChange(tt.Ctx, change))
coverage[change.Type]++
Expand Down Expand Up @@ -402,3 +399,23 @@ func TestStateVerifier(t *testing.T) {
mockChangeReader.AssertExpectations(t)
mockHistoryAdapter.AssertExpectations(t)
}

func generateRandomLedgerEntries(tt *test.T) []xdr.LedgerEntryChange {
gen := randxdr.NewGenerator()
var changes []xdr.LedgerEntryChange
for i := 0; i < 100; i++ {
changes = append(changes,
genLiquidityPool(tt, gen),
genClaimableBalance(tt, gen),
genOffer(tt, gen),
genTrustLine(tt, gen),
genAccount(tt, gen),
genAccountData(tt, gen),
genContractCode(tt, gen),
genConfigSetting(tt, gen),
genTTL(tt, gen),
)
changes = append(changes, genAssetContractMetadata(tt, gen)...)
tamirms marked this conversation as resolved.
Show resolved Hide resolved
}
return changes
}
Loading