Skip to content

Commit 13699e2

Browse files
committed
Merge pull request #1877 from obscuren/head-write
core: fixed head write on block insertion
2 parents 5b34fa5 + 20ab29f commit 13699e2

File tree

2 files changed

+16
-0
lines changed

2 files changed

+16
-0
lines changed

core/blockchain.go

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -297,6 +297,9 @@ func (bc *BlockChain) insert(block *types.Block) {
297297
if err := WriteCanonicalHash(bc.chainDb, block.Hash(), block.NumberU64()); err != nil {
298298
glog.Fatalf("failed to insert block number: %v", err)
299299
}
300+
if err := WriteHeadBlockHash(bc.chainDb, block.Hash()); err != nil {
301+
glog.Fatalf("failed to insert block number: %v", err)
302+
}
300303
bc.currentBlock = block
301304
}
302305

core/blockchain_test.go

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -153,6 +153,19 @@ func insertChain(done chan bool, blockchain *BlockChain, chain types.Blocks, t *
153153
done <- true
154154
}
155155

156+
func TestLastBlock(t *testing.T) {
157+
db, err := ethdb.NewMemDatabase()
158+
if err != nil {
159+
t.Fatal("Failed to create db:", err)
160+
}
161+
bchain := theBlockChain(db, t)
162+
block := makeChain(bchain.CurrentBlock(), 1, db, 0)[0]
163+
bchain.insert(block)
164+
if block.Hash() != GetHeadBlockHash(db) {
165+
t.Errorf("Write/Get HeadBlockHash failed")
166+
}
167+
}
168+
156169
func TestExtendCanonical(t *testing.T) {
157170
CanonicalLength := 5
158171
db, err := ethdb.NewMemDatabase()

0 commit comments

Comments
 (0)