github.com/ethereum/go-ethereum@v1.16.1/core/history/historymode.go (about) 1 // Copyright 2025 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 history 18 19 import ( 20 "fmt" 21 22 "github.com/ethereum/go-ethereum/common" 23 "github.com/ethereum/go-ethereum/params" 24 ) 25 26 // HistoryMode configures history pruning. 27 type HistoryMode uint32 28 29 const ( 30 // KeepAll (default) means that all chain history down to genesis block will be kept. 31 KeepAll HistoryMode = iota 32 33 // KeepPostMerge sets the history pruning point to the merge activation block. 34 KeepPostMerge 35 ) 36 37 func (m HistoryMode) IsValid() bool { 38 return m <= KeepPostMerge 39 } 40 41 func (m HistoryMode) String() string { 42 switch m { 43 case KeepAll: 44 return "all" 45 case KeepPostMerge: 46 return "postmerge" 47 default: 48 return fmt.Sprintf("invalid HistoryMode(%d)", m) 49 } 50 } 51 52 // MarshalText implements encoding.TextMarshaler. 53 func (m HistoryMode) MarshalText() ([]byte, error) { 54 if m.IsValid() { 55 return []byte(m.String()), nil 56 } 57 return nil, fmt.Errorf("unknown history mode %d", m) 58 } 59 60 // UnmarshalText implements encoding.TextUnmarshaler. 61 func (m *HistoryMode) UnmarshalText(text []byte) error { 62 switch string(text) { 63 case "all": 64 *m = KeepAll 65 case "postmerge": 66 *m = KeepPostMerge 67 default: 68 return fmt.Errorf(`unknown sync mode %q, want "all" or "postmerge"`, text) 69 } 70 return nil 71 } 72 73 type PrunePoint struct { 74 BlockNumber uint64 75 BlockHash common.Hash 76 } 77 78 // PrunePoints the pre-defined history pruning cutoff blocks for known networks. 79 // They point to the first post-merge block. Any pruning should truncate *up to* but excluding 80 // given block. 81 var PrunePoints = map[common.Hash]*PrunePoint{ 82 // mainnet 83 params.MainnetGenesisHash: { 84 BlockNumber: 15537393, 85 BlockHash: common.HexToHash("0x55b11b918355b1ef9c5db810302ebad0bf2544255b530cdce90674d5887bb286"), 86 }, 87 // sepolia 88 params.SepoliaGenesisHash: { 89 BlockNumber: 1450409, 90 BlockHash: common.HexToHash("0x229f6b18ca1552f1d5146deceb5387333f40dc6275aebee3f2c5c4ece07d02db"), 91 }, 92 } 93 94 // PrunedHistoryError is returned by APIs when the requested history is pruned. 95 type PrunedHistoryError struct{} 96 97 func (e *PrunedHistoryError) Error() string { return "pruned history unavailable" } 98 func (e *PrunedHistoryError) ErrorCode() int { return 4444 }