-
Notifications
You must be signed in to change notification settings - Fork 2
/
statedb_cache_batch.go
45 lines (35 loc) · 1017 Bytes
/
statedb_cache_batch.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
package statedb_cache
import (
"github.com/ethereum/go-ethereum/ethdb"
)
type StateDBCacheBatch struct {
db *StateDBCacheDatabase
remoteBatch ethdb.Batch
}
func newStateDBCacheBatch(db *StateDBCacheDatabase, batch ethdb.Batch) *StateDBCacheBatch {
return &StateDBCacheBatch{db: db, remoteBatch: batch}
}
func (b *StateDBCacheBatch) Put(key []byte, value []byte) error {
return b.remoteBatch.Put(key, value)
}
func (b *StateDBCacheBatch) Delete(key []byte) error {
return b.remoteBatch.Delete(key)
}
func (b *StateDBCacheBatch) ValueSize() int {
// In ethdb, the size of each commit is too small, this controls the submission frequency
return b.remoteBatch.ValueSize() / 40
}
func (b *StateDBCacheBatch) Write() (err error) {
defer func() {
if err == nil {
_ = b.db.cacheWrite(b)
}
}()
return b.remoteBatch.Write()
}
func (b *StateDBCacheBatch) Reset() {
b.remoteBatch.Reset()
}
func (b *StateDBCacheBatch) Replay(w ethdb.KeyValueWriter) error {
return b.remoteBatch.Replay(w)
}