Skip to content

Commit

Permalink
types: remove unused serialize types and methods
Browse files Browse the repository at this point in the history
  • Loading branch information
bmwill authored and longbowlu committed May 12, 2022
1 parent 3b2d461 commit fc26ec8
Show file tree
Hide file tree
Showing 10 changed files with 39 additions and 902 deletions.
15 changes: 7 additions & 8 deletions sui_core/src/authority.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,15 +16,15 @@ use move_core_types::{
};
use move_vm_runtime::{move_vm::MoveVM, native_functions::NativeFunctionTable};
use narwhal_executor::{ExecutionIndices, ExecutionState};
use std::sync::atomic::AtomicUsize;
use std::sync::atomic::Ordering;
use std::{
collections::{BTreeMap, HashMap, HashSet, VecDeque},
pin::Pin,
sync::Arc,
sync::{
atomic::{AtomicUsize, Ordering},
Arc,
},
};
use sui_adapter::adapter;
use sui_types::serialize::serialize_transaction_info;
use sui_types::{
base_types::*,
batch::{TxSequenceNumber, UpdateItem},
Expand All @@ -38,8 +38,7 @@ use sui_types::{
storage::{BackingPackageStore, DeleteKind, Storage},
MOVE_STDLIB_ADDRESS, SUI_FRAMEWORK_ADDRESS,
};
use tracing::log;
use tracing::{debug, instrument};
use tracing::{debug, instrument, log};

#[cfg(test)]
#[path = "unit_tests/authority_tests.rs"]
Expand Down Expand Up @@ -871,7 +870,7 @@ impl ExecutionState for AuthorityState {
if self._database.effects_exists(digest)? {
let info = self.make_transaction_info(digest).await?;
debug!("Shared-object transaction {digest:?} already executed");
return Ok(serialize_transaction_info(&info));
return Ok(bincode::serialize(&info).unwrap());
}

// Assign locks to shared objects.
Expand All @@ -890,7 +889,7 @@ impl ExecutionState for AuthorityState {
debug!("Executed transaction {digest:?}");

// Return a serialized transaction info response. This will be sent back to the client.
Ok(serialize_transaction_info(&info))
Ok(bincode::serialize(&info).unwrap())
}

fn ask_consensus_write_lock(&self) -> bool {
Expand Down
6 changes: 1 addition & 5 deletions sui_core/src/authority_server.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ use sui_network::{
network::NetworkServer,
tonic,
};
use sui_types::{crypto::VerificationObligation, error::*, messages::*, serialize::*};
use sui_types::{crypto::VerificationObligation, error::*, messages::*};
use tokio::{net::TcpListener, sync::mpsc::Sender};
use tracing::{info, Instrument};

Expand Down Expand Up @@ -242,10 +242,6 @@ impl Validator for AuthorityServer {
.await
.map_err(|e| tonic::Status::internal(e.to_string()))?;

// For some reason the output of consensus changed, we should change it back
let info = deserialize_message(&info[..]).unwrap();
let info = deserialize_transaction_info(info).unwrap();

let payload = BincodeEncodedPayload::try_from(&info)
.map_err(|e| tonic::Status::internal(e.to_string()))?;

Expand Down
12 changes: 8 additions & 4 deletions sui_core/src/consensus_adapter.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ use std::{
use sui_types::{
committee::Committee,
error::{SuiError, SuiResult},
messages::ConsensusTransaction,
messages::{ConsensusTransaction, TransactionInfoResponse},
};
use tokio::{
net::TcpStream,
Expand Down Expand Up @@ -118,7 +118,7 @@ impl ConsensusAdapter {
pub async fn submit(
&self,
certificate: &ConsensusTransaction,
) -> SuiResult<SerializedTransactionInfoResponse> {
) -> SuiResult<TransactionInfoResponse> {
// Check the Sui certificate (submitted by the user).
certificate.check(&self.committee)?;

Expand Down Expand Up @@ -151,7 +151,7 @@ impl ConsensusAdapter {
// certificate will be sequenced. So the best we can do is to set a timer and notify the
// client to retry if we timeout without hearing back from consensus (this module does not
// handle retries). The best timeout value depends on the consensus protocol.
match timeout(self.max_delay, receiver).await {
let resp = match timeout(self.max_delay, receiver).await {
Ok(reply) => reply.expect("Failed to read back from consensus listener"),
Err(e) => {
let message = ConsensusListenerMessage::Cleanup(serialized);
Expand All @@ -161,7 +161,11 @@ impl ConsensusAdapter {
.expect("Cleanup channel with consensus listener dropped");
Err(SuiError::ConsensusConnectionBroken(e.to_string()))
}
}
};

resp.and_then(|r| {
bincode::deserialize(&r).map_err(|e| SuiError::ConsensusConnectionBroken(e.to_string()))
})
}
}

Expand Down
20 changes: 7 additions & 13 deletions sui_core/src/consensus_handler.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,11 @@
use crate::authority_server::AuthorityServer;
use bytes::Bytes;
use std::sync::Arc;
use sui_types::error::{SuiError, SuiResult};
use sui_types::messages::ConfirmationTransaction;
use sui_types::serialize::{deserialize_message, SerializedMessage};
use tokio::sync::broadcast::Receiver;
use tokio::task::JoinHandle;
use sui_types::{
error::{SuiError, SuiResult},
messages::ConfirmationTransaction,
};
use tokio::{sync::broadcast::Receiver, task::JoinHandle};

/// The `ConsensusHandler` receives certificates sequenced by the consensus and updates
/// the authority's database
Expand Down Expand Up @@ -41,14 +41,8 @@ impl ConsensusHandler {
// The consensus simply orders bytes, so we first need to deserialize the
// certificate. If the deserialization fail it is safe to ignore the
// certificate since all correct authorities will do the same.
let confirmation = match deserialize_message(&*bytes) {
Ok(SerializedMessage::Cert(certificate)) => ConfirmationTransaction {
certificate: *certificate,
},
Ok(_) => {
log::debug!("{}", SuiError::UnexpectedMessage);
continue;
}
let confirmation = match bincode::deserialize::<CertifiedTransaction>(bytes) {
Ok(certificate) => ConfirmationTransaction { certificate },
Err(e) => {
log::debug!("Failed to deserialize certificate {e}");
continue;
Expand Down
3 changes: 0 additions & 3 deletions sui_core/src/generate_format.rs
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@ use sui_types::{
CallArg, ExecutionStatus, ObjectInfoRequestKind, SingleTransactionKind, TransactionKind,
},
object::{Data, Owner},
serialize,
};
use typed_store::rocks::TypedStoreError;

Expand Down Expand Up @@ -71,8 +70,6 @@ fn get_registry() -> Result<Registry> {
tracer.trace_type::<base_types::SuiAddress>(&samples)?;
tracer.trace_type::<UpdateItem>(&samples)?;

// The final and main entry point that we must document
tracer.trace_type::<serialize::SerializedMessage>(&samples)?;
tracer.registry()
}

Expand Down
33 changes: 16 additions & 17 deletions sui_core/src/unit_tests/consensus_tests.rs
Original file line number Diff line number Diff line change
@@ -1,25 +1,24 @@
// Copyright (c) 2022, Mysten Labs, Inc.
// SPDX-License-Identifier: Apache-2.0
use super::*;
use crate::authority::authority_tests::get_genesis_package_by_module;
use crate::authority::authority_tests::init_state_with_objects;
use crate::authority::AuthorityState;
use move_core_types::account_address::AccountAddress;
use move_core_types::ident_str;
use crate::authority::{
authority_tests::{get_genesis_package_by_module, init_state_with_objects},
AuthorityState,
};
use move_core_types::{account_address::AccountAddress, ident_str};
use narwhal_executor::ExecutionIndices;
use sui_adapter::genesis;
use sui_types::base_types::{ObjectID, TransactionDigest};
use sui_types::crypto::Signature;
use sui_types::gas_coin::GasCoin;
use sui_types::messages::ConfirmationTransaction;
use sui_types::messages::{
CallArg, CertifiedTransaction, SignatureAggregator, Transaction, TransactionData,
use sui_types::{
base_types::{ObjectID, TransactionDigest},
crypto::Signature,
gas_coin::GasCoin,
messages::{
CallArg, CertifiedTransaction, ConfirmationTransaction, SignatureAggregator, Transaction,
TransactionData,
},
object::{MoveObject, Object, Owner, OBJECT_START_VERSION},
};
use sui_types::object::OBJECT_START_VERSION;
use sui_types::object::{MoveObject, Object, Owner};
use sui_types::serialize::serialize_transaction_info;
use test_utils::network::test_listener;
use test_utils::test_keys;
use test_utils::{network::test_listener, test_keys};
use tokio::sync::mpsc::channel;

/// Default network buffer size.
Expand Down Expand Up @@ -182,7 +181,7 @@ async fn submit_transaction_to_consensus() {
let result = state
.handle_confirmation_transaction(confirmation_transaction)
.await
.map(|info| serialize_transaction_info(&info));
.map(|info| bincode::serialize(&info).unwrap());

// Reply to the submitter.
replier.send(result).unwrap();
Expand Down
Loading

0 comments on commit fc26ec8

Please sign in to comment.