diff --git a/Cargo.lock b/Cargo.lock index 0688c12..e41ac01 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -77,7 +77,7 @@ version = "0.1.0" dependencies = [ "byteorder 1.2.4 (registry+https://github.com/rust-lang/crates.io-index)", "clap 2.32.0 (registry+https://github.com/rust-lang/crates.io-index)", - "codechain-miner 0.1.0 (git+https://github.com/CodeChain-io/codechain-miner.git?rev=96e200d)", + "codechain-miner 0.1.0 (git+https://github.com/CodeChain-io/codechain-miner.git?rev=820e11e)", "cuckoo 0.1.0 (git+https://github.com/CodeChain-io/rust-cuckoo.git?rev=280cab9c)", "env_logger 0.5.12 (registry+https://github.com/rust-lang/crates.io-index)", "ethereum-types 0.3.2 (registry+https://github.com/rust-lang/crates.io-index)", @@ -90,7 +90,7 @@ dependencies = [ [[package]] name = "codechain-miner" version = "0.1.0" -source = "git+https://github.com/CodeChain-io/codechain-miner.git?rev=96e200d#96e200d74a8386a720eae867bf4be37ba72093cf" +source = "git+https://github.com/CodeChain-io/codechain-miner.git?rev=820e11e#820e11e526d4fc49911eac7864152c21bdf8b6de" dependencies = [ "bytes 0.4.9 (registry+https://github.com/rust-lang/crates.io-index)", "ethereum-types 0.3.2 (registry+https://github.com/rust-lang/crates.io-index)", @@ -919,7 +919,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" "checksum bytes 0.4.9 (registry+https://github.com/rust-lang/crates.io-index)" = "e178b8e0e239e844b083d5a0d4a156b2654e67f9f80144d48398fcd736a24fb8" "checksum cfg-if 0.1.5 (registry+https://github.com/rust-lang/crates.io-index)" = "0c4e7bb64a8ebb0d856483e1e682ea3422f883c5f5615a90d51a2c82fe87fdd3" "checksum clap 2.32.0 (registry+https://github.com/rust-lang/crates.io-index)" = "b957d88f4b6a63b9d70d5f454ac8011819c6efa7727858f458ab71c756ce2d3e" -"checksum codechain-miner 0.1.0 (git+https://github.com/CodeChain-io/codechain-miner.git?rev=96e200d)" = "" +"checksum codechain-miner 0.1.0 (git+https://github.com/CodeChain-io/codechain-miner.git?rev=820e11e)" = "" "checksum crossbeam-deque 0.3.1 (registry+https://github.com/rust-lang/crates.io-index)" = "fe8153ef04a7594ded05b427ffad46ddeaf22e63fd48d42b3e1e3bb4db07cae7" "checksum crossbeam-epoch 0.4.3 (registry+https://github.com/rust-lang/crates.io-index)" = "2af0e75710d6181e234c8ecc79f14a97907850a541b13b0be1dd10992f2e4620" "checksum crossbeam-utils 0.3.2 (registry+https://github.com/rust-lang/crates.io-index)" = "d636a8b3bcc1b409d7ffd3facef8f21dcb4009626adbd0c5e6c4305c07253c7b" diff --git a/Cargo.toml b/Cargo.toml index d359e6c..e5c72f5 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -7,7 +7,7 @@ authors = ["CodeChain Team "] [dependencies] byteorder = "1.2" clap = { version = "2", features = ["yaml"] } -codechain-miner = { git = "https://github.com/CodeChain-io/codechain-miner.git", rev = "96e200d" } +codechain-miner = { git = "https://github.com/CodeChain-io/codechain-miner.git", rev = "820e11e" } cuckoo = { git = "https://github.com/CodeChain-io/rust-cuckoo.git", rev = "280cab9c" } ethereum-types = "0.3.2" env_logger = "0.5.10" diff --git a/README.md b/README.md index f71b0b5..c144f11 100644 --- a/README.md +++ b/README.md @@ -15,13 +15,23 @@ The resulting binary file can be found at `target/release/codechain-cuckoo-miner ## Usage ``` -codechain-cuckoo-miner [OPTIONS] +codechain-cuckoo-miner [OPTIONS] [SUBCOMMAND] ``` ### Usage Examples -* N=0x10, M=0x8, L=6, listening on port **3333**, submitting on port **8080**, **1** concurrent jobs : + +* N=0x10, M=0x8, L=6, **1** concurrent jobs : + +Using HTTP (listening on port **3333**, submitting on port **8080**) +``` +codechain-cuckoo-miner -n 0x10 -m 0x8 -l 6 -j 1 http -p 3333 -s 8080 +``` + +or + +Using Stratum ``` -codechain-cuckoo-miner -n 0x10 -m 0x8 -l 6 -p 3333 -s 8080 -j 1 +codechain-cuckoo-miner -n 0x10 -m 0x8 -l 6 -j 1 stratum ``` ## Configuration @@ -30,12 +40,24 @@ codechain-cuckoo-miner -n 0x10 -m 0x8 -l 6 -p 3333 -s 8080 -j 1 | Option | Description | Default | Required | | :----: | ------------------------------ |:-------------:|:--------:| -| `-p` | Port number to receive job | 3333 | No | -| `-s` | Port number to submit solution | 8080 | No | -| `-j` | The number of concurrent jobs | 1 | No | +| `-n` | Number of vertices in graph | None | Yes | +| `-m` | Number of edges in graph | None | Yes | +| `-l` | Length of cycle to detect | None | Yes | +| `-j` | Number of concurrent jobs | 1 | No | + +### RPC Subcommands + +* HTTP + +| Option | Description | Default | Required | +| :----: | ------------------------------ |:-------------:|:--------:| +| `-p` | Port number to receive job | 3333 | No | +| `-s` | Port number to submit solution | 8008 | No | + +* Stratum | Option | Description | Default | Required | | :----: | ------------------------------ |:-------------:|:--------:| -| `-n` | Number of vertices in graph | None | Yes | -| `-m` | Number of edges in graph | None | Yes | -| `-l` | Length of cycle to detect | None | Yes | +| `-p` | Port number to stratum server | 3333 | No | +| `-i` | Miner name | | No | +| `-w` | Miner password | | No | diff --git a/src/cli.yml b/src/cli.yml index e8a71f5..70d0e69 100644 --- a/src/cli.yml +++ b/src/cli.yml @@ -4,16 +4,6 @@ version_short: "v" author: CodeChain Team about: CodeChian Cuckoo Miner args: - - listening port: - short: p - long: port - takes_value: true - default_value: "3333" - - submitting port: - short: s - long: submit - takes_value: true - default_value: "8080" - max vertex: short: n long: max-vertex @@ -34,3 +24,36 @@ args: long: jobs takes_value: true default_value: "1" + +subcommands: + - http: + about: HTTP RPC for Miner + args: + - listening port: + short: p + long: port + takes_value: true + default_value: "3333" + - submitting port: + short: s + long: submit + takes_value: true + default_value: "8080" + - stratum: + about: Stratum RPC for Miner + args: + - server port: + short: p + long: port + takes_value: true + default_value: "8008" + - miner name: + short: i + long: name + takes_value: true + default_value: "" + - miner pwd: + short: w + long: pwd + takes_value: true + default_value: "" diff --git a/src/config.rs b/src/config.rs index bc23ccc..21a1bee 100644 --- a/src/config.rs +++ b/src/config.rs @@ -14,28 +14,22 @@ // You should have received a copy of the GNU Affero General Public License // along with this program. If not, see . -use codechain_miner::{Config, HttpConfig, RpcConfig, Worker}; +use codechain_miner::{Config, RpcConfig, Worker}; use super::worker::CuckooWorker; -#[derive(Clone, Copy)] +#[derive(Clone)] pub struct CuckooConfig { pub max_vertex: usize, pub max_edge: usize, pub cycle_length: usize, - - pub listening_port: u16, - pub submitting_port: u16, - + pub rpc_config: RpcConfig, pub concurrent_jobs: u16, } impl Config for CuckooConfig { fn rpc_config(&self) -> RpcConfig { - RpcConfig::Http(HttpConfig { - listen_port: self.listening_port, - submitting_port: self.submitting_port, - }) + self.rpc_config.clone() } fn jobs(&self) -> usize { @@ -43,6 +37,6 @@ impl Config for CuckooConfig { } fn worker(&self) -> Box { - Box::new(CuckooWorker::new(*self)) + Box::new(CuckooWorker::new(self.clone())) } } diff --git a/src/main.rs b/src/main.rs index 82f59a3..e783b27 100644 --- a/src/main.rs +++ b/src/main.rs @@ -30,7 +30,7 @@ extern crate rustc_hex; mod config; mod worker; -use codechain_miner::run; +use codechain_miner::{run, HttpConfig, RpcConfig, StratumConfig}; use self::config::CuckooConfig; @@ -49,19 +49,38 @@ fn get_options() -> Result { let yaml = load_yaml!("./cli.yml"); let matches = clap::App::from_yaml(yaml).get_matches(); - let listening_port = value_t!(matches, "listening port", u16).map_err(|_| "Invalid listening port")?; - let submitting_port = value_t!(matches, "submitting port", u16).map_err(|_| "Invalid submitting port")?; let max_vertex = hex_value_t!(matches, "max vertex").map_err(|e| format!("Invalid max vertex: {}", e))?; let max_edge = hex_value_t!(matches, "max edge").map_err(|e| format!("Invalid max edge: {}", e))?; let cycle_length = value_t!(matches, "cycle length", usize).map_err(|_| "Invalid cycle length")?; let concurrent_jobs = value_t!(matches, "concurrent jobs", u16).map_err(|_| "Invalid concurrent jobs")?; + let rpc_config: RpcConfig = if let Some(ref matches) = matches.subcommand_matches("http") { + let listening_port = value_t!(matches, "listening port", u16).map_err(|_| "Invalid listening port")?; + let submitting_port = value_t!(matches, "submitting port", u16).map_err(|_| "Invalid submitting port")?; + + RpcConfig::Http(HttpConfig { + listen_port: listening_port, + submitting_port, + }) + } else if let Some(ref matches) = matches.subcommand_matches("stratum") { + let server_port = value_t!(matches, "server port", u16).map_err(|_| "Invalid server port")?; + let miner_name = value_t!(matches, "miner name", String).map_err(|_| "Invalid miner name")?; + let miner_pwd = value_t!(matches, "miner pwd", String).map_err(|_| "Invalid miner password")?; + + RpcConfig::Stratum(StratumConfig { + port: server_port, + id: miner_name, + pwd: miner_pwd, + }) + } else { + return Err(format!("Invalid RPC Config")) + }; + Ok(CuckooConfig { max_vertex, max_edge, cycle_length, - listening_port, - submitting_port, + rpc_config, concurrent_jobs, }) }