ancient_scheme.go 3.0 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586
  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. package rawdb
  17. import "fmt"
  18. // The list of table names of chain freezer.
  19. const (
  20. // chainFreezerHeaderTable indicates the name of the freezer header table.
  21. chainFreezerHeaderTable = "headers"
  22. // chainFreezerHashTable indicates the name of the freezer canonical hash table.
  23. chainFreezerHashTable = "hashes"
  24. // chainFreezerBodiesTable indicates the name of the freezer block body table.
  25. chainFreezerBodiesTable = "bodies"
  26. // chainFreezerReceiptTable indicates the name of the freezer receipts table.
  27. chainFreezerReceiptTable = "receipts"
  28. // chainFreezerDifficultyTable indicates the name of the freezer total difficulty table.
  29. chainFreezerDifficultyTable = "diffs"
  30. )
  31. // chainFreezerNoSnappy configures whether compression is disabled for the ancient-tables.
  32. // Hashes and difficulties don't compress well.
  33. var chainFreezerNoSnappy = map[string]bool{
  34. chainFreezerHeaderTable: false,
  35. chainFreezerHashTable: true,
  36. chainFreezerBodiesTable: false,
  37. chainFreezerReceiptTable: false,
  38. chainFreezerDifficultyTable: true,
  39. }
  40. // The list of identifiers of ancient stores.
  41. var (
  42. chainFreezerName = "chain" // the folder name of chain segment ancient store.
  43. )
  44. // freezers the collections of all builtin freezers.
  45. var freezers = []string{chainFreezerName}
  46. // InspectFreezerTable dumps out the index of a specific freezer table. The passed
  47. // ancient indicates the path of root ancient directory where the chain freezer can
  48. // be opened. Start and end specify the range for dumping out indexes.
  49. // Note this function can only be used for debugging purposes.
  50. func InspectFreezerTable(ancient string, freezerName string, tableName string, start, end int64) error {
  51. var (
  52. path string
  53. tables map[string]bool
  54. )
  55. switch freezerName {
  56. case chainFreezerName:
  57. path, tables = resolveChainFreezerDir(ancient), chainFreezerNoSnappy
  58. default:
  59. return fmt.Errorf("unknown freezer, supported ones: %v", freezers)
  60. }
  61. noSnappy, exist := tables[tableName]
  62. if !exist {
  63. var names []string
  64. for name := range tables {
  65. names = append(names, name)
  66. }
  67. return fmt.Errorf("unknown table, supported ones: %v", names)
  68. }
  69. table, err := newFreezerTable(path, tableName, noSnappy, true)
  70. if err != nil {
  71. return err
  72. }
  73. table.dumpIndexStdout(start, end)
  74. return nil
  75. }