Add separate Struct for Replicator submissions
This commit is contained in:
parent
00cb52c444
commit
b441bac7b2
|
@ -17,17 +17,16 @@ impl Default for ProofStatus {
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Default, Debug, Serialize, Deserialize, Clone)]
|
#[derive(Default, Debug, Serialize, Deserialize, Clone)]
|
||||||
pub struct ProofInfo {
|
pub struct Proof {
|
||||||
pub id: Pubkey,
|
pub id: Pubkey,
|
||||||
pub signature: Signature,
|
pub signature: Signature,
|
||||||
pub sha_state: Hash,
|
pub sha_state: Hash,
|
||||||
pub status: ProofStatus,
|
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Default, Debug, Serialize, Deserialize, Clone)]
|
#[derive(Default, Debug, Serialize, Deserialize, Clone)]
|
||||||
pub struct ValidationInfo {
|
pub struct CheckedProof {
|
||||||
pub id: Pubkey,
|
pub proof: Proof,
|
||||||
pub proof_mask: Vec<ProofStatus>,
|
pub status: ProofStatus,
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Debug, Serialize, Deserialize)]
|
#[derive(Debug, Serialize, Deserialize)]
|
||||||
|
@ -38,11 +37,11 @@ pub enum StorageContract {
|
||||||
ValidatorStorage {
|
ValidatorStorage {
|
||||||
entry_height: u64,
|
entry_height: u64,
|
||||||
hash: Hash,
|
hash: Hash,
|
||||||
lockout_validations: Vec<Vec<ProofInfo>>,
|
lockout_validations: Vec<Vec<CheckedProof>>,
|
||||||
reward_validations: Vec<Vec<ProofInfo>>,
|
reward_validations: Vec<Vec<CheckedProof>>,
|
||||||
},
|
},
|
||||||
ReplicatorStorage {
|
ReplicatorStorage {
|
||||||
proofs: Vec<ProofInfo>,
|
proofs: Vec<Proof>,
|
||||||
reward_validations: Vec<Vec<ProofInfo>>,
|
reward_validations: Vec<Vec<CheckedProof>>,
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,5 +1,5 @@
|
||||||
use crate::id;
|
use crate::id;
|
||||||
use crate::storage_contract::ProofInfo;
|
use crate::storage_contract::CheckedProof;
|
||||||
use serde_derive::{Deserialize, Serialize};
|
use serde_derive::{Deserialize, Serialize};
|
||||||
use solana_sdk::hash::Hash;
|
use solana_sdk::hash::Hash;
|
||||||
use solana_sdk::instruction::{AccountMeta, Instruction};
|
use solana_sdk::instruction::{AccountMeta, Instruction};
|
||||||
|
@ -23,7 +23,7 @@ pub enum StorageInstruction {
|
||||||
},
|
},
|
||||||
ProofValidation {
|
ProofValidation {
|
||||||
entry_height: u64,
|
entry_height: u64,
|
||||||
proofs: Vec<ProofInfo>,
|
proofs: Vec<CheckedProof>,
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -58,12 +58,12 @@ pub fn advertise_recent_blockhash(
|
||||||
pub fn proof_validation(
|
pub fn proof_validation(
|
||||||
from_pubkey: &Pubkey,
|
from_pubkey: &Pubkey,
|
||||||
entry_height: u64,
|
entry_height: u64,
|
||||||
proofs: Vec<ProofInfo>,
|
proofs: Vec<CheckedProof>,
|
||||||
) -> Instruction {
|
) -> Instruction {
|
||||||
let mut account_metas = vec![AccountMeta::new(*from_pubkey, true)];
|
let mut account_metas = vec![AccountMeta::new(*from_pubkey, true)];
|
||||||
proofs
|
proofs.iter().for_each(|checked_proof| {
|
||||||
.iter()
|
account_metas.push(AccountMeta::new(checked_proof.proof.id, false))
|
||||||
.for_each(|proof| account_metas.push(AccountMeta::new(proof.id, false)));
|
});
|
||||||
let storage_instruction = StorageInstruction::ProofValidation {
|
let storage_instruction = StorageInstruction::ProofValidation {
|
||||||
entry_height,
|
entry_height,
|
||||||
proofs,
|
proofs,
|
||||||
|
|
|
@ -2,7 +2,7 @@
|
||||||
//! Receive mining proofs from miners, validate the answers
|
//! Receive mining proofs from miners, validate the answers
|
||||||
//! and give reward for good proofs.
|
//! and give reward for good proofs.
|
||||||
|
|
||||||
use crate::storage_contract::{ProofInfo, ProofStatus, StorageContract};
|
use crate::storage_contract::{CheckedProof, Proof, ProofStatus, StorageContract};
|
||||||
use crate::storage_instruction::StorageInstruction;
|
use crate::storage_instruction::StorageInstruction;
|
||||||
use crate::{get_segment_from_entry, ENTRIES_PER_SEGMENT};
|
use crate::{get_segment_from_entry, ENTRIES_PER_SEGMENT};
|
||||||
use log::*;
|
use log::*;
|
||||||
|
@ -17,7 +17,7 @@ use std::cmp;
|
||||||
pub const TOTAL_VALIDATOR_REWARDS: u64 = 1;
|
pub const TOTAL_VALIDATOR_REWARDS: u64 = 1;
|
||||||
pub const TOTAL_REPLICATOR_REWARDS: u64 = 1;
|
pub const TOTAL_REPLICATOR_REWARDS: u64 = 1;
|
||||||
|
|
||||||
fn count_valid_proofs(proofs: &[ProofInfo]) -> u64 {
|
fn count_valid_proofs(proofs: &[CheckedProof]) -> u64 {
|
||||||
let mut num = 0;
|
let mut num = 0;
|
||||||
for proof in proofs {
|
for proof in proofs {
|
||||||
if let ProofStatus::Valid = proof.status {
|
if let ProofStatus::Valid = proof.status {
|
||||||
|
@ -92,9 +92,11 @@ fn store_validation_result(
|
||||||
if segment_index > reward_validations.len() || reward_validations.is_empty() {
|
if segment_index > reward_validations.len() || reward_validations.is_empty() {
|
||||||
reward_validations.resize(cmp::max(1, segment_index), vec![]);
|
reward_validations.resize(cmp::max(1, segment_index), vec![]);
|
||||||
}
|
}
|
||||||
let mut result = proofs[segment_index].clone();
|
let result = proofs[segment_index].clone();
|
||||||
result.status = status;
|
reward_validations[segment_index].push(CheckedProof {
|
||||||
reward_validations[segment_index].push(result);
|
proof: result,
|
||||||
|
status,
|
||||||
|
});
|
||||||
}
|
}
|
||||||
_ => return Err(InstructionError::InvalidAccountData),
|
_ => return Err(InstructionError::InvalidAccountData),
|
||||||
}
|
}
|
||||||
|
@ -134,7 +136,7 @@ pub fn process_instruction(
|
||||||
|
|
||||||
let segment_index = get_segment_from_entry(entry_height);
|
let segment_index = get_segment_from_entry(entry_height);
|
||||||
if segment_index > proofs.len() || proofs.is_empty() {
|
if segment_index > proofs.len() || proofs.is_empty() {
|
||||||
proofs.resize(cmp::max(1, segment_index), ProofInfo::default());
|
proofs.resize(cmp::max(1, segment_index), Proof::default());
|
||||||
}
|
}
|
||||||
|
|
||||||
if segment_index > proofs.len() {
|
if segment_index > proofs.len() {
|
||||||
|
@ -147,12 +149,10 @@ pub fn process_instruction(
|
||||||
sha_state, entry_height
|
sha_state, entry_height
|
||||||
);
|
);
|
||||||
|
|
||||||
let proof_info = ProofInfo {
|
let proof_info = Proof {
|
||||||
id: *keyed_accounts[0].signer_key().unwrap(),
|
id: *keyed_accounts[0].signer_key().unwrap(),
|
||||||
sha_state,
|
sha_state,
|
||||||
signature,
|
signature,
|
||||||
// don't care
|
|
||||||
status: ProofStatus::Skipped,
|
|
||||||
};
|
};
|
||||||
proofs[segment_index] = proof_info;
|
proofs[segment_index] = proof_info;
|
||||||
} else {
|
} else {
|
||||||
|
@ -281,7 +281,7 @@ pub fn process_instruction(
|
||||||
.into_iter()
|
.into_iter()
|
||||||
.enumerate()
|
.enumerate()
|
||||||
.filter_map(|(i, entry)| {
|
.filter_map(|(i, entry)| {
|
||||||
if previous_proofs[i].1.signature != entry.signature
|
if previous_proofs[i].1.signature != entry.proof.signature
|
||||||
|| entry.status != ProofStatus::Valid
|
|| entry.status != ProofStatus::Valid
|
||||||
{
|
{
|
||||||
let _ = store_validation_result(
|
let _ = store_validation_result(
|
||||||
|
@ -416,14 +416,6 @@ mod tests {
|
||||||
let mut accounts = [Account::default(), Account::default()];
|
let mut accounts = [Account::default(), Account::default()];
|
||||||
accounts[0].data.resize(16 * 1024, 0);
|
accounts[0].data.resize(16 * 1024, 0);
|
||||||
|
|
||||||
let ix = storage_instruction::advertise_recent_blockhash(
|
|
||||||
&pubkey,
|
|
||||||
Hash::default(),
|
|
||||||
ENTRIES_PER_SEGMENT,
|
|
||||||
);
|
|
||||||
|
|
||||||
test_instruction(&ix, &mut accounts).unwrap();
|
|
||||||
|
|
||||||
let ix =
|
let ix =
|
||||||
storage_instruction::mining_proof(&pubkey, Hash::default(), 0, Signature::default());
|
storage_instruction::mining_proof(&pubkey, Hash::default(), 0, Signature::default());
|
||||||
|
|
||||||
|
@ -481,10 +473,10 @@ mod tests {
|
||||||
let entry_height = 0;
|
let entry_height = 0;
|
||||||
let bank_client = BankClient::new(&bank);
|
let bank_client = BankClient::new(&bank);
|
||||||
|
|
||||||
let ix = SystemInstruction::new_account(&mint_pubkey, &validator, 10, 4 * 1042, &id());
|
let ix = system_instruction::create_account(&mint_pubkey, &validator, 10, 4 * 1042, &id());
|
||||||
bank_client.process_instruction(&mint_keypair, ix).unwrap();
|
bank_client.process_instruction(&mint_keypair, ix).unwrap();
|
||||||
|
|
||||||
let ix = SystemInstruction::new_account(&mint_pubkey, &replicator, 10, 4 * 1042, &id());
|
let ix = system_instruction::create_account(&mint_pubkey, &replicator, 10, 4 * 1042, &id());
|
||||||
bank_client.process_instruction(&mint_keypair, ix).unwrap();
|
bank_client.process_instruction(&mint_keypair, ix).unwrap();
|
||||||
|
|
||||||
let ix = storage_instruction::advertise_recent_blockhash(
|
let ix = storage_instruction::advertise_recent_blockhash(
|
||||||
|
@ -519,10 +511,12 @@ mod tests {
|
||||||
let ix = storage_instruction::proof_validation(
|
let ix = storage_instruction::proof_validation(
|
||||||
&validator,
|
&validator,
|
||||||
entry_height,
|
entry_height,
|
||||||
vec![ProofInfo {
|
vec![CheckedProof {
|
||||||
id: replicator,
|
proof: Proof {
|
||||||
signature: Signature::default(),
|
id: replicator,
|
||||||
sha_state: Hash::default(),
|
signature: Signature::default(),
|
||||||
|
sha_state: Hash::default(),
|
||||||
|
},
|
||||||
status: ProofStatus::Valid,
|
status: ProofStatus::Valid,
|
||||||
}],
|
}],
|
||||||
);
|
);
|
||||||
|
@ -552,7 +546,7 @@ mod tests {
|
||||||
bank.register_tick(&bank.last_blockhash());
|
bank.register_tick(&bank.last_blockhash());
|
||||||
}
|
}
|
||||||
|
|
||||||
let ix = StorageInstruction::new_reward_claim(&replicator, entry_height);
|
let ix = storage_instruction::reward_claim(&replicator, entry_height);
|
||||||
bank_client
|
bank_client
|
||||||
.process_instruction(&replicator_keypair, ix)
|
.process_instruction(&replicator_keypair, ix)
|
||||||
.unwrap();
|
.unwrap();
|
||||||
|
@ -630,13 +624,8 @@ mod tests {
|
||||||
|
|
||||||
bank_client.process_instruction(&mint_keypair, ix).unwrap();
|
bank_client.process_instruction(&mint_keypair, ix).unwrap();
|
||||||
|
|
||||||
let ix = system_instruction::create_account(
|
let ix =
|
||||||
&mint_pubkey,
|
system_instruction::create_account(&mint_pubkey, &validator_pubkey, 1, 4 * 1024, &id());
|
||||||
&validator_pubkey,
|
|
||||||
1,
|
|
||||||
4 * 1024,
|
|
||||||
&id(),
|
|
||||||
);
|
|
||||||
|
|
||||||
bank_client.process_instruction(&mint_keypair, ix).unwrap();
|
bank_client.process_instruction(&mint_keypair, ix).unwrap();
|
||||||
|
|
||||||
|
@ -651,7 +640,7 @@ mod tests {
|
||||||
.unwrap();
|
.unwrap();
|
||||||
|
|
||||||
let entry_height = 0;
|
let entry_height = 0;
|
||||||
let ix = storage_instruction::mining_proof()
|
let ix = storage_instruction::mining_proof(
|
||||||
&replicator_pubkey,
|
&replicator_pubkey,
|
||||||
Hash::default(),
|
Hash::default(),
|
||||||
entry_height,
|
entry_height,
|
||||||
|
|
Loading…
Reference in New Issue