mirror of
https://github.com/mimblewimble/grin.git
synced 2025-02-01 08:51:08 +03:00
Cuckoo miner fixes and configurable coinbase maturity (#154)
* cuckoo miner update+coinbase maturity * set mining parameter mode on immature coinbase test
This commit is contained in:
parent
4e49b85b82
commit
e68a6a69bb
7 changed files with 37 additions and 13 deletions
|
@ -12,7 +12,7 @@
|
||||||
// See the License for the specific language governing permissions and
|
// See the License for the specific language governing permissions and
|
||||||
// limitations under the License.
|
// limitations under the License.
|
||||||
|
|
||||||
use core::{core, consensus};
|
use core::{core, consensus, global};
|
||||||
use chain;
|
use chain;
|
||||||
use secp::pedersen;
|
use secp::pedersen;
|
||||||
|
|
||||||
|
@ -60,7 +60,7 @@ impl Output {
|
||||||
x if x.contains(core::transaction::COINBASE_OUTPUT) => {
|
x if x.contains(core::transaction::COINBASE_OUTPUT) => {
|
||||||
(
|
(
|
||||||
OutputType::Coinbase,
|
OutputType::Coinbase,
|
||||||
block_header.height + consensus::COINBASE_MATURITY,
|
block_header.height + global::coinbase_maturity(),
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
_ => (OutputType::Transaction, 0),
|
_ => (OutputType::Transaction, 0),
|
||||||
|
|
|
@ -271,7 +271,7 @@ fn validate_block(
|
||||||
|
|
||||||
// TODO - make sure we are not off-by-1 here vs. the equivalent tansaction
|
// TODO - make sure we are not off-by-1 here vs. the equivalent tansaction
|
||||||
// validation rule
|
// 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);
|
return Err(Error::ImmatureCoinbase);
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
|
@ -27,10 +27,7 @@ use core::target::Difficulty;
|
||||||
pub const REWARD: u64 = 1_000_000_000;
|
pub const REWARD: u64 = 1_000_000_000;
|
||||||
|
|
||||||
/// Number of blocks before a coinbase matures and can be spent
|
/// Number of blocks before a coinbase matures and can be spent
|
||||||
/// TODO - reduced this for testing - need to investigate if we can lower this
|
pub const COINBASE_MATURITY: u64 = 1_000;
|
||||||
/// in test env
|
|
||||||
// pub const COINBASE_MATURITY: u64 = 1_000;
|
|
||||||
pub const COINBASE_MATURITY: u64 = 3;
|
|
||||||
|
|
||||||
/// Block interval, in seconds, the network will tune its next_target for. Note
|
/// 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
|
/// that we may reduce this value in the future as we get more data on mining
|
||||||
|
|
|
@ -24,6 +24,7 @@
|
||||||
use std::sync::RwLock;
|
use std::sync::RwLock;
|
||||||
use consensus::PROOFSIZE;
|
use consensus::PROOFSIZE;
|
||||||
use consensus::DEFAULT_SIZESHIFT;
|
use consensus::DEFAULT_SIZESHIFT;
|
||||||
|
use consensus::COINBASE_MATURITY;
|
||||||
|
|
||||||
/// Define these here, as they should be developer-set, not really tweakable
|
/// Define these here, as they should be developer-set, not really tweakable
|
||||||
/// by users
|
/// by users
|
||||||
|
@ -40,6 +41,12 @@ pub const USER_TESTING_SIZESHIFT: u8 = 16;
|
||||||
/// User testing proof size
|
/// User testing proof size
|
||||||
pub const USER_TESTING_PROOF_SIZE: usize = 42;
|
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
|
/// Mining parameter modes
|
||||||
#[derive(Debug, Clone, Serialize, Deserialize)]
|
#[derive(Debug, Clone, Serialize, Deserialize)]
|
||||||
pub enum MiningParameterMode {
|
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?
|
/// Are we in automated testing mode?
|
||||||
pub fn is_automated_testing_mode() -> bool {
|
pub fn is_automated_testing_mode() -> bool {
|
||||||
let param_ref = MINING_PARAMETER_MODE.read().unwrap();
|
let param_ref = MINING_PARAMETER_MODE.read().unwrap();
|
||||||
|
|
13
grin.toml
13
grin.toml
|
@ -31,10 +31,10 @@ seeding_type = "None"
|
||||||
#The mining parameter mode, which defines the set of cuckoo parameters
|
#The mining parameter mode, which defines the set of cuckoo parameters
|
||||||
#used for mining. Can be:
|
#used for mining. Can be:
|
||||||
#AutomatedTesting - For CI builds and instant blockchain creation
|
#AutomatedTesting - For CI builds and instant blockchain creation
|
||||||
#UserTesting - For regular user testing, much lighter than production more
|
#UserTesting - For regular user testing (cuckoo 16)
|
||||||
#Production - Full production cuckoo parameters
|
#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
|
#7 = Bit flags for FULL_NODE, this structure needs to be changed
|
||||||
#internally to make it more configurable
|
#internally to make it more configurable
|
||||||
|
@ -54,7 +54,7 @@ port = 13414
|
||||||
|
|
||||||
#flag whether mining is enabled
|
#flag whether mining is enabled
|
||||||
|
|
||||||
enable_mining = false
|
enable_mining = false
|
||||||
|
|
||||||
#Whether to use cuckoo-miner, and related parameters
|
#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
|
#CUDA verion of lean miner
|
||||||
#Can currently be used only in Production (30) Mode
|
#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]]
|
#[[mining.cuckoo_miner_plugin_config]]
|
||||||
#type_filter = "lean_cuda"
|
#type_filter = "lean_cuda"
|
||||||
|
|
|
@ -20,6 +20,8 @@ pub use graph;
|
||||||
use core::core::transaction;
|
use core::core::transaction;
|
||||||
use core::core::block;
|
use core::core::block;
|
||||||
use core::core::hash;
|
use core::core::hash;
|
||||||
|
use core::global;
|
||||||
|
use core::global::{MiningParameterMode, MINING_PARAMETER_MODE};
|
||||||
use core::consensus;
|
use core::consensus;
|
||||||
|
|
||||||
use secp;
|
use secp;
|
||||||
|
@ -168,7 +170,7 @@ where
|
||||||
{
|
{
|
||||||
if let Ok(head_header) = self.blockchain.head_header() {
|
if let Ok(head_header) = self.blockchain.head_header() {
|
||||||
if head_header.height <=
|
if head_header.height <=
|
||||||
out_header.height + consensus::COINBASE_MATURITY
|
out_header.height + global::coinbase_maturity()
|
||||||
{
|
{
|
||||||
return Err(PoolError::ImmatureCoinbase {
|
return Err(PoolError::ImmatureCoinbase {
|
||||||
header: out_header,
|
header: out_header,
|
||||||
|
@ -727,6 +729,7 @@ mod tests {
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn test_immature_coinbase() {
|
fn test_immature_coinbase() {
|
||||||
|
global::set_mining_mode(MiningParameterMode::AutomatedTesting);
|
||||||
let mut dummy_chain = DummyChainImpl::new();
|
let mut dummy_chain = DummyChainImpl::new();
|
||||||
let coinbase_output = test_coinbase_output(15);
|
let coinbase_output = test_coinbase_output(15);
|
||||||
dummy_chain.update_utxo_set(DummyUtxoSet::empty().with_output(coinbase_output));
|
dummy_chain.update_utxo_set(DummyUtxoSet::empty().with_output(coinbase_output));
|
||||||
|
|
|
@ -18,10 +18,12 @@ grin_core = { path = "../core" }
|
||||||
|
|
||||||
[dependencies.cuckoo_miner]
|
[dependencies.cuckoo_miner]
|
||||||
git = "https://github.com/mimblewimble/cuckoo-miner"
|
git = "https://github.com/mimblewimble/cuckoo-miner"
|
||||||
tag="grin_integration_12"
|
tag="grin_integration_13"
|
||||||
#path = "../../cuckoo-miner"
|
#path = "../../cuckoo-miner"
|
||||||
#uncomment this feature to turn off plugin builds
|
#uncomment this feature to turn off plugin builds
|
||||||
#features=["no-plugin-build"]
|
#features=["no-plugin-build"]
|
||||||
|
#uncomment this feature to enable cuda builds (cuda toolkit must be installed)
|
||||||
|
#features=["build-cuda-plugins"]
|
||||||
|
|
||||||
[dev_dependencies]
|
[dev_dependencies]
|
||||||
grin_chain = { path = "../chain"}
|
grin_chain = { path = "../chain"}
|
||||||
|
|
Loading…
Reference in a new issue