Go-ethereum: Custom Genesis file working anyone? I'm always getting "wrong genesis block in database"

Created on 19 Apr 2017  Â·  33Comments  Â·  Source: ethereum/go-ethereum

System information

Geth
Version: 1.6.0-stable
Git Commit: facc47cb5cec97b22c815a0a6118816a98f39876
Architecture: amd64
Protocol Versions: [63 62]
Network Id: 1
Go Version: go1.8.1
Operating System: darwin
GOPATH=/Users/aroba/golang
GOROOT=/usr/local/opt/go/libexec

Expected behaviour

I'm trying to setup a custom genesis file but I'm always getting an error

Actual behaviour

Steps to reproduce the behaviour

I start by creating an empty folder

mkdir ~/ethcustgen

I then create a new account

geth --datadir ~/ethcustgen account new

It returns the new account address

Address: {133ded6da4e99fa9e37d75cbc9e8cba18a9a7796}

I then use this address to update a custom genesis file with the same structure as described here:
https://github.com/ethereum/go-ethereum/wiki/Private-network

{
  "config": {
    "chainId": 15,
    "homesteadBlock": 0,
    "eip155Block": 0,
    "eip158Block": 0
  },
  "gasLimit": "210000",
  "difficulty": "20000",
  "alloc": {
    "133ded6da4e99fa9e37d75cbc9e8cba18a9a7796": {
      "balance": "100000000000"
    }
  }
}

I then try to init the genesis file

geth --datadir ~/ethcustgen init genesis.json

But I'm always getting this error:

INFO [04-19|22:18:07] Allocated cache and file handles         database=/Users/aroba/ethdev/geth/chaindata cache=128 handles=1024
Fatal: failed to write genesis block: wrong genesis block in database (have 586de193ebaabec0, new f7d53e3591742e44)

any idea

Backtrace

[backtrace]

Most helpful comment

The error messages states that your chain data already was inited with a genesis block and you are trying to overwrite it with a different one. This might lead to loss of data, and hence is prohibited (starting from Geth 1.6.0). You cannot reinit a chain with a different genesis unless you delete your old chaindata first.

I'll leave this issue open though as quite a lot of people hung up on this so we should probably have a better error message there.

All 33 comments

in your init it looks like you are trying to init a file in the ~/ethdev folder when you just put your file in ~/ethcustgen?

according the error, there is already a genesis block in the ~/ethdev.Whether you have already run this command geth --datadir ~/ethdev before?

Thanks for the quick reply.

Yes, I did it to generate the account I use to inject in the genesis file for the initial allocation of ethereum.

@joeb000 You are right. Its a typo while writing the issue. It was late I was tired, sorry :)
I corrected the issue description.

The error messages states that your chain data already was inited with a genesis block and you are trying to overwrite it with a different one. This might lead to loss of data, and hence is prohibited (starting from Geth 1.6.0). You cannot reinit a chain with a different genesis unless you delete your old chaindata first.

I'll leave this issue open though as quite a lot of people hung up on this so we should probably have a better error message there.

I am also getting this error but under different circumstances.

genesis.json:

{
    "nonce": "0x0000000000000042",
    "timestamp": "0x00",
    "parentHash": "0x0000000000000000000000000000000000000000000000000000000000000000",
    "extraData": "0x00",
    "gasLimit": "0x8000000",
    "difficulty": "0x0400",
    "mixhash": "0x0000000000000000000000000000000000000000000000000000000000000000",
    "coinbase": "0x3333333333333333333333333333333333333333",
    "alloc": {
    },
    "config": {
        "chainId": 3141,
        "homesteadBlock": 0,
        "eip155Block": 0,
        "eip158Block": 0
    }
}

First I run geth --datadir=~/eth/data init genesis.json and it completes successfully:

WARN [05-09|14:41:01] No etherbase set and no accounts found as default
INFO [05-09|14:41:01] Allocated cache and file handles database=/home/corey/eth/data/geth/chaindata cache=128 handles=1024
INFO [05-09|14:41:02] Writing custom genesis block
INFO [05-09|14:41:02] Successfully wrote genesis state hash=6650a0…b5c158

Then I run
geth --testnet --networkid 3141 --ipcdisable --rpc --rpcapi "db,eth,net,web3" --rpcport "8545" --rpccorsdomain "*" --datadir "~/eth/data" --port "30303" --nat "any" --identity "MyNode-1" --rpcaddr "0.0.0.0" --gasprice 0 console
and get the output:

WARN [05-09|14:42:33] No etherbase set and no accounts found as default
INFO [05-09|14:42:33] Starting peer-to-peer node instance=Geth/CybercarNode-1/v1.6.0-stable-facc47cb/linux-amd64/go1.8.1
INFO [05-09|14:42:33] Allocated cache and file handles database=/home/corey/eth/data/geth/chaindata cache=128 handles=1024
WARN [05-09|14:42:33] Upgrading chain database to use sequential keys
INFO [05-09|14:42:33] Database conversion successful
Fatal: Error starting protocol stack: wrong genesis block in database (have 6650a0ac6c5e8054, new 41941023680923e0)

I do not see how I'm initializing the blockchain twice. I'm not trying to create an account or anything before running init and the second thing I run is all about starting up the node and shouldn't be trying to create anything new.

I just updated to 1.6.1 and I have the more detailed output saying Error starting protocol stack: database already contains an incompatible genesis block (have 6650a0ac6c5e8054, new e5be92145a301820) but I don't have a clue what's incompatible.

Don't use --testnet, that forces Ropsten

On May 10, 2017 02:15, "coreyog" notifications@github.com wrote:

I just updated to 1.6.1 and I have the more detailed output saying Error
starting protocol stack: database already contains an incompatible genesis
block (have 6650a0ac6c5e8054, new e5be92145a301820) but I don't have a
clue what's incompatible.

—
You are receiving this because you modified the open/close state.
Reply to this email directly, view it on GitHub
https://github.com/ethereum/go-ethereum/issues/14352#issuecomment-300328193,
or mute the thread
https://github.com/notifications/unsubscribe-auth/AAH6GQoZiNOUS1HSoVLlWa-3VP7tzOieks5r4PORgaJpZM4NCMRH
.

I switched from --testnet to --dev and get the same error. I removed it entirely and the node started successfully. Is it possible to use either of those flags and specify a genesis block?

@coreyog It basically says there is already info in DB about an other blockchain, clean db by calling : geth removedb

@coreyog met the same problem, still don't know how to solve it

@Othmanbench geth removedb won't work, I just tried

I am having same issue.

rm -r /tmp/ethereum_dev_mode/geth
geth --dev init ./genesis.json
INFO [05-24|22:40:59] Allocated cache and file handles database=/tmp/ethereum_dev_mode/geth/chaindata cache=16 handles=16
INFO [05-24|22:40:59] Writing custom genesis block
INFO [05-24|22:40:59] Successfully wrote genesis state database=chaindata hash=07bba7…ec6e53
INFO [05-24|22:40:59] Allocated cache and file handles database=/tmp/ethereum_dev_mode/geth/lightchaindata cache=16 handles=16
INFO [05-24|22:40:59] Writing custom genesis block
INFO [05-24|22:40:59] Successfully wrote genesis state database=lightchaindata hash=07bba7…ec6e53

geth --dev --ipcdisable --rpc --rpcapi="db,eth,net,web3,personal,miner,admin" --networkid 777
INFO [05-24|22:41:08] Starting peer-to-peer node instance=Geth/v1.6.1-stable-021c3c28/linux-amd64/go1.8.1
INFO [05-24|22:41:08] Allocated cache and file handles database=/tmp/ethereum_dev_mode/geth/chaindata cache=128 handles=1024
WARN [05-24|22:41:08] Upgrading chain database to use sequential keys
INFO [05-24|22:41:08] Database conversion successful
Fatal: Error starting protocol stack: database already contains an incompatible genesis block (have 07bba7d17bb42ee0, new e5be92145a301820)

Same problem here, stuck... :-)

I am having the same problem for my local private network. Normally, I was first initiating geth with a genesis block without any accounts, then creating some accounts and go back to the genesis file and add some initial ethers in these accounts. It was working without any problem when I go back to geth.

Now, if I delete the chain data, as suggested above, how can I create accounts and add some balances to them?

{
"config": {
"chainId": 15,
"homesteadBlock": 0,
"eip155Block": 0,
"eip158Block": 0
},
"gasLimit": "210000",
"difficulty": "20000",
"alloc": {

}
}

I am using this info in custom genesis.json file. It is initialising blockchain as below:

WARN [06-05|17:03:31] No etherbase set and no accounts found as default
INFO [06-05|17:03:31] Allocated cache and file handles database=/Users/ceino/TestEthereum/Block1/geth/chaindata cache=16 handles=16
INFO [06-05|17:03:31] Writing custom genesis block
INFO [06-05|17:03:31] Successfully wrote genesis state database=chaindata hash=614a31…9df7ba
INFO [06-05|17:03:31] Allocated cache and file handles database=/Users/ceino/TestEthereum/Block1/geth/lightchaindata cache=16 handles=16
INFO [06-05|17:03:31] Writing custom genesis block
INFO [06-05|17:03:31] Successfully wrote genesis state database=lightchaindata hash=614a31…9df7ba

But when I fire miner command at console, mining is not accomplished accordingly.
Output is:

miner.start(1)
INFO [06-05|17:04:30] Updated mining threads threads=1
INFO [06-05|17:04:30] Starting mining operation
null
INFO [06-05|17:04:30] Commit new mining work number=1 txs=0 uncles=0 elapsed=382.689µs

as you see miner.start(1) returns null

So what else data I need to add to genesis file and in what format so that it should start mining.

If Anyone having idea about this....plz help me...It is my humble request.
Any help is appreciable.....Thanks in advance

"Solved" (???) error
Fatal: Error starting protocol stack: database already contains an incompatible genesis block (have 07bba7d17bb42ee0, new e5be92145a301820)
by issuing
rm -rf <datadir>/geth/chaindata
before mining.

Don't use --testnet, that forces Ropsten

Thanks @karalabe for that tip. --testnet wasn't my issue but tipped me off to removing --dev from my start script and that fixed the same issue for me.

if geth removedb doesn't work then just navigate to the directory containing your chain data ~/.ethereum_private/geth/chaindata and rm any files with the extension .ldb

new genesis blocks should have this structure { "config": { "chainId": 15, "homesteadBlock": 0, "eip155Block": 0, "eip158Block": 0 }, "difficulty": "200000000", "gasLimit": "2100000", "alloc": { "6cb6ae60cbde490423056be4d01c4ce4e685af62": { "balance": "400000" } } }

_Starting mining operation
null_
why?

Removing --dev will solve the problem. Probably because networkid != 1 already assumes its private network

$ ~/.ethereum/geth/chaindata
$ geth init custom-genesis.json
It'll solve your issue

@jay-dee7 - this doesn't solve the problem.
Unfortuanately I can't make --dev working with geth init ....

After trying geth removedb unsuccessfully, and removing .ldb files from ~/.ethereum_private/geth/chaindata , what finally worked for me was removing the .ldb files from ~/.ethereum_private/geth/lightchaindata.
I'm not sure where the switch is between these 2 sources, or why geth chooses one over the other, but that's what it was looking at (except when i called removedb).

somebody help me..

geth --datadir /home/danpatpang/go-ethereum/build/bin/privatechain init CustomGenesis.json
INFO [03-17|02:55:42] Maximum peer count                       ETH=25 LES=0 total=25
INFO [03-17|02:55:42] Allocated cache and file handles         database=/home/danpatpang/go-ethereum/build/bin/privatechain/geth/chaindata cache=16 handles=16
INFO [03-17|02:55:42] Persisted trie from memory database      nodes=1 size=201.00B time=5.684µs gcnodes=0 gcsize=0.00B gctime=0s livenodes=1 livesize=0.00B
Fatal: Failed to write genesis block: database already contains an incompatible genesis block (have d4e56740f876aef8, new 8eb4620ea97ffa4b)

I try to remove database. but this error repeat... help..
I use private.

removing ~/.ethereum_private/geth/lightchaindata. resolved for me

Removing the .ldb file from the _datadir_ works for me, thanks for the help!

Hello,total newbie here! Can someone tell me the best solution on the error.

Fatal: Failed to write genesis block: database already contains an incompatible genesis block (have d4e56740f876aef8, new d1a12dd8ee31c1b4)

I read some of the comments and i guess i am to stupid to understand what to do lol.

geth --dev init genesis.json worked for me

in one line, or get the pid with:
ps ax | grep geth
kill -INT
geth --dev init genesis.json
rm-rf~/.ethereum_private/geth/lightchaindata.

Is it dev networkid!=1?
try geth --dev initypur- genesis.jso it?

@AlexandreRoba
geth removedb --datadir data
geth init
rm -rf chaindate must!
you can many eth hahha!

I have the same issues.
In my case, simply remove geth dir
then re-init is OK

Was this page helpful?
0 / 5 - 0 ratings