Add storage mining pool (#4364)

* Add storage mining pool

* Set gossip port

* Add create-storage-mining-pool-account wallet command

* Add claim-storage-reward wallet command

* Create storage account upfront

* Add storage program to genesis

* Use STORAGE_ACCOUNT_SPACE

* Fix tests

* Add wallet commands to create validator/replicator storage accounts

* Add create_validator_storage_account()

* Storage stage no longer implicitly creates a storage account
This commit is contained in:
Michael Vines
2019-05-23 14:50:23 -07:00
committed by GitHub
parent 6b35e16676
commit b37d2fde3d
18 changed files with 735 additions and 177 deletions

View File

@@ -9,6 +9,14 @@ use solana_sdk::system_instruction;
#[derive(Serialize, Deserialize, Debug, Clone)]
pub enum StorageInstruction {
/// Initialize the account as a mining pool, validator or replicator
///
/// Expects 1 Account:
/// 0 - Account to be initialized
InitializeMiningPool,
InitializeValidatorStorage,
InitializeReplicatorStorage,
SubmitMiningProof {
sha_state: Hash,
slot: u64,
@@ -18,6 +26,11 @@ pub enum StorageInstruction {
hash: Hash,
slot: u64,
},
/// Redeem storage reward credits
///
/// Expects 1 Account:
/// 0 - Storage account with credits to redeem
/// 1 - MiningPool account to redeem credits from
ClaimStorageReward {
slot: u64,
},
@@ -27,12 +40,71 @@ pub enum StorageInstruction {
},
}
pub fn create_account(from: &Pubkey, to: &Pubkey, lamports: u64) -> Instruction {
system_instruction::create_account(&from, to, lamports, STORAGE_ACCOUNT_SPACE, &id())
pub fn create_validator_storage_account(
from_pubkey: &Pubkey,
storage_pubkey: &Pubkey,
lamports: u64,
) -> Vec<Instruction> {
vec![
system_instruction::create_account(
from_pubkey,
storage_pubkey,
lamports,
STORAGE_ACCOUNT_SPACE,
&id(),
),
Instruction::new(
id(),
&StorageInstruction::InitializeValidatorStorage,
vec![AccountMeta::new(*storage_pubkey, false)],
),
]
}
pub fn create_replicator_storage_account(
from_pubkey: &Pubkey,
storage_pubkey: &Pubkey,
lamports: u64,
) -> Vec<Instruction> {
vec![
system_instruction::create_account(
from_pubkey,
storage_pubkey,
lamports,
STORAGE_ACCOUNT_SPACE,
&id(),
),
Instruction::new(
id(),
&StorageInstruction::InitializeReplicatorStorage,
vec![AccountMeta::new(*storage_pubkey, false)],
),
]
}
pub fn create_mining_pool_account(
from_pubkey: &Pubkey,
storage_pubkey: &Pubkey,
lamports: u64,
) -> Vec<Instruction> {
vec![
system_instruction::create_account(
from_pubkey,
storage_pubkey,
lamports,
STORAGE_ACCOUNT_SPACE,
&id(),
),
Instruction::new(
id(),
&StorageInstruction::InitializeMiningPool,
vec![AccountMeta::new(*storage_pubkey, false)],
),
]
}
pub fn mining_proof(
from_pubkey: &Pubkey,
storage_pubkey: &Pubkey,
sha_state: Hash,
slot: u64,
signature: Signature,
@@ -42,12 +114,12 @@ pub fn mining_proof(
slot,
signature,
};
let account_metas = vec![AccountMeta::new(*from_pubkey, true)];
let account_metas = vec![AccountMeta::new(*storage_pubkey, true)];
Instruction::new(id(), &storage_instruction, account_metas)
}
pub fn advertise_recent_blockhash(
from_pubkey: &Pubkey,
storage_pubkey: &Pubkey,
storage_hash: Hash,
slot: u64,
) -> Instruction {
@@ -55,12 +127,16 @@ pub fn advertise_recent_blockhash(
hash: storage_hash,
slot,
};
let account_metas = vec![AccountMeta::new(*from_pubkey, true)];
let account_metas = vec![AccountMeta::new(*storage_pubkey, true)];
Instruction::new(id(), &storage_instruction, account_metas)
}
pub fn proof_validation(from_pubkey: &Pubkey, slot: u64, proofs: Vec<CheckedProof>) -> Instruction {
let mut account_metas = vec![AccountMeta::new(*from_pubkey, true)];
pub fn proof_validation(
storage_pubkey: &Pubkey,
slot: u64,
proofs: Vec<CheckedProof>,
) -> Instruction {
let mut account_metas = vec![AccountMeta::new(*storage_pubkey, true)];
proofs.iter().for_each(|checked_proof| {
account_metas.push(AccountMeta::new(checked_proof.proof.id, false))
});
@@ -68,8 +144,15 @@ pub fn proof_validation(from_pubkey: &Pubkey, slot: u64, proofs: Vec<CheckedProo
Instruction::new(id(), &storage_instruction, account_metas)
}
pub fn reward_claim(from_pubkey: &Pubkey, slot: u64) -> Instruction {
pub fn claim_reward(
storage_pubkey: &Pubkey,
mining_pool_pubkey: &Pubkey,
slot: u64,
) -> Instruction {
let storage_instruction = StorageInstruction::ClaimStorageReward { slot };
let account_metas = vec![AccountMeta::new(*from_pubkey, true)];
let account_metas = vec![
AccountMeta::new(*storage_pubkey, false),
AccountMeta::new(*mining_pool_pubkey, false),
];
Instruction::new(id(), &storage_instruction, account_metas)
}