aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorJeffrey Wilcke <jeffrey@ethereum.org>2015-10-06 02:00:57 +0800
committerJeffrey Wilcke <jeffrey@ethereum.org>2015-10-06 02:00:57 +0800
commit13699e2dd97e181247200f75fd11d2be0bb960bc (patch)
tree745743d196b406563144bb62e7bb8a1cccbff092
parent5b34fa538e54320778314081df97da561f7c6314 (diff)
parent20ab29f8855982f28c6887743c737531065fa792 (diff)
downloadgo-tangerine-13699e2dd97e181247200f75fd11d2be0bb960bc.tar.gz
go-tangerine-13699e2dd97e181247200f75fd11d2be0bb960bc.tar.zst
go-tangerine-13699e2dd97e181247200f75fd11d2be0bb960bc.zip
Merge pull request #1877 from obscuren/head-write
core: fixed head write on block insertion
-rw-r--r--core/blockchain.go3
-rw-r--r--core/blockchain_test.go13
2 files changed, 16 insertions, 0 deletions
diff --git a/core/blockchain.go b/core/blockchain.go
index e8209f8e3..ad545cf69 100644
--- a/core/blockchain.go
+++ b/core/blockchain.go
@@ -297,6 +297,9 @@ func (bc *BlockChain) insert(block *types.Block) {
if err := WriteCanonicalHash(bc.chainDb, block.Hash(), block.NumberU64()); err != nil {
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
}
diff --git a/core/blockchain_test.go b/core/blockchain_test.go
index e034417ce..13971ccba 100644
--- a/core/blockchain_test.go
+++ b/core/blockchain_test.go
@@ -153,6 +153,19 @@ func insertChain(done chan bool, blockchain *BlockChain, chain types.Blocks, t *
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) {
CanonicalLength := 5
db, err := ethdb.NewMemDatabase()