Rename replicator to archiver (#6464)

* Rename replicator to archiver

* cargo fmt

* Fix grammar
This commit is contained in:
Greg Fitzgerald
2019-10-21 11:29:37 -06:00
committed by GitHub
parent 6c79f56c2c
commit 9232057e95
61 changed files with 529 additions and 560 deletions

View File

@ -62,7 +62,7 @@ impl Default for ProofStatus {
#[derive(Default, Debug, Serialize, Deserialize, Clone, PartialEq)]
pub struct Proof {
/// The encryption key the replicator used (also used to generate offsets)
/// The encryption key the archiver used (also used to generate offsets)
pub signature: Signature,
/// A "recent" blockhash used to generate the seed
pub blockhash: Hash,
@ -82,14 +82,14 @@ pub enum StorageContract {
segment: u64,
// Most recently advertised blockhash
hash: Hash,
// Lockouts and Rewards are per segment per replicator. It needs to remain this way until
// Lockouts and Rewards are per segment per archiver. It needs to remain this way until
// the challenge stage is added.
lockout_validations: BTreeMap<u64, BTreeMap<Pubkey, Vec<ProofStatus>>>,
// Used to keep track of ongoing credits
credits: Credits,
},
ReplicatorStorage {
ArchiverStorage {
owner: Pubkey,
// TODO what to do about duplicate proofs across segments? - Check the blockhashes
// Map of Proofs per segment, in a Vec
@ -139,7 +139,7 @@ impl<'a> StorageAccount<'a> {
let storage_contract = &mut self.account.state()?;
if let StorageContract::Uninitialized = storage_contract {
*storage_contract = match account_type {
StorageAccountType::Replicator => StorageContract::ReplicatorStorage {
StorageAccountType::Archiver => StorageContract::ArchiverStorage {
owner,
proofs: BTreeMap::new(),
validations: BTreeMap::new(),
@ -168,7 +168,7 @@ impl<'a> StorageAccount<'a> {
clock: sysvar::clock::Clock,
) -> Result<(), InstructionError> {
let mut storage_contract = &mut self.account.state()?;
if let StorageContract::ReplicatorStorage {
if let StorageContract::ArchiverStorage {
proofs,
validations,
credits,
@ -278,7 +278,7 @@ impl<'a> StorageAccount<'a> {
clock: sysvar::clock::Clock,
segment_index: u64,
proofs_per_account: Vec<Vec<ProofStatus>>,
replicator_accounts: &mut [StorageAccount],
archiver_accounts: &mut [StorageAccount],
) -> Result<(), InstructionError> {
let mut storage_contract = &mut self.account.state()?;
if let StorageContract::ValidatorStorage {
@ -293,12 +293,12 @@ impl<'a> StorageAccount<'a> {
));
}
let accounts = replicator_accounts
let accounts = archiver_accounts
.iter_mut()
.enumerate()
.filter_map(|(i, account)| {
account.account.state().ok().map(|contract| match contract {
StorageContract::ReplicatorStorage {
StorageContract::ArchiverStorage {
proofs: account_proofs,
..
} => {
@ -349,11 +349,11 @@ impl<'a> StorageAccount<'a> {
// allow validators to store successful validations
stored_proofs
.into_iter()
.for_each(|(replicator_account_id, proof_mask)| {
.for_each(|(archiver_account_id, proof_mask)| {
lockout_validations
.entry(segment_index)
.or_default()
.insert(replicator_account_id, proof_mask);
.insert(archiver_account_id, proof_mask);
});
self.account.set_state(storage_contract)
@ -387,7 +387,7 @@ impl<'a> StorageAccount<'a> {
check_redeemable(credits, rewards.storage_point_value, rewards_pool, owner)?;
self.account.set_state(storage_contract)
} else if let StorageContract::ReplicatorStorage {
} else if let StorageContract::ArchiverStorage {
owner: account_owner,
validations,
credits,
@ -438,7 +438,7 @@ pub fn create_rewards_pool() -> Account {
Account::new_data(std::u64::MAX, &StorageContract::RewardsPool, &crate::id()).unwrap()
}
/// Store the result of a proof validation into the replicator account
/// Store the result of a proof validation into the archiver account
fn store_validation_result(
me: &Pubkey,
clock: &sysvar::clock::Clock,
@ -448,7 +448,7 @@ fn store_validation_result(
) -> Result<(), InstructionError> {
let mut storage_contract = storage_account.account.state()?;
match &mut storage_contract {
StorageContract::ReplicatorStorage {
StorageContract::ArchiverStorage {
proofs,
validations,
credits,
@ -514,7 +514,7 @@ mod tests {
if let StorageContract::ValidatorStorage { .. } = contract {
assert!(true)
}
if let StorageContract::ReplicatorStorage { .. } = &mut contract {
if let StorageContract::ArchiverStorage { .. } = &mut contract {
panic!("Contract should not decode into two types");
}
@ -526,10 +526,10 @@ mod tests {
credits: Credits::default(),
};
storage_account.account.set_state(&contract).unwrap();
if let StorageContract::ReplicatorStorage { .. } = contract {
if let StorageContract::ArchiverStorage { .. } = contract {
panic!("Wrong contract type");
}
contract = StorageContract::ReplicatorStorage {
contract = StorageContract::ArchiverStorage {
owner: Pubkey::default(),
proofs: BTreeMap::new(),
validations: BTreeMap::new(),
@ -574,7 +574,7 @@ mod tests {
if let StorageContract::Uninitialized = storage_contract {
let mut proofs = BTreeMap::new();
proofs.insert(0, vec![proof.clone()]);
*storage_contract = StorageContract::ReplicatorStorage {
*storage_contract = StorageContract::ArchiverStorage {
owner: Pubkey::default(),
proofs,
validations: BTreeMap::new(),

View File

@ -10,13 +10,13 @@ use solana_sdk::sysvar::{clock, rewards};
#[derive(Debug, Serialize, Deserialize, PartialEq, Clone, Copy)]
pub enum StorageAccountType {
Replicator,
Archiver,
Validator,
}
#[derive(Serialize, Deserialize, Debug, Clone)]
pub enum StorageInstruction {
/// Initialize the account as a validator or replicator
/// Initialize the account as a validator or archiver
///
/// Expects 1 Account:
/// 0 - Account to be initialized
@ -40,14 +40,14 @@ pub enum StorageInstruction {
/// Expects 1 Account:
/// 0 - Storage account with credits to redeem
/// 1 - Clock Syscall to figure out the clock epoch
/// 2 - Replicator account to credit - this account *must* be the owner
/// 2 - Archiver account to credit - this account *must* be the owner
/// 3 - MiningPool account to redeem credits from
/// 4 - Rewards Syscall to figure out point values
ClaimStorageReward,
ProofValidation {
/// The segment during which this proof was generated
segment: u64,
/// A Vec of proof masks per keyed replicator account loaded by the instruction
/// A Vec of proof masks per keyed archiver account loaded by the instruction
proofs: Vec<Vec<ProofStatus>>,
},
}

View File

@ -54,7 +54,7 @@ fn test_instruction(
fn test_account_owner() {
let account_owner = Pubkey::new_rand();
let validator_storage_pubkey = Pubkey::new_rand();
let replicator_storage_pubkey = Pubkey::new_rand();
let archiver_storage_pubkey = Pubkey::new_rand();
let GenesisBlockInfo {
genesis_block,
@ -90,18 +90,18 @@ fn test_account_owner() {
let message = Message::new(storage_instruction::create_storage_account(
&mint_pubkey,
&account_owner,
&replicator_storage_pubkey,
&archiver_storage_pubkey,
1,
StorageAccountType::Replicator,
StorageAccountType::Archiver,
));
bank_client
.send_message(&[&mint_keypair], message)
.expect("failed to create account");
let account = bank
.get_account(&replicator_storage_pubkey)
.get_account(&archiver_storage_pubkey)
.expect("account not found");
let storage_contract = account.state().expect("couldn't unpack account data");
if let StorageContract::ReplicatorStorage { owner, .. } = storage_contract {
if let StorageContract::ArchiverStorage { owner, .. } = storage_contract {
assert_eq!(owner, account_owner);
} else {
assert!(false, "wrong account type found")
@ -119,7 +119,7 @@ fn test_proof_bounds() {
{
let mut storage_account = StorageAccount::new(pubkey, &mut account);
storage_account
.initialize_storage(account_owner, StorageAccountType::Replicator)
.initialize_storage(account_owner, StorageAccountType::Archiver)
.unwrap();
}
@ -232,7 +232,7 @@ fn test_submit_mining_ok() {
{
let mut storage_account = StorageAccount::new(pubkey, &mut account);
storage_account
.initialize_storage(account_owner, StorageAccountType::Replicator)
.initialize_storage(account_owner, StorageAccountType::Archiver)
.unwrap();
}
@ -270,14 +270,14 @@ fn test_validate_mining() {
.native_instruction_processors
.push(solana_storage_program::solana_storage_program!());
let mint_pubkey = mint_keypair.pubkey();
// 1 owner for all replicator and validator accounts for the test
// 1 owner for all archiver and validator accounts for the test
let owner_pubkey = Pubkey::new_rand();
let replicator_1_storage_keypair = Keypair::new();
let replicator_1_storage_id = replicator_1_storage_keypair.pubkey();
let archiver_1_storage_keypair = Keypair::new();
let archiver_1_storage_id = archiver_1_storage_keypair.pubkey();
let replicator_2_storage_keypair = Keypair::new();
let replicator_2_storage_id = replicator_2_storage_keypair.pubkey();
let archiver_2_storage_keypair = Keypair::new();
let archiver_2_storage_id = archiver_2_storage_keypair.pubkey();
let validator_storage_keypair = Keypair::new();
let validator_storage_id = validator_storage_keypair.pubkey();
@ -291,7 +291,7 @@ fn test_validate_mining() {
&bank_client,
&mint_keypair,
&[&validator_storage_id],
&[&replicator_1_storage_id, &replicator_2_storage_id],
&[&archiver_1_storage_id, &archiver_2_storage_id],
10,
);
@ -317,24 +317,24 @@ fn test_validate_mining() {
Ok(_)
);
// submit proofs 5 proofs for each replicator for segment 0
// submit proofs 5 proofs for each archiver for segment 0
let mut checked_proofs: HashMap<_, Vec<_>> = HashMap::new();
for _ in 0..5 {
checked_proofs
.entry(replicator_1_storage_id)
.entry(archiver_1_storage_id)
.or_default()
.push(submit_proof(
&mint_keypair,
&replicator_1_storage_keypair,
&archiver_1_storage_keypair,
&bank_client,
0,
));
checked_proofs
.entry(replicator_2_storage_id)
.entry(archiver_2_storage_id)
.or_default()
.push(submit_proof(
&mint_keypair,
&replicator_2_storage_keypair,
&archiver_2_storage_keypair,
&bank_client,
0,
));
@ -429,15 +429,12 @@ fn test_validate_mining() {
bank.register_tick(&bank.last_blockhash());
}
assert_eq!(
bank_client.get_balance(&replicator_1_storage_id).unwrap(),
10
);
assert_eq!(bank_client.get_balance(&archiver_1_storage_id).unwrap(), 10);
let message = Message::new_with_payer(
vec![storage_instruction::claim_reward(
&owner_pubkey,
&replicator_1_storage_id,
&archiver_1_storage_id,
)],
Some(&mint_pubkey),
);
@ -451,7 +448,7 @@ fn test_validate_mining() {
let message = Message::new_with_payer(
vec![storage_instruction::claim_reward(
&owner_pubkey,
&replicator_2_storage_id,
&archiver_2_storage_id,
)],
Some(&mint_pubkey),
);
@ -469,7 +466,7 @@ fn init_storage_accounts(
client: &BankClient,
mint: &Keypair,
validator_accounts_to_create: &[&Pubkey],
replicator_accounts_to_create: &[&Pubkey],
archiver_accounts_to_create: &[&Pubkey],
lamports: u64,
) {
let mut ixs: Vec<_> = vec![system_instruction::transfer_now(&mint.pubkey(), owner, 1)];
@ -487,17 +484,15 @@ fn init_storage_accounts(
})
.collect(),
);
replicator_accounts_to_create
.into_iter()
.for_each(|account| {
ixs.append(&mut storage_instruction::create_storage_account(
&mint.pubkey(),
owner,
account,
lamports,
StorageAccountType::Replicator,
))
});
archiver_accounts_to_create.into_iter().for_each(|account| {
ixs.append(&mut storage_instruction::create_storage_account(
&mint.pubkey(),
owner,
account,
lamports,
StorageAccountType::Archiver,
))
});
let message = Message::new(ixs);
client.send_message(&[mint], message).unwrap();
}
@ -573,8 +568,8 @@ fn test_bank_storage() {
.native_instruction_processors
.push(solana_storage_program::solana_storage_program!());
let mint_pubkey = mint_keypair.pubkey();
let replicator_keypair = Keypair::new();
let replicator_pubkey = replicator_keypair.pubkey();
let archiver_keypair = Keypair::new();
let archiver_pubkey = archiver_keypair.pubkey();
let validator_keypair = Keypair::new();
let validator_pubkey = validator_keypair.pubkey();
@ -595,9 +590,9 @@ fn test_bank_storage() {
let message = Message::new(storage_instruction::create_storage_account(
&mint_pubkey,
&Pubkey::default(),
&replicator_pubkey,
&archiver_pubkey,
11,
StorageAccountType::Replicator,
StorageAccountType::Archiver,
));
bank_client.send_message(&[&mint_keypair], message).unwrap();
@ -627,7 +622,7 @@ fn test_bank_storage() {
let slot = 0;
let message = Message::new_with_payer(
vec![storage_instruction::mining_proof(
&replicator_pubkey,
&archiver_pubkey,
Hash::default(),
slot,
Signature::default(),
@ -636,7 +631,7 @@ fn test_bank_storage() {
Some(&mint_pubkey),
);
assert_matches!(
bank_client.send_message(&[&mint_keypair, &replicator_keypair], message),
bank_client.send_message(&[&mint_keypair, &archiver_keypair], message),
Ok(_)
);