2019-06-06 17:40:01 -07:00
										 
									 
								 
							 | 
							
								
							 | 
							
								
							 | 
							
							
								use assert_matches::assert_matches;
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								use bincode::deserialize;
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								use log::*;
							 | 
						
					
						
							
								
									
										
										
										
											2019-10-04 15:18:19 -06:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								use solana_runtime::{
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								    bank::Bank,
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								    bank_client::BankClient,
							 | 
						
					
						
							
								
									
										
										
										
											2019-11-08 23:56:57 -05:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								    genesis_utils::{create_genesis_config, GenesisConfigInfo},
							 | 
						
					
						
							
								
									
										
										
										
											2019-10-04 15:18:19 -06:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								};
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								use solana_sdk::{
							 | 
						
					
						
							
								
									
										
										
										
											2020-01-22 17:54:06 -08:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								    account_utils::StateMut,
							 | 
						
					
						
							
								
									
										
										
										
											2019-10-04 15:18:19 -06:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								    client::SyncClient,
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								    clock::{get_segment_from_slot, DEFAULT_SLOTS_PER_SEGMENT, DEFAULT_TICKS_PER_SLOT},
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								    hash::{hash, Hash},
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								    message::Message,
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								    pubkey::Pubkey,
							 | 
						
					
						
							
								
									
										
										
										
											2020-02-20 14:28:55 -07:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								    signature::{Keypair, Signature, Signer},
							 | 
						
					
						
							
								
									
										
										
										
											2019-10-04 15:18:19 -06:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								    system_instruction,
							 | 
						
					
						
							
								
									
										
										
										
											2019-11-04 12:31:24 -08:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								    sysvar::{
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								        rewards::{self, Rewards},
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								        Sysvar,
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								    },
							 | 
						
					
						
							
								
									
										
										
										
											2019-10-04 15:18:19 -06:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								};
							 | 
						
					
						
							
								
									
										
										
										
											2019-11-20 16:32:19 -08:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								use solana_storage_program::{
							 | 
						
					
						
							
								
									
										
										
										
											2019-10-04 15:18:19 -06:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								    id,
							 | 
						
					
						
							
								
									
										
										
										
											2019-12-04 12:41:54 -08:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								    storage_contract::{ProofStatus, StorageContract},
							 | 
						
					
						
							
								
									
										
										
										
											2019-10-04 15:18:19 -06:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								    storage_instruction::{self, StorageAccountType},
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								    storage_processor::process_instruction,
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								};
							 | 
						
					
						
							
								
									
										
										
										
											2020-01-28 17:03:20 -08:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								use std::{collections::HashMap, sync::Arc};
							 | 
						
					
						
							
								
									
										
										
										
											2019-06-06 17:40:01 -07:00
										 
									 
								 
							 | 
							
								
							 | 
							
								
							 | 
							
							
								
							 | 
						
					
						
							
								
									
										
										
										
											2019-07-09 16:48:40 -07:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								const TICKS_IN_SEGMENT: u64 = DEFAULT_SLOTS_PER_SEGMENT * DEFAULT_TICKS_PER_SLOT;
							 | 
						
					
						
							
								
									
										
										
										
											2019-06-06 17:40:01 -07:00
										 
									 
								 
							 | 
							
								
							 | 
							
								
							 | 
							
							
								
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								#[test]
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								fn test_account_owner() {
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								    let account_owner = Pubkey::new_rand();
							 | 
						
					
						
							
								
									
										
										
										
											2019-11-08 15:57:35 +05:30
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								    let validator_storage_keypair = Keypair::new();
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								    let validator_storage_pubkey = validator_storage_keypair.pubkey();
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								    let archiver_storage_keypair = Keypair::new();
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								    let archiver_storage_pubkey = archiver_storage_keypair.pubkey();
							 | 
						
					
						
							
								
									
										
										
										
											2019-06-06 17:40:01 -07:00
										 
									 
								 
							 | 
							
								
							 | 
							
								
							 | 
							
							
								
							 | 
						
					
						
							
								
									
										
										
										
											2019-11-08 23:56:57 -05:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								    let GenesisConfigInfo {
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								        genesis_config,
							 | 
						
					
						
							
								
									
										
										
										
											2019-06-22 17:18:35 -07:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								        mint_keypair,
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								        ..
							 | 
						
					
						
							
								
									
										
										
										
											2019-11-08 23:56:57 -05:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								    } = create_genesis_config(1000);
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								    let mut bank = Bank::new(&genesis_config);
							 | 
						
					
						
							
								
									
										
										
										
											2019-06-06 17:40:01 -07:00
										 
									 
								 
							 | 
							
								
							 | 
							
								
							 | 
							
							
								    let mint_pubkey = mint_keypair.pubkey();
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								    bank.add_instruction_processor(id(), process_instruction);
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								    let bank = Arc::new(bank);
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								    let bank_client = BankClient::new_shared(&bank);
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								
							 | 
						
					
						
							
								
									
										
										
										
											2019-10-04 15:18:19 -06:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								    let message = Message::new(storage_instruction::create_storage_account(
							 | 
						
					
						
							
								
									
										
										
										
											2019-06-06 17:40:01 -07:00
										 
									 
								 
							 | 
							
								
							 | 
							
								
							 | 
							
							
								        &mint_pubkey,
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								        &account_owner,
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								        &validator_storage_pubkey,
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								        1,
							 | 
						
					
						
							
								
									
										
										
										
											2019-10-04 15:18:19 -06:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								        StorageAccountType::Validator,
							 | 
						
					
						
							
								
									
										
										
										
											2019-06-06 17:40:01 -07:00
										 
									 
								 
							 | 
							
								
							 | 
							
								
							 | 
							
							
								    ));
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								    bank_client
							 | 
						
					
						
							
								
									
										
										
										
											2019-11-08 15:57:35 +05:30
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								        .send_message(&[&mint_keypair, &validator_storage_keypair], message)
							 | 
						
					
						
							
								
									
										
										
										
											2019-06-06 17:40:01 -07:00
										 
									 
								 
							 | 
							
								
							 | 
							
								
							 | 
							
							
								        .expect("failed to create account");
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								    let account = bank
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								        .get_account(&validator_storage_pubkey)
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								        .expect("account not found");
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								    let storage_contract = account.state().expect("couldn't unpack account data");
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								    if let StorageContract::ValidatorStorage { owner, .. } = storage_contract {
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								        assert_eq!(owner, account_owner);
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								    } else {
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								        assert!(false, "wrong account type found")
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								    }
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								
							 | 
						
					
						
							
								
									
										
										
										
											2019-10-04 15:18:19 -06:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								    let message = Message::new(storage_instruction::create_storage_account(
							 | 
						
					
						
							
								
									
										
										
										
											2019-06-06 17:40:01 -07:00
										 
									 
								 
							 | 
							
								
							 | 
							
								
							 | 
							
							
								        &mint_pubkey,
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								        &account_owner,
							 | 
						
					
						
							
								
									
										
										
										
											2019-10-21 11:29:37 -06:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								        &archiver_storage_pubkey,
							 | 
						
					
						
							
								
									
										
										
										
											2019-06-06 17:40:01 -07:00
										 
									 
								 
							 | 
							
								
							 | 
							
								
							 | 
							
							
								        1,
							 | 
						
					
						
							
								
									
										
										
										
											2019-10-21 11:29:37 -06:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								        StorageAccountType::Archiver,
							 | 
						
					
						
							
								
									
										
										
										
											2019-06-06 17:40:01 -07:00
										 
									 
								 
							 | 
							
								
							 | 
							
								
							 | 
							
							
								    ));
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								    bank_client
							 | 
						
					
						
							
								
									
										
										
										
											2019-11-08 15:57:35 +05:30
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								        .send_message(&[&mint_keypair, &archiver_storage_keypair], message)
							 | 
						
					
						
							
								
									
										
										
										
											2019-06-06 17:40:01 -07:00
										 
									 
								 
							 | 
							
								
							 | 
							
								
							 | 
							
							
								        .expect("failed to create account");
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								    let account = bank
							 | 
						
					
						
							
								
									
										
										
										
											2019-10-21 11:29:37 -06:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								        .get_account(&archiver_storage_pubkey)
							 | 
						
					
						
							
								
									
										
										
										
											2019-06-06 17:40:01 -07:00
										 
									 
								 
							 | 
							
								
							 | 
							
								
							 | 
							
							
								        .expect("account not found");
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								    let storage_contract = account.state().expect("couldn't unpack account data");
							 | 
						
					
						
							
								
									
										
										
										
											2019-10-21 11:29:37 -06:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								    if let StorageContract::ArchiverStorage { owner, .. } = storage_contract {
							 | 
						
					
						
							
								
									
										
										
										
											2019-06-06 17:40:01 -07:00
										 
									 
								 
							 | 
							
								
							 | 
							
								
							 | 
							
							
								        assert_eq!(owner, account_owner);
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								    } else {
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								        assert!(false, "wrong account type found")
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								    }
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								}
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								#[test]
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								fn test_validate_mining() {
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								    solana_logger::setup();
							 | 
						
					
						
							
								
									
										
										
										
											2019-11-08 23:56:57 -05:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								    let GenesisConfigInfo {
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								        mut genesis_config,
							 | 
						
					
						
							
								
									
										
										
										
											2019-06-22 17:18:35 -07:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								        mint_keypair,
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								        ..
							 | 
						
					
						
							
								
									
										
										
										
											2019-11-08 23:56:57 -05:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								    } = create_genesis_config(100_000_000_000);
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								    genesis_config
							 | 
						
					
						
							
								
									
										
										
										
											2019-06-11 18:27:47 -07:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								        .native_instruction_processors
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								        .push(solana_storage_program::solana_storage_program!());
							 | 
						
					
						
							
								
									
										
										
										
											2019-06-06 17:40:01 -07:00
										 
									 
								 
							 | 
							
								
							 | 
							
								
							 | 
							
							
								    let mint_pubkey = mint_keypair.pubkey();
							 | 
						
					
						
							
								
									
										
										
										
											2019-10-21 11:29:37 -06:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								    // 1 owner for all archiver and validator accounts for the test
							 | 
						
					
						
							
								
									
										
										
										
											2019-06-13 17:53:54 -07:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								    let owner_pubkey = Pubkey::new_rand();
							 | 
						
					
						
							
								
									
										
										
										
											2019-06-06 17:40:01 -07:00
										 
									 
								 
							 | 
							
								
							 | 
							
								
							 | 
							
							
								
							 | 
						
					
						
							
								
									
										
										
										
											2019-10-21 11:29:37 -06:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								    let archiver_1_storage_keypair = Keypair::new();
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								    let archiver_1_storage_id = archiver_1_storage_keypair.pubkey();
							 | 
						
					
						
							
								
									
										
										
										
											2019-06-06 17:40:01 -07:00
										 
									 
								 
							 | 
							
								
							 | 
							
								
							 | 
							
							
								
							 | 
						
					
						
							
								
									
										
										
										
											2019-10-21 11:29:37 -06:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								    let archiver_2_storage_keypair = Keypair::new();
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								    let archiver_2_storage_id = archiver_2_storage_keypair.pubkey();
							 | 
						
					
						
							
								
									
										
										
										
											2019-06-06 17:40:01 -07:00
										 
									 
								 
							 | 
							
								
							 | 
							
								
							 | 
							
							
								
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								    let validator_storage_keypair = Keypair::new();
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								    let validator_storage_id = validator_storage_keypair.pubkey();
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								
							 | 
						
					
						
							
								
									
										
										
										
											2019-11-08 23:56:57 -05:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								    let bank = Bank::new(&genesis_config);
							 | 
						
					
						
							
								
									
										
										
										
											2019-06-06 17:40:01 -07:00
										 
									 
								 
							 | 
							
								
							 | 
							
								
							 | 
							
							
								    let bank = Arc::new(bank);
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								    let bank_client = BankClient::new_shared(&bank);
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								    init_storage_accounts(
							 | 
						
					
						
							
								
									
										
										
										
											2019-06-13 17:53:54 -07:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								        &owner_pubkey,
							 | 
						
					
						
							
								
									
										
										
										
											2019-06-06 17:40:01 -07:00
										 
									 
								 
							 | 
							
								
							 | 
							
								
							 | 
							
							
								        &bank_client,
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								        &mint_keypair,
							 | 
						
					
						
							
								
									
										
										
										
											2019-11-08 15:57:35 +05:30
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								        &[&validator_storage_keypair],
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								        &[&archiver_1_storage_keypair, &archiver_2_storage_keypair],
							 | 
						
					
						
							
								
									
										
										
										
											2019-06-06 17:40:01 -07:00
										 
									 
								 
							 | 
							
								
							 | 
							
								
							 | 
							
							
								        10,
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								    );
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								
							 | 
						
					
						
							
								
									
										
										
										
											2019-06-11 18:27:47 -07:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								    // create a new bank in segment 2
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								    let bank = Arc::new(Bank::new_from_parent(
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								        &bank,
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								        &Pubkey::default(),
							 | 
						
					
						
							
								
									
										
										
										
											2019-07-09 16:48:40 -07:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								        DEFAULT_SLOTS_PER_SEGMENT * 2,
							 | 
						
					
						
							
								
									
										
										
										
											2019-06-11 18:27:47 -07:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								    ));
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								    let bank_client = BankClient::new_shared(&bank);
							 | 
						
					
						
							
								
									
										
										
										
											2019-06-06 17:40:01 -07:00
										 
									 
								 
							 | 
							
								
							 | 
							
								
							 | 
							
							
								
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								    // advertise for storage segment 1
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								    let message = Message::new_with_payer(
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								        vec![storage_instruction::advertise_recent_blockhash(
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								            &validator_storage_id,
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								            Hash::default(),
							 | 
						
					
						
							
								
									
										
										
										
											2019-07-09 16:48:40 -07:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								            1,
							 | 
						
					
						
							
								
									
										
										
										
											2019-06-06 17:40:01 -07:00
										 
									 
								 
							 | 
							
								
							 | 
							
								
							 | 
							
							
								        )],
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								        Some(&mint_pubkey),
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								    );
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								    assert_matches!(
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								        bank_client.send_message(&[&mint_keypair, &validator_storage_keypair], message),
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								        Ok(_)
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								    );
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								
							 | 
						
					
						
							
								
									
										
										
										
											2019-10-21 11:29:37 -06:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								    // submit proofs 5 proofs for each archiver for segment 0
							 | 
						
					
						
							
								
									
										
										
										
											2019-06-06 17:40:01 -07:00
										 
									 
								 
							 | 
							
								
							 | 
							
								
							 | 
							
							
								    let mut checked_proofs: HashMap<_, Vec<_>> = HashMap::new();
							 | 
						
					
						
							
								
									
										
										
										
											2019-06-11 18:27:47 -07:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								    for _ in 0..5 {
							 | 
						
					
						
							
								
									
										
										
										
											2019-06-06 17:40:01 -07:00
										 
									 
								 
							 | 
							
								
							 | 
							
								
							 | 
							
							
								        checked_proofs
							 | 
						
					
						
							
								
									
										
										
										
											2019-10-21 11:29:37 -06:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								            .entry(archiver_1_storage_id)
							 | 
						
					
						
							
								
									
										
										
										
											2019-06-06 17:40:01 -07:00
										 
									 
								 
							 | 
							
								
							 | 
							
								
							 | 
							
							
								            .or_default()
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								            .push(submit_proof(
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								                &mint_keypair,
							 | 
						
					
						
							
								
									
										
										
										
											2019-10-21 11:29:37 -06:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								                &archiver_1_storage_keypair,
							 | 
						
					
						
							
								
									
										
										
										
											2019-06-06 17:40:01 -07:00
										 
									 
								 
							 | 
							
								
							 | 
							
								
							 | 
							
							
								                &bank_client,
							 | 
						
					
						
							
								
									
										
										
										
											2019-06-11 18:27:47 -07:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								                0,
							 | 
						
					
						
							
								
									
										
										
										
											2019-06-06 17:40:01 -07:00
										 
									 
								 
							 | 
							
								
							 | 
							
								
							 | 
							
							
								            ));
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								        checked_proofs
							 | 
						
					
						
							
								
									
										
										
										
											2019-10-21 11:29:37 -06:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								            .entry(archiver_2_storage_id)
							 | 
						
					
						
							
								
									
										
										
										
											2019-06-06 17:40:01 -07:00
										 
									 
								 
							 | 
							
								
							 | 
							
								
							 | 
							
							
								            .or_default()
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								            .push(submit_proof(
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								                &mint_keypair,
							 | 
						
					
						
							
								
									
										
										
										
											2019-10-21 11:29:37 -06:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								                &archiver_2_storage_keypair,
							 | 
						
					
						
							
								
									
										
										
										
											2019-06-06 17:40:01 -07:00
										 
									 
								 
							 | 
							
								
							 | 
							
								
							 | 
							
							
								                &bank_client,
							 | 
						
					
						
							
								
									
										
										
										
											2019-06-11 18:27:47 -07:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								                0,
							 | 
						
					
						
							
								
									
										
										
										
											2019-06-06 17:40:01 -07:00
										 
									 
								 
							 | 
							
								
							 | 
							
								
							 | 
							
							
								            ));
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								    }
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								    let message = Message::new_with_payer(
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								        vec![storage_instruction::advertise_recent_blockhash(
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								            &validator_storage_id,
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								            Hash::default(),
							 | 
						
					
						
							
								
									
										
										
										
											2019-07-09 16:48:40 -07:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								            2,
							 | 
						
					
						
							
								
									
										
										
										
											2019-06-06 17:40:01 -07:00
										 
									 
								 
							 | 
							
								
							 | 
							
								
							 | 
							
							
								        )],
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								        Some(&mint_pubkey),
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								    );
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								
							 | 
						
					
						
							
								
									
										
										
										
											2019-06-11 18:27:47 -07:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								    // move banks into the next segment
							 | 
						
					
						
							
								
									
										
										
										
											2019-07-09 16:48:40 -07:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								    let proof_segment = get_segment_from_slot(bank.slot(), bank.slots_per_segment());
							 | 
						
					
						
							
								
									
										
										
										
											2019-06-11 18:27:47 -07:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								    let bank = Arc::new(Bank::new_from_parent(
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								        &bank,
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								        &Pubkey::default(),
							 | 
						
					
						
							
								
									
										
										
										
											2019-07-09 16:48:40 -07:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								        DEFAULT_SLOTS_PER_SEGMENT + bank.slot(),
							 | 
						
					
						
							
								
									
										
										
										
											2019-06-11 18:27:47 -07:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								    ));
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								    let bank_client = BankClient::new_shared(&bank);
							 | 
						
					
						
							
								
									
										
										
										
											2019-06-06 17:40:01 -07:00
										 
									 
								 
							 | 
							
								
							 | 
							
								
							 | 
							
							
								
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								    assert_matches!(
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								        bank_client.send_message(&[&mint_keypair, &validator_storage_keypair], message),
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								        Ok(_)
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								    );
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								    let message = Message::new_with_payer(
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								        vec![storage_instruction::proof_validation(
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								            &validator_storage_id,
							 | 
						
					
						
							
								
									
										
										
										
											2019-06-11 18:27:47 -07:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								            proof_segment as u64,
							 | 
						
					
						
							
								
									
										
										
										
											2019-06-13 17:53:54 -07:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								            checked_proofs.into_iter().map(|entry| entry).collect(),
							 | 
						
					
						
							
								
									
										
										
										
											2019-06-06 17:40:01 -07:00
										 
									 
								 
							 | 
							
								
							 | 
							
								
							 | 
							
							
								        )],
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								        Some(&mint_pubkey),
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								    );
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								    assert_matches!(
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								        bank_client.send_message(&[&mint_keypair, &validator_storage_keypair], message),
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								        Ok(_)
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								    );
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								    let message = Message::new_with_payer(
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								        vec![storage_instruction::advertise_recent_blockhash(
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								            &validator_storage_id,
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								            Hash::default(),
							 | 
						
					
						
							
								
									
										
										
										
											2019-07-09 16:48:40 -07:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								            3,
							 | 
						
					
						
							
								
									
										
										
										
											2019-06-06 17:40:01 -07:00
										 
									 
								 
							 | 
							
								
							 | 
							
								
							 | 
							
							
								        )],
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								        Some(&mint_pubkey),
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								    );
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								
							 | 
						
					
						
							
								
									
										
										
										
											2019-06-11 18:27:47 -07:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								    // move banks into the next segment
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								    let bank = Arc::new(Bank::new_from_parent(
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								        &bank,
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								        &Pubkey::default(),
							 | 
						
					
						
							
								
									
										
										
										
											2019-07-09 16:48:40 -07:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								        DEFAULT_SLOTS_PER_SEGMENT + bank.slot(),
							 | 
						
					
						
							
								
									
										
										
										
											2019-06-11 18:27:47 -07:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								    ));
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								    let bank_client = BankClient::new_shared(&bank);
							 | 
						
					
						
							
								
									
										
										
										
											2019-06-06 17:40:01 -07:00
										 
									 
								 
							 | 
							
								
							 | 
							
								
							 | 
							
							
								
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								    assert_matches!(
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								        bank_client.send_message(&[&mint_keypair, &validator_storage_keypair], message),
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								        Ok(_)
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								    );
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								    assert_eq!(bank_client.get_balance(&validator_storage_id).unwrap(), 10);
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								
							 | 
						
					
						
							
								
									
										
										
										
											2019-06-26 10:40:03 -07:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								    let bank = Arc::new(Bank::new_from_parent(
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								        &bank,
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								        &Pubkey::default(),
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								        bank.slot() + bank.epoch_schedule().slots_per_epoch,
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								    ));
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								    let bank_client = BankClient::new_shared(&bank);
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								    let rewards = bank
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								        .get_account(&rewards::id())
							 | 
						
					
						
							
								
									
										
										
										
											2019-09-10 18:53:02 -07:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								        .map(|account| Rewards::from_account(&account).unwrap())
							 | 
						
					
						
							
								
									
										
										
										
											2019-06-26 10:40:03 -07:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								        .unwrap();
							 | 
						
					
						
							
								
									
										
										
										
											2019-06-06 17:40:01 -07:00
										 
									 
								 
							 | 
							
								
							 | 
							
								
							 | 
							
							
								    let message = Message::new_with_payer(
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								        vec![storage_instruction::claim_reward(
							 | 
						
					
						
							
								
									
										
										
										
											2019-06-13 17:53:54 -07:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								            &owner_pubkey,
							 | 
						
					
						
							
								
									
										
										
										
											2019-06-06 17:40:01 -07:00
										 
									 
								 
							 | 
							
								
							 | 
							
								
							 | 
							
							
								            &validator_storage_id,
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								        )],
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								        Some(&mint_pubkey),
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								    );
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								    assert_matches!(bank_client.send_message(&[&mint_keypair], message), Ok(_));
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								    assert_eq!(
							 | 
						
					
						
							
								
									
										
										
										
											2019-06-13 17:53:54 -07:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								        bank_client.get_balance(&owner_pubkey).unwrap(),
							 | 
						
					
						
							
								
									
										
										
										
											2019-06-26 10:40:03 -07:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								        1 + ((rewards.storage_point_value * 10_f64) as u64)
							 | 
						
					
						
							
								
									
										
										
										
											2019-06-06 17:40:01 -07:00
										 
									 
								 
							 | 
							
								
							 | 
							
								
							 | 
							
							
								    );
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								    // tick the bank into the next storage epoch so that rewards can be claimed
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								    for _ in 0..=TICKS_IN_SEGMENT {
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								        bank.register_tick(&bank.last_blockhash());
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								    }
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								
							 | 
						
					
						
							
								
									
										
										
										
											2019-10-21 11:29:37 -06:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								    assert_eq!(bank_client.get_balance(&archiver_1_storage_id).unwrap(), 10);
							 | 
						
					
						
							
								
									
										
										
										
											2019-06-06 17:40:01 -07:00
										 
									 
								 
							 | 
							
								
							 | 
							
								
							 | 
							
							
								
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								    let message = Message::new_with_payer(
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								        vec![storage_instruction::claim_reward(
							 | 
						
					
						
							
								
									
										
										
										
											2019-06-13 17:53:54 -07:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								            &owner_pubkey,
							 | 
						
					
						
							
								
									
										
										
										
											2019-10-21 11:29:37 -06:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								            &archiver_1_storage_id,
							 | 
						
					
						
							
								
									
										
										
										
											2019-06-06 17:40:01 -07:00
										 
									 
								 
							 | 
							
								
							 | 
							
								
							 | 
							
							
								        )],
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								        Some(&mint_pubkey),
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								    );
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								    assert_matches!(bank_client.send_message(&[&mint_keypair], message), Ok(_));
							 | 
						
					
						
							
								
									
										
										
										
											2019-06-13 17:53:54 -07:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								    assert_eq!(
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								        bank_client.get_balance(&owner_pubkey).unwrap(),
							 | 
						
					
						
							
								
									
										
										
										
											2019-06-26 10:40:03 -07:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								        1 + ((rewards.storage_point_value * 10_f64) as u64)
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								            + (rewards.storage_point_value * 5_f64) as u64
							 | 
						
					
						
							
								
									
										
										
										
											2019-06-13 17:53:54 -07:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								    );
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								
							 | 
						
					
						
							
								
									
										
										
										
											2019-06-06 17:40:01 -07:00
										 
									 
								 
							 | 
							
								
							 | 
							
								
							 | 
							
							
								    let message = Message::new_with_payer(
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								        vec![storage_instruction::claim_reward(
							 | 
						
					
						
							
								
									
										
										
										
											2019-06-13 17:53:54 -07:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								            &owner_pubkey,
							 | 
						
					
						
							
								
									
										
										
										
											2019-10-21 11:29:37 -06:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								            &archiver_2_storage_id,
							 | 
						
					
						
							
								
									
										
										
										
											2019-06-06 17:40:01 -07:00
										 
									 
								 
							 | 
							
								
							 | 
							
								
							 | 
							
							
								        )],
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								        Some(&mint_pubkey),
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								    );
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								    assert_matches!(bank_client.send_message(&[&mint_keypair], message), Ok(_));
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								    assert_eq!(
							 | 
						
					
						
							
								
									
										
										
										
											2019-06-13 17:53:54 -07:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								        bank_client.get_balance(&owner_pubkey).unwrap(),
							 | 
						
					
						
							
								
									
										
										
										
											2019-06-26 10:40:03 -07:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								        1 + (rewards.storage_point_value * 10_f64) as u64
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								            + (rewards.storage_point_value * 5_f64) as u64
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								            + (rewards.storage_point_value * 5_f64) as u64
							 | 
						
					
						
							
								
									
										
										
										
											2019-06-06 17:40:01 -07:00
										 
									 
								 
							 | 
							
								
							 | 
							
								
							 | 
							
							
								    );
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								}
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								fn init_storage_accounts(
							 | 
						
					
						
							
								
									
										
										
										
											2019-06-13 17:53:54 -07:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								    owner: &Pubkey,
							 | 
						
					
						
							
								
									
										
										
										
											2019-06-06 17:40:01 -07:00
										 
									 
								 
							 | 
							
								
							 | 
							
								
							 | 
							
							
								    client: &BankClient,
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								    mint: &Keypair,
							 | 
						
					
						
							
								
									
										
										
										
											2019-11-08 15:57:35 +05:30
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								    validator_accounts_to_create: &[&Keypair],
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								    archiver_accounts_to_create: &[&Keypair],
							 | 
						
					
						
							
								
									
										
										
										
											2019-06-06 17:40:01 -07:00
										 
									 
								 
							 | 
							
								
							 | 
							
								
							 | 
							
							
								    lamports: u64,
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								) {
							 | 
						
					
						
							
								
									
										
										
										
											2019-11-08 15:57:35 +05:30
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								    let mut signers = vec![mint];
							 | 
						
					
						
							
								
									
										
										
										
											2019-10-23 22:01:22 -07:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								    let mut ixs: Vec<_> = vec![system_instruction::transfer(&mint.pubkey(), owner, 1)];
							 | 
						
					
						
							
								
									
										
										
										
											2019-06-13 17:53:54 -07:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								    ixs.append(
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								        &mut validator_accounts_to_create
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								            .into_iter()
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								            .flat_map(|account| {
							 | 
						
					
						
							
								
									
										
										
										
											2019-11-08 15:57:35 +05:30
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								                signers.push(&account);
							 | 
						
					
						
							
								
									
										
										
										
											2019-10-04 15:18:19 -06:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								                storage_instruction::create_storage_account(
							 | 
						
					
						
							
								
									
										
										
										
											2019-06-13 17:53:54 -07:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								                    &mint.pubkey(),
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								                    owner,
							 | 
						
					
						
							
								
									
										
										
										
											2019-11-08 15:57:35 +05:30
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								                    &account.pubkey(),
							 | 
						
					
						
							
								
									
										
										
										
											2019-06-13 17:53:54 -07:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								                    lamports,
							 | 
						
					
						
							
								
									
										
										
										
											2019-10-04 15:18:19 -06:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								                    StorageAccountType::Validator,
							 | 
						
					
						
							
								
									
										
										
										
											2019-06-13 17:53:54 -07:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								                )
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								            })
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								            .collect(),
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								    );
							 | 
						
					
						
							
								
									
										
										
										
											2019-10-21 11:29:37 -06:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								    archiver_accounts_to_create.into_iter().for_each(|account| {
							 | 
						
					
						
							
								
									
										
										
										
											2019-11-08 15:57:35 +05:30
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								        signers.push(&account);
							 | 
						
					
						
							
								
									
										
										
										
											2019-10-21 11:29:37 -06:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								        ixs.append(&mut storage_instruction::create_storage_account(
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								            &mint.pubkey(),
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								            owner,
							 | 
						
					
						
							
								
									
										
										
										
											2019-11-08 15:57:35 +05:30
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								            &account.pubkey(),
							 | 
						
					
						
							
								
									
										
										
										
											2019-10-21 11:29:37 -06:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								            lamports,
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								            StorageAccountType::Archiver,
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								        ))
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								    });
							 | 
						
					
						
							
								
									
										
										
										
											2019-06-06 17:40:01 -07:00
										 
									 
								 
							 | 
							
								
							 | 
							
								
							 | 
							
							
								    let message = Message::new(ixs);
							 | 
						
					
						
							
								
									
										
										
										
											2019-11-08 15:57:35 +05:30
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								    client.send_message(&signers, message).unwrap();
							 | 
						
					
						
							
								
									
										
										
										
											2019-06-06 17:40:01 -07:00
										 
									 
								 
							 | 
							
								
							 | 
							
								
							 | 
							
							
								}
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								
							 | 
						
					
						
							
								
									
										
										
										
											2019-07-09 16:48:40 -07:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								fn get_storage_segment<C: SyncClient>(client: &C, account: &Pubkey) -> u64 {
							 | 
						
					
						
							
								
									
										
										
										
											2019-06-06 17:40:01 -07:00
										 
									 
								 
							 | 
							
								
							 | 
							
								
							 | 
							
							
								    match client.get_account_data(&account).unwrap() {
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								        Some(storage_system_account_data) => {
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								            let contract = deserialize(&storage_system_account_data);
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								            if let Ok(contract) = contract {
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								                match contract {
							 | 
						
					
						
							
								
									
										
										
										
											2019-07-09 16:48:40 -07:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								                    StorageContract::ValidatorStorage { segment, .. } => {
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								                        return segment;
							 | 
						
					
						
							
								
									
										
										
										
											2019-06-06 17:40:01 -07:00
										 
									 
								 
							 | 
							
								
							 | 
							
								
							 | 
							
							
								                    }
							 | 
						
					
						
							
								
									
										
										
										
											2019-07-09 16:48:40 -07:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								                    _ => info!("error in reading segment"),
							 | 
						
					
						
							
								
									
										
										
										
											2019-06-06 17:40:01 -07:00
										 
									 
								 
							 | 
							
								
							 | 
							
								
							 | 
							
							
								                }
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								            }
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								        }
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								        None => {
							 | 
						
					
						
							
								
									
										
										
										
											2019-07-09 16:48:40 -07:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								            info!("error in reading segment");
							 | 
						
					
						
							
								
									
										
										
										
											2019-06-06 17:40:01 -07:00
										 
									 
								 
							 | 
							
								
							 | 
							
								
							 | 
							
							
								        }
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								    }
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								    0
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								}
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								fn submit_proof(
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								    mint_keypair: &Keypair,
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								    storage_keypair: &Keypair,
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								    bank_client: &BankClient,
							 | 
						
					
						
							
								
									
										
										
										
											2019-06-11 18:27:47 -07:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								    segment_index: u64,
							 | 
						
					
						
							
								
									
										
										
										
											2019-06-13 17:53:54 -07:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								) -> ProofStatus {
							 | 
						
					
						
							
								
									
										
										
										
											2019-06-06 17:40:01 -07:00
										 
									 
								 
							 | 
							
								
							 | 
							
								
							 | 
							
							
								    let sha_state = Hash::new(Pubkey::new_rand().as_ref());
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								    let message = Message::new_with_payer(
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								        vec![storage_instruction::mining_proof(
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								            &storage_keypair.pubkey(),
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								            sha_state,
							 | 
						
					
						
							
								
									
										
										
										
											2019-07-09 16:48:40 -07:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								            segment_index,
							 | 
						
					
						
							
								
									
										
										
										
											2019-06-06 17:40:01 -07:00
										 
									 
								 
							 | 
							
								
							 | 
							
								
							 | 
							
							
								            Signature::default(),
							 | 
						
					
						
							
								
									
										
										
										
											2019-06-13 17:53:54 -07:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								            bank_client.get_recent_blockhash().unwrap().0,
							 | 
						
					
						
							
								
									
										
										
										
											2019-06-06 17:40:01 -07:00
										 
									 
								 
							 | 
							
								
							 | 
							
								
							 | 
							
							
								        )],
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								        Some(&mint_keypair.pubkey()),
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								    );
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								    assert_matches!(
							 | 
						
					
						
							
								
									
										
										
										
											2020-02-20 13:13:23 -07:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								        bank_client.send_message(&[mint_keypair, storage_keypair], message),
							 | 
						
					
						
							
								
									
										
										
										
											2019-06-06 17:40:01 -07:00
										 
									 
								 
							 | 
							
								
							 | 
							
								
							 | 
							
							
								        Ok(_)
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								    );
							 | 
						
					
						
							
								
									
										
										
										
											2019-06-13 17:53:54 -07:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								    ProofStatus::Valid
							 | 
						
					
						
							
								
									
										
										
										
											2019-06-06 17:40:01 -07:00
										 
									 
								 
							 | 
							
								
							 | 
							
								
							 | 
							
							
								}
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								fn get_storage_blockhash<C: SyncClient>(client: &C, account: &Pubkey) -> Hash {
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								    if let Some(storage_system_account_data) = client.get_account_data(&account).unwrap() {
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								        let contract = deserialize(&storage_system_account_data);
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								        if let Ok(contract) = contract {
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								            match contract {
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								                StorageContract::ValidatorStorage { hash, .. } => {
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								                    return hash;
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								                }
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								                _ => (),
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								            }
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								        }
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								    }
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								    Hash::default()
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								}
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								#[test]
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								fn test_bank_storage() {
							 | 
						
					
						
							
								
									
										
										
										
											2019-11-08 23:56:57 -05:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								    let GenesisConfigInfo {
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								        mut genesis_config,
							 | 
						
					
						
							
								
									
										
										
										
											2019-06-22 17:18:35 -07:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								        mint_keypair,
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								        ..
							 | 
						
					
						
							
								
									
										
										
										
											2019-11-08 23:56:57 -05:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								    } = create_genesis_config(1000);
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								    genesis_config
							 | 
						
					
						
							
								
									
										
										
										
											2019-06-11 18:27:47 -07:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								        .native_instruction_processors
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								        .push(solana_storage_program::solana_storage_program!());
							 | 
						
					
						
							
								
									
										
										
										
											2019-06-06 17:40:01 -07:00
										 
									 
								 
							 | 
							
								
							 | 
							
								
							 | 
							
							
								    let mint_pubkey = mint_keypair.pubkey();
							 | 
						
					
						
							
								
									
										
										
										
											2019-10-21 11:29:37 -06:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								    let archiver_keypair = Keypair::new();
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								    let archiver_pubkey = archiver_keypair.pubkey();
							 | 
						
					
						
							
								
									
										
										
										
											2019-06-06 17:40:01 -07:00
										 
									 
								 
							 | 
							
								
							 | 
							
								
							 | 
							
							
								    let validator_keypair = Keypair::new();
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								    let validator_pubkey = validator_keypair.pubkey();
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								
							 | 
						
					
						
							
								
									
										
										
										
											2019-11-08 23:56:57 -05:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								    let bank = Bank::new(&genesis_config);
							 | 
						
					
						
							
								
									
										
										
										
											2019-06-06 17:40:01 -07:00
										 
									 
								 
							 | 
							
								
							 | 
							
								
							 | 
							
							
								    // tick the bank up until it's moved into storage segment 2
							 | 
						
					
						
							
								
									
										
										
										
											2019-06-11 18:27:47 -07:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								    // create a new bank in storage segment 2
							 | 
						
					
						
							
								
									
										
										
										
											2019-07-09 16:48:40 -07:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								    let bank = Bank::new_from_parent(
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								        &Arc::new(bank),
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								        &Pubkey::new_rand(),
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								        DEFAULT_SLOTS_PER_SEGMENT * 2,
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								    );
							 | 
						
					
						
							
								
									
										
										
										
											2019-06-06 17:40:01 -07:00
										 
									 
								 
							 | 
							
								
							 | 
							
								
							 | 
							
							
								    let bank_client = BankClient::new(bank);
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								    let x = 42;
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								    let x2 = x * 2;
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								    let storage_blockhash = hash(&[x2]);
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								
							 | 
						
					
						
							
								
									
										
										
										
											2019-10-04 15:18:19 -06:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								    let message = Message::new(storage_instruction::create_storage_account(
							 | 
						
					
						
							
								
									
										
										
										
											2019-06-06 17:40:01 -07:00
										 
									 
								 
							 | 
							
								
							 | 
							
								
							 | 
							
							
								        &mint_pubkey,
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								        &Pubkey::default(),
							 | 
						
					
						
							
								
									
										
										
										
											2019-10-21 11:29:37 -06:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								        &archiver_pubkey,
							 | 
						
					
						
							
								
									
										
										
										
											2019-10-19 18:23:27 -07:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								        11,
							 | 
						
					
						
							
								
									
										
										
										
											2019-10-21 11:29:37 -06:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								        StorageAccountType::Archiver,
							 | 
						
					
						
							
								
									
										
										
										
											2019-06-06 17:40:01 -07:00
										 
									 
								 
							 | 
							
								
							 | 
							
								
							 | 
							
							
								    ));
							 | 
						
					
						
							
								
									
										
										
										
											2019-11-08 15:57:35 +05:30
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								    bank_client
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								        .send_message(&[&mint_keypair, &archiver_keypair], message)
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								        .unwrap();
							 | 
						
					
						
							
								
									
										
										
										
											2019-06-06 17:40:01 -07:00
										 
									 
								 
							 | 
							
								
							 | 
							
								
							 | 
							
							
								
							 | 
						
					
						
							
								
									
										
										
										
											2019-10-04 15:18:19 -06:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								    let message = Message::new(storage_instruction::create_storage_account(
							 | 
						
					
						
							
								
									
										
										
										
											2019-06-06 17:40:01 -07:00
										 
									 
								 
							 | 
							
								
							 | 
							
								
							 | 
							
							
								        &mint_pubkey,
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								        &Pubkey::default(),
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								        &validator_pubkey,
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								        1,
							 | 
						
					
						
							
								
									
										
										
										
											2019-10-04 15:18:19 -06:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								        StorageAccountType::Validator,
							 | 
						
					
						
							
								
									
										
										
										
											2019-06-06 17:40:01 -07:00
										 
									 
								 
							 | 
							
								
							 | 
							
								
							 | 
							
							
								    ));
							 | 
						
					
						
							
								
									
										
										
										
											2019-11-08 15:57:35 +05:30
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								    bank_client
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								        .send_message(&[&mint_keypair, &validator_keypair], message)
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								        .unwrap();
							 | 
						
					
						
							
								
									
										
										
										
											2019-06-06 17:40:01 -07:00
										 
									 
								 
							 | 
							
								
							 | 
							
								
							 | 
							
							
								
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								    let message = Message::new_with_payer(
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								        vec![storage_instruction::advertise_recent_blockhash(
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								            &validator_pubkey,
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								            storage_blockhash,
							 | 
						
					
						
							
								
									
										
										
										
											2019-07-09 16:48:40 -07:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								            1,
							 | 
						
					
						
							
								
									
										
										
										
											2019-06-06 17:40:01 -07:00
										 
									 
								 
							 | 
							
								
							 | 
							
								
							 | 
							
							
								        )],
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								        Some(&mint_pubkey),
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								    );
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								    assert_matches!(
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								        bank_client.send_message(&[&mint_keypair, &validator_keypair], message),
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								        Ok(_)
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								    );
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								    let slot = 0;
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								    let message = Message::new_with_payer(
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								        vec![storage_instruction::mining_proof(
							 | 
						
					
						
							
								
									
										
										
										
											2019-10-21 11:29:37 -06:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								            &archiver_pubkey,
							 | 
						
					
						
							
								
									
										
										
										
											2019-06-06 17:40:01 -07:00
										 
									 
								 
							 | 
							
								
							 | 
							
								
							 | 
							
							
								            Hash::default(),
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								            slot,
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								            Signature::default(),
							 | 
						
					
						
							
								
									
										
										
										
											2019-06-13 17:53:54 -07:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								            bank_client.get_recent_blockhash().unwrap().0,
							 | 
						
					
						
							
								
									
										
										
										
											2019-06-06 17:40:01 -07:00
										 
									 
								 
							 | 
							
								
							 | 
							
								
							 | 
							
							
								        )],
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								        Some(&mint_pubkey),
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								    );
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								    assert_matches!(
							 | 
						
					
						
							
								
									
										
										
										
											2019-10-21 11:29:37 -06:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								        bank_client.send_message(&[&mint_keypair, &archiver_keypair], message),
							 | 
						
					
						
							
								
									
										
										
										
											2019-06-06 17:40:01 -07:00
										 
									 
								 
							 | 
							
								
							 | 
							
								
							 | 
							
							
								        Ok(_)
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								    );
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								
							 | 
						
					
						
							
								
									
										
										
										
											2019-07-09 16:48:40 -07:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								    assert_eq!(get_storage_segment(&bank_client, &validator_pubkey), 1);
							 | 
						
					
						
							
								
									
										
										
										
											2019-06-06 17:40:01 -07:00
										 
									 
								 
							 | 
							
								
							 | 
							
								
							 | 
							
							
								    assert_eq!(
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								        get_storage_blockhash(&bank_client, &validator_pubkey),
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								        storage_blockhash
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								    );
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								}
							 |