Skip to content

Commit

Permalink
Fix a few issues in get_object_info_execute in AuthorityAggregator (#473
Browse files Browse the repository at this point in the history
)
  • Loading branch information
lxfind authored Feb 18, 2022
1 parent ec02fe5 commit 4a2385f
Show file tree
Hide file tree
Showing 2 changed files with 57 additions and 46 deletions.
64 changes: 23 additions & 41 deletions sui_core/src/authority_aggregator.rs
Original file line number Diff line number Diff line change
Expand Up @@ -331,8 +331,13 @@ where
Ok(accumulated_state)
}

/// Return all the information in the network about a specific object, including all versions of it
/// as well as all certificates that lead to the versions and the authorities at that version.
/// Return all the information in the network regarding the latest state of a specific object.
/// For each authority queried, we obtain the latest object state along with the certificate that
/// lead up to that state. The results from each authority are aggreated for the return.
/// The first part of the return value is a map from each unique (ObjectRef, TransactionDigest)
/// pair to the content of the object as well as a list of authorities that responded this
/// pair.
/// The second part of the return value is a map from transaction digest to the cert.
async fn get_object_by_id(
&self,
object_id: ObjectID,
Expand Down Expand Up @@ -992,40 +997,21 @@ where
.map(|(name, _)| self.committee.weight(name))
.sum();

// If we have f+1 stake telling us of the latest version of the object, we just accept it.
let mut is_ok = false;
if stake >= self.committee.validity_threshold() {
if obj_option.is_none() {
return Ok(ObjectRead::Deleted(obj_ref));
} else {
// safe due to check
return Ok(ObjectRead::Exists(
obj_ref,
obj_option.unwrap(),
layout_option,
));
}
// If we have f+1 stake telling us of the latest version of the object, we just accept it.
is_ok = true;
} else if cert_map.contains_key(&tx_digest) {
// If we have less stake telling us about the latest state of an object
// we re-run the certificate on all authorities to ensure it is correct.
if let Ok(_effects) = self
.process_certificate(cert_map[&tx_digest].clone(), AUTHORITY_REQUEST_TIMEOUT)
.await
{
let mut is_ok = false;

// The mutated or created case
if _effects
.mutated
.iter()
.filter(|(oref, _)| *oref == obj_ref)
.count()
!= 0
|| _effects
.created
.iter()
.filter(|(oref, _)| *oref == obj_ref)
.count()
!= 0
.mutated_and_created()
.any(|(oref, _)| *oref == obj_ref)
{
is_ok = true;
}
Expand All @@ -1035,30 +1021,26 @@ where
&& _effects
.deleted
.iter()
.filter(|(id, seq, _)| *id == obj_ref.0 && seq.increment() == obj_ref.1)
.count()
!= 0
.any(|(id, seq, _)| *id == obj_ref.0 && seq.increment() == obj_ref.1)
{
is_ok = true;
}

if !is_ok {
// Report a byzantine fault here
// TODO: Report a byzantine fault here
continue;
}

// NOTE: here we should validate the object is correct from the effects
if obj_option.is_none() {
}
}
if is_ok {
match obj_option {
Some(obj) => {
return Ok(ObjectRead::Exists(obj_ref, obj, layout_option));
}
None => {
return Ok(ObjectRead::Deleted(obj_ref));
} else {
// safe due to check
return Ok(ObjectRead::Exists(
obj_ref,
obj_option.unwrap(),
layout_option,
));
}
}
};
}
}

Expand Down
39 changes: 34 additions & 5 deletions sui_core/src/safe_client.rs
Original file line number Diff line number Diff line change
Expand Up @@ -98,20 +98,49 @@ impl<C> SafeClient<C> {
certificate.check(&self.committee)?;
}

// Check the right version is returned
if let Some(requested_version) = &request.request_sequence_number {
if let Some(object_ref) = &response.requested_object_reference {
// Check the right object ID and version is returned
if let Some((object_id, version, _)) = &response.requested_object_reference {
fp_ensure!(
object_id == &request.object_id,
SuiError::ByzantineAuthoritySuspicion {
authority: self.address
}
);
if let Some(requested_version) = &request.request_sequence_number {
fp_ensure!(
object_ref.1 == *requested_version,
version == requested_version,
SuiError::ByzantineAuthoritySuspicion {
authority: self.address
}
);
}
}

// If an order lock is returned it is valid.
if let Some(object_and_lock) = &response.object_and_lock {
if request.request_sequence_number.is_none() {
// If request_sequence_number is none, we are requesting the latest version.
match response.requested_object_reference {
Some(obj_ref) => {
// Since we are requesting the latest version, we should validate that if the object's
// reference actually match with the one from the responded object reference.
fp_ensure!(
object_and_lock.object.to_object_reference() == obj_ref,
SuiError::ByzantineAuthoritySuspicion {
authority: self.address
}
);
}
None => {
// Since we are returning the object for the latest version,
// we must also have the requested object reference in the response.
// Otherwise the authority has inconsistent data.
return Err(SuiError::ByzantineAuthoritySuspicion {
authority: self.address,
});
}
}
}

if let Some(signed_order) = &object_and_lock.lock {
signed_order.check(&self.committee)?;
// Check it has the right signer
Expand Down

1 comment on commit 4a2385f

@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.24s
�[0m�[0m�[1m�[32m Running�[0m target/release/bench
�[2m2022-02-18T22:28:28.158351Z�[0m �[32m INFO�[0m �[2mbench�[0m�[2m:�[0m Starting benchmark: OrdersAndCerts
�[2m2022-02-18T22:28:28.158385Z�[0m �[32m INFO�[0m �[2mbench�[0m�[2m:�[0m Preparing accounts.
�[2m2022-02-18T22:28:28.159454Z�[0m �[32m INFO�[0m �[2mbench�[0m�[2m:�[0m Open database on path: "/tmp/DB_82F2661E8C968991FC7D2E33A028F58D77919710"
�[2m2022-02-18T22:28:33.357140Z�[0m �[32m INFO�[0m �[2mbench�[0m�[2m:�[0m Preparing transactions.
�[2m2022-02-18T22:28:42.023449Z�[0m �[32m INFO�[0m �[2msui_core::authority_server�[0m�[2m:�[0m Listening to TCP traffic on 127.0.0.1:9555
�[2m2022-02-18T22:28:43.025135Z�[0m �[32m INFO�[0m �[2mbench�[0m�[2m:�[0m Number of TCP connections: 2
�[2m2022-02-18T22:28:43.025163Z�[0m �[32m INFO�[0m �[2mbench�[0m�[2m:�[0m Set max_in_flight to 500
�[2m2022-02-18T22:28:43.025167Z�[0m �[32m INFO�[0m �[2mbench�[0m�[2m:�[0m Sending requests.
�[2m2022-02-18T22:28:43.033269Z�[0m �[32m INFO�[0m �[2msui_network::network�[0m�[2m:�[0m Sending TCP requests to 127.0.0.1:9555
�[2m2022-02-18T22:28:43.037858Z�[0m �[32m INFO�[0m �[2msui_network::network�[0m�[2m:�[0m Sending TCP requests to 127.0.0.1:9555
�[2m2022-02-18T22:28:44.570807Z�[0m �[32m INFO�[0m �[2msui_core::authority_server�[0m�[2m:�[0m 127.0.0.1:9555 has processed 5000 packets
�[2m2022-02-18T22:28:45.730581Z�[0m �[32m INFO�[0m �[2msui_network::network�[0m�[2m:�[0m In flight 500 Remaining 35000
�[2m2022-02-18T22:28:45.944311Z�[0m �[32m INFO�[0m �[2msui_network::network�[0m�[2m:�[0m In flight 500 Remaining 35000
�[2m2022-02-18T22:28:45.971223Z�[0m �[32m INFO�[0m �[2msui_core::authority_server�[0m�[2m:�[0m 127.0.0.1:9555 has processed 10000 packets
�[2m2022-02-18T22:28:47.470737Z�[0m �[32m INFO�[0m �[2msui_core::authority_server�[0m�[2m:�[0m 127.0.0.1:9555 has processed 15000 packets
�[2m2022-02-18T22:28:48.625881Z�[0m �[32m INFO�[0m �[2msui_network::network�[0m�[2m:�[0m In flight 500 Remaining 30000
�[2m2022-02-18T22:28:48.960049Z�[0m �[32m INFO�[0m �[2msui_core::authority_server�[0m�[2m:�[0m 127.0.0.1:9555 has processed 20000 packets
�[2m2022-02-18T22:28:49.034593Z�[0m �[32m INFO�[0m �[2msui_network::network�[0m�[2m:�[0m In flight 500 Remaining 30000
�[2m2022-02-18T22:28:50.451703Z�[0m �[32m INFO�[0m �[2msui_core::authority_server�[0m�[2m:�[0m 127.0.0.1:9555 has processed 25000 packets
�[2m2022-02-18T22:28:51.668213Z�[0m �[32m INFO�[0m �[2msui_network::network�[0m�[2m:�[0m In flight 500 Remaining 25000
�[2m2022-02-18T22:28:52.010243Z�[0m �[32m INFO�[0m �[2msui_core::authority_server�[0m�[2m:�[0m 127.0.0.1:9555 has processed 30000 packets
�[2m2022-02-18T22:28:52.192489Z�[0m �[32m INFO�[0m �[2msui_network::network�[0m�[2m:�[0m In flight 500 Remaining 25000
�[2m2022-02-18T22:28:53.507994Z�[0m �[32m INFO�[0m �[2msui_core::authority_server�[0m�[2m:�[0m 127.0.0.1:9555 has processed 35000 packets
�[2m2022-02-18T22:28:54.760836Z�[0m �[32m INFO�[0m �[2msui_network::network�[0m�[2m:�[0m In flight 500 Remaining 20000
�[2m2022-02-18T22:28:54.953076Z�[0m �[32m INFO�[0m �[2msui_network::network�[0m�[2m:�[0m In flight 500 Remaining 20000
�[2m2022-02-18T22:28:55.007777Z�[0m �[32m INFO�[0m �[2msui_core::authority_server�[0m�[2m:�[0m 127.0.0.1:9555 has processed 40000 packets
�[2m2022-02-18T22:28:56.538080Z�[0m �[32m INFO�[0m �[2msui_core::authority_server�[0m�[2m:�[0m 127.0.0.1:9555 has processed 45000 packets
�[2m2022-02-18T22:28:57.817291Z�[0m �[32m INFO�[0m �[2msui_network::network�[0m�[2m:�[0m In flight 500 Remaining 15000
�[2m2022-02-18T22:28:57.832486Z�[0m �[32m INFO�[0m �[2msui_network::network�[0m�[2m:�[0m In flight 500 Remaining 15000
�[2m2022-02-18T22:28:57.890689Z�[0m �[32m INFO�[0m �[2msui_core::authority_server�[0m�[2m:�[0m 127.0.0.1:9555 has processed 50000 packets
�[2m2022-02-18T22:28:58.797218Z�[0m �[32m INFO�[0m �[2msui_core::authority_server�[0m�[2m:�[0m 127.0.0.1:9555 has processed 55000 packets
�[2m2022-02-18T22:28:59.684564Z�[0m �[32m INFO�[0m �[2msui_network::network�[0m�[2m:�[0m In flight 500 Remaining 10000
�[2m2022-02-18T22:28:59.729364Z�[0m �[32m INFO�[0m �[2msui_network::network�[0m�[2m:�[0m In flight 500 Remaining 10000
�[2m2022-02-18T22:28:59.812897Z�[0m �[32m INFO�[0m �[2msui_core::authority_server�[0m�[2m:�[0m 127.0.0.1:9555 has processed 60000 packets
�[2m2022-02-18T22:29:00.726956Z�[0m �[32m INFO�[0m �[2msui_core::authority_server�[0m�[2m:�[0m 127.0.0.1:9555 has processed 65000 packets
�[2m2022-02-18T22:29:01.556865Z�[0m �[32m INFO�[0m �[2msui_network::network�[0m�[2m:�[0m In flight 500 Remaining 5000
�[2m2022-02-18T22:29:01.566046Z�[0m �[32m INFO�[0m �[2msui_network::network�[0m�[2m:�[0m In flight 500 Remaining 5000
�[2m2022-02-18T22:29:01.638042Z�[0m �[32m INFO�[0m �[2msui_core::authority_server�[0m�[2m:�[0m 127.0.0.1:9555 has processed 70000 packets
�[2m2022-02-18T22:29:02.559353Z�[0m �[32m INFO�[0m �[2msui_core::authority_server�[0m�[2m:�[0m 127.0.0.1:9555 has processed 75000 packets
�[2m2022-02-18T22:29:03.503133Z�[0m �[32m INFO�[0m �[2msui_core::authority_server�[0m�[2m:�[0m 127.0.0.1:9555 has processed 80000 packets
�[2m2022-02-18T22:29:03.524096Z�[0m �[32m INFO�[0m �[2msui_network::network�[0m�[2m:�[0m Done sending TCP requests to 127.0.0.1:9555
�[2m2022-02-18T22:29:03.548949Z�[0m �[32m INFO�[0m �[2msui_network::network�[0m�[2m:�[0m Done sending TCP requests to 127.0.0.1:9555
�[2m2022-02-18T22:29:03.550376Z�[0m �[32m INFO�[0m �[2mbench�[0m�[2m:�[0m Received 80000 responses.
�[2m2022-02-18T22:29:03.717290Z�[0m �[33m WARN�[0m �[2mbench�[0m�[2m:�[0m Completed benchmark for OrdersAndCerts
Total time: 20525194us, items: 40000, tx/sec: 1948.8244544728786

Please sign in to comment.