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

Include operation information in the ingest.Change struct #5536

Merged
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
Show all changes
29 commits
Select commit Hold shift + click to select a range
d158205
Include operation information in the Change struct
karthikiyer56 Nov 20, 2024
66abef5
Dont error out when operation index out of range
karthikiyer56 Nov 20, 2024
fb94fdf
Fix failing unit test
karthikiyer56 Nov 21, 2024
06139d3
Reafactor ledger_transaction.GetChanges() to use internal functions
karthikiyer56 Nov 21, 2024
070c552
reformat comments
karthikiyer56 Nov 21, 2024
26780fa
Add all types of change reasons to the Change struct. Simplify Ledger…
karthikiyer56 Nov 21, 2024
b168415
Add LCM and transaction info altogether in change entry
karthikiyer56 Nov 21, 2024
29bc9bc
Wrte help doc for Change Entry
karthikiyer56 Nov 21, 2024
73e4494
Add TxHash to LedgerTransaction struct
karthikiyer56 Nov 21, 2024
c06e241
reorg comments
karthikiyer56 Nov 21, 2024
fe7cef8
Comments cleanup
karthikiyer56 Nov 21, 2024
06c515c
Address PR review changes
karthikiyer56 Nov 25, 2024
01b86b0
rename fields
karthikiyer56 Nov 25, 2024
e363afc
uncommit half baked changes
karthikiyer56 Nov 25, 2024
e2f95d6
Add helpers in intergration tests for creating captive core config
karthikiyer56 Nov 25, 2024
564c3bb
fix updates to change struct
karthikiyer56 Nov 27, 2024
88af498
Updates to integration.go
karthikiyer56 Nov 27, 2024
343373b
Integration tests for change - part 1
karthikiyer56 Nov 27, 2024
c7f37fb
Undo all changes to parameters_test.go
karthikiyer56 Nov 28, 2024
5313aa6
Make updates to comments and rename variables
karthikiyer56 Nov 30, 2024
dccf1e2
- Several changes to integration.go to pull out common functions from…
karthikiyer56 Nov 30, 2024
6d97032
cosmetic doc style changes
karthikiyer56 Nov 30, 2024
adf96c1
check err before file close
karthikiyer56 Nov 30, 2024
fee6685
Add tx test and in change_test.go
karthikiyer56 Dec 1, 2024
157c12e
code cleanup
karthikiyer56 Dec 1, 2024
b82a9dd
Rework test fixtures
karthikiyer56 Dec 3, 2024
3bd80ec
reformat file
karthikiyer56 Dec 3, 2024
e4b3a67
Fix breaking test
karthikiyer56 Dec 3, 2024
c3fbe24
Address code review comments
karthikiyer56 Dec 3, 2024
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
16 changes: 13 additions & 3 deletions ingest/change.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,10 +16,20 @@ import (
// If an entry is created: Pre is nil and Post is not nil.
// If an entry is updated: Pre is not nil and Post is not nil.
// If an entry is removed: Pre is not nil and Post is nil.
// If this change is caused by a operation in a transaction, include the operation information. Wont work when changes are compacted
type Change struct {
Type xdr.LedgerEntryType
Pre *xdr.LedgerEntry
Post *xdr.LedgerEntry
Type xdr.LedgerEntryType
Pre *xdr.LedgerEntry
Post *xdr.LedgerEntry
isOperationChange bool
karthikiyer56 marked this conversation as resolved.
Show resolved Hide resolved
operationInfo *OperationInfo
}

type OperationInfo struct {
operationIdx uint32
operation *xdr.Operation
operationResult *xdr.OperationResultTr
txEnvelope *xdr.TransactionEnvelope
}

// String returns a best effort string representation of the change.
Expand Down
89 changes: 74 additions & 15 deletions ingest/ledger_transaction.go
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@ func (t *LedgerTransaction) GetChanges() ([]Change, error) {
return changes, errors.New("TransactionMeta.V=0 not supported")
case 1:
v1Meta := t.UnsafeMeta.MustV1()
// The var `txChanges` reflect the ledgerEntryChanges that are changed because of the transaction as a whole
txChanges := GetChangesFromLedgerEntryChanges(v1Meta.TxChanges)
changes = append(changes, txChanges...)

Expand All @@ -50,34 +51,54 @@ func (t *LedgerTransaction) GetChanges() ([]Change, error) {
return changes, nil
}

for _, operationMeta := range v1Meta.Operations {
// These changes reflect the ledgerEntry changes that were caused by the operations in the transaction
// Populate the operationInfo for these changes in the `Change` struct

// TODO: Refactor this to use LedgerTransaction.GetOperationChanges
for opIdx, operationMeta := range v1Meta.Operations {
opChanges := GetChangesFromLedgerEntryChanges(
operationMeta.Changes,
)
for _, change := range opChanges {
op, found := t.GetOperation(uint32(opIdx))
if !found {
return []Change{}, errors.New("could not find operation")
}
results, _ := t.Result.OperationResults()
operationResult := results[opIdx].MustTr()
operationInfo := OperationInfo{
operationIdx: uint32(opIdx),
operation: &op,
operationResult: &operationResult,
txEnvelope: &t.Envelope,
}
change.operationInfo = &operationInfo
change.isOperationChange = true
}
changes = append(changes, opChanges...)
}
case 2, 3:
var (
beforeChanges, afterChanges xdr.LedgerEntryChanges
operationMeta []xdr.OperationMeta
txBeforeChanges, txAfterChanges xdr.LedgerEntryChanges
operationMeta []xdr.OperationMeta
)

switch t.UnsafeMeta.V {
case 2:
v2Meta := t.UnsafeMeta.MustV2()
beforeChanges = v2Meta.TxChangesBefore
afterChanges = v2Meta.TxChangesAfter
txBeforeChanges = v2Meta.TxChangesBefore
txAfterChanges = v2Meta.TxChangesAfter
operationMeta = v2Meta.Operations
case 3:
v3Meta := t.UnsafeMeta.MustV3()
beforeChanges = v3Meta.TxChangesBefore
afterChanges = v3Meta.TxChangesAfter
txBeforeChanges = v3Meta.TxChangesBefore
txAfterChanges = v3Meta.TxChangesAfter
operationMeta = v3Meta.Operations
default:
panic("Invalid meta version, expected 2 or 3")
}

txChangesBefore := GetChangesFromLedgerEntryChanges(beforeChanges)
txChangesBefore := GetChangesFromLedgerEntryChanges(txBeforeChanges)
changes = append(changes, txChangesBefore...)

// Ignore operations meta and txChangesAfter if txInternalError
Expand All @@ -86,14 +107,31 @@ func (t *LedgerTransaction) GetChanges() ([]Change, error) {
return changes, nil
}

for _, operationMeta := range operationMeta {
// TODO: Refactor this to use LedgerTransaction.GetOperationChanges
for opIdx, operationMetaChanges := range operationMeta {
opChanges := GetChangesFromLedgerEntryChanges(
operationMeta.Changes,
operationMetaChanges.Changes,
)
for _, change := range opChanges {
op, found := t.GetOperation(uint32(opIdx))
if !found {
return []Change{}, errors.New("could not find operation")
}
results, _ := t.Result.OperationResults()
operationResult := results[opIdx].MustTr()
operationInfo := OperationInfo{
operationIdx: uint32(opIdx),
operation: &op,
operationResult: &operationResult,
txEnvelope: &t.Envelope,
}
change.operationInfo = &operationInfo
change.isOperationChange = true
}
changes = append(changes, opChanges...)
}

txChangesAfter := GetChangesFromLedgerEntryChanges(afterChanges)
txChangesAfter := GetChangesFromLedgerEntryChanges(txAfterChanges)
changes = append(changes, txChangesAfter...)
default:
return changes, errors.New("Unsupported TransactionMeta version")
Expand Down Expand Up @@ -137,18 +175,39 @@ func (t *LedgerTransaction) GetOperationChanges(operationIndex uint32) ([]Change
return changes, errors.New("Unsupported TransactionMeta version")
}

return operationChanges(operationMeta, operationIndex), nil
changes, err := t.operationChanges(operationMeta, operationIndex)
if err != nil {
return []Change{}, err
}
return changes, nil
}

func operationChanges(ops []xdr.OperationMeta, index uint32) []Change {
func (t *LedgerTransaction) operationChanges(ops []xdr.OperationMeta, index uint32) ([]Change, error) {
if int(index) >= len(ops) {
return []Change{}
return []Change{}, nil // TODO - operations_processor somehow seems to be failing without this
}

operationMeta := ops[index]
return GetChangesFromLedgerEntryChanges(
changes := GetChangesFromLedgerEntryChanges(
operationMeta.Changes,
)
for _, change := range changes {
op, found := t.GetOperation(index)
if !found {
return []Change{}, errors.New("could not find operation")
}
results, _ := t.Result.OperationResults()
operationResult := results[index].MustTr()
operationInfo := OperationInfo{
operationIdx: index,
operation: &op,
operationResult: &operationResult,
txEnvelope: &t.Envelope,
}
change.operationInfo = &operationInfo
change.isOperationChange = true
}
return changes, nil
}

// GetDiagnosticEvents returns all contract events emitted by a given operation.
Expand Down
Loading