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: Update ingestion library and horizon to adapt to protocol 23 representation of evictions #5619

Merged
merged 8 commits into from
Mar 17, 2025

Conversation

tamirms
Copy link
Contributor

@tamirms tamirms commented Mar 4, 2025

PR Checklist

PR Structure

  • This PR has reasonably narrow scope (if not, break it down into smaller PRs).
  • This PR avoids mixing refactoring changes with feature changes (split into two PRs
    otherwise).
  • This PR's title starts with name of package that is most changed in the PR, ex.
    services/friendbot, or all or doc if the changes are broad or impact many
    packages.

Thoroughness

  • This PR adds tests for the most critical parts of the new functionality or fixes.
  • I've updated any docs (developer docs, .md
    files, etc... affected by this change). Take a look in the docs folder for a given service,
    like this one.

Release planning

  • I've reviewed the changes in this PR and if I consider them worthwhile for being mentioned on release notes then I have updated the relevant CHANGELOG.md within the component folder structure. For example, if I changed horizon, then I updated (services/horizon/CHANGELOG.md. I add a new line item describing the change and reference to this PR. If I don't update a CHANGELOG, I acknowledge this PR's change may not be mentioned in future release notes.
  • I've decided if this PR requires a new major/minor version according to
    semver, or if it's mainly a patch change. The PR is targeted at the next
    release branch if it's not a patch change.

What

CAP-62 and CAP-66 updates the LedgerCloseMeta xdr to no longer populate the evictedPersistentLedgerEntries field. Instead, both persistent and temporary ledger keys will be included in the evictedTemporaryLedgerKeys field which will be renamed to evictedKeys in protocol 23.

The ingestion library previously presented evictions of persistent ledger entries as a Change instance with the Reason set to LedgerEntryChangeReasonEviction. This allowed downstream consumers of a Change stream to handle evictions as if they were equivalent to ledger entry deletions. However, in protocol 23 we can no longer maintain this strategy because the full contents of the evicted ledger entry will not be present in the LedgerCloseMeta xdr. We will only have the ledger key for the evicted ledger entry.

This means that ledger entry evictions will need to be handled outside of Change stream processing by downstream services. The second commit of this PR fixes the asset stats processor in Horizon to adapt to this new reality where evictions no longer appear in the Change stream.

The asset stats processor can ignore evicted contract balance ledger entries because contract balance ledger entries are deleted from the horizon db immediately upon expiration. However, the asset stats processor still needs to ingest the stellar asset contract instance storage so that we can link stellar classic assets with their corresponding contract id. So when the stellar asset contract instance storage is evicted we also need to handle that event so we can remove the link between stellar classic asset and the stellar asset contract id.

Also fixes #5578

Known limitations

[N/A]

@tamirms tamirms requested a review from a team March 4, 2025 22:32
Copy link
Contributor

@Shaptic Shaptic left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This looks good from a change perspective if I understand it correctly, but I don't feel great about reviewing the asset changes since I'm relatively unfamiliar with them.

Either way, though, integration tests will reveal issues once RPC gets tagged off, assuming we have some for SAC+eviction+asset stats?

@tamirms
Copy link
Contributor Author

tamirms commented Mar 5, 2025

Either way, though, integration tests will reveal issues once RPC gets tagged off, assuming we have some for SAC+eviction+asset stats?

@Shaptic yeah, we have a issue to capture writing the protocol 23 eviction / restoration integration tests: #5613

} else if err != nil {
return errors.Wrap(err, "error querying asset by asset code and issuer")
} else if dbContractID, ok := stat.GetContractID(); ok {
// the asset stat already has a column_id set which is unexpected (the column should be NULL)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

is this condition likely to ever happen?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

no, it should never happen which is why this code path returns an error

var rowsAffected int64
stat, err := p.assetStatsQ.GetAssetStatByContract(ctx, contractID)
if pkgerrors.Is(err, sql.ErrNoRows) {
// we cannot know for sure if the contract id belongs to a legitimate SAC
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

if the contractId is even passed to this removeContractId, then it must be a SAC contract, right?
Meaning, this condition if pkgErrors.Is(err, sqlErrNoRows shud never be triggered, right?
So, doesnt it make sense to return a meaningful error instead of nil?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

unfortunately we cannot know if the contract id is a SAC unless we have the full ledger entry containing the asset metadata which is stored in persistent contract data. But, in protocol 23 we will not have the full ledger entry for evictions. We will only have the ledger keys which were evicted

Copy link
Contributor

@urvisavla urvisavla left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Overall, the changes look good to me conceptually. This PR does a great job of refactoring/simplifying some of the existing logic around error handling. I spent a couple of days reviewing it but there are still many nuances to the AssetStatsProcessor that are difficult to fully grasp.

@tamirms tamirms merged commit 413fe10 into stellar:protocol-23 Mar 17, 2025
21 checks passed
@tamirms tamirms deleted the evictions branch March 17, 2025 22:43
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants