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 Change struct #5536

Open
wants to merge 11 commits into
base: master
Choose a base branch
from

Conversation

karthikiyer56
Copy link
Contributor

@karthikiyer56 karthikiyer56 commented Nov 20, 2024

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

This PR deals with this github issue - #5535

Why

[TODO: Why this change is being made. Include any context required to understand the why.]

Known limitations

[TODO or N/A]

@karthikiyer56 karthikiyer56 force-pushed the karthik/5535/Extend-change-struct-with-operationDetails branch from ba3ad68 to d158205 Compare November 20, 2024 08:40
ingest/change.go Outdated
Type xdr.LedgerEntryType
Pre *xdr.LedgerEntry
Post *xdr.LedgerEntry
isOperationChange bool
Copy link
Contributor

Choose a reason for hiding this comment

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

It looks like there are several sources for a change within a Ledger:

I think it would be could to have a separate type which represents the source of the change. The source of the change can be similar to an xdr union in that it is belonging to one of the categories listed above.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Done

ingest/change.go Outdated
Pre *xdr.LedgerEntry
Post *xdr.LedgerEntry
reason LedgerEntryChangeReason
TransactionData *TransactionEnvelopeAndResult
Copy link
Contributor

Choose a reason for hiding this comment

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

I think it's better to include a pointer to LedgerTransaction which already contains the envelope and the result. It can also be used to find the operation via the GetOperation() function. so we can also get rid of OperationInfo and store the operation index in Change. The operation index will only be valid if the change reason is equal to Operation

Copy link
Contributor

Choose a reason for hiding this comment

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

We should also add another field which is a pointer to the LedgerCloseMeta which produced this change

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Done

ingest/change.go Outdated
Type xdr.LedgerEntryType
Pre *xdr.LedgerEntry
Post *xdr.LedgerEntry
reason LedgerEntryChangeReason
Copy link
Contributor

Choose a reason for hiding this comment

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

reason should be exported so that it is accessible outside the ingest package

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Done

ingest/change.go Outdated
Operation
Transaction
FeeChange
ProtocolUpgrade
Copy link
Contributor

Choose a reason for hiding this comment

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

I'm not sure if the upgrades field in the LCM corresponds to protocol upgrades, I would confirm this with the stellar core team.

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 need to confirm.
A deeper code inspection indicates that UpgradeChanges can mean much more than just ProtocolUpgrade related changes.
Have modified the Chagne struct to include LedgerUpgradeChange

operationInfo *OperationInfo
}

type LedgerEntryChangeReason uint16
Copy link
Contributor

Choose a reason for hiding this comment

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

could you add a doc comment for this type and the enum values listed below this code

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yes, I redid the comments on this Change struct nauseam 🙈

@tamirms
Copy link
Contributor

tamirms commented Nov 21, 2024

@karthikiyer56 TestLiquidityPoolDepositDetails in master/services/horizon/internal/ingest/processors/transaction_operation_wrapper_test.go is one of the unit tests that is failing on your branch.

I looked into it and the reason it is failing is because the ingest.LedgerTransaction instance in the test is not complete. It is missing the transaction envelope.

The test exercises a code path where GetOperationChanges() is called on the ingest.LedgerTransaction instance. It fails there because you have modified the code to include operation details into the change. The operation info is pulled from the transaction envelope (which is the right thing to do). However, because the test case does not populate the ingest.LedgerTransaction instance with a transaction envelop, the operation is not found and that causes the test not to pass.

@karthikiyer56
Copy link
Contributor Author

karthikiyer56 commented Nov 21, 2024

@karthikiyer56 TestLiquidityPoolDepositDetails in master/services/horizon/internal/ingest/processors/transaction_operation_wrapper_test.go is one of the unit tests that is failing on your branch.

I looked into it and the reason it is failing is because the ingest.LedgerTransaction instance in the test is not complete. It is missing the transaction envelope.

The test exercises a code path where GetOperationChanges() is called on the ingest.LedgerTransaction instance. It fails there because you have modified the code to include operation details into the change. The operation info is pulled from the transaction envelope (which is the right thing to do). However, because the test case does not populate the ingest.LedgerTransaction instance with a transaction envelop, the operation is not found and that causes the test not to pass.

Yup.
Earlier in the day, when the code was fetching operational results, more tests were failing because the ledger operations were missing in more tests.
I tried fixing them, and they still were failing, even when i did add operations to a few test fixtures

So, i decided to simplify the data returned in the change structure 😓
Just as well, since we can derive more details from just envelope and tx result, at the call site itself, when we use the code in trades processing.

At any rate,i thought the latest changes should not cause any unit test failures anymore. I'll look into the one that is failing now.

Good call-out.
Ima just pass a pointer to the ingest.edgerTransaction itself in change,instead of TX envelope and result pair

@@ -17,6 +17,8 @@ type LedgerTransaction struct {
FeeChanges xdr.LedgerEntryChanges
UnsafeMeta xdr.TransactionMeta
LedgerVersion uint32
Lcm *xdr.LedgerCloseMeta // This is read-only and not to be modified by downstream functions
Hash *xdr.Hash
Copy link
Contributor

Choose a reason for hiding this comment

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

Hash and Lcm should be values instead of pointers since we expect them to be non-nil

@@ -17,6 +17,8 @@ type LedgerTransaction struct {
FeeChanges xdr.LedgerEntryChanges
UnsafeMeta xdr.TransactionMeta
LedgerVersion uint32
Lcm *xdr.LedgerCloseMeta // This is read-only and not to be modified by downstream functions
Copy link
Contributor

Choose a reason for hiding this comment

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

I think this should be a private variable since it only is present here for populating changes.

Copy link
Contributor

Choose a reason for hiding this comment

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

Hash can remain public because it is a property of the transaction

Copy link
Contributor

Choose a reason for hiding this comment

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

Also, I think Lcm should be renamed to Ledger to be consistent with how the other fields in this struct are named (note that none of the other fields are abbreviated)

changes := GetChangesFromLedgerEntryChanges(t.FeeChanges)
for _, change := range changes {
change.Reason = FeeChange
change.Tx = t
Copy link
Contributor

Choose a reason for hiding this comment

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

I think we should also populate the ledger field in the change

for _, change := range changes {
change.Reason = Operation
change.Tx = t
change.OperationIdx = index
Copy link
Contributor

Choose a reason for hiding this comment

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

I think we should also populate the ledger field in the change

Comment on lines +218 to +221
// This is not expected to happen.
if (e == TransactionEnvelope{}) {
return []Operation{}
}
Copy link
Contributor

Choose a reason for hiding this comment

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

I don't think this is necessary

@@ -324,7 +324,7 @@ func addAccountAndMuxedAccountDetails(result map[string]interface{}, a xdr.Muxed
// _muxed_id fields should had ideally been stored in the DB as a string instead of uint64
// due to Javascript not being able to handle them, see https://github.com/stellar/go/issues/3714
// However, we released this code in the wild before correcting it. Thus, what we do is
// work around it (by preprocessing it into a string) in Operation.UnmarshalDetails()
// work around it (by preprocessing it into a string) in OperationChange.UnmarshalDetails()
Copy link
Contributor

Choose a reason for hiding this comment

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

I don't think we need to update the comment here

@@ -336,7 +336,7 @@ func TestFeeMetaAndOperationsChangesSeparate(t *testing.T) {
assert.Equal(t, operationChanges[0].Pre.Data.MustAccount().Balance, xdr.Int64(300))
assert.Equal(t, operationChanges[0].Post.Data.MustAccount().Balance, xdr.Int64(400))

// Ignore operation meta if tx result is txInternalError
// Ignore operation meta if Tx result is txInternalError
Copy link
Contributor

Choose a reason for hiding this comment

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

I don't think we should be changing this comment

Comment on lines +69 to +71
OperationIdx uint32
Tx *LedgerTransaction
Lcm *xdr.LedgerCloseMeta
Copy link
Contributor

Choose a reason for hiding this comment

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

I think the fields should be consistent with how other public fields in this package are named. So, Tx should be renamed to Transaction, Lcm -> Ledger, OperationIdx -> OperationIndex

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.

2 participants