Geth version: 1.7.0
OS & Version: Linux -- docker container: ethereum/client-go:v1.7.0
geth --dev works with custom genesis block.
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)
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
````
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)
````
This is a huge problem when trying to test code locally. :(
I'll take a look at this
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)
$geth version
Geth
Version: 1.7.2-stable
Git Commit: 1db4ecdc0b9e828ff65777fb466fc7c1d04e0de9
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
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
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.
I'm facing the same issue. It is really annoying to test locally without --dev and --dev.period.
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.
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.
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.
@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.
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
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?
Thank you very much.
@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.
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
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