code.vegaprotocol.io/vega@v0.79.0/core/snapshot/config.go (about) 1 // Copyright (C) 2023 Gobalsky Labs Limited 2 // 3 // This program is free software: you can redistribute it and/or modify 4 // it under the terms of the GNU Affero General Public License as 5 // published by the Free Software Foundation, either version 3 of the 6 // License, or (at your option) any later version. 7 // 8 // This program is distributed in the hope that it will be useful, 9 // but WITHOUT ANY WARRANTY; without even the implied warranty of 10 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 11 // GNU Affero General Public License for more details. 12 // 13 // You should have received a copy of the GNU Affero General Public License 14 // along with this program. If not, see <http://www.gnu.org/licenses/>. 15 16 package snapshot 17 18 import ( 19 "errors" 20 21 "code.vegaprotocol.io/vega/core/types" 22 "code.vegaprotocol.io/vega/libs/config/encoding" 23 "code.vegaprotocol.io/vega/logging" 24 ) 25 26 const ( 27 LevelDB = "GOLevelDB" 28 InMemoryDB = "memory" 29 ) 30 31 var ( 32 ErrStartHeightCannotBeNegative = errors.New("the value for \"load-from-block-height\" must be positive, or zero") 33 ErrKeepRecentMustBeHigherOrEqualTo1 = errors.New("the value for \"snapshot-keep-recent\" must higher or equal to 1") 34 ) 35 36 type Config struct { 37 Level encoding.LogLevel `choice:"debug" choice:"info" choice:"warning" choice:"error" choice:"panic" choice:"fatal" description:"Logging level (default: info)" long:"log-level"` 38 KeepRecent uint `description:"Number of historic snapshots to keep on disk. The minimum value is 1." long:"snapshot-keep-recent"` 39 RetryLimit uint `description:"Maximum number of times to try and apply snapshot chunk coming from state-sync" long:"max-retries"` 40 Storage string `choice:"GOLevelDB" choice:"memory" description:"Storage type to use" long:"storage"` 41 StartHeight int64 `description:"If there are local snapshots, load the one matching the specified block height. If there is no local snapshot, and state-sync is enabled, the node waits for a snapshot to match the specified block height to be offered by the network peers. If set to 0, the latest snapshot is loaded." long:"load-from-block-height"` 42 } 43 44 // DefaultConfig creates an instance of the package specific configuration, given a 45 // pointer to a logger instance to be used for logging within the package. 46 func DefaultConfig() Config { 47 return Config{ 48 Level: encoding.LogLevel{Level: logging.InfoLevel}, 49 KeepRecent: 10, 50 RetryLimit: 5, 51 Storage: LevelDB, 52 StartHeight: 0, 53 } 54 } 55 56 // Validate checks the values in the config file are sensible. 57 func (c *Config) Validate() error { 58 if c.KeepRecent < 1 { 59 return ErrKeepRecentMustBeHigherOrEqualTo1 60 } 61 62 if c.StartHeight < 0 { 63 // TODO Enable this validation error once the migration to 0.73 is done 64 // on mainnet. In the meantime, we set it to 0 as this will save the 65 // validators to update their configuration from -1 to 0, which would 66 // trigger the removal of the snapshots in case of a rollback. 67 // In previous version, setting it to 0 is interpreted as starting 68 // from scratch. 69 // return ErrStartHeightCannotBeNegative 70 c.StartHeight = 0 71 } 72 73 switch c.Storage { 74 case InMemoryDB, LevelDB: 75 return nil 76 default: 77 return types.ErrInvalidSnapshotStorageMethod 78 } 79 }