Skip to content

Commit

Permalink
Add new config param to disable snapshot file creation. Defaults to f…
Browse files Browse the repository at this point in the history
…alse. (#1711)
  • Loading branch information
alexsporn authored and muXxer committed Dec 27, 2022
1 parent a087afa commit dcff558
Show file tree
Hide file tree
Showing 8 changed files with 17 additions and 0 deletions.
1 change: 1 addition & 0 deletions config.json
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@
"autoRevalidation": false
},
"snapshots": {
"enabled": false,
"depth": 50,
"interval": 200,
"fullPath": "snapshots/mainnet/full_snapshot.bin",
Expand Down
1 change: 1 addition & 0 deletions config_devnet.json
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@
"autoRevalidation": false
},
"snapshots": {
"enabled": false,
"depth": 50,
"interval": 200,
"fullPath": "snapshots/devnet/full_snapshot.bin",
Expand Down
1 change: 1 addition & 0 deletions core/snapshot/core.go
Original file line number Diff line number Diff line change
Expand Up @@ -181,6 +181,7 @@ func provide(c *dig.Container) {
deps.Storage,
deps.SyncManager,
deps.UTXOManager,
deps.NodeConfig.Bool(CfgSnapshotsEnabled),
deps.NetworkID,
networkIDSource,
deps.SnapshotsFullPath,
Expand Down
3 changes: 3 additions & 0 deletions core/snapshot/params.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@ import (
)

const (
// whether to generate snapshot files.
CfgSnapshotsEnabled = "snapshots.enabled"
// the depth, respectively the starting point, at which a snapshot of the ledger is generated
CfgSnapshotsDepth = "snapshots.depth"
// interval, in milestones, at which snapshot files are created (snapshots are only created if the node is synced)
Expand Down Expand Up @@ -42,6 +44,7 @@ var params = &node.PluginParams{
Params: map[string]*flag.FlagSet{
"nodeConfig": func() *flag.FlagSet {
fs := flag.NewFlagSet("", flag.ContinueOnError)
fs.Bool(CfgSnapshotsEnabled, false, "whether to generate snapshot files")
fs.Int(CfgSnapshotsDepth, 50, "the depth, respectively the starting point, at which a snapshot of the ledger is generated")
fs.Int(CfgSnapshotsInterval, 200, "interval, in milestones, at which snapshot files are created (snapshots are only created if the node is synced)")
fs.String(CfgSnapshotsFullPath, "snapshots/mainnet/full_snapshot.bin", "path to the full snapshot file")
Expand Down
2 changes: 2 additions & 0 deletions documentation/docs/how_tos/managing_a_node.md
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ Another important directory is the `snapshots` directory. You can control the `s

```json
"snapshots": {
"enabled": false,
"interval": 50,
"fullPath": "snapshots/mainnet/full_snapshot.bin",
"deltaPath": "snapshots/mainnet/delta_snapshot.bin",
Expand Down Expand Up @@ -111,6 +112,7 @@ Your node's ledger accumulates many messages, which uses a significant disk capa

```json
"snapshots": {
"enabled": false,
"interval": 50,
"fullPath": "snapshots/mainnet/full_snapshot.bin",
"deltaPath": "snapshots/mainnet/delta_snapshot.bin",
Expand Down
2 changes: 2 additions & 0 deletions documentation/docs/references/configuration.md
Original file line number Diff line number Diff line change
Expand Up @@ -146,6 +146,7 @@ Example:

| Name | Description | Type |
| :---------------------------- | :--------------------------------------------------------------------------------------------------------------------------------------------------------------------- | :--------------- |
| enabled | whether to generate snapshot files | bool |
| depth | The depth, respectively the starting point, at which a snapshot of the ledger is generated | integer |
| interval | Interval, in milestones, at which snapshot files are created (snapshots are only created if the node is synced) | integer |
| fullPath | Path to the full snapshot file | string |
Expand All @@ -164,6 +165,7 @@ Example:

```json
"snapshots": {
"enabled": false,
"depth": 50,
"interval": 200,
"fullPath": "snapshots/mainnet/full_snapshot.bin",
Expand Down
6 changes: 6 additions & 0 deletions pkg/snapshot/snapshot.go
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,7 @@ type SnapshotManager struct {
storage *storage.Storage
syncManager *syncmanager.SyncManager
utxoManager *utxo.Manager
snapshotCreationEnabled bool
networkID uint64
networkIDSource string
snapshotFullPath string
Expand Down Expand Up @@ -108,6 +109,7 @@ func NewSnapshotManager(
storage *storage.Storage,
syncManager *syncmanager.SyncManager,
utxoManager *utxo.Manager,
snapshotCreationEnabled bool,
networkID uint64,
networkIDSource string,
snapshotFullPath string,
Expand All @@ -131,6 +133,7 @@ func NewSnapshotManager(
WrappedLogger: utils.NewWrappedLogger(log),
tangleDatabase: tangleDatabase,
utxoDatabase: utxoDatabase,
snapshotCreationEnabled: snapshotCreationEnabled,
storage: storage,
syncManager: syncManager,
utxoManager: utxoManager,
Expand Down Expand Up @@ -168,6 +171,9 @@ func (s *SnapshotManager) IsSnapshottingOrPruning() bool {
}

func (s *SnapshotManager) shouldTakeSnapshot(confirmedMilestoneIndex milestone.Index) bool {
if !s.snapshotCreationEnabled {
return false
}

snapshotInfo := s.storage.SnapshotInfo()
if snapshotInfo == nil {
Expand Down
1 change: 1 addition & 0 deletions private_tangle/config_private_tangle.json
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@
"autoRevalidation": false
},
"snapshots": {
"enabled": false,
"depth": 50,
"interval": 200,
"fullPath": "snapshots/private_tangle/full_snapshot.bin",
Expand Down

0 comments on commit dcff558

Please sign in to comment.