cmd/geth, core: make "geth blocktest" work again

The test genesis block was not written properly, block insertion failed
immediately.

While here, fix the panic when shutting down "geth blocktest" with
Ctrl+C. The signal handler is now installed automatically, causing
ethereum.Stop to crash because everything is already stopped.
This commit is contained in:
Felix Lange 2015-09-22 23:55:31 +02:00
parent e56cbc225e
commit 70b6174748
2 changed files with 1 additions and 6 deletions

View File

@ -91,7 +91,6 @@ func runBlockTest(ctx *cli.Context) {
if err != nil { if err != nil {
utils.Fatalf("%v", err) utils.Fatalf("%v", err)
} }
defer ethereum.Stop()
if rpc { if rpc {
fmt.Println("Block Test post state validated, starting RPC interface.") fmt.Println("Block Test post state validated, starting RPC interface.")
startEth(ctx, ethereum) startEth(ctx, ethereum)
@ -106,7 +105,6 @@ func runOneBlockTest(ctx *cli.Context, test *tests.BlockTest) (*eth.Ethereum, er
cfg.MaxPeers = 0 // disable network cfg.MaxPeers = 0 // disable network
cfg.Shh = false // disable whisper cfg.Shh = false // disable whisper
cfg.NAT = nil // disable port mapping cfg.NAT = nil // disable port mapping
ethereum, err := eth.New(cfg) ethereum, err := eth.New(cfg)
if err != nil { if err != nil {
return nil, err return nil, err
@ -114,7 +112,6 @@ func runOneBlockTest(ctx *cli.Context, test *tests.BlockTest) (*eth.Ethereum, er
// import the genesis block // import the genesis block
ethereum.ResetWithGenesisBlock(test.Genesis) ethereum.ResetWithGenesisBlock(test.Genesis)
// import pre accounts // import pre accounts
_, err = test.InsertPreState(ethereum) _, err = test.InsertPreState(ethereum)
if err != nil { if err != nil {
@ -122,16 +119,13 @@ func runOneBlockTest(ctx *cli.Context, test *tests.BlockTest) (*eth.Ethereum, er
} }
cm := ethereum.ChainManager() cm := ethereum.ChainManager()
validBlocks, err := test.TryBlocksInsert(cm) validBlocks, err := test.TryBlocksInsert(cm)
if err != nil { if err != nil {
return ethereum, fmt.Errorf("Block Test load error: %v", err) return ethereum, fmt.Errorf("Block Test load error: %v", err)
} }
newDB := cm.State() newDB := cm.State()
if err := test.ValidatePostState(newDB); err != nil { if err := test.ValidatePostState(newDB); err != nil {
return ethereum, fmt.Errorf("post state validation failed: %v", err) return ethereum, fmt.Errorf("post state validation failed: %v", err)
} }
return ethereum, test.ValidateImportedHeaders(cm, validBlocks) return ethereum, test.ValidateImportedHeaders(cm, validBlocks)
} }

View File

@ -279,6 +279,7 @@ func (bc *ChainManager) ResetWithGenesisBlock(genesis *types.Block) {
if err := WriteBlock(bc.chainDb, genesis); err != nil { if err := WriteBlock(bc.chainDb, genesis); err != nil {
glog.Fatalf("failed to write genesis block: %v", err) glog.Fatalf("failed to write genesis block: %v", err)
} }
bc.genesisBlock = genesis
bc.insert(bc.genesisBlock) bc.insert(bc.genesisBlock)
bc.currentBlock = bc.genesisBlock bc.currentBlock = bc.genesisBlock
bc.setTotalDifficulty(genesis.Difficulty()) bc.setTotalDifficulty(genesis.Difficulty())