github.com/dominant-strategies/go-quai@v0.28.2/ethdb/database.go (about)

     1  // Copyright 2014 The go-ethereum Authors
     2  // This file is part of the go-ethereum library.
     3  //
     4  // The go-ethereum library is free software: you can redistribute it and/or modify
     5  // it under the terms of the GNU Lesser General Public License as published by
     6  // the Free Software Foundation, either version 3 of the License, or
     7  // (at your option) any later version.
     8  //
     9  // The go-ethereum library is distributed in the hope that it will be useful,
    10  // but WITHOUT ANY WARRANTY; without even the implied warranty of
    11  // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
    12  // GNU Lesser General Public License for more details.
    13  //
    14  // You should have received a copy of the GNU Lesser General Public License
    15  // along with the go-ethereum library. If not, see <http://www.gnu.org/licenses/>.
    16  
    17  // Package ethdb defines the interfaces for an Quai data store.
    18  package ethdb
    19  
    20  import (
    21  	"io"
    22  )
    23  
    24  // KeyValueReader wraps the Has and Get method of a backing data store.
    25  type KeyValueReader interface {
    26  	// Has retrieves if a key is present in the key-value data store.
    27  	Has(key []byte) (bool, error)
    28  
    29  	// Get retrieves the given key if it's present in the key-value data store.
    30  	Get(key []byte) ([]byte, error)
    31  }
    32  
    33  // KeyValueWriter wraps the Put method of a backing data store.
    34  type KeyValueWriter interface {
    35  	// Put inserts the given value into the key-value data store.
    36  	Put(key []byte, value []byte) error
    37  
    38  	// Delete removes the key from the key-value data store.
    39  	Delete(key []byte) error
    40  }
    41  
    42  // Stater wraps the Stat method of a backing data store.
    43  type Stater interface {
    44  	// Stat returns a particular internal stat of the database.
    45  	Stat(property string) (string, error)
    46  }
    47  
    48  // Compacter wraps the Compact method of a backing data store.
    49  type Compacter interface {
    50  	// Compact flattens the underlying data store for the given key range. In essence,
    51  	// deleted and overwritten versions are discarded, and the data is rearranged to
    52  	// reduce the cost of operations needed to access them.
    53  	//
    54  	// A nil start is treated as a key before all keys in the data store; a nil limit
    55  	// is treated as a key after all keys in the data store. If both is nil then it
    56  	// will compact entire data store.
    57  	Compact(start []byte, limit []byte) error
    58  }
    59  
    60  // KeyValueStore contains all the methods required to allow handling different
    61  // key-value data stores backing the high level database.
    62  type KeyValueStore interface {
    63  	KeyValueReader
    64  	KeyValueWriter
    65  	Batcher
    66  	Iteratee
    67  	Stater
    68  	Compacter
    69  	io.Closer
    70  }
    71  
    72  // AncientReader contains the methods required to read from immutable ancient data.
    73  type AncientReader interface {
    74  	// HasAncient returns an indicator whether the specified data exists in the
    75  	// ancient store.
    76  	HasAncient(kind string, number uint64) (bool, error)
    77  
    78  	// Ancient retrieves an ancient binary blob from the append-only immutable files.
    79  	Ancient(kind string, number uint64) ([]byte, error)
    80  
    81  	// Ancients returns the ancient item numbers in the ancient store.
    82  	Ancients() (uint64, error)
    83  
    84  	// AncientSize returns the ancient size of the specified category.
    85  	AncientSize(kind string) (uint64, error)
    86  }
    87  
    88  // AncientWriter contains the methods required to write to immutable ancient data.
    89  type AncientWriter interface {
    90  	// AppendAncient injects all binary blobs belong to block at the end of the
    91  	// append-only immutable table files.
    92  	AppendAncient(number uint64, hash, header, body, receipt, etxSet []byte) error
    93  
    94  	// TruncateAncients discards all but the first n ancient data from the ancient store.
    95  	TruncateAncients(n uint64) error
    96  
    97  	// Sync flushes all in-memory ancient store data to disk.
    98  	Sync() error
    99  }
   100  
   101  // Reader contains the methods required to read data from both key-value as well as
   102  // immutable ancient data.
   103  type Reader interface {
   104  	KeyValueReader
   105  	AncientReader
   106  }
   107  
   108  // Writer contains the methods required to write data to both key-value as well as
   109  // immutable ancient data.
   110  type Writer interface {
   111  	KeyValueWriter
   112  	AncientWriter
   113  }
   114  
   115  // AncientStore contains all the methods required to allow handling different
   116  // ancient data stores backing immutable chain data store.
   117  type AncientStore interface {
   118  	AncientReader
   119  	AncientWriter
   120  	io.Closer
   121  }
   122  
   123  // Database contains all the methods required by the high level database to not
   124  // only access the key-value data store but also the chain freezer.
   125  type Database interface {
   126  	Reader
   127  	Writer
   128  	Batcher
   129  	Iteratee
   130  	Stater
   131  	Compacter
   132  	io.Closer
   133  }