Author

Topic: Change genesis block, regtest mining fail (Read 251 times)

jr. member
Activity: 113
Merit: 5
August 06, 2018, 08:14:38 AM
#6
i generate the unix time, nonce from scratch, for regtest , now mining is working.

previously, i re-use the unix time, nonce that are generated for mainnet , in regtest. For that, mining wasn't working
jr. member
Activity: 113
Merit: 5
August 06, 2018, 03:58:58 AM
#5
You could always compare your generated block with the actual genesis block:

Code:
0100000000000000000000000000000000000000000000000000000000000000000000003ba3edfd7a7b12b27ac72c3e67768f617fc81bc3888a51323a9fb8aa4b1e5e4a29ab5f49ffff001d1dac2b7c0101000000010000000000000000000000000000000000000000000000000000000000000000ffffffff4d04ffff001d0104455468652054696d65732030332f4a616e2f32303039204368616e63656c6c6f72206f6e206272696e6b206f66207365636f6e64206261696c6f757420666f722062616e6b73ffffffff0100f2052a01000000434104678afdb0fe5548271967f1a67130b7105cd6a828e03909a67962e0ea1f61deb649f6bc3f4cef38c4f35504e51ec112de5c384df7ba0b8d578a4c702b6bf11d5fac00000000
May i know how to compare the generated block to actual genesis block? Comparing the hash of the block?

Quote
Or when looking for specific values in a human readable fornat:

Code:
{
  "hash": "000000000019d6689c085ae165831e934ff763ae46a2a6c172b3f1b60a8ce26f",
  "ver": 1,
  "prev_block": "0000000000000000000000000000000000000000000000000000000000000000",
  "mrkl_root": "4a5e1e4baab89f3a32518a88c31bc87f618f76673e2cc77ab2127b7afdeda33b",
  "time": 1231006505,
  "bits": 486604799,
  "nonce": 2083236893,
  "n_tx": 1,
  "size": 285,
  "tx": [
    {
      "hash": "4a5e1e4baab89f3a32518a88c31bc87f618f76673e2cc77ab2127b7afdeda33b",
      "ver": 1,
      "vin_sz": 1,
      "vout_sz": 1,
      "lock_time": 0,
      "size": 204,
      "in": [
        {
          "prev_out": {
            "hash": "0000000000000000000000000000000000000000000000000000000000000000",
            "n": 4294967295
          },
          "coinbase": "04ffff001d0104455468652054696d65732030332f4a616e2f32303039204368616e63656c6c6f72206f6e206272696e6b206f66207365636f6e64206261696c6f757420666f722062616e6b73"
        }
      ],
      "out": [
        {
          "value": "50.00000000",
          "scriptPubKey": "04678afdb0fe5548271967f1a67130b7105cd6a828e03909a67962e0ea1f61deb649f6bc3f4cef38c4f35504e51ec112de5c384df7ba0b8d578a4c702b6bf11d5f OP_CHECKSIG"
        }
      ],
      "nid": "c2151f94f6ca6cecbe5d17cd12aaa40e5b1571ca10da82f2f5bcdb6205dcad6a"
    }
  ],
  "mrkl_tree": [
    "4a5e1e4baab89f3a32518a88c31bc87f618f76673e2cc77ab2127b7afdeda33b"
  ],
  "next_block": "00000000839a8e6886ab5951d76f411475428afc90947ee320161bbf18eb6048"
}
what is the command to generate the info above?
sr. member
Activity: 310
Merit: 727
---------> 1231006505
August 06, 2018, 02:14:38 AM
#4
You could always compare your generated block with the actual genesis block:

Code:
0100000000000000000000000000000000000000000000000000000000000000000000003ba3edfd7a7b12b27ac72c3e67768f617fc81bc3888a51323a9fb8aa4b1e5e4a29ab5f49ffff001d1dac2b7c0101000000010000000000000000000000000000000000000000000000000000000000000000ffffffff4d04ffff001d0104455468652054696d65732030332f4a616e2f32303039204368616e63656c6c6f72206f6e206272696e6b206f66207365636f6e64206261696c6f757420666f722062616e6b73ffffffff0100f2052a01000000434104678afdb0fe5548271967f1a67130b7105cd6a828e03909a67962e0ea1f61deb649f6bc3f4cef38c4f35504e51ec112de5c384df7ba0b8d578a4c702b6bf11d5fac00000000

Or when looking for specific values in a human readable fornat:

Code:
{
  "hash": "000000000019d6689c085ae165831e934ff763ae46a2a6c172b3f1b60a8ce26f",
  "ver": 1,
  "prev_block": "0000000000000000000000000000000000000000000000000000000000000000",
  "mrkl_root": "4a5e1e4baab89f3a32518a88c31bc87f618f76673e2cc77ab2127b7afdeda33b",
  "time": 1231006505,
  "bits": 486604799,
  "nonce": 2083236893,
  "n_tx": 1,
  "size": 285,
  "tx": [
    {
      "hash": "4a5e1e4baab89f3a32518a88c31bc87f618f76673e2cc77ab2127b7afdeda33b",
      "ver": 1,
      "vin_sz": 1,
      "vout_sz": 1,
      "lock_time": 0,
      "size": 204,
      "in": [
        {
          "prev_out": {
            "hash": "0000000000000000000000000000000000000000000000000000000000000000",
            "n": 4294967295
          },
          "coinbase": "04ffff001d0104455468652054696d65732030332f4a616e2f32303039204368616e63656c6c6f72206f6e206272696e6b206f66207365636f6e64206261696c6f757420666f722062616e6b73"
        }
      ],
      "out": [
        {
          "value": "50.00000000",
          "scriptPubKey": "04678afdb0fe5548271967f1a67130b7105cd6a828e03909a67962e0ea1f61deb649f6bc3f4cef38c4f35504e51ec112de5c384df7ba0b8d578a4c702b6bf11d5f OP_CHECKSIG"
        }
      ],
      "nid": "c2151f94f6ca6cecbe5d17cd12aaa40e5b1571ca10da82f2f5bcdb6205dcad6a"
    }
  ],
  "mrkl_tree": [
    "4a5e1e4baab89f3a32518a88c31bc87f618f76673e2cc77ab2127b7afdeda33b"
  ],
  "next_block": "00000000839a8e6886ab5951d76f411475428afc90947ee320161bbf18eb6048"
}
jr. member
Activity: 113
Merit: 5
August 06, 2018, 12:39:41 AM
#3
Because the genesis block actually has to be mined. It must have a valid proof of work, you cannot just make a genesis block that fails the consensus rules (except for the prevblock rule).

I used the program genesisgen to mine the genesis block , and put the information , such as, nBits, nonce , unix time , into CreateGenesisBlock() function.

May i know what is still missing ?
staff
Activity: 3458
Merit: 6793
Just writing some code
August 05, 2018, 11:33:44 PM
#2
Because the genesis block actually has to be mined. It must have a valid proof of work, you cannot just make a genesis block that fails the consensus rules (except for the prevblock rule).
jr. member
Activity: 113
Merit: 5
August 05, 2018, 09:22:22 PM
#1
after i change genesis block in chainparams.cpp, i do mining in regtest mode.

Quote
$ bitcoin-cli -datadir=../datadir2/  generate 101
[
]
the return result is empty. However, i can see new blocks created in debug.log

Quote
CreateNewBlock(): block weight: 900 txs: 0 fees: 0 sigops 400
2018-08-02 08:15:24   nProofOfWorkLimit = 545259519  before bounds
2018-08-02 08:15:24   nProofOfWorkLimit = 545259519  before bounds
2018-08-02 08:15:24   nProofOfWorkLimit = 545259519  before bounds

i found out the reason , in regtest mode, after changing the genesis block, in bitcoin core mining.cpp, generateBlocks() call CheckProofOfWork(), the parameter passed to the function, includes hash value of block, so in CheckProofOfWork() , the line `if (UintToArith256(hash) > bnTarget)`   is fulfilled and returns false, so mining fails.

Why changing of genesis block causing mining to fail in regtest ?
Jump to: