-
Notifications
You must be signed in to change notification settings - Fork 513
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: Add support for CAP-63 #5615
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -163,6 +163,14 @@ func (c *ChangeCompactor) getLedgerKey(ledgerEntry *xdr.LedgerEntry) ([]byte, er | |
return ledgerKey, nil | ||
} | ||
|
||
// maxTTL returns the ttl entry with the highest LiveUntilLedgerSeq | ||
func maxTTL(a, b xdr.TtlEntry) xdr.TtlEntry { | ||
if a.LiveUntilLedgerSeq > b.LiveUntilLedgerSeq { | ||
return a | ||
} | ||
return b | ||
} | ||
|
||
// addUpdatedChange adds a change to the cache, but returns an error if update | ||
// change is unexpected. | ||
func (c *ChangeCompactor) addUpdatedChange(change Change) error { | ||
|
@@ -179,22 +187,19 @@ func (c *ChangeCompactor) addUpdatedChange(change Change) error { | |
} | ||
|
||
switch existingChange.ChangeType { | ||
case xdr.LedgerEntryChangeTypeLedgerEntryCreated: | ||
// If existing type is created it means that this entry does not | ||
// exist in a DB so we update entry change. | ||
c.cache[ledgerKeyString] = Change{ | ||
Type: change.Type, | ||
Pre: existingChange.Pre, // = nil | ||
Post: change.Post, | ||
ChangeType: existingChange.ChangeType, | ||
case xdr.LedgerEntryChangeTypeLedgerEntryCreated, | ||
xdr.LedgerEntryChangeTypeLedgerEntryUpdated, | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. LedgerEntryUpdated's are now cached into the compactor all the time, before it was dropped, don't see any changes in existing tests that may have broken related to this, I do see the new coverage on TTL's, is there potential edge case where LedgerEntryUpdated should still be dropped or are TTL's the only source of an LedgerEntryUpdated? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
the behavior is actually the same. The fallthrough keyword means it should match the case below. In other words, case xdr.LedgerEntryChangeTypeLedgerEntryUpdated:
fallthrough
case xdr.LedgerEntryChangeTypeLedgerEntryRestored: is equivalent to: case xdr.LedgerEntryChangeTypeLedgerEntryUpdated, xdr.LedgerEntryChangeTypeLedgerEntryRestored: |
||
xdr.LedgerEntryChangeTypeLedgerEntryRestored: | ||
post := change.Post | ||
if change.Type == xdr.LedgerEntryTypeTtl { | ||
// CAP-63 introduces special update semantics for TTL entries, see | ||
// https://github.com/stellar/stellar-protocol/blob/master/core/cap-0063.md#ttl-ledger-change-semantics | ||
*post.Data.Ttl = maxTTL(*existingChange.Post.Data.Ttl, *post.Data.Ttl) | ||
} | ||
case xdr.LedgerEntryChangeTypeLedgerEntryUpdated: | ||
fallthrough | ||
case xdr.LedgerEntryChangeTypeLedgerEntryRestored: | ||
c.cache[ledgerKeyString] = Change{ | ||
Type: change.Type, | ||
Pre: existingChange.Pre, | ||
Post: change.Post, | ||
Post: post, | ||
ChangeType: existingChange.ChangeType, //keep the existing change type | ||
} | ||
case xdr.LedgerEntryChangeTypeLedgerEntryRemoved: | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Acknowledged for the maxTTL