Update Move support to accomadate Libra's changes to compiler behavior (#6993)

This commit is contained in:
Jack May 2019-11-18 16:47:01 -08:00 committed by GitHub
parent cbf7c0080b
commit 6ec918fabb
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
13 changed files with 475 additions and 540 deletions

View File

@ -5,7 +5,7 @@ use solana_client::perf_utils::{sample_txs, SampleStats};
use solana_core::gen_keys::GenKeys; use solana_core::gen_keys::GenKeys;
use solana_drone::drone::request_airdrop_transaction; use solana_drone::drone::request_airdrop_transaction;
#[cfg(feature = "move")] #[cfg(feature = "move")]
use solana_librapay_api::{create_genesis, upload_mint_program, upload_payment_program}; use solana_librapay_api::{create_genesis, upload_mint_script, upload_payment_script};
use solana_measure::measure::Measure; use solana_measure::measure::Measure;
use solana_metrics::{self, datapoint_debug}; use solana_metrics::{self, datapoint_debug};
use solana_sdk::{ use solana_sdk::{
@ -789,7 +789,7 @@ fn fund_move_keys<T: Client>(
total: u64, total: u64,
libra_pay_program_id: &Pubkey, libra_pay_program_id: &Pubkey,
libra_mint_program_id: &Pubkey, libra_mint_program_id: &Pubkey,
libra_mint_key: &Keypair, libra_genesis_key: &Keypair,
) { ) {
let (mut blockhash, _fee_calculator) = get_recent_blockhash(client); let (mut blockhash, _fee_calculator) = get_recent_blockhash(client);
@ -804,17 +804,18 @@ fn fund_move_keys<T: Client>(
let tx = librapay_transaction::mint_tokens( let tx = librapay_transaction::mint_tokens(
&libra_mint_program_id, &libra_mint_program_id,
funding_key, funding_key,
libra_mint_key, libra_genesis_key,
&libra_funding_key.pubkey(), &libra_funding_key.pubkey(),
total, total,
blockhash, blockhash,
); );
client client
.send_message(&[funding_key, libra_mint_key], tx.message) .send_message(&[funding_key, libra_genesis_key], tx.message)
.unwrap(); .unwrap();
info!("creating {} move accounts...", keypairs.len()); info!("creating {} move accounts...", keypairs.len());
let create_len = 8; let total_len = keypairs.len();
let create_len = 5;
let mut funding_time = Measure::start("funding_time"); let mut funding_time = Measure::start("funding_time");
for (i, keys) in keypairs.chunks(create_len).enumerate() { for (i, keys) in keypairs.chunks(create_len).enumerate() {
if client if client
@ -828,24 +829,22 @@ fn fund_move_keys<T: Client>(
let keypairs: Vec<_> = keys.iter().map(|k| k).collect(); let keypairs: Vec<_> = keys.iter().map(|k| k).collect();
let tx = librapay_transaction::create_accounts(funding_key, &keypairs, 1, blockhash); let tx = librapay_transaction::create_accounts(funding_key, &keypairs, 1, blockhash);
let ser_size = bincode::serialized_size(&tx).unwrap(); let ser_size = bincode::serialized_size(&tx).unwrap();
let mut keys = vec![funding_key];
client.send_message(&[funding_key], tx.message).unwrap(); keys.extend(&keypairs);
client.send_message(&keys, tx.message).unwrap();
if i % 10 == 0 { if i % 10 == 0 {
info!( info!(
"size: {} created {} accounts of {}", "created {} accounts of {} (size {})",
ser_size,
i, i,
(keypairs.len() / create_len), total_len / create_len,
ser_size,
); );
} }
} }
funding_time.stop();
info!("funding accounts {}ms", funding_time.as_ms());
const NUM_FUNDING_KEYS: usize = 4; const NUM_FUNDING_KEYS: usize = 10;
let funding_keys: Vec<_> = (0..NUM_FUNDING_KEYS).map(|_| Keypair::new()).collect(); let funding_keys: Vec<_> = (0..NUM_FUNDING_KEYS).map(|_| Keypair::new()).collect();
let pubkey_amounts: Vec<_> = funding_keys let pubkey_amounts: Vec<_> = funding_keys
.iter() .iter()
@ -870,7 +869,10 @@ fn fund_move_keys<T: Client>(
sleep(Duration::from_millis(100)); sleep(Duration::from_millis(100));
} }
assert!(balance > 0); assert!(balance > 0);
info!("funded multiple funding accounts.. {:?}", balance); info!(
"funded multiple funding accounts with {:?} lanports",
balance
);
let libra_funding_keys: Vec<_> = (0..NUM_FUNDING_KEYS).map(|_| Keypair::new()).collect(); let libra_funding_keys: Vec<_> = (0..NUM_FUNDING_KEYS).map(|_| Keypair::new()).collect();
for (i, key) in libra_funding_keys.iter().enumerate() { for (i, key) in libra_funding_keys.iter().enumerate() {
@ -881,7 +883,7 @@ fn fund_move_keys<T: Client>(
let tx = librapay_transaction::transfer( let tx = librapay_transaction::transfer(
libra_pay_program_id, libra_pay_program_id,
&libra_mint_key.pubkey(), &libra_genesis_key.pubkey(),
&funding_keys[i], &funding_keys[i],
&libra_funding_key, &libra_funding_key,
&key.pubkey(), &key.pubkey(),
@ -901,7 +903,7 @@ fn fund_move_keys<T: Client>(
for (j, key) in keys.iter().enumerate() { for (j, key) in keys.iter().enumerate() {
let tx = librapay_transaction::transfer( let tx = librapay_transaction::transfer(
libra_pay_program_id, libra_pay_program_id,
&libra_mint_key.pubkey(), &libra_genesis_key.pubkey(),
&funding_keys[j], &funding_keys[j],
&libra_funding_keys[j], &libra_funding_keys[j],
&key.pubkey(), &key.pubkey(),
@ -914,7 +916,6 @@ fn fund_move_keys<T: Client>(
.expect("create_account in generate_and_fund_keypairs"); .expect("create_account in generate_and_fund_keypairs");
} }
info!("sent... checking balance {}", i);
for (j, key) in keys.iter().enumerate() { for (j, key) in keys.iter().enumerate() {
let mut times = 0; let mut times = 0;
loop { loop {
@ -932,11 +933,16 @@ fn fund_move_keys<T: Client>(
} }
} }
info!("funded: {} of {}", i, keypairs.len() / NUM_FUNDING_KEYS); info!(
"funded group {} of {}",
i + 1,
keypairs.len() / NUM_FUNDING_KEYS
);
blockhash = get_recent_blockhash(client).0; blockhash = get_recent_blockhash(client).0;
} }
info!("done funding keys.."); funding_time.stop();
info!("done funding keys, took {} ms", funding_time.as_ms());
} }
pub fn generate_and_fund_keypairs<T: Client>( pub fn generate_and_fund_keypairs<T: Client>(
@ -986,8 +992,8 @@ pub fn generate_and_fund_keypairs<T: Client>(
{ {
if use_move { if use_move {
let libra_genesis_keypair = create_genesis(&funding_key, client, 10_000_000); let libra_genesis_keypair = create_genesis(&funding_key, client, 10_000_000);
let libra_mint_program_id = upload_mint_program(&funding_key, client); let libra_mint_program_id = upload_mint_script(&funding_key, client);
let libra_pay_program_id = upload_payment_program(&funding_key, client); let libra_pay_program_id = upload_payment_script(&funding_key, client);
// Generate another set of keypairs for move accounts. // Generate another set of keypairs for move accounts.
// Still fund the solana ones which will be used for fees. // Still fund the solana ones which will be used for fees.

View File

@ -57,8 +57,10 @@ fn test_bench_tps_local_cluster(config: Config) {
) )
.unwrap(); .unwrap();
let total = do_bench_tps(vec![client], config, keypairs, 0, move_keypairs); let _total = do_bench_tps(vec![client], config, keypairs, 0, move_keypairs);
assert!(total > 100);
#[cfg(not(debug_assertions))]
assert!(_total > 100);
} }
#[test] #[test]
@ -71,12 +73,12 @@ fn test_bench_tps_local_cluster_solana() {
test_bench_tps_local_cluster(config); test_bench_tps_local_cluster(config);
} }
#[ignore]
#[test] #[test]
#[serial]
fn test_bench_tps_local_cluster_move() { fn test_bench_tps_local_cluster_move() {
let mut config = Config::default(); let mut config = Config::default();
config.tx_count = 100; config.tx_count = 100;
config.duration = Duration::from_secs(25); config.duration = Duration::from_secs(10);
config.use_move = true; config.use_move = true;
test_bench_tps_local_cluster(config); test_bench_tps_local_cluster(config);

View File

@ -251,7 +251,6 @@ dependencies = [
"libc 0.2.65 (registry+https://github.com/rust-lang/crates.io-index)", "libc 0.2.65 (registry+https://github.com/rust-lang/crates.io-index)",
"num-integer 0.1.41 (registry+https://github.com/rust-lang/crates.io-index)", "num-integer 0.1.41 (registry+https://github.com/rust-lang/crates.io-index)",
"num-traits 0.2.8 (registry+https://github.com/rust-lang/crates.io-index)", "num-traits 0.2.8 (registry+https://github.com/rust-lang/crates.io-index)",
"serde 1.0.102 (registry+https://github.com/rust-lang/crates.io-index)",
"time 0.1.42 (registry+https://github.com/rust-lang/crates.io-index)", "time 0.1.42 (registry+https://github.com/rust-lang/crates.io-index)",
] ]
@ -1818,7 +1817,6 @@ dependencies = [
"bincode 1.2.0 (registry+https://github.com/rust-lang/crates.io-index)", "bincode 1.2.0 (registry+https://github.com/rust-lang/crates.io-index)",
"bs58 0.3.0 (registry+https://github.com/rust-lang/crates.io-index)", "bs58 0.3.0 (registry+https://github.com/rust-lang/crates.io-index)",
"byteorder 1.3.2 (registry+https://github.com/rust-lang/crates.io-index)", "byteorder 1.3.2 (registry+https://github.com/rust-lang/crates.io-index)",
"chrono 0.4.9 (registry+https://github.com/rust-lang/crates.io-index)",
"ed25519-dalek 1.0.0-pre.2 (registry+https://github.com/rust-lang/crates.io-index)", "ed25519-dalek 1.0.0-pre.2 (registry+https://github.com/rust-lang/crates.io-index)",
"generic-array 0.13.2 (registry+https://github.com/rust-lang/crates.io-index)", "generic-array 0.13.2 (registry+https://github.com/rust-lang/crates.io-index)",
"hex 0.4.0 (registry+https://github.com/rust-lang/crates.io-index)", "hex 0.4.0 (registry+https://github.com/rust-lang/crates.io-index)",
@ -1829,7 +1827,6 @@ dependencies = [
"num-traits 0.2.8 (registry+https://github.com/rust-lang/crates.io-index)", "num-traits 0.2.8 (registry+https://github.com/rust-lang/crates.io-index)",
"rand 0.6.5 (registry+https://github.com/rust-lang/crates.io-index)", "rand 0.6.5 (registry+https://github.com/rust-lang/crates.io-index)",
"rand_chacha 0.1.1 (registry+https://github.com/rust-lang/crates.io-index)", "rand_chacha 0.1.1 (registry+https://github.com/rust-lang/crates.io-index)",
"rayon 1.2.0 (registry+https://github.com/rust-lang/crates.io-index)",
"serde 1.0.102 (registry+https://github.com/rust-lang/crates.io-index)", "serde 1.0.102 (registry+https://github.com/rust-lang/crates.io-index)",
"serde_bytes 0.11.2 (registry+https://github.com/rust-lang/crates.io-index)", "serde_bytes 0.11.2 (registry+https://github.com/rust-lang/crates.io-index)",
"serde_derive 1.0.102 (registry+https://github.com/rust-lang/crates.io-index)", "serde_derive 1.0.102 (registry+https://github.com/rust-lang/crates.io-index)",
@ -1837,7 +1834,6 @@ dependencies = [
"sha2 0.8.0 (registry+https://github.com/rust-lang/crates.io-index)", "sha2 0.8.0 (registry+https://github.com/rust-lang/crates.io-index)",
"solana-crate-features 0.21.0", "solana-crate-features 0.21.0",
"solana-logger 0.21.0", "solana-logger 0.21.0",
"untrusted 0.7.0 (registry+https://github.com/rust-lang/crates.io-index)",
] ]
[[package]] [[package]]
@ -1876,7 +1872,6 @@ dependencies = [
name = "solana-storage-api" name = "solana-storage-api"
version = "0.21.0" version = "0.21.0"
dependencies = [ dependencies = [
"assert_matches 1.3.0 (registry+https://github.com/rust-lang/crates.io-index)",
"bincode 1.2.0 (registry+https://github.com/rust-lang/crates.io-index)", "bincode 1.2.0 (registry+https://github.com/rust-lang/crates.io-index)",
"log 0.4.8 (registry+https://github.com/rust-lang/crates.io-index)", "log 0.4.8 (registry+https://github.com/rust-lang/crates.io-index)",
"num-derive 0.3.0 (registry+https://github.com/rust-lang/crates.io-index)", "num-derive 0.3.0 (registry+https://github.com/rust-lang/crates.io-index)",

View File

@ -21,11 +21,6 @@ dependencies = [
"winapi 0.3.8 (registry+https://github.com/rust-lang/crates.io-index)", "winapi 0.3.8 (registry+https://github.com/rust-lang/crates.io-index)",
] ]
[[package]]
name = "approx"
version = "0.1.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
[[package]] [[package]]
name = "ar" name = "ar"
version = "0.6.2" version = "0.6.2"
@ -289,16 +284,6 @@ name = "cfg-if"
version = "0.1.10" version = "0.1.10"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
[[package]]
name = "cgmath"
version = "0.16.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
dependencies = [
"approx 0.1.1 (registry+https://github.com/rust-lang/crates.io-index)",
"num-traits 0.1.43 (registry+https://github.com/rust-lang/crates.io-index)",
"rand 0.4.6 (registry+https://github.com/rust-lang/crates.io-index)",
]
[[package]] [[package]]
name = "chashmap" name = "chashmap"
version = "2.2.2" version = "2.2.2"
@ -316,7 +301,6 @@ dependencies = [
"libc 0.2.65 (registry+https://github.com/rust-lang/crates.io-index)", "libc 0.2.65 (registry+https://github.com/rust-lang/crates.io-index)",
"num-integer 0.1.41 (registry+https://github.com/rust-lang/crates.io-index)", "num-integer 0.1.41 (registry+https://github.com/rust-lang/crates.io-index)",
"num-traits 0.2.8 (registry+https://github.com/rust-lang/crates.io-index)", "num-traits 0.2.8 (registry+https://github.com/rust-lang/crates.io-index)",
"serde 1.0.102 (registry+https://github.com/rust-lang/crates.io-index)",
"time 0.1.42 (registry+https://github.com/rust-lang/crates.io-index)", "time 0.1.42 (registry+https://github.com/rust-lang/crates.io-index)",
] ]
@ -370,11 +354,12 @@ dependencies = [
[[package]] [[package]]
name = "colored" name = "colored"
version = "1.8.0" version = "1.9.0"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
dependencies = [ dependencies = [
"atty 0.2.13 (registry+https://github.com/rust-lang/crates.io-index)",
"lazy_static 1.4.0 (registry+https://github.com/rust-lang/crates.io-index)", "lazy_static 1.4.0 (registry+https://github.com/rust-lang/crates.io-index)",
"winconsole 0.10.0 (registry+https://github.com/rust-lang/crates.io-index)", "winapi 0.3.8 (registry+https://github.com/rust-lang/crates.io-index)",
] ]
[[package]] [[package]]
@ -630,7 +615,7 @@ dependencies = [
"bloom 0.3.2 (registry+https://github.com/rust-lang/crates.io-index)", "bloom 0.3.2 (registry+https://github.com/rust-lang/crates.io-index)",
"byteorder 1.3.2 (registry+https://github.com/rust-lang/crates.io-index)", "byteorder 1.3.2 (registry+https://github.com/rust-lang/crates.io-index)",
"clap 2.33.0 (registry+https://github.com/rust-lang/crates.io-index)", "clap 2.33.0 (registry+https://github.com/rust-lang/crates.io-index)",
"colored 1.8.0 (registry+https://github.com/rust-lang/crates.io-index)", "colored 1.9.0 (registry+https://github.com/rust-lang/crates.io-index)",
"enum-primitive-derive 0.1.2 (registry+https://github.com/rust-lang/crates.io-index)", "enum-primitive-derive 0.1.2 (registry+https://github.com/rust-lang/crates.io-index)",
"env_logger 0.5.13 (registry+https://github.com/rust-lang/crates.io-index)", "env_logger 0.5.13 (registry+https://github.com/rust-lang/crates.io-index)",
"fnv 1.0.6 (registry+https://github.com/rust-lang/crates.io-index)", "fnv 1.0.6 (registry+https://github.com/rust-lang/crates.io-index)",
@ -901,7 +886,7 @@ dependencies = [
[[package]] [[package]]
name = "hash32" name = "hash32"
version = "0.1.0" version = "0.1.1"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
dependencies = [ dependencies = [
"byteorder 1.3.2 (registry+https://github.com/rust-lang/crates.io-index)", "byteorder 1.3.2 (registry+https://github.com/rust-lang/crates.io-index)",
@ -1999,11 +1984,6 @@ dependencies = [
"winreg 0.6.2 (registry+https://github.com/rust-lang/crates.io-index)", "winreg 0.6.2 (registry+https://github.com/rust-lang/crates.io-index)",
] ]
[[package]]
name = "rgb"
version = "0.8.14"
source = "registry+https://github.com/rust-lang/crates.io-index"
[[package]] [[package]]
name = "ring" name = "ring"
version = "0.16.9" version = "0.16.9"
@ -2316,6 +2296,7 @@ dependencies = [
"bytes 0.4.12 (registry+https://github.com/rust-lang/crates.io-index)", "bytes 0.4.12 (registry+https://github.com/rust-lang/crates.io-index)",
"cc 1.0.46 (registry+https://github.com/rust-lang/crates.io-index)", "cc 1.0.46 (registry+https://github.com/rust-lang/crates.io-index)",
"curve25519-dalek 1.2.3 (registry+https://github.com/rust-lang/crates.io-index)", "curve25519-dalek 1.2.3 (registry+https://github.com/rust-lang/crates.io-index)",
"ed25519-dalek 1.0.0-pre.1 (registry+https://github.com/rust-lang/crates.io-index)",
"either 1.5.3 (registry+https://github.com/rust-lang/crates.io-index)", "either 1.5.3 (registry+https://github.com/rust-lang/crates.io-index)",
"failure 0.1.6 (registry+https://github.com/rust-lang/crates.io-index)", "failure 0.1.6 (registry+https://github.com/rust-lang/crates.io-index)",
"lazy_static 1.4.0 (registry+https://github.com/rust-lang/crates.io-index)", "lazy_static 1.4.0 (registry+https://github.com/rust-lang/crates.io-index)",
@ -2324,26 +2305,12 @@ dependencies = [
"regex-syntax 0.6.12 (registry+https://github.com/rust-lang/crates.io-index)", "regex-syntax 0.6.12 (registry+https://github.com/rust-lang/crates.io-index)",
"reqwest 0.9.22 (registry+https://github.com/rust-lang/crates.io-index)", "reqwest 0.9.22 (registry+https://github.com/rust-lang/crates.io-index)",
"serde 1.0.102 (registry+https://github.com/rust-lang/crates.io-index)", "serde 1.0.102 (registry+https://github.com/rust-lang/crates.io-index)",
"solana-ed25519-dalek 0.2.0 (registry+https://github.com/rust-lang/crates.io-index)",
"syn 0.15.44 (registry+https://github.com/rust-lang/crates.io-index)", "syn 0.15.44 (registry+https://github.com/rust-lang/crates.io-index)",
"syn 1.0.7 (registry+https://github.com/rust-lang/crates.io-index)", "syn 1.0.7 (registry+https://github.com/rust-lang/crates.io-index)",
"tokio 0.1.22 (registry+https://github.com/rust-lang/crates.io-index)", "tokio 0.1.22 (registry+https://github.com/rust-lang/crates.io-index)",
"winapi 0.3.8 (registry+https://github.com/rust-lang/crates.io-index)", "winapi 0.3.8 (registry+https://github.com/rust-lang/crates.io-index)",
] ]
[[package]]
name = "solana-ed25519-dalek"
version = "0.2.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
dependencies = [
"clear_on_drop 0.2.3 (registry+https://github.com/rust-lang/crates.io-index)",
"curve25519-dalek 1.2.3 (registry+https://github.com/rust-lang/crates.io-index)",
"failure 0.1.6 (registry+https://github.com/rust-lang/crates.io-index)",
"rand 0.6.5 (registry+https://github.com/rust-lang/crates.io-index)",
"serde 1.0.102 (registry+https://github.com/rust-lang/crates.io-index)",
"sha2 0.8.0 (registry+https://github.com/rust-lang/crates.io-index)",
]
[[package]] [[package]]
name = "solana-librapay-api" name = "solana-librapay-api"
version = "0.21.0" version = "0.21.0"
@ -2467,7 +2434,7 @@ dependencies = [
"bincode 1.2.0 (registry+https://github.com/rust-lang/crates.io-index)", "bincode 1.2.0 (registry+https://github.com/rust-lang/crates.io-index)",
"bs58 0.3.0 (registry+https://github.com/rust-lang/crates.io-index)", "bs58 0.3.0 (registry+https://github.com/rust-lang/crates.io-index)",
"byteorder 1.3.2 (registry+https://github.com/rust-lang/crates.io-index)", "byteorder 1.3.2 (registry+https://github.com/rust-lang/crates.io-index)",
"chrono 0.4.9 (registry+https://github.com/rust-lang/crates.io-index)", "ed25519-dalek 1.0.0-pre.1 (registry+https://github.com/rust-lang/crates.io-index)",
"generic-array 0.13.2 (registry+https://github.com/rust-lang/crates.io-index)", "generic-array 0.13.2 (registry+https://github.com/rust-lang/crates.io-index)",
"hex 0.4.0 (registry+https://github.com/rust-lang/crates.io-index)", "hex 0.4.0 (registry+https://github.com/rust-lang/crates.io-index)",
"itertools 0.8.1 (registry+https://github.com/rust-lang/crates.io-index)", "itertools 0.8.1 (registry+https://github.com/rust-lang/crates.io-index)",
@ -2477,16 +2444,13 @@ dependencies = [
"num-traits 0.2.8 (registry+https://github.com/rust-lang/crates.io-index)", "num-traits 0.2.8 (registry+https://github.com/rust-lang/crates.io-index)",
"rand 0.6.5 (registry+https://github.com/rust-lang/crates.io-index)", "rand 0.6.5 (registry+https://github.com/rust-lang/crates.io-index)",
"rand_chacha 0.1.1 (registry+https://github.com/rust-lang/crates.io-index)", "rand_chacha 0.1.1 (registry+https://github.com/rust-lang/crates.io-index)",
"rayon 1.2.0 (registry+https://github.com/rust-lang/crates.io-index)",
"serde 1.0.102 (registry+https://github.com/rust-lang/crates.io-index)", "serde 1.0.102 (registry+https://github.com/rust-lang/crates.io-index)",
"serde_bytes 0.11.2 (registry+https://github.com/rust-lang/crates.io-index)", "serde_bytes 0.11.2 (registry+https://github.com/rust-lang/crates.io-index)",
"serde_derive 1.0.102 (registry+https://github.com/rust-lang/crates.io-index)", "serde_derive 1.0.102 (registry+https://github.com/rust-lang/crates.io-index)",
"serde_json 1.0.41 (registry+https://github.com/rust-lang/crates.io-index)", "serde_json 1.0.41 (registry+https://github.com/rust-lang/crates.io-index)",
"sha2 0.8.0 (registry+https://github.com/rust-lang/crates.io-index)", "sha2 0.8.0 (registry+https://github.com/rust-lang/crates.io-index)",
"solana-crate-features 0.21.0", "solana-crate-features 0.21.0",
"solana-ed25519-dalek 0.2.0 (registry+https://github.com/rust-lang/crates.io-index)",
"solana-logger 0.21.0", "solana-logger 0.21.0",
"untrusted 0.7.0 (registry+https://github.com/rust-lang/crates.io-index)",
] ]
[[package]] [[package]]
@ -2521,7 +2485,6 @@ dependencies = [
name = "solana-storage-api" name = "solana-storage-api"
version = "0.21.0" version = "0.21.0"
dependencies = [ dependencies = [
"assert_matches 1.3.0 (registry+https://github.com/rust-lang/crates.io-index)",
"bincode 1.2.0 (registry+https://github.com/rust-lang/crates.io-index)", "bincode 1.2.0 (registry+https://github.com/rust-lang/crates.io-index)",
"log 0.4.8 (registry+https://github.com/rust-lang/crates.io-index)", "log 0.4.8 (registry+https://github.com/rust-lang/crates.io-index)",
"num-derive 0.3.0 (registry+https://github.com/rust-lang/crates.io-index)", "num-derive 0.3.0 (registry+https://github.com/rust-lang/crates.io-index)",
@ -2959,7 +2922,7 @@ dependencies = [
"byteorder 1.3.2 (registry+https://github.com/rust-lang/crates.io-index)", "byteorder 1.3.2 (registry+https://github.com/rust-lang/crates.io-index)",
"combine 2.5.2 (registry+https://github.com/rust-lang/crates.io-index)", "combine 2.5.2 (registry+https://github.com/rust-lang/crates.io-index)",
"elfkit 0.0.6 (registry+https://github.com/rust-lang/crates.io-index)", "elfkit 0.0.6 (registry+https://github.com/rust-lang/crates.io-index)",
"hash32 0.1.0 (registry+https://github.com/rust-lang/crates.io-index)", "hash32 0.1.1 (registry+https://github.com/rust-lang/crates.io-index)",
"libc 0.2.65 (registry+https://github.com/rust-lang/crates.io-index)", "libc 0.2.65 (registry+https://github.com/rust-lang/crates.io-index)",
"log 0.4.8 (registry+https://github.com/rust-lang/crates.io-index)", "log 0.4.8 (registry+https://github.com/rust-lang/crates.io-index)",
"num-traits 0.2.8 (registry+https://github.com/rust-lang/crates.io-index)", "num-traits 0.2.8 (registry+https://github.com/rust-lang/crates.io-index)",
@ -3736,17 +3699,6 @@ dependencies = [
"winapi-util 0.1.2 (registry+https://github.com/rust-lang/crates.io-index)", "winapi-util 0.1.2 (registry+https://github.com/rust-lang/crates.io-index)",
] ]
[[package]]
name = "winconsole"
version = "0.10.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
dependencies = [
"cgmath 0.16.1 (registry+https://github.com/rust-lang/crates.io-index)",
"lazy_static 1.4.0 (registry+https://github.com/rust-lang/crates.io-index)",
"rgb 0.8.14 (registry+https://github.com/rust-lang/crates.io-index)",
"winapi 0.3.8 (registry+https://github.com/rust-lang/crates.io-index)",
]
[[package]] [[package]]
name = "winreg" name = "winreg"
version = "0.6.2" version = "0.6.2"
@ -3778,7 +3730,6 @@ dependencies = [
"checksum adler32 1.0.4 (registry+https://github.com/rust-lang/crates.io-index)" = "5d2e7343e7fc9de883d1b0341e0b13970f764c14101234857d2ddafa1cb1cac2" "checksum adler32 1.0.4 (registry+https://github.com/rust-lang/crates.io-index)" = "5d2e7343e7fc9de883d1b0341e0b13970f764c14101234857d2ddafa1cb1cac2"
"checksum aho-corasick 0.7.6 (registry+https://github.com/rust-lang/crates.io-index)" = "58fb5e95d83b38284460a5fda7d6470aa0b8844d283a0b614b8535e880800d2d" "checksum aho-corasick 0.7.6 (registry+https://github.com/rust-lang/crates.io-index)" = "58fb5e95d83b38284460a5fda7d6470aa0b8844d283a0b614b8535e880800d2d"
"checksum ansi_term 0.11.0 (registry+https://github.com/rust-lang/crates.io-index)" = "ee49baf6cb617b853aa8d93bf420db2383fab46d314482ca2803b40d5fde979b" "checksum ansi_term 0.11.0 (registry+https://github.com/rust-lang/crates.io-index)" = "ee49baf6cb617b853aa8d93bf420db2383fab46d314482ca2803b40d5fde979b"
"checksum approx 0.1.1 (registry+https://github.com/rust-lang/crates.io-index)" = "08abcc3b4e9339e33a3d0a5ed15d84a687350c05689d825e0f6655eef9e76a94"
"checksum ar 0.6.2 (registry+https://github.com/rust-lang/crates.io-index)" = "579681b3fecd1e9d6b5ce6969e05f9feb913f296eddaf595be1166a5ca597bc4" "checksum ar 0.6.2 (registry+https://github.com/rust-lang/crates.io-index)" = "579681b3fecd1e9d6b5ce6969e05f9feb913f296eddaf595be1166a5ca597bc4"
"checksum arc-swap 0.4.3 (registry+https://github.com/rust-lang/crates.io-index)" = "f1a1eca3195b729bbd64e292ef2f5fff6b1c28504fed762ce2b1013dde4d8e92" "checksum arc-swap 0.4.3 (registry+https://github.com/rust-lang/crates.io-index)" = "f1a1eca3195b729bbd64e292ef2f5fff6b1c28504fed762ce2b1013dde4d8e92"
"checksum arrayref 0.3.5 (registry+https://github.com/rust-lang/crates.io-index)" = "0d382e583f07208808f6b1249e60848879ba3543f57c32277bf52d69c2f0f0ee" "checksum arrayref 0.3.5 (registry+https://github.com/rust-lang/crates.io-index)" = "0d382e583f07208808f6b1249e60848879ba3543f57c32277bf52d69c2f0f0ee"
@ -3816,7 +3767,6 @@ dependencies = [
"checksum c_linked_list 1.1.1 (registry+https://github.com/rust-lang/crates.io-index)" = "4964518bd3b4a8190e832886cdc0da9794f12e8e6c1613a9e90ff331c4c8724b" "checksum c_linked_list 1.1.1 (registry+https://github.com/rust-lang/crates.io-index)" = "4964518bd3b4a8190e832886cdc0da9794f12e8e6c1613a9e90ff331c4c8724b"
"checksum cc 1.0.46 (registry+https://github.com/rust-lang/crates.io-index)" = "0213d356d3c4ea2c18c40b037c3be23cd639825c18f25ee670ac7813beeef99c" "checksum cc 1.0.46 (registry+https://github.com/rust-lang/crates.io-index)" = "0213d356d3c4ea2c18c40b037c3be23cd639825c18f25ee670ac7813beeef99c"
"checksum cfg-if 0.1.10 (registry+https://github.com/rust-lang/crates.io-index)" = "4785bdd1c96b2a846b2bd7cc02e86b6b3dbf14e7e53446c4f54c92a361040822" "checksum cfg-if 0.1.10 (registry+https://github.com/rust-lang/crates.io-index)" = "4785bdd1c96b2a846b2bd7cc02e86b6b3dbf14e7e53446c4f54c92a361040822"
"checksum cgmath 0.16.1 (registry+https://github.com/rust-lang/crates.io-index)" = "64a4b57c8f4e3a2e9ac07e0f6abc9c24b6fc9e1b54c3478cfb598f3d0023e51c"
"checksum chashmap 2.2.2 (registry+https://github.com/rust-lang/crates.io-index)" = "ff41a3c2c1e39921b9003de14bf0439c7b63a9039637c291e1a64925d8ddfa45" "checksum chashmap 2.2.2 (registry+https://github.com/rust-lang/crates.io-index)" = "ff41a3c2c1e39921b9003de14bf0439c7b63a9039637c291e1a64925d8ddfa45"
"checksum chrono 0.4.9 (registry+https://github.com/rust-lang/crates.io-index)" = "e8493056968583b0193c1bb04d6f7684586f3726992d6c573261941a895dbd68" "checksum chrono 0.4.9 (registry+https://github.com/rust-lang/crates.io-index)" = "e8493056968583b0193c1bb04d6f7684586f3726992d6c573261941a895dbd68"
"checksum clap 2.33.0 (registry+https://github.com/rust-lang/crates.io-index)" = "5067f5bb2d80ef5d68b4c87db81601f0b75bca627bc2ef76b141d7b846a3c6d9" "checksum clap 2.33.0 (registry+https://github.com/rust-lang/crates.io-index)" = "5067f5bb2d80ef5d68b4c87db81601f0b75bca627bc2ef76b141d7b846a3c6d9"
@ -3824,7 +3774,7 @@ dependencies = [
"checksum cloudabi 0.0.3 (registry+https://github.com/rust-lang/crates.io-index)" = "ddfc5b9aa5d4507acaf872de71051dfd0e309860e88966e1051e462a077aac4f" "checksum cloudabi 0.0.3 (registry+https://github.com/rust-lang/crates.io-index)" = "ddfc5b9aa5d4507acaf872de71051dfd0e309860e88966e1051e462a077aac4f"
"checksum codespan 0.2.1 (registry+https://github.com/rust-lang/crates.io-index)" = "004def512a9848b23a68ed110927d102b0e6d9f3dc732e28570879afde051f8c" "checksum codespan 0.2.1 (registry+https://github.com/rust-lang/crates.io-index)" = "004def512a9848b23a68ed110927d102b0e6d9f3dc732e28570879afde051f8c"
"checksum codespan-reporting 0.2.1 (registry+https://github.com/rust-lang/crates.io-index)" = "ab081a14ab8f9598ce826890fe896d0addee68c7a58ab49008369ccbb51510a8" "checksum codespan-reporting 0.2.1 (registry+https://github.com/rust-lang/crates.io-index)" = "ab081a14ab8f9598ce826890fe896d0addee68c7a58ab49008369ccbb51510a8"
"checksum colored 1.8.0 (registry+https://github.com/rust-lang/crates.io-index)" = "6cdb90b60f2927f8d76139c72dbde7e10c3a2bc47c8594c9c7a66529f2687c03" "checksum colored 1.9.0 (registry+https://github.com/rust-lang/crates.io-index)" = "433e7ac7d511768127ed85b0c4947f47a254131e37864b2dc13f52aa32cd37e5"
"checksum combine 2.5.2 (registry+https://github.com/rust-lang/crates.io-index)" = "1645a65a99c7c8d345761f4b75a6ffe5be3b3b27a93ee731fccc5050ba6be97c" "checksum combine 2.5.2 (registry+https://github.com/rust-lang/crates.io-index)" = "1645a65a99c7c8d345761f4b75a6ffe5be3b3b27a93ee731fccc5050ba6be97c"
"checksum constant_time_eq 0.1.4 (registry+https://github.com/rust-lang/crates.io-index)" = "995a44c877f9212528ccc74b21a232f66ad69001e40ede5bcee2ac9ef2657120" "checksum constant_time_eq 0.1.4 (registry+https://github.com/rust-lang/crates.io-index)" = "995a44c877f9212528ccc74b21a232f66ad69001e40ede5bcee2ac9ef2657120"
"checksum cookie 0.12.0 (registry+https://github.com/rust-lang/crates.io-index)" = "888604f00b3db336d2af898ec3c1d5d0ddf5e6d462220f2ededc33a87ac4bbd5" "checksum cookie 0.12.0 (registry+https://github.com/rust-lang/crates.io-index)" = "888604f00b3db336d2af898ec3c1d5d0ddf5e6d462220f2ededc33a87ac4bbd5"
@ -3884,7 +3834,7 @@ dependencies = [
"checksum getrandom 0.1.13 (registry+https://github.com/rust-lang/crates.io-index)" = "e7db7ca94ed4cd01190ceee0d8a8052f08a247aa1b469a7f68c6a3b71afcf407" "checksum getrandom 0.1.13 (registry+https://github.com/rust-lang/crates.io-index)" = "e7db7ca94ed4cd01190ceee0d8a8052f08a247aa1b469a7f68c6a3b71afcf407"
"checksum glob 0.2.11 (registry+https://github.com/rust-lang/crates.io-index)" = "8be18de09a56b60ed0edf84bc9df007e30040691af7acd1c41874faac5895bfb" "checksum glob 0.2.11 (registry+https://github.com/rust-lang/crates.io-index)" = "8be18de09a56b60ed0edf84bc9df007e30040691af7acd1c41874faac5895bfb"
"checksum h2 0.1.26 (registry+https://github.com/rust-lang/crates.io-index)" = "a5b34c246847f938a410a03c5458c7fee2274436675e76d8b903c08efc29c462" "checksum h2 0.1.26 (registry+https://github.com/rust-lang/crates.io-index)" = "a5b34c246847f938a410a03c5458c7fee2274436675e76d8b903c08efc29c462"
"checksum hash32 0.1.0 (registry+https://github.com/rust-lang/crates.io-index)" = "12d790435639c06a7b798af9e1e331ae245b7ef915b92f70a39b4cf8c00686af" "checksum hash32 0.1.1 (registry+https://github.com/rust-lang/crates.io-index)" = "d4041af86e63ac4298ce40e5cca669066e75b6f1aa3390fe2561ffa5e1d9f4cc"
"checksum heck 0.3.1 (registry+https://github.com/rust-lang/crates.io-index)" = "20564e78d53d2bb135c343b3f47714a56af2061f1c928fdb541dc7b9fdd94205" "checksum heck 0.3.1 (registry+https://github.com/rust-lang/crates.io-index)" = "20564e78d53d2bb135c343b3f47714a56af2061f1c928fdb541dc7b9fdd94205"
"checksum hex 0.3.2 (registry+https://github.com/rust-lang/crates.io-index)" = "805026a5d0141ffc30abb3be3173848ad46a1b1664fe632428479619a3644d77" "checksum hex 0.3.2 (registry+https://github.com/rust-lang/crates.io-index)" = "805026a5d0141ffc30abb3be3173848ad46a1b1664fe632428479619a3644d77"
"checksum hex 0.4.0 (registry+https://github.com/rust-lang/crates.io-index)" = "023b39be39e3a2da62a94feb433e91e8bcd37676fbc8bea371daf52b7a769a3e" "checksum hex 0.4.0 (registry+https://github.com/rust-lang/crates.io-index)" = "023b39be39e3a2da62a94feb433e91e8bcd37676fbc8bea371daf52b7a769a3e"
@ -4003,7 +3953,6 @@ dependencies = [
"checksum rental 0.5.5 (registry+https://github.com/rust-lang/crates.io-index)" = "8545debe98b2b139fb04cad8618b530e9b07c152d99a5de83c860b877d67847f" "checksum rental 0.5.5 (registry+https://github.com/rust-lang/crates.io-index)" = "8545debe98b2b139fb04cad8618b530e9b07c152d99a5de83c860b877d67847f"
"checksum rental-impl 0.5.5 (registry+https://github.com/rust-lang/crates.io-index)" = "475e68978dc5b743f2f40d8e0a8fdc83f1c5e78cbf4b8fa5e74e73beebc340de" "checksum rental-impl 0.5.5 (registry+https://github.com/rust-lang/crates.io-index)" = "475e68978dc5b743f2f40d8e0a8fdc83f1c5e78cbf4b8fa5e74e73beebc340de"
"checksum reqwest 0.9.22 (registry+https://github.com/rust-lang/crates.io-index)" = "2c2064233e442ce85c77231ebd67d9eca395207dec2127fe0bbedde4bd29a650" "checksum reqwest 0.9.22 (registry+https://github.com/rust-lang/crates.io-index)" = "2c2064233e442ce85c77231ebd67d9eca395207dec2127fe0bbedde4bd29a650"
"checksum rgb 0.8.14 (registry+https://github.com/rust-lang/crates.io-index)" = "2089e4031214d129e201f8c3c8c2fe97cd7322478a0d1cdf78e7029b0042efdb"
"checksum ring 0.16.9 (registry+https://github.com/rust-lang/crates.io-index)" = "6747f8da1f2b1fabbee1aaa4eb8a11abf9adef0bf58a41cee45db5d59cecdfac" "checksum ring 0.16.9 (registry+https://github.com/rust-lang/crates.io-index)" = "6747f8da1f2b1fabbee1aaa4eb8a11abf9adef0bf58a41cee45db5d59cecdfac"
"checksum rust-argon2 0.5.1 (registry+https://github.com/rust-lang/crates.io-index)" = "4ca4eaef519b494d1f2848fc602d18816fed808a981aedf4f1f00ceb7c9d32cf" "checksum rust-argon2 0.5.1 (registry+https://github.com/rust-lang/crates.io-index)" = "4ca4eaef519b494d1f2848fc602d18816fed808a981aedf4f1f00ceb7c9d32cf"
"checksum rustc-demangle 0.1.16 (registry+https://github.com/rust-lang/crates.io-index)" = "4c691c0e608126e00913e33f0ccf3727d5fc84573623b8d65b2df340b5201783" "checksum rustc-demangle 0.1.16 (registry+https://github.com/rust-lang/crates.io-index)" = "4c691c0e608126e00913e33f0ccf3727d5fc84573623b8d65b2df340b5201783"
@ -4034,7 +3983,6 @@ dependencies = [
"checksum slog-stdlog 4.0.0 (registry+https://github.com/rust-lang/crates.io-index)" = "be4d87903baf655da2d82bc3ac3f7ef43868c58bf712b3a661fda72009304c23" "checksum slog-stdlog 4.0.0 (registry+https://github.com/rust-lang/crates.io-index)" = "be4d87903baf655da2d82bc3ac3f7ef43868c58bf712b3a661fda72009304c23"
"checksum slog-term 2.4.2 (registry+https://github.com/rust-lang/crates.io-index)" = "54b50e85b73c2bd42ceb97b6ded235576d405bd1e974242ccfe634fa269f6da7" "checksum slog-term 2.4.2 (registry+https://github.com/rust-lang/crates.io-index)" = "54b50e85b73c2bd42ceb97b6ded235576d405bd1e974242ccfe634fa269f6da7"
"checksum smallvec 0.6.11 (registry+https://github.com/rust-lang/crates.io-index)" = "cefaa50e76a6f10b86f36e640eb1739eafbd4084865067778463913e43a77ff3" "checksum smallvec 0.6.11 (registry+https://github.com/rust-lang/crates.io-index)" = "cefaa50e76a6f10b86f36e640eb1739eafbd4084865067778463913e43a77ff3"
"checksum solana-ed25519-dalek 0.2.0 (registry+https://github.com/rust-lang/crates.io-index)" = "1c21f9d5aa62959872194dfd086feb4e8efec1c2589d27e6a0339904759e99fc"
"checksum solana_libra_bytecode_verifier 0.0.1-sol4 (registry+https://github.com/rust-lang/crates.io-index)" = "79c3b7e9555da6f04a3f542a40e92bbbd46d0f05bd270ae3ff8c0283c329a179" "checksum solana_libra_bytecode_verifier 0.0.1-sol4 (registry+https://github.com/rust-lang/crates.io-index)" = "79c3b7e9555da6f04a3f542a40e92bbbd46d0f05bd270ae3ff8c0283c329a179"
"checksum solana_libra_canonical_serialization 0.0.1-sol4 (registry+https://github.com/rust-lang/crates.io-index)" = "c674689dd2d17b0bab49501f0d63ec71b3e1f8fab2eae86174e37768435a54aa" "checksum solana_libra_canonical_serialization 0.0.1-sol4 (registry+https://github.com/rust-lang/crates.io-index)" = "c674689dd2d17b0bab49501f0d63ec71b3e1f8fab2eae86174e37768435a54aa"
"checksum solana_libra_compiler 0.0.1-sol4 (registry+https://github.com/rust-lang/crates.io-index)" = "908b00b637e6eaf835d67bea2329bbee82e75f8e162744fd707ca9c9e4c1400b" "checksum solana_libra_compiler 0.0.1-sol4 (registry+https://github.com/rust-lang/crates.io-index)" = "908b00b637e6eaf835d67bea2329bbee82e75f8e162744fd707ca9c9e4c1400b"
@ -4149,7 +4097,6 @@ dependencies = [
"checksum winapi-util 0.1.2 (registry+https://github.com/rust-lang/crates.io-index)" = "7168bab6e1daee33b4557efd0e95d5ca70a03706d39fa5f3fe7a236f584b03c9" "checksum winapi-util 0.1.2 (registry+https://github.com/rust-lang/crates.io-index)" = "7168bab6e1daee33b4557efd0e95d5ca70a03706d39fa5f3fe7a236f584b03c9"
"checksum winapi-x86_64-pc-windows-gnu 0.4.0 (registry+https://github.com/rust-lang/crates.io-index)" = "712e227841d057c1ee1cd2fb22fa7e5a5461ae8e48fa2ca79ec42cfc1931183f" "checksum winapi-x86_64-pc-windows-gnu 0.4.0 (registry+https://github.com/rust-lang/crates.io-index)" = "712e227841d057c1ee1cd2fb22fa7e5a5461ae8e48fa2ca79ec42cfc1931183f"
"checksum wincolor 1.0.2 (registry+https://github.com/rust-lang/crates.io-index)" = "96f5016b18804d24db43cebf3c77269e7569b8954a8464501c216cc5e070eaa9" "checksum wincolor 1.0.2 (registry+https://github.com/rust-lang/crates.io-index)" = "96f5016b18804d24db43cebf3c77269e7569b8954a8464501c216cc5e070eaa9"
"checksum winconsole 0.10.0 (registry+https://github.com/rust-lang/crates.io-index)" = "3ef84b96d10db72dd980056666d7f1e7663ce93d82fa33b63e71c966f4cf5032"
"checksum winreg 0.6.2 (registry+https://github.com/rust-lang/crates.io-index)" = "b2986deb581c4fe11b621998a5e53361efe6b48a151178d0cd9eeffa4dc6acc9" "checksum winreg 0.6.2 (registry+https://github.com/rust-lang/crates.io-index)" = "b2986deb581c4fe11b621998a5e53361efe6b48a151178d0cd9eeffa4dc6acc9"
"checksum ws2_32-sys 0.2.1 (registry+https://github.com/rust-lang/crates.io-index)" = "d59cefebd0c892fa2dd6de581e937301d8552cb44489cdff035c6187cb63fa5e" "checksum ws2_32-sys 0.2.1 (registry+https://github.com/rust-lang/crates.io-index)" = "d59cefebd0c892fa2dd6de581e937301d8552cb44489cdff035c6187cb63fa5e"
"checksum x25519-dalek 0.5.2 (registry+https://github.com/rust-lang/crates.io-index)" = "7ee1585dc1484373cbc1cee7aafda26634665cf449436fd6e24bfd1fad230538" "checksum x25519-dalek 0.5.2 (registry+https://github.com/rust-lang/crates.io-index)" = "7ee1585dc1484373cbc1cee7aafda26634665cf449436fd6e24bfd1fad230538"

View File

@ -12,11 +12,11 @@ edition = "2018"
bincode = "1.2.0" bincode = "1.2.0"
log = "0.4.8" log = "0.4.8"
solana-logger = { path = "../../logger", version = "0.21.0" } solana-logger = { path = "../../logger", version = "0.21.0" }
solana-sdk = { path = "../../sdk", version = "0.21.0" }
solana-runtime = { path = "../../runtime", version = "0.21.0" }
types = { version = "0.0.1-sol4", package = "solana_libra_types" }
language_e2e_tests = { version = "0.0.1-sol4", package = "solana_libra_language_e2e_tests" }
solana-move-loader-api = { path = "../move_loader_api", version = "0.21.0" } solana-move-loader-api = { path = "../move_loader_api", version = "0.21.0" }
solana-runtime = { path = "../../runtime", version = "0.21.0" }
solana-sdk = { path = "../../sdk", version = "0.21.0" }
language_e2e_tests = { version = "0.0.1-sol4", package = "solana_libra_language_e2e_tests" }
types = { version = "0.0.1-sol4", package = "solana_libra_types" }
[lib] [lib]
crate-type = ["lib"] crate-type = ["lib"]

View File

@ -25,12 +25,12 @@ use solana_sdk::system_instruction;
use types::account_config; use types::account_config;
pub fn create_genesis<T: Client>(from_key: &Keypair, client: &T, amount: u64) -> Keypair { pub fn create_genesis<T: Client>(from: &Keypair, client: &T, amount: u64) -> Keypair {
let libra_genesis_key = Keypair::new(); let genesis = Keypair::new();
let instruction = system_instruction::create_account( let instruction = system_instruction::create_account(
&from_key.pubkey(), &from.pubkey(),
&libra_genesis_key.pubkey(), &genesis.pubkey(),
1, 1,
bincode::serialized_size(&LibraAccountState::create_genesis(amount).unwrap()).unwrap() bincode::serialized_size(&LibraAccountState::create_genesis(amount).unwrap()).unwrap()
as u64, as u64,
@ -38,35 +38,33 @@ pub fn create_genesis<T: Client>(from_key: &Keypair, client: &T, amount: u64) ->
); );
client client
.send_message( .send_message(&[&from, &genesis], Message::new(vec![instruction]))
&[&from_key, &libra_genesis_key],
Message::new(vec![instruction]),
)
.unwrap(); .unwrap();
let instruction = librapay_instruction::genesis(&libra_genesis_key.pubkey(), amount); let instruction = librapay_instruction::genesis(&genesis.pubkey(), amount);
let message = Message::new_with_payer(vec![instruction], Some(&from_key.pubkey())); let message = Message::new_with_payer(vec![instruction], Some(&from.pubkey()));
client client.send_message(&[from, &genesis], message).unwrap();
.send_message(&[from_key, &libra_genesis_key], message)
.unwrap();
libra_genesis_key genesis
} }
pub fn upload_move_program<T: Client>(from: &Keypair, client: &T, code: &str) -> Pubkey { pub fn publish_module<T: Client>(from: &Keypair, client: &T, code: &str) -> Pubkey {
let address = account_config::association_address(); let address = account_config::association_address();
let account_state = LibraAccountState::create_program(&address, code, vec![]); let account_state = LibraAccountState::create_module(&address, code, vec![]);
let program_bytes = bincode::serialize(&account_state).unwrap(); let bytes = bincode::serialize(&account_state).unwrap();
load_program( load_program(client, &from, &solana_sdk::move_loader::id(), bytes)
client,
&from,
&solana_sdk::move_loader::id(),
program_bytes,
)
} }
pub fn upload_mint_program<T: Client>(from: &Keypair, client: &T) -> Pubkey { pub fn upload_script<T: Client>(from: &Keypair, client: &T, code: &str) -> Pubkey {
let address = account_config::association_address();
let account_state = LibraAccountState::create_script(&address, code, vec![]);
let bytes = bincode::serialize(&account_state).unwrap();
load_program(client, &from, &solana_sdk::move_loader::id(), bytes)
}
pub fn upload_mint_script<T: Client>(from: &Keypair, client: &T) -> Pubkey {
let code = " let code = "
import 0x0.LibraAccount; import 0x0.LibraAccount;
import 0x0.LibraCoin; import 0x0.LibraCoin;
@ -74,10 +72,9 @@ pub fn upload_mint_program<T: Client>(from: &Keypair, client: &T) -> Pubkey {
LibraAccount.mint_to_address(move(payee), move(amount)); LibraAccount.mint_to_address(move(payee), move(amount));
return; return;
}"; }";
upload_move_program(from, client, code) upload_script(from, client, code)
} }
pub fn upload_payment_script<T: Client>(from: &Keypair, client: &T) -> Pubkey {
pub fn upload_payment_program<T: Client>(from: &Keypair, client: &T) -> Pubkey {
let code = " let code = "
import 0x0.LibraAccount; import 0x0.LibraAccount;
import 0x0.LibraCoin; import 0x0.LibraCoin;
@ -87,7 +84,7 @@ pub fn upload_payment_program<T: Client>(from: &Keypair, client: &T) -> Pubkey {
} }
"; ";
upload_move_program(from, client, code) upload_script(from, client, code)
} }
pub fn process_instruction( pub fn process_instruction(

View File

@ -10,15 +10,13 @@ use types::transaction::TransactionArgument;
pub fn genesis(genesis_pubkey: &Pubkey, microlibras: u64) -> Instruction { pub fn genesis(genesis_pubkey: &Pubkey, microlibras: u64) -> Instruction {
let data = bincode::serialize(&InvokeCommand::CreateGenesis(microlibras)).unwrap(); let data = bincode::serialize(&InvokeCommand::CreateGenesis(microlibras)).unwrap();
let ix_data = LoaderInstruction::InvokeMain { data }; let ix_data = LoaderInstruction::InvokeMain { data };
let accounts = vec![AccountMeta::new(*genesis_pubkey, true)]; let accounts = vec![AccountMeta::new(*genesis_pubkey, true)];
Instruction::new(solana_sdk::move_loader::id(), &ix_data, accounts) Instruction::new(solana_sdk::move_loader::id(), &ix_data, accounts)
} }
pub fn mint( pub fn mint(
program_pubkey: &Pubkey, script_pubkey: &Pubkey,
from_pubkey: &Pubkey, genesis_pubkey: &Pubkey,
to_pubkey: &Pubkey, to_pubkey: &Pubkey,
microlibras: u64, microlibras: u64,
) -> Instruction { ) -> Instruction {
@ -27,7 +25,7 @@ pub fn mint(
TransactionArgument::U64(microlibras), TransactionArgument::U64(microlibras),
]; ];
let data = bincode::serialize(&InvokeCommand::RunProgram { let data = bincode::serialize(&InvokeCommand::RunScript {
sender_address: account_config::association_address(), sender_address: account_config::association_address(),
function_name: "main".to_string(), function_name: "main".to_string(),
args, args,
@ -36,8 +34,8 @@ pub fn mint(
let ix_data = LoaderInstruction::InvokeMain { data }; let ix_data = LoaderInstruction::InvokeMain { data };
let accounts = vec![ let accounts = vec![
AccountMeta::new_readonly(*program_pubkey, false), AccountMeta::new_readonly(*script_pubkey, false),
AccountMeta::new(*from_pubkey, true), AccountMeta::new(*genesis_pubkey, true),
AccountMeta::new(*to_pubkey, false), AccountMeta::new(*to_pubkey, false),
]; ];
@ -45,8 +43,8 @@ pub fn mint(
} }
pub fn transfer( pub fn transfer(
program_pubkey: &Pubkey, script_pubkey: &Pubkey,
mint_pubkey: &Pubkey, genesis_pubkey: &Pubkey,
from_pubkey: &Pubkey, from_pubkey: &Pubkey,
to_pubkey: &Pubkey, to_pubkey: &Pubkey,
microlibras: u64, microlibras: u64,
@ -56,7 +54,7 @@ pub fn transfer(
TransactionArgument::U64(microlibras), TransactionArgument::U64(microlibras),
]; ];
let data = bincode::serialize(&InvokeCommand::RunProgram { let data = bincode::serialize(&InvokeCommand::RunScript {
sender_address: pubkey_to_address(from_pubkey), sender_address: pubkey_to_address(from_pubkey),
function_name: "main".to_string(), function_name: "main".to_string(),
args, args,
@ -65,8 +63,8 @@ pub fn transfer(
let ix_data = LoaderInstruction::InvokeMain { data }; let ix_data = LoaderInstruction::InvokeMain { data };
let accounts = vec![ let accounts = vec![
AccountMeta::new_readonly(*program_pubkey, false), AccountMeta::new_readonly(*script_pubkey, false),
AccountMeta::new_readonly(*mint_pubkey, false), AccountMeta::new_readonly(*genesis_pubkey, false),
AccountMeta::new(*from_pubkey, true), AccountMeta::new(*from_pubkey, true),
AccountMeta::new(*to_pubkey, false), AccountMeta::new(*to_pubkey, false),
]; ];
@ -80,19 +78,19 @@ mod tests {
#[test] #[test]
fn test_pay() { fn test_pay() {
let from = Pubkey::new_rand(); let from_pubkey = Pubkey::new_rand();
let to = Pubkey::new_rand(); let to_pubkey = Pubkey::new_rand();
let program_id = Pubkey::new_rand(); let program_id = Pubkey::new_rand();
let mint_id = Pubkey::new_rand(); let mint_id = Pubkey::new_rand();
transfer(&program_id, &mint_id, &from, &to, 1); transfer(&program_id, &mint_id, &from_pubkey, &to_pubkey, 1);
} }
#[test] #[test]
fn test_mint() { fn test_mint() {
let program_id = Pubkey::new_rand(); let program_id = Pubkey::new_rand();
let from = Pubkey::new_rand(); let from_pubkey = Pubkey::new_rand();
let to = Pubkey::new_rand(); let to_pubkey = Pubkey::new_rand();
mint(&program_id, &from, &to, 1); mint(&program_id, &from_pubkey, &to_pubkey, 1);
} }
} }

View File

@ -3,6 +3,7 @@ use log::*;
use solana_move_loader_api::account_state::{pubkey_to_address, LibraAccountState}; use solana_move_loader_api::account_state::{pubkey_to_address, LibraAccountState};
use solana_move_loader_api::data_store::DataStore; use solana_move_loader_api::data_store::DataStore;
use solana_sdk::client::Client; use solana_sdk::client::Client;
use solana_sdk::commitment_config::CommitmentConfig;
use solana_sdk::hash::Hash; use solana_sdk::hash::Hash;
use solana_sdk::pubkey::Pubkey; use solana_sdk::pubkey::Pubkey;
use solana_sdk::signature::{Keypair, KeypairUtil}; use solana_sdk::signature::{Keypair, KeypairUtil};
@ -12,67 +13,74 @@ use std::boxed::Box;
use std::error; use std::error;
use std::fmt; use std::fmt;
pub fn create_genesis( pub fn create_genesis(keypair: &Keypair, microlibras: u64, recent_blockhash: Hash) -> Transaction {
genesis_keypair: &Keypair, let ix = librapay_instruction::genesis(&keypair.pubkey(), microlibras);
microlibras: u64,
recent_blockhash: Hash,
) -> Transaction {
let ix = librapay_instruction::genesis(&genesis_keypair.pubkey(), microlibras);
Transaction::new_signed_with_payer( Transaction::new_signed_with_payer(
vec![ix], vec![ix],
Some(&genesis_keypair.pubkey()), Some(&keypair.pubkey()),
&[genesis_keypair], &[keypair],
recent_blockhash, recent_blockhash,
) )
} }
pub fn mint_tokens( pub fn mint_tokens(
program_id: &Pubkey, script_pubkey: &Pubkey,
payer: &Keypair, payer_keypair: &Keypair,
mint: &Keypair, genesis_keypair: &Keypair,
to: &Pubkey, to_pubkey: &Pubkey,
microlibras: u64, microlibras: u64,
recent_blockhash: Hash, recent_blockhash: Hash,
) -> Transaction { ) -> Transaction {
let ix = librapay_instruction::mint(program_id, &mint.pubkey(), to, microlibras); let ix = librapay_instruction::mint(
script_pubkey,
&genesis_keypair.pubkey(),
to_pubkey,
microlibras,
);
Transaction::new_signed_with_payer( Transaction::new_signed_with_payer(
vec![ix], vec![ix],
Some(&payer.pubkey()), Some(&payer_keypair.pubkey()),
&[payer, mint], &[payer_keypair, genesis_keypair],
recent_blockhash, recent_blockhash,
) )
} }
pub fn transfer( pub fn transfer(
program_id: &Pubkey, script_pubkey: &Pubkey,
mint: &Pubkey, genesis_pubkey: &Pubkey,
payer: &Keypair, payer_keypair: &Keypair,
from: &Keypair, from_keypair: &Keypair,
to: &Pubkey, to_pubkey: &Pubkey,
microlibras: u64, microlibras: u64,
recent_blockhash: Hash, recent_blockhash: Hash,
) -> Transaction { ) -> Transaction {
let ix = librapay_instruction::transfer(program_id, mint, &from.pubkey(), to, microlibras); let ix = librapay_instruction::transfer(
script_pubkey,
genesis_pubkey,
&from_keypair.pubkey(),
to_pubkey,
microlibras,
);
Transaction::new_signed_with_payer( Transaction::new_signed_with_payer(
vec![ix], vec![ix],
Some(&payer.pubkey()), Some(&payer_keypair.pubkey()),
&[payer, from], &[payer_keypair, from_keypair],
recent_blockhash, recent_blockhash,
) )
} }
pub fn create_accounts( pub fn create_accounts(
from: &Keypair, from_keypair: &Keypair,
to: &[&Keypair], to_keypair: &[&Keypair],
lamports: u64, lamports: u64,
recent_blockhash: Hash, recent_blockhash: Hash,
) -> Transaction { ) -> Transaction {
let instructions = to let instructions = to_keypair
.iter() .iter()
.map(|to| { .map(|keypair| {
system_instruction::create_account( system_instruction::create_account(
&from.pubkey(), &from_keypair.pubkey(),
&to.pubkey(), &keypair.pubkey(),
lamports, lamports,
400, 400,
&solana_sdk::move_loader::id(), &solana_sdk::move_loader::id(),
@ -80,18 +88,18 @@ pub fn create_accounts(
}) })
.collect(); .collect();
let mut from_signers = vec![from]; let mut from_signers = vec![from_keypair];
from_signers.extend_from_slice(to); from_signers.extend_from_slice(to_keypair);
Transaction::new_signed_instructions(&from_signers, instructions, recent_blockhash) Transaction::new_signed_instructions(&from_signers, instructions, recent_blockhash)
} }
pub fn create_account( pub fn create_account(
from: &Keypair, from_keypair: &Keypair,
to: &Keypair, to_keypair: &Keypair,
lamports: u64, lamports: u64,
recent_blockhash: Hash, recent_blockhash: Hash,
) -> Transaction { ) -> Transaction {
create_accounts(from, &[to], lamports, recent_blockhash) create_accounts(from_keypair, &[to_keypair], lamports, recent_blockhash)
} }
#[derive(Debug)] #[derive(Debug)]
@ -109,12 +117,13 @@ impl error::Error for LibrapayError {}
pub fn get_libra_balance<T: Client>( pub fn get_libra_balance<T: Client>(
client: &T, client: &T,
account_address: &Pubkey, pubkey: &Pubkey,
) -> Result<u64, Box<dyn error::Error>> { ) -> Result<u64, Box<dyn error::Error>> {
let account = client.get_account_data(&account_address)?; if let Some(account) =
if let Some(account) = account { client.get_account_with_commitment(&pubkey, CommitmentConfig::recent())?
{
let mut data_store = DataStore::default(); let mut data_store = DataStore::default();
match bincode::deserialize(&account)? { match bincode::deserialize(&account.data)? {
LibraAccountState::User(_, write_set) => { LibraAccountState::User(_, write_set) => {
data_store.apply_write_set(&write_set); data_store.apply_write_set(&write_set);
} }
@ -127,9 +136,8 @@ pub fn get_libra_balance<T: Client>(
} }
} }
let resource = data_store let resource = data_store
.read_account_resource(&pubkey_to_address(account_address)) .read_account_resource(&pubkey_to_address(pubkey))
.unwrap(); .unwrap();
let res = resource.balance(); let res = resource.balance();
Ok(res) Ok(res)
} else { } else {
@ -140,7 +148,7 @@ pub fn get_libra_balance<T: Client>(
#[cfg(test)] #[cfg(test)]
mod tests { mod tests {
use super::*; use super::*;
use crate::{create_genesis, upload_mint_program, upload_payment_program}; use crate::{create_genesis, upload_mint_script, upload_payment_script};
use solana_runtime::bank::Bank; use solana_runtime::bank::Bank;
use solana_runtime::bank_client::BankClient; use solana_runtime::bank_client::BankClient;
use solana_sdk::genesis_config::create_genesis_config; use solana_sdk::genesis_config::create_genesis_config;
@ -148,7 +156,7 @@ mod tests {
use std::sync::Arc; use std::sync::Arc;
fn create_bank(lamports: u64) -> (Arc<Bank>, Keypair, Keypair, Pubkey, Pubkey) { fn create_bank(lamports: u64) -> (Arc<Bank>, Keypair, Keypair, Pubkey, Pubkey) {
let (genesis_config, mint_keypair) = create_genesis_config(lamports); let (genesis_config, mint) = create_genesis_config(lamports);
let mut bank = Bank::new(&genesis_config); let mut bank = Bank::new(&genesis_config);
bank.add_instruction_processor( bank.add_instruction_processor(
solana_sdk::move_loader::id(), solana_sdk::move_loader::id(),
@ -156,59 +164,73 @@ mod tests {
); );
let shared_bank = Arc::new(bank); let shared_bank = Arc::new(bank);
let bank_client = BankClient::new_shared(&shared_bank); let bank_client = BankClient::new_shared(&shared_bank);
let genesis_keypair = create_genesis(&mint_keypair, &bank_client, 1_000_000); let genesis_pubkey = create_genesis(&mint, &bank_client, 1_000_000);
let mint_program_pubkey = upload_mint_program(&mint_keypair, &bank_client); let mint_script_pubkey = upload_mint_script(&mint, &bank_client);
let program_pubkey = upload_payment_program(&mint_keypair, &bank_client); let script_pubkey = upload_payment_script(&mint, &bank_client);
( (
shared_bank, shared_bank,
mint_keypair, mint,
genesis_keypair, genesis_pubkey,
mint_program_pubkey, mint_script_pubkey,
program_pubkey, script_pubkey,
) )
} }
#[test] #[test]
fn test_transfer() { fn test_transfer() {
let (bank, mint_keypair, libra_genesis_keypair, mint_program_id, program_id) = solana_logger::setup();
create_bank(10_000);
let from = Keypair::new();
let to = Keypair::new();
let tx = create_accounts(&mint_keypair, &[&from, &to], 1, bank.last_blockhash()); let (bank, mint, genesis_keypair, mint_script_pubkey, payment_script_pubkey) =
create_bank(10_000);
let from_keypair = Keypair::new();
let to_keypair = Keypair::new();
let tx = create_accounts(
&mint,
&[&from_keypair, &to_keypair],
1,
bank.last_blockhash(),
);
bank.process_transaction(&tx).unwrap(); bank.process_transaction(&tx).unwrap();
info!( info!(
"created accounts: mint: {} libra_mint: {}", "created accounts: mint: {} genesis_pubkey: {}",
mint_keypair.pubkey(), mint.pubkey(),
libra_genesis_keypair.pubkey() genesis_keypair.pubkey()
);
info!(
" from: {} to: {}",
from_keypair.pubkey(),
to_keypair.pubkey()
); );
info!(" from: {} to: {}", from.pubkey(), to.pubkey());
let tx = mint_tokens( let tx = mint_tokens(
&mint_program_id, &mint_script_pubkey,
&mint_keypair, &mint,
&libra_genesis_keypair, &genesis_keypair,
&from.pubkey(), &from_keypair.pubkey(),
1, 1,
bank.last_blockhash(), bank.last_blockhash(),
); );
bank.process_transaction(&tx).unwrap(); bank.process_transaction(&tx).unwrap();
let client = BankClient::new_shared(&bank); let client = BankClient::new_shared(&bank);
assert_eq!(1, get_libra_balance(&client, &from.pubkey()).unwrap()); assert_eq!(
1,
get_libra_balance(&client, &from_keypair.pubkey()).unwrap()
);
info!("passed mint... doing another transfer.."); info!("passed mint... doing another transfer..");
let tx = transfer( let tx = transfer(
&program_id, &payment_script_pubkey,
&libra_genesis_keypair.pubkey(), &genesis_keypair.pubkey(),
&mint_keypair, &mint,
&from, &from_keypair,
&to.pubkey(), &to_keypair.pubkey(),
1, 1,
bank.last_blockhash(), bank.last_blockhash(),
); );
bank.process_transaction(&tx).unwrap(); bank.process_transaction(&tx).unwrap();
assert_eq!(1, get_libra_balance(&client, &to.pubkey()).unwrap()); assert_eq!(1, get_libra_balance(&client, &to_keypair.pubkey()).unwrap());
} }
} }

View File

@ -252,7 +252,6 @@ dependencies = [
"libc 0.2.65 (registry+https://github.com/rust-lang/crates.io-index)", "libc 0.2.65 (registry+https://github.com/rust-lang/crates.io-index)",
"num-integer 0.1.41 (registry+https://github.com/rust-lang/crates.io-index)", "num-integer 0.1.41 (registry+https://github.com/rust-lang/crates.io-index)",
"num-traits 0.2.8 (registry+https://github.com/rust-lang/crates.io-index)", "num-traits 0.2.8 (registry+https://github.com/rust-lang/crates.io-index)",
"serde 1.0.102 (registry+https://github.com/rust-lang/crates.io-index)",
"time 0.1.42 (registry+https://github.com/rust-lang/crates.io-index)", "time 0.1.42 (registry+https://github.com/rust-lang/crates.io-index)",
] ]
@ -2116,7 +2115,6 @@ dependencies = [
"bincode 1.2.0 (registry+https://github.com/rust-lang/crates.io-index)", "bincode 1.2.0 (registry+https://github.com/rust-lang/crates.io-index)",
"bs58 0.3.0 (registry+https://github.com/rust-lang/crates.io-index)", "bs58 0.3.0 (registry+https://github.com/rust-lang/crates.io-index)",
"byteorder 1.3.2 (registry+https://github.com/rust-lang/crates.io-index)", "byteorder 1.3.2 (registry+https://github.com/rust-lang/crates.io-index)",
"chrono 0.4.9 (registry+https://github.com/rust-lang/crates.io-index)",
"ed25519-dalek 1.0.0-pre.1 (registry+https://github.com/rust-lang/crates.io-index)", "ed25519-dalek 1.0.0-pre.1 (registry+https://github.com/rust-lang/crates.io-index)",
"generic-array 0.13.2 (registry+https://github.com/rust-lang/crates.io-index)", "generic-array 0.13.2 (registry+https://github.com/rust-lang/crates.io-index)",
"hex 0.4.0 (registry+https://github.com/rust-lang/crates.io-index)", "hex 0.4.0 (registry+https://github.com/rust-lang/crates.io-index)",
@ -2127,7 +2125,6 @@ dependencies = [
"num-traits 0.2.8 (registry+https://github.com/rust-lang/crates.io-index)", "num-traits 0.2.8 (registry+https://github.com/rust-lang/crates.io-index)",
"rand 0.6.5 (registry+https://github.com/rust-lang/crates.io-index)", "rand 0.6.5 (registry+https://github.com/rust-lang/crates.io-index)",
"rand_chacha 0.1.1 (registry+https://github.com/rust-lang/crates.io-index)", "rand_chacha 0.1.1 (registry+https://github.com/rust-lang/crates.io-index)",
"rayon 1.2.0 (registry+https://github.com/rust-lang/crates.io-index)",
"serde 1.0.102 (registry+https://github.com/rust-lang/crates.io-index)", "serde 1.0.102 (registry+https://github.com/rust-lang/crates.io-index)",
"serde_bytes 0.11.2 (registry+https://github.com/rust-lang/crates.io-index)", "serde_bytes 0.11.2 (registry+https://github.com/rust-lang/crates.io-index)",
"serde_derive 1.0.102 (registry+https://github.com/rust-lang/crates.io-index)", "serde_derive 1.0.102 (registry+https://github.com/rust-lang/crates.io-index)",
@ -2135,7 +2132,6 @@ dependencies = [
"sha2 0.8.0 (registry+https://github.com/rust-lang/crates.io-index)", "sha2 0.8.0 (registry+https://github.com/rust-lang/crates.io-index)",
"solana-crate-features 0.21.0", "solana-crate-features 0.21.0",
"solana-logger 0.21.0", "solana-logger 0.21.0",
"untrusted 0.7.0 (registry+https://github.com/rust-lang/crates.io-index)",
] ]
[[package]] [[package]]

View File

@ -10,7 +10,7 @@ use types::{
account_address::AccountAddress, account_address::AccountAddress,
account_config, account_config,
identifier::Identifier, identifier::Identifier,
transaction::Program, transaction::{Module, Script},
write_set::{WriteOp, WriteSet}, write_set::{WriteOp, WriteSet},
}; };
use vm::{ use vm::{
@ -46,14 +46,17 @@ pub struct ModuleBytes {
pub enum LibraAccountState { pub enum LibraAccountState {
/// No data for this account yet /// No data for this account yet
Unallocated, Unallocated,
/// Json string representation of types::transaction::Program /// Json string representation of types::transaction::Module
CompiledProgram(String), CompiledScript(String),
/// Serialized verified program bytes /// Json string representation of types::transaction::Script
VerifiedProgram { CompiledModule(String),
/// Serialized verified script bytes
VerifiedScript {
#[serde(with = "serde_bytes")] #[serde(with = "serde_bytes")]
script_bytes: Vec<u8>, script_bytes: Vec<u8>,
modules_bytes: Vec<ModuleBytes>,
}, },
// Write set containing the published module
PublishedModule(WriteSet),
/// Associated genesis account and the write set containing the Libra account data /// Associated genesis account and the write set containing the Libra account data
User(Pubkey, WriteSet), User(Pubkey, WriteSet),
/// Write sets containing the mint and stdlib modules /// Write sets containing the mint and stdlib modules
@ -64,53 +67,56 @@ impl LibraAccountState {
Self::Unallocated Self::Unallocated
} }
pub fn create_program( fn create_compiler(sender_address: &AccountAddress, deps: Vec<&Vec<u8>>) -> Compiler {
sender_address: &AccountAddress,
code: &str,
deps: Vec<&Vec<u8>>,
) -> Self {
// Compiler needs all the dependencies and the dependency module's account's // Compiler needs all the dependencies and the dependency module's account's
// data into `VerifiedModules` // data into `VerifiedModules`
let mut extra_deps: Vec<VerifiedModule> = vec![]; let mut extra_deps: Vec<VerifiedModule> = vec![];
for dep in deps { for dep in deps {
let state: Self = bincode::deserialize(&dep).unwrap(); let state: Self = bincode::deserialize(&dep).unwrap();
if let Self::User(_, write_set) = state { if let Self::PublishedModule(write_set) = state {
for (_, write_op) in write_set.iter() { for (_, write_op) in write_set.iter() {
if let WriteOp::Value(raw_bytes) = write_op { if let WriteOp::Value(raw_bytes) = write_op {
extra_deps.push( let v =
VerifiedModule::new(CompiledModule::deserialize(&raw_bytes).unwrap()) VerifiedModule::new(CompiledModule::deserialize(&raw_bytes).unwrap())
.unwrap(), .unwrap();
); extra_deps.push(v);
} }
} }
} }
} }
let compiler = Compiler { Compiler {
address: *sender_address, address: *sender_address,
extra_deps, extra_deps,
..Compiler::default() ..Compiler::default()
}; }
let compiled_program = compiler }
.into_compiled_program(code)
.expect("Failed to compile"); pub fn create_script(sender_address: &AccountAddress, code: &str, deps: Vec<&Vec<u8>>) -> Self {
let compiler = Self::create_compiler(sender_address, deps);
let compiled_script = compiler.into_script(code).expect("Failed to compile");
let mut script_bytes = vec![]; let mut script_bytes = vec![];
compiled_program compiled_script
.script
.serialize(&mut script_bytes) .serialize(&mut script_bytes)
.expect("Unable to serialize script"); .expect("Unable to serialize script");
let mut modules_bytes = vec![];
for module in &compiled_program.modules { // TODO args?
let mut buf = vec![]; Self::CompiledScript(serde_json::to_string(&Script::new(script_bytes, vec![])).unwrap())
module
.serialize(&mut buf)
.expect("Unable to serialize module");
modules_bytes.push(buf);
} }
Self::CompiledProgram(
serde_json::to_string(&Program::new(script_bytes, modules_bytes, vec![])).unwrap(), pub fn create_module(sender_address: &AccountAddress, code: &str, deps: Vec<&Vec<u8>>) -> Self {
) let compiler = Self::create_compiler(sender_address, deps);
let compiled_module = compiler
.into_compiled_module(code)
.expect("Failed to compile");
let mut module_bytes = vec![];
compiled_module
.serialize(&mut module_bytes)
.expect("Unable to serialize script");
Self::CompiledModule(serde_json::to_string(&Module::new(module_bytes)).unwrap())
} }
pub fn create_user(owner: &Pubkey, write_set: WriteSet) -> Self { pub fn create_user(owner: &Pubkey, write_set: WriteSet) -> Self {

View File

@ -1,3 +1,4 @@
use bytecode_verifier::verifier::VerifiedModule;
use canonical_serialization::SimpleDeserializer; use canonical_serialization::SimpleDeserializer;
use failure::prelude::*; use failure::prelude::*;
use indexmap::IndexMap; use indexmap::IndexMap;
@ -7,10 +8,10 @@ use types::{
access_path::AccessPath, access_path::AccessPath,
account_address::AccountAddress, account_address::AccountAddress,
account_config::{self, AccountResource}, account_config::{self, AccountResource},
language_storage::ModuleId,
write_set::{WriteOp, WriteSet, WriteSetMut}, write_set::{WriteOp, WriteSet, WriteSetMut},
}; };
use vm::{errors::VMResult, CompiledModule}; use vm::access::ModuleAccess;
use vm::errors::VMResult;
use vm_runtime::{data_cache::RemoteCache, identifier::create_access_path}; use vm_runtime::{data_cache::RemoteCache, identifier::create_access_path};
/// An in-memory implementation of [`StateView`] and [`RemoteCache`] for the VM. /// An in-memory implementation of [`StateView`] and [`RemoteCache`] for the VM.
@ -84,16 +85,14 @@ impl DataStore {
self.data.remove(access_path) self.data.remove(access_path)
} }
/// Adds a [`CompiledModule`] to this data store. /// Adds a [`VerifiedModule`] to this data store.
/// pub fn add_module(&mut self, module: &VerifiedModule) -> Result<()> {
/// Does not do any sort of verification on the module. let access_path = AccessPath::from(&module.self_id());
pub fn add_module(&mut self, module_id: &ModuleId, module: &CompiledModule) {
let access_path = AccessPath::from(module_id); let mut bytes = vec![];
let mut value = vec![]; module.serialize(&mut bytes)?;
module self.set(access_path, bytes);
.serialize(&mut value) Ok(())
.expect("serializing this module should work");
self.set(access_path, value);
} }
/// Dumps the data store to stdout /// Dumps the data store to stdout

View File

@ -1,4 +1,4 @@
use crate::account_state::{pubkey_to_address, LibraAccountState, ModuleBytes}; use crate::account_state::{pubkey_to_address, LibraAccountState};
use crate::data_store::DataStore; use crate::data_store::DataStore;
use crate::error_mappers::*; use crate::error_mappers::*;
use bytecode_verifier::verifier::{VerifiedModule, VerifiedScript}; use bytecode_verifier::verifier::{VerifiedModule, VerifiedScript};
@ -17,7 +17,7 @@ use types::{
account_address::AccountAddress, account_address::AccountAddress,
account_config, account_config,
identifier::Identifier, identifier::Identifier,
transaction::{Program, TransactionArgument, TransactionOutput}, transaction::{Module, Script, TransactionArgument, TransactionOutput},
}; };
use vm::{ use vm::{
access::ModuleAccess, access::ModuleAccess,
@ -59,13 +59,13 @@ pub fn process_instruction(
pub enum InvokeCommand { pub enum InvokeCommand {
/// Create a new genesis account /// Create a new genesis account
CreateGenesis(u64), CreateGenesis(u64),
/// Run a Move program /// run a Move script
RunProgram { RunScript {
/// Sender of the "transaction", the "sender" who is running this program /// Sender of the "transaction", the "sender" who is running this script
sender_address: AccountAddress, sender_address: AccountAddress,
/// Name of the program's function to call /// Name of the script's function to call
function_name: String, function_name: String,
/// Arguments to pass to the program being called /// Arguments to pass to the script being called
args: Vec<TransactionArgument>, args: Vec<TransactionArgument>,
}, },
} }
@ -75,7 +75,7 @@ pub struct MoveProcessor {}
impl MoveProcessor { impl MoveProcessor {
#[allow(clippy::needless_pass_by_value)] #[allow(clippy::needless_pass_by_value)]
fn missing_account() -> InstructionError { fn missing_account() -> InstructionError {
debug!("Error: Missing account"); debug!("Error: Missing libra account");
InstructionError::InvalidAccountData InstructionError::InvalidAccountData
} }
@ -108,75 +108,15 @@ impl MoveProcessor {
Ok(()) Ok(())
} }
fn verify_program( fn deserialize_verified_script(data: &[u8]) -> Result<VerifiedScript, InstructionError> {
script: &VerifiedScript,
modules: &[VerifiedModule],
) -> Result<(LibraAccountState), InstructionError> {
let mut script_bytes = vec![];
script
.as_inner()
.serialize(&mut script_bytes)
.map_err(map_failure_error)?;
let mut modules_bytes = vec![];
for module in modules.iter() {
let mut buf = vec![];
module
.as_inner()
.serialize(&mut buf)
.map_err(map_failure_error)?;
modules_bytes.push(ModuleBytes { bytes: buf });
}
Ok(LibraAccountState::VerifiedProgram {
script_bytes,
modules_bytes,
})
}
fn deserialize_compiled_program(
data: &[u8],
) -> Result<(CompiledScript, Vec<CompiledModule>), InstructionError> {
match limited_deserialize(data)? { match limited_deserialize(data)? {
LibraAccountState::CompiledProgram(string) => { LibraAccountState::VerifiedScript { script_bytes } => {
let program: Program = serde_json::from_str(&string).map_err(map_json_error)?;
let script =
CompiledScript::deserialize(&program.code()).map_err(map_err_vm_status)?;
let modules = program
.modules()
.iter()
.map(|bytes| CompiledModule::deserialize(&bytes))
.collect::<Result<Vec<_>, _>>()
.map_err(map_err_vm_status)?;
Ok((script, modules))
}
_ => {
debug!("Error: Program account does not contain a program");
Err(InstructionError::InvalidArgument)
}
}
}
fn deserialize_verified_program(
data: &[u8],
) -> Result<(VerifiedScript, Vec<VerifiedModule>), InstructionError> {
match limited_deserialize(data)? {
LibraAccountState::VerifiedProgram {
script_bytes,
modules_bytes,
} => {
let script = let script =
VerifiedScript::deserialize(&script_bytes).map_err(map_err_vm_status)?; VerifiedScript::deserialize(&script_bytes).map_err(map_err_vm_status)?;
let modules = modules_bytes Ok(script)
.iter()
.map(|module_bytes| VerifiedModule::deserialize(&module_bytes.bytes))
.collect::<Result<Vec<_>, _>>()
.map_err(map_err_vm_status)?;
Ok((script, modules))
} }
_ => { _ => {
debug!("Error: Program account does not contain a program"); debug!("Error: Script account does not contain a script");
Err(InstructionError::InvalidArgument) Err(InstructionError::InvalidArgument)
} }
} }
@ -187,26 +127,16 @@ impl MoveProcessor {
function_name: &str, function_name: &str,
args: Vec<TransactionArgument>, args: Vec<TransactionArgument>,
script: VerifiedScript, script: VerifiedScript,
modules: Vec<VerifiedModule>,
data_store: &DataStore, data_store: &DataStore,
) -> Result<TransactionOutput, InstructionError> { ) -> Result<TransactionOutput, InstructionError> {
let allocator = Arena::new(); let allocator = Arena::new();
let code_cache = VMModuleCache::new(&allocator); let code_cache = VMModuleCache::new(&allocator);
let module_cache = BlockModuleCache::new(&code_cache, ModuleFetcherImpl::new(data_store)); let module_cache = BlockModuleCache::new(&code_cache, ModuleFetcherImpl::new(data_store));
let mut modules_to_publish = vec![]; let modules_to_publish = vec![];
let main_module = script.into_module(); let main_module = script.into_module();
let module_id = main_module.self_id(); let module_id = main_module.self_id();
module_cache.cache_module(main_module); module_cache.cache_module(main_module);
for verified_module in modules {
let mut raw_bytes = vec![];
verified_module
.as_inner()
.serialize(&mut raw_bytes)
.map_err(map_failure_error)?;
modules_to_publish.push((verified_module.self_id(), raw_bytes));
module_cache.cache_module(verified_module);
}
let mut txn_metadata = TransactionMetadata::default(); let mut txn_metadata = TransactionMetadata::default();
txn_metadata.sender = sender_address; txn_metadata.sender = sender_address;
@ -245,15 +175,19 @@ impl MoveProcessor {
} }
for keyed_account in keyed_accounts_iter { for keyed_account in keyed_accounts_iter {
if let LibraAccountState::User(owner, write_set) = match limited_deserialize(&keyed_account.account.data)? {
limited_deserialize(&keyed_account.account.data)? LibraAccountState::User(owner, write_set) => {
{
if owner != *genesis.unsigned_key() { if owner != *genesis.unsigned_key() {
debug!("All user accounts must be owned by the genesis"); debug!("User account must be owned by this genesis");
return Err(InstructionError::InvalidArgument); return Err(InstructionError::InvalidArgument);
} }
data_store.apply_write_set(&write_set) data_store.apply_write_set(&write_set)
} }
LibraAccountState::PublishedModule(write_set) => {
data_store.apply_write_set(&write_set)
}
_ => (),
}
} }
Ok(data_store) Ok(data_store)
} }
@ -293,11 +227,14 @@ impl MoveProcessor {
let write_set = write_sets let write_set = write_sets
.remove(&pubkey_to_address(keyed_account.unsigned_key())) .remove(&pubkey_to_address(keyed_account.unsigned_key()))
.ok_or_else(Self::missing_account)?; .ok_or_else(Self::missing_account)?;
if !keyed_account.account.executable {
// Only write back non-executable accounts
Self::serialize_and_enforce_length( Self::serialize_and_enforce_length(
&LibraAccountState::User(genesis_key, write_set), &LibraAccountState::User(genesis_key, write_set),
&mut keyed_account.account.data, &mut keyed_account.account.data,
)?; )?;
} }
}
if !write_sets.is_empty() { if !write_sets.is_empty() {
debug!("Error: Missing keyed accounts"); debug!("Error: Missing keyed accounts");
return Err(InstructionError::GenericError); return Err(InstructionError::GenericError);
@ -311,60 +248,104 @@ impl MoveProcessor {
bytes: &[u8], bytes: &[u8],
) -> Result<(), InstructionError> { ) -> Result<(), InstructionError> {
let mut keyed_accounts_iter = keyed_accounts.iter_mut(); let mut keyed_accounts_iter = keyed_accounts.iter_mut();
let program = next_keyed_account(&mut keyed_accounts_iter)?; let keyed_account = next_keyed_account(&mut keyed_accounts_iter)?;
if program.signer_key().is_none() { if keyed_account.signer_key().is_none() {
debug!("Error: key[0] did not sign the transaction"); debug!("Error: key[0] did not sign the transaction");
return Err(InstructionError::MissingRequiredSignature); return Err(InstructionError::MissingRequiredSignature);
} }
let offset = offset as usize; let offset = offset as usize;
let len = bytes.len(); let len = bytes.len();
trace!("Write: offset={} length={}", offset, len); trace!("Write: offset={} length={}", offset, len);
if program.account.data.len() < offset + len { if keyed_account.account.data.len() < offset + len {
debug!( debug!(
"Error: Write overflow: {} < {}", "Error: Write overflow: {} < {}",
program.account.data.len(), keyed_account.account.data.len(),
offset + len offset + len
); );
return Err(InstructionError::AccountDataTooSmall); return Err(InstructionError::AccountDataTooSmall);
} }
program.account.data[offset..offset + len].copy_from_slice(&bytes); keyed_account.account.data[offset..offset + len].copy_from_slice(&bytes);
Ok(()) Ok(())
} }
pub fn do_finalize(keyed_accounts: &mut [KeyedAccount]) -> Result<(), InstructionError> { pub fn do_finalize(keyed_accounts: &mut [KeyedAccount]) -> Result<(), InstructionError> {
let mut keyed_accounts_iter = keyed_accounts.iter_mut(); let mut keyed_accounts_iter = keyed_accounts.iter_mut();
let program = next_keyed_account(&mut keyed_accounts_iter)?; let finalized = next_keyed_account(&mut keyed_accounts_iter)?;
let rent = next_keyed_account(&mut keyed_accounts_iter)?; let rent = next_keyed_account(&mut keyed_accounts_iter)?;
if program.signer_key().is_none() { if finalized.signer_key().is_none() {
debug!("Error: key[0] did not sign the transaction"); debug!("Error: account to finalize did not sign the transaction");
return Err(InstructionError::MissingRequiredSignature); return Err(InstructionError::MissingRequiredSignature);
} }
rent::verify_rent_exemption(&program, &rent)?; rent::verify_rent_exemption(&finalized, &rent)?;
let (compiled_script, compiled_modules) =
Self::deserialize_compiled_program(&program.account.data)?;
let verified_script = VerifiedScript::new(compiled_script).unwrap();
let verified_modules = compiled_modules
.into_iter()
.map(VerifiedModule::new)
.collect::<Result<Vec<_>, _>>()
.map_err(map_vm_verification_error)?;
match limited_deserialize(&finalized.account.data)? {
LibraAccountState::CompiledScript(string) => {
let script: Script = serde_json::from_str(&string).map_err(map_json_error)?;
let compiled_script =
CompiledScript::deserialize(&script.code()).map_err(map_err_vm_status)?;
let verified_script = match VerifiedScript::new(compiled_script) {
Ok(script) => script,
Err((_, errors)) => {
if errors.is_empty() {
return Err(InstructionError::GenericError);
} else {
return Err(map_err_vm_status(errors[0].clone()));
}
}
};
let mut script_bytes = vec![];
verified_script
.as_inner()
.serialize(&mut script_bytes)
.map_err(map_failure_error)?;
Self::serialize_and_enforce_length( Self::serialize_and_enforce_length(
&Self::verify_program(&verified_script, &verified_modules)?, &LibraAccountState::VerifiedScript { script_bytes },
&mut program.account.data, &mut finalized.account.data,
)?;
info!("Finalize script: {:?}", finalized.unsigned_key());
}
LibraAccountState::CompiledModule(string) => {
let module: Module = serde_json::from_str(&string).map_err(map_json_error)?;
let compiled_module =
CompiledModule::deserialize(&module.code()).map_err(map_err_vm_status)?;
let verified_module =
VerifiedModule::new(compiled_module).map_err(map_vm_verification_error)?;
let mut data_store = DataStore::default();
data_store
.add_module(&verified_module)
.map_err(map_failure_error)?;
let mut write_sets = data_store
.into_write_sets()
.map_err(|_| InstructionError::GenericError)?;
let write_set = write_sets
.remove(&pubkey_to_address(finalized.unsigned_key()))
.ok_or_else(Self::missing_account)?;
Self::serialize_and_enforce_length(
&LibraAccountState::PublishedModule(write_set),
&mut finalized.account.data,
)?; )?;
program.account.executable = true; if !write_sets.is_empty() {
debug!("Error: Missing keyed accounts");
return Err(InstructionError::GenericError);
}
info!("Finalize module: {:?}", finalized.unsigned_key());
}
_ => {
debug!("Error: Account to finalize does not contain compiled data");
return Err(InstructionError::InvalidArgument);
}
};
finalized.account.executable = true;
info!(
"Finalize: {:?}",
program.signer_key().unwrap_or(&Pubkey::default())
);
Ok(()) Ok(())
} }
@ -375,17 +356,17 @@ impl MoveProcessor {
match limited_deserialize(&data)? { match limited_deserialize(&data)? {
InvokeCommand::CreateGenesis(amount) => { InvokeCommand::CreateGenesis(amount) => {
let mut keyed_accounts_iter = keyed_accounts.iter_mut(); let mut keyed_accounts_iter = keyed_accounts.iter_mut();
let program = next_keyed_account(&mut keyed_accounts_iter)?; let script = next_keyed_account(&mut keyed_accounts_iter)?;
if program.account.owner != id() { if script.account.owner != id() {
debug!("Error: Move program account not owned by Move loader"); debug!("Error: Move script account not owned by Move loader");
return Err(InstructionError::InvalidArgument); return Err(InstructionError::InvalidArgument);
} }
match limited_deserialize(&program.account.data)? { match limited_deserialize(&script.account.data)? {
LibraAccountState::Unallocated => Self::serialize_and_enforce_length( LibraAccountState::Unallocated => Self::serialize_and_enforce_length(
&LibraAccountState::create_genesis(amount)?, &LibraAccountState::create_genesis(amount)?,
&mut program.account.data, &mut script.account.data,
), ),
_ => { _ => {
debug!("Error: Must provide an unallocated account"); debug!("Error: Must provide an unallocated account");
@ -393,35 +374,39 @@ impl MoveProcessor {
} }
} }
} }
InvokeCommand::RunProgram { InvokeCommand::RunScript {
sender_address, sender_address,
function_name, function_name,
args, args,
} => { } => {
let mut keyed_accounts_iter = keyed_accounts.iter_mut(); let mut keyed_accounts_iter = keyed_accounts.iter_mut();
let program = next_keyed_account(&mut keyed_accounts_iter)?; let script = next_keyed_account(&mut keyed_accounts_iter)?;
if program.account.owner != id() { trace!(
debug!("Error: Move program account not owned by Move loader"); "Run script {:?} with entrypoint {:?}",
script.unsigned_key(),
function_name
);
if script.account.owner != id() {
debug!("Error: Move script account not owned by Move loader");
return Err(InstructionError::InvalidArgument); return Err(InstructionError::InvalidArgument);
} }
if !program.account.executable { if !script.account.executable {
debug!("Error: Move program account not executable"); debug!("Error: Move script account not executable");
return Err(InstructionError::AccountNotExecutable); return Err(InstructionError::AccountNotExecutable);
} }
let data_accounts = keyed_accounts_iter.into_slice(); let data_accounts = keyed_accounts_iter.into_slice();
let mut data_store = Self::keyed_accounts_to_data_store(&data_accounts)?; let mut data_store = Self::keyed_accounts_to_data_store(&data_accounts)?;
let (verified_script, verified_modules) = let verified_script = Self::deserialize_verified_script(&script.account.data)?;
Self::deserialize_verified_program(&program.account.data)?;
let output = Self::execute( let output = Self::execute(
sender_address, sender_address,
&function_name, &function_name,
args, args,
verified_script, verified_script,
verified_modules,
&data_store, &data_store,
)?; )?;
for event in output.events() { for event in output.events() {
@ -476,15 +461,15 @@ mod tests {
let code = "main() { return; }"; let code = "main() { return; }";
let sender_address = AccountAddress::default(); let sender_address = AccountAddress::default();
let mut program = LibraAccount::create_program(&sender_address, code, vec![]); let mut script = LibraAccount::create_script(&sender_address, code, vec![]);
let rent_id = rent::id(); let rent_id = rent::id();
let mut rent_account = rent::create_account(1, &Rent::default()); let mut rent_account = rent::create_account(1, &Rent::default());
let mut keyed_accounts = vec![ let mut keyed_accounts = vec![
KeyedAccount::new(&program.key, true, &mut program.account), KeyedAccount::new(&script.key, true, &mut script.account),
KeyedAccount::new(&rent_id, false, &mut rent_account), KeyedAccount::new(&rent_id, false, &mut rent_account),
]; ];
MoveProcessor::do_finalize(&mut keyed_accounts).unwrap(); MoveProcessor::do_finalize(&mut keyed_accounts).unwrap();
let (_, _) = MoveProcessor::deserialize_verified_program(&program.account.data).unwrap(); let _ = MoveProcessor::deserialize_verified_script(&script.account.data).unwrap();
} }
#[test] #[test]
@ -492,14 +477,13 @@ mod tests {
solana_logger::setup(); solana_logger::setup();
let amount = 10_000_000; let amount = 10_000_000;
let mut unallocated = LibraAccount::create_unallocated(); let mut unallocated = LibraAccount::create_unallocated(BIG_ENOUGH);
let mut keyed_accounts = vec![KeyedAccount::new( let mut keyed_accounts = vec![KeyedAccount::new(
&unallocated.key, &unallocated.key,
false, false,
&mut unallocated.account, &mut unallocated.account,
)]; )];
keyed_accounts[0].account.data.resize(BIG_ENOUGH, 0);
MoveProcessor::do_invoke_main( MoveProcessor::do_invoke_main(
&mut keyed_accounts, &mut keyed_accounts,
&bincode::serialize(&InvokeCommand::CreateGenesis(amount)).unwrap(), &bincode::serialize(&InvokeCommand::CreateGenesis(amount)).unwrap(),
@ -516,31 +500,31 @@ mod tests {
} }
#[test] #[test]
fn test_invoke_main() { fn test_invoke_script() {
solana_logger::setup(); solana_logger::setup();
let code = "main() { return; }"; let code = "main() { return; }";
let sender_address = AccountAddress::default(); let sender_address = AccountAddress::default();
let mut program = LibraAccount::create_program(&sender_address, code, vec![]); let mut script = LibraAccount::create_script(&sender_address, code, vec![]);
let mut genesis = LibraAccount::create_genesis(1_000_000_000); let mut genesis = LibraAccount::create_genesis(1_000_000_000);
let rent_id = rent::id(); let rent_id = rent::id();
let mut rent_account = rent::create_account(1, &Rent::default()); let mut rent_account = rent::create_account(1, &Rent::default());
let mut keyed_accounts = vec![ let mut keyed_accounts = vec![
KeyedAccount::new(&program.key, true, &mut program.account), KeyedAccount::new(&script.key, true, &mut script.account),
KeyedAccount::new(&rent_id, false, &mut rent_account), KeyedAccount::new(&rent_id, false, &mut rent_account),
]; ];
MoveProcessor::do_finalize(&mut keyed_accounts).unwrap(); MoveProcessor::do_finalize(&mut keyed_accounts).unwrap();
let mut keyed_accounts = vec![ let mut keyed_accounts = vec![
KeyedAccount::new(&program.key, true, &mut program.account), KeyedAccount::new(&script.key, true, &mut script.account),
KeyedAccount::new(&genesis.key, false, &mut genesis.account), KeyedAccount::new(&genesis.key, false, &mut genesis.account),
]; ];
MoveProcessor::do_invoke_main( MoveProcessor::do_invoke_main(
&mut keyed_accounts, &mut keyed_accounts,
&bincode::serialize(&InvokeCommand::RunProgram { &bincode::serialize(&InvokeCommand::RunScript {
sender_address, sender_address,
function_name: "main".to_string(), function_name: "main".to_string(),
args: vec![], args: vec![],
@ -550,6 +534,29 @@ mod tests {
.unwrap(); .unwrap();
} }
#[test]
fn test_publish_module() {
solana_logger::setup();
let code = "
module M {
universal_truth(): u64 {
return 42;
}
}
";
let mut module = LibraAccount::create_module(code, vec![]);
let rent_id = rent::id();
let mut rent_account = rent::create_account(1, &Rent::default());
let mut keyed_accounts = vec![
KeyedAccount::new(&module.key, true, &mut module.account),
KeyedAccount::new(&rent_id, false, &mut rent_account),
];
keyed_accounts[0].account.data.resize(BIG_ENOUGH, 0);
MoveProcessor::do_finalize(&mut keyed_accounts).unwrap();
}
#[test] #[test]
fn test_invoke_endless_loop() { fn test_invoke_endless_loop() {
solana_logger::setup(); solana_logger::setup();
@ -561,27 +568,27 @@ mod tests {
} }
"; ";
let sender_address = AccountAddress::default(); let sender_address = AccountAddress::default();
let mut program = LibraAccount::create_program(&sender_address, code, vec![]); let mut script = LibraAccount::create_script(&sender_address, code, vec![]);
let mut genesis = LibraAccount::create_genesis(1_000_000_000); let mut genesis = LibraAccount::create_genesis(1_000_000_000);
let rent_id = rent::id(); let rent_id = rent::id();
let mut rent_account = rent::create_account(1, &Rent::default()); let mut rent_account = rent::create_account(1, &Rent::default());
let mut keyed_accounts = vec![ let mut keyed_accounts = vec![
KeyedAccount::new(&program.key, true, &mut program.account), KeyedAccount::new(&script.key, true, &mut script.account),
KeyedAccount::new(&rent_id, false, &mut rent_account), KeyedAccount::new(&rent_id, false, &mut rent_account),
]; ];
MoveProcessor::do_finalize(&mut keyed_accounts).unwrap(); MoveProcessor::do_finalize(&mut keyed_accounts).unwrap();
let mut keyed_accounts = vec![ let mut keyed_accounts = vec![
KeyedAccount::new(&program.key, true, &mut program.account), KeyedAccount::new(&script.key, true, &mut script.account),
KeyedAccount::new(&genesis.key, false, &mut genesis.account), KeyedAccount::new(&genesis.key, false, &mut genesis.account),
]; ];
assert_eq!( assert_eq!(
MoveProcessor::do_invoke_main( MoveProcessor::do_invoke_main(
&mut keyed_accounts, &mut keyed_accounts,
&bincode::serialize(&InvokeCommand::RunProgram { &bincode::serialize(&InvokeCommand::RunScript {
sender_address, sender_address,
function_name: "main".to_string(), function_name: "main".to_string(),
args: vec![], args: vec![],
@ -602,7 +609,7 @@ mod tests {
let mut accounts = mint_coins(amount).unwrap(); let mut accounts = mint_coins(amount).unwrap();
let mut accounts_iter = accounts.iter_mut(); let mut accounts_iter = accounts.iter_mut();
let _program = next_libra_account(&mut accounts_iter).unwrap(); let _script = next_libra_account(&mut accounts_iter).unwrap();
let genesis = next_libra_account(&mut accounts_iter).unwrap(); let genesis = next_libra_account(&mut accounts_iter).unwrap();
let payee = next_libra_account(&mut accounts_iter).unwrap(); let payee = next_libra_account(&mut accounts_iter).unwrap();
match bincode::deserialize(&payee.account.data).unwrap() { match bincode::deserialize(&payee.account.data).unwrap() {
@ -616,8 +623,6 @@ mod tests {
} }
let payee_resource = data_store.read_account_resource(&payee.address).unwrap(); let payee_resource = data_store.read_account_resource(&payee.address).unwrap();
println!("{}:{}", line!(), file!());
assert_eq!(amount, payee_resource.balance()); assert_eq!(amount, payee_resource.balance());
assert_eq!(0, payee_resource.sequence_number()); assert_eq!(0, payee_resource.sequence_number());
} }
@ -629,7 +634,7 @@ mod tests {
let mut accounts = mint_coins(amount_to_mint).unwrap(); let mut accounts = mint_coins(amount_to_mint).unwrap();
let mut accounts_iter = accounts.iter_mut(); let mut accounts_iter = accounts.iter_mut();
let _program = next_libra_account(&mut accounts_iter).unwrap(); let _script = next_libra_account(&mut accounts_iter).unwrap();
let genesis = next_libra_account(&mut accounts_iter).unwrap(); let genesis = next_libra_account(&mut accounts_iter).unwrap();
let sender = next_libra_account(&mut accounts_iter).unwrap(); let sender = next_libra_account(&mut accounts_iter).unwrap();
@ -641,32 +646,29 @@ mod tests {
return; return;
} }
"; ";
let mut program = LibraAccount::create_program(&genesis.address, code, vec![]); let mut script = LibraAccount::create_script(&genesis.address, code, vec![]);
let mut payee = LibraAccount::create_unallocated(); let mut payee = LibraAccount::create_unallocated(BIG_ENOUGH);
let rent_id = rent::id(); let rent_id = rent::id();
let mut rent_account = rent::create_account(1, &Rent::default()); let mut rent_account = rent::create_account(1, &Rent::default());
let mut keyed_accounts = vec![ let mut keyed_accounts = vec![
KeyedAccount::new(&program.key, true, &mut program.account), KeyedAccount::new(&script.key, true, &mut script.account),
KeyedAccount::new(&rent_id, false, &mut rent_account), KeyedAccount::new(&rent_id, false, &mut rent_account),
]; ];
keyed_accounts[0].account.data.resize(BIG_ENOUGH, 0);
MoveProcessor::do_finalize(&mut keyed_accounts).unwrap(); MoveProcessor::do_finalize(&mut keyed_accounts).unwrap();
let mut keyed_accounts = vec![ let mut keyed_accounts = vec![
KeyedAccount::new(&program.key, true, &mut program.account), KeyedAccount::new(&script.key, true, &mut script.account),
KeyedAccount::new(&genesis.key, false, &mut genesis.account), KeyedAccount::new(&genesis.key, false, &mut genesis.account),
KeyedAccount::new(&sender.key, false, &mut sender.account), KeyedAccount::new(&sender.key, false, &mut sender.account),
KeyedAccount::new(&payee.key, false, &mut payee.account), KeyedAccount::new(&payee.key, false, &mut payee.account),
]; ];
keyed_accounts[2].account.data.resize(BIG_ENOUGH, 0);
keyed_accounts[3].account.data.resize(BIG_ENOUGH, 0);
let amount = 2; let amount = 2;
MoveProcessor::do_invoke_main( MoveProcessor::do_invoke_main(
&mut keyed_accounts, &mut keyed_accounts,
&bincode::serialize(&InvokeCommand::RunProgram { &bincode::serialize(&InvokeCommand::RunScript {
sender_address: sender.address.clone(), sender_address: sender.address.clone(),
function_name: "main".to_string(), function_name: "main".to_string(),
args: vec![ args: vec![
@ -688,147 +690,101 @@ mod tests {
assert_eq!(0, payee_resource.sequence_number()); assert_eq!(0, payee_resource.sequence_number());
} }
#[test]
fn test_invoke_local_module() {
solana_logger::setup();
let code = "
modules:
module M {
public universal_truth(): u64 {
return 42;
}
}
script:
import Transaction.M;
main() {
let x: u64;
x = M.universal_truth();
return;
}
";
let mut genesis = LibraAccount::create_genesis(1_000_000_000);
let mut payee = LibraAccount::create_unallocated();
let mut program = LibraAccount::create_program(&payee.address, code, vec![]);
let rent_id = rent::id();
let mut rent_account = rent::create_account(1, &Rent::default());
let mut keyed_accounts = vec![
KeyedAccount::new(&program.key, true, &mut program.account),
KeyedAccount::new(&rent_id, false, &mut rent_account),
];
keyed_accounts[0].account.data.resize(BIG_ENOUGH, 0);
MoveProcessor::do_finalize(&mut keyed_accounts).unwrap();
let mut keyed_accounts = vec![
KeyedAccount::new(&program.key, true, &mut program.account),
KeyedAccount::new(&genesis.key, false, &mut genesis.account),
KeyedAccount::new(&payee.key, false, &mut payee.account),
];
keyed_accounts[2].account.data.resize(BIG_ENOUGH, 0);
MoveProcessor::do_invoke_main(
&mut keyed_accounts,
&bincode::serialize(&InvokeCommand::RunProgram {
sender_address: payee.address,
function_name: "main".to_string(),
args: vec![],
})
.unwrap(),
)
.unwrap();
}
#[test] #[test]
fn test_invoke_published_module() { fn test_invoke_published_module() {
solana_logger::setup(); solana_logger::setup();
let universal_truth = 42;
// First publish the module // First publish the module
let code = " let code = format!(
module M { "
public universal_truth(): u64 { module M {{
return 42; public universal_truth(): u64 {{
} return {};
} }}
"; }}
let mut module = LibraAccount::create_unallocated(); ",
let mut program = LibraAccount::create_program(&module.address, code, vec![]); universal_truth
let mut genesis = LibraAccount::create_genesis(1_000_000_000); );
let mut module = LibraAccount::create_module(&code, vec![]);
let rent_id = rent::id(); let rent_id = rent::id();
let mut rent_account = rent::create_account(1, &Rent::default()); let mut rent_account = rent::create_account(1, &Rent::default());
let mut keyed_accounts = vec![ let mut keyed_accounts = vec![
KeyedAccount::new(&program.key, true, &mut program.account), KeyedAccount::new(&module.key, true, &mut module.account),
KeyedAccount::new(&rent_id, false, &mut rent_account), KeyedAccount::new(&rent_id, false, &mut rent_account),
]; ];
keyed_accounts[0].account.data.resize(BIG_ENOUGH, 0); keyed_accounts[0].account.data.resize(BIG_ENOUGH, 0);
MoveProcessor::do_finalize(&mut keyed_accounts).unwrap(); MoveProcessor::do_finalize(&mut keyed_accounts).unwrap();
let mut keyed_accounts = vec![
KeyedAccount::new(&program.key, true, &mut program.account),
KeyedAccount::new(&genesis.key, false, &mut genesis.account),
KeyedAccount::new(&module.key, false, &mut module.account),
];
keyed_accounts[2].account.data.resize(BIG_ENOUGH, 0);
MoveProcessor::do_invoke_main(
&mut keyed_accounts,
&bincode::serialize(&InvokeCommand::RunProgram {
sender_address: module.address,
function_name: "main".to_string(),
args: vec![],
})
.unwrap(),
)
.unwrap();
// Next invoke the published module // Next invoke the published module
let amount_to_mint = 84;
let mut accounts = mint_coins(amount_to_mint).unwrap();
let mut accounts_iter = accounts.iter_mut();
let _script = next_libra_account(&mut accounts_iter).unwrap();
let genesis = next_libra_account(&mut accounts_iter).unwrap();
let sender = next_libra_account(&mut accounts_iter).unwrap();
let code = format!( let code = format!(
" "
import 0x0.LibraAccount;
import 0x0.LibraCoin;
import 0x{}.M; import 0x{}.M;
main() {{
let x: u64; main(payee: address) {{
x = M.universal_truth(); let amount: u64;
amount = M.universal_truth();
LibraAccount.pay_from_sender(move(payee), move(amount));
return; return;
}} }}
", ",
module.address module.address
); );
let mut program = let mut script =
LibraAccount::create_program(&module.address, &code, vec![&module.account.data]); LibraAccount::create_script(&genesis.address, &code, vec![&module.account.data]);
let mut payee = LibraAccount::create_unallocated(BIG_ENOUGH);
let rent_id = rent::id(); let rent_id = rent::id();
let mut rent_account = rent::create_account(1, &Rent::default()); let mut rent_account = rent::create_account(1, &Rent::default());
let mut keyed_accounts = vec![ let mut keyed_accounts = vec![
KeyedAccount::new(&program.key, true, &mut program.account), KeyedAccount::new(&script.key, true, &mut script.account),
KeyedAccount::new(&rent_id, false, &mut rent_account), KeyedAccount::new(&rent_id, false, &mut rent_account),
]; ];
MoveProcessor::do_finalize(&mut keyed_accounts).unwrap(); MoveProcessor::do_finalize(&mut keyed_accounts).unwrap();
let mut keyed_accounts = vec![ let mut keyed_accounts = vec![
KeyedAccount::new(&program.key, true, &mut program.account), KeyedAccount::new(&script.key, true, &mut script.account),
KeyedAccount::new(&genesis.key, false, &mut genesis.account), KeyedAccount::new(&genesis.key, false, &mut genesis.account),
KeyedAccount::new(&sender.key, false, &mut sender.account),
KeyedAccount::new(&module.key, false, &mut module.account), KeyedAccount::new(&module.key, false, &mut module.account),
KeyedAccount::new(&payee.key, false, &mut payee.account),
]; ];
MoveProcessor::do_invoke_main( MoveProcessor::do_invoke_main(
&mut keyed_accounts, &mut keyed_accounts,
&bincode::serialize(&InvokeCommand::RunProgram { &bincode::serialize(&InvokeCommand::RunScript {
sender_address: program.address, sender_address: sender.address.clone(),
function_name: "main".to_string(), function_name: "main".to_string(),
args: vec![], args: vec![TransactionArgument::Address(payee.address.clone())],
}) })
.unwrap(), .unwrap(),
) )
.unwrap(); .unwrap();
let data_store = MoveProcessor::keyed_accounts_to_data_store(&keyed_accounts[1..]).unwrap();
let sender_resource = data_store.read_account_resource(&sender.address).unwrap();
let payee_resource = data_store.read_account_resource(&payee.address).unwrap();
assert_eq!(amount_to_mint - universal_truth, sender_resource.balance());
assert_eq!(0, sender_resource.sequence_number());
assert_eq!(universal_truth, payee_resource.balance());
assert_eq!(0, payee_resource.sequence_number());
} }
// Helpers // Helpers
@ -843,30 +799,28 @@ mod tests {
} }
"; ";
let mut genesis = LibraAccount::create_genesis(1_000_000_000); let mut genesis = LibraAccount::create_genesis(1_000_000_000);
let mut program = LibraAccount::create_program(&genesis.address, code, vec![]); let mut script = LibraAccount::create_script(&genesis.address.clone(), code, vec![]);
let mut payee = LibraAccount::create_unallocated(); let mut payee = LibraAccount::create_unallocated(BIG_ENOUGH);
let rent_id = rent::id(); let rent_id = rent::id();
let mut rent_account = rent::create_account(1, &Rent::default()); let mut rent_account = rent::create_account(1, &Rent::default());
let mut keyed_accounts = vec![ let mut keyed_accounts = vec![
KeyedAccount::new(&program.key, true, &mut program.account), KeyedAccount::new(&script.key, true, &mut script.account),
KeyedAccount::new(&rent_id, false, &mut rent_account), KeyedAccount::new(&rent_id, false, &mut rent_account),
]; ];
keyed_accounts[0].account.data.resize(BIG_ENOUGH, 0);
MoveProcessor::do_finalize(&mut keyed_accounts).unwrap(); MoveProcessor::do_finalize(&mut keyed_accounts).unwrap();
let mut keyed_accounts = vec![ let mut keyed_accounts = vec![
KeyedAccount::new(&program.key, true, &mut program.account), KeyedAccount::new(&script.key, true, &mut script.account),
KeyedAccount::new(&genesis.key, false, &mut genesis.account), KeyedAccount::new(&genesis.key, false, &mut genesis.account),
KeyedAccount::new(&payee.key, false, &mut payee.account), KeyedAccount::new(&payee.key, false, &mut payee.account),
]; ];
keyed_accounts[2].account.data.resize(BIG_ENOUGH, 0);
MoveProcessor::do_invoke_main( MoveProcessor::do_invoke_main(
&mut keyed_accounts, &mut keyed_accounts,
&bincode::serialize(&InvokeCommand::RunProgram { &bincode::serialize(&InvokeCommand::RunScript {
sender_address: genesis.address.clone(), sender_address: account_config::association_address(),
function_name: "main".to_string(), function_name: "main".to_string(),
args: vec![ args: vec![
TransactionArgument::Address(pubkey_to_address(&payee.key)), TransactionArgument::Address(pubkey_to_address(&payee.key)),
@ -878,7 +832,7 @@ mod tests {
.unwrap(); .unwrap();
Ok(vec![ Ok(vec![
LibraAccount::new(program.key, program.account), LibraAccount::new(script.key, script.account),
LibraAccount::new(genesis.key, genesis.account), LibraAccount::new(genesis.key, genesis.account),
LibraAccount::new(payee.key, payee.account), LibraAccount::new(payee.key, payee.account),
]) ])
@ -905,14 +859,18 @@ mod tests {
} }
} }
pub fn create_unallocated() -> Self { pub fn create_unallocated(size: usize) -> Self {
let key = Pubkey::new_rand(); let key = Pubkey::new_rand();
let account = Account { let mut account = Account {
lamports: 1, lamports: 1,
data: bincode::serialize(&LibraAccountState::create_unallocated()).unwrap(), data: bincode::serialize(&LibraAccountState::create_unallocated()).unwrap(),
owner: id(), owner: id(),
..Account::default() ..Account::default()
}; };
if account.data.len() < size {
account.data.resize(size, 0);
}
Self::new(key, account) Self::new(key, account)
} }
@ -922,30 +880,39 @@ mod tests {
owner: id(), owner: id(),
..Account::default() ..Account::default()
}; };
let mut genesis = Self::new( let mut genesis = Self::new(Pubkey::new_rand(), account);
Pubkey::new(&account_config::association_address().to_vec()),
account,
);
let pre_data = LibraAccountState::create_genesis(amount).unwrap(); let pre_data = LibraAccountState::create_genesis(amount).unwrap();
let _hi = "hello"; let _hi = "hello";
genesis.account.data = bincode::serialize(&pre_data).unwrap(); genesis.account.data = bincode::serialize(&pre_data).unwrap();
genesis genesis
} }
pub fn create_program( pub fn create_script(
sender_address: &AccountAddress, sender_address: &AccountAddress,
code: &str, code: &str,
deps: Vec<&Vec<u8>>, deps: Vec<&Vec<u8>>,
) -> Self { ) -> Self {
let mut program = Self::create_unallocated(); let mut script = Self::create_unallocated(0);
program.account.data = bincode::serialize(&LibraAccountState::create_program( script.account.data = bincode::serialize(&LibraAccountState::create_script(
sender_address, sender_address,
code, code,
deps, deps,
)) ))
.unwrap(); .unwrap();
program.account.executable = true;
program script
}
pub fn create_module(code: &str, deps: Vec<&Vec<u8>>) -> Self {
let mut module = Self::create_unallocated(0);
module.account.data = bincode::serialize(&LibraAccountState::create_module(
&module.address,
code,
deps,
))
.unwrap();
module
} }
} }
} }

View File

@ -1593,7 +1593,7 @@ mod tests {
let mut stake_keyed_account = KeyedAccount::new(&stake_pubkey, true, &mut stake_account); let mut stake_keyed_account = KeyedAccount::new(&stake_pubkey, true, &mut stake_account);
// Stake some lamports (available lampoorts for withdrawals will reduce) // Stake some lamports (available lamports for withdrawals will reduce)
let vote_pubkey = Pubkey::new_rand(); let vote_pubkey = Pubkey::new_rand();
let mut vote_account = let mut vote_account =
vote_state::create_account(&vote_pubkey, &Pubkey::new_rand(), 0, 100); vote_state::create_account(&vote_pubkey, &Pubkey::new_rand(), 0, 100);