From e68a6a69bb4bb7cfebbd8b36323b3ab0572240d8 Mon Sep 17 00:00:00 2001 From: Yeastplume Date: Wed, 4 Oct 2017 18:44:22 +0100 Subject: [PATCH] Cuckoo miner fixes and configurable coinbase maturity (#154) * cuckoo miner update+coinbase maturity * set mining parameter mode on immature coinbase test --- api/src/types.rs | 4 ++-- chain/src/pipe.rs | 2 +- core/src/consensus.rs | 5 +---- core/src/global.rs | 17 +++++++++++++++++ grin.toml | 13 +++++++++---- pool/src/pool.rs | 5 ++++- pow/Cargo.toml | 4 +++- 7 files changed, 37 insertions(+), 13 deletions(-) diff --git a/api/src/types.rs b/api/src/types.rs index 7fc12a02d..f3002e2f0 100644 --- a/api/src/types.rs +++ b/api/src/types.rs @@ -12,7 +12,7 @@ // See the License for the specific language governing permissions and // limitations under the License. -use core::{core, consensus}; +use core::{core, consensus, global}; use chain; use secp::pedersen; @@ -60,7 +60,7 @@ impl Output { x if x.contains(core::transaction::COINBASE_OUTPUT) => { ( OutputType::Coinbase, - block_header.height + consensus::COINBASE_MATURITY, + block_header.height + global::coinbase_maturity(), ) } _ => (OutputType::Transaction, 0), diff --git a/chain/src/pipe.rs b/chain/src/pipe.rs index d3898d1cd..1450bc9db 100644 --- a/chain/src/pipe.rs +++ b/chain/src/pipe.rs @@ -271,7 +271,7 @@ fn validate_block( // TODO - make sure we are not off-by-1 here vs. the equivalent tansaction // validation rule - if b.header.height <= output_header.height + consensus::COINBASE_MATURITY { + if b.header.height <= output_header.height + global::coinbase_maturity() { return Err(Error::ImmatureCoinbase); } }; diff --git a/core/src/consensus.rs b/core/src/consensus.rs index 543e3e61e..fabeb8bfb 100644 --- a/core/src/consensus.rs +++ b/core/src/consensus.rs @@ -27,10 +27,7 @@ use core::target::Difficulty; pub const REWARD: u64 = 1_000_000_000; /// Number of blocks before a coinbase matures and can be spent -/// TODO - reduced this for testing - need to investigate if we can lower this -/// in test env -// pub const COINBASE_MATURITY: u64 = 1_000; -pub const COINBASE_MATURITY: u64 = 3; +pub const COINBASE_MATURITY: u64 = 1_000; /// Block interval, in seconds, the network will tune its next_target for. Note /// that we may reduce this value in the future as we get more data on mining diff --git a/core/src/global.rs b/core/src/global.rs index 0a3448ddd..97e6a2b14 100644 --- a/core/src/global.rs +++ b/core/src/global.rs @@ -24,6 +24,7 @@ use std::sync::RwLock; use consensus::PROOFSIZE; use consensus::DEFAULT_SIZESHIFT; +use consensus::COINBASE_MATURITY; /// Define these here, as they should be developer-set, not really tweakable /// by users @@ -40,6 +41,12 @@ pub const USER_TESTING_SIZESHIFT: u8 = 16; /// User testing proof size pub const USER_TESTING_PROOF_SIZE: usize = 42; +/// Automated testing coinbase maturity +pub const AUTOMATED_TESTING_COINBASE_MATURITY: u64 = 3; + +/// User testing coinbase maturity +pub const USER_TESTING_COINBASE_MATURITY: u64 = 3; + /// Mining parameter modes #[derive(Debug, Clone, Serialize, Deserialize)] pub enum MiningParameterMode { @@ -85,6 +92,16 @@ pub fn proofsize() -> usize { } } +/// Coinbase maturity +pub fn coinbase_maturity() -> u64 { + let param_ref = MINING_PARAMETER_MODE.read().unwrap(); + match *param_ref { + MiningParameterMode::AutomatedTesting => AUTOMATED_TESTING_COINBASE_MATURITY, + MiningParameterMode::UserTesting => USER_TESTING_COINBASE_MATURITY, + MiningParameterMode::Production => COINBASE_MATURITY, + } +} + /// Are we in automated testing mode? pub fn is_automated_testing_mode() -> bool { let param_ref = MINING_PARAMETER_MODE.read().unwrap(); diff --git a/grin.toml b/grin.toml index 9f37578f8..a640738d2 100644 --- a/grin.toml +++ b/grin.toml @@ -31,10 +31,10 @@ seeding_type = "None" #The mining parameter mode, which defines the set of cuckoo parameters #used for mining. Can be: #AutomatedTesting - For CI builds and instant blockchain creation -#UserTesting - For regular user testing, much lighter than production more -#Production - Full production cuckoo parameters +#UserTesting - For regular user testing (cuckoo 16) +#Production - Full production cuckoo parameter (cuckoo 30) -mining_parameter_mode = "Production" +mining_parameter_mode = "UserTesting" #7 = Bit flags for FULL_NODE, this structure needs to be changed #internally to make it more configurable @@ -54,7 +54,7 @@ port = 13414 #flag whether mining is enabled -enable_mining = false +enable_mining = false #Whether to use cuckoo-miner, and related parameters @@ -128,6 +128,11 @@ parameter_list = {NUM_THREADS=4, NUM_TRIMS=68} #CUDA verion of lean miner #Can currently be used only in Production (30) Mode +#This plugin is not built by default. To build: +#1) Ensure the latest cuda toolkit is installed +# (nvcc should be on the pat) +#2) Uncomment the 'build-cuda-plugin' feature +# in pow/Cargo.toml #[[mining.cuckoo_miner_plugin_config]] #type_filter = "lean_cuda" diff --git a/pool/src/pool.rs b/pool/src/pool.rs index fa30d30d0..aa6f91bc4 100644 --- a/pool/src/pool.rs +++ b/pool/src/pool.rs @@ -20,6 +20,8 @@ pub use graph; use core::core::transaction; use core::core::block; use core::core::hash; +use core::global; +use core::global::{MiningParameterMode, MINING_PARAMETER_MODE}; use core::consensus; use secp; @@ -168,7 +170,7 @@ where { if let Ok(head_header) = self.blockchain.head_header() { if head_header.height <= - out_header.height + consensus::COINBASE_MATURITY + out_header.height + global::coinbase_maturity() { return Err(PoolError::ImmatureCoinbase { header: out_header, @@ -727,6 +729,7 @@ mod tests { #[test] fn test_immature_coinbase() { + global::set_mining_mode(MiningParameterMode::AutomatedTesting); let mut dummy_chain = DummyChainImpl::new(); let coinbase_output = test_coinbase_output(15); dummy_chain.update_utxo_set(DummyUtxoSet::empty().with_output(coinbase_output)); diff --git a/pow/Cargo.toml b/pow/Cargo.toml index dbfdd10b7..09e2717b4 100644 --- a/pow/Cargo.toml +++ b/pow/Cargo.toml @@ -18,10 +18,12 @@ grin_core = { path = "../core" } [dependencies.cuckoo_miner] git = "https://github.com/mimblewimble/cuckoo-miner" -tag="grin_integration_12" +tag="grin_integration_13" #path = "../../cuckoo-miner" #uncomment this feature to turn off plugin builds #features=["no-plugin-build"] +#uncomment this feature to enable cuda builds (cuda toolkit must be installed) +#features=["build-cuda-plugins"] [dev_dependencies] grin_chain = { path = "../chain"}