-
Notifications
You must be signed in to change notification settings - Fork 507
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
Token Transfer Processor - Derive classic events from operation and operation results #5609
base: master
Are you sure you want to change the base?
Conversation
159c84a
to
36946d4
Compare
36946d4
to
571679c
Compare
…action_envelope and the test fixture. It is not used anyway
… work, regardless of order
@@ -592,31 +596,6 @@ func (t *LedgerTransaction) AccountMuxed() (string, bool) { | |||
|
|||
} | |||
|
|||
func (t *LedgerTransaction) FeeAccount() (string, 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.
The name of the function seems to suggest that this function will give the underlying fee account - be it a regular transaction or a fee bump transaction.
IMO, this is very misleading.
- I found that it behaved contrary to what the name suggested when my code was not working as expected, in that if it the tx is not a fee bump tx, it returns
""
. xxxAccount
being the function name, i'd expect the return type to bexdr.MuxedAccount
, to be consistent with other functions here.
Besides, I dont see it being used anywhere other than in a sample unit test.
I am removing this function and the function below so as to not cause further confusion
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 agree with your assessment but we should sync with @chowbao to make sure etl isn't impacted by this change
|
||
import ( | ||
"github.com/stellar/go/ingest" | ||
addressProto "github.com/stellar/go/ingest/address" |
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.
This file is the real deal and needs to be reviewed thoroughly.
Adding a comment to ensure that this doesnt slip up - since the load diff might not render the file.
) | ||
|
||
var ( | ||
someTxAccount = xdr.MustMuxedAddress("GBF3XFXGBGNQDN3HOSZ7NVRF6TJ2JOD5U6ELIWJOOEI6T5WKMQT2YSXQ") |
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.
There are several variables here that I am using throughout the test, and so they have been clubbed here at the top.
They, IMHO, improve the code readability when reviewing the tests, and I am not inclined to move them to individual tests, but rather have them at the top-level here
…ad of a muxed account. This helps simplify the logic at call site for the operations when called with LPhash or CBid
…entries from operation changes
…y the most complicated functions to implement
…ase to validate some logic
@@ -18,6 +22,240 @@ import ( | |||
"github.com/stellar/go/xdr" | |||
) | |||
|
|||
func TestLiquidityPoolHappyPath2(t *testing.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.
the changes in this integration test are purely for PoC.
will be removed later
…ated this claimable balance
return generatedClaimableBalanceIds, nil | ||
} | ||
|
||
func getClaimableBalanceEntriesFromOperationChanges(tx ingest.LedgerTransaction, opIndex uint32) ([]xdr.ClaimableBalanceEntry, error) { |
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.
this function is used to find claimable balances that were either created or removed. however, the caller expects the returned list to never have a mix between the two types. I think it would be better to add a xdr.LedgerEntryChangeType
parameter which can be used to filter for the exact change types desired by the caller (e.g. only created claimable balances or only removed claimable balances)
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.
Seeing that this is an internal function, I see little chance for misuse/mis-representation of what this function is intended to do.
at any rate, I have changed the function to accept a changeType xdr.LedgerEntryChangeType
and added a comment at the top.
callers of the function will either pass - LedgerEntryChangeTypeLedgerEntryRemoved
or LedgerEntryChangeTypeLedgerEntryCreated
. It will fail when anything else is passed
if len(entries) == 0 { | ||
return nil, ErrNoLiquidityPoolEntryFound | ||
} |
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.
nit: I think it's better style to return the empty list without an error so the caller can decide how the empty list should be handled. it's not obvious from the name of the function that at least 1 liquidity pool should be present and anything otherwise would be an error
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.
reworked to do error/length check at call-site instead of inside the function
if len(entries) == 0 { | ||
return nil, ErrNoClaimableBalanceEntryFound | ||
} |
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.
nit, same comment as ErrNoLiquidityPoolEntryFound:
I think it's better style to return the empty list without an error so the caller can decide how the empty list should be handled.
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.
reworked to do error/length check at call-site instead of inside the function
…dress code review comments
…n and its results
return generateEventsForRevokedTrustlines(tx, opIndex) | ||
} | ||
|
||
func generateEventsForRevokedTrustlines(tx ingest.LedgerTransaction, opIndex uint32) ([]*TokenTransferEvent, error) { |
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.
this is the dooziest logic of all the code in this file.
I have written unit tests that test this ad-nauseum
This is the only part of the code where I have felt the need to be over-liberal with comments to indicate what the code is doing, since it is very non-trivial how the Cbs are generated from LPs when trustline revocation of an asset happens for a trustor account
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 reviewed the logic and it looks correct to me. I think the code would be easier to understand if you refactored it to avoid iterating over impactedLiquidityPools
twice, but that's just my personal opinion. Here's my attempt to simplify the code:
feel free to take or reject whichever parts you see fit
) | ||
|
||
/* | ||
Helper function to convert LiquidityPoolId to generate ClaimableBalanceIds in a deterministic way as per |
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 needed a place to park this generic logic that generates CBids from LPids.
I use this in the code and also in the unit tests.
It didnt make sense to subsume it under token_transfer_processor
, so parking it here under a new directory -converters
under support
Happy to move this to another place, so long as this is a public function.
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 would put it either in the xdr package or along with the xdrill code in the ingest package. Also, I suggest using a more concise name for the function, maybe, ClaimableBalanceIdFromRevocation or BalanceIdFromRevocation?
if !(changeType == xdr.LedgerEntryChangeTypeLedgerEntryRemoved || changeType == xdr.LedgerEntryChangeTypeLedgerEntryCreated) { | ||
return nil, fmt.Errorf("changeType: %v, not allowed", changeType) | ||
} |
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 error is necessary. The function will obtain all cb changes occurring from an operation filtered by a change type. The fact that the function happens to be called only for removed or created changes is something determined by the caller
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.
oh nevermind, I just realized that with updates it's not clear which claimable balance (either pre or post) to include. you can ignore this comment
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.
you could simplify the if statement condition to:
if !(changeType == xdr.LedgerEntryChangeTypeLedgerEntryRemoved || changeType == xdr.LedgerEntryChangeTypeLedgerEntryCreated) { | |
return nil, fmt.Errorf("changeType: %v, not allowed", changeType) | |
} | |
if changeType == xdr.LedgerEntryChangeTypeLedgerEntryUpdated { | |
return nil, fmt.Errorf("LEDGER_ENTRY_UPDATED is not a valid filter") | |
} |
if change.Type != xdr.LedgerEntryTypeClaimableBalance { | ||
continue | ||
} | ||
// Check if claimable balance entry is deleted | ||
//?? maybe it is not necessary to check change.Pre != nil && change.Post since that will be true for deleted entries? | ||
if changeType == xdr.LedgerEntryChangeTypeLedgerEntryRemoved && change.Pre != nil && change.Post == nil { | ||
cb = change.Pre.Data.MustClaimableBalance() | ||
entries = append(entries, cb) | ||
} else if changeType == xdr.LedgerEntryChangeTypeLedgerEntryCreated && change.Post != nil && change.Pre == nil { // check if claimable balance entry is created | ||
cb = change.Post.Data.MustClaimableBalance() | ||
entries = append(entries, cb) | ||
} |
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.
if change.Type != xdr.LedgerEntryTypeClaimableBalance { | |
continue | |
} | |
// Check if claimable balance entry is deleted | |
//?? maybe it is not necessary to check change.Pre != nil && change.Post since that will be true for deleted entries? | |
if changeType == xdr.LedgerEntryChangeTypeLedgerEntryRemoved && change.Pre != nil && change.Post == nil { | |
cb = change.Pre.Data.MustClaimableBalance() | |
entries = append(entries, cb) | |
} else if changeType == xdr.LedgerEntryChangeTypeLedgerEntryCreated && change.Post != nil && change.Pre == nil { // check if claimable balance entry is created | |
cb = change.Post.Data.MustClaimableBalance() | |
entries = append(entries, cb) | |
} | |
if change.Type != xdr.LedgerEntryTypeClaimableBalance || change.LedgerEntryChangeType() != changeType { | |
continue | |
} | |
if change.Pre != nil { | |
cb = change.Pre.Data.MustClaimableBalance() | |
entries = append(entries, cb) | |
} else if change.Post != nil { | |
cb = change.Post.Data.MustClaimableBalance() | |
entries = append(entries, cb) | |
} |
amtA, amtB := delta.amountChangeForAssetA, delta.amountChangeForAssetB | ||
if amtA <= 0 { | ||
return nil, | ||
fmt.Errorf("deposited amount (%v) for asset: %v, cannot be negative in LiquidityPool: %v", amtA, assetA.String(), lpIdToStrkey(lpId)) |
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.
error string indicates negative values are not allowed but the if statement is actually including 0 values as well in the illegal state
var ( | ||
xlmProtoAsset = assetProto.NewNativeAsset() | ||
ErrNoLiquidityPoolEntryFound = errors.New("no liquidity pool entry found in operation changes") | ||
ErrNoClaimableBalanceEntryFound = errors.New("no claimable balance entry found in operation 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.
this is no longer used
|
||
func lpIdToStrkey(lpId xdr.PoolId) string { | ||
return xdr.Hash(lpId).HexString() | ||
} |
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.
this file is quite long, it would be easier to read the code if the code in this file was split into multiple files. maybe this could be refactored into three files:
- one for path payment and offer related operations
- one for revocation and liquidity pool operations
- one for everything else
This PR deals with deriving TokenTransferEvents from operation and operation results as described in #5580
This PR is strictly dealing with classic and classic operations, i.e the PR implements the ask from #5592