From 5b0ee8ec304663898073b7a4c659e1def23716df Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?P=C3=A9ter=20Szil=C3=A1gyi?= Date: Tue, 13 Oct 2015 12:04:25 +0300 Subject: core, eth, trie: fix data races and merge/review issues --- ethdb/memory_database.go | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) (limited to 'ethdb') diff --git a/ethdb/memory_database.go b/ethdb/memory_database.go index 330834fa4..01273b9db 100644 --- a/ethdb/memory_database.go +++ b/ethdb/memory_database.go @@ -17,6 +17,7 @@ package ethdb import ( + "errors" "fmt" "sync" @@ -56,7 +57,10 @@ func (db *MemDatabase) Get(key []byte) ([]byte, error) { db.lock.RLock() defer db.lock.RUnlock() - return db.db[string(key)], nil + if entry, ok := db.db[string(key)]; ok { + return entry, nil + } + return nil, errors.New("not found") } func (db *MemDatabase) Keys() [][]byte { @@ -132,8 +136,8 @@ func (b *memBatch) Write() error { b.lock.RLock() defer b.lock.RUnlock() - b.db.lock.RLock() - defer b.db.lock.RUnlock() + b.db.lock.Lock() + defer b.db.lock.Unlock() for _, kv := range b.writes { b.db.db[string(kv.k)] = kv.v -- cgit v1.2.3