Bitcoin Forum
June 01, 2024, 02:25:20 PM *
News: Latest Bitcoin Core release: 27.0 [Torrent]
 
   Home   Help Search Login Register More  
Pages: [1]
  Print  
Author Topic: How to add premine in the bitcoin source  (Read 164 times)
vanshtah (OP)
Newbie
*
Offline Offline

Activity: 12
Merit: 1


View Profile
February 04, 2020, 01:02:38 AM
Merited by Quickseller (1)
 #1

Hello all, I am learning about bitcoin development, a created a new genesis, I compiled it and i got the windows, Linux and mac wallet running pretty well. Now I also want to add premine to the source code and with some searches in the google I found a solution to it.

In validation.cpp #L1041

Code:
CAmount GetBlockSubsidy(int nHeight, const Consensus::Params& consensusParams)
{
    int halvings = nHeight / consensusParams.nSubsidyHalvingInterval;
    // Force block reward to zero when right shift is undefined.
    if (halvings >= 64)
        return 0;
    CAmount nSubsidy = 50 * COIN;
    if(nHeight == 4) 
    {
        nSubsidy = 1000000000 * COIN;
        return nSubsidy;
    }
    // Subsidy is cut in half every 210,000 blocks which will occur approximately every 4 years.
    nSubsidy >>= halvings;
    return nSubsidy;
}

I start the mining I got the coins but I cannot spend it, do anyone has a solution to it
nc50lc
Legendary
*
Offline Offline

Activity: 2436
Merit: 5665


Self-proclaimed Genius


View Profile
February 04, 2020, 02:54:08 AM
 #2

-snip-
I start the mining I got the coins but I cannot spend it, do anyone has a solution to it
It needs to have at least 100 confirmations to be spendable.
In other words, you need to mine another 100 blocks.

█▀▀▀











█▄▄▄
▀▀▀▀▀▀▀▀▀▀▀
e
▄▄▄▄▄▄▄▄▄▄▄
█████████████
████████████▄███
██▐███████▄█████▀
█████████▄████▀
███▐████▄███▀
████▐██████▀
█████▀█████
███████████▄
████████████▄
██▄█████▀█████▄
▄█████████▀█████▀
███████████▀██▀
████▀█████████
▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀
c.h.
▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄
▀▀▀█











▄▄▄█
▄██████▄▄▄
█████████████▄▄
███████████████
███████████████
███████████████
███████████████
███░░█████████
███▌▐█████████
█████████████
███████████▀
██████████▀
████████▀
▀██▀▀
vanshtah (OP)
Newbie
*
Offline Offline

Activity: 12
Merit: 1


View Profile
February 04, 2020, 03:39:01 AM
 #3

-snip-
I start the mining I got the coins but I cannot spend it, do anyone has a solution to it
It needs to have at least 100 confirmations to be spendable.
In other words, you need to mine another 100 blocks.
I have mined 1000 blocks but still cannot spend it. I enabled the advanced wallet input control feature from the QT wallet and tried selective input to do a transaction but it is unconfirmed. There are 100 new blocks mined and still going on
nc50lc
Legendary
*
Offline Offline

Activity: 2436
Merit: 5665


Self-proclaimed Genius


View Profile
February 04, 2020, 04:04:54 AM
 #4

Hmm no confirmations, maybe because of the current value of MAX_MONEY (master/src/amount.h) which is equal to the maximum "mineable" coins, not the actual value for max bitcoins.
The premine output exceeded the MAX_MONEY which makes those coinbase transactions with 1Billion BTC output invalid.

█▀▀▀











█▄▄▄
▀▀▀▀▀▀▀▀▀▀▀
e
▄▄▄▄▄▄▄▄▄▄▄
█████████████
████████████▄███
██▐███████▄█████▀
█████████▄████▀
███▐████▄███▀
████▐██████▀
█████▀█████
███████████▄
████████████▄
██▄█████▀█████▄
▄█████████▀█████▀
███████████▀██▀
████▀█████████
▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀
c.h.
▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄
▀▀▀█











▄▄▄█
▄██████▄▄▄
█████████████▄▄
███████████████
███████████████
███████████████
███████████████
███░░█████████
███▌▐█████████
█████████████
███████████▀
██████████▀
████████▀
▀██▀▀
vanshtah (OP)
Newbie
*
Offline Offline

Activity: 12
Merit: 1


View Profile
February 04, 2020, 04:08:59 AM
Last edit: February 04, 2020, 04:26:01 AM by vanshtah
 #5

Hmm no confirmations, maybe because of the current value of MAX_MONEY (master/src/amount.h) which is equal to the maximum "mineable" coins.
The premine output exceeded the MAX_MONEY which makes those coinbase transactions with 1Billion BTC output invalid.

Updated that too

Code:
static const CAmount MAX_MONEY = 10000000000 * COIN;

Block 4 details

Code:
{
    "hash": "e8f6528f802bc3ada6d258983b6a573a2fe3534231d01c56defaac7040c0e926",
    "confirmations": 1478,
    "strippedsize": 216,
    "size": 216,
    "weight": 864,
    "height": 4,
    "version": 536870912,
    "versionHex": "20000000",
    "merkleroot": "c888967eedfb202a3f7f075c0a5602006dde4e153c40dea8742afccbb2ab4a70",
    "tx": "See 'Transaction IDs'",
    "time": 1580260378,
    "mediantime": 1580259876,
    "nonce": 55920,
    "bits": "1e0ffff0",
    "difficulty": 0.000244140625,
    "chainwork": "0000000000000000000000000000000000000000000000000000000000500050",
    "previousblockhash": "409c8ef479727dd5e183855ae7820042bfe7133b06e57f8810f4b6898a4a2711",
    "nextblockhash": "c8d0f2f55e7aaf21e8637d420556bb932281151d6f39741d6c499310f8185261",
    "coinbaseTx": {
        "txid": "c888967eedfb202a3f7f075c0a5602006dde4e153c40dea8742afccbb2ab4a70",
        "hash": "c888967eedfb202a3f7f075c0a5602006dde4e153c40dea8742afccbb2ab4a70",
        "version": 2,
        "size": 135,
        "vsize": 135,
        "locktime": 0,
        "vin": [
            {
                "coinbase": "540107",
                "sequence": 4294967295
            }
        ],
        "vout": [
            {
                "value": "1000000000.00000000",
                "n": 0,
                "scriptPubKey": {
                    "asm": "OP_DUP OP_HASH160 72563c4d79d5f410805691e233e5d4083f33a8cf OP_EQUALVERIFY OP_CHECKSIG",
                    "hex": "76a91472563c4d79d5f410805691e233e5d4083f33a8cf88ac",
                    "reqSigs": 1,
                    "type": "pubkeyhash",
                    "addresses": [
                        "ASCRz7q4RzWNjyZfD4Rrg214Y3CU57pa9v"
                    ]
                }
            },
            {
                "value": 0,
                "n": 1,
                "scriptPubKey": {
                    "asm": "OP_RETURN aa21a9ede2f61c3f71d1defd3fa999dfa36953755c690689799962b48bebd836974e8cf9",
                    "hex": "6a24aa21a9ede2f61c3f71d1defd3fa999dfa36953755c690689799962b48bebd836974e8cf9",
                    "type": "nulldata"
                }
            }
        ],
        "hex": "02000000010000000000000000000000000000000000000000000000000000000000000000ffffffff03540107ffffffff0200008a5d784563011976a91472563c4d79d5f410805691e233e5d4083f33a8cf88ac0000000000000000266a24aa21a9ede2f61c3f71d1defd3fa999dfa36953755c690689799962b48bebd836974e8cf900000000",
        "blockhash": "e8f6528f802bc3ada6d258983b6a573a2fe3534231d01c56defaac7040c0e926",
        "confirmations": 1478,
        "time": 1580260378,
        "blocktime": 1580260378
    },
    "totalFees": "999999950",
    "miner": null
}
Heisenberg_Hunter
Legendary
*
Offline Offline

Activity: 1583
Merit: 1278


Heisenberg Design Services


View Profile WWW
February 06, 2020, 07:31:00 PM
 #6

Guess I have answered a question of yours about building litecoin wallet way back in September last year. If you are running a cloned copy of original bitcoin code (I assume you are doing the same) you wouldn't be able to spend the genesis block coins. This was a feature which was included right from the original code by satoshi himself. If satoshi was to spend the coins from genesis block, the nodes would reject such a transaction today and this is how it was programmed. To make the genesis block coins spendable, you should probably try this out :

As for the latest version of Bitcoin Core 0.19.0.1 is concerned, the code for making the genesis block spendable is available in validation.cpp #L1936

Code:
 // Special case for the genesis block, skipping connection of its transactions
    // (its coinbase is unspendable)
    if (block.GetHash() == chainparams.GetConsensus().hashGenesisBlock) {
        if (!fJustCheck)
            view.SetBestBlock(pindex->GetBlockHash());
        return true;
    }

Delete the return true; piece of line or comment the whole line. Last year, I got to read a post from stackexchange which indeed made the genesis block spendable via a fork. Will try to search them up and provide for reference.

Until then, try the above one to see if you could spend your coins.
nc50lc
Legendary
*
Offline Offline

Activity: 2436
Merit: 5665


Self-proclaimed Genius


View Profile
February 07, 2020, 04:18:17 AM
 #7

The problem is that the coinbase transaction that he's trying to spend isn't the genesis block's.
He specifically set the block at height 4 to have a 1,000,000,000BTC reward and he's unable to spend it.

I can only suggest him to try it with 'regtest' first but I suppose he already did that.

█▀▀▀











█▄▄▄
▀▀▀▀▀▀▀▀▀▀▀
e
▄▄▄▄▄▄▄▄▄▄▄
█████████████
████████████▄███
██▐███████▄█████▀
█████████▄████▀
███▐████▄███▀
████▐██████▀
█████▀█████
███████████▄
████████████▄
██▄█████▀█████▄
▄█████████▀█████▀
███████████▀██▀
████▀█████████
▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀
c.h.
▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄
▀▀▀█











▄▄▄█
▄██████▄▄▄
█████████████▄▄
███████████████
███████████████
███████████████
███████████████
███░░█████████
███▌▐█████████
█████████████
███████████▀
██████████▀
████████▀
▀██▀▀
Pages: [1]
  Print  
 
Jump to:  

Powered by MySQL Powered by PHP Powered by SMF 1.1.19 | SMF © 2006-2009, Simple Machines Valid XHTML 1.0! Valid CSS!