Skip to content

Commit

Permalink
[fastx client] TX Operations From CLI Fail (MystenLabs#316)
Browse files Browse the repository at this point in the history
* * Fix cli bug due to checks of actual object digest in authorities
* Fixed bug in benchmark caused by change of TransferOrder's response, transfer now returns OrderInfoResponse

* minor fixes

* address PR comments
  • Loading branch information
patrickkuo authored Feb 2, 2022
1 parent 2575901 commit f458c89
Show file tree
Hide file tree
Showing 4 changed files with 36 additions and 29 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ done
# * Private account states are stored in one local wallet `accounts.json`.
# * `initial_accounts.toml` is used to mint the corresponding initially randomly generated (for now) objects at startup on the server side.
./client --committee committee.json --accounts accounts.json create-accounts --num 100 \
--gas-objs-per-account 10 --value-per-per-obj 2000000 initial_accounts.toml
--gas-objs-per-account 10 --value-per-obj 2000000 initial_accounts.toml
# Start servers
for I in 1 2 3 4
do
Expand Down
38 changes: 21 additions & 17 deletions fastpay/src/client.rs
Original file line number Diff line number Diff line change
Expand Up @@ -282,9 +282,9 @@ fn mass_update_recipients(
}
}

fn deserialize_response(response: &[u8]) -> Option<ObjectInfoResponse> {
fn deserialize_response(response: &[u8]) -> Option<OrderInfoResponse> {
match deserialize_message(response) {
Ok(SerializedMessage::ObjectInfoResp(info)) => Some(*info),
Ok(SerializedMessage::OrderResp(info)) => Some(*info),
Ok(SerializedMessage::Error(error)) => {
error!("Received error value: {}", error);
None
Expand Down Expand Up @@ -455,8 +455,7 @@ enum ClientCommands {

/// Gas value per object
#[structopt(long, default_value = "1000")]
#[allow(dead_code)]
value_per_per_obj: u32,
value_per_obj: u64,

/// Initial state config file path
#[structopt(name = "init-state-cfg")]
Expand Down Expand Up @@ -771,8 +770,7 @@ fn main() {
let votes: Vec<_> = responses
.into_iter()
.filter_map(|buf| {
deserialize_response(&buf[..])
.and_then(|info| info.object_and_lock.unwrap().lock)
deserialize_response(&buf[..]).and_then(|info| info.signed_order)
})
.collect();
info!("Received {} valid votes.", votes.len());
Expand Down Expand Up @@ -801,11 +799,14 @@ fn main() {
responses
.iter()
.fold(0, |acc, buf| match deserialize_response(&buf[..]) {
Some(info) => {
confirmed.insert(info.object().unwrap().id());
Some(OrderInfoResponse {
signed_order: Some(order),
..
}) => {
confirmed.insert(*order.order.object_id());
acc + 1
}
None => acc,
_ => acc,
});
warn!(
"Received {} valid confirmations for {} transfers.",
Expand All @@ -828,31 +829,34 @@ fn main() {
num,
gas_objs_per_account,
// TODO: Integrate gas logic with https://github.com/MystenLabs/fastnft/pull/97
value_per_per_obj: _,
value_per_obj,
initial_state_config_path,
} => {
let num_accounts: u32 = num;
let num_of_addresses: u32 = num;
let mut init_state_cfg: InitialStateConfig = InitialStateConfig::new();

for _ in 0..num_accounts {
for _ in 0..num_of_addresses {
let (address, key) = get_key_pair();
let mut objects = Vec::new();
let mut object_refs = Vec::new();
let mut gas_object_ids = Vec::new();
for _ in 0..gas_objs_per_account {
let object = Object::with_id_owner_gas_for_testing(
ObjectID::random(),
SequenceNumber::default(),
FastPayAddress::random_for_testing_only(),
100000,
address,
value_per_obj,
);
object_refs.push(object.to_object_reference());
gas_object_ids.push(object.id())
gas_object_ids.push(object.id());
objects.push(object)
}

let account = UserAccount::new(object_refs.clone(), gas_object_ids);
let account = UserAccount::new(address, key, object_refs, gas_object_ids);

init_state_cfg.config.push(InitialStateConfigEntry {
address: account.address,
object_refs,
objects,
});

accounts_config.insert(account);
Expand Down
16 changes: 11 additions & 5 deletions fastpay/src/config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ use fastx_types::{
messages::{CertifiedOrder, OrderKind},
};

use fastx_types::object::Object;
use move_core_types::language_storage::TypeTag;
use move_core_types::{identifier::Identifier, transaction_argument::TransactionArgument};
use serde::{Deserialize, Serialize};
Expand All @@ -17,6 +18,7 @@ use std::{
io::{BufReader, BufWriter, Write},
iter::FromIterator,
};

#[derive(Clone, Debug, Serialize, Deserialize)]
pub struct AuthorityConfig {
#[serde(
Expand Down Expand Up @@ -107,8 +109,12 @@ pub struct UserAccount {
}

impl UserAccount {
pub fn new(object_refs: Vec<ObjectRef>, gas_object_ids: Vec<ObjectID>) -> Self {
let (address, key) = get_key_pair();
pub fn new(
address: FastPayAddress,
key: KeyPair,
object_refs: Vec<ObjectRef>,
gas_object_ids: Vec<ObjectID>,
) -> Self {
let object_refs = object_refs
.into_iter()
.map(|object_ref| (object_ref.0, object_ref))
Expand Down Expand Up @@ -273,7 +279,7 @@ impl AccountsConfig {
#[derive(Serialize, Deserialize)]
pub struct InitialStateConfigEntry {
pub address: FastPayAddress,
pub object_refs: Vec<ObjectRef>,
pub objects: Vec<Object>,
}
#[derive(Serialize, Deserialize)]
pub struct InitialStateConfig {
Expand All @@ -288,11 +294,11 @@ impl InitialStateConfig {
pub fn read(path: &str) -> Result<Self, anyhow::Error> {
let raw_data: String = read_to_string(path)?.parse()?;

Ok(toml::from_str(&raw_data)?)
Ok(serde_json::from_str(&raw_data)?)
}

pub fn write(&self, path: &str) -> Result<(), std::io::Error> {
let config = toml::to_string(self).unwrap();
let config = serde_json::to_string(self).unwrap();

fs::write(path, config).expect("Unable to write to initial config file");
Ok(())
Expand Down
9 changes: 3 additions & 6 deletions fastpay/src/server.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
use fastpay::config::*;
use fastpay_core::{authority::*, authority_server::AuthorityServer};
use fastx_network::transport;
use fastx_types::{base_types::*, committee::Committee, object::Object};
use fastx_types::{base_types::*, committee::Committee};

use futures::future::join_all;
use std::path::Path;
Expand Down Expand Up @@ -50,11 +50,8 @@ fn make_server(
store,
)
.await;
for initial_state_cfg_entry in &initial_accounts_config.config {
let address = &initial_state_cfg_entry.address;
for (object_id, _, _) in &initial_state_cfg_entry.object_refs {
let object = Object::with_id_owner_for_testing(*object_id, *address);

for initial_state_cfg_entry in initial_accounts_config.config {
for object in initial_state_cfg_entry.objects {
state.init_order_lock(object.to_object_reference()).await;
state.insert_object(object).await;
}
Expand Down

0 comments on commit f458c89

Please sign in to comment.