Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions Cargo.lock

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

4 changes: 4 additions & 0 deletions bench-tps/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,10 @@ solana-metrics = { path = "../metrics", version = "0.17.0" }
solana-netutil = { path = "../netutil", version = "0.17.0" }
solana-runtime = { path = "../runtime", version = "0.17.0" }
solana-sdk = { path = "../sdk", version = "0.17.0" }
types = { git = "https://github.com/solana-labs/libra", branch = "solana-0.0.0" }
compiler = { git = "https://github.com/solana-labs/libra", branch = "solana-0.0.0" }
bincode = "1.1.4"
solana-move-loader-api = { path = "../programs/move_loader_api", version = "0.17.0" }

[features]
cuda = ["solana/cuda"]
Expand Down
116 changes: 111 additions & 5 deletions bench-tps/src/bench.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
use solana_metrics;

#[macro_use]
extern crate solana_move_loader_api;

use log::*;
use rayon::prelude::*;
use solana::gen_keys::GenKeys;
Expand All @@ -24,6 +27,15 @@ use std::thread::Builder;
use std::time::Duration;
use std::time::Instant;

use bincode;
use compiler::Compiler;
use solana_runtime::loader_utils::load_program;
use solana_sdk::instruction::{AccountMeta, Instruction};
use solana_sdk::loader_instruction::LoaderInstruction;
use solana_sdk::pubkey::Pubkey;
use types::account_address::AccountAddress;
use types::transaction::{Program, TransactionArgument};

pub const MAX_SPENDS_PER_TX: u64 = 4;
pub const NUM_LAMPORTS_PER_ACCOUNT: u64 = 128;

Expand All @@ -32,6 +44,79 @@ pub enum BenchTpsError {
AirdropFailure,
}

const USE_MOVE: bool = true;

fn new_move_transaction(
program_id: &Pubkey,
from: &Keypair,
recent_blockhash: Hash,
args: Vec<TransactionArgument>,
) -> Transaction {
let data = bincode::serialize(&args).unwrap();
let ix = LoaderInstruction::InvokeMain { data };
let ix_data = bincode::serialize(&ix).unwrap();

let accounts = vec![AccountMeta::new(from.pubkey(), true)];

let ixs = vec![Instruction::new(*program_id, &ix_data, accounts)];
Transaction::new_signed_instructions(&[from], ixs, recent_blockhash)
}

fn upload_move_program<T: Client>(from: &Keypair, client: &Arc<T>) -> Pubkey {
let code = "//! no-execute

// A small variant of the peer-peer payment example that creates a fresh
// account if one does not already exist.

import 0x0.LibraAccount;
import 0x0.LibraCoin;
main(payee: address, amount: u64) {
let coin: R#LibraCoin.T;
let account_exists: bool;

// Acquire a LibraCoin.T resource with value `amount` from the sender's
// account. This will fail if the sender's balance is less than `amount`.
coin = LibraAccount.withdraw_from_sender(move(amount));

account_exists = LibraAccount.exists(copy(payee));

if (!move(account_exists)) {
// Creates a fresh account at the address `payee` by publishing a
// LibraAccount.T resource under this address. If there is already a
// LibraAccount.T resource under the address, this will fail.
create_account(copy(payee));
}

LibraAccount.deposit(move(payee), move(coin));
return;
}";

let address = AccountAddress::default();
let compiler = Compiler {
code,
address,
..Compiler::default()
};
let compiled_program = compiler.into_compiled_program().expect("Failed to compile");

let mut script = vec![];
compiled_program
.script
.serialize(&mut script)
.expect("Unable to serialize script");
let mut modules = vec![];
for m in compiled_program.modules.iter() {
let mut buf = vec![];
m.serialize(&mut buf).expect("Unable to serialize module");
modules.push(buf);
}

let program = Program::new(script, modules, vec![]);
let program_bytes = serde_json::to_vec(&program).unwrap();

load_program(client, &from, &solana_move_loader_api::id(), program_bytes)
}

pub type Result<T> = std::result::Result<T, BenchTpsError>;

pub type SharedTransactions = Arc<RwLock<VecDeque<Vec<(Transaction, u64)>>>>;
Expand Down Expand Up @@ -87,6 +172,12 @@ where

let exit_signal = Arc::new(AtomicBool::new(false));

let program_id = if USE_MOVE {
upload_move_program(&keypairs[0], client)
} else {
Pubkey::default()
};

// Setup a thread per validator to sample every period
// collect the max transaction rate and total tx count seen
let maxes = Arc::new(RwLock::new(Vec::new()));
Expand Down Expand Up @@ -165,6 +256,7 @@ where
&keypairs[len..],
threads,
reclaim_lamports_back_to_source_account,
&program_id,
);
// In sustained mode overlap the transfers with generation
// this has higher average performance but lower peak performance
Expand Down Expand Up @@ -228,6 +320,7 @@ fn generate_txs(
dest: &[Keypair],
threads: usize,
reclaim: bool,
program_id: &Pubkey,
) {
let tx_count = source.len();
println!("Signing transactions... {} (reclaim={})", tx_count, reclaim);
Expand All @@ -241,10 +334,23 @@ fn generate_txs(
let transactions: Vec<_> = pairs
.par_iter()
.map(|(id, keypair)| {
(
system_transaction::create_user_account(id, &keypair.pubkey(), 1, *blockhash),
timestamp(),
)
if USE_MOVE {
let mut pubkey = [0u8; 32];
pubkey.copy_from_slice(&id.pubkey().as_ref());
let args = vec![
TransactionArgument::Address(AccountAddress::new(pubkey)),
TransactionArgument::U64(1),
];
(
new_move_transaction(program_id, &keypair, *blockhash, args),
timestamp(),
)
} else {
(
system_transaction::create_user_account(id, &keypair.pubkey(), 1, *blockhash),
timestamp(),
)
}
})
.collect();

Expand Down Expand Up @@ -695,7 +801,7 @@ mod tests {

let mut config = Config::default();
config.tx_count = 100;
config.duration = Duration::from_secs(5);
config.duration = Duration::from_secs(10);

let client = create_client(
(cluster.entry_point_info.rpc, cluster.entry_point_info.tpu),
Expand Down
2 changes: 2 additions & 0 deletions core/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,8 @@ solana-stake-api = { path = "../programs/stake_api", version = "0.17.0" }
solana-stake-program = { path = "../programs/stake_program", version = "0.17.0" }
solana-storage-api = { path = "../programs/storage_api", version = "0.17.0" }
solana-storage-program = { path = "../programs/storage_program", version = "0.17.0" }
solana-move-loader-program = { path = "../programs/move_loader_program", version = "0.17.0" }
solana-move-loader-api = { path = "../programs/move_loader_api", version = "0.17.0" }
solana-vote-api = { path = "../programs/vote_api", version = "0.17.0" }
solana-vote-program = { path = "../programs/vote_program", version = "0.17.0" }
solana-vote-signer = { path = "../vote-signer", version = "0.17.0" }
Expand Down
3 changes: 3 additions & 0 deletions core/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -101,3 +101,6 @@ extern crate solana_metrics;
extern crate matches;

extern crate crossbeam_channel;

#[macro_use]
extern crate solana_move_loader_program;
5 changes: 5 additions & 0 deletions core/src/local_cluster.rs
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,8 @@ use std::fs::remove_dir_all;
use std::io::{Error, ErrorKind, Result};
use std::sync::Arc;

use solana_move_loader_api;

pub struct ValidatorInfo {
pub keypair: Arc<Keypair>,
pub voting_keypair: Arc<Keypair>,
Expand Down Expand Up @@ -164,6 +166,9 @@ impl LocalCluster {
genesis_block
.native_instruction_processors
.push(solana_storage_program!());
genesis_block
.native_instruction_processors
.push(solana_move_loader_program!());

let (leader_ledger_path, _blockhash) = create_new_tmp_ledger!(&genesis_block);
let leader_contact_info = leader_node.info.clone();
Expand Down
9 changes: 5 additions & 4 deletions runtime/src/loader_utils.rs
Original file line number Diff line number Diff line change
@@ -1,15 +1,16 @@
use crate::bank_client::BankClient;
use log::*;
use serde::Serialize;
use solana_sdk::client::SyncClient;
use solana_sdk::client::Client;
use solana_sdk::instruction::{AccountMeta, Instruction};
use solana_sdk::loader_instruction;
use solana_sdk::message::Message;
use solana_sdk::pubkey::Pubkey;
use solana_sdk::signature::{Keypair, KeypairUtil};
use solana_sdk::system_instruction;
use std::sync::Arc;

pub fn load_program(
bank_client: &BankClient,
pub fn load_program<T: Client>(
bank_client: &Arc<T>,
from_keypair: &Keypair,
loader_pubkey: &Pubkey,
program: Vec<u8>,
Expand Down