aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorJeffrey Wilcke <jeffrey@ethereum.org>2015-05-28 01:00:08 +0800
committerJeffrey Wilcke <jeffrey@ethereum.org>2015-05-28 01:00:08 +0800
commit5479be9f6412ccd60e86d6c9be972894cf99abdf (patch)
treeae6c7f6d5bfaf4380bf54cac5fadd291b08ee1a7
parent903b95fffabf0f8c94594b69d95747772e6abed8 (diff)
parent020006a8ede0463346ad3d4ae318d299eee63fb1 (diff)
downloaddexon-5479be9f6412ccd60e86d6c9be972894cf99abdf.tar
dexon-5479be9f6412ccd60e86d6c9be972894cf99abdf.tar.gz
dexon-5479be9f6412ccd60e86d6c9be972894cf99abdf.tar.bz2
dexon-5479be9f6412ccd60e86d6c9be972894cf99abdf.tar.lz
dexon-5479be9f6412ccd60e86d6c9be972894cf99abdf.tar.xz
dexon-5479be9f6412ccd60e86d6c9be972894cf99abdf.tar.zst
dexon-5479be9f6412ccd60e86d6c9be972894cf99abdf.zip
Merge pull request #1129 from obscuren/database_cache_removal
ethdb, common: cache removal
-rw-r--r--common/db.go1
-rw-r--r--core/chain_manager.go1
-rw-r--r--ethdb/database.go64
3 files changed, 7 insertions, 59 deletions
diff --git a/common/db.go b/common/db.go
index ae13c7557..c12a2cfb0 100644
--- a/common/db.go
+++ b/common/db.go
@@ -5,7 +5,6 @@ type Database interface {
Put(key []byte, value []byte)
Get(key []byte) ([]byte, error)
Delete(key []byte) error
- LastKnownTD() []byte
Close()
Flush() error
}
diff --git a/core/chain_manager.go b/core/chain_manager.go
index ec479db25..ee73145c1 100644
--- a/core/chain_manager.go
+++ b/core/chain_manager.go
@@ -69,6 +69,7 @@ func CalcGasLimit(parent *types.Block) *big.Int {
gl := new(big.Int).Sub(parent.GasLimit(), decay)
gl = gl.Add(gl, contrib)
+ gl = gl.Add(gl, big.NewInt(1))
gl = common.BigMax(gl, params.MinGasLimit)
if gl.Cmp(params.GenesisGasLimit) < 0 {
diff --git a/ethdb/database.go b/ethdb/database.go
index 9bf09467b..019645ced 100644
--- a/ethdb/database.go
+++ b/ethdb/database.go
@@ -1,8 +1,6 @@
package ethdb
import (
- "sync"
-
"github.com/ethereum/go-ethereum/compression/rle"
"github.com/ethereum/go-ethereum/logger"
"github.com/ethereum/go-ethereum/logger/glog"
@@ -15,14 +13,10 @@ import (
var OpenFileLimit = 64
type LDBDatabase struct {
+ // filename for reporting
fn string
-
- mu sync.Mutex
+ // LevelDB instance
db *leveldb.DB
-
- queue map[string][]byte
-
- quit chan struct{}
}
// NewLDBDatabase returns a LevelDB wrapped object. LDBDatabase does not persist data by
@@ -40,85 +34,39 @@ func NewLDBDatabase(file string) (*LDBDatabase, error) {
return nil, err
}
database := &LDBDatabase{
- fn: file,
- db: db,
- quit: make(chan struct{}),
+ fn: file,
+ db: db,
}
- database.makeQueue()
return database, nil
}
-func (self *LDBDatabase) makeQueue() {
- self.queue = make(map[string][]byte)
-}
-
// Put puts the given key / value to the queue
func (self *LDBDatabase) Put(key []byte, value []byte) {
- self.mu.Lock()
- defer self.mu.Unlock()
-
- self.queue[string(key)] = value
+ self.db.Put(key, rle.Compress(value), nil)
}
// Get returns the given key if it's present.
func (self *LDBDatabase) Get(key []byte) ([]byte, error) {
- self.mu.Lock()
- defer self.mu.Unlock()
-
- // Check queue first
- if dat, ok := self.queue[string(key)]; ok {
- return dat, nil
- }
-
dat, err := self.db.Get(key, nil)
if err != nil {
return nil, err
}
-
return rle.Decompress(dat)
}
// Delete deletes the key from the queue and database
func (self *LDBDatabase) Delete(key []byte) error {
- self.mu.Lock()
- defer self.mu.Unlock()
-
- // make sure it's not in the queue
- delete(self.queue, string(key))
-
return self.db.Delete(key, nil)
}
-func (self *LDBDatabase) LastKnownTD() []byte {
- data, _ := self.Get([]byte("LTD"))
-
- if len(data) == 0 {
- data = []byte{0x0}
- }
-
- return data
-}
-
func (self *LDBDatabase) NewIterator() iterator.Iterator {
return self.db.NewIterator(nil, nil)
}
// Flush flushes out the queue to leveldb
func (self *LDBDatabase) Flush() error {
- self.mu.Lock()
- defer self.mu.Unlock()
-
- batch := new(leveldb.Batch)
-
- for key, value := range self.queue {
- batch.Put([]byte(key), rle.Compress(value))
- }
- self.makeQueue() // reset the queue
-
- glog.V(logger.Detail).Infoln("Flush database: ", self.fn)
-
- return self.db.Write(batch, nil)
+ return nil
}
func (self *LDBDatabase) Close() {