Skip to content

Commit

Permalink
More CLI tweaks
Browse files Browse the repository at this point in the history
  • Loading branch information
ade authored and ade committed Dec 29, 2021
1 parent d8db91c commit ca61f9d
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 24 deletions.
21 changes: 11 additions & 10 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -26,10 +26,11 @@ do
./server --server server"$I".json generate --host 127.0.0.1 --port 9"$I"00 --shards 4 >> committee.json
done

# Create configuration files for 1000 user accounts.
# Create configuration files for 100 user accounts, with 4 gas objects per account and 200 value each.
# * 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 1000 initial_accounts.toml
./client --committee committee.json --accounts accounts.json create-accounts --num 100 \
--gas-objs-per-account 4 --value-per-per-obj 200 initial_accounts.toml
# Start servers
for I in 1 2 3 4
do
Expand All @@ -40,23 +41,23 @@ do
done

# Query account addresses
./client --committee committee.json --accounts accounts.json query_accounts_addrs
./client --committee committee.json --accounts accounts.json query-accounts-addrs

# Query (locally cached) object info for first and last user account
ACCOUNT1=`./client --committee committee.json --accounts accounts.json query_accounts_addrs | head -n 1`
ACCOUNT2=`./client --committee committee.json --accounts accounts.json query_accounts_addrs | tail -n -1`
./client --committee committee.json --accounts accounts.json query_objects "$ACCOUNT1"
./client --committee committee.json --accounts accounts.json query_objects "$ACCOUNT2"
ACCOUNT1=`./client --committee committee.json --accounts accounts.json query-accounts-addrs | head -n 1`
ACCOUNT2=`./client --committee committee.json --accounts accounts.json query-accounts-addrs | tail -n -1`
./client --committee committee.json --accounts accounts.json query-objects "$ACCOUNT1"
./client --committee committee.json --accounts accounts.json query-objects "$ACCOUNT2"

# Get the first ObjectId for Account1
ACCOUNT1_OBJECT1=`./client --committee committee.json --accounts accounts.json query_objects "$ACCOUNT1" | head -n 1 | awk -F: '{ print $1 }'`
ACCOUNT1_OBJECT1=`./client --committee committee.json --accounts accounts.json query-objects "$ACCOUNT1" | head -n 1 | awk -F: '{ print $1 }'`

# Transfer object by ObjectID
./client --committee committee.json --accounts accounts.json transfer "$ACCOUNT1_OBJECT1" --from "$ACCOUNT1" --to "$ACCOUNT2"

# Query objects again again
./client --committee committee.json --accounts accounts.json query_objects "$ACCOUNT1"
./client --committee committee.json --accounts accounts.json query_objects "$ACCOUNT2"
./client --committee committee.json --accounts accounts.json query-objects "$ACCOUNT1"
./client --committee committee.json --accounts accounts.json query-objects "$ACCOUNT2"

# Launch local benchmark using all user accounts
./client --committee committee.json --accounts accounts.json benchmark
Expand Down
31 changes: 17 additions & 14 deletions fastpay/src/client.rs
Original file line number Diff line number Diff line change
Expand Up @@ -291,7 +291,8 @@ fn deserialize_response(response: &[u8]) -> Option<AccountInfoResponse> {
#[derive(StructOpt)]
#[structopt(
name = "FastPay Client",
about = "A Byzantine fault tolerant payments sidechain with low-latency finality and high throughput"
about = "A Byzantine fault tolerant payments sidechain with low-latency finality and high throughput",
rename_all = "kebab-case"
)]
struct ClientOpt {
/// Sets the file storing the state of our user accounts (an empty one will be created if missing)
Expand Down Expand Up @@ -320,6 +321,7 @@ struct ClientOpt {
}

#[derive(StructOpt)]
#[structopt(rename_all = "kebab-case")]
enum ClientCommands {
/// Transfer funds
#[structopt(name = "transfer")]
Expand All @@ -337,11 +339,11 @@ enum ClientCommands {
},

/// Obtain the Account Addresses
#[structopt(name = "query_accounts_addrs")]
#[structopt(name = "query-accounts-addrs")]
QueryAccountAddresses {},

/// Obtain the Object Info
#[structopt(name = "query_objects")]
#[structopt(name = "query-objects")]
QueryObjects {
/// Address of the account
address: String,
Expand All @@ -364,19 +366,19 @@ enum ClientCommands {
},

/// Create new user accounts with randomly generated object IDs
#[structopt(name = "create_accounts")]
#[structopt(name = "create-accounts")]
CreateAccounts {
/// Number of additional accounts to create
#[structopt(long, default_value = "1000", name = "num")]
#[structopt(long, default_value = "1000")]
num: u32,

/// Number of objects per account
#[structopt(long, default_value = "1000", name = "objs-per-account")]
objs_per_account: u32,
#[structopt(long, default_value = "1000")]
gas_objs_per_account: u32,

/// Gas value per object
#[structopt(long, default_value = "1000", name = "gas-per-obj")]
gas_per_obj: u32,
#[structopt(long, default_value = "1000")]
value_per_per_obj: u32,

/// Initial state config file path
#[structopt(name = "init-state-cfg")]
Expand Down Expand Up @@ -575,27 +577,28 @@ fn main() {

ClientCommands::CreateAccounts {
num,
objs_per_account,
gas_per_obj,
gas_objs_per_account,
value_per_per_obj,
initial_state_config_path,
} => {
let num_accounts: u32 = num;
let mut init_state_cfg: InitialStateConfig = InitialStateConfig::new();

for _ in 0..num_accounts {
let obj_ids = create_random_object_ids(objs_per_account);
let obj_ids = create_random_object_ids(gas_objs_per_account);
let account = UserAccount::new(obj_ids.clone());

init_state_cfg.config.push(InitialStateConfigEntry {
address: account.address,
object_ids: obj_ids.clone(),
});

// TODO: Integrate gas logic with https://github.com/MystenLabs/fastnft/pull/97
println!(
"{}:{:?}, with gas {}",
"{}: gas object IDs {:?}, with value {}",
encode_address(&account.address),
obj_ids,
gas_per_obj
value_per_per_obj
);
accounts_config.insert(account);
}
Expand Down

0 comments on commit ca61f9d

Please sign in to comment.