Skip to content

Commit

Permalink
upgrade to 2.0
Browse files Browse the repository at this point in the history
  • Loading branch information
miralandlabs committed Aug 9, 2024
1 parent 8d79224 commit b52cee8
Show file tree
Hide file tree
Showing 12 changed files with 556 additions and 270 deletions.
15 changes: 14 additions & 1 deletion Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 3 additions & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "more-cli"
version = "1.1.2"
version = "2.0.0"
edition = "2021"
license = "Apache-2.0"
description = "A command line interface for ORE cryptocurrency mining. Tailored by Miraland Labs."
Expand All @@ -26,6 +26,7 @@ cached = "0.46.1"
chrono = "0.4.38"
clap = { version = "4.4.12", features = ["derive"] }
colored = "2.0"
core_affinity = "0.8.1"
drillx = "2.0.0"
# drillx = { git = "https://github.com/regolith-labs/drillx", branch = "master", features = ["solana"] }
futures = "0.3.30"
Expand All @@ -51,6 +52,7 @@ spl-associated-token-account = { version = "^2.3", features = [
"no-entrypoint",
] }
tokio = "1.35.1"
url = "2.5"

# [patch.crates-io]
# drillx = { path = "../drillx/drillx" }
Expand Down
24 changes: 24 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,30 @@ To install the CLI, use [cargo](https://doc.rust-lang.org/cargo/getting-started/
cargo install more-cli
```


### Dependencies
If you run into issues during installation, please install the following dependencies for your operating system and try again:

#### Linux
```
sudo apt-get install openssl pkg-config libssl-dev
```

#### MacOS (using [Homebrew](https://brew.sh/))
```
brew install openssl pkg-config
# If you encounter issues with OpenSSL, you might need to set the following environment variables:
export PATH="/usr/local/opt/openssl/bin:$PATH"
export LDFLAGS="-L/usr/local/opt/openssl/lib"
export CPPFLAGS="-I/usr/local/opt/openssl/include"
```

#### Windows (using [Chocolatey](https://chocolatey.org/))
```
choco install openssl pkgconfiglite
```

## Build

To build the codebase from scratch, checkout the repo and use cargo to build:
Expand Down
26 changes: 22 additions & 4 deletions src/args.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,10 +16,10 @@ pub struct BenchmarkArgs {
long,
short,
value_name = "THREAD_COUNT",
help = "The number of threads to use during the benchmark",
help = "The number of cores to use during the benchmark",
default_value = "1"
)]
pub threads: u64,
pub cores: u64,
}

#[derive(Parser, Debug)]
Expand Down Expand Up @@ -54,15 +54,23 @@ pub struct InitializeArgs {}

#[derive(Parser, Debug)]
pub struct MineArgs {
// #[cfg(not(feature = "gpu"))]
#[arg(
long,
short,
value_name = "CORES_COUNT",
help = "The number of CPU cores to allocate to mining",
default_value = "1"
)]
pub cores: Option<u64>,

#[arg(
long,
short,
value_name = "THREAD_COUNT",
help = "The number of CPU threads to allocate to mining",
default_value = "1"
)]
pub threads: u64,
pub threads: Option<u64>,

#[arg(
long,
Expand All @@ -74,6 +82,16 @@ pub struct MineArgs {
pub buffer_time: u64,
}

#[derive(Parser, Debug)]
pub struct ProofArgs {
#[arg(
index = 0,
value_name = "ADDRESS",
help = "The address of the proof to fetch"
)]
pub address: Option<String>,
}

#[derive(Parser, Debug)]
pub struct RewardsArgs {}

Expand Down
28 changes: 23 additions & 5 deletions src/benchmark.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
use std::{sync::Arc, time::Instant};

use drillx::equix;
use solana_rpc_client::spinner;

use crate::{args::BenchmarkArgs, Miner};
Expand All @@ -8,8 +9,8 @@ const TEST_DURATION: i64 = 30;

impl Miner {
pub async fn benchmark(&self, args: BenchmarkArgs) {
// Check num threads
self.check_num_cores(args.threads);
// Check num cores
self.check_num_cores(args.cores);

// Dispatch job to each thread
let challenge = [0; 32];
Expand All @@ -18,16 +19,33 @@ impl Miner {
"Benchmarking. This will take {} sec...",
TEST_DURATION
));
let handles: Vec<_> = (0..args.threads)
let core_ids = core_affinity::get_core_ids().unwrap();
let handles: Vec<_> = core_ids
.into_iter()
.map(|i| {
std::thread::spawn({
move || {
let timer = Instant::now();
let first_nonce = u64::MAX.saturating_div(args.threads).saturating_mul(i);
let first_nonce = u64::MAX
.saturating_div(args.cores)
.saturating_mul(i.id as u64);
let mut nonce = first_nonce;
let mut memory = equix::SolverMemory::new();
loop {
// Return if core should not be used
if (i.id as u64).ge(&args.cores) {
return 0;
}

// Pin to core
let _ = core_affinity::set_for_current(i);

// Create hash
let _hx = drillx::hash(&challenge, &nonce.to_le_bytes());
let _hx = drillx::hash_with_memory(
&mut memory,
&challenge,
&nonce.to_le_bytes(),
);

// Increment nonce
nonce += 1;
Expand Down
43 changes: 11 additions & 32 deletions src/busses.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ use ore_api::{
state::Bus,
};
use ore_utils::AccountDeserialize;
use solana_program::pubkey::Pubkey;
// use solana_program::pubkey::Pubkey;

impl Miner {
// // MI: vanilla version
Expand Down Expand Up @@ -38,47 +38,26 @@ impl Miner {
}
}

// // MI
// pub async fn _find_max_ore_bus(&self) -> Pubkey {
// // MI: inspired by DanielChrobak
// pub async fn find_bus(&self) -> Pubkey {
// let client = self.rpc_client.clone();
// let mut max_rewards: f64 = 0.;
// let mut max_ore_bus: Pubkey = Pubkey::default();
// for address in BUS_ADDRESSES.iter() {
// let data = client.get_account_data(address).await.unwrap();
// match Bus::try_from_bytes(&data) {
// Ok(bus) => {
// let mut max_ore_bus: Pubkey = BUS_ADDRESSES[0];
// let data = client.get_multiple_accounts(&BUS_ADDRESSES).await.unwrap();

// for (address, account) in BUS_ADDRESSES.iter().zip(data.iter()) {
// if let Some(account) = account {
// let data_bytes = &account.data[..]; // Extract data bytes
// if let Ok(bus) = Bus::try_from_bytes(data_bytes) {
// let rewards = (bus.rewards as f64) / 10f64.powf(TOKEN_DECIMALS as f64);
// if rewards > max_rewards {
// max_rewards = rewards;
// max_ore_bus = *address;
// }
// }
// Err(_) => {}
// }
// }

// max_ore_bus
// }

// MI: inspired by DanielChrobak
pub async fn find_bus(&self) -> Pubkey {
let client = self.rpc_client.clone();
let mut max_rewards: f64 = 0.;
let mut max_ore_bus: Pubkey = BUS_ADDRESSES[0];
let data = client.get_multiple_accounts(&BUS_ADDRESSES).await.unwrap();

for (address, account) in BUS_ADDRESSES.iter().zip(data.iter()) {
if let Some(account) = account {
let data_bytes = &account.data[..]; // Extract data bytes
if let Ok(bus) = Bus::try_from_bytes(data_bytes) {
let rewards = (bus.rewards as f64) / 10f64.powf(TOKEN_DECIMALS as f64);
if rewards > max_rewards {
max_rewards = rewards;
max_ore_bus = *address;
}
}
}
}

max_ore_bus
}
}
Loading

0 comments on commit b52cee8

Please sign in to comment.