Skip to content

Commit

Permalink
Move rust transcation-builder into client/
Browse files Browse the repository at this point in the history
  • Loading branch information
thefallentree authored and bors-libra committed Aug 28, 2020
1 parent 7cfd561 commit 6ed2378
Show file tree
Hide file tree
Showing 20 changed files with 75 additions and 87 deletions.
2 changes: 1 addition & 1 deletion .github/CODEOWNERS
Validating CODEOWNERS rules …
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
/json-rpc/json-rpc-spec.md @thefallentree @xli
/json-rpc/types/ @thefallentree @xli
/json-rpc/src/methods.rs @thefallentree @xli
/client/libra-dev/ @thefallentree @xli
/client/ @thefallentree @xli
# Subscribe to LCS format changes
/testsuite/generate-format/tests/staged/libra.yaml @thefallentree @matbd @xli
# Subscribe to TCB dependency summary changes
Expand Down
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
# .gitignore file locally for IDE/Emacs/Vim generated files.
**/target
**/*.rs.bk
/.idea

# Ignore wallet mnemonic files used for deterministic key derivation
*.mnemonic
Expand Down
6 changes: 2 additions & 4 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ members = [
"client/json-rpc",
"client/libra-dev",
"client/swiss-knife",
"client/transaction-builder",
"common/bitvec",
"common/bounded-executor",
"common/channel",
Expand Down Expand Up @@ -92,7 +93,6 @@ members = [
"language/tools/transaction-replay",
"language/tools/vm-genesis",
"language/transaction-builder",
"language/transaction-builder/generated",
"language/transaction-builder/generator",
"language/vm",
"language/vm/serializer-tests",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,13 +12,15 @@ edition = "2018"
once_cell = "1.4.1"
serde = { version = "1.0.115", features = ["derive"] }

move-core-types = { path = "../../move-core/types", version = "0.1.0" }
libra-types = { path = "../../../types", version = "0.1.0" }
libra-workspace-hack = { path = "../../../common/workspace-hack", version = "0.1.0" }
compiled-stdlib = { path = "../../language/stdlib/compiled", version = "0.1.0" }
lcs = { path = "../../common/lcs", version = "0.1.0", package = "libra-canonical-serialization" }
move-core-types = { path = "../../language/move-core/types", version = "0.1.0" }
libra-types = { path = "../../types", version = "0.1.0" }
libra-workspace-hack = { path = "../../common/workspace-hack", version = "0.1.0" }

proptest = { version = "0.10.1", optional = true }
proptest-derive = { version = "0.2.0", optional = true }
libra-proptest-helpers = { path = "../../../common/proptest-helpers", version = "0.1.0", optional = true }
libra-proptest-helpers = { path = "../../common/proptest-helpers", version = "0.1.0", optional = true }

[features]
default = []
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,4 +3,5 @@

#![forbid(unsafe_code)]

pub mod misc;
pub mod stdlib;
47 changes: 47 additions & 0 deletions client/transaction-builder/src/misc.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
// Copyright (c) The Libra Core Contributors
// SPDX-License-Identifier: Apache-2.0

#![forbid(unsafe_code)]

use compiled_stdlib::{transaction_scripts::StdlibScript, StdLibOptions};
use libra_types::{
access_path::AccessPath,
block_metadata::BlockMetadata,
transaction::{ChangeSet, Transaction},
write_set::{WriteOp, WriteSetMut},
};
use std::convert::TryFrom;

// TODO: this should go away once we are no longer using it in tests
pub fn encode_block_prologue_script(block_metadata: BlockMetadata) -> Transaction {
Transaction::BlockMetadata(block_metadata)
}

/// Update WriteSet
pub fn encode_stdlib_upgrade_transaction(option: StdLibOptions) -> ChangeSet {
let mut write_set = WriteSetMut::new(vec![]);
let stdlib = compiled_stdlib::stdlib_modules(option);
for module in stdlib {
let mut bytes = vec![];
module
.serialize(&mut bytes)
.expect("Failed to serialize module");
write_set.push((
AccessPath::code_access_path(&module.self_id()),
WriteOp::Value(bytes),
));
}
ChangeSet::new(
write_set.freeze().expect("Failed to create writeset"),
vec![],
)
}

// TODO: delete and use StdlibScript::try_from directly if it's ok to drop the "_transaction"?
/// Returns a user friendly mnemonic for the transaction type if the transaction is
/// for a known, white listed, transaction.
pub fn get_transaction_name(code: &[u8]) -> String {
StdlibScript::try_from(code).map_or("<unknown transaction>".to_string(), |name| {
format!("{}_transaction", name)
})
}
File renamed without changes.
6 changes: 3 additions & 3 deletions json-rpc/docs/client_implementation_guide.md
Original file line number Diff line number Diff line change
Expand Up @@ -324,14 +324,14 @@ Once the above basic function works, you have a minimum client ready for usage.
To make a production quality client, please checkout our [Client CHECKLIST](client_checklist.md).

[1]: https://libra.github.io/libra/libra_types/transaction/struct.SignedTransaction.html "SignedTransaction"
[2]: ./../../language/transaction-builder/generator/README.md "Transaction Builder Generator"
[2]: ../../language/transaction-builder/generator/README.md "Transaction Builder Generator"
[3]: ./../../client/swiss-knife/README.md "Libra Swiss Knife"
[4]: https://libra.github.io/libra/libra_types/transaction/struct.RawTransaction.html "RawTransaction"
[5]: https://libra.github.io/libra/libra_canonical_serialization/index.html "LCS"
[6]: ./../../client/swiss-knife#generate-a-ed25519-keypair "Swiss Knife Gen Keys"
[7]: ./../../language/stdlib/transaction_scripts/doc/peer_to_peer_with_metadata.md#function-peer_to_peer_with_metadata-1 "P2P script doc"
[8]: ./../../client/swiss-knife/readme.md#examples-for-generate-raw-txn-and-generate-signed-txn-operations "Swiss Knife gen txn"
[9]: ./../../client/swiss-knife/readme.md#building-the-binary-in-a-release-optimized-mode "Swiss Knife binary"
[10]: ./../../language/transaction-builder/generator/README.md#supported-languages "Transaction Builder Generator supports"
[10]: ../../language/transaction-builder/generator/README.md#supported-languages "Transaction Builder Generator supports"
[11]: ./../../client/libra-dev/include/data.h "C binding head file"
[12]: ./../../language/transaction-builder/generator/README.md#java "Generate Java Txn Builder"
[12]: ../../language/transaction-builder/generator/README.md#java "Generate Java Txn Builder"
2 changes: 1 addition & 1 deletion language/e2e-testsuite/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ libra-types = { path = "../../types", version = "0.1.0", features = ["fuzzing"]
move-core-types = { path = "../move-core/types", version = "0.1.0" }
move-vm-types = { path = "../move-vm/types", version = "0.1.0" }
transaction-builder = { path = "../transaction-builder", version = "0.1.0"}
transaction-builder-generated = { path = "../transaction-builder/generated", version = "0.1.0"}
transaction-builder-generated = { path = "../../client/transaction-builder", version = "0.1.0"}
vm = { path = "../vm", version = "0.1.0" }
libra-vm = { path = "../libra-vm", version = "0.1.0" }
proptest = "0.10.1"
Expand Down
2 changes: 1 addition & 1 deletion language/stdlib/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ libra-workspace-hack = { path = "../../common/workspace-hack", version = "0.1.0"
datatest-stable = { path = "../../common/datatest-stable", version = "0.1.0" }
lcs = { path = "../../common/lcs", version = "0.1.0", package = "libra-canonical-serialization" }
vm = { path = "../vm", version = "0.1.0" }
transaction-builder-generator = { path = "../../language/transaction-builder/generator", version = "0.1.0" }
transaction-builder-generator = { path = "../transaction-builder/generator", version = "0.1.0" }

clap = "2.33.3"
log = "0.4.11"
Expand Down
2 changes: 1 addition & 1 deletion language/stdlib/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ pub const COMPILED_TRANSACTION_SCRIPTS_ABI_DIR: &str = "compiled/transaction_scr

/// Where to write generated transaction builders.
pub const TRANSACTION_BUILDERS_GENERATED_SOURCE_PATH: &str =
"../transaction-builder/generated/src/stdlib.rs";
"../../client/transaction-builder/src/stdlib.rs";

pub fn filter_move_files(dir_iter: impl Iterator<Item = PathBuf>) -> impl Iterator<Item = PathBuf> {
dir_iter.flat_map(|path| {
Expand Down
6 changes: 1 addition & 5 deletions language/transaction-builder/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -11,12 +11,8 @@ edition = "2018"
[dependencies]
mirai-annotations = "1.10.1"

compiled-stdlib = { path = "../stdlib/compiled", version = "0.1.0" }
move-core-types = { path = "../move-core/types", version = "0.1.0" }
lcs = { path = "../../common/lcs", version = "0.1.0", package = "libra-canonical-serialization" }
libra-types = { path = "../../types", version = "0.1.0" }
libra-workspace-hack = { path = "../../common/workspace-hack", version = "0.1.0" }
transaction-builder-generated = { path = "generated", version = "0.1.0" }
transaction-builder-generated = { path = "../../client/transaction-builder", version = "0.1.0" }

[features]
default = []
56 changes: 3 additions & 53 deletions language/transaction-builder/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,57 +3,7 @@

#![forbid(unsafe_code)]

use compiled_stdlib::{transaction_scripts::StdlibScript, StdLibOptions};
use libra_types::{
access_path::AccessPath,
block_metadata::BlockMetadata,
on_chain_config::LibraVersion,
transaction::{ChangeSet, Script, Transaction},
write_set::{WriteOp, WriteSetMut},
};
use std::convert::TryFrom;
// TODO: remove
pub use transaction_builder_generated::misc::*;
// TODO: remove
pub use transaction_builder_generated::stdlib::*;

pub fn encode_update_libra_version_script(
sliding_nonce: u64,
libra_version: LibraVersion,
) -> Script {
transaction_builder_generated::stdlib::encode_update_libra_version_script(
sliding_nonce,
libra_version.major as u64,
)
}

// TODO: this should go away once we are no longer using it in tests
pub fn encode_block_prologue_script(block_metadata: BlockMetadata) -> Transaction {
Transaction::BlockMetadata(block_metadata)
}

/// Update WriteSet
pub fn encode_stdlib_upgrade_transaction(option: StdLibOptions) -> ChangeSet {
let mut write_set = WriteSetMut::new(vec![]);
let stdlib = compiled_stdlib::stdlib_modules(option);
for module in stdlib {
let mut bytes = vec![];
module
.serialize(&mut bytes)
.expect("Failed to serialize module");
write_set.push((
AccessPath::code_access_path(&module.self_id()),
WriteOp::Value(bytes),
));
}
ChangeSet::new(
write_set.freeze().expect("Failed to create writeset"),
vec![],
)
}

// TODO: delete and use StdlibScript::try_from directly if it's ok to drop the "_transaction"?
/// Returns a user friendly mnemonic for the transaction type if the transaction is
/// for a known, white listed, transaction.
pub fn get_transaction_name(code: &[u8]) -> String {
StdlibScript::try_from(code).map_or("<unknown transaction>".to_string(), |name| {
format!("{}_transaction", name)
})
}
2 changes: 1 addition & 1 deletion secure/key-manager/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ libra-secure-storage = { path = "../../secure/storage", version = "0.1.0" }
libra-secure-time = { path = "../../secure/time", version = "0.1.0" }
libra-types = { path = "../../types", version = "0.1.0" }
libra-workspace-hack = { path = "../../common/workspace-hack", version = "0.1.0" }
transaction-builder-generated = { path = "../../language/transaction-builder/generated", version = "0.1.0" }
transaction-builder-generated = { path = "../../client/transaction-builder", version = "0.1.0" }

[dev-dependencies]
anyhow = "1.0.32"
Expand Down
2 changes: 1 addition & 1 deletion summaries/summary-default.toml
Original file line number Diff line number Diff line change
Expand Up @@ -715,7 +715,7 @@ features = ['default']
[[target-package]]
name = 'transaction-builder-generated'
version = '0.1.0'
workspace-path = 'language/transaction-builder/generated'
workspace-path = 'client/transaction-builder'
status = 'workspace'
features = ['default']

Expand Down
2 changes: 1 addition & 1 deletion summaries/summary-full.toml
Original file line number Diff line number Diff line change
Expand Up @@ -877,7 +877,7 @@ features = ['default']
[[target-package]]
name = 'transaction-builder-generated'
version = '0.1.0'
workspace-path = 'language/transaction-builder/generated'
workspace-path = 'client/transaction-builder'
status = 'initial'
features = ['default', 'fuzzing', 'libra-proptest-helpers', 'proptest', 'proptest-derive']

Expand Down
2 changes: 1 addition & 1 deletion summaries/summary-release.toml
Original file line number Diff line number Diff line change
Expand Up @@ -596,7 +596,7 @@ features = ['default']
[[target-package]]
name = 'transaction-builder-generated'
version = '0.1.0'
workspace-path = 'language/transaction-builder/generated'
workspace-path = 'client/transaction-builder'
status = 'workspace'
features = ['default']

Expand Down
5 changes: 1 addition & 4 deletions testsuite/cli/src/client_proxy.rs
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,6 @@ use libra_types::{
account_state::AccountState,
chain_id::ChainId,
ledger_info::LedgerInfoWithSignatures,
on_chain_config::LibraVersion,
transaction::{
authenticator::AuthenticationKey,
helpers::{create_unsigned_txn, create_user_txn, TransactionSigner},
Expand Down Expand Up @@ -642,9 +641,7 @@ impl ClientProxy {
TransactionPayload::Script(
transaction_builder::encode_update_libra_version_script(
self.libra_root_account.as_ref().unwrap().sequence_number,
LibraVersion {
major: space_delim_strings[1].parse::<u64>().unwrap(),
},
space_delim_strings[1].parse::<u64>().unwrap(),
),
),
is_blocking,
Expand Down
6 changes: 1 addition & 5 deletions testsuite/cluster-test/src/experiments/versioning_test.rs
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@ use libra_logger::prelude::*;
use libra_types::{
account_config::{lbr_type_tag, LBR_NAME},
chain_id::ChainId,
on_chain_config::LibraVersion,
transaction::{helpers::create_user_txn, TransactionPayload},
};
use std::{collections::HashSet, fmt, time::Duration};
Expand Down Expand Up @@ -168,10 +167,7 @@ impl Experiment for ValidatorVersioning {
let allowed_nonce = 0;
let update_txn = create_user_txn(
&faucet_account.key_pair,
TransactionPayload::Script(encode_update_libra_version_script(
allowed_nonce,
LibraVersion { major: 11 },
)),
TransactionPayload::Script(encode_update_libra_version_script(allowed_nonce, 11)),
faucet_account.address,
faucet_account.sequence_number,
123456,
Expand Down

0 comments on commit 6ed2378

Please sign in to comment.