Bitcoin Forum
May 13, 2024, 08:18:49 PM *
News: Latest Bitcoin Core release: 27.0 [Torrent]
 
   Home   Help Search Login Register More  
Pages: [1]
  Print  
Author Topic: Change genesis block, regtest mining fail  (Read 229 times)
victorkimba17 (OP)
Jr. Member
*
Offline Offline

Activity: 113
Merit: 5


View Profile
August 06, 2018, 02:22:22 AM
 #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 ?
1715631529
Hero Member
*
Offline Offline

Posts: 1715631529

View Profile Personal Message (Offline)

Ignore
1715631529
Reply with quote  #2

1715631529
Report to moderator
The Bitcoin network protocol was designed to be extremely flexible. It can be used to create timed transactions, escrow transactions, multi-signature transactions, etc. The current features of the client only hint at what will be possible in the future.
Advertised sites are not endorsed by the Bitcoin Forum. They may be unsafe, untrustworthy, or illegal in your jurisdiction.
1715631529
Hero Member
*
Offline Offline

Posts: 1715631529

View Profile Personal Message (Offline)

Ignore
1715631529
Reply with quote  #2

1715631529
Report to moderator
achow101
Moderator
Legendary
*
expert
Offline Offline

Activity: 3388
Merit: 6635


Just writing some code


View Profile WWW
August 06, 2018, 04:33:44 AM
Merited by gmaxwell (1)
 #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).

victorkimba17 (OP)
Jr. Member
*
Offline Offline

Activity: 113
Merit: 5


View Profile
August 06, 2018, 05: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 ?
TheArchaeologist
Sr. Member
****
Offline Offline

Activity: 310
Merit: 727


---------> 1231006505


View Profile WWW
August 06, 2018, 07: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"
}

Sooner or later you're going to realize, just as I did, that there's a difference between knowing the path and walking the path
victorkimba17 (OP)
Jr. Member
*
Offline Offline

Activity: 113
Merit: 5


View Profile
August 06, 2018, 08: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?
victorkimba17 (OP)
Jr. Member
*
Offline Offline

Activity: 113
Merit: 5


View Profile
August 06, 2018, 01:14:38 PM
 #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
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!