diff --git a/src/bench/bench_bitcoin.cpp b/src/bench/bench_bitcoin.cpp index d0d7c03ee1..564b1a8c73 100644 --- a/src/bench/bench_bitcoin.cpp +++ b/src/bench/bench_bitcoin.cpp @@ -33,40 +33,40 @@ static void SetupBenchArgs() int main(int argc, char** argv) { - SetupBenchArgs(); - std::string error; - if (!gArgs.ParseParameters(argc, argv, error)) { - tfm::format(std::cerr, "Error parsing command line arguments: %s\n", error.c_str()); - return EXIT_FAILURE; - } - - if (HelpRequested(gArgs)) { - std::cout << gArgs.GetHelpMessage(); - - return EXIT_SUCCESS; - } - - int64_t evaluations = gArgs.GetArg("-evals", DEFAULT_BENCH_EVALUATIONS); - std::string regex_filter = gArgs.GetArg("-filter", DEFAULT_BENCH_FILTER); - std::string scaling_str = gArgs.GetArg("-scaling", DEFAULT_BENCH_SCALING); - bool is_list_only = gArgs.GetBoolArg("-list", false); - - double scaling_factor; - if (!ParseDouble(scaling_str, &scaling_factor)) { - tfm::format(std::cerr, "Error parsing scaling factor as double: %s\n", scaling_str.c_str()); - return EXIT_FAILURE; - } - - std::unique_ptr printer = MakeUnique(); - std::string printer_arg = gArgs.GetArg("-printer", DEFAULT_BENCH_PRINTER); - if ("plot" == printer_arg) { - printer.reset(new benchmark::PlotlyPrinter( - gArgs.GetArg("-plot-plotlyurl", DEFAULT_PLOT_PLOTLYURL), - gArgs.GetArg("-plot-width", DEFAULT_PLOT_WIDTH), - gArgs.GetArg("-plot-height", DEFAULT_PLOT_HEIGHT))); - } - - benchmark::BenchRunner::RunAll(*printer, evaluations, scaling_factor, regex_filter, is_list_only); +// SetupBenchArgs(); // TODO: (temp) disable benches +// std::string error; +// if (!gArgs.ParseParameters(argc, argv, error)) { +// tfm::format(std::cerr, "Error parsing command line arguments: %s\n", error.c_str()); +// return EXIT_FAILURE; +// } +// +// if (HelpRequested(gArgs)) { +// std::cout << gArgs.GetHelpMessage(); +// +// return EXIT_SUCCESS; +// } +// +// int64_t evaluations = gArgs.GetArg("-evals", DEFAULT_BENCH_EVALUATIONS); +// std::string regex_filter = gArgs.GetArg("-filter", DEFAULT_BENCH_FILTER); +// std::string scaling_str = gArgs.GetArg("-scaling", DEFAULT_BENCH_SCALING); +// bool is_list_only = gArgs.GetBoolArg("-list", false); +// +// double scaling_factor; +// if (!ParseDouble(scaling_str, &scaling_factor)) { +// tfm::format(std::cerr, "Error parsing scaling factor as double: %s\n", scaling_str.c_str()); +// return EXIT_FAILURE; +// } +// +// std::unique_ptr printer = MakeUnique(); +// std::string printer_arg = gArgs.GetArg("-printer", DEFAULT_BENCH_PRINTER); +// if ("plot" == printer_arg) { +// printer.reset(new benchmark::PlotlyPrinter( +// gArgs.GetArg("-plot-plotlyurl", DEFAULT_PLOT_PLOTLYURL), +// gArgs.GetArg("-plot-width", DEFAULT_PLOT_WIDTH), +// gArgs.GetArg("-plot-height", DEFAULT_PLOT_HEIGHT))); +// } +// +// benchmark::BenchRunner::RunAll(*printer, evaluations, scaling_factor, regex_filter, is_list_only); return EXIT_SUCCESS; } diff --git a/src/bench/duplicate_inputs.cpp b/src/bench/duplicate_inputs.cpp index d5d45e42a5..78348d8254 100644 --- a/src/bench/duplicate_inputs.cpp +++ b/src/bench/duplicate_inputs.cpp @@ -8,6 +8,8 @@ #include #include #include +#include + #include #include diff --git a/src/bitcoin-tx.cpp b/src/bitcoin-tx.cpp index f4972c3cd4..b3c434d2cf 100644 --- a/src/bitcoin-tx.cpp +++ b/src/bitcoin-tx.cpp @@ -6,11 +6,11 @@ #include #endif +#include #include #include #include #include -#include #include #include #include diff --git a/src/chain.h b/src/chain.h index bef75e6b86..9a268cc8a1 100644 --- a/src/chain.h +++ b/src/chain.h @@ -220,6 +220,7 @@ class CBlockIndex height = 0; mintedBlocks = 0; sig = {}; + minter = CKeyID(); } CBlockIndex() @@ -239,6 +240,7 @@ class CBlockIndex mintedBlocks = block.mintedBlocks; stakeModifier = block.stakeModifier; sig = block.sig; + block.ExtractMinterKey(minter); } FlatFilePos GetBlockPos() const { diff --git a/src/chainparams.cpp b/src/chainparams.cpp index b98b0c6c09..eecd7c8a9b 100644 --- a/src/chainparams.cpp +++ b/src/chainparams.cpp @@ -7,8 +7,8 @@ #include #include -#include #include +#include #include #include #include @@ -142,6 +142,7 @@ class CMainParams : public CChainParams { // Masternodes' params consensus.mn.activationDelay = 1500; + consensus.mn.resignDelay = 300; consensus.mn.collateralUnlockDelay = 300; consensus.mn.creationFee = 1 * COIN; consensus.mn.collateralAmount = 100 * COIN; @@ -257,10 +258,11 @@ class CTestNetParams : public CChainParams { consensus.nMinimumChainWork = uint256S("0x00"); // By default assume that the signatures in ancestors of this block are valid. - consensus.defaultAssumeValid = uint256S("0x0000000000000037a8cd3e06cd5edbfe9dd1dbcc5dacab279376ef7cfc2b4c75"); //1354312 + consensus.defaultAssumeValid = uint256S("0x00"); // Masternodes' params consensus.mn.activationDelay = 10; + consensus.mn.resignDelay = 10; consensus.mn.collateralUnlockDelay = 10; consensus.mn.creationFee = 1 * COIN; consensus.mn.collateralAmount = 10 * COIN; @@ -283,11 +285,17 @@ class CTestNetParams : public CChainParams { bech32_hrp = "tf"; - genesis = CreateGenesisBlock(1569396815, 0x1e0fffff, 1, 50 * COIN, CreateGenesisMasternodes()); + // owner base58, operator base58 + vMasternodes.push_back({"7M3g9CSERjLdXisE5pv2qryDbURUj9Vpi1", "7Grgx69MZJ4wDKRx1bBxLqTnU9T3quKW7n"}); + vMasternodes.push_back({"7L29itepC13pgho1X2y7mcuf4WjkBi7x2w", "773MiaEtQK2HAwWj55gyuRiU8tSwowRTTW"}); + vMasternodes.push_back({"75Wramp2iARchHedXcn1qRkQtMpSt9Mi3V", "7Ku81yvqbPkxpWjZpZWZZnWydXyzJozZfN"}); + vMasternodes.push_back({"7LfqHbyh9dBQDjWB6MxcWvH2PBC5iY4wPa", "75q6ftr3QGfBT3DBu15fVfetP6duAgfhNH"}); + + genesis = CreateGenesisBlock(1297053593, 0x207fffff, 1, 50 * COIN, CreateGenesisMasternodes()); // 0x1e0fffff consensus.hashGenesisBlock = genesis.GetHash(); - assert(consensus.hashGenesisBlock == uint256S("0xc0f410a59e9aa22afd67ee4671d41c2e3135c0efc589446e4b393cc534d178ac")); - assert(genesis.hashMerkleRoot == uint256S("0x800c7581a09c96d98bdad848db8fc027e8869d28d890ca21f6c25124baf53afe")); + assert(consensus.hashGenesisBlock == uint256S("0x00000e04e92efbd4a99b9f38abd22bc1e97651ab194a72a6390687f99c4d1555")); + assert(genesis.hashMerkleRoot == uint256S("0xc4b5095034837015551b4ef0eb56eab6706b3d102cc44a910c0eee084932ef5b")); vFixedSeeds.clear(); vSeeds.clear(); @@ -311,8 +319,7 @@ class CTestNetParams : public CChainParams { }; chainTxData = ChainTxData{ - // Data from rpc: getchaintxstats 4096 0000000000000037a8cd3e06cd5edbfe9dd1dbcc5dacab279376ef7cfc2b4c75 - /* nTime */ 1569396815, + /* nTime */ 0, /* nTxCount */ 0, /* dTxRate */ 0 }; @@ -328,21 +335,21 @@ class CRegTestParams : public CChainParams { strNetworkID = "regtest"; consensus.nSubsidyHalvingInterval = 150; consensus.BIP16Exception = uint256(); - consensus.BIP34Height = 0; // BIP34 activated on regtest (Used in functional tests) + consensus.BIP34Height = 500; // BIP34 activated on regtest (Used in functional tests) consensus.BIP34Hash = uint256(); - consensus.BIP65Height = 0; // BIP65 activated on regtest (Used in functional tests) - consensus.BIP66Height = 0; // BIP66 activated on regtest (Used in functional tests) + consensus.BIP65Height = 1351; // BIP65 activated on regtest (Used in functional tests) + consensus.BIP66Height = 1251; // BIP66 activated on regtest (Used in functional tests) consensus.pos.diffLimit = uint256S("00000fffffffffffffffffffffffffffffffffffffffffffffffffffffffffff"); consensus.pos.nTargetTimespan = 14 * 24 * 60 * 60; // two weeks consensus.pos.nTargetSpacing = 10 * 60; // 10 minutes - consensus.pos.fAllowMinDifficultyBlocks = false; // only for regtest - consensus.pos.fNoRetargeting = false; // only for regtest + consensus.pos.fAllowMinDifficultyBlocks = true; // only for regtest + consensus.pos.fNoRetargeting = true; // only for regtest consensus.pos.coinstakeMaturity = 100; consensus.pos.allowMintingWithoutPeers = true; // don't mint if no peers connected - consensus.CSVHeight = 1; // CSV activated on regtest (Used in rpc activation tests) + consensus.CSVHeight = 432; // CSV activated on regtest (Used in rpc activation tests) consensus.SegwitHeight = 0; // SEGWIT is always activated on regtest unless overridden consensus.nRuleChangeActivationThreshold = 108; // 75% for testchains consensus.nMinerConfirmationWindow = 144; // Faster than normal for regtest (144 instead of 2016) @@ -358,6 +365,7 @@ class CRegTestParams : public CChainParams { // Masternodes' params consensus.mn.activationDelay = 10; + consensus.mn.resignDelay = 10; consensus.mn.collateralUnlockDelay = 10; consensus.mn.creationFee = 1 * COIN; consensus.mn.collateralAmount = 10 * COIN; @@ -390,8 +398,9 @@ class CRegTestParams : public CChainParams { genesis = CreateGenesisBlock(1296688602, 0x207fffff, 1, 50 * COIN, CreateGenesisMasternodes()); consensus.hashGenesisBlock = genesis.GetHash(); - assert(consensus.hashGenesisBlock == uint256S("0x000006772a3244d0a5a4911a5cb1d7e910e175f4e4b77c755018459122fa7a89")); - assert(genesis.hashMerkleRoot == uint256S("0x2faeba8cd467cb0df14c48d30b57736f1ed3275790401d127a03d55037df7b5c")); + + assert(consensus.hashGenesisBlock == uint256S("0x5deed118789bf5acdce79974f15b9a1cffb924875f52e702ca93d926d290b31f")); + assert(genesis.hashMerkleRoot == uint256S("0x955d1c4074ccd34639cae5d1234bbef645b34866bfd18f083dd80928618e80fb")); vFixedSeeds.clear(); //!< Regtest mode doesn't have any fixed seeds. vSeeds.clear(); //!< Regtest mode doesn't have any DNS seeds. diff --git a/src/chainparams.h b/src/chainparams.h index 9c6743b420..7bff5b93f6 100644 --- a/src/chainparams.h +++ b/src/chainparams.h @@ -8,6 +8,7 @@ #include #include +#include #include #include diff --git a/src/consensus/params.h b/src/consensus/params.h index a9dee5ccb6..7cb54bf3b1 100644 --- a/src/consensus/params.h +++ b/src/consensus/params.h @@ -97,6 +97,7 @@ struct Params { CAmount creationFee; CAmount collateralAmount; int activationDelay; + int resignDelay; int collateralUnlockDelay; int historyFrame; }; diff --git a/src/httprpc.cpp b/src/httprpc.cpp index 306d718574..c943f58c7a 100644 --- a/src/httprpc.cpp +++ b/src/httprpc.cpp @@ -7,7 +7,6 @@ #include #include #include -#include #include #include #include diff --git a/src/init.cpp b/src/init.cpp index bf101d7b17..fe9401e89e 100644 --- a/src/init.cpp +++ b/src/init.cpp @@ -25,7 +25,6 @@ #include #include #include -#include #include #include #include @@ -503,6 +502,7 @@ void SetupServerArgs() gArgs.AddArg("-debug=", "Output debugging information (default: -nodebug, supplying is optional). " "If is not supplied or if = 1, output all debugging information. can be: " + ListLogCategories() + ".", ArgsManager::ALLOW_ANY, OptionsCategory::DEBUG_TEST); gArgs.AddArg("-debugexclude=", strprintf("Exclude debugging information for a category. Can be used in conjunction with -debug=1 to output debug logs for all categories except one or more specified categories."), ArgsManager::ALLOW_ANY, OptionsCategory::DEBUG_TEST); + gArgs.AddArg("-gen", strprintf("Generate coins (default: %u)", DEFAULT_GENERATE), ArgsManager::ALLOW_ANY | ArgsManager::DEBUG_ONLY, OptionsCategory::DEBUG_TEST); gArgs.AddArg("-logips", strprintf("Include IP addresses in debug output (default: %u)", DEFAULT_LOGIPS), ArgsManager::ALLOW_ANY, OptionsCategory::DEBUG_TEST); gArgs.AddArg("-logtimestamps", strprintf("Prepend debug output with timestamp (default: %u)", DEFAULT_LOGTIMESTAMPS), ArgsManager::ALLOW_ANY, OptionsCategory::DEBUG_TEST); gArgs.AddArg("-logthreadnames", strprintf("Prepend debug output with name of the originating thread (only available on platforms supporting thread_local) (default: %u)", DEFAULT_LOGTHREADNAMES), ArgsManager::ALLOW_ANY, OptionsCategory::DEBUG_TEST); @@ -1835,54 +1835,56 @@ bool AppInitMain(InitInterfaces& interfaces) }, DUMP_BANS_INTERVAL * 1000); // ********************************************************* Step 14: start minter thread - pos::ThreadStaker::Args stakerParams{}; - { - CKey key; - std::vector> wallets = GetWallets(); - if (wallets.size() == 0) { - LogPrintf("Warning! wallets not found"); - return true; - } - std::shared_ptr defaultWallet = wallets[0]; + if(gArgs.GetBoolArg("-gen", DEFAULT_GENERATE)) { + LOCK(cs_main); - CTxDestination destination; + auto myIDs = pmasternodesview->AmIOperator(); + if (myIDs) + { + pos::ThreadStaker::Args stakerParams{}; + { + std::vector> wallets = GetWallets(); + if (wallets.size() == 0) { + LogPrintf("Warning! wallets not found\n"); + return true; + } + std::shared_ptr defaultWallet = wallets[0]; - std::string minterAddress = gArgs.GetArg("-minterAddress", ""); - if (minterAddress != "") { - destination = DecodeDestination(minterAddress); - if (!IsValidDestination(destination)) { - LogPrintf("Error: coinstake destination is invalid"); - return false; - } - } else { - std::string strErr; - if(!defaultWallet->GetNewDestination(OutputType::LEGACY, "", destination, strErr)) { - LogPrintf("%s\n", strErr); - return false; - } - } + CKey minterKey; + bool found =false; + for (auto&& wallet : wallets) { + if (wallet->GetKey(myIDs->operatorAuthAddress, minterKey)) { + found = true; + break; + } + } + if (!found) { + LogPrintf("Error: masternode operator private key not found\n"); + return false; + } - CScript coinbaseScript = GetScriptForDestination(destination); - CKey minterKey; - if (!defaultWallet->GetKey(CKeyID(*boost::get(&destination)), minterKey)) { - LogPrintf("Error: private key not found"); - return false; - } + CMasternode const & node = *pmasternodesview->ExistMasternode(myIDs->id); + CTxDestination destination = node.operatorType == 1 ? CTxDestination(PKHash(node.operatorAuthAddress)) : CTxDestination(WitnessV0KeyHash(node.operatorAuthAddress)); - stakerParams.coinbaseScript = coinbaseScript; - stakerParams.minterKey = minterKey; - } + CScript coinbaseScript = GetScriptForDestination(destination); - // Mint proof-of-stake blocks in background - threadGroup.create_thread([=]() { - TraceThread("CoinStaker", [=]() { - // Fill Staker Args + stakerParams.coinbaseScript = coinbaseScript; + stakerParams.minterKey = minterKey; + stakerParams.masternodeID = myIDs->id; + } + + // Mint proof-of-stake blocks in background + threadGroup.create_thread([=]() { + TraceThread("CoinStaker", [=]() { + // Fill Staker Args - // Run ThreadStaker - pos::ThreadStaker threadStaker{}; - threadStaker(stakerParams, chainparams); - }); - }); + // Run ThreadStaker + pos::ThreadStaker threadStaker{}; + threadStaker(stakerParams, chainparams); + }); + }); + } + } return true; } diff --git a/src/key_io.cpp b/src/key_io.cpp index c5ba83effb..8cf05702e8 100644 --- a/src/key_io.cpp +++ b/src/key_io.cpp @@ -2,10 +2,9 @@ // Distributed under the MIT software license, see the accompanying // file COPYING or http://www.opensource.org/licenses/mit-license.php. -#include - #include #include +#include #include