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

geth --dev doesn't work with a custom genesis block (geth init ...). #15182

Closed
robert-zaremba opened this issue Sep 21, 2017 · 18 comments
Closed

Comments

@robert-zaremba
Copy link
Contributor

robert-zaremba commented Sep 21, 2017

System information

Geth version: 1.7.0
OS & Version: Linux -- docker container: ethereum/client-go:v1.7.0

Expected behaviour

geth --dev works with custom genesis block.

Actual behaviour

geth --dev returns error if runs after removing DB and geth init myGenesis.json

Fatal: Error starting protocol stack: database already contains an incompatible genesis block (have 2a99ba45a8097ae4, new e5be92145a301820)

Steps to reproduce the behaviour

gethGenesisBlock.json (the config is the same as the one logged when running geth --dev on a clean storage):

{
    "config": {
        "chainId": 1337,
        "homesteadBlock": 0,
        "byzantiumBlock": 0,
        "eip150Block": 0,
        "eip155Block": 0,
        "eip158Block": 0
    },
    "difficulty": "0x100",
    "gasLimit": "20000000",
    "alloc": {}
}

steps:

geth --dev --datadir ~/.ethereum init gethGenesisBlock.json 
geth --dev --datadir ~/.ethereum 

Backtrace

root@2969dbe94b30:~> geth --dev --datadir ~/.ethereum init gethGenesisBlock.json 
INFO [09-21|09:52:11] Allocated cache and file handles         database=/root/.ethereum/geth/chaindata cache=16 handles=16
INFO [09-21|09:52:11] Writing custom genesis block 
INFO [09-21|09:52:11] Successfully wrote genesis state         database=chaindata                      hash=2a99ba…8016cb
INFO [09-21|09:52:11] Allocated cache and file handles         database=/root/.ethereum/geth/lightchaindata cache=16 handles=16
INFO [09-21|09:52:12] Writing custom genesis block 
INFO [09-21|09:52:12] Successfully wrote genesis state         database=lightchaindata                      hash=2a99ba…8016cb

root@2969dbe94b30:~> geth --dev --datadir ~/.ethereum 
INFO [09-21|09:52:21] Starting peer-to-peer node               instance=Geth/v1.7.0-stable/linux-amd64/go1.9
INFO [09-21|09:52:21] Allocated cache and file handles         database=/root/.ethereum/geth/chaindata cache=128 handles=1024
WARN [09-21|09:52:21] Upgrading database to use lookup entries 
INFO [09-21|09:52:21] Database deduplication successful        deduped=0
Fatal: Error starting protocol stack: database already contains an incompatible genesis block (have 2a99ba45a8097ae4, new e5be92145a301820)
@awgneo
Copy link

awgneo commented Oct 24, 2017

This is a huge problem when trying to test code locally. :(

@nulltrope
Copy link

I'll take a look at this

@tundak
Copy link

tundak commented Nov 8, 2017

Getting below issue

geth --datadir "/var/www/html/eth/mychain" --rpc --rpcaddr 127.0.0.1 --rpcport 8545 --dev 
WARN [11-08|13:45:13] No etherbase set and no accounts found as default 
INFO [11-08|13:45:13] Starting peer-to-peer node               instance=Geth/v1.7.2-stable-1db4ecdc/linux-amd64/go1.9
INFO [11-08|13:45:13] Allocated cache and file handles         database=/var/www/html/eth/mychain/geth/chaindata cache=128 handles=1024
Fatal: Error starting protocol stack: database already contains an incompatible genesis block (have d1a12dd8ee31c1b4, new e5be92145a301820)

@4ntoine
Copy link

4ntoine commented Nov 16, 2017

$geth version
Geth
Version: 1.7.2-stable
Git Commit: 1db4ecd
Architecture: amd64
Protocol Versions: [63 62]
Network Id: 1
Go Version: go1.9.2
Operating System: darwin
GOPATH=
GOROOT=/usr/local/Cellar/go/1.9.2/libexec

@slatunje
Copy link

slatunje commented Dec 3, 2017

I am still facing the same issue...has this issue been fixed yet?

geth  --datadir=./data init genesis.json

then run

geth --datadir=./data --dev

and I get

WARN [12-03|03:25:34] Upgrading database to use lookup entries
INFO [12-03|03:25:34] Database deduplication successful        deduped=0
Fatal: Error starting protocol stack: database already contains an incompatible genesis block (have 2fb1a756bef56a20, new b8e537153deef718)    

however running without initialising with geth --datadir=./data init genesis.json seems to work:

 geth --datadir=./data --dev

@nulltrope
Copy link

haven't been able to work on this yet, if somebody else wants to handle they can. Otherwise I can take another look in a week or two.

@trenner
Copy link

trenner commented Dec 13, 2017

I'm facing the same issue. It is really annoying to test locally without --dev and --dev.period.

@naddison36
Copy link

I'm also getting this issue when I use the --dev option with a custom genesis file that has been initialised. The problem with not being able to use a custom genesis file is I can't prefund a set of test accounts.

@nulltrope
Copy link

Going through the core/genesis.go code you can see here that the only reason for this error is because --dev is invoking the genesis contrustor with its own genesis block.

Therefore if you had created a genesis block manually beforehand, for example with geth --datadir=./data init genesis.json , then try to run the node with geth --datadir=./data --dev , it will fail because you have an "incompatible" genesis block already in the data directory from the first step, and the second step is trying to use its own genesis block.

Fixing this would require changing the functionality of the --dev flag to either not create a genesis block and initialize a datadir on its own (i.e. you'd have to run init first) or make it so that --dev will only create a genesis block if there is none already in the datadir.

@slatunje
Copy link

slatunje commented Dec 19, 2017

How about separate --datadir per environment?

For example:

geth --datadir=./data init genesis.json will produce data as normal

data/

geth --datadir=./data --dev can then generate data into data/dev child directory

data/
└── dev/

This way --dev need not worry about conflicted genesis blocks. It will make the running of the command flags idempotent.

@nulltrope
Copy link

@slatunje that would make sense, however I think the issue here is that users want to be able to use --dev with their own generated data & genesis block so that wallets can be prepopulated, etc.

But I see the advantage to having --dev generate the data for you, because it is an all-in-one command, so simply removing the data creation step from the dev flag doesn't seem to be the solution either.

Maybe some others can chime in with their thoughts here.

@iurimatias
Copy link
Member

Any updates on this? It remains a problem, being able to use a custom genesis block together with the functionality of --dev is very useful

@robert-zaremba
Copy link
Contributor Author

It seams that with new geth (1.8) the behaviour changed. It's not possible any more to use --dev with --datadir. Can anybody confirm and point a link to the documentation?

@stvenyin
Copy link

Thank you very much.

@adamschmideg adamschmideg added this to the 1.8.17 milestone Oct 3, 2018
@adamschmideg adamschmideg removed this from the 1.8.17 milestone Oct 4, 2018
@karalabe
Copy link
Member

karalabe commented Oct 4, 2018

@robert-zaremba You can still use dev with datadir. Dev just uses a 0-period clique chain.

That said, --dev was not meant to be used on custom networks / genesis blocks. If you need a custom setup, you can init a chain of your choosing. Dev will try to be smart and configure a lot of stuff for easy testing, but it's not flexible, it's easy.

@stvenyin
Copy link

stvenyin commented Jan 5, 2019

geth --datadir=./data --dev
if use dev mode
src
core/genesis.go
// Check whether the genesis block is already written.
if genesis != nil {
block, _ := genesis.ToBlock()
hash := block.Hash()
if hash != stored {
return genesis.Config, block.Hash(), &GenesisMismatchError{stored, hash}
}
}

usually people always use this method
geth --datadir=./data init genesis.json
geth --datadir=./data --dev
it proof of proof work

@stvenyin
Copy link

stvenyin commented Jan 5, 2019

cd data
cd ../
sudo rmdir data
I'm using eth --dev init genesis.json
geth --networkid 123 --dev --datadir data --.......自己加上
@karalabe it's solve this problem
Thank you

@dhvanipa
Copy link

To get geth to use the same dev private key on startup, you can put the original keystore file under the keystore directory.

Export:

  1. Run geth in dev mode as you want.
  2. Re run the geth command with dumpgenesis to get the genesis.json it used. Save this file.
  3. Copy over the file under data/keystore assuming data is your datadir.
  4. geth export --datadir data geth_backup 0 <latest block number>

Import

  1. Copy over genesis.json
  2. geth init --datadir new-data genesis.json
  3. Copy over the file under data/keystore to this new place's new-data/keystore
  4. Copy over geth_backup file to this new folder
  5. geth --datadir new-data import geth_backup
  6. Run geth in dev mode pointing to this datadir and it'll now start with the same dev account and at the latest block number.

So for development if you want a couple of accounts pre-funded, just make those as the first transactions from the dev account.

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

No branches or pull requests