Skip to content
Permalink
Browse files

Remove premine code that is not used in the project

  • Loading branch information...
brandonlehmann committed Jul 8, 2019
1 parent 3e55752 commit a7c3ba17db5aebb4ec7531ecfd1c29deda89eb7f
@@ -148,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);
@@ -644,7 +641,6 @@ 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),
@@ -665,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);

@@ -720,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()");
@@ -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; }
@@ -252,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; }
@@ -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,7 +380,7 @@ std::string print_peerlist_to_string(const std::list<PeerlistEntry>& pl) {
//-----------------------------------------------------------------------------------

bool NodeServer::init(const NetNodeConfig& config) {
for (auto seed : CryptoNote::SEED_NODES) {
for (const auto &seed : CryptoNote::SEED_NODES) {
append_net_address(m_seed_nodes, seed);
}

@@ -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.

@@ -44,29 +44,6 @@ const uint64_t LWMA_2_DIFFICULTY_BLOCK_INDEX_V3 = 800000;
const unsigned EMISSION_SPEED_FACTOR = 25;
static_assert(EMISSION_SPEED_FACTOR <= 8 * sizeof(uint64_t), "Bad EMISSION_SPEED_FACTOR");

/* Premine amount */
const uint64_t GENESIS_BLOCK_REWARD = UINT64_C(0);

/* How to generate a premine:
* Compile your code
* Run zedwallet, ignore that it can't connect to the daemon, and generate an
address. Save this and the keys somewhere safe.
* Launch the daemon with these arguments:
--print-genesis-tx --genesis-block-reward-address <premine wallet address>
For example:
TurtleCoind --print-genesis-tx --genesis-block-reward-address TRTLv2Fyavy8CXG8BPEbNeCHFZ1fuDCYCZ3vW5H5LXN4K2M2MHUpTENip9bbavpHvvPwb4NDkBWrNgURAd5DB38FHXWZyoBh4wW
* Take the hash printed, and replace it with the hash below in GENESIS_COINBASE_TX_HEX
* Recompile, setup your seed nodes, and start mining
* You should see your premine appear in the previously generated wallet.
*/
const char GENESIS_COINBASE_TX_HEX[] = "010a01ff000188f3b501029b2e4c0281c0b02e7c53291a94d1d0cbff8883f8024f5142ee494ffbbd088071210142694232c5b04151d9e4c27d31ec7a68ea568b19488cfcb422659a07a0e44dd5";
static_assert(sizeof(GENESIS_COINBASE_TX_HEX)/sizeof(*GENESIS_COINBASE_TX_HEX) != 1, "GENESIS_COINBASE_TX_HEX must not be empty.");

0 comments on commit a7c3ba1

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