From 5258785c81959109138ebeca613f12c277188abc Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?P=C3=A9ter=20Szil=C3=A1gyi?= Date: Thu, 21 Dec 2017 13:56:11 +0200 Subject: cmd, core, eth/tracers: support fancier js tracing (#15516) * cmd, core, eth/tracers: support fancier js tracing * eth, internal/web3ext: rework trace API, concurrency, chain tracing * eth/tracers: add three more JavaScript tracers * eth/tracers, vendor: swap ottovm to duktape for tracing * core, eth, internal: finalize call tracer and needed extras * eth, tests: prestate tracer, call test suite, rewinding * vendor: fix windows builds for tracer js engine * vendor: temporary duktape fix * eth/tracers: fix up 4byte and evmdis tracer * vendor: pull in latest duktape with my upstream fixes * eth: fix some review comments * eth: rename rewind to reexec to make it more obvious * core/vm: terminate tracing using defers --- ethdb/memory_database.go | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) (limited to 'ethdb') diff --git a/ethdb/memory_database.go b/ethdb/memory_database.go index 699bd0c9f..0dd93a279 100644 --- a/ethdb/memory_database.go +++ b/ethdb/memory_database.go @@ -37,6 +37,12 @@ func NewMemDatabase() (*MemDatabase, error) { }, nil } +func NewMemDatabaseWithCap(size int) (*MemDatabase, error) { + return &MemDatabase{ + db: make(map[string][]byte, size), + }, nil +} + func (db *MemDatabase) Put(key []byte, value []byte) error { db.lock.Lock() defer db.lock.Unlock() @@ -74,14 +80,6 @@ func (db *MemDatabase) Keys() [][]byte { return keys } -/* -func (db *MemDatabase) GetKeys() []*common.Key { - data, _ := db.Get([]byte("KeyRing")) - - return []*common.Key{common.NewKeyFromBytes(data)} -} -*/ - func (db *MemDatabase) Delete(key []byte) error { db.lock.Lock() defer db.lock.Unlock() @@ -96,6 +94,8 @@ func (db *MemDatabase) NewBatch() Batch { return &memBatch{db: db} } +func (db *MemDatabase) Len() int { return len(db.db) } + type kv struct{ k, v []byte } type memBatch struct { -- cgit v1.2.3 From 017b9f7eacd1048661b22b7892caf680deb2b548 Mon Sep 17 00:00:00 2001 From: Martin Holst Swende Date: Tue, 30 Jan 2018 18:03:31 +0100 Subject: core, ethdb: reuse database batches (#15989) * leveldb: Update leveldb to 211f780 (poolfix) * core, ethdb: reuse database batches --- ethdb/database.go | 8 ++++++++ ethdb/interface.go | 2 ++ ethdb/memory_database.go | 5 +++++ 3 files changed, 15 insertions(+) (limited to 'ethdb') diff --git a/ethdb/database.go b/ethdb/database.go index 93755dd7e..9a7c85d9e 100644 --- a/ethdb/database.go +++ b/ethdb/database.go @@ -299,6 +299,10 @@ func (b *ldbBatch) ValueSize() int { return b.size } +func (b *ldbBatch) Reset() { + b.b.Reset() +} + type table struct { db Database prefix string @@ -358,3 +362,7 @@ func (tb *tableBatch) Write() error { func (tb *tableBatch) ValueSize() int { return tb.batch.ValueSize() } + +func (tb *tableBatch) Reset() { + tb.batch.Reset() +} diff --git a/ethdb/interface.go b/ethdb/interface.go index 99a5b770d..537312003 100644 --- a/ethdb/interface.go +++ b/ethdb/interface.go @@ -41,4 +41,6 @@ type Batch interface { Putter ValueSize() int // amount of data in the batch Write() error + // Reset resets the batch for reuse + Reset() } diff --git a/ethdb/memory_database.go b/ethdb/memory_database.go index 0dd93a279..8efd7bf84 100644 --- a/ethdb/memory_database.go +++ b/ethdb/memory_database.go @@ -123,3 +123,8 @@ func (b *memBatch) Write() error { func (b *memBatch) ValueSize() int { return b.size } + +func (b *memBatch) Reset() { + b.writes = b.writes[:0] + b.size = 0 +} -- cgit v1.2.3 From 3e89b80ccb1110c04f4db7b8201c9c6d27b824c4 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?P=C3=A9ter=20Szil=C3=A1gyi?= Date: Tue, 30 Jan 2018 19:12:28 +0200 Subject: ethdb: reset the batch size too on reset --- ethdb/database.go | 1 + 1 file changed, 1 insertion(+) (limited to 'ethdb') diff --git a/ethdb/database.go b/ethdb/database.go index 9a7c85d9e..d86585f07 100644 --- a/ethdb/database.go +++ b/ethdb/database.go @@ -301,6 +301,7 @@ func (b *ldbBatch) ValueSize() int { func (b *ldbBatch) Reset() { b.b.Reset() + b.size = 0 } type table struct { -- cgit v1.2.3