Skip to content

Commit

Permalink
[vm] switch script function argument type to bcs bytes (#2326)
Browse files Browse the repository at this point in the history
* [vm] upgrade vm to 03_25

* switch to bcs bytes for txn args in script function

* fix unit tests and fmt

* fix test_modify_on_chain_config_consensus_by_dao

Co-authored-by: jolestar <jolestar@gmail.com>
  • Loading branch information
guangyuz and jolestar authored Mar 25, 2021
1 parent 897867e commit 73c32f1
Show file tree
Hide file tree
Showing 38 changed files with 480 additions and 296 deletions.
111 changes: 66 additions & 45 deletions Cargo.lock

Large diffs are not rendered by default.

22 changes: 9 additions & 13 deletions chain/tests/test_epoch_switch.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,9 +14,7 @@ use starcoin_types::account_config::association_address;
use starcoin_types::account_config::stc_type_tag;
use starcoin_types::block::Block;
use starcoin_types::genesis_config::ChainId;
use starcoin_types::transaction::{
ScriptFunction, SignedUserTransaction, TransactionArgument, TransactionPayload,
};
use starcoin_types::transaction::{ScriptFunction, SignedUserTransaction, TransactionPayload};
use starcoin_vm_types::account_config::core_code_address;
use starcoin_vm_types::identifier::Identifier;
use starcoin_vm_types::language_storage::ModuleId;
Expand Down Expand Up @@ -111,10 +109,9 @@ fn build_cast_vote_txn(
alice: &Account,
action_type_tag: TypeTag,
voting_power: u128,
_net: &ChainNetwork,
expire_time: u64,
) -> SignedUserTransaction {
let proposer_id = 0;
let proposer_id: u64 = 0;
println!("alice voting power: {}", voting_power);
let vote_script_function = ScriptFunction::new(
ModuleId::new(
Expand All @@ -124,10 +121,10 @@ fn build_cast_vote_txn(
Identifier::new("cast_vote").unwrap(),
vec![stc_type_tag(), action_type_tag],
vec![
TransactionArgument::Address(*alice.address()),
TransactionArgument::U64(proposer_id),
TransactionArgument::Bool(true),
TransactionArgument::U128(voting_power / 2),
bcs_ext::to_bytes(alice.address()).unwrap(),
bcs_ext::to_bytes(&proposer_id).unwrap(),
bcs_ext::to_bytes(&true).unwrap(),
bcs_ext::to_bytes(&(voting_power / 2)).unwrap(),
],
);
alice.sign_txn(build_transaction(
Expand All @@ -150,8 +147,8 @@ fn build_queue_txn(
Identifier::new("queue_proposal_action").unwrap(),
vec![stc_type_tag(), action_type_tag],
vec![
TransactionArgument::Address(*alice.address()),
TransactionArgument::U64(0),
bcs_ext::to_bytes(alice.address()).unwrap(),
bcs_ext::to_bytes(&0u64).unwrap(),
],
);
alice.sign_txn(build_transaction(
Expand Down Expand Up @@ -271,7 +268,6 @@ pub fn modify_on_chain_config_by_dao_block(
&alice,
action_type_tag.clone(),
voting_power,
net,
block_timestamp / 1000,
)],
)?;
Expand Down Expand Up @@ -316,7 +312,7 @@ pub fn modify_on_chain_config_by_dao_block(
*alice.address(),
0,
);
assert_eq!(state, AGREED);
assert_eq!(state, AGREED, "expect AGREED state, but got {}", state);
}

// block 6
Expand Down
4 changes: 2 additions & 2 deletions cmd/starcoin/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -44,10 +44,10 @@ starcoin-genesis = { path = "../../genesis" }
starcoin-resource-viewer = { path = "../../vm/resource-viewer" }
starcoin-service-registry = { path = "../../commons/service-registry" }
starcoin-move-explain = { path = "../../vm/move-explain" }
errmapgen = { git = "https://github.com/starcoinorg/diem", rev="e3967fa3dd494bdf929ac99160f89751cac4c58b" }
errmapgen = { git = "https://github.com/starcoinorg/diem", rev="a318bb619320e8f3c8ec7e3e3bbbe1af8bc52dee" }
network-api = {path = "../../network/api", package="network-api"}
starcoin-network-rpc-api = {path = "../../network-rpc/api"}
short-hex-str = { git = "https://github.com/starcoinorg/diem", rev="e3967fa3dd494bdf929ac99160f89751cac4c58b" }
short-hex-str = { git = "https://github.com/starcoinorg/diem", rev="a318bb619320e8f3c8ec7e3e3bbbe1af8bc52dee" }


[dev-dependencies]
Expand Down
3 changes: 2 additions & 1 deletion cmd/starcoin/src/account/execute_script_function_cmd.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ use starcoin_types::transaction::{
};
use starcoin_vm_types::account_address::AccountAddress;
use starcoin_vm_types::transaction::ScriptFunction;
use starcoin_vm_types::transaction_argument::convert_txn_args;
use starcoin_vm_types::{language_storage::TypeTag, parser::parse_type_tag};
use structopt::StructOpt;

Expand Down Expand Up @@ -109,7 +110,7 @@ impl CommandAction for ExecuteScriptFunctionCmd {
script_function.module,
script_function.function,
type_tags,
args,
convert_txn_args(&args),
),
opt.max_gas_amount,
opt.gas_price,
Expand Down
14 changes: 10 additions & 4 deletions cmd/starcoin/src/dev/execute_cmd.rs
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ use starcoin_types::transaction::{
ScriptFunction, TransactionArgument, TransactionPayload,
};
use starcoin_vm_types::account_address::AccountAddress;
use starcoin_vm_types::transaction_argument::convert_txn_args;
use starcoin_vm_types::{language_storage::TypeTag, parser::parse_type_tag};
use std::path::PathBuf;
use stdlib::restore_stdlib_in_dir;
Expand Down Expand Up @@ -167,8 +168,9 @@ impl CommandAction for ExecuteCommand {
let txn_payload = match (bytedata, script_function_id) {
// package deploy
(Some((bytecode, false)), function_id) => {
let module_init_script_function = function_id
.map(|id| ScriptFunction::new(id.module, id.function, type_tags, args));
let module_init_script_function = function_id.map(|id| {
ScriptFunction::new(id.module, id.function, type_tags, convert_txn_args(&args))
});
let package =
Package::new(vec![Module::new(bytecode)], module_init_script_function)?;
TransactionPayload::Package(package)
Expand All @@ -183,8 +185,12 @@ impl CommandAction for ExecuteCommand {
}
// script function
(None, Some(function_id)) => {
let script_function =
ScriptFunction::new(function_id.module, function_id.function, type_tags, args);
let script_function = ScriptFunction::new(
function_id.module,
function_id.function,
type_tags,
convert_txn_args(&args),
);
TransactionPayload::ScriptFunction(script_function)
}
(None, None) => {
Expand Down
5 changes: 3 additions & 2 deletions cmd/starcoin/src/dev/tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ use starcoin_vm_types::language_storage::ModuleId;
use starcoin_vm_types::transaction::{
RawUserTransaction, SignedUserTransaction, TransactionPayload,
};
use starcoin_vm_types::transaction_argument::convert_txn_args;
use starcoin_vm_types::{
account_config::{association_address, genesis_address, AccountResource},
transaction::Package,
Expand Down Expand Up @@ -233,7 +234,7 @@ fn test_upgrade_module() {
),
Identifier::new("cast_vote").unwrap(),
type_tags,
args,
convert_txn_args(&args),
);
let vote_raw_txn = RawUserTransaction::new_script_function(
default_account.address,
Expand Down Expand Up @@ -402,7 +403,7 @@ fn test_only_new_module() {
),
Identifier::new("update_module_upgrade_strategy").unwrap(),
Vec::new(),
args,
convert_txn_args(&args),
);
let only_new_module_strategy_raw_txn = RawUserTransaction::new_script_function(
default_account.address,
Expand Down
4 changes: 2 additions & 2 deletions commons/crypto/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,8 @@ serde = { version = "1.0.125" }
serde_bytes = "0.11.5"
hex = "0.4.3"
anyhow = "1.0"
diem-crypto = { package="diem-crypto", git = "https://github.com/starcoinorg/diem", rev="e3967fa3dd494bdf929ac99160f89751cac4c58b", features = ["fuzzing"] }
diem-crypto-derive = { package="diem-crypto-derive", git = "https://github.com/starcoinorg/diem", rev="e3967fa3dd494bdf929ac99160f89751cac4c58b" }
diem-crypto = { package="diem-crypto", git = "https://github.com/starcoinorg/diem", rev="a318bb619320e8f3c8ec7e3e3bbbe1af8bc52dee", features = ["fuzzing"] }
diem-crypto-derive = { package="diem-crypto-derive", git = "https://github.com/starcoinorg/diem", rev="a318bb619320e8f3c8ec7e3e3bbbe1af8bc52dee" }
bcs-ext = { package="bcs-ext", path = "../bcs_ext" }
crypto-macro = { package="starcoin-crypto-macro", path = "./crypto-macro"}
rand = "0.8.3"
Expand Down
2 changes: 1 addition & 1 deletion commons/proptest-helpers/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ edition = "2018"

[dependencies]
crossbeam = "0.7.3"
diem-proptest-helpers = { package="diem-proptest-helpers", git = "https://github.com/starcoinorg/diem", rev="e3967fa3dd494bdf929ac99160f89751cac4c58b" }
diem-proptest-helpers = { package="diem-proptest-helpers", git = "https://github.com/starcoinorg/diem", rev="a318bb619320e8f3c8ec7e3e3bbbe1af8bc52dee" }

proptest = "1.0.0"
proptest-derive = "0.3.0"
2 changes: 1 addition & 1 deletion config/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ starcoin-vm-types = { path = "../vm/types" }
starcoin-uint = { path = "../types/uint" }
network-p2p-types = { path = "../network-p2p/types"}
starcoin-logger = {path = "../commons/logger", package="starcoin-logger"}
diem-temppath = { git = "https://github.com/starcoinorg/diem", rev="e3967fa3dd494bdf929ac99160f89751cac4c58b" }
diem-temppath = { git = "https://github.com/starcoinorg/diem", rev="a318bb619320e8f3c8ec7e3e3bbbe1af8bc52dee" }
starcoin-system = {path = "../commons/system", package="starcoin-system"}
network-api = {path = "../network/api", package="network-api"}
stdlib = { path = "../vm/stdlib"}
8 changes: 4 additions & 4 deletions devtools/x/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ globset = "0.4.6"
regex = "1.4.3"
rayon = "1.5.0"
indexmap = "1.6.2"
x-core = { package="x-core", git = "https://github.com/starcoinorg/diem", rev="e3967fa3dd494bdf929ac99160f89751cac4c58b" }
x-lint = { package="x-lint", git = "https://github.com/starcoinorg/diem", rev="e3967fa3dd494bdf929ac99160f89751cac4c58b" }
diem-workspace-hack = { package="diem-workspace-hack", git = "https://github.com/starcoinorg/diem", rev="e3967fa3dd494bdf929ac99160f89751cac4c58b" }
diem-x = { package="x", git = "https://github.com/starcoinorg/diem", rev="e3967fa3dd494bdf929ac99160f89751cac4c58b" }
x-core = { package="x-core", git = "https://github.com/starcoinorg/diem", rev="a318bb619320e8f3c8ec7e3e3bbbe1af8bc52dee" }
x-lint = { package="x-lint", git = "https://github.com/starcoinorg/diem", rev="a318bb619320e8f3c8ec7e3e3bbbe1af8bc52dee" }
diem-workspace-hack = { package="diem-workspace-hack", git = "https://github.com/starcoinorg/diem", rev="a318bb619320e8f3c8ec7e3e3bbbe1af8bc52dee" }
diem-x = { package="x", git = "https://github.com/starcoinorg/diem", rev="a318bb619320e8f3c8ec7e3e3bbbe1af8bc52dee" }
3 changes: 1 addition & 2 deletions etc/starcoin_types.yml
Original file line number Diff line number Diff line change
Expand Up @@ -168,8 +168,7 @@ ScriptFunction:
SEQ:
TYPENAME: TypeTag
- args:
SEQ:
TYPENAME: TransactionArgument
SEQ: BYTES
ScriptFunctionABI:
STRUCT:
- name: STR
Expand Down
20 changes: 9 additions & 11 deletions executor/src/account.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ use starcoin_types::{
event::EventHandle,
transaction::{
authenticator::AuthenticationKey, RawUserTransaction, ScriptFunction,
SignedUserTransaction, TransactionArgument, TransactionPayload,
SignedUserTransaction, TransactionPayload,
},
write_set::{WriteOp, WriteSet, WriteSetMut},
};
Expand Down Expand Up @@ -655,10 +655,10 @@ pub fn peer_to_peer_txn(
expiration_timestamp_secs: u64,
chain_id: ChainId,
) -> SignedUserTransaction {
let mut args: Vec<TransactionArgument> = Vec::new();
args.push(TransactionArgument::Address(*receiver.address()));
args.push(TransactionArgument::U8Vector(receiver.auth_key().to_vec()));
args.push(TransactionArgument::U128(transfer_amount));
let mut args: Vec<Vec<u8>> = Vec::new();
args.push(bcs_ext::to_bytes(receiver.address()).unwrap());
args.push(bcs_ext::to_bytes(&receiver.auth_key().to_vec()).unwrap());
args.push(bcs_ext::to_bytes(&transfer_amount).unwrap());

// get a SignedTransaction
sender.create_signed_txn_with_args(
Expand Down Expand Up @@ -687,12 +687,10 @@ pub fn create_account_txn_sent_as_association(
expiration_timstamp_secs: u64,
net: &ChainNetwork,
) -> SignedUserTransaction {
let mut args: Vec<TransactionArgument> = Vec::new();
args.push(TransactionArgument::Address(*new_account.address()));
args.push(TransactionArgument::U8Vector(
new_account.auth_key().to_vec(),
));
args.push(TransactionArgument::U128(initial_amount));
let mut args: Vec<Vec<u8>> = Vec::new();
args.push(bcs_ext::to_bytes(new_account.address()).unwrap());
args.push(bcs_ext::to_bytes(&new_account.auth_key().to_vec()).unwrap());
args.push(bcs_ext::to_bytes(&initial_amount).unwrap());

create_signed_txn_with_association_account(
TransactionPayload::ScriptFunction(ScriptFunction::new(
Expand Down
8 changes: 4 additions & 4 deletions executor/src/executor_test.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ use starcoin_resource_viewer::MoveValueAnnotator;
use starcoin_transaction_builder::{DEFAULT_EXPIRATION_TIME, DEFAULT_MAX_GAS_AMOUNT};
use starcoin_types::identifier::Identifier;
use starcoin_types::language_storage::ModuleId;
use starcoin_types::transaction::{RawUserTransaction, ScriptFunction, TransactionArgument};
use starcoin_types::transaction::{RawUserTransaction, ScriptFunction};
use starcoin_types::{
account_config, block_metadata::BlockMetadata, transaction::Transaction,
transaction::TransactionPayload, transaction::TransactionStatus,
Expand Down Expand Up @@ -124,9 +124,9 @@ fn test_gen_accounts() -> Result<()> {
Identifier::new("peer_to_peer_batch").unwrap(),
vec![stc_type_tag()],
vec![
TransactionArgument::U8Vector(address_vec),
TransactionArgument::U8Vector(auth_key_vec),
TransactionArgument::U128(1),
bcs_ext::to_bytes(&address_vec).unwrap(),
bcs_ext::to_bytes(&auth_key_vec).unwrap(),
bcs_ext::to_bytes(&1u128).unwrap(),
],
);
association_execute(
Expand Down
13 changes: 6 additions & 7 deletions executor/src/stdlib_test/module_upgrade_test.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@ use starcoin_types::transaction::ScriptFunction;
use starcoin_vm_types::account_config::core_code_address;
use starcoin_vm_types::account_config::{genesis_address, stc_type_tag};
use starcoin_vm_types::transaction::{Package, TransactionPayload};
use starcoin_vm_types::transaction_argument::TransactionArgument;
use starcoin_vm_types::values::VMValueCast;
use test_helper::dao::dao_vote_test;
use test_helper::executor::*;
Expand Down Expand Up @@ -37,10 +36,10 @@ fn test_dao_upgrade_module() -> Result<()> {
Identifier::new("propose_module_upgrade").unwrap(),
vec![stc_type_tag()],
vec![
TransactionArgument::Address(genesis_address()),
TransactionArgument::U8Vector(package_hash.to_vec()),
TransactionArgument::U64(1),
TransactionArgument::U64(0),
bcs_ext::to_bytes(&genesis_address()).unwrap(),
bcs_ext::to_bytes(&package_hash.to_vec()).unwrap(),
bcs_ext::to_bytes(&1u64).unwrap(),
bcs_ext::to_bytes(&0u64).unwrap(),
],
);
let execute_script_function = ScriptFunction::new(
Expand All @@ -51,8 +50,8 @@ fn test_dao_upgrade_module() -> Result<()> {
Identifier::new("submit_module_upgrade_plan").unwrap(),
vec![stc_type_tag()],
vec![
TransactionArgument::Address(*alice.address()),
TransactionArgument::U64(0),
bcs_ext::to_bytes(alice.address()).unwrap(),
bcs_ext::to_bytes(&0u64).unwrap(),
],
);
let chain_state = dao_vote_test(
Expand Down
Binary file modified genesis/generated/halley/genesis
Binary file not shown.
Binary file modified genesis/generated/proxima/genesis
Binary file not shown.
Loading

0 comments on commit 73c32f1

Please sign in to comment.