-
Notifications
You must be signed in to change notification settings - Fork 499
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
base: master
Are you sure you want to change the base?
Include operation information in the Change struct #5536
Conversation
ba3ad68
to
d158205
Compare
ingest/change.go
Outdated
Type xdr.LedgerEntryType | ||
Pre *xdr.LedgerEntry | ||
Post *xdr.LedgerEntry | ||
isOperationChange bool |
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.
It looks like there are several sources for a change within a Ledger:
- fees which are executed at the transaction level
- upgrades which are executed at the ledger level
- evictions which are executed at the ledger level
- transaction level changes
- operation level changes
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.
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.
Done
ingest/change.go
Outdated
Pre *xdr.LedgerEntry | ||
Post *xdr.LedgerEntry | ||
reason LedgerEntryChangeReason | ||
TransactionData *TransactionEnvelopeAndResult |
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.
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
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.
We should also add another field which is a pointer to the LedgerCloseMeta which produced this change
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.
Done
ingest/change.go
Outdated
Type xdr.LedgerEntryType | ||
Pre *xdr.LedgerEntry | ||
Post *xdr.LedgerEntry | ||
reason LedgerEntryChangeReason |
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.
reason should be exported so that it is accessible outside the ingest package
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.
Done
ingest/change.go
Outdated
Operation | ||
Transaction | ||
FeeChange | ||
ProtocolUpgrade |
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.
I'm not sure if the upgrades field in the LCM corresponds to protocol upgrades, I would confirm this with the stellar core team.
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.
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 |
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.
could you add a doc comment for this type and the enum values listed below this code
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.
Yes, I redid the comments on this Change struct nauseam 🙈
@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. So, i decided to simplify the data returned in the change structure 😓 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. |
@@ -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 |
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.
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 |
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.
I think this should be a private variable since it only is present here for populating changes.
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.
Hash can remain public because it is a property of the transaction
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.
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 |
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.
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 |
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.
I think we should also populate the ledger field in the change
// This is not expected to happen. | ||
if (e == TransactionEnvelope{}) { | ||
return []Operation{} | ||
} |
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.
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() |
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.
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 |
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.
I don't think we should be changing this comment
OperationIdx uint32 | ||
Tx *LedgerTransaction | ||
Lcm *xdr.LedgerCloseMeta |
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.
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
PR Checklist
PR Structure
otherwise).
services/friendbot
, orall
ordoc
if the changes are broad or impact manypackages.
Thoroughness
.md
files, etc... affected by this change). Take a look in the
docs
folder for a given service,like this one.
Release planning
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.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]