Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Adds proof_authority arg to mine command #150

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 7 additions & 0 deletions src/args.rs
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,13 @@ pub struct MineArgs {
default_value = "5"
)]
pub buffer_time: u64,

#[arg(
long,
value_name = "PROOF_AUTHORITY",
help = "Authority of the Proof to mine for, if different from signer keypair."
)]
pub proof_authority: Option<String>,
}

#[derive(Parser, Debug)]
Expand Down
16 changes: 11 additions & 5 deletions src/mine.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
use std::{sync::Arc, sync::RwLock, time::Instant};
use std::{sync::Arc, sync::RwLock, time::Instant, str::FromStr};

use colored::*;
use drillx::{
Expand Down Expand Up @@ -26,9 +26,15 @@ use crate::{

impl Miner {
pub async fn mine(&self, args: MineArgs) {
let proof_authority = if let Some(v) = &args.proof_authority {
Pubkey::from_str(v).unwrap()
} else {
self.signer().pubkey()
};

// Open account, if needed.
let signer = self.signer();
self.open().await;
self.open(proof_authority).await;

// Check num threads
self.check_num_cores(args.cores);
Expand All @@ -40,7 +46,7 @@ impl Miner {
// Fetch proof
let config = get_config(&self.rpc_client).await;
let proof =
get_updated_proof_with_authority(&self.rpc_client, signer.pubkey(), last_hash_at)
get_updated_proof_with_authority(&self.rpc_client, proof_authority, last_hash_at)
.await;
println!(
"\n\nStake: {} ORE\n{} Multiplier: {:12}x",
Expand All @@ -67,7 +73,7 @@ impl Miner {
.await;

// Build instruction set
let mut ixs = vec![ore_api::instruction::auth(proof_pubkey(signer.pubkey()))];
let mut ixs = vec![ore_api::instruction::auth(proof_pubkey(proof_authority))];
let mut compute_budget = 500_000;
if self.should_reset(config).await && rand::thread_rng().gen_range(0..100).eq(&0) {
compute_budget += 100_000;
Expand All @@ -77,7 +83,7 @@ impl Miner {
// Build mine ix
ixs.push(ore_api::instruction::mine(
signer.pubkey(),
signer.pubkey(),
proof_authority,
self.find_bus().await,
solution,
));
Expand Down
5 changes: 3 additions & 2 deletions src/open.rs
Original file line number Diff line number Diff line change
@@ -1,13 +1,14 @@
use solana_program::pubkey::Pubkey;
use solana_sdk::signature::Signer;

use crate::{send_and_confirm::ComputeBudget, utils::proof_pubkey, Miner};

impl Miner {
pub async fn open(&self) {
pub async fn open(&self, proof_authority: Pubkey) {
// Return early if miner is already registered
let signer = self.signer();
let fee_payer = self.fee_payer();
let proof_address = proof_pubkey(signer.pubkey());
let proof_address = proof_pubkey(proof_authority);
if self.rpc_client.get_account(&proof_address).await.is_ok() {
return;
}
Expand Down