Skip to content

Commit

Permalink
Remove diem_types::protocol_spec
Browse files Browse the repository at this point in the history
With a new genesis in mind, we are taking the easy route of giving up binary compatibility.
  • Loading branch information
msmouse authored and bors-libra committed Dec 11, 2021
1 parent 39450ea commit 2aee399
Show file tree
Hide file tree
Showing 109 changed files with 388 additions and 673 deletions.
26 changes: 10 additions & 16 deletions api/src/context.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,15 +6,9 @@ use diem_config::config::{ApiConfig, JsonRpcConfig, RoleType};
use diem_crypto::HashValue;
use diem_mempool::{MempoolClientRequest, MempoolClientSender, SubmissionStatus};
use diem_types::{
account_address::AccountAddress,
account_state::AccountState,
account_state_blob::AccountStateBlob,
chain_id::ChainId,
contract_event::ContractEvent,
event::EventKey,
ledger_info::LedgerInfoWithSignatures,
protocol_spec::DpnProto,
transaction::{SignedTransaction, TransactionInfo},
account_address::AccountAddress, account_state::AccountState,
account_state_blob::AccountStateBlob, chain_id::ChainId, contract_event::ContractEvent,
event::EventKey, ledger_info::LedgerInfoWithSignatures, transaction::SignedTransaction,
};
use storage_interface::{MoveDbReader, Order};

Expand All @@ -31,7 +25,7 @@ use warp::{filters::BoxedFilter, Filter, Reply};
#[derive(Clone)]
pub struct Context {
chain_id: ChainId,
db: Arc<dyn MoveDbReader<DpnProto>>,
db: Arc<dyn MoveDbReader>,
mp_sender: MempoolClientSender,
role: RoleType,
jsonrpc_config: JsonRpcConfig,
Expand All @@ -41,7 +35,7 @@ pub struct Context {
impl Context {
pub fn new(
chain_id: ChainId,
db: Arc<dyn MoveDbReader<DpnProto>>,
db: Arc<dyn MoveDbReader>,
mp_sender: MempoolClientSender,
role: RoleType,
jsonrpc_config: JsonRpcConfig,
Expand All @@ -57,7 +51,7 @@ impl Context {
}
}

pub fn move_converter(&self) -> MoveConverter<dyn MoveDbReader<DpnProto> + '_> {
pub fn move_converter(&self) -> MoveConverter<dyn MoveDbReader + '_> {
MoveConverter::new(self.db.borrow())
}

Expand Down Expand Up @@ -126,7 +120,7 @@ impl Context {
start_version: u64,
limit: u16,
ledger_version: u64,
) -> Result<Vec<TransactionOnChainData<TransactionInfo>>> {
) -> Result<Vec<TransactionOnChainData>> {
let data = self
.db
.get_transactions(start_version, limit as u64, ledger_version, true)?;
Expand Down Expand Up @@ -167,7 +161,7 @@ impl Context {
start_seq_number: u64,
limit: u16,
ledger_version: u64,
) -> Result<Vec<TransactionOnChainData<TransactionInfo>>> {
) -> Result<Vec<TransactionOnChainData>> {
let txns = self.db.get_account_transactions(
address,
start_seq_number,
Expand All @@ -182,7 +176,7 @@ impl Context {
&self,
hash: HashValue,
ledger_version: u64,
) -> Result<Option<TransactionOnChainData<TransactionInfo>>> {
) -> Result<Option<TransactionOnChainData>> {
Ok(self
.db
.get_transaction_by_hash(hash, ledger_version, true)?
Expand All @@ -208,7 +202,7 @@ impl Context {
&self,
version: u64,
ledger_version: u64,
) -> Result<TransactionOnChainData<TransactionInfo>> {
) -> Result<TransactionOnChainData> {
Ok(self
.db
.get_transaction_by_version(version, ledger_version, true)?
Expand Down
4 changes: 2 additions & 2 deletions api/src/runtime.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ use crate::{context::Context, index};

use diem_config::config::{ApiConfig, JsonRpcConfig, NodeConfig};
use diem_mempool::MempoolClientSender;
use diem_types::{chain_id::ChainId, protocol_spec::DpnProto};
use diem_types::chain_id::ChainId;
use futures::join;
use storage_interface::MoveDbReader;
use warp::{Filter, Reply};
Expand All @@ -21,7 +21,7 @@ use tokio::runtime::{Builder, Runtime};
pub fn bootstrap(
config: &NodeConfig,
chain_id: ChainId,
db: Arc<dyn MoveDbReader<DpnProto>>,
db: Arc<dyn MoveDbReader>,
mp_sender: MempoolClientSender,
) -> anyhow::Result<Runtime> {
let runtime = Builder::new_multi_thread()
Expand Down
11 changes: 3 additions & 8 deletions api/src/tests/test_context.rs
Original file line number Diff line number Diff line change
Expand Up @@ -30,8 +30,7 @@ use diem_types::{
chain_id::ChainId,
ledger_info::{LedgerInfo, LedgerInfoWithSignatures},
on_chain_config::VMPublishingOption,
protocol_spec::DpnProto,
transaction::{Transaction, TransactionInfo, TransactionStatus},
transaction::{Transaction, TransactionStatus},
};
use diem_vm::DiemVM;
use diemdb::DiemDB;
Expand Down Expand Up @@ -81,7 +80,7 @@ pub fn new_test_context() -> TestContext {
rng,
root_keys,
validator_owner,
Box::new(BlockExecutor::<DpnProto, DiemVM>::new(db_rw)),
Box::new(BlockExecutor::<DiemVM>::new(db_rw)),
mempool,
db,
)
Expand Down Expand Up @@ -191,11 +190,7 @@ impl TestContext {
self.context.get_latest_ledger_info().unwrap()
}

pub fn get_transactions(
&self,
start: u64,
limit: u16,
) -> Vec<TransactionOnChainData<TransactionInfo>> {
pub fn get_transactions(&self, start: u64, limit: u16) -> Vec<TransactionOnChainData> {
self.context
.get_transactions(start, limit, self.get_latest_ledger_info().version())
.unwrap()
Expand Down
2 changes: 1 addition & 1 deletion api/src/tests/transactions_test.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ use diem_types::{
account_config::{from_currency_code_string, xus_tag, XUS_NAME},
transaction::{
authenticator::{AuthenticationKey, TransactionAuthenticator},
ChangeSet, Script, ScriptFunction, Transaction, TransactionInfoTrait,
ChangeSet, Script, ScriptFunction, Transaction,
},
write_set::{WriteOp, WriteSetMut},
};
Expand Down
14 changes: 4 additions & 10 deletions api/src/transactions.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ use diem_api_types::{
};
use diem_types::{
mempool_status::MempoolStatusCode,
transaction::{RawTransaction, SignedTransaction, TransactionInfo},
transaction::{RawTransaction, SignedTransaction},
};

use anyhow::Result;
Expand Down Expand Up @@ -240,10 +240,7 @@ impl Transactions {
self.render_transactions(data)
}

fn render_transactions(
self,
data: Vec<TransactionOnChainData<TransactionInfo>>,
) -> Result<impl Reply, Error> {
fn render_transactions(self, data: Vec<TransactionOnChainData>) -> Result<impl Reply, Error> {
if data.is_empty() {
let txns: Vec<Transaction> = vec![];
return Response::new(self.ledger_info, &txns);
Expand Down Expand Up @@ -301,7 +298,7 @@ impl Transactions {
Error::not_found("transaction", id, self.ledger_info.version())
}

fn get_by_version(&self, version: u64) -> Result<Option<TransactionData<TransactionInfo>>> {
fn get_by_version(&self, version: u64) -> Result<Option<TransactionData>> {
if version > self.ledger_info.version() {
return Ok(None);
}
Expand All @@ -316,10 +313,7 @@ impl Transactions {
// because the period a transaction stay in the mempool is likely short.
// Although the mempool get transation is async, but looking up txn in database is a sync call,
// thus we keep it simple and call them in sequence.
async fn get_by_hash(
&self,
hash: diem_crypto::HashValue,
) -> Result<Option<TransactionData<TransactionInfo>>> {
async fn get_by_hash(&self, hash: diem_crypto::HashValue) -> Result<Option<TransactionData>> {
let from_db = self
.context
.get_transaction_by_hash(hash, self.ledger_info.version())?;
Expand Down
13 changes: 5 additions & 8 deletions api/types/src/convert.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,10 +12,7 @@ use diem_types::{
access_path::{AccessPath, Path},
chain_id::ChainId,
contract_event::ContractEvent,
transaction::{
ModuleBundle, RawTransaction, Script, ScriptFunction, SignedTransaction,
TransactionInfoTrait,
},
transaction::{ModuleBundle, RawTransaction, Script, ScriptFunction, SignedTransaction},
vm_status::{AbortLocation, KeptVMStatus},
write_set::WriteOp,
};
Expand Down Expand Up @@ -71,10 +68,10 @@ impl<'a, R: MoveResolver + ?Sized> MoveConverter<'a, R> {
Ok((txn, payload).into())
}

pub fn try_into_onchain_transaction<T: TransactionInfoTrait>(
pub fn try_into_onchain_transaction(
&self,
timestamp: u64,
data: TransactionOnChainData<T>,
data: TransactionOnChainData,
) -> Result<Transaction> {
use diem_types::transaction::Transaction::*;
let info = self.into_transaction_info(data.version, &data.info);
Expand All @@ -92,10 +89,10 @@ impl<'a, R: MoveResolver + ?Sized> MoveConverter<'a, R> {
})
}

pub fn into_transaction_info<T: TransactionInfoTrait>(
pub fn into_transaction_info(
&self,
version: u64,
info: &T,
info: &diem_types::transaction::TransactionInfo,
) -> TransactionInfo {
TransactionInfo {
version: version.into(),
Expand Down
29 changes: 13 additions & 16 deletions api/types/src/transaction.rs
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,7 @@ use diem_types::{
contract_event::ContractEvent,
transaction::{
authenticator::{AccountAuthenticator, TransactionAuthenticator},
default_protocol::TransactionWithProof,
Script, SignedTransaction, TransactionInfoTrait,
Script, SignedTransaction, TransactionWithProof,
},
};

Expand All @@ -31,34 +30,32 @@ use std::{
};

#[derive(Clone, Debug)]
pub enum TransactionData<T: TransactionInfoTrait> {
OnChain(TransactionOnChainData<T>),
pub enum TransactionData {
OnChain(TransactionOnChainData),
Pending(Box<SignedTransaction>),
}

impl<T: TransactionInfoTrait> From<TransactionOnChainData<T>> for TransactionData<T> {
fn from(txn: TransactionOnChainData<T>) -> Self {
impl From<TransactionOnChainData> for TransactionData {
fn from(txn: TransactionOnChainData) -> Self {
Self::OnChain(txn)
}
}

impl<T: TransactionInfoTrait> From<SignedTransaction> for TransactionData<T> {
impl From<SignedTransaction> for TransactionData {
fn from(txn: SignedTransaction) -> Self {
Self::Pending(Box::new(txn))
}
}

#[derive(Clone, Debug, Eq, PartialEq)]
pub struct TransactionOnChainData<T: TransactionInfoTrait> {
pub struct TransactionOnChainData {
pub version: u64,
pub transaction: diem_types::transaction::Transaction,
pub info: T,
pub info: diem_types::transaction::TransactionInfo,
pub events: Vec<ContractEvent>,
}

impl From<TransactionWithProof>
for TransactionOnChainData<diem_types::transaction::TransactionInfo>
{
impl From<TransactionWithProof> for TransactionOnChainData {
fn from(txn: TransactionWithProof) -> Self {
Self {
version: txn.version,
Expand All @@ -69,19 +66,19 @@ impl From<TransactionWithProof>
}
}

impl<T: TransactionInfoTrait>
impl
From<(
u64,
diem_types::transaction::Transaction,
T,
diem_types::transaction::TransactionInfo,
Vec<ContractEvent>,
)> for TransactionOnChainData<T>
)> for TransactionOnChainData
{
fn from(
(version, transaction, info, events): (
u64,
diem_types::transaction::Transaction,
T,
diem_types::transaction::TransactionInfo,
Vec<ContractEvent>,
),
) -> Self {
Expand Down
6 changes: 3 additions & 3 deletions config/management/genesis/src/verify.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ use diem_network_address_encryption::Error as NetworkAddressError;
use diem_temppath::TempPath;
use diem_types::{
account_address::AccountAddress, account_config, account_state::AccountState,
network_address::NetworkAddress, on_chain_config::ValidatorSet, protocol_spec::DpnProto,
network_address::NetworkAddress, on_chain_config::ValidatorSet,
validator_config::ValidatorConfig, waypoint::Waypoint,
};
use diem_vm::DiemVM;
Expand All @@ -29,7 +29,7 @@ use std::{
str::FromStr,
sync::Arc,
};
use storage_interface::{default_protocol::DbReaderWriter, DbReader};
use storage_interface::{DbReader, DbReaderWriter};
use structopt::StructOpt;

/// Prints the public information within a store
Expand Down Expand Up @@ -242,7 +242,7 @@ fn compute_genesis(
/// Read from the ledger the validator config from the validator set for the specified account
fn validator_config(
validator_account: AccountAddress,
reader: Arc<dyn DbReader<DpnProto>>,
reader: Arc<dyn DbReader>,
) -> Result<ValidatorConfig, Error> {
let blob = reader
.get_latest_account_state(account_config::validator_set_address())
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,14 +11,14 @@ use crate::{
use consensus_types::{block::Block, quorum_cert::QuorumCert};
use diem_config::config::NodeConfig;
use diem_crypto::{ed25519::Ed25519PrivateKey, Uniform};
use diem_types::{protocol_spec::DpnProto, validator_signer::ValidatorSigner};
use diem_types::validator_signer::ValidatorSigner;
use execution_correctness::{ExecutionCorrectness, ExecutionCorrectnessManager};
use executor_test_helpers::start_storage_service;
use executor_types::ExecutedTrees;
use std::sync::Arc;
use storage_interface::DbReader;

fn get_initial_data_and_qc(db: &dyn DbReader<DpnProto>) -> (RecoveryData, QuorumCert) {
fn get_initial_data_and_qc(db: &dyn DbReader) -> (RecoveryData, QuorumCert) {
// find the block corresponding to storage latest ledger info
let startup_info = db
.get_startup_info()
Expand Down
2 changes: 1 addition & 1 deletion consensus/src/consensus_provider.rs
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ use execution_correctness::ExecutionCorrectnessManager;
use futures::channel::mpsc;
use network::application::storage::PeerMetadataStorage;
use std::sync::Arc;
use storage_interface::default_protocol::DbReaderWriter;
use storage_interface::DbReaderWriter;
use tokio::runtime::{self, Runtime};

/// Helper function to start consensus based on configuration and return the runtime
Expand Down
9 changes: 3 additions & 6 deletions consensus/src/liveness/leader_reputation.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,10 +12,7 @@ use consensus_types::{
use diem_crypto::HashValue;
use diem_infallible::Mutex;
use diem_logger::prelude::*;
use diem_types::{
block_metadata::{new_block_event_key, NewBlockEvent},
protocol_spec::DpnProto,
};
use diem_types::block_metadata::{new_block_event_key, NewBlockEvent};
use std::{
cmp::Ordering,
collections::{HashMap, HashSet},
Expand All @@ -32,12 +29,12 @@ pub trait MetadataBackend: Send + Sync {

pub struct DiemDBBackend {
window_size: usize,
diem_db: Arc<dyn DbReader<DpnProto>>,
diem_db: Arc<dyn DbReader>,
window: Mutex<Vec<(u64, NewBlockEvent)>>,
}

impl DiemDBBackend {
pub fn new(window_size: usize, diem_db: Arc<dyn DbReader<DpnProto>>) -> Self {
pub fn new(window_size: usize, diem_db: Arc<dyn DbReader>) -> Self {
Self {
window_size,
diem_db,
Expand Down
Loading

0 comments on commit 2aee399

Please sign in to comment.