Commit 13699e2d authored by Jeffrey Wilcke's avatar Jeffrey Wilcke

Merge pull request #1877 from obscuren/head-write

core: fixed head write on block insertion
parents 5b34fa53 20ab29f8
...@@ -297,6 +297,9 @@ func (bc *BlockChain) insert(block *types.Block) { ...@@ -297,6 +297,9 @@ func (bc *BlockChain) insert(block *types.Block) {
if err := WriteCanonicalHash(bc.chainDb, block.Hash(), block.NumberU64()); err != nil { if err := WriteCanonicalHash(bc.chainDb, block.Hash(), block.NumberU64()); err != nil {
glog.Fatalf("failed to insert block number: %v", err) glog.Fatalf("failed to insert block number: %v", err)
} }
if err := WriteHeadBlockHash(bc.chainDb, block.Hash()); err != nil {
glog.Fatalf("failed to insert block number: %v", err)
}
bc.currentBlock = block bc.currentBlock = block
} }
......
...@@ -153,6 +153,19 @@ func insertChain(done chan bool, blockchain *BlockChain, chain types.Blocks, t * ...@@ -153,6 +153,19 @@ func insertChain(done chan bool, blockchain *BlockChain, chain types.Blocks, t *
done <- true done <- true
} }
func TestLastBlock(t *testing.T) {
db, err := ethdb.NewMemDatabase()
if err != nil {
t.Fatal("Failed to create db:", err)
}
bchain := theBlockChain(db, t)
block := makeChain(bchain.CurrentBlock(), 1, db, 0)[0]
bchain.insert(block)
if block.Hash() != GetHeadBlockHash(db) {
t.Errorf("Write/Get HeadBlockHash failed")
}
}
func TestExtendCanonical(t *testing.T) { func TestExtendCanonical(t *testing.T) {
CanonicalLength := 5 CanonicalLength := 5
db, err := ethdb.NewMemDatabase() db, err := ethdb.NewMemDatabase()
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment