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: Add support for ledger entry change type "restore" for Protocol 23 #5587

Merged
merged 19 commits into from
Feb 18, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
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: 1 addition & 1 deletion .github/workflows/horizon.yml
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ jobs:
HORIZON_INTEGRATION_TESTS_CAPTIVE_CORE_USE_DB: true
PROTOCOL_22_CORE_DEBIAN_PKG_VERSION: 22.1.0-2194.0241e79f7.focal
PROTOCOL_22_CORE_DOCKER_IMG: stellar/stellar-core:22.1.0-2194.0241e79f7.focal
PROTOCOL_22_STELLAR_RPC_DOCKER_IMG: stellar/stellar-rpc:22.1.1
PROTOCOL_22_STELLAR_RPC_DOCKER_IMG: stellar/stellar-rpc:22.1.2
PGHOST: localhost
PGPORT: 5432
PGUSER: postgres
Expand Down
3 changes: 3 additions & 0 deletions ingest/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,9 @@ All notable changes to this project will be documented in this file. This projec

## Pending

### Protocol 23 Support
* Added support for the new `RESTORE` ledger entry change type [5587](https://github.com/stellar/go/pull/5587).

### Bug Fixes
* Update the boundary check in `BufferedStorageBackend` to queue ledgers up to the end boundary, resolving skipped final batch when the `from` ledger doesn't align with file boundary [5563](https://github.com/stellar/go/pull/5563).

Expand Down
65 changes: 40 additions & 25 deletions ingest/change.go
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,9 @@ type Change struct {
// The type of the ledger entry being changed.
Type xdr.LedgerEntryType

// The specific type of change, such as Created, Updated, Removed or Restored.
ChangeType xdr.LedgerEntryChangeType

// The state of the LedgerEntry before the change. This will be nil if the entry was created.
Pre *xdr.LedgerEntry

Expand Down Expand Up @@ -134,6 +137,7 @@ func (c Change) LedgerKey() (xdr.LedgerKey, error) {
// - for create, pre is null and post is a new entry,
// - for update, pre is previous state and post is the current state,
// - for removed, pre is previous state and post is null.
// - for restored, pre is null and post is a new/restored entry
//
// stellar-core source:
// https://github.com/stellar/stellar-core/blob/e584b43/src/ledger/LedgerTxn.cpp#L582
Expand All @@ -144,24 +148,49 @@ func GetChangesFromLedgerEntryChanges(ledgerEntryChanges xdr.LedgerEntryChanges)
case xdr.LedgerEntryChangeTypeLedgerEntryCreated:
created := entryChange.MustCreated()
changes = append(changes, Change{
Type: created.Data.Type,
Pre: nil,
Post: &created,
Type: created.Data.Type,
Pre: nil,
Post: &created,
ChangeType: entryChange.Type,
})
case xdr.LedgerEntryChangeTypeLedgerEntryUpdated:
state := ledgerEntryChanges[i-1].MustState()
// Update entries always have a previous state entry [state, updated]
// except for contract entries that are restored and updated within the same
// transaction, which appear as [restored, updated]
// For details, see https://github.com/stellar/stellar-protocol/blob/master/core/cap-0062.md
updated := entryChange.MustUpdated()
state, ok := ledgerEntryChanges[i-1].GetState()
if !ok {
state = ledgerEntryChanges[i-1].MustRestored()
}
changes = append(changes, Change{
Type: state.Data.Type,
Pre: &state,
Post: &updated,
Type: state.Data.Type,
Pre: &state,
Post: &updated,
ChangeType: entryChange.Type,
})
case xdr.LedgerEntryChangeTypeLedgerEntryRemoved:
state := ledgerEntryChanges[i-1].MustState()
// Removed entries always have an associated state entry [state, updated]
// except for contract entries that are restored and removed within the same
// transaction, which appear as [restored, removed]
// For details, see https://github.com/stellar/stellar-protocol/blob/master/core/cap-0062.md
state, ok := ledgerEntryChanges[i-1].GetState()
if !ok {
state = ledgerEntryChanges[i-1].MustRestored()
}
changes = append(changes, Change{
Type: state.Data.Type,
Pre: &state,
Post: nil,
ChangeType: entryChange.Type,
})
case xdr.LedgerEntryChangeTypeLedgerEntryRestored:
restored := entryChange.MustRestored()
changes = append(changes, Change{
Type: state.Data.Type,
Pre: &state,
Post: nil,
Type: restored.Data.Type,
Pre: nil,
Post: &restored,
ChangeType: entryChange.Type,
})
case xdr.LedgerEntryChangeTypeLedgerEntryState:
continue
Expand Down Expand Up @@ -221,20 +250,6 @@ func sortChanges(changes []Change) {
sort.Stable(newSortableChanges(changes))
}

// LedgerEntryChangeType returns type in terms of LedgerEntryChangeType.
func (c Change) LedgerEntryChangeType() xdr.LedgerEntryChangeType {
switch {
case c.Pre == nil && c.Post != nil:
return xdr.LedgerEntryChangeTypeLedgerEntryCreated
case c.Pre != nil && c.Post == nil:
return xdr.LedgerEntryChangeTypeLedgerEntryRemoved
case c.Pre != nil && c.Post != nil:
return xdr.LedgerEntryChangeTypeLedgerEntryUpdated
default:
panic("Invalid state of Change (Pre == nil && Post == nil)")
}
}

// getLiquidityPool gets the most recent state of the LiquidityPool that exists or existed.
func (c Change) getLiquidityPool() (*xdr.LiquidityPoolEntry, error) {
var entry *xdr.LiquidityPoolEntry
Expand Down
Loading
Loading