core, eth, ethdb, trie: simplify range proofs

This commit is contained in:
Péter Szilágyi
2021-04-28 23:09:15 +03:00
parent a81cf0d2b3
commit fae165a5de
12 changed files with 149 additions and 237 deletions

View File

@ -25,9 +25,6 @@ const IdealBatchSize = 100 * 1024
type Batch interface {
KeyValueWriter
// KeyCount retrieves the number of keys queued up for writing.
KeyCount() int
// ValueSize retrieves the amount of data queued up for writing.
ValueSize() int
@ -47,3 +44,28 @@ type Batcher interface {
// until a final write is called.
NewBatch() Batch
}
// HookedBatch wraps an arbitrary batch where each operation may be hooked into
// to monitor from black box code.
type HookedBatch struct {
Batch
OnPut func(key []byte, value []byte) // Callback if a key is inserted
OnDelete func(key []byte) // Callback if a key is deleted
}
// Put inserts the given value into the key-value data store.
func (b HookedBatch) Put(key []byte, value []byte) error {
if b.OnPut != nil {
b.OnPut(key, value)
}
return b.Batch.Put(key, value)
}
// Delete removes the key from the key-value data store.
func (b HookedBatch) Delete(key []byte) error {
if b.OnDelete != nil {
b.OnDelete(key)
}
return b.Batch.Delete(key)
}