github.com/ethereum/go-ethereum@v1.14.3/core/rawdb/ancient_scheme.go (about)

     1  // Copyright 2022 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 rawdb
    18  
    19  import (
    20  	"path/filepath"
    21  
    22  	"github.com/ethereum/go-ethereum/ethdb"
    23  )
    24  
    25  // The list of table names of chain freezer.
    26  const (
    27  	// ChainFreezerHeaderTable indicates the name of the freezer header table.
    28  	ChainFreezerHeaderTable = "headers"
    29  
    30  	// ChainFreezerHashTable indicates the name of the freezer canonical hash table.
    31  	ChainFreezerHashTable = "hashes"
    32  
    33  	// ChainFreezerBodiesTable indicates the name of the freezer block body table.
    34  	ChainFreezerBodiesTable = "bodies"
    35  
    36  	// ChainFreezerReceiptTable indicates the name of the freezer receipts table.
    37  	ChainFreezerReceiptTable = "receipts"
    38  
    39  	// ChainFreezerDifficultyTable indicates the name of the freezer total difficulty table.
    40  	ChainFreezerDifficultyTable = "diffs"
    41  )
    42  
    43  // chainFreezerNoSnappy configures whether compression is disabled for the ancient-tables.
    44  // Hashes and difficulties don't compress well.
    45  var chainFreezerNoSnappy = map[string]bool{
    46  	ChainFreezerHeaderTable:     false,
    47  	ChainFreezerHashTable:       true,
    48  	ChainFreezerBodiesTable:     false,
    49  	ChainFreezerReceiptTable:    false,
    50  	ChainFreezerDifficultyTable: true,
    51  }
    52  
    53  const (
    54  	// stateHistoryTableSize defines the maximum size of freezer data files.
    55  	stateHistoryTableSize = 2 * 1000 * 1000 * 1000
    56  
    57  	// stateHistoryAccountIndex indicates the name of the freezer state history table.
    58  	stateHistoryMeta         = "history.meta"
    59  	stateHistoryAccountIndex = "account.index"
    60  	stateHistoryStorageIndex = "storage.index"
    61  	stateHistoryAccountData  = "account.data"
    62  	stateHistoryStorageData  = "storage.data"
    63  )
    64  
    65  var stateFreezerNoSnappy = map[string]bool{
    66  	stateHistoryMeta:         true,
    67  	stateHistoryAccountIndex: false,
    68  	stateHistoryStorageIndex: false,
    69  	stateHistoryAccountData:  false,
    70  	stateHistoryStorageData:  false,
    71  }
    72  
    73  // The list of identifiers of ancient stores.
    74  var (
    75  	ChainFreezerName = "chain" // the folder name of chain segment ancient store.
    76  	StateFreezerName = "state" // the folder name of reverse diff ancient store.
    77  )
    78  
    79  // freezers the collections of all builtin freezers.
    80  var freezers = []string{ChainFreezerName, StateFreezerName}
    81  
    82  // NewStateFreezer initializes the ancient store for state history.
    83  //
    84  //   - if the empty directory is given, initializes the pure in-memory
    85  //     state freezer (e.g. dev mode).
    86  //   - if non-empty directory is given, initializes the regular file-based
    87  //     state freezer.
    88  func NewStateFreezer(ancientDir string, readOnly bool) (ethdb.ResettableAncientStore, error) {
    89  	if ancientDir == "" {
    90  		return NewMemoryFreezer(readOnly, stateFreezerNoSnappy), nil
    91  	}
    92  	return newResettableFreezer(filepath.Join(ancientDir, StateFreezerName), "eth/db/state", readOnly, stateHistoryTableSize, stateFreezerNoSnappy)
    93  }