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

Remove balance from client test and added object ownership checks in test #48

Merged
merged 9 commits into from
Dec 17, 2021

Conversation

patrickkuo
Copy link
Contributor

  • Default make_client with empty objects, objects are added using fund_account later on
  • changed fund_account to populate account with objects instead of balance
  • added object ownership checks in tests

TODO:

@patrickkuo patrickkuo self-assigned this Dec 10, 2021
@patrickkuo patrickkuo marked this pull request as ready for review December 10, 2021 18:31
@patrickkuo patrickkuo linked an issue Dec 12, 2021 that may be closed by this pull request
@patrickkuo patrickkuo changed the title Removed balance from client test and added object ownership checks in test Remove balance from client test and added object ownership checks in test Dec 12, 2021
Copy link
Collaborator

@gdanezis gdanezis left a comment

Choose a reason for hiding this comment

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

Nice one, and particularly on the tests which were a mess. See my comment on whether you want to return the latest seq number of a given object that is supported by at least some honest node, which I think the client might need for various sync / confirmations.

/// NOTE: This is only reliable in the synchronous model, with a sufficient timeout value.
#[cfg(test)]
async fn get_strong_majority_balance(&mut self, object_id: ObjectID) -> Balance {
async fn object_ownership_have_quorum(&mut self, object_id: ObjectID) -> bool {
Copy link
Collaborator

Choose a reason for hiding this comment

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

I wonder: is it useful here to return the highest sequence number for which we have a quorum instead of just true/false?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Good call! this will be much more useful then bool

Ok(_info) => Some((*name, Balance::from(0))),
_ => None,
Ok(info) => {
if info.owner == address {
Copy link
Collaborator

Choose a reason for hiding this comment

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

I think this test is a skeleton from when we had address as the index. Should it now be something like "info.object_id == object_id". And if you want to keep track of sequence numbers you can store Some(info.seq) to analyze later.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

info.object_id == object_id will always be true in this case, because the object id is use in the Request and the Response should return data for the same object_id.

This check is for checking if the info requester is the owner of the object

Copy link
Collaborator

Choose a reason for hiding this comment

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

Why does it matter if the info requester is the owner of the object?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

this method is for testing the object have the right ownership after transfer

@patrickkuo patrickkuo force-pushed the pat/client_test_refactoring branch from b10ec4f to 20e28f7 Compare December 14, 2021 10:09
fastpay_core/src/client.rs Outdated Show resolved Hide resolved
fastpay_core/src/client.rs Outdated Show resolved Hide resolved
fastpay_core/src/client.rs Outdated Show resolved Hide resolved
/// NOTE: This is only reliable in the synchronous model, with a sufficient timeout value.
#[cfg(test)]
async fn get_strong_majority_balance(&mut self, object_id: ObjectID) -> Balance {
async fn get_strong_majority_owner(
Copy link
Collaborator

Choose a reason for hiding this comment

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

Nit: doc comment needs updating to reflect new return value

.try_lock()
.unwrap()
.init_order_lock((object_id, 0.into()));
let object_ids: Vec<ObjectID> = object_ids.next().unwrap_or(Vec::new());
Copy link
Contributor

Choose a reason for hiding this comment

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

have you considered writing this by doing something like for (client, object_ids) in clients.zip(object_ids)?

let _balances = balances.into_iter().map(Balance::from);
for (_, client) in clients.iter_mut() {
let mut object_ids = object_ids.into_iter();
for client in clients.clone() {
let addr = address;
Copy link
Contributor

Choose a reason for hiding this comment

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

Is this alias meaningful?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

nope, will remove it

let numbers: futures::stream::FuturesUnordered<_> = self
.authority_clients
let mut authority_clients = self.authority_clients.clone();
let numbers: futures::stream::FuturesUnordered<_> = authority_clients
.iter_mut()
.map(|(name, client)| {
let fut = client.handle_account_info_request(request.clone());
Copy link
Contributor

Choose a reason for hiding this comment

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

It's fishy that handle_account_info_request requires a mutable client, and I'd love a bit of insight as to why.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

this is originated from send_recv_bytes_internal in network, which required &mut self unnecessarily, I have changed it to &self in my next check in

@patrickkuo patrickkuo merged commit cbb6c89 into main Dec 17, 2021
@patrickkuo patrickkuo deleted the pat/client_test_refactoring branch January 12, 2022 11:48
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.

[fastx distsys] Refactor Client code
4 participants