diff --git a/Cargo.lock b/Cargo.lock index d1af5f8257..6416ae2f7b 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -658,7 +658,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" [[package]] name = "grin" -version = "0.4.2" +version = "0.5.0" dependencies = [ "blake2-rfc 0.2.18 (registry+https://github.com/rust-lang/crates.io-index)", "built 0.3.0 (registry+https://github.com/rust-lang/crates.io-index)", @@ -670,16 +670,16 @@ dependencies = [ "failure 0.1.3 (registry+https://github.com/rust-lang/crates.io-index)", "failure_derive 0.1.3 (registry+https://github.com/rust-lang/crates.io-index)", "flate2 1.0.6 (registry+https://github.com/rust-lang/crates.io-index)", - "grin_api 0.4.2", - "grin_chain 0.4.2", - "grin_config 0.4.2", - "grin_core 0.4.2", - "grin_keychain 0.4.2", - "grin_p2p 0.4.2", - "grin_servers 0.4.2", - "grin_store 0.4.2", - "grin_util 0.4.2", - "grin_wallet 0.4.2", + "grin_api 0.5.0", + "grin_chain 0.5.0", + "grin_config 0.5.0", + "grin_core 0.5.0", + "grin_keychain 0.5.0", + "grin_p2p 0.5.0", + "grin_servers 0.5.0", + "grin_store 0.5.0", + "grin_util 0.5.0", + "grin_wallet 0.5.0", "humansize 1.1.0 (registry+https://github.com/rust-lang/crates.io-index)", "log 0.4.6 (registry+https://github.com/rust-lang/crates.io-index)", "reqwest 0.9.5 (registry+https://github.com/rust-lang/crates.io-index)", @@ -692,17 +692,17 @@ dependencies = [ [[package]] name = "grin_api" -version = "0.4.2" +version = "0.5.0" dependencies = [ "failure 0.1.3 (registry+https://github.com/rust-lang/crates.io-index)", "failure_derive 0.1.3 (registry+https://github.com/rust-lang/crates.io-index)", "futures 0.1.25 (registry+https://github.com/rust-lang/crates.io-index)", - "grin_chain 0.4.2", - "grin_core 0.4.2", - "grin_p2p 0.4.2", - "grin_pool 0.4.2", - "grin_store 0.4.2", - "grin_util 0.4.2", + "grin_chain 0.5.0", + "grin_core 0.5.0", + "grin_p2p 0.5.0", + "grin_pool 0.5.0", + "grin_store 0.5.0", + "grin_util 0.5.0", "http 0.1.14 (registry+https://github.com/rust-lang/crates.io-index)", "hyper 0.12.17 (registry+https://github.com/rust-lang/crates.io-index)", "hyper-rustls 0.14.0 (registry+https://github.com/rust-lang/crates.io-index)", @@ -723,7 +723,7 @@ dependencies = [ [[package]] name = "grin_chain" -version = "0.4.2" +version = "0.5.0" dependencies = [ "bitflags 1.0.4 (registry+https://github.com/rust-lang/crates.io-index)", "byteorder 1.2.7 (registry+https://github.com/rust-lang/crates.io-index)", @@ -732,10 +732,10 @@ dependencies = [ "env_logger 0.5.13 (registry+https://github.com/rust-lang/crates.io-index)", "failure 0.1.3 (registry+https://github.com/rust-lang/crates.io-index)", "failure_derive 0.1.3 (registry+https://github.com/rust-lang/crates.io-index)", - "grin_core 0.4.2", - "grin_keychain 0.4.2", - "grin_store 0.4.2", - "grin_util 0.4.2", + "grin_core 0.5.0", + "grin_keychain 0.5.0", + "grin_store 0.5.0", + "grin_util 0.5.0", "lmdb-zero 0.4.4 (registry+https://github.com/rust-lang/crates.io-index)", "log 0.4.6 (registry+https://github.com/rust-lang/crates.io-index)", "lru-cache 0.1.1 (registry+https://github.com/rust-lang/crates.io-index)", @@ -746,13 +746,14 @@ dependencies = [ [[package]] name = "grin_config" -version = "0.4.2" +version = "0.5.0" dependencies = [ "dirs 1.0.4 (registry+https://github.com/rust-lang/crates.io-index)", - "grin_p2p 0.4.2", - "grin_servers 0.4.2", - "grin_util 0.4.2", - "grin_wallet 0.4.2", + "grin_core 0.5.0", + "grin_p2p 0.5.0", + "grin_servers 0.5.0", + "grin_util 0.5.0", + "grin_wallet 0.5.0", "pretty_assertions 0.5.1 (registry+https://github.com/rust-lang/crates.io-index)", "rand 0.5.5 (registry+https://github.com/rust-lang/crates.io-index)", "serde 1.0.81 (registry+https://github.com/rust-lang/crates.io-index)", @@ -762,7 +763,7 @@ dependencies = [ [[package]] name = "grin_core" -version = "0.4.2" +version = "0.5.0" dependencies = [ "bitflags 1.0.4 (registry+https://github.com/rust-lang/crates.io-index)", "blake2-rfc 0.2.18 (registry+https://github.com/rust-lang/crates.io-index)", @@ -771,8 +772,8 @@ dependencies = [ "croaring 0.3.7 (registry+https://github.com/rust-lang/crates.io-index)", "failure 0.1.3 (registry+https://github.com/rust-lang/crates.io-index)", "failure_derive 0.1.3 (registry+https://github.com/rust-lang/crates.io-index)", - "grin_keychain 0.4.2", - "grin_util 0.4.2", + "grin_keychain 0.5.0", + "grin_util 0.5.0", "lazy_static 1.2.0 (registry+https://github.com/rust-lang/crates.io-index)", "log 0.4.6 (registry+https://github.com/rust-lang/crates.io-index)", "lru-cache 0.1.1 (registry+https://github.com/rust-lang/crates.io-index)", @@ -787,12 +788,12 @@ dependencies = [ [[package]] name = "grin_keychain" -version = "0.4.2" +version = "0.5.0" dependencies = [ "blake2-rfc 0.2.18 (registry+https://github.com/rust-lang/crates.io-index)", "byteorder 1.2.7 (registry+https://github.com/rust-lang/crates.io-index)", "digest 0.7.6 (registry+https://github.com/rust-lang/crates.io-index)", - "grin_util 0.4.2", + "grin_util 0.5.0", "hmac 0.6.3 (registry+https://github.com/rust-lang/crates.io-index)", "lazy_static 1.2.0 (registry+https://github.com/rust-lang/crates.io-index)", "log 0.4.6 (registry+https://github.com/rust-lang/crates.io-index)", @@ -808,16 +809,16 @@ dependencies = [ [[package]] name = "grin_p2p" -version = "0.4.2" +version = "0.5.0" dependencies = [ "bitflags 1.0.4 (registry+https://github.com/rust-lang/crates.io-index)", "bytes 0.4.11 (registry+https://github.com/rust-lang/crates.io-index)", "chrono 0.4.6 (registry+https://github.com/rust-lang/crates.io-index)", "enum_primitive 0.1.1 (registry+https://github.com/rust-lang/crates.io-index)", - "grin_core 0.4.2", - "grin_pool 0.4.2", - "grin_store 0.4.2", - "grin_util 0.4.2", + "grin_core 0.5.0", + "grin_pool 0.5.0", + "grin_store 0.5.0", + "grin_util 0.5.0", "lmdb-zero 0.4.4 (registry+https://github.com/rust-lang/crates.io-index)", "log 0.4.6 (registry+https://github.com/rust-lang/crates.io-index)", "net2 0.2.33 (registry+https://github.com/rust-lang/crates.io-index)", @@ -829,15 +830,15 @@ dependencies = [ [[package]] name = "grin_pool" -version = "0.4.2" +version = "0.5.0" dependencies = [ "blake2-rfc 0.2.18 (registry+https://github.com/rust-lang/crates.io-index)", "chrono 0.4.6 (registry+https://github.com/rust-lang/crates.io-index)", - "grin_chain 0.4.2", - "grin_core 0.4.2", - "grin_keychain 0.4.2", - "grin_store 0.4.2", - "grin_util 0.4.2", + "grin_chain 0.5.0", + "grin_core 0.5.0", + "grin_keychain 0.5.0", + "grin_store 0.5.0", + "grin_util 0.5.0", "log 0.4.6 (registry+https://github.com/rust-lang/crates.io-index)", "rand 0.5.5 (registry+https://github.com/rust-lang/crates.io-index)", "serde 1.0.81 (registry+https://github.com/rust-lang/crates.io-index)", @@ -860,21 +861,21 @@ dependencies = [ [[package]] name = "grin_servers" -version = "0.4.2" +version = "0.5.0" dependencies = [ "blake2-rfc 0.2.18 (registry+https://github.com/rust-lang/crates.io-index)", "bufstream 0.1.4 (registry+https://github.com/rust-lang/crates.io-index)", "chrono 0.4.6 (registry+https://github.com/rust-lang/crates.io-index)", "futures 0.1.25 (registry+https://github.com/rust-lang/crates.io-index)", - "grin_api 0.4.2", - "grin_chain 0.4.2", - "grin_core 0.4.2", - "grin_keychain 0.4.2", - "grin_p2p 0.4.2", - "grin_pool 0.4.2", - "grin_store 0.4.2", - "grin_util 0.4.2", - "grin_wallet 0.4.2", + "grin_api 0.5.0", + "grin_chain 0.5.0", + "grin_core 0.5.0", + "grin_keychain 0.5.0", + "grin_p2p 0.5.0", + "grin_pool 0.5.0", + "grin_store 0.5.0", + "grin_util 0.5.0", + "grin_wallet 0.5.0", "http 0.1.14 (registry+https://github.com/rust-lang/crates.io-index)", "hyper 0.12.17 (registry+https://github.com/rust-lang/crates.io-index)", "hyper-staticfile 0.3.0 (registry+https://github.com/rust-lang/crates.io-index)", @@ -890,7 +891,7 @@ dependencies = [ [[package]] name = "grin_store" -version = "0.4.2" +version = "0.5.0" dependencies = [ "byteorder 1.2.7 (registry+https://github.com/rust-lang/crates.io-index)", "chrono 0.4.6 (registry+https://github.com/rust-lang/crates.io-index)", @@ -899,8 +900,8 @@ dependencies = [ "failure 0.1.3 (registry+https://github.com/rust-lang/crates.io-index)", "failure_derive 0.1.3 (registry+https://github.com/rust-lang/crates.io-index)", "filetime 0.2.4 (registry+https://github.com/rust-lang/crates.io-index)", - "grin_core 0.4.2", - "grin_util 0.4.2", + "grin_core 0.5.0", + "grin_util 0.5.0", "libc 0.2.44 (registry+https://github.com/rust-lang/crates.io-index)", "lmdb-zero 0.4.4 (registry+https://github.com/rust-lang/crates.io-index)", "log 0.4.6 (registry+https://github.com/rust-lang/crates.io-index)", @@ -912,7 +913,7 @@ dependencies = [ [[package]] name = "grin_util" -version = "0.4.2" +version = "0.5.0" dependencies = [ "backtrace 0.3.9 (registry+https://github.com/rust-lang/crates.io-index)", "base64 0.9.3 (registry+https://github.com/rust-lang/crates.io-index)", @@ -932,7 +933,7 @@ dependencies = [ [[package]] name = "grin_wallet" -version = "0.4.2" +version = "0.5.0" dependencies = [ "blake2-rfc 0.2.18 (registry+https://github.com/rust-lang/crates.io-index)", "byteorder 1.2.7 (registry+https://github.com/rust-lang/crates.io-index)", @@ -940,13 +941,13 @@ dependencies = [ "failure 0.1.3 (registry+https://github.com/rust-lang/crates.io-index)", "failure_derive 0.1.3 (registry+https://github.com/rust-lang/crates.io-index)", "futures 0.1.25 (registry+https://github.com/rust-lang/crates.io-index)", - "grin_api 0.4.2", - "grin_chain 0.4.2", - "grin_config 0.4.2", - "grin_core 0.4.2", - "grin_keychain 0.4.2", - "grin_store 0.4.2", - "grin_util 0.4.2", + "grin_api 0.5.0", + "grin_chain 0.5.0", + "grin_config 0.5.0", + "grin_core 0.5.0", + "grin_keychain 0.5.0", + "grin_store 0.5.0", + "grin_util 0.5.0", "hyper 0.12.17 (registry+https://github.com/rust-lang/crates.io-index)", "log 0.4.6 (registry+https://github.com/rust-lang/crates.io-index)", "prettytable-rs 0.7.0 (registry+https://github.com/rust-lang/crates.io-index)", diff --git a/Cargo.toml b/Cargo.toml index 198a695939..0d1243d8b8 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "grin" -version = "0.4.2" +version = "0.5.0" authors = ["Grin Developers "] description = "Simple, private and scalable cryptocurrency implementation based on the MimbleWimble chain format." license = "Apache-2.0" @@ -35,14 +35,14 @@ term = "0.5" failure = "0.1" failure_derive = "0.1" -grin_api = { path = "./api", version = "0.4.2" } -grin_config = { path = "./config", version = "0.4.2" } -grin_core = { path = "./core", version = "0.4.2" } -grin_keychain = { path = "./keychain", version = "0.4.2" } -grin_p2p = { path = "./p2p", version = "0.4.2" } -grin_servers = { path = "./servers", version = "0.4.2" } -grin_util = { path = "./util", version = "0.4.2" } -grin_wallet = { path = "./wallet", version = "0.4.2" } +grin_api = { path = "./api", version = "0.5.0" } +grin_config = { path = "./config", version = "0.5.0" } +grin_core = { path = "./core", version = "0.5.0" } +grin_keychain = { path = "./keychain", version = "0.5.0" } +grin_p2p = { path = "./p2p", version = "0.5.0" } +grin_servers = { path = "./servers", version = "0.5.0" } +grin_util = { path = "./util", version = "0.5.0" } +grin_wallet = { path = "./wallet", version = "0.5.0" } [build-dependencies] built = "0.3" @@ -51,5 +51,5 @@ flate2 = "1.0" tar = "0.4" [dev-dependencies] -grin_chain = { path = "./chain", version = "0.4.2" } -grin_store = { path = "./store", version = "0.4.2" } +grin_chain = { path = "./chain", version = "0.5.0" } +grin_store = { path = "./store", version = "0.5.0" } diff --git a/api/Cargo.toml b/api/Cargo.toml index 61a6910247..242dea4bbd 100644 --- a/api/Cargo.toml +++ b/api/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "grin_api" -version = "0.4.2" +version = "0.5.0" authors = ["Grin Developers "] description = "APIs for grin, a simple, private and scalable cryptocurrency implementation based on the MimbleWimble chain format." license = "Apache-2.0" @@ -30,9 +30,9 @@ futures = "0.1.21" rustls = "0.13" url = "1.7.0" -grin_core = { path = "../core", version = "0.4.2" } -grin_chain = { path = "../chain", version = "0.4.2" } -grin_p2p = { path = "../p2p", version = "0.4.2" } -grin_pool = { path = "../pool", version = "0.4.2" } -grin_store = { path = "../store", version = "0.4.2" } -grin_util = { path = "../util", version = "0.4.2" } +grin_core = { path = "../core", version = "0.5.0" } +grin_chain = { path = "../chain", version = "0.5.0" } +grin_p2p = { path = "../p2p", version = "0.5.0" } +grin_pool = { path = "../pool", version = "0.5.0" } +grin_store = { path = "../store", version = "0.5.0" } +grin_util = { path = "../util", version = "0.5.0" } diff --git a/chain/Cargo.toml b/chain/Cargo.toml index ebb7b4d9a1..791286c593 100644 --- a/chain/Cargo.toml +++ b/chain/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "grin_chain" -version = "0.4.2" +version = "0.5.0" authors = ["Grin Developers "] description = "Chain implementation for grin, a simple, private and scalable cryptocurrency implementation based on the MimbleWimble chain format." license = "Apache-2.0" @@ -22,10 +22,10 @@ serde_derive = "1" chrono = "0.4.4" lru-cache = "0.1" -grin_core = { path = "../core", version = "0.4.2" } -grin_keychain = { path = "../keychain", version = "0.4.2" } -grin_store = { path = "../store", version = "0.4.2" } -grin_util = { path = "../util", version = "0.4.2" } +grin_core = { path = "../core", version = "0.5.0" } +grin_keychain = { path = "../keychain", version = "0.5.0" } +grin_store = { path = "../store", version = "0.5.0" } +grin_util = { path = "../util", version = "0.5.0" } [dev-dependencies] env_logger = "0.5" diff --git a/chain/src/error.rs b/chain/src/error.rs index 99f570e2ca..9de778a505 100644 --- a/chain/src/error.rs +++ b/chain/src/error.rs @@ -120,7 +120,7 @@ pub enum ErrorKind { #[fail(display = "Genesis Block Required")] GenesisBlockRequired, /// Error from underlying tx handling - #[fail(display = "Transaction Error")] + #[fail(display = "Transaction Validation Error: {:?}", _0)] Transaction(transaction::Error), /// Anything else #[fail(display = "Other Error: {}", _0)] diff --git a/chain/tests/data_file_integrity.rs b/chain/tests/data_file_integrity.rs index d3cc0b8add..90da6c9ce4 100644 --- a/chain/tests/data_file_integrity.rs +++ b/chain/tests/data_file_integrity.rs @@ -77,7 +77,7 @@ fn data_files() { //new block so chain references should be freed { let chain = setup(chain_dir); - let keychain = ExtKeychain::from_random_seed().unwrap(); + let keychain = ExtKeychain::from_random_seed(false).unwrap(); for n in 1..4 { let prev = chain.head_header().unwrap(); diff --git a/chain/tests/mine_simple_chain.rs b/chain/tests/mine_simple_chain.rs index adcd930c38..122b06884d 100644 --- a/chain/tests/mine_simple_chain.rs +++ b/chain/tests/mine_simple_chain.rs @@ -58,7 +58,7 @@ fn setup(dir_name: &str, genesis: Block) -> Chain { #[test] fn mine_empty_chain() { global::set_mining_mode(ChainTypes::AutomatedTesting); - let keychain = keychain::ExtKeychain::from_random_seed().unwrap(); + let keychain = keychain::ExtKeychain::from_random_seed(false).unwrap(); mine_some_on_top(".grin", pow::mine_genesis_block().unwrap(), &keychain); } @@ -68,7 +68,7 @@ fn mine_genesis_reward_chain() { // add coinbase data from the dev genesis block let mut genesis = genesis::genesis_dev(); - let keychain = keychain::ExtKeychain::from_random_seed().unwrap(); + let keychain = keychain::ExtKeychain::from_random_seed(false).unwrap(); let key_id = keychain::ExtKeychain::derive_key_id(0, 1, 0, 0, 0); let reward = reward::output(&keychain, &key_id, 0).unwrap(); genesis = genesis.with_reward(reward.0, reward.1); @@ -158,7 +158,7 @@ where fn mine_forks() { global::set_mining_mode(ChainTypes::AutomatedTesting); let chain = setup(".grin2", pow::mine_genesis_block().unwrap()); - let kc = ExtKeychain::from_random_seed().unwrap(); + let kc = ExtKeychain::from_random_seed(false).unwrap(); // add a first block to not fork genesis let prev = chain.head_header().unwrap(); @@ -200,7 +200,7 @@ fn mine_forks() { #[test] fn mine_losing_fork() { global::set_mining_mode(ChainTypes::AutomatedTesting); - let kc = ExtKeychain::from_random_seed().unwrap(); + let kc = ExtKeychain::from_random_seed(false).unwrap(); let chain = setup(".grin3", pow::mine_genesis_block().unwrap()); // add a first block we'll be forking from @@ -232,7 +232,7 @@ fn mine_losing_fork() { #[test] fn longer_fork() { global::set_mining_mode(ChainTypes::AutomatedTesting); - let kc = ExtKeychain::from_random_seed().unwrap(); + let kc = ExtKeychain::from_random_seed(false).unwrap(); // to make it easier to compute the txhashset roots in the test, we // prepare 2 chains, the 2nd will be have the forked blocks we can // then send back on the 1st @@ -275,7 +275,7 @@ fn spend_in_fork_and_compact() { util::init_test_logger(); let chain = setup(".grin6", pow::mine_genesis_block().unwrap()); let prev = chain.head_header().unwrap(); - let kc = ExtKeychain::from_random_seed().unwrap(); + let kc = ExtKeychain::from_random_seed(false).unwrap(); let mut fork_head = prev; @@ -404,7 +404,7 @@ fn output_header_mappings() { ".grin_header_for_output", pow::mine_genesis_block().unwrap(), ); - let keychain = ExtKeychain::from_random_seed().unwrap(); + let keychain = ExtKeychain::from_random_seed(false).unwrap(); let mut reward_outputs = vec![]; for n in 1..15 { diff --git a/chain/tests/store_indices.rs b/chain/tests/store_indices.rs index c5b4f04bb8..a5686e278b 100644 --- a/chain/tests/store_indices.rs +++ b/chain/tests/store_indices.rs @@ -51,7 +51,7 @@ fn test_various_store_indices() { let chain_dir = ".grin_idx_1"; clean_output_dir(chain_dir); - let keychain = ExtKeychain::from_random_seed().unwrap(); + let keychain = ExtKeychain::from_random_seed(false).unwrap(); let key_id = ExtKeychainPath::new(1, 1, 0, 0, 0).to_identifier(); let db_env = Arc::new(store::new_env(chain_dir.to_string())); diff --git a/chain/tests/test_coinbase_maturity.rs b/chain/tests/test_coinbase_maturity.rs index 939797baff..ec42a841d6 100644 --- a/chain/tests/test_coinbase_maturity.rs +++ b/chain/tests/test_coinbase_maturity.rs @@ -60,7 +60,7 @@ fn test_coinbase_maturity() { let prev = chain.head_header().unwrap(); - let keychain = ExtKeychain::from_random_seed().unwrap(); + let keychain = ExtKeychain::from_random_seed(false).unwrap(); let key_id1 = ExtKeychainPath::new(1, 1, 0, 0, 0).to_identifier(); let key_id2 = ExtKeychainPath::new(1, 2, 0, 0, 0).to_identifier(); let key_id3 = ExtKeychainPath::new(1, 3, 0, 0, 0).to_identifier(); @@ -142,7 +142,7 @@ fn test_coinbase_maturity() { for _ in 0..3 { let prev = chain.head_header().unwrap(); - let keychain = ExtKeychain::from_random_seed().unwrap(); + let keychain = ExtKeychain::from_random_seed(false).unwrap(); let pk = ExtKeychainPath::new(1, 1, 0, 0, 0).to_identifier(); let reward = libtx::reward::output(&keychain, &pk, 0).unwrap(); diff --git a/config/Cargo.toml b/config/Cargo.toml index 318e219026..b5a6a0176b 100644 --- a/config/Cargo.toml +++ b/config/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "grin_config" -version = "0.4.2" +version = "0.5.0" authors = ["Grin Developers "] description = "Configuration for grin, a simple, private and scalable cryptocurrency implementation based on the MimbleWimble chain format." license = "Apache-2.0" @@ -16,10 +16,11 @@ serde_derive = "1" toml = "0.4" dirs = "1.0.3" -grin_servers = { path = "../servers", version = "0.4.2" } -grin_p2p = { path = "../p2p", version = "0.4.2" } -grin_util = { path = "../util", version = "0.4.2" } -grin_wallet = { path = "../wallet", version = "0.4.2" } +grin_core = { path = "../core", version = "0.5.0" } +grin_servers = { path = "../servers", version = "0.5.0" } +grin_p2p = { path = "../p2p", version = "0.5.0" } +grin_util = { path = "../util", version = "0.5.0" } +grin_wallet = { path = "../wallet", version = "0.5.0" } [dev-dependencies] pretty_assertions = "0.5.1" diff --git a/config/src/comments.rs b/config/src/comments.rs index 8ed346ffe7..6622b5f913 100644 --- a/config/src/comments.rs +++ b/config/src/comments.rs @@ -168,7 +168,7 @@ fn comments() -> HashMap { retval.insert( "[server.p2p_config]".to_string(), "#test miner wallet URL (burns if this doesn't exist) -#test_miner_wallet_url = \"http://127.0.0.1:13415\" +#test_miner_wallet_url = \"http://127.0.0.1:3415\" ######################################### ### SERVER P2P CONFIGURATION ### @@ -208,15 +208,15 @@ fn comments() -> HashMap { "[server.p2p_config.capabilities]".to_string(), "#If the seeding type is List, the list of peers to connect to can #be specified as follows: -#seeds = [\"192.168.0.1:13414\",\"192.168.0.2:13414\"] +#seeds = [\"192.168.0.1:3414\",\"192.168.0.2:3414\"] #hardcoded peer lists for allow/deny #will *only* connect to peers in allow list -#peers_allow = [\"192.168.0.1:13414\", \"192.168.0.2:13414\"] +#peers_allow = [\"192.168.0.1:3414\", \"192.168.0.2:3414\"] #will *never* connect to peers in deny list -#peers_deny = [\"192.168.0.3:13414\", \"192.168.0.4:13414\"] +#peers_deny = [\"192.168.0.3:3414\", \"192.168.0.4:3414\"] #a list of preferred peers to connect to -#peers_preferred = [\"192.168.0.1:13414\",\"192.168.0.2:13414\"] +#peers_preferred = [\"192.168.0.1:3414\",\"192.168.0.2:3414\"] #how long a banned peer should stay banned #ban_window = 10800 diff --git a/config/src/config.rs b/config/src/config.rs index 21791dd76b..d334b41b60 100644 --- a/config/src/config.rs +++ b/config/src/config.rs @@ -26,6 +26,8 @@ use std::path::PathBuf; use toml; use crate::comments::insert_comments; +use crate::core::global; +use crate::p2p; use crate::servers::ServerConfig; use crate::types::{ ConfigError, ConfigMembers, GlobalConfig, GlobalWalletConfig, GlobalWalletConfigMembers, @@ -45,21 +47,14 @@ const GRIN_CHAIN_DIR: &'static str = "chain_data"; const GRIN_WALLET_DIR: &'static str = "wallet_data"; const API_SECRET_FILE_NAME: &'static str = ".api_secret"; -fn get_grin_path() -> Result { +fn get_grin_path(chain_type: &global::ChainTypes) -> Result { // Check if grin dir exists - let grin_path = { - match dirs::home_dir() { - Some(mut p) => { - p.push(GRIN_HOME); - p - } - None => { - let mut pb = PathBuf::new(); - pb.push(GRIN_HOME); - pb - } - } + let mut grin_path = match dirs::home_dir() { + Some(p) => p, + None => PathBuf::new(), }; + grin_path.push(GRIN_HOME); + grin_path.push(chain_type.shortname()); // Create if the default path doesn't exist if !grin_path.exists() { fs::create_dir_all(grin_path.clone())?; @@ -107,8 +102,8 @@ fn check_api_secret(api_secret_path: &PathBuf) -> Result<(), ConfigError> { } /// Check that the api secret file exists and is valid -fn check_api_secret_file() -> Result<(), ConfigError> { - let grin_path = get_grin_path()?; +fn check_api_secret_file(chain_type: &global::ChainTypes) -> Result<(), ConfigError> { + let grin_path = get_grin_path(chain_type)?; let mut api_secret_path = grin_path.clone(); api_secret_path.push(API_SECRET_FILE_NAME); if !api_secret_path.exists() { @@ -119,14 +114,14 @@ fn check_api_secret_file() -> Result<(), ConfigError> { } /// Handles setup and detection of paths for node -pub fn initial_setup_server() -> Result { - check_api_secret_file()?; +pub fn initial_setup_server(chain_type: &global::ChainTypes) -> Result { + check_api_secret_file(chain_type)?; // Use config file if current directory if it exists, .grin home otherwise if let Some(p) = check_config_current_dir(SERVER_CONFIG_FILE_NAME) { GlobalConfig::new(p.to_str().unwrap()) } else { // Check if grin dir exists - let grin_path = get_grin_path()?; + let grin_path = get_grin_path(chain_type)?; // Get path to default config file let mut config_path = grin_path.clone(); @@ -134,7 +129,7 @@ pub fn initial_setup_server() -> Result { // Spit it out if it doesn't exist if !config_path.exists() { - let mut default_config = GlobalConfig::default(); + let mut default_config = GlobalConfig::for_chain(chain_type); // update paths relative to current dir default_config.update_paths(&grin_path); default_config.write_to_file(config_path.to_str().unwrap())?; @@ -145,14 +140,16 @@ pub fn initial_setup_server() -> Result { } /// Handles setup and detection of paths for wallet -pub fn initial_setup_wallet() -> Result { - check_api_secret_file()?; +pub fn initial_setup_wallet( + chain_type: &global::ChainTypes, +) -> Result { + check_api_secret_file(chain_type)?; // Use config file if current directory if it exists, .grin home otherwise if let Some(p) = check_config_current_dir(WALLET_CONFIG_FILE_NAME) { GlobalWalletConfig::new(p.to_str().unwrap()) } else { // Check if grin dir exists - let grin_path = get_grin_path()?; + let grin_path = get_grin_path(chain_type)?; // Get path to default config file let mut config_path = grin_path.clone(); @@ -160,7 +157,7 @@ pub fn initial_setup_wallet() -> Result { // Spit it out if it doesn't exist if !config_path.exists() { - let mut default_config = GlobalWalletConfig::default(); + let mut default_config = GlobalWalletConfig::for_chain(chain_type); // update paths relative to current dir default_config.update_paths(&grin_path); default_config.write_to_file(config_path.to_str().unwrap())?; @@ -208,6 +205,51 @@ impl Default for GlobalWalletConfig { } impl GlobalConfig { + /// Same as GlobalConfig::default() but further tweaks parameters to + /// apply defaults for each chain type + pub fn for_chain(chain_type: &global::ChainTypes) -> GlobalConfig { + let mut defaults_conf = GlobalConfig::default(); + let mut defaults = &mut defaults_conf.members.as_mut().unwrap().server; + defaults.chain_type = chain_type.clone(); + + match *chain_type { + global::ChainTypes::Mainnet => {} + global::ChainTypes::Floonet => { + defaults.api_http_addr = "127.0.0.1:13413".to_owned(); + defaults.p2p_config.port = 13414; + defaults + .stratum_mining_config + .as_mut() + .unwrap() + .stratum_server_addr = Some("127.0.0.1:13416".to_owned()); + defaults + .stratum_mining_config + .as_mut() + .unwrap() + .wallet_listener_url = "http://127.0.0.1:13415".to_owned(); + } + global::ChainTypes::UserTesting => { + defaults.api_http_addr = "127.0.0.1:23413".to_owned(); + defaults.p2p_config.port = 23414; + defaults.p2p_config.seeding_type = p2p::Seeding::None; + defaults + .stratum_mining_config + .as_mut() + .unwrap() + .stratum_server_addr = Some("127.0.0.1:23416".to_owned()); + defaults + .stratum_mining_config + .as_mut() + .unwrap() + .wallet_listener_url = "http://127.0.0.1:23415".to_owned(); + } + global::ChainTypes::AutomatedTesting => { + panic!("Can't run automated testing directly"); + } + } + defaults_conf + } + /// Requires the path to a config file pub fn new(file_path: &str) -> Result { let mut return_value = GlobalConfig::default(); @@ -315,6 +357,29 @@ impl GlobalConfig { /// TODO: Properly templatize these structs (if it's worth the effort) impl GlobalWalletConfig { + /// Same as GlobalConfig::default() but further tweaks parameters to + /// apply defaults for each chain type + pub fn for_chain(chain_type: &global::ChainTypes) -> GlobalWalletConfig { + let mut defaults_conf = GlobalWalletConfig::default(); + let mut defaults = &mut defaults_conf.members.as_mut().unwrap().wallet; + defaults.chain_type = Some(chain_type.clone()); + + match *chain_type { + global::ChainTypes::Mainnet => {} + global::ChainTypes::Floonet => { + defaults.api_listen_port = 13415; + defaults.check_node_api_http_addr = "http://127.0.0.1:13413".to_owned(); + } + global::ChainTypes::UserTesting => { + defaults.api_listen_port = 23415; + defaults.check_node_api_http_addr = "http://127.0.0.1:23413".to_owned(); + } + global::ChainTypes::AutomatedTesting => { + panic!("Can't run automated testing directly"); + } + } + defaults_conf + } /// Requires the path to a config file pub fn new(file_path: &str) -> Result { let mut return_value = GlobalWalletConfig::default(); diff --git a/config/src/lib.rs b/config/src/lib.rs index 54054a4345..aec60bc5ea 100644 --- a/config/src/lib.rs +++ b/config/src/lib.rs @@ -26,6 +26,8 @@ use dirs; extern crate serde_derive; use toml; +use grin_core as core; +use grin_p2p as p2p; use grin_servers as servers; use grin_util as util; use grin_wallet as wallet; diff --git a/core/Cargo.toml b/core/Cargo.toml index affae0c056..7164c04ae6 100644 --- a/core/Cargo.toml +++ b/core/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "grin_core" -version = "0.4.2" +version = "0.5.0" authors = ["Grin Developers "] description = "Chain implementation for grin, a simple, private and scalable cryptocurrency implementation based on the MimbleWimble chain format." license = "Apache-2.0" @@ -28,5 +28,5 @@ uuid = { version = "0.6", features = ["serde", "v4"] } log = "0.4" chrono = "0.4.4" -grin_keychain = { path = "../keychain", version = "0.4.2" } -grin_util = { path = "../util", version = "0.4.2" } +grin_keychain = { path = "../keychain", version = "0.5.0" } +grin_util = { path = "../util", version = "0.5.0" } diff --git a/core/src/consensus.rs b/core/src/consensus.rs index 5500a12400..00f471a9c3 100644 --- a/core/src/consensus.rs +++ b/core/src/consensus.rs @@ -231,7 +231,8 @@ impl HeaderInfo { timestamp, difficulty, secondary_scaling: global::initial_graph_weight(), - is_secondary: global::is_mainnet(), // floonet launched with false:-( + + is_secondary: true, } } @@ -242,7 +243,7 @@ impl HeaderInfo { timestamp: 1, difficulty, secondary_scaling, - is_secondary: false, + is_secondary: true, } } } diff --git a/core/src/core/transaction.rs b/core/src/core/transaction.rs index 845116d90a..8644a0f154 100644 --- a/core/src/core/transaction.rs +++ b/core/src/core/transaction.rs @@ -1349,37 +1349,31 @@ impl From for OutputIdentifier { } /// Construct msg from tx fee, lock_height and kernel features. -/// In testnet4 we did not include the kernel features in the message being signed. -/// In mainnet we changed this to include features and we hash (fee || lock_height || features) -/// to produce a 32 byte message to sign. /// -/// testnet4: msg = (fee || lock_height) -/// mainnet: msg = hash(features) for coinbase kernels -/// hash(features || fee) for plain kernels -/// hash(features || fee || lock_height) for height locked kernels +/// msg = hash(features) for coinbase kernels +/// hash(features || fee) for plain kernels +/// hash(features || fee || lock_height) for height locked kernels /// pub fn kernel_sig_msg( fee: u64, lock_height: u64, features: KernelFeatures, ) -> Result { - if features.is_coinbase() && fee != 0 || !features.is_height_locked() && lock_height != 0 { + let valid_features = match features { + KernelFeatures::COINBASE => fee == 0 && lock_height == 0, + KernelFeatures::PLAIN => lock_height == 0, + KernelFeatures::HEIGHT_LOCKED => true, + _ => false, + }; + if !valid_features { return Err(Error::InvalidKernelFeatures); } - let msg = if global::is_testnet() { - let mut bytes = [0; 32]; - BigEndian::write_u64(&mut bytes[16..24], fee); - BigEndian::write_u64(&mut bytes[24..], lock_height); - secp::Message::from_slice(&bytes)? - } else { - let hash = match features { - KernelFeatures::COINBASE => (features).hash(), - KernelFeatures::PLAIN => (features, fee).hash(), - _ => (features, fee, lock_height).hash(), - }; - secp::Message::from_slice(&hash.as_bytes())? + let hash = match features { + KernelFeatures::COINBASE => (features).hash(), + KernelFeatures::PLAIN => (features, fee).hash(), + _ => (features, fee, lock_height).hash(), }; - Ok(msg) + Ok(secp::Message::from_slice(&hash.as_bytes())?) } /// kernel features as determined by lock height @@ -1401,7 +1395,7 @@ mod test { #[test] fn test_kernel_ser_deser() { - let keychain = ExtKeychain::from_random_seed().unwrap(); + let keychain = ExtKeychain::from_random_seed(false).unwrap(); let key_id = ExtKeychain::derive_key_id(1, 1, 0, 0, 0); let commit = keychain.commit(5, &key_id).unwrap(); @@ -1446,7 +1440,7 @@ mod test { #[test] fn commit_consistency() { - let keychain = ExtKeychain::from_seed(&[0; 32]).unwrap(); + let keychain = ExtKeychain::from_seed(&[0; 32], false).unwrap(); let key_id = ExtKeychain::derive_key_id(1, 1, 0, 0, 0); let commit = keychain.commit(1003, &key_id).unwrap(); @@ -1459,7 +1453,7 @@ mod test { #[test] fn input_short_id() { - let keychain = ExtKeychain::from_seed(&[0; 32]).unwrap(); + let keychain = ExtKeychain::from_seed(&[0; 32], false).unwrap(); let key_id = ExtKeychain::derive_key_id(1, 1, 0, 0, 0); let commit = keychain.commit(5, &key_id).unwrap(); diff --git a/core/src/genesis.rs b/core/src/genesis.rs index 25e3a661d2..bfbb654174 100644 --- a/core/src/genesis.rs +++ b/core/src/genesis.rs @@ -51,21 +51,21 @@ pub fn genesis_dev() -> core::Block { pub fn genesis_floo() -> core::Block { let gen = core::Block::with_header(core::BlockHeader { height: 0, - timestamp: Utc.ymd(2018, 12, 20).and_hms(20, 58, 32), + timestamp: Utc.ymd(2018, 12, 28).and_hms(20, 48, 4), prev_root: Hash::from_hex( - "ae144568a9ec32faf57e9ca5b5f0997d33f30bd3352fd84c953e6526d847c26b", + "00000000000000000017ff4903ef366c8f62e3151ba74e41b8332a126542f538", ) .unwrap(), output_root: Hash::from_hex( - "47d2570266451203c62cd003c706e3ec37e9cb4292316744abfa68a1b133bc1c", + "73b5e0a05ea9e1e4e33b8f1c723bc5c10d17f07042c2af7644f4dbb61f4bc556", ) .unwrap(), range_proof_root: Hash::from_hex( - "53ea93e80fe37e9a0cbb9c1a1ddf467213922481a4435921aacf55ffb3f388fc", + "667a3ba22f237a875f67c9933037c8564097fa57a3e75be507916de28fc0da26", ) .unwrap(), kernel_root: Hash::from_hex( - "3ff7655b2846a1313dd72e1c516a2fa262638fabc8e0d4c1dddf80773bbd472d", + "cfdddfe2d938d0026f8b1304442655bbdddde175ff45ddf44cb03bcb0071a72d", ) .unwrap(), total_kernel_offset: BlindingFactor::from_hex( @@ -75,17 +75,17 @@ pub fn genesis_floo() -> core::Block { output_mmr_size: 1, kernel_mmr_size: 1, pow: ProofOfWork { - total_difficulty: Difficulty::from_num(10_u64.pow(6)), + total_difficulty: Difficulty::from_num(10_u64.pow(5)), secondary_scaling: 1856, - nonce: 22, + nonce: 23, proof: Proof { nonces: vec![ - 48398361, 50434294, 73758991, 93493375, 94716564, 101961133, 153506566, - 159476458, 164019912, 208165915, 216747111, 218441011, 221663358, 262514197, - 264746362, 278423427, 282069592, 284508695, 297003554, 327321117, 327780367, - 329474453, 333639856, 356316379, 366419120, 381872178, 386038638, 389726932, - 390055244, 392425788, 399530286, 426997994, 436531599, 456084550, 456375883, - 459156409, 474067792, 480904139, 487380747, 489307817, 496780560, 530227836, + 16994232, 22975978, 32664019, 44016212, 50238216, 57272481, 85779161, + 124272202, 125203242, 133907662, 140522149, 145870823, 147481297, 164952795, + 177186722, 183382201, 197418356, 211393794, 239282197, 239323031, 250757611, + 281414565, 305112109, 308151499, 357235186, 374041407, 389924708, 390768911, + 401322239, 401886855, 406986280, 416797005, 418935317, 429007407, 439527429, + 484809502, 486257104, 495589543, 495892390, 525019296, 529899691, 531685572, ], edge_bits: 29, }, @@ -98,15 +98,15 @@ pub fn genesis_floo() -> core::Block { lock_height: 0, excess: Commitment::from_vec( util::from_hex( - "0817a9e97a070ba5f9fa185c093b4b13b262ed4b4712b6f7c92881b27168f9a2cb".to_string(), + "08df2f1d996cee37715d9ac0a0f3b13aae508d1101945acb8044954aee30960be9".to_string(), ) .unwrap(), ), excess_sig: Signature::from_raw_data(&[ - 172, 131, 105, 224, 31, 11, 0, 70, 109, 54, 230, 184, 177, 138, 46, 137, 202, 215, 152, - 37, 192, 132, 88, 254, 110, 76, 57, 32, 42, 13, 19, 89, 82, 89, 116, 66, 30, 132, 120, - 148, 122, 100, 97, 38, 141, 219, 57, 184, 171, 130, 213, 235, 83, 202, 69, 13, 213, 60, - 150, 172, 33, 37, 209, 57, + 25, 176, 52, 246, 172, 1, 12, 220, 247, 111, 73, 101, 13, 16, 157, 130, 110, 196, 123, + 217, 246, 137, 45, 110, 106, 186, 0, 151, 255, 193, 233, 178, 103, 26, 210, 215, 200, + 89, 146, 188, 9, 161, 28, 212, 227, 143, 82, 54, 5, 223, 16, 65, 237, 132, 196, 241, + 39, 76, 133, 45, 252, 131, 88, 0, ]) .unwrap(), }; @@ -114,51 +114,51 @@ pub fn genesis_floo() -> core::Block { features: core::OutputFeatures::COINBASE, commit: Commitment::from_vec( util::from_hex( - "08f5523cbd8b2e1dae3eefdd9dd1069e0c8a7f055a0611da79f42530c5de0d044b".to_string(), + "08c12007af16d1ee55fffe92cef808c77e318dae70c3bc70cb6361f49d517f1b68".to_string(), ) .unwrap(), ), proof: RangeProof { plen: SINGLE_BULLET_PROOF_SIZE, proof: [ - 47, 196, 194, 238, 233, 164, 218, 64, 54, 92, 83, 248, 225, 116, 189, 225, 202, 66, - 213, 63, 195, 209, 238, 189, 153, 198, 231, 219, 3, 146, 102, 67, 26, 7, 199, 150, - 160, 244, 48, 166, 113, 6, 241, 49, 133, 248, 201, 80, 34, 19, 118, 249, 44, 213, - 215, 235, 228, 187, 215, 116, 212, 203, 232, 183, 12, 66, 29, 11, 28, 17, 212, 104, - 126, 203, 103, 60, 176, 149, 182, 206, 70, 138, 180, 213, 76, 99, 25, 184, 40, 177, - 197, 179, 71, 63, 19, 72, 253, 129, 115, 107, 90, 249, 39, 108, 134, 10, 231, 172, - 172, 59, 207, 118, 175, 124, 197, 132, 73, 154, 148, 8, 73, 26, 231, 75, 24, 134, - 199, 93, 15, 43, 45, 49, 69, 167, 194, 23, 114, 16, 117, 209, 127, 123, 18, 209, - 12, 34, 219, 196, 37, 7, 226, 132, 70, 111, 113, 164, 203, 175, 105, 175, 196, 62, - 225, 138, 162, 176, 190, 109, 96, 210, 15, 38, 245, 200, 83, 155, 185, 111, 85, - 234, 6, 3, 246, 98, 175, 127, 94, 65, 29, 78, 27, 53, 32, 230, 85, 91, 195, 112, - 84, 135, 56, 207, 213, 165, 40, 248, 238, 202, 225, 142, 79, 89, 81, 197, 138, 65, - 14, 232, 145, 44, 73, 6, 43, 8, 43, 42, 127, 151, 68, 18, 19, 83, 14, 142, 180, 75, - 25, 4, 97, 166, 237, 212, 187, 106, 154, 36, 223, 231, 177, 58, 70, 1, 195, 113, - 144, 151, 45, 185, 0, 174, 116, 212, 122, 239, 96, 1, 122, 211, 41, 96, 230, 110, - 242, 145, 176, 230, 55, 143, 142, 234, 151, 49, 151, 109, 252, 120, 147, 244, 178, - 73, 196, 221, 150, 85, 69, 113, 50, 166, 92, 91, 98, 188, 77, 76, 48, 192, 112, - 184, 108, 143, 134, 56, 46, 119, 21, 71, 247, 119, 133, 225, 72, 15, 158, 60, 64, - 71, 57, 134, 243, 228, 58, 13, 58, 209, 71, 4, 72, 87, 129, 51, 46, 64, 188, 60, - 157, 56, 120, 23, 2, 47, 143, 79, 176, 54, 3, 47, 227, 124, 70, 242, 8, 59, 113, - 203, 51, 65, 138, 131, 121, 45, 131, 132, 171, 161, 49, 235, 129, 39, 164, 234, 69, - 172, 95, 28, 180, 118, 163, 151, 148, 66, 65, 104, 222, 232, 154, 22, 30, 149, 196, - 214, 163, 93, 76, 128, 142, 233, 106, 171, 213, 148, 59, 101, 56, 22, 127, 232, 4, - 63, 111, 9, 188, 163, 40, 158, 24, 65, 81, 203, 231, 93, 197, 102, 170, 70, 239, - 229, 13, 172, 110, 157, 226, 112, 182, 28, 150, 222, 62, 224, 94, 182, 220, 243, - 236, 62, 156, 129, 220, 127, 155, 141, 0, 243, 159, 113, 28, 158, 95, 205, 35, 72, - 132, 46, 235, 176, 146, 233, 93, 111, 4, 105, 236, 176, 165, 102, 168, 188, 121, - 105, 175, 197, 114, 97, 40, 2, 165, 153, 85, 135, 114, 147, 95, 216, 50, 108, 52, - 225, 186, 215, 110, 122, 230, 14, 246, 141, 180, 41, 22, 132, 58, 8, 31, 187, 221, - 231, 14, 33, 52, 88, 219, 200, 77, 246, 134, 18, 0, 113, 144, 6, 146, 54, 24, 113, - 14, 64, 182, 116, 229, 250, 201, 126, 84, 192, 80, 13, 57, 232, 55, 113, 139, 249, - 166, 231, 123, 101, 236, 147, 144, 2, 9, 51, 2, 189, 188, 200, 66, 29, 16, 22, 150, - 45, 220, 15, 161, 180, 214, 244, 104, 41, 77, 171, 246, 243, 56, 47, 63, 103, 216, - 151, 199, 249, 169, 165, 119, 200, 243, 161, 83, 46, 225, 195, 92, 96, 150, 0, 165, - 170, 14, 211, 226, 244, 70, 218, 137, 254, 197, 175, 208, 119, 199, 121, 4, 7, 190, - 118, 55, 197, 208, 41, 109, 161, 34, 33, 210, 58, 99, 81, 97, 57, 156, 57, 144, 83, - 97, 49, 248, 89, 201, 88, 169, 9, 211, 34, 136, 174, 195, 224, 51, 103, 12, 237, - 172, 46, 216, 5, 168, + 159, 156, 202, 179, 128, 169, 14, 227, 176, 79, 118, 180, 62, 164, 2, 234, 123, 30, + 77, 126, 232, 124, 42, 186, 239, 208, 21, 217, 228, 246, 148, 74, 100, 25, 247, + 251, 82, 100, 37, 16, 146, 122, 164, 5, 2, 165, 212, 192, 221, 167, 199, 8, 231, + 149, 158, 216, 194, 200, 62, 15, 53, 200, 188, 207, 0, 79, 211, 88, 194, 211, 54, + 1, 206, 53, 72, 118, 155, 184, 233, 166, 245, 224, 16, 254, 209, 235, 153, 85, 53, + 145, 33, 186, 218, 118, 144, 35, 189, 241, 63, 229, 52, 237, 231, 39, 176, 202, 93, + 247, 85, 131, 16, 193, 247, 180, 33, 138, 255, 102, 190, 213, 129, 174, 182, 167, + 3, 126, 184, 221, 99, 114, 238, 219, 157, 125, 230, 179, 160, 89, 202, 230, 16, 91, + 199, 57, 158, 225, 142, 125, 12, 211, 164, 78, 9, 4, 155, 106, 157, 41, 233, 188, + 237, 205, 184, 53, 0, 190, 24, 215, 42, 44, 184, 120, 58, 196, 198, 190, 114, 50, + 98, 240, 15, 213, 77, 163, 24, 3, 212, 125, 93, 175, 169, 249, 24, 27, 191, 113, + 89, 59, 169, 40, 87, 250, 144, 159, 118, 171, 232, 92, 217, 5, 179, 152, 249, 247, + 71, 239, 26, 180, 82, 177, 226, 132, 185, 3, 33, 162, 120, 98, 87, 109, 57, 100, + 202, 162, 57, 230, 44, 31, 63, 213, 30, 222, 241, 78, 162, 118, 120, 70, 196, 128, + 72, 223, 110, 5, 17, 151, 97, 214, 43, 57, 157, 1, 59, 87, 96, 17, 159, 174, 144, + 217, 159, 87, 36, 113, 41, 155, 186, 252, 162, 46, 22, 80, 133, 3, 113, 248, 11, + 118, 144, 155, 188, 77, 166, 40, 119, 107, 15, 233, 47, 47, 101, 77, 167, 141, 235, + 148, 34, 218, 164, 168, 71, 20, 239, 71, 24, 12, 109, 146, 232, 243, 65, 31, 72, + 186, 131, 190, 43, 227, 157, 41, 49, 126, 136, 51, 41, 50, 213, 37, 186, 223, 87, + 248, 34, 43, 132, 34, 0, 143, 75, 79, 43, 74, 183, 26, 2, 168, 53, 203, 208, 159, + 69, 107, 124, 33, 68, 113, 206, 127, 216, 158, 15, 52, 206, 1, 101, 109, 199, 13, + 131, 122, 29, 131, 133, 125, 219, 70, 69, 144, 133, 68, 233, 67, 203, 132, 160, + 143, 101, 84, 110, 15, 175, 111, 124, 24, 185, 222, 154, 238, 77, 241, 105, 8, 224, + 230, 43, 178, 49, 95, 137, 33, 227, 118, 207, 239, 56, 21, 51, 220, 22, 48, 162, + 22, 118, 229, 215, 248, 112, 198, 126, 180, 27, 161, 237, 56, 2, 220, 129, 126, 11, + 104, 8, 133, 190, 162, 204, 3, 63, 249, 173, 210, 152, 252, 143, 157, 79, 228, 232, + 230, 72, 164, 131, 183, 151, 230, 219, 186, 21, 34, 154, 219, 215, 231, 179, 47, + 217, 44, 115, 203, 157, 35, 195, 113, 235, 194, 102, 96, 205, 24, 221, 213, 147, + 120, 178, 221, 153, 146, 44, 172, 131, 77, 21, 61, 15, 5, 6, 205, 164, 203, 76, + 228, 29, 126, 136, 88, 230, 210, 62, 164, 103, 125, 55, 231, 129, 89, 61, 222, 50, + 71, 71, 75, 230, 70, 80, 85, 193, 136, 183, 222, 146, 46, 235, 0, 222, 118, 32, 70, + 85, 39, 92, 233, 211, 169, 159, 207, 145, 13, 206, 125, 3, 45, 51, 64, 167, 179, + 133, 83, 57, 190, 51, 239, 211, 74, 116, 75, 71, 248, 249, 184, 13, 31, 129, 107, + 104, 179, 76, 194, 186, 4, 13, 122, 167, 254, 126, 153, 50, 8, 1, 200, 203, 213, + 230, 217, 97, 105, 50, 208, 126, 180, 113, 81, 152, 238, 123, 157, 232, 19, 164, + 159, 164, 89, 75, 33, 70, 140, 204, 158, 236, 10, 226, 102, 14, 88, 134, 82, 131, + 36, 195, 127, 158, 81, 252, 223, 165, 11, 52, 105, 245, 245, 228, 235, 168, 175, + 52, 175, 76, 157, 120, 208, 99, 135, 210, 81, 114, 230, 181, ], }, }; @@ -221,11 +221,11 @@ mod test { println!("floonet genesis full hash: {}\n", gen_bin.hash().to_hex()); assert_eq!( gen_hash.to_hex(), - "cb272478ee4abbf41a3d8cc8f2f828785cf38bd7f0dcacfdd6db5f8f2d8f6e24" + "edc758c1370d43e1d733f70f58cf187c3be8242830429b1676b89fd91ccf2dab" ); assert_eq!( gen_bin.hash().to_hex(), - "5fcc7afebc2dcfb98f982dd4d9ff7878fca45038d22677ef6360745c90505035" + "91c638fc019a54e6652bd6bb3d9c5e0c17e889cef34a5c28528e7eb61a884dc4" ); } diff --git a/core/src/global.rs b/core/src/global.rs index b3ba9fef35..24114dbc47 100644 --- a/core/src/global.rs +++ b/core/src/global.rs @@ -93,6 +93,18 @@ pub enum ChainTypes { Mainnet, } +impl ChainTypes { + /// Short name representing the chain type ("floo", "main", etc.) + pub fn shortname(&self) -> String { + match *self { + ChainTypes::AutomatedTesting => "auto".to_owned(), + ChainTypes::UserTesting => "user".to_owned(), + ChainTypes::Floonet => "floo".to_owned(), + ChainTypes::Mainnet => "main".to_owned(), + } + } +} + impl Default for ChainTypes { fn default() -> ChainTypes { ChainTypes::Floonet @@ -152,11 +164,6 @@ where } } -/// Return the type of the pos -pub fn pow_type() -> PoWContextTypes { - PoWContextTypes::Cuckatoo -} - /// The minimum acceptable edge_bits pub fn min_edge_bits() -> u8 { let param_ref = CHAIN_TYPE.read(); @@ -256,12 +263,11 @@ pub fn is_user_testing_mode() -> bool { /// Production defined as a live public network, testnet[n] or mainnet. pub fn is_production_mode() -> bool { let param_ref = CHAIN_TYPE.read(); - ChainTypes::Floonet == *param_ref - || ChainTypes::Mainnet == *param_ref + ChainTypes::Floonet == *param_ref || ChainTypes::Mainnet == *param_ref } -/// Are we in one of our (many) testnets? -pub fn is_testnet() -> bool { +/// Are we in floonet? +pub fn is_floonet() -> bool { let param_ref = CHAIN_TYPE.read(); ChainTypes::Floonet == *param_ref } @@ -290,6 +296,12 @@ pub fn get_genesis_nonce() -> u64 { } } +/// Short name representing the current chain type ("floo", "main", etc.) +pub fn chain_shortname() -> String { + let param_ref = CHAIN_TYPE.read(); + param_ref.shortname() +} + /// Converts an iterator of block difficulty data to more a more manageable /// vector and pads if needed (which will) only be needed for the first few /// blocks after genesis diff --git a/core/src/libtx/aggsig.rs b/core/src/libtx/aggsig.rs index 43e37ea53c..4dea7f7678 100644 --- a/core/src/libtx/aggsig.rs +++ b/core/src/libtx/aggsig.rs @@ -234,7 +234,7 @@ pub fn verify_partial_sig( /// use keychain::{Keychain, ExtKeychain}; /// /// let secp = Secp256k1::with_caps(ContextFlag::Commit); -/// let keychain = ExtKeychain::from_random_seed().unwrap(); +/// let keychain = ExtKeychain::from_random_seed(false).unwrap(); /// let fees = 10_000; /// let value = reward(fees); /// let key_id = ExtKeychain::derive_key_id(1, 1, 0, 0, 0); @@ -266,16 +266,7 @@ where K: Keychain, { let skey = k.derive_key(value, key_id)?; - let sig = aggsig::sign_single( - secp, - &msg, - &skey, - None, - None, - None, - blind_sum, - None, - )?; + let sig = aggsig::sign_single(secp, &msg, &skey, None, None, None, blind_sum, None)?; Ok(sig) } @@ -308,7 +299,7 @@ where /// /// // Create signature /// let secp = Secp256k1::with_caps(ContextFlag::Commit); -/// let keychain = ExtKeychain::from_random_seed().unwrap(); +/// let keychain = ExtKeychain::from_random_seed(false).unwrap(); /// let fees = 10_000; /// let value = reward(fees); /// let key_id = ExtKeychain::derive_key_id(1, 1, 0, 0, 0); diff --git a/core/src/libtx/build.rs b/core/src/libtx/build.rs index f502f4d862..6b59be3a25 100644 --- a/core/src/libtx/build.rs +++ b/core/src/libtx/build.rs @@ -54,7 +54,11 @@ where move |build, (tx, kern, sum)| -> (Transaction, TxKernel, BlindSum) { let commit = build.keychain.commit(value, &key_id).unwrap(); let input = Input::new(features, commit); - (tx.with_input(input), kern, sum.sub_key_id(key_id.to_value_path(value))) + ( + tx.with_input(input), + kern, + sum.sub_key_id(key_id.to_value_path(value)), + ) }, ) } @@ -261,7 +265,7 @@ mod test { #[test] fn blind_simple_tx() { - let keychain = ExtKeychain::from_random_seed().unwrap(); + let keychain = ExtKeychain::from_random_seed(false).unwrap(); let key_id1 = ExtKeychainPath::new(1, 1, 0, 0, 0).to_identifier(); let key_id2 = ExtKeychainPath::new(1, 2, 0, 0, 0).to_identifier(); let key_id3 = ExtKeychainPath::new(1, 3, 0, 0, 0).to_identifier(); @@ -284,7 +288,7 @@ mod test { #[test] fn blind_simple_tx_with_offset() { - let keychain = ExtKeychain::from_random_seed().unwrap(); + let keychain = ExtKeychain::from_random_seed(false).unwrap(); let key_id1 = ExtKeychainPath::new(1, 1, 0, 0, 0).to_identifier(); let key_id2 = ExtKeychainPath::new(1, 2, 0, 0, 0).to_identifier(); let key_id3 = ExtKeychainPath::new(1, 3, 0, 0, 0).to_identifier(); @@ -307,7 +311,7 @@ mod test { #[test] fn blind_simpler_tx() { - let keychain = ExtKeychain::from_random_seed().unwrap(); + let keychain = ExtKeychain::from_random_seed(false).unwrap(); let key_id1 = ExtKeychainPath::new(1, 1, 0, 0, 0).to_identifier(); let key_id2 = ExtKeychainPath::new(1, 2, 0, 0, 0).to_identifier(); diff --git a/core/src/libtx/slate.rs b/core/src/libtx/slate.rs index 693ac9a99e..bbd028f6ea 100644 --- a/core/src/libtx/slate.rs +++ b/core/src/libtx/slate.rs @@ -260,7 +260,7 @@ impl Slate { if let Some(m) = message.clone() { let hashed = blake2b(secp::constants::MESSAGE_SIZE, &[], &m.as_bytes()[..]); let m = secp::Message::from_slice(&hashed.as_bytes())?; - let res = aggsig::sign_single(&keychain.secp(), &m, &sec_key, None)?; + let res = aggsig::sign_single(&keychain.secp(), &m, &sec_key, Some(&pub_key))?; Some(res) } else { None @@ -360,7 +360,7 @@ impl Slate { &m, None, &p.public_blind_excess, - None, + Some(&p.public_blind_excess), false, ) { error!("verify_messages - participant message doesn't match signature. Message: \"{}\"", diff --git a/core/src/pow.rs b/core/src/pow.rs index 52136afbb8..90f228ee39 100644 --- a/core/src/pow.rs +++ b/core/src/pow.rs @@ -136,11 +136,12 @@ mod test { /// We'll be generating genesis blocks differently #[test] fn genesis_pow() { - global::set_mining_mode(ChainTypes::AutomatedTesting); + global::set_mining_mode(ChainTypes::UserTesting); let mut b = genesis::genesis_dev(); - b.header.pow.nonce = 485; + b.header.pow.nonce = 28106; b.header.pow.proof.edge_bits = global::min_edge_bits(); + println!("proof {}", global::proofsize()); pow_size( &mut b.header, Difficulty::min(), @@ -148,8 +149,13 @@ mod test { global::min_edge_bits(), ) .unwrap(); + println!("nonce {}", b.header.pow.nonce); assert_ne!(b.header.pow.nonce, 310); assert!(b.header.pow.to_difficulty(0) >= Difficulty::min()); - assert!(verify_size(&b.header).is_ok()); + let start = ::std::time::Instant::now(); + for n in 0..100000 { + assert!(verify_size(&b.header).is_ok()); + } + println!("==> {}", start.elapsed().as_secs()); } } diff --git a/core/tests/block.rs b/core/tests/block.rs index 908b94962f..8f813b4720 100644 --- a/core/tests/block.rs +++ b/core/tests/block.rs @@ -42,7 +42,7 @@ fn verifier_cache() -> Arc> { // TODO: make this fast enough or add similar but faster test? #[allow(dead_code)] fn too_large_block() { - let keychain = ExtKeychain::from_random_seed().unwrap(); + let keychain = ExtKeychain::from_random_seed(false).unwrap(); let max_out = MAX_BLOCK_WEIGHT / BLOCK_OUTPUT_WEIGHT; let mut pks = vec![]; @@ -83,7 +83,7 @@ fn very_empty_block() { #[test] // builds a block with a tx spending another and check that cut_through occurred fn block_with_cut_through() { - let keychain = ExtKeychain::from_random_seed().unwrap(); + let keychain = ExtKeychain::from_random_seed(false).unwrap(); let key_id1 = ExtKeychain::derive_key_id(1, 1, 0, 0, 0); let key_id2 = ExtKeychain::derive_key_id(1, 2, 0, 0, 0); let key_id3 = ExtKeychain::derive_key_id(1, 3, 0, 0, 0); @@ -119,7 +119,7 @@ fn block_with_cut_through() { #[test] fn empty_block_with_coinbase_is_valid() { - let keychain = ExtKeychain::from_random_seed().unwrap(); + let keychain = ExtKeychain::from_random_seed(false).unwrap(); let prev = BlockHeader::default(); let key_id = ExtKeychain::derive_key_id(1, 1, 0, 0, 0); let b = new_block(vec![], &keychain, &prev, &key_id); @@ -156,7 +156,7 @@ fn empty_block_with_coinbase_is_valid() { // invalidates the block and specifically it causes verify_coinbase to fail // additionally verifying the merkle_inputs_outputs also fails fn remove_coinbase_output_flag() { - let keychain = ExtKeychain::from_random_seed().unwrap(); + let keychain = ExtKeychain::from_random_seed(false).unwrap(); let prev = BlockHeader::default(); let key_id = ExtKeychain::derive_key_id(1, 1, 0, 0, 0); let mut b = new_block(vec![], &keychain, &prev, &key_id); @@ -178,7 +178,7 @@ fn remove_coinbase_output_flag() { // test that flipping the COINBASE flag on the kernel features // invalidates the block and specifically it causes verify_coinbase to fail fn remove_coinbase_kernel_flag() { - let keychain = ExtKeychain::from_random_seed().unwrap(); + let keychain = ExtKeychain::from_random_seed(false).unwrap(); let prev = BlockHeader::default(); let key_id = ExtKeychain::derive_key_id(1, 1, 0, 0, 0); let mut b = new_block(vec![], &keychain, &prev, &key_id); @@ -202,7 +202,7 @@ fn remove_coinbase_kernel_flag() { #[test] fn serialize_deserialize_block_header() { - let keychain = ExtKeychain::from_random_seed().unwrap(); + let keychain = ExtKeychain::from_random_seed(false).unwrap(); let prev = BlockHeader::default(); let key_id = ExtKeychain::derive_key_id(1, 1, 0, 0, 0); let b = new_block(vec![], &keychain, &prev, &key_id); @@ -219,7 +219,7 @@ fn serialize_deserialize_block_header() { #[test] fn serialize_deserialize_block() { let tx1 = tx1i2o(); - let keychain = ExtKeychain::from_random_seed().unwrap(); + let keychain = ExtKeychain::from_random_seed(false).unwrap(); let prev = BlockHeader::default(); let key_id = ExtKeychain::derive_key_id(1, 1, 0, 0, 0); let b = new_block(vec![&tx1], &keychain, &prev, &key_id); @@ -237,7 +237,7 @@ fn serialize_deserialize_block() { #[test] fn empty_block_serialized_size() { - let keychain = ExtKeychain::from_random_seed().unwrap(); + let keychain = ExtKeychain::from_random_seed(false).unwrap(); let prev = BlockHeader::default(); let key_id = ExtKeychain::derive_key_id(1, 1, 0, 0, 0); let b = new_block(vec![], &keychain, &prev, &key_id); @@ -249,7 +249,7 @@ fn empty_block_serialized_size() { #[test] fn block_single_tx_serialized_size() { - let keychain = ExtKeychain::from_random_seed().unwrap(); + let keychain = ExtKeychain::from_random_seed(false).unwrap(); let tx1 = tx1i2o(); let prev = BlockHeader::default(); let key_id = ExtKeychain::derive_key_id(1, 1, 0, 0, 0); @@ -262,7 +262,7 @@ fn block_single_tx_serialized_size() { #[test] fn empty_compact_block_serialized_size() { - let keychain = ExtKeychain::from_random_seed().unwrap(); + let keychain = ExtKeychain::from_random_seed(false).unwrap(); let prev = BlockHeader::default(); let key_id = ExtKeychain::derive_key_id(1, 1, 0, 0, 0); let b = new_block(vec![], &keychain, &prev, &key_id); @@ -275,7 +275,7 @@ fn empty_compact_block_serialized_size() { #[test] fn compact_block_single_tx_serialized_size() { - let keychain = ExtKeychain::from_random_seed().unwrap(); + let keychain = ExtKeychain::from_random_seed(false).unwrap(); let tx1 = tx1i2o(); let prev = BlockHeader::default(); let key_id = ExtKeychain::derive_key_id(1, 1, 0, 0, 0); @@ -289,7 +289,7 @@ fn compact_block_single_tx_serialized_size() { #[test] fn block_10_tx_serialized_size() { - let keychain = ExtKeychain::from_random_seed().unwrap(); + let keychain = ExtKeychain::from_random_seed(false).unwrap(); global::set_mining_mode(global::ChainTypes::Mainnet); let mut txs = vec![]; @@ -308,7 +308,7 @@ fn block_10_tx_serialized_size() { #[test] fn compact_block_10_tx_serialized_size() { - let keychain = ExtKeychain::from_random_seed().unwrap(); + let keychain = ExtKeychain::from_random_seed(false).unwrap(); let mut txs = vec![]; for _ in 0..10 { @@ -327,7 +327,7 @@ fn compact_block_10_tx_serialized_size() { #[test] fn compact_block_hash_with_nonce() { - let keychain = ExtKeychain::from_random_seed().unwrap(); + let keychain = ExtKeychain::from_random_seed(false).unwrap(); let tx = tx1i2o(); let prev = BlockHeader::default(); let key_id = ExtKeychain::derive_key_id(1, 1, 0, 0, 0); @@ -357,7 +357,7 @@ fn compact_block_hash_with_nonce() { #[test] fn convert_block_to_compact_block() { - let keychain = ExtKeychain::from_random_seed().unwrap(); + let keychain = ExtKeychain::from_random_seed(false).unwrap(); let tx1 = tx1i2o(); let prev = BlockHeader::default(); let key_id = ExtKeychain::derive_key_id(1, 1, 0, 0, 0); @@ -380,7 +380,7 @@ fn convert_block_to_compact_block() { #[test] fn hydrate_empty_compact_block() { - let keychain = ExtKeychain::from_random_seed().unwrap(); + let keychain = ExtKeychain::from_random_seed(false).unwrap(); let prev = BlockHeader::default(); let key_id = ExtKeychain::derive_key_id(1, 1, 0, 0, 0); let b = new_block(vec![], &keychain, &prev, &key_id); @@ -393,7 +393,7 @@ fn hydrate_empty_compact_block() { #[test] fn serialize_deserialize_compact_block() { - let keychain = ExtKeychain::from_random_seed().unwrap(); + let keychain = ExtKeychain::from_random_seed(false).unwrap(); let tx1 = tx1i2o(); let prev = BlockHeader::default(); let key_id = ExtKeychain::derive_key_id(1, 1, 0, 0, 0); diff --git a/core/tests/common.rs b/core/tests/common.rs index 0ef7494cd9..184c0b0c95 100644 --- a/core/tests/common.rs +++ b/core/tests/common.rs @@ -29,7 +29,7 @@ use grin_keychain as keychain; // utility producing a transaction with 2 inputs and a single outputs pub fn tx2i1o() -> Transaction { - let keychain = keychain::ExtKeychain::from_random_seed().unwrap(); + let keychain = keychain::ExtKeychain::from_random_seed(false).unwrap(); let key_id1 = keychain::ExtKeychain::derive_key_id(1, 1, 0, 0, 0); let key_id2 = keychain::ExtKeychain::derive_key_id(1, 2, 0, 0, 0); let key_id3 = keychain::ExtKeychain::derive_key_id(1, 3, 0, 0, 0); @@ -48,7 +48,7 @@ pub fn tx2i1o() -> Transaction { // utility producing a transaction with a single input and output pub fn tx1i1o() -> Transaction { - let keychain = keychain::ExtKeychain::from_random_seed().unwrap(); + let keychain = keychain::ExtKeychain::from_random_seed(false).unwrap(); let key_id1 = keychain::ExtKeychain::derive_key_id(1, 1, 0, 0, 0); let key_id2 = keychain::ExtKeychain::derive_key_id(1, 2, 0, 0, 0); @@ -63,7 +63,7 @@ pub fn tx1i1o() -> Transaction { // and two outputs (one change output) // Note: this tx has an "offset" kernel pub fn tx1i2o() -> Transaction { - let keychain = keychain::ExtKeychain::from_random_seed().unwrap(); + let keychain = keychain::ExtKeychain::from_random_seed(false).unwrap(); let key_id1 = keychain::ExtKeychain::derive_key_id(1, 1, 0, 0, 0); let key_id2 = keychain::ExtKeychain::derive_key_id(1, 2, 0, 0, 0); let key_id3 = keychain::ExtKeychain::derive_key_id(1, 3, 0, 0, 0); diff --git a/core/tests/consensus.rs b/core/tests/consensus.rs index 2cb6d2dd86..44407bc396 100644 --- a/core/tests/consensus.rs +++ b/core/tests/consensus.rs @@ -454,7 +454,7 @@ fn test_secondary_pow_ratio() { // Tests for mainnet chain type. { global::set_mining_mode(global::ChainTypes::Mainnet); - assert_eq!(global::is_testnet(), false); + assert_eq!(global::is_floonet(), false); assert_eq!(secondary_pow_ratio(1), 90); assert_eq!(secondary_pow_ratio(89), 90); @@ -496,7 +496,7 @@ fn test_secondary_pow_ratio() { // Tests for testnet4 chain type (covers pre and post hardfork). { global::set_mining_mode(global::ChainTypes::Floonet); - assert_eq!(global::is_testnet(), true); + assert_eq!(global::is_floonet(), true); assert_eq!(secondary_pow_ratio(1), 90); assert_eq!(secondary_pow_ratio(89), 90); @@ -544,7 +544,7 @@ fn test_secondary_pow_scale() { // mainnet testing { global::set_mining_mode(global::ChainTypes::Mainnet); - assert_eq!(global::is_mainnet(), true); + assert_eq!(global::is_floonet(), false); // all primary, factor should increase so it becomes easier to find a high // difficulty block diff --git a/core/tests/core.rs b/core/tests/core.rs index 56940a7dcc..8c6641ad95 100644 --- a/core/tests/core.rs +++ b/core/tests/core.rs @@ -75,7 +75,7 @@ fn tx_double_ser_deser() { #[test] #[should_panic(expected = "Keychain Error")] fn test_zero_commit_fails() { - let mut keychain = ExtKeychain::from_random_seed().unwrap(); + let mut keychain = ExtKeychain::from_random_seed(false).unwrap(); keychain.set_use_switch_commits(false); let key_id1 = ExtKeychain::derive_key_id(1, 1, 0, 0, 0); @@ -97,7 +97,7 @@ fn verifier_cache() -> Arc> { #[test] fn build_tx_kernel() { - let keychain = ExtKeychain::from_random_seed().unwrap(); + let keychain = ExtKeychain::from_random_seed(false).unwrap(); let key_id1 = ExtKeychain::derive_key_id(1, 1, 0, 0, 0); let key_id2 = ExtKeychain::derive_key_id(1, 2, 0, 0, 0); let key_id3 = ExtKeychain::derive_key_id(1, 3, 0, 0, 0); @@ -322,7 +322,7 @@ fn basic_transaction_deaggregation() { #[test] fn hash_output() { - let keychain = ExtKeychain::from_random_seed().unwrap(); + let keychain = ExtKeychain::from_random_seed(false).unwrap(); let key_id1 = ExtKeychain::derive_key_id(1, 1, 0, 0, 0); let key_id2 = ExtKeychain::derive_key_id(1, 2, 0, 0, 0); let key_id3 = ExtKeychain::derive_key_id(1, 3, 0, 0, 0); @@ -377,7 +377,7 @@ fn tx_hash_diff() { /// 2 inputs, 2 outputs transaction. #[test] fn tx_build_exchange() { - let keychain = ExtKeychain::from_random_seed().unwrap(); + let keychain = ExtKeychain::from_random_seed(false).unwrap(); let key_id1 = ExtKeychain::derive_key_id(1, 1, 0, 0, 0); let key_id2 = ExtKeychain::derive_key_id(1, 2, 0, 0, 0); let key_id3 = ExtKeychain::derive_key_id(1, 3, 0, 0, 0); @@ -415,7 +415,7 @@ fn tx_build_exchange() { #[test] fn reward_empty_block() { - let keychain = keychain::ExtKeychain::from_random_seed().unwrap(); + let keychain = keychain::ExtKeychain::from_random_seed(false).unwrap(); let key_id = ExtKeychain::derive_key_id(1, 1, 0, 0, 0); let previous_header = BlockHeader::default(); @@ -430,7 +430,7 @@ fn reward_empty_block() { #[test] fn reward_with_tx_block() { - let keychain = keychain::ExtKeychain::from_random_seed().unwrap(); + let keychain = keychain::ExtKeychain::from_random_seed(false).unwrap(); let key_id = ExtKeychain::derive_key_id(1, 1, 0, 0, 0); let vc = verifier_cache(); @@ -450,7 +450,7 @@ fn reward_with_tx_block() { #[test] fn simple_block() { - let keychain = keychain::ExtKeychain::from_random_seed().unwrap(); + let keychain = keychain::ExtKeychain::from_random_seed(false).unwrap(); let key_id = ExtKeychain::derive_key_id(1, 1, 0, 0, 0); let vc = verifier_cache(); @@ -471,7 +471,7 @@ fn simple_block() { #[test] fn test_block_with_timelocked_tx() { - let keychain = keychain::ExtKeychain::from_random_seed().unwrap(); + let keychain = keychain::ExtKeychain::from_random_seed(false).unwrap(); let key_id1 = ExtKeychain::derive_key_id(1, 1, 0, 0, 0); let key_id2 = ExtKeychain::derive_key_id(1, 2, 0, 0, 0); diff --git a/core/tests/transaction.rs b/core/tests/transaction.rs index fc89f97744..285913dd28 100644 --- a/core/tests/transaction.rs +++ b/core/tests/transaction.rs @@ -25,7 +25,7 @@ use grin_keychain as keychain; #[test] fn test_output_ser_deser() { - let keychain = ExtKeychain::from_random_seed().unwrap(); + let keychain = ExtKeychain::from_random_seed(false).unwrap(); let key_id = ExtKeychain::derive_key_id(1, 1, 0, 0, 0); let commit = keychain.commit(5, &key_id).unwrap(); let proof = proof::create(&keychain, 5, &key_id, commit, None).unwrap(); diff --git a/core/tests/verifier_cache.rs b/core/tests/verifier_cache.rs index 6a0b00857e..de59b6aa0b 100644 --- a/core/tests/verifier_cache.rs +++ b/core/tests/verifier_cache.rs @@ -32,7 +32,7 @@ fn verifier_cache() -> Arc> { fn test_verifier_cache_rangeproofs() { let cache = verifier_cache(); - let keychain = ExtKeychain::from_random_seed().unwrap(); + let keychain = ExtKeychain::from_random_seed(false).unwrap(); let key_id = ExtKeychain::derive_key_id(1, 1, 0, 0, 0); let commit = keychain.commit(5, &key_id).unwrap(); let proof = proof::create(&keychain, 5, &key_id, commit, None).unwrap(); diff --git a/etc/gen_gen/Cargo.toml b/etc/gen_gen/Cargo.toml index ae0c73829c..818d30600c 100644 --- a/etc/gen_gen/Cargo.toml +++ b/etc/gen_gen/Cargo.toml @@ -15,12 +15,12 @@ path = "src/bin/gen_gen.rs" [dependencies] chrono = "0.4.4" -cuckoo_miner = "0.4.2" +cuckoo_miner = "0.5.0" curl = "0.4.19" grin_core = { path = "../../core" } grin_chain = { path = "../../chain" } grin_keychain = { path = "../../keychain" } -grin_miner_plugin = "0.4.2" +grin_miner_plugin = "0.5.0" grin_store = { path = "../../store" } grin_util = { path = "../../util" } grin_wallet = { path = "../../wallet" } diff --git a/etc/gen_gen/src/bin/gen_gen.rs b/etc/gen_gen/src/bin/gen_gen.rs index 1f636d7062..829ba42346 100644 --- a/etc/gen_gen/src/bin/gen_gen.rs +++ b/etc/gen_gen/src/bin/gen_gen.rs @@ -85,21 +85,21 @@ fn main() { &rpassword::prompt_password_stdout("Password: ").unwrap(), ) .unwrap(); - let keychain: ExtKeychain = seed.derive_keychain().unwrap(); - let key_id = ExtKeychain::derive_key_id(2, 1, 0, 0, 0); + let keychain: ExtKeychain = seed.derive_keychain(false).unwrap(); + let key_id = ExtKeychain::derive_key_id(3, 1, 0, 0, 0); let reward = core::libtx::reward::output(&keychain, &key_id, 0).unwrap(); gen = gen.with_reward(reward.0, reward.1); { // setup a tmp chain to set block header roots - core::global::set_mining_mode(core::global::ChainTypes::AutomatedTesting); + core::global::set_mining_mode(core::global::ChainTypes::UserTesting); let tmp_chain = setup_chain(".grin.tmp", core::pow::mine_genesis_block().unwrap()); tmp_chain.set_txhashset_roots(&mut gen).unwrap(); } // sets the timestamp and prev_root from the bitcoin block (needs to be // after set_txhashset roots to not get overwritten) - gen.header.timestamp = Utc::now() + Duration::minutes(30); + gen.header.timestamp = Utc::now() + Duration::minutes(45); gen.header.prev_root = core::core::hash::Hash::from_hex(&h1).unwrap(); // mine a Cuckaroo29 block diff --git a/keychain/Cargo.toml b/keychain/Cargo.toml index 8789e52327..4d7d1b4208 100644 --- a/keychain/Cargo.toml +++ b/keychain/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "grin_keychain" -version = "0.4.2" +version = "0.5.0" authors = ["Grin Developers "] description = "Chain implementation for grin, a simple, private and scalable cryptocurrency implementation based on the MimbleWimble chain format." license = "Apache-2.0" @@ -27,4 +27,4 @@ sha2 = "0.7" pbkdf2 = "0.2" -grin_util = { path = "../util", version = "0.4.2" } +grin_util = { path = "../util", version = "0.5.0" } diff --git a/keychain/src/extkey_bip32.rs b/keychain/src/extkey_bip32.rs index 70005a3575..392410cb86 100644 --- a/keychain/src/extkey_bip32.rs +++ b/keychain/src/extkey_bip32.rs @@ -78,8 +78,8 @@ impl Default for Fingerprint { /// not what the actual implementation is pub trait BIP32Hasher { - fn network_priv() -> [u8; 4]; - fn network_pub() -> [u8; 4]; + fn network_priv(&self) -> [u8; 4]; + fn network_pub(&self) -> [u8; 4]; fn master_seed() -> [u8; 12]; fn init_sha512(&mut self, seed: &[u8]); fn append_sha512(&mut self, value: &[u8]); @@ -89,27 +89,34 @@ pub trait BIP32Hasher { } /// Implementation of the above that uses the standard BIP32 Hash algorithms +#[derive(Clone, Debug)] pub struct BIP32GrinHasher { + is_floo: bool, hmac_sha512: Hmac, } impl BIP32GrinHasher { /// New empty hasher - pub fn new() -> BIP32GrinHasher { + pub fn new(is_floo: bool) -> BIP32GrinHasher { BIP32GrinHasher { + is_floo: is_floo, hmac_sha512: HmacSha512::new(GenericArray::from_slice(&[0u8; 128])), } } } impl BIP32Hasher for BIP32GrinHasher { - fn network_priv() -> [u8; 4] { - // gprv - [0x03, 0x3C, 0x04, 0xA4] + fn network_priv(&self) -> [u8; 4] { + match self.is_floo { + true => [0x03, 0x27, 0x3A, 0x10], // fprv + false => [0x03, 0x3C, 0x04, 0xA4], // gprv + } } - fn network_pub() -> [u8; 4] { - // gpub - [0x03, 0x3C, 0x08, 0xDF] + fn network_pub(&self) -> [u8; 4] { + match self.is_floo { + true => [0x03, 0x27, 0x3E, 0x4B], // fpub + false => [0x03, 0x3C, 0x08, 0xDF], // gpub + } } fn master_seed() -> [u8; 12] { b"IamVoldemort".to_owned() @@ -357,7 +364,7 @@ impl ExtendedPrivKey { let result = hasher.result_sha512(); Ok(ExtendedPrivKey { - network: H::network_priv(), + network: hasher.network_priv(), depth: 0, parent_fingerprint: Default::default(), child_number: ChildNumber::from_normal_idx(0), @@ -371,12 +378,13 @@ impl ExtendedPrivKey { secp: &Secp256k1, mnemonic: &str, passphrase: &str, + is_floo: bool, ) -> Result { let seed = match mnemonic::to_seed(mnemonic, passphrase) { Ok(s) => s, Err(e) => return Err(Error::MnemonicError(e)), }; - let mut hasher = BIP32GrinHasher::new(); + let mut hasher = BIP32GrinHasher::new(is_floo); let key = r#try!(ExtendedPrivKey::new_master(secp, &mut hasher, &seed)); Ok(key) } @@ -449,7 +457,7 @@ impl ExtendedPrivKey { { let secp = Secp256k1::with_caps(ContextFlag::SignOnly); // Compute extended public key - let pk: ExtendedPubKey = ExtendedPubKey::from_private::(&secp, self); + let pk: ExtendedPubKey = ExtendedPubKey::from_private::(&secp, self, hasher); // Do SHA256 of just the ECDSA pubkey let sha2_res = hasher.sha_256(&pk.public_key.serialize_vec(&secp, true)[..]); // do RIPEMD160 @@ -469,12 +477,12 @@ impl ExtendedPrivKey { impl ExtendedPubKey { /// Derives a public key from a private key - pub fn from_private(secp: &Secp256k1, sk: &ExtendedPrivKey) -> ExtendedPubKey + pub fn from_private(secp: &Secp256k1, sk: &ExtendedPrivKey, hasher: &mut H) -> ExtendedPubKey where H: BIP32Hasher, { ExtendedPubKey { - network: H::network_pub(), + network: hasher.network_pub(), depth: sk.depth, parent_fingerprint: sk.parent_fingerprint, child_number: sk.child_number, @@ -696,11 +704,11 @@ mod tests { } impl BIP32Hasher for BIP32ReferenceHasher { - fn network_priv() -> [u8; 4] { + fn network_priv(&self) -> [u8; 4] { // bitcoin network (xprv) (for test vectors) [0x04, 0x88, 0xAD, 0xE4] } - fn network_pub() -> [u8; 4] { + fn network_pub(&self) -> [u8; 4] { // bitcoin network (xpub) (for test vectors) [0x04, 0x88, 0xB2, 0x1E] } @@ -743,7 +751,7 @@ mod tests { ) { let mut h = BIP32ReferenceHasher::new(); let mut sk = ExtendedPrivKey::new_master(secp, &mut h, seed).unwrap(); - let mut pk = ExtendedPubKey::from_private::(secp, &sk); + let mut pk = ExtendedPubKey::from_private::(secp, &sk, &mut h); // Check derivation convenience method for ExtendedPrivKey assert_eq!( @@ -771,7 +779,7 @@ mod tests { match num { ChildNumber::Normal { .. } => { let pk2 = pk.ckd_pub(secp, &mut h, num).unwrap(); - pk = ExtendedPubKey::from_private::(secp, &sk); + pk = ExtendedPubKey::from_private::(secp, &sk, &mut h); assert_eq!(pk, pk2); } ChildNumber::Hardened { .. } => { @@ -779,7 +787,7 @@ mod tests { pk.ckd_pub(secp, &mut h, num), Err(Error::CannotDeriveFromHardenedKey) ); - pk = ExtendedPubKey::from_private::(secp, &sk); + pk = ExtendedPubKey::from_private::(secp, &sk, &mut h); } } } diff --git a/keychain/src/keychain.rs b/keychain/src/keychain.rs index cb10895cf7..31a5db408d 100644 --- a/keychain/src/keychain.rs +++ b/keychain/src/keychain.rs @@ -30,37 +30,41 @@ pub struct ExtKeychain { secp: Secp256k1, master: ExtendedPrivKey, use_switch_commits: bool, + hasher: BIP32GrinHasher, } impl Keychain for ExtKeychain { - fn from_seed(seed: &[u8]) -> Result { - let mut h = BIP32GrinHasher::new(); + fn from_seed(seed: &[u8], is_floo: bool) -> Result { + let mut h = BIP32GrinHasher::new(is_floo); let secp = secp::Secp256k1::with_caps(secp::ContextFlag::Commit); let master = ExtendedPrivKey::new_master(&secp, &mut h, seed)?; let keychain = ExtKeychain { secp: secp, master: master, use_switch_commits: true, + hasher: h, }; Ok(keychain) } - fn from_mnemonic(word_list: &str, extension_word: &str) -> Result { + fn from_mnemonic(word_list: &str, extension_word: &str, is_floo: bool) -> Result { let secp = secp::Secp256k1::with_caps(secp::ContextFlag::Commit); - let master = ExtendedPrivKey::from_mnemonic(&secp, word_list, extension_word)?; + let h = BIP32GrinHasher::new(is_floo); + let master = ExtendedPrivKey::from_mnemonic(&secp, word_list, extension_word, is_floo)?; let keychain = ExtKeychain { secp: secp, master: master, use_switch_commits: true, + hasher: h, }; Ok(keychain) } /// For testing - probably not a good idea to use outside of tests. - fn from_random_seed() -> Result { + fn from_random_seed(is_floo: bool) -> Result { let seed: String = thread_rng().sample_iter(&Alphanumeric).take(16).collect(); let seed = blake2::blake2b::blake2b(32, &[], seed.as_bytes()); - ExtKeychain::from_seed(seed.as_bytes()) + ExtKeychain::from_seed(seed.as_bytes(), is_floo) } fn root_key_id() -> Identifier { @@ -72,7 +76,7 @@ impl Keychain for ExtKeychain { } fn derive_key(&self, amount: u64, id: &Identifier) -> Result { - let mut h = BIP32GrinHasher::new(); + let mut h = self.hasher.clone(); let p = id.to_path(); let mut ext_key = self.master; for i in 0..p.depth { @@ -172,7 +176,7 @@ mod test { #[test] fn test_key_derivation() { - let keychain = ExtKeychain::from_random_seed().unwrap(); + let keychain = ExtKeychain::from_random_seed(false).unwrap(); let secp = keychain.secp(); let path = ExtKeychainPath::new(1, 1, 0, 0, 0); @@ -196,7 +200,7 @@ mod test { // and summing the keys used to commit to 0 have the same result. #[test] fn secret_key_addition() { - let keychain = ExtKeychain::from_random_seed().unwrap(); + let keychain = ExtKeychain::from_random_seed(false).unwrap(); let skey1 = SecretKey::from_slice( &keychain.secp, diff --git a/keychain/src/types.rs b/keychain/src/types.rs index 5ba9d455b8..66e5ba95fd 100644 --- a/keychain/src/types.rs +++ b/keychain/src/types.rs @@ -451,13 +451,13 @@ pub struct ValueExtKeychainPath { pub trait Keychain: Sync + Send + Clone { /// Generates a keychain from a raw binary seed (which has already been /// decrypted if applicable). - fn from_seed(seed: &[u8]) -> Result; + fn from_seed(seed: &[u8], is_floo: bool) -> Result; /// Generates a keychain from a list of space-separated mnemonic words - fn from_mnemonic(word_list: &str, extension_word: &str) -> Result; + fn from_mnemonic(word_list: &str, extension_word: &str, is_floo: bool) -> Result; /// Generates a keychain from a randomly generated seed. Mostly used for tests. - fn from_random_seed() -> Result; + fn from_random_seed(is_floo: bool) -> Result; /// Root identifier for that keychain fn root_key_id() -> Identifier; diff --git a/p2p/Cargo.toml b/p2p/Cargo.toml index 82d1385023..d5ef7e9f6e 100644 --- a/p2p/Cargo.toml +++ b/p2p/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "grin_p2p" -version = "0.4.2" +version = "0.5.0" authors = ["Grin Developers "] description = "Chain implementation for grin, a simple, private and scalable cryptocurrency implementation based on the MimbleWimble chain format." license = "Apache-2.0" @@ -22,9 +22,9 @@ serde_derive = "1" log = "0.4" chrono = { version = "0.4.4", features = ["serde"] } -grin_core = { path = "../core", version = "0.4.2" } -grin_store = { path = "../store", version = "0.4.2" } -grin_util = { path = "../util", version = "0.4.2" } +grin_core = { path = "../core", version = "0.5.0" } +grin_store = { path = "../store", version = "0.5.0" } +grin_util = { path = "../util", version = "0.5.0" } [dev-dependencies] -grin_pool = { path = "../pool", version = "0.4.2" } +grin_pool = { path = "../pool", version = "0.5.0" } diff --git a/p2p/src/msg.rs b/p2p/src/msg.rs index f347cbed70..0eaccc1948 100644 --- a/p2p/src/msg.rs +++ b/p2p/src/msg.rs @@ -19,11 +19,11 @@ use std::io::{Read, Write}; use std::net::{Ipv4Addr, Ipv6Addr, SocketAddr, SocketAddrV4, SocketAddrV6}; use std::time; -use crate::core::consensus; use crate::core::core::hash::Hash; use crate::core::core::BlockHeader; use crate::core::pow::Difficulty; use crate::core::ser::{self, FixedLength, Readable, Reader, StreamingReader, Writeable, Writer}; +use crate::core::{consensus, global}; use crate::types::{ Capabilities, Error, ReasonForBan, MAX_BLOCK_HEADERS, MAX_LOCATORS, MAX_PEER_ADDRS, }; @@ -35,8 +35,10 @@ pub const PROTOCOL_VERSION: u32 = 1; /// Grin's user agent with current version pub const USER_AGENT: &'static str = concat!("MW/Grin ", env!("CARGO_PKG_VERSION")); -/// Magic number expected in the header of every message -const MAGIC: [u8; 2] = [0x53, 0x35]; +/// Magic numbers expected in the header of every message +const OTHER_MAGIC: [u8; 2] = [73, 43]; +const FLOONET_MAGIC: [u8; 2] = [83, 59]; +const MAINNET_MAGIC: [u8; 2] = [97, 61]; /// Max theoretical size of a block filled with outputs. const MAX_BLOCK_SIZE: u64 = @@ -99,6 +101,14 @@ fn max_msg_size(msg_type: Type) -> u64 { } } +fn magic() -> [u8; 2] { + match *global::CHAIN_TYPE.read() { + global::ChainTypes::Floonet => FLOONET_MAGIC, + global::ChainTypes::Mainnet => MAINNET_MAGIC, + _ => OTHER_MAGIC, + } +} + /// Read a header from the provided stream without blocking if the /// underlying stream is async. Typically headers will be polled for, so /// we do not want to block. @@ -187,7 +197,7 @@ impl MsgHeader { /// Creates a new message header. pub fn new(msg_type: Type, len: u64) -> MsgHeader { MsgHeader { - magic: MAGIC, + magic: magic(), msg_type: msg_type, msg_len: len, } @@ -213,12 +223,13 @@ impl Writeable for MsgHeader { impl Readable for MsgHeader { fn read(reader: &mut dyn Reader) -> Result { - reader.expect_u8(MAGIC[0])?; - reader.expect_u8(MAGIC[1])?; + let m = magic(); + reader.expect_u8(m[0])?; + reader.expect_u8(m[1])?; let (t, len) = ser_multiread!(reader, read_u8, read_u64); match Type::from_u8(t) { Some(ty) => Ok(MsgHeader { - magic: MAGIC, + magic: m, msg_type: ty, msg_len: len, }), diff --git a/p2p/src/types.rs b/p2p/src/types.rs index d25b9d86a4..c9cbc26904 100644 --- a/p2p/src/types.rs +++ b/p2p/src/types.rs @@ -132,7 +132,7 @@ impl Default for P2PConfig { let ipaddr = "0.0.0.0".parse().unwrap(); P2PConfig { host: ipaddr, - port: 13414, + port: 3414, capabilities: Capabilities::FULL_NODE, seeding_type: Seeding::default(), seeds: None, diff --git a/pool/Cargo.toml b/pool/Cargo.toml index 083ead1d4d..25c7a4488c 100644 --- a/pool/Cargo.toml +++ b/pool/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "grin_pool" -version = "0.4.2" +version = "0.5.0" authors = ["Grin Developers "] description = "Chain implementation for grin, a simple, private and scalable cryptocurrency implementation based on the MimbleWimble chain format." license = "Apache-2.0" @@ -17,10 +17,10 @@ serde_derive = "1" log = "0.4" chrono = "0.4.4" -grin_core = { path = "../core", version = "0.4.2" } -grin_keychain = { path = "../keychain", version = "0.4.2" } -grin_store = { path = "../store", version = "0.4.2" } -grin_util = { path = "../util", version = "0.4.2" } +grin_core = { path = "../core", version = "0.5.0" } +grin_keychain = { path = "../keychain", version = "0.5.0" } +grin_store = { path = "../store", version = "0.5.0" } +grin_util = { path = "../util", version = "0.5.0" } [dev-dependencies] -grin_chain = { path = "../chain", version = "0.4.2" } +grin_chain = { path = "../chain", version = "0.5.0" } diff --git a/pool/tests/block_building.rs b/pool/tests/block_building.rs index 29dd0ba396..3e3a8d6dd9 100644 --- a/pool/tests/block_building.rs +++ b/pool/tests/block_building.rs @@ -30,7 +30,7 @@ use std::sync::Arc; #[test] fn test_transaction_pool_block_building() { util::init_test_logger(); - let keychain: ExtKeychain = Keychain::from_random_seed().unwrap(); + let keychain: ExtKeychain = Keychain::from_random_seed(false).unwrap(); let db_root = ".grin_block_building".to_string(); clean_output_dir(db_root.clone()); diff --git a/pool/tests/block_reconciliation.rs b/pool/tests/block_reconciliation.rs index 6404cddd0c..08c3fb1729 100644 --- a/pool/tests/block_reconciliation.rs +++ b/pool/tests/block_reconciliation.rs @@ -30,7 +30,7 @@ use std::sync::Arc; #[test] fn test_transaction_pool_block_reconciliation() { - let keychain: ExtKeychain = Keychain::from_random_seed().unwrap(); + let keychain: ExtKeychain = Keychain::from_random_seed(false).unwrap(); let db_root = ".grin_block_reconciliation".to_string(); clean_output_dir(db_root.clone()); diff --git a/pool/tests/coinbase_maturity.rs b/pool/tests/coinbase_maturity.rs index 50c055c2a1..27ebaae1b1 100644 --- a/pool/tests/coinbase_maturity.rs +++ b/pool/tests/coinbase_maturity.rs @@ -67,7 +67,7 @@ impl BlockChain for CoinbaseMaturityErrorChainAdapter { /// Test we correctly verify coinbase maturity when adding txs to the pool. #[test] fn test_coinbase_maturity() { - let keychain: ExtKeychain = Keychain::from_random_seed().unwrap(); + let keychain: ExtKeychain = Keychain::from_random_seed(false).unwrap(); // Mocking this up with an adapter that will raise an error for coinbase // maturity. diff --git a/pool/tests/transaction_pool.rs b/pool/tests/transaction_pool.rs index 1cf7261085..c8d18ecd9b 100644 --- a/pool/tests/transaction_pool.rs +++ b/pool/tests/transaction_pool.rs @@ -29,7 +29,7 @@ use std::sync::Arc; /// Test we can add some txs to the pool (both stempool and txpool). #[test] fn test_the_transaction_pool() { - let keychain: ExtKeychain = Keychain::from_random_seed().unwrap(); + let keychain: ExtKeychain = Keychain::from_random_seed(false).unwrap(); let db_root = ".grin_transaction_pool".to_string(); clean_output_dir(db_root.clone()); diff --git a/servers/Cargo.toml b/servers/Cargo.toml index e2ef6a4879..90c8b911f7 100644 --- a/servers/Cargo.toml +++ b/servers/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "grin_servers" -version = "0.4.2" +version = "0.5.0" authors = ["Grin Developers "] description = "Simple, private and scalable cryptocurrency implementation based on the MimbleWimble chain format." license = "Apache-2.0" @@ -25,15 +25,15 @@ chrono = "0.4.4" bufstream = "~0.1" jsonrpc-core = "~8.0" -grin_api = { path = "../api", version = "0.4.2" } -grin_chain = { path = "../chain", version = "0.4.2" } -grin_core = { path = "../core", version = "0.4.2" } -grin_keychain = { path = "../keychain", version = "0.4.2" } -grin_p2p = { path = "../p2p", version = "0.4.2" } -grin_pool = { path = "../pool", version = "0.4.2" } -grin_store = { path = "../store", version = "0.4.2" } -grin_util = { path = "../util", version = "0.4.2" } -grin_wallet = { path = "../wallet", version = "0.4.2" } +grin_api = { path = "../api", version = "0.5.0" } +grin_chain = { path = "../chain", version = "0.5.0" } +grin_core = { path = "../core", version = "0.5.0" } +grin_keychain = { path = "../keychain", version = "0.5.0" } +grin_p2p = { path = "../p2p", version = "0.5.0" } +grin_pool = { path = "../pool", version = "0.5.0" } +grin_store = { path = "../store", version = "0.5.0" } +grin_util = { path = "../util", version = "0.5.0" } +grin_wallet = { path = "../wallet", version = "0.5.0" } [dev-dependencies] blake2-rfc = "0.2" diff --git a/servers/src/common/types.rs b/servers/src/common/types.rs index 8c4a144530..626c9a64f0 100644 --- a/servers/src/common/types.rs +++ b/servers/src/common/types.rs @@ -172,7 +172,7 @@ impl Default for ServerConfig { fn default() -> ServerConfig { ServerConfig { db_root: "grin_chain".to_string(), - api_http_addr: "127.0.0.1:13413".to_string(), + api_http_addr: "127.0.0.1:3413".to_string(), api_secret_path: Some(".api_secret".to_string()), p2p_config: p2p::P2PConfig::default(), dandelion_config: pool::DandelionConfig::default(), @@ -218,12 +218,12 @@ pub struct StratumServerConfig { impl Default for StratumServerConfig { fn default() -> StratumServerConfig { StratumServerConfig { - wallet_listener_url: "http://127.0.0.1:13415".to_string(), + wallet_listener_url: "http://127.0.0.1:3415".to_string(), burn_reward: false, attempt_time_per_block: 15, minimum_share_difficulty: 1, enable_stratum_server: Some(false), - stratum_server_addr: Some("127.0.0.1:13416".to_string()), + stratum_server_addr: Some("127.0.0.1:3416".to_string()), } } } diff --git a/servers/src/grin/seed.rs b/servers/src/grin/seed.rs index e79d23e116..de49286200 100644 --- a/servers/src/grin/seed.rs +++ b/servers/src/grin/seed.rs @@ -335,7 +335,7 @@ fn listen_for_addrs( pub fn dns_seeds() -> Box Vec + Send> { Box::new(|| { let mut addresses: Vec = vec![]; - let net_seeds = if global::is_testnet() { + let net_seeds = if global::is_floonet() { FLOONET_DNS_SEEDS } else { MAINNET_DNS_SEEDS diff --git a/servers/src/mining/mine_block.rs b/servers/src/mining/mine_block.rs index 5aa3216b15..6d2684281f 100644 --- a/servers/src/mining/mine_block.rs +++ b/servers/src/mining/mine_block.rs @@ -25,7 +25,7 @@ use std::time::Duration; use crate::chain; use crate::common::types::Error; use crate::core::core::verifier_cache::VerifierCache; -use crate::core::{consensus, core, ser}; +use crate::core::{consensus, core, global, ser}; use crate::keychain::{ExtKeychain, Identifier, Keychain}; use crate::pool; use crate::util; @@ -170,11 +170,10 @@ fn build_block( /// fn burn_reward(block_fees: BlockFees) -> Result<(core::Output, core::TxKernel, BlockFees), Error> { warn!("Burning block fees: {:?}", block_fees); - let keychain = ExtKeychain::from_random_seed().unwrap(); + let keychain = ExtKeychain::from_random_seed(global::is_floonet()).unwrap(); let key_id = ExtKeychain::derive_key_id(1, 1, 0, 0, 0); let (out, kernel) = - crate::core::libtx::reward::output(&keychain, &key_id, block_fees.fees) - .unwrap(); + crate::core::libtx::reward::output(&keychain, &key_id, block_fees.fees).unwrap(); Ok((out, kernel, block_fees)) } diff --git a/servers/tests/framework.rs b/servers/tests/framework.rs index 8b645cb42f..79988f728e 100644 --- a/servers/tests/framework.rs +++ b/servers/tests/framework.rs @@ -306,7 +306,7 @@ impl LocalServerContainer { wallet_seed: &wallet::WalletSeed, ) -> wallet::WalletInfo { let keychain: keychain::ExtKeychain = wallet_seed - .derive_keychain() + .derive_keychain(false) .expect("Failed to derive keychain from seed file and passphrase."); let client_n = HTTPNodeClient::new(&config.check_node_api_http_addr, None); let mut wallet = LMDBBackend::new(config.clone(), "", client_n) @@ -332,7 +332,7 @@ impl LocalServerContainer { wallet::WalletSeed::from_file(config, "").expect("Failed to read wallet seed file."); let keychain: keychain::ExtKeychain = wallet_seed - .derive_keychain() + .derive_keychain(false) .expect("Failed to derive keychain from seed file and passphrase."); let client_n = HTTPNodeClient::new(&config.check_node_api_http_addr, None); diff --git a/src/bin/cmd/config.rs b/src/bin/cmd/config.rs index fad31dadbe..16b7b38c3d 100644 --- a/src/bin/cmd/config.rs +++ b/src/bin/cmd/config.rs @@ -14,11 +14,12 @@ /// Grin configuration file output command use crate::config::{GlobalConfig, GlobalWalletConfig}; +use crate::core::global; use std::env; /// Create a config file in the current directory -pub fn config_command_server(file_name: &str) { - let mut default_config = GlobalConfig::default(); +pub fn config_command_server(chain_type: &global::ChainTypes, file_name: &str) { + let mut default_config = GlobalConfig::for_chain(chain_type); let current_dir = env::current_dir().unwrap_or_else(|e| { panic!("Error creating config file: {}", e); }); @@ -44,8 +45,8 @@ pub fn config_command_server(file_name: &str) { } /// Create a config file in the current directory -pub fn config_command_wallet(file_name: &str) { - let mut default_config = GlobalWalletConfig::default(); +pub fn config_command_wallet(chain_type: &global::ChainTypes, file_name: &str) { + let mut default_config = GlobalWalletConfig::for_chain(chain_type); let current_dir = env::current_dir().unwrap_or_else(|e| { panic!("Error creating config file: {}", e); }); diff --git a/src/bin/grin.rs b/src/bin/grin.rs index e6e19ef4f8..d43b175456 100644 --- a/src/bin/grin.rs +++ b/src/bin/grin.rs @@ -79,12 +79,26 @@ fn real_main() -> i32 { let mut wallet_config = None; let mut node_config = None; + let chain_type = if args.is_present("floonet") { + global::ChainTypes::Floonet + } else if args.is_present("usernet") { + global::ChainTypes::UserTesting + } else { + global::ChainTypes::Mainnet + }; + + // TODO remove for mainnet + if chain_type == global::ChainTypes::Mainnet { + println!("Mainnet not ready yet! In the meantime run 'grin --floonet ...'"); + exit(1); + } + // Deal with configuration file creation match args.subcommand() { ("server", Some(server_args)) => { // If it's just a server config command, do it and exit if let ("config", Some(_)) = server_args.subcommand() { - cmd::config_command_server(SERVER_CONFIG_FILE_NAME); + cmd::config_command_server(&chain_type, SERVER_CONFIG_FILE_NAME); return 0; } } @@ -93,7 +107,7 @@ fn real_main() -> i32 { // (if desired) if let ("init", Some(init_args)) = wallet_args.subcommand() { if init_args.is_present("here") { - cmd::config_command_wallet(WALLET_CONFIG_FILE_NAME); + cmd::config_command_wallet(&chain_type, WALLET_CONFIG_FILE_NAME); } } } @@ -103,7 +117,7 @@ fn real_main() -> i32 { match args.subcommand() { // If it's a wallet command, try and load a wallet config file ("wallet", Some(wallet_args)) => { - let mut w = config::initial_setup_wallet().unwrap_or_else(|e| { + let mut w = config::initial_setup_wallet(&chain_type).unwrap_or_else(|e| { panic!("Error loading wallet configuration: {}", e); }); if !cmd::seed_exists(w.members.as_ref().unwrap().wallet.clone()) { @@ -124,7 +138,7 @@ fn real_main() -> i32 { } // Otherwise load up the node config as usual _ => { - let mut s = config::initial_setup_server().unwrap_or_else(|e| { + let mut s = config::initial_setup_server(&chain_type).unwrap_or_else(|e| { panic!("Error loading server configuration: {}", e); }); let mut l = s.members.as_mut().unwrap().logging.clone().unwrap(); diff --git a/src/bin/grin.yml b/src/bin/grin.yml index 686242047c..a6c0513fc2 100644 --- a/src/bin/grin.yml +++ b/src/bin/grin.yml @@ -1,8 +1,17 @@ name: grin -version: "0.4.2" +version: "0.5.0" about: Lightweight implementation of the MimbleWimble protocol. author: The Grin Team +args: + - floonet: + help: Run grin against the Floonet (as opposed to mainnet) + long: floonet + takes_value: false + - usernet: + help: Run grin as a local-only network. Doesn't block peer connections but will not connect to any peer or seed + long: usernet + takes_value: false subcommands: - server: about: Control the Grin server diff --git a/store/Cargo.toml b/store/Cargo.toml index ebd665f9c9..ae7c13d144 100644 --- a/store/Cargo.toml +++ b/store/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "grin_store" -version = "0.4.2" +version = "0.5.0" authors = ["Grin Developers "] description = "Simple, private and scalable cryptocurrency implementation based on the MimbleWimble chain format." license = "Apache-2.0" @@ -22,8 +22,8 @@ serde = "1" serde_derive = "1" log = "0.4" -grin_core = { path = "../core", version = "0.4.2" } -grin_util = { path = "../util", version = "0.4.2" } +grin_core = { path = "../core", version = "0.5.0" } +grin_util = { path = "../util", version = "0.5.0" } [dev-dependencies] chrono = "0.4.4" diff --git a/util/Cargo.toml b/util/Cargo.toml index 1d45e67824..9c4123ce53 100644 --- a/util/Cargo.toml +++ b/util/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "grin_util" -version = "0.4.2" +version = "0.5.0" authors = ["Grin Developers "] description = "Simple, private and scalable cryptocurrency implementation based on the MimbleWimble chain format." license = "Apache-2.0" diff --git a/wallet/Cargo.toml b/wallet/Cargo.toml index ecec96a0ab..5e81e0b267 100644 --- a/wallet/Cargo.toml +++ b/wallet/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "grin_wallet" -version = "0.4.2" +version = "0.5.0" authors = ["Grin Developers "] description = "Simple, private and scalable cryptocurrency implementation based on the MimbleWimble chain format." license = "Apache-2.0" @@ -31,13 +31,13 @@ uuid = { version = "0.6", features = ["serde", "v4"] } url = "1.7.0" chrono = { version = "0.4.4", features = ["serde"] } -grin_api = { path = "../api", version = "0.4.2" } -grin_core = { path = "../core", version = "0.4.2" } -grin_keychain = { path = "../keychain", version = "0.4.2" } -grin_store = { path = "../store", version = "0.4.2" } -grin_util = { path = "../util", version = "0.4.2" } -grin_chain = { path = "../chain", version = "0.4.2" } +grin_api = { path = "../api", version = "0.5.0" } +grin_core = { path = "../core", version = "0.5.0" } +grin_keychain = { path = "../keychain", version = "0.5.0" } +grin_store = { path = "../store", version = "0.5.0" } +grin_util = { path = "../util", version = "0.5.0" } +grin_chain = { path = "../chain", version = "0.5.0" } [dev-dependencies] -grin_store = { path = "../store", version = "0.4.2" } -grin_config = { path = "../config", version = "0.4.2" } +grin_store = { path = "../store", version = "0.5.0" } +grin_config = { path = "../config", version = "0.5.0" } diff --git a/wallet/src/libwallet/internal/tx.rs b/wallet/src/libwallet/internal/tx.rs index af7e1c9063..e5f4b6c3c5 100644 --- a/wallet/src/libwallet/internal/tx.rs +++ b/wallet/src/libwallet/internal/tx.rs @@ -233,7 +233,7 @@ mod test { // demonstrate that input.commitment == referenced output.commitment // based on the public key and amount begin spent fn output_commitment_equals_input_commitment_on_spend() { - let keychain = ExtKeychain::from_random_seed().unwrap(); + let keychain = ExtKeychain::from_random_seed(false).unwrap(); let key_id1 = ExtKeychainPath::new(1, 1, 0, 0, 0).to_identifier(); let tx1 = build::transaction(vec![build::output(105, key_id1.clone())], &keychain).unwrap(); diff --git a/wallet/src/lmdb_wallet.rs b/wallet/src/lmdb_wallet.rs index dbc34ae925..b901c171fe 100644 --- a/wallet/src/lmdb_wallet.rs +++ b/wallet/src/lmdb_wallet.rs @@ -32,7 +32,7 @@ use crate::keychain::{ChildNumber, ExtKeychain, Identifier, Keychain}; use crate::store::{self, option_to_not_found, to_key, to_key_u64}; use crate::core::core::Transaction; -use crate::core::ser; +use crate::core::{global, ser}; use crate::libwallet::types::*; use crate::libwallet::{internal, Error, ErrorKind}; use crate::types::{WalletConfig, WalletSeed}; @@ -179,7 +179,7 @@ where .context(ErrorKind::CallbackImpl("Error opening wallet"))?; self.keychain = Some( wallet_seed - .derive_keychain() + .derive_keychain(global::is_floonet()) .context(ErrorKind::CallbackImpl("Error deriving keychain"))?, ); Ok(()) diff --git a/wallet/src/types.rs b/wallet/src/types.rs index 7a58f7fa37..80b383d0db 100644 --- a/wallet/src/types.rs +++ b/wallet/src/types.rs @@ -66,10 +66,10 @@ impl Default for WalletConfig { WalletConfig { chain_type: Some(ChainTypes::Floonet), api_listen_interface: "127.0.0.1".to_string(), - api_listen_port: 13415, + api_listen_port: 3415, api_secret_path: Some(".api_secret".to_string()), node_api_secret_path: Some(".api_secret".to_string()), - check_node_api_http_addr: "http://127.0.0.1:13413".to_string(), + check_node_api_http_addr: "http://127.0.0.1:3413".to_string(), data_file_dir: ".".to_string(), tls_certificate_file: None, tls_certificate_key: None, @@ -124,8 +124,8 @@ impl WalletSeed { seed.as_bytes().to_vec() } - pub fn derive_keychain(&self) -> Result { - let result = K::from_seed(&self.0)?; + pub fn derive_keychain(&self, is_floonet: bool) -> Result { + let result = K::from_seed(&self.0, is_floonet)?; Ok(result) } @@ -218,36 +218,7 @@ impl WalletSeed { let mut buffer = String::new(); file.read_to_string(&mut buffer).context(ErrorKind::IO)?; let enc_seed: EncryptedWalletSeed = - match serde_json::from_str(&buffer).context(ErrorKind::Format) { - Ok(s) => s, - Err(_) => { - println!("Attempting to convert old wallet seed file to new format"); - // TODO: remove for mainnet - // try to convert from old format - let mut bak_file = File::create(format!("{}.bak", seed_file_path)) - .context(ErrorKind::IO)?; - let mut file = File::create(seed_file_path).context(ErrorKind::IO)?; - let old_wallet_seed = WalletSeed::from_hex(&buffer.trim())?; - bak_file - .write_all(&old_wallet_seed.to_hex().as_bytes()) - .context(ErrorKind::IO)?; - let mut c_wallet_seed = [0u8; 32]; - c_wallet_seed.copy_from_slice(&old_wallet_seed.0[0..32]); - let converted_wallet_seed = - WalletSeed::derive_keychain_old(c_wallet_seed, password); - let enc_seed = EncryptedWalletSeed::from_seed( - &WalletSeed::from_bytes(&converted_wallet_seed), - password, - )?; - let enc_seed_json = - serde_json::to_string_pretty(&enc_seed).context(ErrorKind::Format)?; - file.write_all(&enc_seed_json.as_bytes()) - .context(ErrorKind::IO)?; - println!("Seed file conversion done"); - println!("Consider moving funds to a newly-created wallet to support recovery phrases"); - enc_seed - } - }; + serde_json::from_str(&buffer).context(ErrorKind::Format)?; let wallet_seed = enc_seed.decrypt(password)?; Ok(wallet_seed) } else { diff --git a/wallet/tests/libwallet.rs b/wallet/tests/libwallet.rs index 3ca5ac974d..0d72d44cac 100644 --- a/wallet/tests/libwallet.rs +++ b/wallet/tests/libwallet.rs @@ -31,8 +31,8 @@ fn kernel_sig_msg() -> secp::Message { #[test] fn aggsig_sender_receiver_interaction() { - let sender_keychain = ExtKeychain::from_random_seed().unwrap(); - let receiver_keychain = ExtKeychain::from_random_seed().unwrap(); + let sender_keychain = ExtKeychain::from_random_seed(true).unwrap(); + let receiver_keychain = ExtKeychain::from_random_seed(true).unwrap(); // Calculate the kernel excess here for convenience. // Normally this would happen during transaction building. @@ -41,7 +41,7 @@ fn aggsig_sender_receiver_interaction() { let skey1 = sender_keychain.derive_key(0, &id1).unwrap(); let skey2 = receiver_keychain.derive_key(0, &id1).unwrap(); - let keychain = ExtKeychain::from_random_seed().unwrap(); + let keychain = ExtKeychain::from_random_seed(true).unwrap(); let blinding_factor = keychain .blind_sum( &BlindSum::new() @@ -224,7 +224,7 @@ fn aggsig_sender_receiver_interaction() { // Check we can verify the sig using the kernel excess { - let keychain = ExtKeychain::from_random_seed().unwrap(); + let keychain = ExtKeychain::from_random_seed(true).unwrap(); let msg = kernel_sig_msg(); let sig_verifies = aggsig::verify_single_from_commit(&keychain.secp(), &final_sig, &msg, &kernel_excess); @@ -235,8 +235,8 @@ fn aggsig_sender_receiver_interaction() { #[test] fn aggsig_sender_receiver_interaction_offset() { - let sender_keychain = ExtKeychain::from_random_seed().unwrap(); - let receiver_keychain = ExtKeychain::from_random_seed().unwrap(); + let sender_keychain = ExtKeychain::from_random_seed(true).unwrap(); + let receiver_keychain = ExtKeychain::from_random_seed(true).unwrap(); // This is the kernel offset that we use to split the key // Summing these at the block level prevents the @@ -250,7 +250,7 @@ fn aggsig_sender_receiver_interaction_offset() { let skey1 = sender_keychain.derive_key(0, &id1).unwrap(); let skey2 = receiver_keychain.derive_key(0, &id1).unwrap(); - let keychain = ExtKeychain::from_random_seed().unwrap(); + let keychain = ExtKeychain::from_random_seed(true).unwrap(); let blinding_factor = keychain .blind_sum( &BlindSum::new() @@ -439,7 +439,7 @@ fn aggsig_sender_receiver_interaction_offset() { // Check we can verify the sig using the kernel excess { - let keychain = ExtKeychain::from_random_seed().unwrap(); + let keychain = ExtKeychain::from_random_seed(true).unwrap(); let msg = kernel_sig_msg(); let sig_verifies = aggsig::verify_single_from_commit(&keychain.secp(), &final_sig, &msg, &kernel_excess); @@ -450,7 +450,7 @@ fn aggsig_sender_receiver_interaction_offset() { #[test] fn test_rewind_range_proof() { - let keychain = ExtKeychain::from_random_seed().unwrap(); + let keychain = ExtKeychain::from_random_seed(true).unwrap(); let key_id = ExtKeychain::derive_key_id(1, 1, 0, 0, 0); let key_id2 = ExtKeychain::derive_key_id(1, 2, 0, 0, 0); let commit = keychain.commit(5, &key_id).unwrap();