Skip to content

Commit

Permalink
[refactor] move fastx core types and authority into separate crates
Browse files Browse the repository at this point in the history
Separate out the fastx base types (used by clients, the adapter, authority, ...) and the authority code. A future PR connecting the `fastx-programmability` and `fastpay-core` crates leads to cyclic dependencies without this refactor.
  • Loading branch information
sblackshear committed Dec 8, 2021
1 parent 65247d7 commit 7db00b8
Show file tree
Hide file tree
Showing 31 changed files with 79 additions and 56 deletions.
3 changes: 2 additions & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,8 @@ members = [
"fastpay_core",
"fastpay",
"fastx_programmability/adapter",
"fastx_programmability/framework"
"fastx_programmability/framework",
"fastx_types",
]

[profile.release]
Expand Down
1 change: 1 addition & 0 deletions fastpay/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ tempfile = "3.2.0"
tokio = { version = "0.2.22", features = ["full"] }

fastpay_core = { path = "../fastpay_core" }
fastx-types = { path = "../fastx_types" }

[[bin]]
name = "client"
Expand Down
8 changes: 3 additions & 5 deletions fastpay/src/bench.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,10 @@

#![deny(warnings)]

use fastpay::{network, transport};
use fastpay_core::{
authority::*, base_types::*, committee::*, messages::*, object::Object, serialize::*,
};

use bytes::Bytes;
use fastpay::{network, transport};
use fastpay_core::authority::*;
use fastx_types::{base_types::*, committee::*, messages::*, object::Object, serialize::*};
use futures::stream::StreamExt;
use log::*;
use std::{
Expand Down
5 changes: 2 additions & 3 deletions fastpay/src/client.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,8 @@
#![deny(warnings)]

use fastpay::{config::*, network, transport};
use fastpay_core::{
authority::*, base_types::*, client::*, committee::Committee, messages::*, serialize::*,
};
use fastpay_core::{authority::*, client::*};
use fastx_types::{base_types::*, committee::Committee, messages::*, serialize::*};

use bytes::Bytes;
use futures::stream::StreamExt;
Expand Down
4 changes: 2 additions & 2 deletions fastpay/src/config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,9 @@
// SPDX-License-Identifier: Apache-2.0

use crate::transport::NetworkProtocol;
use fastpay_core::{
use fastpay_core::client::ClientState;
use fastx_types::{
base_types::*,
client::ClientState,
messages::{Address, CertifiedOrder, OrderKind},
};

Expand Down
3 changes: 2 additions & 1 deletion fastpay/src/network.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,8 @@
// SPDX-License-Identifier: Apache-2.0

use crate::transport::*;
use fastpay_core::{authority::*, base_types::*, client::*, error::*, messages::*, serialize::*};
use fastpay_core::{authority::*, client::*};
use fastx_types::{base_types::*, error::*, messages::*, serialize::*};

use bytes::Bytes;
use futures::future::FutureExt;
Expand Down
3 changes: 2 additions & 1 deletion fastpay/src/server.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,8 @@
#![deny(warnings)]

use fastpay::{config::*, network, transport};
use fastpay_core::{authority::*, base_types::*, committee::Committee, object::Object};
use fastpay_core::authority::*;
use fastx_types::{base_types::*, committee::Committee, object::Object};

use futures::future::join_all;
use log::*;
Expand Down
19 changes: 1 addition & 18 deletions fastpay_core/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -6,30 +6,13 @@ publish = false
edition = "2018"

[dependencies]
base64 = "0.12.3"
bcs = "0.1.3"
bincode = "1.3.1"
failure = "0.1.8"
futures = "0.3.5"
rand = "0.7.3"
serde = { version = "1.0.115", features = ["derive"] }
tokio = { version = "0.2.22", features = ["full"] }
ed25519 = { version = "1.0.1"}
ed25519-dalek = { version = "1.0.1", features = ["batch", "serde"] }
serde-name = "0.1.2"
structopt = "0.3.21"

fastx-types = { path = "../fastx_types" }
move-binary-format = { git = "https://github.com/diem/diem", rev="661a2d1367a64a02027e4ed8f4b18f0a37cfaa17" }
move-core-types = { git = "https://github.com/diem/diem", rev="661a2d1367a64a02027e4ed8f4b18f0a37cfaa17" }

[dev-dependencies]
similar-asserts = { version = "1.1.0" }
serde-reflection = "0.3.2"
serde_yaml = "0.8.17"
assert-str = "0.1"

[[example]]
name = "generate-format"
path = "src/generate_format.rs"
test = false

5 changes: 3 additions & 2 deletions fastpay_core/src/authority.rs
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
// Copyright (c) Facebook, Inc. and its affiliates.
// SPDX-License-Identifier: Apache-2.0

use crate::{
base_types::*, committee::Committee, error::FastPayError, messages::*, object::Object,
use fastx_types::{
base_types::*, committee::Committee, error::FastPayError, fp_bail, fp_ensure, messages::*,
object::Object,
};
use std::{collections::BTreeMap, convert::TryInto};

Expand Down
5 changes: 4 additions & 1 deletion fastpay_core/src/client.rs
Original file line number Diff line number Diff line change
@@ -1,8 +1,11 @@
// Copyright (c) Facebook, Inc. and its affiliates.
// SPDX-License-Identifier: Apache-2.0

use crate::{base_types::*, committee::Committee, downloader::*, error::FastPayError, messages::*};
use crate::downloader::*;
use failure::{bail, ensure};
use fastx_types::{
base_types::*, committee::Committee, error::FastPayError, fp_ensure, messages::*,
};
use futures::{future, StreamExt};
use rand::seq::SliceRandom;
use std::collections::{btree_map, BTreeMap, BTreeSet, HashMap};
Expand Down
2 changes: 1 addition & 1 deletion fastpay_core/src/fastpay_smart_contract.rs
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
// Copyright (c) Facebook, Inc. and its affiliates.
// SPDX-License-Identifier: Apache-2.0

use super::{base_types::*, committee::Committee, messages::*};
use failure::ensure;
use fastx_types::{base_types::*, committee::Committee, messages::*};
use std::collections::BTreeMap;

#[cfg(test)]
Expand Down
2 changes: 1 addition & 1 deletion fastpay_core/src/generate_format.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
// Copyright (c) Facebook, Inc. and its affiliates.
// SPDX-License-Identifier: Apache-2.0

use fastpay_core::{error, messages, serialize};
use fastx_types::{error, messages, serialize};
use serde_reflection::{Registry, Result, Samples, Tracer, TracerConfig};
use std::{fs::File, io::Write};
use structopt::{clap::arg_enum, StructOpt};
Expand Down
8 changes: 0 additions & 8 deletions fastpay_core/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,15 +8,7 @@
)]
#![deny(warnings)]

#[macro_use]
pub mod error;

pub mod authority;
pub mod base_types;
pub mod client;
pub mod committee;
pub mod downloader;
pub mod fastpay_smart_contract;
pub mod messages;
pub mod object;
pub mod serialize;
2 changes: 2 additions & 0 deletions fastpay_core/src/unit_tests/authority_tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@
// SPDX-License-Identifier: Apache-2.0

use super::*;
#[cfg(test)]
use fastx_types::base_types::dbg_addr;

#[test]
fn test_handle_transfer_order_bad_signature() {
Expand Down
7 changes: 2 additions & 5 deletions fastpay_core/src/unit_tests/client_tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,8 @@
#![allow(clippy::same_item_push)] // get_key_pair returns random elements

use super::*;
use crate::{
authority::{Authority, AuthorityState},
base_types::Amount,
object::Object,
};
use crate::authority::{Authority, AuthorityState};
use fastx_types::{base_types::Amount, object::Object};
use futures::lock::Mutex;
use std::{
collections::{BTreeMap, HashMap},
Expand Down
1 change: 1 addition & 0 deletions fastx_programmability/adapter/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ move-vm-runtime = { git = "https://github.com/diem/diem", rev="661a2d1367a64a020
fastpay_core = { path = "../../fastpay_core" }
fastx-framework = { path = "../framework" }
fastx-verifier = { path = "../verifier" }
fastx-types = { path = "../../fastx_types" }

[dev-dependencies]
datatest-stable = "0.1.1"
Expand Down
2 changes: 1 addition & 1 deletion fastx_programmability/adapter/src/adapter.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,8 @@ use crate::{
MOVE_STDLIB_ADDRESS,
};
use anyhow::Result;
use fastpay_core::error::{FastPayError, FastPayResult};
use fastx_framework::natives;
use fastx_types::error::{FastPayError, FastPayResult};
use fastx_verifier::verifier;
use move_binary_format::{errors::VMError, file_format::CompiledModule};

Expand Down
2 changes: 2 additions & 0 deletions fastx_programmability/verifier/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -14,3 +14,5 @@ publish = false
move-binary-format = { git = "https://github.com/diem/diem", rev="661a2d1367a64a02027e4ed8f4b18f0a37cfaa17" }

fastpay_core = { path = "../../fastpay_core" }
fastx-types = { path = "../../fastx_types" }

2 changes: 1 addition & 1 deletion fastx_programmability/verifier/src/dummy_verifier.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
// Copyright (c) Mysten Labs
// SPDX-License-Identifier: Apache-2.0

use fastpay_core::error::FastPayResult;
use fastx_types::error::FastPayResult;
use move_binary_format::file_format::CompiledModule;

pub fn verify_module(_: &CompiledModule) -> FastPayResult {
Expand Down
2 changes: 1 addition & 1 deletion fastx_programmability/verifier/src/verifier.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@

//! This module contains the public APIs supported by the bytecode verifier.
use fastpay_core::error::FastPayResult;
use fastx_types::error::FastPayResult;
use move_binary_format::file_format::CompiledModule;

use crate::dummy_verifier;
Expand Down
23 changes: 23 additions & 0 deletions fastx_types/Cargo.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
[package]
name = "fastx-types"
version = "0.1.0"
authors = ["Mysten Labs <[email protected]>"]
publish = false
edition = "2018"

[dependencies]
base64 = "0.12.3"
bcs = "0.1.3"
bincode = "1.3.1"
failure = "0.1.8"
futures = "0.3.5"
rand = "0.7.3"
serde = { version = "1.0.115", features = ["derive"] }
tokio = { version = "0.2.22", features = ["full"] }
ed25519 = { version = "1.0.1"}
ed25519-dalek = { version = "1.0.1", features = ["batch", "serde"] }
serde-name = "0.1.2"
structopt = "0.3.21"

move-binary-format = { git = "https://github.com/diem/diem", rev="661a2d1367a64a02027e4ed8f4b18f0a37cfaa17" }
move-core-types = { git = "https://github.com/diem/diem", rev="661a2d1367a64a02027e4ed8f4b18f0a37cfaa17" }
Original file line number Diff line number Diff line change
Expand Up @@ -82,13 +82,11 @@ pub fn decode_address(s: &str) -> Result<PublicKeyBytes, failure::Error> {
Ok(PublicKeyBytes(address))
}

#[cfg(test)]
pub fn dbg_addr(name: u8) -> FastPayAddress {
let addr = [name; dalek::PUBLIC_KEY_LENGTH];
PublicKeyBytes(addr)
}

#[cfg(test)]
pub fn dbg_object_id(name: u8) -> ObjectID {
ObjectID::from_bytes([name; ObjectID::LENGTH]).unwrap()
}
Expand Down
File renamed without changes.
File renamed without changes.
18 changes: 18 additions & 0 deletions fastx_types/src/lib.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
// Copyright (c) Mysten Labs
// SPDX-License-Identifier: Apache-2.0
#![warn(
future_incompatible,
nonstandard_style,
rust_2018_idioms,
rust_2021_compatibility
)]
#![deny(warnings)]

#[macro_use]
pub mod error;

pub mod base_types;
pub mod committee;
pub mod messages;
pub mod object;
pub mod serialize;
6 changes: 4 additions & 2 deletions fastpay_core/src/messages.rs → fastx_types/src/messages.rs
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
// Copyright (c) Facebook, Inc. and its affiliates.
// SPDX-License-Identifier: Apache-2.0

use crate::authority::TransactionDigest;

use super::{base_types::*, committee::Committee, error::*};

#[cfg(test)]
Expand All @@ -19,6 +17,10 @@ use std::{
hash::{Hash, Hasher},
};

// Refactor: eventually a transaction will have a (unique) digest. For the moment we only
// have transfer transactions so we index them by the object/seq they mutate.
pub(crate) type TransactionDigest = (ObjectID, SequenceNumber);

#[derive(Eq, PartialEq, Clone, Debug, Serialize, Deserialize)]
pub struct FundingTransaction {
pub recipient: FastPayAddress,
Expand Down
File renamed without changes.
File renamed without changes.

0 comments on commit 7db00b8

Please sign in to comment.