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

Allow account_objects RPC to filter by "check" (RIPD-1589) #2356

Closed
wants to merge 3 commits into from

Conversation

scottschurr
Copy link
Collaborator

@mDuo13 found a bug in the Checks implementation (Thanks!). This fixes that particular bug. Also adds some more unit tests for account_objects.

@ripplelabs-jenkins
Copy link
Collaborator

ripplelabs-jenkins commented Jan 25, 2018

Jenkins Build Summary

Built from this commit

Built at 20180203 - 00:52:48

Test Results

Build Type Result Status
clang.debug.unity 986 cases, 0 failed, t: 443s PASS ✅
coverage 986 cases, 0 failed, t: 573s PASS ✅
clang.debug.nounity 984 cases, 0 failed, t: 353s PASS ✅
gcc.debug.unity 986 cases, 0 failed, t: 396s PASS ✅
gcc.debug.nounity 984 cases, 0 failed, t: 276s PASS ✅
clang.release.unity 985 cases, 0 failed, t: 470s PASS ✅
gcc.release.unity 985 cases, 0 failed, t: 510s PASS ✅

@mDuo13
Copy link
Collaborator

mDuo13 commented Jan 26, 2018

(For tracking purposes, this fixes #2350)


// Verify that the non-returning types still don't return anything.
// Note that, interestingly, they now return a null object rather
// than an empty array. Not sure what triggers that...
Copy link
Collaborator

Choose a reason for hiding this comment

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

This null object thing might be worth looking into

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Agreed. Surprised me a bit too (which is why I called it out). But I have other stuff I need to chase down before I look into this one. My inclination would be to change it so it always return an empty array. But there might be a downside for users who expect a null object to be returned in this case. I'll let you think about that. If we (conservatively) decide not to change the behavior then it's not really worth investigating...

[&env, &acct_objs] (Account const& acct, char const* type)
{
Json::Value const resp = acct_objs (acct, type);
return resp["result"]["account_objects"].isNull();
Copy link
Contributor

Choose a reason for hiding this comment

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

What is the rest of the response? status? Is there an error?

// Verify that the non-returning types still don't return anything.
// Note that, interestingly, they now return a null object rather
// than an empty array. Not sure what triggers that...
BEAST_EXPECT (acct_objs_is_null (gw, jss::account));
Copy link
Contributor

Choose a reason for hiding this comment

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

These are essentially jibberish, unrecognized types ?

Copy link
Contributor

Choose a reason for hiding this comment

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

Nevermind, I see. I thought amendments and hashes was non sensical in the context of account_objects. So non-returning types means there was just no results?

Copy link
Contributor

Choose a reason for hiding this comment

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

I guess it's this line here:
https://github.com/ripple/rippled/blob/develop/src/ripple/rpc/impl/RPCHelpers.cpp#L100

It is probably the weird json library, which creates a null node, until you run append on it.

This is probably the "fix":

 auto& jvObjects = jvResult[jss::account_objects] = Json::Value(Json::objectValue);

@bachase bachase self-requested a review January 29, 2018 18:15
@bachase bachase self-assigned this Jan 29, 2018
Copy link
Collaborator

@bachase bachase left a comment

Choose a reason for hiding this comment

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

Looks good.

I recommend making the change @sublimator suggested; you can cherry-pick bachase@8cff40e.

@scottschurr
Copy link
Collaborator Author

Thanks @bachase. Your [FOLD] is incorporated.


bool const isArray = resp["result"]["account_objects"].isArray();
return isArray && (resp["result"]["account_objects"].size() == 0);
};
Copy link
Contributor

@miguelportilla miguelportilla Feb 1, 2018

Choose a reason for hiding this comment

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

Suggestion: If the lambda takes a size param, it can be called from other instances in the test.

        auto acct_objs_is_size =
            [&env, &acct_objs](Account const& acct, char const* type, unsigned size)
        {
            Json::Value const resp = acct_objs(acct, type);

            return resp[jss::result][jss::account_objects].isArray() &&
                resp[jss::result][jss::account_objects].size() == size;
        };

These instances

            BEAST_EXPECT (resp["result"]["account_objects"].isArray());
            BEAST_EXPECT (resp["result"]["account_objects"].size() == 1);

Can become

          BEAST_EXPECT (acct_objs_is_size(gw, jss::state, 1));

Copy link
Collaborator

@intelliot intelliot left a comment

Choose a reason for hiding this comment

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

Most of this is over my head, but I didn't spot any problems.

@@ -316,10 +316,215 @@ class AccountObjects_test : public beast::unit_test::suite
}
}

void testObjectTypes()
{
testcase ("object types");
Copy link
Collaborator

Choose a reason for hiding this comment

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

Looks like (elsewhere in the file) there usually isn't a space between testcase and (?

i.e.

testcase("object types");

{ {
{ jss::account, ltACCOUNT_ROOT },
{ jss::amendments, ltAMENDMENTS },
{ jss::check, ltCHECK },
Copy link
Collaborator

Choose a reason for hiding this comment

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

This is just adding 1 new type (check) and reordering a few others?

auto const& escrow = resp["result"]["account_objects"][0u];
BEAST_EXPECT (escrow["Account"] == gw.human());
BEAST_EXPECT (escrow["Destination"] == gw.human());
BEAST_EXPECT (escrow["Amount"].asInt() == 100'000'000);
Copy link
Contributor

@miguelportilla miguelportilla Feb 1, 2018

Choose a reason for hiding this comment

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

Consider asUInt()?

// Find the trustline and make sure it's the right one.
Json::Value const resp = acct_objs (gw, jss::state);

BEAST_EXPECT (resp["result"]["account_objects"].isArray());
Copy link
Contributor

@miguelportilla miguelportilla Feb 1, 2018

Choose a reason for hiding this comment

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

Consider using defined json fields instead.
eg. resp[jss::result][jss::account_objects]

}
// Run up the number of directory entries so gw has two
// directory nodes.
for (int d = 1'000'032; d >= 1'000'000; d -= 1)
Copy link
Contributor

Choose a reason for hiding this comment

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

Nit: --d

Copy link
Contributor

@miguelportilla miguelportilla left a comment

Choose a reason for hiding this comment

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

Left a few suggestions but not holding back. Excellent work @scottschurr 👍

@scottschurr scottschurr force-pushed the account-objects-checks branch from f1ed64c to e8396a2 Compare February 2, 2018 00:51
@scottschurr
Copy link
Collaborator Author

Thanks for the review, @miguelportilla and @intelliot. Great suggestions. I believe the most recent commit (e8396a2) addresses your comments. If you're good with it I'll mark the pull request passed. Thanks.

@scottschurr scottschurr added the Passed Passed code review & PR owner thinks it's ready to merge. Perf sign-off may still be required. label Feb 2, 2018
@ximinez
Copy link
Collaborator

ximinez commented Feb 2, 2018

(For tracking purposes, this fixes #2350)

If this fixes an issue, you should update the commit message to reflect that. Just include the string "fixes #2350" anywhere in the message, and the issue will get automatically closed when the PR is merged.

@scottschurr scottschurr force-pushed the account-objects-checks branch from e8396a2 to ff81627 Compare February 2, 2018 23:55
@scottschurr
Copy link
Collaborator Author

@ximinez: Here I got trained on how to handle RIPD comments and now you want me to adapt to GitHub issues too. 😉 Commit message updated.

@ximinez
Copy link
Collaborator

ximinez commented Feb 3, 2018

It never ends!

Copy link
Collaborator

@ximinez ximinez left a comment

Choose a reason for hiding this comment

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

👍

BEAST_EXPECT (acct_objs_is_size (acct_objs (gw, jss::amendments), 0));
BEAST_EXPECT (acct_objs_is_size (acct_objs (gw, jss::directory), 0));
BEAST_EXPECT (acct_objs_is_size (acct_objs (gw, jss::fee), 0));
BEAST_EXPECT (acct_objs_is_size (acct_objs (gw, jss::hashes), 0));
Copy link
Collaborator

Choose a reason for hiding this comment

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

These tests are great. I'm was going to suggest you do one more unfiltered, but it looks like testUnsteppedThenStepped has that covered.

@bachase bachase mentioned this pull request Feb 3, 2018
@bachase
Copy link
Collaborator

bachase commented Feb 5, 2018

Merged in 88570df

@bachase bachase closed this Feb 5, 2018
@scottschurr scottschurr deleted the account-objects-checks branch February 17, 2018 00:39
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Passed Passed code review & PR owner thinks it's ready to merge. Perf sign-off may still be required.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

8 participants