Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Custom Genesis file working anyone? I'm always getting "wrong genesis block in database" #14352

Closed
AlexandreRoba opened this issue Apr 19, 2017 · 33 comments · Fixed by #14358
Closed
Milestone

Comments

@AlexandreRoba
Copy link

AlexandreRoba commented Apr 19, 2017

System information

Geth
Version: 1.6.0-stable
Git Commit: facc47c
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]
@joeb000
Copy link

joeb000 commented Apr 19, 2017

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?

@xuxiao415
Copy link

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

@AlexandreRoba
Copy link
Author

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.

@AlexandreRoba
Copy link
Author

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

@karalabe
Copy link
Member

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.

@coreyog
Copy link

coreyog commented May 9, 2017

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.

@coreyog
Copy link

coreyog commented May 9, 2017

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.

@karalabe
Copy link
Member

karalabe commented May 10, 2017 via email

@coreyog
Copy link

coreyog commented May 10, 2017

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?

@Othmanbench
Copy link

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

@Charliethewind
Copy link

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

@Charliethewind
Copy link

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

@ta20170412
Copy link

ta20170412 commented May 24, 2017

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)

@wiwwo
Copy link

wiwwo commented Jun 3, 2017

Same problem here, stuck... :-)

@ogurcan
Copy link

ogurcan commented Jun 5, 2017

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?

@Jitendra2902
Copy link

{
"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

@wiwwo
Copy link

wiwwo commented Jun 6, 2017

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

@proehlen
Copy link

proehlen commented Jun 12, 2017

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.

@aleksajovanovic
Copy link

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

@aleksajovanovic
Copy link

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

@stern365
Copy link

Starting mining operation
null

why?

@asofyan
Copy link

asofyan commented Jul 27, 2017

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

@jay-dee7
Copy link

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

@robert-zaremba
Copy link
Contributor

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

@asiena
Copy link

asiena commented Dec 1, 2017

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

@Danpatpang
Copy link

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.

@spatro14
Copy link

spatro14 commented Jun 2, 2018

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

@Jasonyou1995
Copy link

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

@EfaStromberg
Copy link

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.

@devrajsinghrawat
Copy link

geth --dev init genesis.json worked for me

@stvenyin
Copy link

stvenyin commented Jan 5, 2019

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?

@stvenyin
Copy link

stvenyin commented Jan 5, 2019

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

@BIG-CHENG
Copy link

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.