Skip to content
Permalink
Browse files

Merge pull request #846 from turtlecoin/remove_unused_code

Remove Legacy Unused Code
  • Loading branch information...
zpalmtree committed Jul 8, 2019
2 parents 7b2d693 + a7c3ba1 commit d025ef86f97216438bb96d9b53ca0e353ab29571
@@ -1,6 +1,6 @@
// Copyright (c) 2012-2017, The CryptoNote developers, The Bytecoin developers
// Copyright (c) 2014-2018, The Monero Project
// Copyright (c) 2018, The TurtleCoin Developers
// Copyright (c) 2018-2019, The TurtleCoin Developers
//
// Please see the included LICENSE file for more information.

@@ -50,14 +50,6 @@ bool Currency::init() {
return false;
}

if (isTestnet()) {
m_upgradeHeightV2 = 0;
m_upgradeHeightV3 = static_cast<uint32_t>(-1);
m_blocksFileName = "testnet_" + m_blocksFileName;
m_blockIndexesFileName = "testnet_" + m_blockIndexesFileName;
m_txPoolFileName = "testnet_" + m_txPoolFileName;
}

return true;
}

@@ -80,9 +72,7 @@ bool Currency::generateGenesisBlock() {
genesisBlockTemplate.minorVersion = BLOCK_MINOR_VERSION_0;
genesisBlockTemplate.timestamp = 0;
genesisBlockTemplate.nonce = 70;
if (m_testnet) {
++genesisBlockTemplate.nonce;
}

//miner::find_nonce_for_given_block(bl, 1, 0);
cachedGenesisBlock.reset(new CachedBlock(genesisBlockTemplate));
return true;
@@ -158,9 +148,6 @@ bool Currency::getBlockReward(uint8_t blockMajorVersion, size_t medianSize, size
assert(m_emissionSpeedFactor > 0 && m_emissionSpeedFactor <= 8 * sizeof(uint64_t));

uint64_t baseReward = (m_moneySupply - alreadyGeneratedCoins) >> m_emissionSpeedFactor;
if (alreadyGeneratedCoins == 0 && m_genesisBlockReward != 0) {
baseReward = m_genesisBlockReward;
}

size_t blockGrantedFullRewardZone = blockGrantedFullRewardZoneByBlockVersion(blockMajorVersion);
medianSize = std::max(medianSize, blockGrantedFullRewardZone);
@@ -654,11 +641,9 @@ m_upgradeWindow(currency.m_upgradeWindow),
m_blocksFileName(currency.m_blocksFileName),
m_blockIndexesFileName(currency.m_blockIndexesFileName),
m_txPoolFileName(currency.m_txPoolFileName),
m_genesisBlockReward(currency.m_genesisBlockReward),
m_zawyDifficultyBlockIndex(currency.m_zawyDifficultyBlockIndex),
m_zawyDifficultyV2(currency.m_zawyDifficultyV2),
m_zawyDifficultyBlockVersion(currency.m_zawyDifficultyBlockVersion),
m_testnet(currency.m_testnet),
genesisBlockTemplate(std::move(currency.genesisBlockTemplate)),
cachedGenesisBlock(new CachedBlock(genesisBlockTemplate)),
logger(currency.logger) {
@@ -676,12 +661,11 @@ CurrencyBuilder::CurrencyBuilder(std::shared_ptr<Logging::ILogger> log) : m_curr

moneySupply(parameters::MONEY_SUPPLY);
emissionSpeedFactor(parameters::EMISSION_SPEED_FACTOR);
genesisBlockReward(parameters::GENESIS_BLOCK_REWARD);

rewardBlocksWindow(parameters::CRYPTONOTE_REWARD_BLOCKS_WINDOW);
zawyDifficultyBlockIndex(parameters::ZAWY_DIFFICULTY_BLOCK_INDEX);
zawyDifficultyV2(parameters::ZAWY_DIFFICULTY_V2);
zawyDifficultyBlockVersion(parameters::ZAWY_DIFFICULTY_DIFFICULTY_BLOCK_VERSION);
zawyDifficultyBlockIndex(parameters::ZAWY_DIFFICULTY_BLOCK_INDEX);
zawyDifficultyV2(parameters::ZAWY_DIFFICULTY_V2);
zawyDifficultyBlockVersion(parameters::ZAWY_DIFFICULTY_DIFFICULTY_BLOCK_VERSION);
blockGrantedFullRewardZone(parameters::CRYPTONOTE_BLOCK_GRANTED_FULL_REWARD_ZONE);
minerTxBlobReservedSize(parameters::CRYPTONOTE_COINBASE_BLOB_RESERVED_SIZE);

@@ -722,8 +706,7 @@ zawyDifficultyBlockVersion(parameters::ZAWY_DIFFICULTY_DIFFICULTY_BLOCK_VERSION)
blockIndexesFileName(parameters::CRYPTONOTE_BLOCKINDEXES_FILENAME);
txPoolFileName(parameters::CRYPTONOTE_POOLDATA_FILENAME);

isBlockexplorer(false);
testnet(false);
isBlockexplorer(false);
}

Transaction CurrencyBuilder::generateGenesisTransaction() {
@@ -732,42 +715,7 @@ Transaction CurrencyBuilder::generateGenesisTransaction() {
m_currency.constructMinerTx(1, 0, 0, 0, 0, 0, ac, tx); // zero fee in genesis
return tx;
}
Transaction CurrencyBuilder::generateGenesisTransaction(const std::vector<AccountPublicAddress>& targets) {
assert(!targets.empty());

CryptoNote::Transaction tx;
tx.inputs.clear();
tx.outputs.clear();
tx.extra.clear();
tx.version = CURRENT_TRANSACTION_VERSION;
tx.unlockTime = m_currency.m_minedMoneyUnlockWindow;
KeyPair txkey = generateKeyPair();
addTransactionPublicKeyToExtra(tx.extra, txkey.publicKey);
BaseInput in;
in.blockIndex = 0;
tx.inputs.push_back(in);
uint64_t block_reward = m_currency.m_genesisBlockReward;
uint64_t target_amount = block_reward / targets.size();
uint64_t first_target_amount = target_amount + block_reward % targets.size();
for (size_t i = 0; i < targets.size(); ++i) {
Crypto::KeyDerivation derivation = boost::value_initialized<Crypto::KeyDerivation>();
Crypto::PublicKey outEphemeralPubKey = boost::value_initialized<Crypto::PublicKey>();
bool r = Crypto::generate_key_derivation(targets[i].viewPublicKey, txkey.secretKey, derivation);
if (r) {}
assert(r == true);
// CHECK_AND_ASSERT_MES(r, false, "while creating outs: failed to generate_key_derivation(" << targets[i].viewPublicKey << ", " << txkey.sec << ")");
r = Crypto::derive_public_key(derivation, i, targets[i].spendPublicKey, outEphemeralPubKey);
assert(r == true);
// CHECK_AND_ASSERT_MES(r, false, "while creating outs: failed to derive_public_key(" << derivation << ", " << i << ", " << targets[i].spendPublicKey << ")");
KeyOutput tk;
tk.key = outEphemeralPubKey;
TransactionOutput out;
out.amount = (i == 0) ? first_target_amount : target_amount;
out.target = tk;
tx.outputs.push_back(out);
}
return tx;
}

CurrencyBuilder& CurrencyBuilder::emissionSpeedFactor(unsigned int val) {
if (val <= 0 || val > 8 * sizeof(uint64_t)) {
throw std::invalid_argument("val at emissionSpeedFactor()");
@@ -1,6 +1,6 @@
// Copyright (c) 2012-2017, The CryptoNote developers, The Bytecoin developers
// Copyright (c) 2014-2018, The Monero Project
// Copyright (c) 2018, The TurtleCoin Developers
// Copyright (c) 2018-2019, The TurtleCoin Developers
//
// Please see the included LICENSE file for more information.

@@ -91,13 +91,13 @@ class Currency {

uint64_t difficultyTarget() const { return m_difficultyTarget; }
size_t difficultyWindow() const { return m_difficultyWindow; }
size_t difficultyWindowByBlockVersion(uint8_t blockMajorVersion) const;
size_t difficultyWindowByBlockVersion(uint8_t blockMajorVersion) const;
size_t difficultyLag() const { return m_difficultyLag; }
size_t difficultyLagByBlockVersion(uint8_t blockMajorVersion) const;
size_t difficultyLagByBlockVersion(uint8_t blockMajorVersion) const;
size_t difficultyCut() const { return m_difficultyCut; }
size_t difficultyCutByBlockVersion(uint8_t blockMajorVersion) const;
size_t difficultyCutByBlockVersion(uint8_t blockMajorVersion) const;
size_t difficultyBlocksCount() const { return m_difficultyWindow + m_difficultyLag; }
size_t difficultyBlocksCountByBlockVersion(uint8_t blockMajorVersion, uint32_t height) const;
size_t difficultyBlocksCountByBlockVersion(uint8_t blockMajorVersion, uint32_t height) const;

size_t maxBlockSizeInitial() const { return m_maxBlockSizeInitial; }
uint64_t maxBlockSizeGrowthSpeedNumerator() const { return m_maxBlockSizeGrowthSpeedNumerator; }
@@ -127,7 +127,6 @@ size_t difficultyBlocksCountByBlockVersion(uint8_t blockMajorVersion, uint32_t h
const std::string& txPoolFileName() const { return m_txPoolFileName; }

bool isBlockexplorer() const { return m_isBlockexplorer; }
bool isTestnet() const { return m_testnet; }

const BlockTemplate& genesisBlock() const { return cachedGenesisBlock->getBlock(); }
const Crypto::Hash& genesisBlockHash() const { return cachedGenesisBlock->getBlockHash(); }
@@ -230,9 +229,6 @@ size_t difficultyBlocksCountByBlockVersion(uint8_t blockMajorVersion, uint32_t h
std::string m_blockIndexesFileName;
std::string m_txPoolFileName;



bool m_testnet;
bool m_isBlockexplorer;

BlockTemplate genesisBlockTemplate;
@@ -256,7 +252,7 @@ class CurrencyBuilder : boost::noncopyable {
}

Transaction generateGenesisTransaction();
Transaction generateGenesisTransaction(const std::vector<AccountPublicAddress>& targets);

CurrencyBuilder& maxBlockNumber(uint32_t val) { m_currency.m_maxBlockHeight = val; return *this; }
CurrencyBuilder& maxBlockBlobSize(size_t val) { m_currency.m_maxBlockBlobSize = val; return *this; }
CurrencyBuilder& maxTxSize(size_t val) { m_currency.m_maxTxSize = val; return *this; }
@@ -315,7 +311,6 @@ class CurrencyBuilder : boost::noncopyable {
CurrencyBuilder& txPoolFileName(const std::string& val) { m_currency.m_txPoolFileName = val; return *this; }

CurrencyBuilder& isBlockexplorer(const bool val) { m_currency.m_isBlockexplorer = val; return *this; }
CurrencyBuilder& testnet(bool val) { m_currency.m_testnet = val; return *this; }

private:
Currency m_currency;
@@ -1,5 +1,5 @@
// Copyright (c) 2012-2017, The CryptoNote developers, The Bytecoin developers
// Copyright (c) 2018, The TurtleCoin Developers
// Copyright (c) 2018-2019, The TurtleCoin Developers
//
// Please see the included LICENSE file for more information.

@@ -22,7 +22,6 @@ DataBaseConfig::DataBaseConfig() :
maxOpenFiles(DATABASE_DEFAULT_MAX_OPEN_FILES),
writeBufferSize(DATABASE_WRITE_BUFFER_MB_DEFAULT_SIZE * MEGABYTE),
readCacheSize(DATABASE_READ_BUFFER_MB_DEFAULT_SIZE * MEGABYTE),
testnet(false),
configFolderDefaulted(false),
compressionEnabled(false) {
}
@@ -72,10 +71,6 @@ uint64_t DataBaseConfig::getReadCacheSize() const {
return readCacheSize;
}

bool DataBaseConfig::getTestnet() const {
return testnet;
}

bool DataBaseConfig::getCompressionEnabled() const {
return compressionEnabled;
}
@@ -1,5 +1,5 @@
// Copyright (c) 2012-2017, The CryptoNote developers, The Bytecoin developers
// Copyright (c) 2018, The TurtleCoin Developers
// Copyright (c) 2018-2019, The TurtleCoin Developers
//
// Please see the included LICENSE file for more information.

@@ -24,7 +24,6 @@ class DataBaseConfig {
uint32_t getMaxOpenFiles() const;
uint64_t getWriteBufferSize() const; //Bytes
uint64_t getReadCacheSize() const; //Bytes
bool getTestnet() const;
bool getCompressionEnabled() const;

private:
@@ -34,7 +33,6 @@ class DataBaseConfig {
uint32_t maxOpenFiles;
uint64_t writeBufferSize;
uint64_t readCacheSize;
bool testnet;
bool compressionEnabled;
};
} //namespace CryptoNote
@@ -1,19 +1,7 @@
// Copyright (c) 2012-2017, The CryptoNote developers, The Bytecoin developers
// Copyright (c) 2018-2019, The TurtleCoin Developers
//
// This file is part of Bytecoin.
//
// Bytecoin is free software: you can redistribute it and/or modify
// it under the terms of the GNU Lesser General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// Bytecoin is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU Lesser General Public License for more details.
//
// You should have received a copy of the GNU Lesser General Public License
// along with Bytecoin. If not, see <http://www.gnu.org/licenses/>.
// Please see the included LICENSE file for more information.

#include "RocksDBWrapper.h"

@@ -29,7 +17,6 @@ using namespace Logging;

namespace {
const std::string DB_NAME = "DB";
const std::string TESTNET_DB_NAME = "testnet_DB";
}

RocksDBWrapper::RocksDBWrapper(std::shared_ptr<Logging::ILogger> logger) : logger(logger, "RocksDBWrapper"), state(NOT_INITIALIZED){
@@ -220,9 +207,5 @@ rocksdb::Options RocksDBWrapper::getDBOptions(const DataBaseConfig& config) {
}

std::string RocksDBWrapper::getDataDir(const DataBaseConfig& config) {
if (config.getTestnet()) {
return config.getDataDir() + '/' + TESTNET_DB_NAME;
} else {
return config.getDataDir() + '/' + DB_NAME;
}
return config.getDataDir() + '/' + DB_NAME;
}
@@ -50,41 +50,14 @@ using namespace CryptoNote;
using namespace Logging;
using namespace DaemonConfig;

void print_genesis_tx_hex(const std::vector<std::string> rewardAddresses, const bool blockExplorerMode, std::shared_ptr<LoggerManager> logManager)
void print_genesis_tx_hex(const bool blockExplorerMode, std::shared_ptr<LoggerManager> logManager)
{
std::vector<CryptoNote::AccountPublicAddress> rewardTargets;

CryptoNote::CurrencyBuilder currencyBuilder(logManager);
currencyBuilder.isBlockexplorer(blockExplorerMode);

CryptoNote::Currency currency = currencyBuilder.currency();

for (const auto& rewardAddress : rewardAddresses)
{
CryptoNote::AccountPublicAddress address;
if (!currency.parseAccountAddressString(rewardAddress, address))
{
std::cout << "Failed to parse genesis reward address: " << rewardAddress << std::endl;
return;
}
rewardTargets.emplace_back(std::move(address));
}

CryptoNote::Transaction transaction;

if (rewardTargets.empty())
{
if (CryptoNote::parameters::GENESIS_BLOCK_REWARD > 0)
{
std::cout << "Error: Genesis Block Reward Addresses are not defined" << std::endl;
return;
}
transaction = CryptoNote::CurrencyBuilder(logManager).generateGenesisTransaction();
}
else
{
transaction = CryptoNote::CurrencyBuilder(logManager).generateGenesisTransaction(rewardTargets);
}
const auto transaction = CryptoNote::CurrencyBuilder(logManager).generateGenesisTransaction();

std::string transactionHex = Common::toHex(CryptoNote::toBinaryArray(transaction));
std::cout << getProjectCLIHeader() << std::endl << std::endl
@@ -130,7 +103,7 @@ int main(int argc, char* argv[])

if (config.printGenesisTx) // Do we weant to generate the Genesis Tx?
{
print_genesis_tx_hex(config.genesisAwardAddresses, false, logManager);
print_genesis_tx_hex(false, logManager);
exit(0);
}

@@ -43,7 +43,6 @@ namespace DaemonConfig{
("version","Output daemon version information",cxxopts::value<bool>()->default_value("false")->implicit_value("true"));

options.add_options("Genesis Block")
("genesis-block-reward-address", "Specify the address for any premine genesis block rewards", cxxopts::value<std::vector<std::string>>(), "<address>")
("print-genesis-tx", "Print the genesis block transaction hex and exits", cxxopts::value<bool>()->default_value("false")->implicit_value("true"));

options.add_options("Daemon")
@@ -103,11 +102,6 @@ namespace DaemonConfig{
config.outputFile = cli["save-config"].as<std::string>();
}

if (cli.count("genesis-block-reward-address") > 0)
{
config.genesisAwardAddresses = cli["genesis-block-reward-address"].as<std::vector<std::string>>();
}

if (cli.count("help") > 0)
{
config.help = cli["help"].as<bool>();
@@ -380,12 +380,8 @@ std::string print_peerlist_to_string(const std::list<PeerlistEntry>& pl) {
//-----------------------------------------------------------------------------------

bool NodeServer::init(const NetNodeConfig& config) {
if (!config.getTestnet()) {
for (auto seed : CryptoNote::SEED_NODES) {
append_net_address(m_seed_nodes, seed);
}
} else {
m_network_id.data[0] += 1;
for (const auto &seed : CryptoNote::SEED_NODES) {
append_net_address(m_seed_nodes, seed);
}

if (!handleConfig(config)) {
@@ -57,7 +57,6 @@ NetNodeConfig::NetNodeConfig() {
allowLocalIp = false;
hideMyPort = false;
configFolder = Tools::getDefaultDataDirectory();
testnet = false;
p2pStateReset = false;
}

@@ -111,17 +110,9 @@ bool NetNodeConfig::init(const std::string interface, const int port, const int
}

std::string NetNodeConfig::getP2pStateFilename() const {
if (testnet) {
return "testnet_" + p2pStateFilename;
}

return p2pStateFilename;
}

bool NetNodeConfig::getTestnet() const {
return testnet;
}

bool NetNodeConfig::getP2pStateReset() const {
return p2pStateReset;
}

0 comments on commit d025ef8

Please sign in to comment.
You can’t perform that action at this time.