-
Notifications
You must be signed in to change notification settings - Fork 1.5k
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
Fix account_objects command for AMM account root #4678
Conversation
… account_objects.
I'm mildly against adding special cases here. Either the AMM should be in the owner directory, or account_objects should not return it. I think it's a weird quirk to artificially add an AMM to the account_objects response. I would be more OK with adding error cases to the account_objects API method to return invalidParams when filtering by a type that can't be owned by an account. Maybe this is hypocritical of me, but I'd be more OK with adding a special case error message directing people toward the right way to look up an AMM than I would with adding a special case to actually return the AMM even though it's not "owned" in the typical sense. I'm willing to be convinced that this special case is warranted because AMM accounts are weird in a bunch of ways anyway, but, yeah. |
Isn't NFT handled as a special case? Is the ownership criteria purely based on the directory entry? The AMM directory entry is only used for the purpose of supporting |
I don't have strong opinion regarding treating/not treating it as special case in rippled, as I'm not well versed in rippled codebase. - If AMM object can be accessed via account_objects requestonly 1 request is needed to get AMM data. {
"method": "account_objects",
"params": [
{
"account": "rfgqMq9M2MXc7PjQqjFLomrFSg4AwQ35z2",
"ledger_index": "current",
"type": "amm"
}
]
} - If account_objects will not be able to retrieve AMM object2 requests are required
Considering clients might do such requests over an big array of LP tokens - in terms of efficiency, rippled will have to handle less requests with this change. |
bool const filterAMM = | ||
typeFilter.has_value() && typeMatchesFilter(typeFilter.value(), ltAMM); | ||
// skip amm if marker (dirIndex) is provided | ||
if (dirIndex == uint256{} && (!typeFilter.has_value() || filterAMM)) |
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 like declaring variables in if statements for simple cases where it saves polluting the parent scope with extra variables. Here I think the code is clearer if the variables are declared in the parent scope (which is already small). I'd also remove the == using256{}
construct. Something like:
if (!dirIndex.signum() && (!typeFilter.has_value() || filterAMM))
{
auto const sle = ledger.read(keylet::account(account));
if (!sle)
return false;
bool const isAMM = sle->isFieldPresent(sfAMMID);
if (filterAMM && !isAMM)
return false;
if (isAMM)
{
auto const sleAMM =
ledger.read(keylet::amm(sle->getFieldH256(sfAMMID)));
if (!sleAMM)
return false;
jvObjects.append(sleAMM->getJson(JsonOptions::none));
if (filterAMM)
return true;
if (limit == 1)
{
jvResult[jss::limit] = limit;
jvResult[jss::marker] = "AMM";
return true;
}
if (limit > 1)
--mlimit;
}
I don't think NFTs are handled as a special case in
It's true that the AMM stuff is a special case regardless. But I do think it's more confusing to have this complicated logic in I suggest an alternative approach for the situation @MaestroLegato describes: extend the |
This sounds reasonable to me. Why use |
We still have to handle |
yeah I agree |
@mDuo13 Maybe we should just add back the owner directory for AMM? Could still add enhanced |
Closing in favor of another PR, which is going to add the owner directory back in and add amm account to amm_info. |
Closed in favor of #4682 |
High Level Overview of Change
Fix
account_objects
for AMM account root to retrieve related AMM object and the trustlines.Context of Change
This is a bug, which was introduced in #4626.
Type of Change
Before / After
Prior to #4626, AMM root account and AMM object were linked via the owner directory entry, which enabled transparent integration with
account_object
command. #4626 removed the owner directory entry and addedAMMID
to the account root. This fix fetches AMM object viaAMMID
, which is AMM object key. Since there could be the truslines associated with AMM root account, thelimit
is adjusted for AMM object and themarker
set toAMM
if the limit is 1.Test Plan
AccountObjects
unit-test is extended to verify the above logic.