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
18 changes: 13 additions & 5 deletions fastpay_core/src/client.rs
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,6 @@ pub trait Client {
/// Do not confirm the transaction.
fn transfer_to_fastpay_unsafe_unconfirmed(
&mut self,
amount: Amount,
recipient: FastPayAddress,
object_id: ObjectID,
user_data: UserData,
Expand Down Expand Up @@ -277,23 +276,33 @@ where
)
}

/// Find the highest balance that is backed by a quorum of authorities.
/// Return true if the ownership of the object is backed by a quorum of authorities.
patrickkuo marked this conversation as resolved.
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 object_ownership_have_quorum(
&mut self,
patrickkuo marked this conversation as resolved.
Show resolved Hide resolved
object_id: ObjectID,
) -> Option<SequenceNumber> {
patrickkuo marked this conversation as resolved.
Show resolved Hide resolved
let request = AccountInfoRequest {
object_id,
request_sequence_number: None,
request_received_transfers_excluding_first_nth: None,
};
let address = self.address;
let numbers: futures::stream::FuturesUnordered<_> = self
.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

async move {
match fut.await {
Ok(_info) => Some((*name, Balance::from(0))),
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

Some((*name, Some(info.next_sequence_number)))
} else {
None
}
}
_ => None,
}
}
Expand Down Expand Up @@ -686,7 +695,6 @@ where

fn transfer_to_fastpay_unsafe_unconfirmed(
&mut self,
_amount: Amount,
recipient: FastPayAddress,
object_id: ObjectID,
user_data: UserData,
Expand Down
Loading