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

xdrill for operations #2

Open
wants to merge 11 commits into
base: 5550/xdrill-transactions
Choose a base branch
from

Conversation

chowbao
Copy link
Owner

@chowbao chowbao commented Jan 16, 2025

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

github issue

xdrill functions for LedgerOperations

Why

Create low level helper functions for operations parsing

Known limitations

  • Refactor of the processor/transforms to be done in separate ticket/pr

@chowbao
Copy link
Owner Author

chowbao commented Jan 17, 2025

Similar problems in stellar#5568 and #1 exist in this PR as well. TODO: fix it

Copy link

@sydneynotthecity sydneynotthecity left a comment

Choose a reason for hiding this comment

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

High level, there are some quirks in stellar-etl. Now is the time for us to discuss whether it makes sense to incorporate back in to XDRill or not. Particularly:

  • int vs real representation for asset amounts - should this stay in raw integer form? Should we convert to real? Offer both?
  • Asset id - this is an optimization specific to Hubble. Does it make sense to create a more universal asset hash? If so, does FarmHash make the most sense?
  • buy vs sell side of offers. In Horizon, these are presented as base and counter assets, where base asset hash < counter asset hash so that the trade pairs are consistently on the same side. This may be an opportunity for us to reimagine how we want this schema to be defined

if ok {
operationResultTr, ok := operationResults[o.OperationIndex].GetTr()
if ok {
operationTraceCode, err := operationResultTr.MapOperationResultTr()

Choose a reason for hiding this comment

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

nit: = instead of :=

Copy link
Owner Author

Choose a reason for hiding this comment

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

updated in c68cd9a

if err := o.addAccountAndMuxedAccountDetails(details, op.Destination, "to"); err != nil {
return details, err
}
details["amount"] = o.ConvertStroopValueToReal(op.Amount)

Choose a reason for hiding this comment

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

do we want to bring over this logic from stellar-etl? I think both RPC and horizon keep the raw stroop values to avoid floating point errors. wdyt of keeping amounts in stroops?

Copy link
Owner Author

Choose a reason for hiding this comment

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

Hmm that's fair. Less railroading people into floating point if they don't want ot

Copy link
Owner Author

Choose a reason for hiding this comment

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

updated in c68cd9a

if ledgerKey.TrustLine.Asset.Type == xdr.AssetTypeAssetTypePoolShare {
result["trustline_liquidity_pool_id"] = o.PoolIDToString(*ledgerKey.TrustLine.Asset.LiquidityPoolId)
} else {
result["trustline_asset"] = ledgerKey.TrustLine.Asset.ToAsset().StringCanonical()

Choose a reason for hiding this comment

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

nit: Should we be parsing asset consistent via addAssetDetails...?

Copy link
Owner Author

Choose a reason for hiding this comment

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

Let me take a look at this again. Might have just been stellar-etl never updated this or there was an actual reason for this

Copy link
Owner Author

Choose a reason for hiding this comment

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

Yeah so this is a type TrustLineAsset

type TrustLineAsset struct {
	Type            AssetType
	AlphaNum4       *AlphaNum4
	AlphaNum12      *AlphaNum12
	LiquidityPoolId *PoolId
}

Note the extra LiquidityPoolId *PoolId

Whereas addAssetDetails only handles normal Asset types. I'll try to consolidate as I think they effectively want the same "asset" info

return details, fmt.Errorf("could not access CreateClaimableBalance info for this operation (index %d)", o.OperationIndex)
}

details["asset"] = op.Asset.StringCanonical()

Choose a reason for hiding this comment

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

nit: asset representation is different from manage buy/sell offer

Copy link
Owner Author

Choose a reason for hiding this comment

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

updated in c68cd9a

ingest/ledger_operation.go Show resolved Hide resolved
details := map[string]interface{}{}
_, ok := o.Operation.Body.GetRestoreFootprintOp()
if !ok {
return details, fmt.Errorf("could not access InvokeHostFunction info for this operation (index %d)", o.OperationIndex)

Choose a reason for hiding this comment

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

nit: copy/paste error. wrong operation type

Copy link
Owner Author

Choose a reason for hiding this comment

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

🤦

Copy link
Owner Author

Choose a reason for hiding this comment

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

updated in c68cd9a

@chowbao
Copy link
Owner Author

chowbao commented Jan 23, 2025

High level, there are some quirks in stellar-etl. Now is the time for us to discuss whether it makes sense to incorporate back in to XDRill or not. Particularly:

  • int vs real representation for asset amounts - should this stay in raw integer form? Should we convert to real? Offer both?
  • Asset id - this is an optimization specific to Hubble. Does it make sense to create a more universal asset hash? If so, does FarmHash make the most sense?
  • buy vs sell side of offers. In Horizon, these are presented as base and counter assets, where base asset hash < counter asset hash so that the trade pairs are consistently on the same side. This may be an opportunity for us to reimagine how we want this schema to be defined

Now is the time for us to discuss whether it makes sense to incorporate back in to XDRill or not

Yeah I was debating this too. Thinking about it again I personally would lean towards addressing the quirks now. It means less refactoring in the future in favor of spending more time now.

But I think it might be the right decision to defer for now. It's much easier to test and compare similar logic rather than slightly different logic. Like for refactor/testing of stellar-etl/processors/xdrill it'll be as easy as writing the new code and compare the output of old stellar-etl == new stellar-etl. I think the fewer value fixes we make will make the diffing much easier. Basically sticking with the status quo makes it easier for myself or anyone else to pick up later.

  • int vs real representation for asset amounts - should this stay in raw integer form? Should we convert to real? Offer both?

I agree with keeping this in the raw form instead of converted float

  • Asset id - this is an optimization specific to Hubble. Does it make sense to create a more universal asset hash? If so, does FarmHash make the most sense?

iirc the issue with the pure FarmHash is that it didn't fit nicely into the BigQuery integer size (64/128 bytes?) which is why some asset_ids can be negative because the BQ column for asset_id is int64 (?) instead of a long long type (128+). This is hacky.

I'm not opposed to making this more standard and make more sense though

  • buy vs sell side of offers. In Horizon, these are presented as base and counter assets, where base asset hash < counter asset hash so that the trade pairs are consistently on the same side. This may be an opportunity for us to reimagine how we want this schema to be defined

👍

Edit: So I went ahead and did make the int versus real amount change

@@ -0,0 +1,47 @@
package ingest
Copy link
Owner Author

Choose a reason for hiding this comment

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

Similarly to #3 (comment)

OperationDetails has been updated to structs to preserve strict typing for data instead of the the previous map[string]string/interface{}

Copy link
Owner Author

Choose a reason for hiding this comment

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

Oh also if anyone has better suggestions for organizing and what dir to put these files in I'm happy to update. One issue is that golang doesn't let you put these in a different directory and still have it as part of the same package (only files in the same dir can go in the same package) but if I separate these functions out to their own package I create a circular dependency with go/ingest

}

// TODO: Parameters should be processed with xdr2json
invokeHostFunctionDetail.Parameters, invokeHostFunctionDetail.ParametersDecoded = o.serializeParameters(args)
Copy link
Owner Author

Choose a reason for hiding this comment

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

How do we feel about making Parameters a straight JSON from xdr2json instead of our current ScVal parameter mess?

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