Skip to content

Commit

Permalink
Remove balance from client test and added object ownership checks in …
Browse files Browse the repository at this point in the history
…test (#48)

* fund account using objects instead of amount

* refactored get_strong_majority_balance to object_ownership_have_quorum to confirm the client have ownership of an object in test

Co-authored-by: François Garillot <[email protected]>
  • Loading branch information
patrickkuo and huitseeker authored Dec 17, 2021
1 parent 41afeea commit cbb6c89
Show file tree
Hide file tree
Showing 4 changed files with 186 additions and 118 deletions.
2 changes: 1 addition & 1 deletion fastpay/src/bench.rs
Original file line number Diff line number Diff line change
Expand Up @@ -215,7 +215,7 @@ impl ClientServerBenchmark {
info!("Received {} responses.", responses.len(),);
} else {
// Use actual client core
let mut client = network::Client::new(
let client = network::Client::new(
self.protocol,
self.host.clone(),
self.port,
Expand Down
6 changes: 3 additions & 3 deletions fastpay/src/network.rs
Original file line number Diff line number Diff line change
Expand Up @@ -172,7 +172,7 @@ impl Client {
}

async fn send_recv_bytes_internal(
&mut self,
&self,
shard: ShardId,
buf: Vec<u8>,
) -> Result<Vec<u8>, io::Error> {
Expand All @@ -188,7 +188,7 @@ impl Client {
}

pub async fn send_recv_bytes(
&mut self,
&self,
shard: ShardId,
buf: Vec<u8>,
) -> Result<AccountInfoResponse, FastPayError> {
Expand Down Expand Up @@ -233,7 +233,7 @@ impl AuthorityClient for Client {

/// Handle information requests for this account.
fn handle_account_info_request(
&mut self,
&self,
request: AccountInfoRequest,
) -> AsyncResult<'_, AccountInfoResponse, FastPayError> {
Box::pin(async move {
Expand Down
25 changes: 13 additions & 12 deletions fastpay_core/src/client.rs
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ pub trait AuthorityClient {

/// Handle information requests for this account.
fn handle_account_info_request(
&mut self,
&self,
request: AccountInfoRequest,
) -> AsyncResult<'_, AccountInfoResponse, FastPayError>;
}
Expand Down 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 @@ -253,14 +252,14 @@ where
/// Find the highest sequence number that is known to a quorum of authorities.
/// NOTE: This is only reliable in the synchronous model, with a sufficient timeout value.
#[cfg(test)]
async fn get_strong_majority_sequence_number(&mut self, object_id: ObjectID) -> SequenceNumber {
async fn get_strong_majority_sequence_number(&self, object_id: ObjectID) -> SequenceNumber {
let request = AccountInfoRequest {
object_id,
request_sequence_number: None,
request_received_transfers_excluding_first_nth: None,
};
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());
Expand All @@ -277,23 +276,26 @@ where
)
}

/// Find the highest balance that is backed by a quorum of authorities.
/// Return owner address and sequence number of an object backed by a quorum of authorities.
/// 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(
&self,
object_id: ObjectID,
) -> Option<(FastPayAddress, SequenceNumber)> {
let request = AccountInfoRequest {
object_id,
request_sequence_number: None,
request_received_transfers_excluding_first_nth: None,
};
let numbers: futures::stream::FuturesUnordered<_> = self
.authority_clients
.iter_mut()
let authority_clients = self.authority_clients.clone();
let numbers: futures::stream::FuturesUnordered<_> = authority_clients
.iter()
.map(|(name, client)| {
let fut = client.handle_account_info_request(request.clone());
async move {
match fut.await {
Ok(_info) => Some((*name, Balance::from(0))),
Ok(info) => Some((*name, Some((info.owner, info.next_sequence_number)))),
_ => None,
}
}
Expand Down Expand Up @@ -686,7 +688,6 @@ where

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

1 comment on commit cbb6c89

@github-actions
Copy link
Contributor

Choose a reason for hiding this comment

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

Bench results

�[0m�[0m�[1m�[32m Finished�[0m release [optimized + debuginfo] target(s) in 1.27s
�[0m�[0m�[1m�[32m Running�[0m target/release/bench
[2021-12-17T10:57:19Z INFO bench] Preparing accounts.
[2021-12-17T10:57:21Z INFO bench] Preparing transactions.
[2021-12-17T10:57:30Z INFO fastpay::network] Listening to Udp traffic on 127.0.0.1:9569
[2021-12-17T10:57:30Z INFO fastpay::network] Listening to Udp traffic on 127.0.0.1:9559
[2021-12-17T10:57:30Z INFO fastpay::network] Listening to Udp traffic on 127.0.0.1:9558
[2021-12-17T10:57:30Z INFO fastpay::network] Listening to Udp traffic on 127.0.0.1:9557
[2021-12-17T10:57:30Z INFO fastpay::network] Listening to Udp traffic on 127.0.0.1:9555
[2021-12-17T10:57:30Z INFO fastpay::network] Listening to Udp traffic on 127.0.0.1:9560
[2021-12-17T10:57:30Z INFO fastpay::network] Listening to Udp traffic on 127.0.0.1:9561
[2021-12-17T10:57:30Z INFO fastpay::network] Listening to Udp traffic on 127.0.0.1:9562
[2021-12-17T10:57:30Z INFO fastpay::network] Listening to Udp traffic on 127.0.0.1:9563
[2021-12-17T10:57:30Z INFO fastpay::network] Listening to Udp traffic on 127.0.0.1:9556
[2021-12-17T10:57:30Z INFO fastpay::network] Listening to Udp traffic on 127.0.0.1:9568
[2021-12-17T10:57:30Z INFO fastpay::network] Listening to Udp traffic on 127.0.0.1:9564
[2021-12-17T10:57:30Z INFO fastpay::network] Listening to Udp traffic on 127.0.0.1:9566
[2021-12-17T10:57:30Z INFO fastpay::network] Listening to Udp traffic on 127.0.0.1:9567
[2021-12-17T10:57:30Z INFO fastpay::network] Listening to Udp traffic on 127.0.0.1:9565
[2021-12-17T10:57:31Z INFO bench] Set max_in_flight per shard to 66
[2021-12-17T10:57:31Z INFO bench] Sending requests.
[2021-12-17T10:57:31Z INFO fastpay::network] Sending Udp requests to 127.0.0.1:9568 (shard 13)
[2021-12-17T10:57:31Z INFO fastpay::network] Sending Udp requests to 127.0.0.1:9555 (shard 0)
[2021-12-17T10:57:31Z INFO fastpay::network] Sending Udp requests to 127.0.0.1:9565 (shard 10)
[2021-12-17T10:57:31Z INFO fastpay::network] Sending Udp requests to 127.0.0.1:9556 (shard 1)
[2021-12-17T10:57:31Z INFO fastpay::network] Sending Udp requests to 127.0.0.1:9564 (shard 9)
[2021-12-17T10:57:31Z INFO fastpay::network] Sending Udp requests to 127.0.0.1:9557 (shard 2)
[2021-12-17T10:57:31Z INFO fastpay::network] Sending Udp requests to 127.0.0.1:9561 (shard 6)
[2021-12-17T10:57:31Z INFO fastpay::network] Sending Udp requests to 127.0.0.1:9567 (shard 12)
[2021-12-17T10:57:31Z INFO fastpay::network] Sending Udp requests to 127.0.0.1:9560 (shard 5)
[2021-12-17T10:57:31Z INFO fastpay::network] Sending Udp requests to 127.0.0.1:9566 (shard 11)
[2021-12-17T10:57:31Z INFO fastpay::network] Sending Udp requests to 127.0.0.1:9569 (shard 14)
[2021-12-17T10:57:31Z INFO fastpay::network] Sending Udp requests to 127.0.0.1:9558 (shard 3)
[2021-12-17T10:57:31Z INFO fastpay::network] Sending Udp requests to 127.0.0.1:9562 (shard 7)
[2021-12-17T10:57:31Z INFO fastpay::network] Sending Udp requests to 127.0.0.1:9563 (shard 8)
[2021-12-17T10:57:31Z INFO fastpay::network] Sending Udp requests to 127.0.0.1:9559 (shard 4)
[2021-12-17T10:57:32Z INFO fastpay::network] In flight 66 Remaining 5000
[2021-12-17T10:57:43Z INFO fastpay::network] 127.0.0.1:9555 (shard 0) has processed 5000 packets
[2021-12-17T10:57:43Z INFO fastpay::network] 127.0.0.1:9557 (shard 2) has processed 5000 packets
[2021-12-17T10:57:43Z INFO fastpay::network] 127.0.0.1:9559 (shard 4) has processed 5000 packets
[2021-12-17T10:57:43Z INFO fastpay::network] 127.0.0.1:9556 (shard 1) has processed 5000 packets
[2021-12-17T10:57:43Z INFO fastpay::network] 127.0.0.1:9564 (shard 9) has processed 5000 packets
[2021-12-17T10:57:43Z INFO fastpay::network] 127.0.0.1:9568 (shard 13) has processed 5000 packets
[2021-12-17T10:57:43Z INFO fastpay::network] 127.0.0.1:9563 (shard 8) has processed 5000 packets
[2021-12-17T10:57:43Z INFO fastpay::network] Done sending Udp requests to 127.0.0.1:9555 (shard 0)
[2021-12-17T10:57:43Z INFO fastpay::network] 127.0.0.1:9558 (shard 3) has processed 5000 packets
[2021-12-17T10:57:43Z INFO fastpay::network] 127.0.0.1:9562 (shard 7) has processed 5000 packets
[2021-12-17T10:57:43Z INFO fastpay::network] 127.0.0.1:9569 (shard 14) has processed 5000 packets
[2021-12-17T10:57:43Z INFO fastpay::network] 127.0.0.1:9567 (shard 12) has processed 5000 packets
[2021-12-17T10:57:43Z INFO fastpay::network] Done sending Udp requests to 127.0.0.1:9559 (shard 4)
[2021-12-17T10:57:43Z INFO fastpay::network] Done sending Udp requests to 127.0.0.1:9568 (shard 13)
[2021-12-17T10:57:43Z INFO fastpay::network] 127.0.0.1:9566 (shard 11) has processed 5000 packets
[2021-12-17T10:57:43Z INFO fastpay::network] 127.0.0.1:9561 (shard 6) has processed 5000 packets
[2021-12-17T10:57:43Z INFO fastpay::network] 127.0.0.1:9565 (shard 10) has processed 5000 packets
[2021-12-17T10:57:43Z INFO fastpay::network] Done sending Udp requests to 127.0.0.1:9567 (shard 12)
[2021-12-17T10:57:43Z INFO fastpay::network] 127.0.0.1:9560 (shard 5) has processed 5000 packets
[2021-12-17T10:57:44Z INFO fastpay::network] Done sending Udp requests to 127.0.0.1:9557 (shard 2)
[2021-12-17T10:57:44Z INFO fastpay::network] Done sending Udp requests to 127.0.0.1:9562 (shard 7)
[2021-12-17T10:57:44Z INFO fastpay::network] Done sending Udp requests to 127.0.0.1:9564 (shard 9)
[2021-12-17T10:57:44Z INFO fastpay::network] Done sending Udp requests to 127.0.0.1:9556 (shard 1)
[2021-12-17T10:57:44Z INFO fastpay::network] Done sending Udp requests to 127.0.0.1:9563 (shard 8)
[2021-12-17T10:57:44Z INFO fastpay::network] Done sending Udp requests to 127.0.0.1:9565 (shard 10)
[2021-12-17T10:57:44Z INFO fastpay::network] Done sending Udp requests to 127.0.0.1:9569 (shard 14)
[2021-12-17T10:57:44Z INFO fastpay::network] Done sending Udp requests to 127.0.0.1:9566 (shard 11)
[2021-12-17T10:57:44Z INFO fastpay::network] Done sending Udp requests to 127.0.0.1:9558 (shard 3)
[2021-12-17T10:57:44Z INFO fastpay::network] Done sending Udp requests to 127.0.0.1:9560 (shard 5)
[2021-12-17T10:57:44Z INFO fastpay::network] Done sending Udp requests to 127.0.0.1:9561 (shard 6)
[2021-12-17T10:57:44Z INFO bench] Received 80000 responses.
[2021-12-17T10:57:44Z WARN bench] Total time: 12404561ms, items: 40000, tx/sec: 3224.6203634292256

Please sign in to comment.