aboutsummaryrefslogtreecommitdiffstats
path: root/ethdb
diff options
context:
space:
mode:
Diffstat (limited to 'ethdb')
-rw-r--r--ethdb/batch.go4
-rw-r--r--ethdb/database.go63
-rw-r--r--ethdb/leveldb/leveldb.go4
-rw-r--r--ethdb/memorydb/memorydb.go2
4 files changed, 62 insertions, 11 deletions
diff --git a/ethdb/batch.go b/ethdb/batch.go
index a9c406354..e261415bf 100644
--- a/ethdb/batch.go
+++ b/ethdb/batch.go
@@ -23,7 +23,7 @@ const IdealBatchSize = 100 * 1024
// Batch is a write-only database that commits changes to its host database
// when Write is called. A batch cannot be used concurrently.
type Batch interface {
- Writer
+ KeyValueWriter
// ValueSize retrieves the amount of data queued up for writing.
ValueSize() int
@@ -35,7 +35,7 @@ type Batch interface {
Reset()
// Replay replays the batch contents.
- Replay(w Writer) error
+ Replay(w KeyValueWriter) error
}
// Batcher wraps the NewBatch method of a backing data store.
diff --git a/ethdb/database.go b/ethdb/database.go
index bab99aed1..1ba169bcf 100644
--- a/ethdb/database.go
+++ b/ethdb/database.go
@@ -19,8 +19,8 @@ package ethdb
import "io"
-// Reader wraps the Has and Get method of a backing data store.
-type Reader interface {
+// KeyValueReader wraps the Has and Get method of a backing data store.
+type KeyValueReader interface {
// Has retrieves if a key is present in the key-value data store.
Has(key []byte) (bool, error)
@@ -28,8 +28,8 @@ type Reader interface {
Get(key []byte) ([]byte, error)
}
-// Writer wraps the Put method of a backing data store.
-type Writer interface {
+// KeyValueWriter wraps the Put method of a backing data store.
+type KeyValueWriter interface {
// Put inserts the given value into the key-value data store.
Put(key []byte, value []byte) error
@@ -58,8 +58,8 @@ type Compacter interface {
// KeyValueStore contains all the methods required to allow handling different
// key-value data stores backing the high level database.
type KeyValueStore interface {
- Reader
- Writer
+ KeyValueReader
+ KeyValueWriter
Batcher
Iteratee
Stater
@@ -67,6 +67,57 @@ type KeyValueStore interface {
io.Closer
}
+// AncientReader contains the methods required to read from immutable ancient data.
+type AncientReader interface {
+ // HasAncient returns an indicator whether the specified data exists in the
+ // ancient store.
+ HasAncient(kind string, number uint64) (bool, error)
+
+ // Ancient retrieves an ancient binary blob from the append-only immutable files.
+ Ancient(kind string, number uint64) ([]byte, error)
+
+ // Ancients returns the ancient item numbers in the ancient store.
+ Ancients() (uint64, error)
+
+ // AncientSize returns the ancient size of the specified category.
+ AncientSize(kind string) (uint64, error)
+}
+
+// AncientWriter contains the methods required to write to immutable ancient data.
+type AncientWriter interface {
+ // AppendAncient injects all binary blobs belong to block at the end of the
+ // append-only immutable table files.
+ AppendAncient(number uint64, hash, header, body, receipt, td []byte) error
+
+ // TruncateAncients discards all but the first n ancient data from the ancient store.
+ TruncateAncients(n uint64) error
+
+ // Sync flushes all in-memory ancient store data to disk.
+ Sync() error
+}
+
+// Reader contains the methods required to read data from both key-value as well as
+// immutable ancient data.
+type Reader interface {
+ KeyValueReader
+ AncientReader
+}
+
+// Writer contains the methods required to write data to both key-value as well as
+// immutable ancient data.
+type Writer interface {
+ KeyValueWriter
+ AncientWriter
+}
+
+// AncientStore contains all the methods required to allow handling different
+// ancient data stores backing immutable chain data store.
+type AncientStore interface {
+ AncientReader
+ AncientWriter
+ io.Closer
+}
+
// Database contains all the methods required by the high level database to not
// only access the key-value data store but also the chain freezer.
type Database interface {
diff --git a/ethdb/leveldb/leveldb.go b/ethdb/leveldb/leveldb.go
index 8eabee50e..f74e94d92 100644
--- a/ethdb/leveldb/leveldb.go
+++ b/ethdb/leveldb/leveldb.go
@@ -425,13 +425,13 @@ func (b *batch) Reset() {
}
// Replay replays the batch contents.
-func (b *batch) Replay(w ethdb.Writer) error {
+func (b *batch) Replay(w ethdb.KeyValueWriter) error {
return b.b.Replay(&replayer{writer: w})
}
// replayer is a small wrapper to implement the correct replay methods.
type replayer struct {
- writer ethdb.Writer
+ writer ethdb.KeyValueWriter
failure error
}
diff --git a/ethdb/memorydb/memorydb.go b/ethdb/memorydb/memorydb.go
index cb8b27f3b..caa9b02a1 100644
--- a/ethdb/memorydb/memorydb.go
+++ b/ethdb/memorydb/memorydb.go
@@ -270,7 +270,7 @@ func (b *batch) Reset() {
}
// Replay replays the batch contents.
-func (b *batch) Replay(w ethdb.Writer) error {
+func (b *batch) Replay(w ethdb.KeyValueWriter) error {
for _, keyvalue := range b.writes {
if keyvalue.delete {
if err := w.Delete(keyvalue.key); err != nil {