-
Notifications
You must be signed in to change notification settings - Fork 203
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #6015 from multiversx/merge-rc-v1.6.next1-rc-v1.7.…
…0-2024.03.05 Merge rc v1.6.next1 rc v1.7.0 2024.03.05
- Loading branch information
Showing
7 changed files
with
384 additions
and
452 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
package operationmodes | ||
|
||
import ( | ||
"github.com/multiversx/mx-chain-go/config" | ||
logger "github.com/multiversx/mx-chain-logger-go" | ||
) | ||
|
||
// ProcessHistoricalBalancesMode will process the provided flags for the historical balances | ||
func ProcessHistoricalBalancesMode(log logger.Logger, configs *config.Configs) { | ||
configs.GeneralConfig.StoragePruning.Enabled = true | ||
configs.GeneralConfig.StoragePruning.ValidatorCleanOldEpochsData = false | ||
configs.GeneralConfig.StoragePruning.ObserverCleanOldEpochsData = false | ||
configs.GeneralConfig.GeneralSettings.StartInEpochEnabled = false | ||
configs.GeneralConfig.StoragePruning.AccountsTrieCleanOldEpochsData = false | ||
configs.GeneralConfig.StateTriesConfig.AccountsStatePruningEnabled = false | ||
configs.GeneralConfig.DbLookupExtensions.Enabled = true | ||
configs.PreferencesConfig.Preferences.FullArchive = true | ||
|
||
log.Warn("the node is in historical balances mode! Will auto-set some config values", | ||
"StoragePruning.Enabled", configs.GeneralConfig.StoragePruning.Enabled, | ||
"StoragePruning.ValidatorCleanOldEpochsData", configs.GeneralConfig.StoragePruning.ValidatorCleanOldEpochsData, | ||
"StoragePruning.ObserverCleanOldEpochsData", configs.GeneralConfig.StoragePruning.ObserverCleanOldEpochsData, | ||
"StoragePruning.AccountsTrieCleanOldEpochsData", configs.GeneralConfig.StoragePruning.AccountsTrieCleanOldEpochsData, | ||
"GeneralSettings.StartInEpochEnabled", configs.GeneralConfig.GeneralSettings.StartInEpochEnabled, | ||
"StateTriesConfig.AccountsStatePruningEnabled", configs.GeneralConfig.StateTriesConfig.AccountsStatePruningEnabled, | ||
"DbLookupExtensions.Enabled", configs.GeneralConfig.DbLookupExtensions.Enabled, | ||
"Preferences.FullArchive", configs.PreferencesConfig.Preferences.FullArchive, | ||
) | ||
} | ||
|
||
// IsInHistoricalBalancesMode returns true if the configuration provided denotes a historical balances mode | ||
func IsInHistoricalBalancesMode(configs *config.Configs) bool { | ||
return configs.GeneralConfig.StoragePruning.Enabled && | ||
!configs.GeneralConfig.StoragePruning.ValidatorCleanOldEpochsData && | ||
!configs.GeneralConfig.StoragePruning.ObserverCleanOldEpochsData && | ||
!configs.GeneralConfig.GeneralSettings.StartInEpochEnabled && | ||
!configs.GeneralConfig.StoragePruning.AccountsTrieCleanOldEpochsData && | ||
!configs.GeneralConfig.StateTriesConfig.AccountsStatePruningEnabled && | ||
configs.GeneralConfig.DbLookupExtensions.Enabled && | ||
configs.PreferencesConfig.Preferences.FullArchive | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,141 @@ | ||
package operationmodes | ||
|
||
import ( | ||
"testing" | ||
|
||
"github.com/multiversx/mx-chain-go/config" | ||
"github.com/multiversx/mx-chain-go/testscommon" | ||
"github.com/stretchr/testify/assert" | ||
) | ||
|
||
func TestProcessHistoricalBalancesMode(t *testing.T) { | ||
t.Parallel() | ||
|
||
cfg := &config.Configs{ | ||
GeneralConfig: &config.Config{}, | ||
PreferencesConfig: &config.Preferences{}, | ||
} | ||
ProcessHistoricalBalancesMode(&testscommon.LoggerStub{}, cfg) | ||
|
||
assert.True(t, cfg.GeneralConfig.StoragePruning.Enabled) | ||
assert.False(t, cfg.GeneralConfig.StoragePruning.ValidatorCleanOldEpochsData) | ||
assert.False(t, cfg.GeneralConfig.StoragePruning.ObserverCleanOldEpochsData) | ||
assert.False(t, cfg.GeneralConfig.GeneralSettings.StartInEpochEnabled) | ||
assert.False(t, cfg.GeneralConfig.StoragePruning.AccountsTrieCleanOldEpochsData) | ||
assert.False(t, cfg.GeneralConfig.StateTriesConfig.AccountsStatePruningEnabled) | ||
assert.True(t, cfg.GeneralConfig.DbLookupExtensions.Enabled) | ||
assert.True(t, cfg.PreferencesConfig.Preferences.FullArchive) | ||
} | ||
|
||
func TestIsInHistoricalBalancesMode(t *testing.T) { | ||
t.Parallel() | ||
|
||
t.Run("empty configs should return false", func(t *testing.T) { | ||
t.Parallel() | ||
|
||
cfg := &config.Configs{ | ||
GeneralConfig: &config.Config{}, | ||
PreferencesConfig: &config.Preferences{}, | ||
} | ||
assert.False(t, IsInHistoricalBalancesMode(cfg)) | ||
}) | ||
t.Run("storage pruning disabled should return false", func(t *testing.T) { | ||
t.Parallel() | ||
|
||
cfg := &config.Configs{ | ||
GeneralConfig: &config.Config{}, | ||
PreferencesConfig: &config.Preferences{}, | ||
} | ||
ProcessHistoricalBalancesMode(&testscommon.LoggerStub{}, cfg) | ||
cfg.GeneralConfig.StoragePruning.Enabled = false | ||
assert.False(t, IsInHistoricalBalancesMode(cfg)) | ||
}) | ||
t.Run("validator clean old epoch data enabled should return false", func(t *testing.T) { | ||
t.Parallel() | ||
|
||
cfg := &config.Configs{ | ||
GeneralConfig: &config.Config{}, | ||
PreferencesConfig: &config.Preferences{}, | ||
} | ||
ProcessHistoricalBalancesMode(&testscommon.LoggerStub{}, cfg) | ||
cfg.GeneralConfig.StoragePruning.ValidatorCleanOldEpochsData = true | ||
assert.False(t, IsInHistoricalBalancesMode(cfg)) | ||
}) | ||
t.Run("observer clean old epoch data enabled should return false", func(t *testing.T) { | ||
t.Parallel() | ||
|
||
cfg := &config.Configs{ | ||
GeneralConfig: &config.Config{}, | ||
PreferencesConfig: &config.Preferences{}, | ||
} | ||
ProcessHistoricalBalancesMode(&testscommon.LoggerStub{}, cfg) | ||
cfg.GeneralConfig.StoragePruning.ObserverCleanOldEpochsData = true | ||
assert.False(t, IsInHistoricalBalancesMode(cfg)) | ||
}) | ||
t.Run("start in epoch enabled should return false", func(t *testing.T) { | ||
t.Parallel() | ||
|
||
cfg := &config.Configs{ | ||
GeneralConfig: &config.Config{}, | ||
PreferencesConfig: &config.Preferences{}, | ||
} | ||
ProcessHistoricalBalancesMode(&testscommon.LoggerStub{}, cfg) | ||
cfg.GeneralConfig.GeneralSettings.StartInEpochEnabled = true | ||
assert.False(t, IsInHistoricalBalancesMode(cfg)) | ||
}) | ||
t.Run("accounts trie clean old epoch data enabled should return false", func(t *testing.T) { | ||
t.Parallel() | ||
|
||
cfg := &config.Configs{ | ||
GeneralConfig: &config.Config{}, | ||
PreferencesConfig: &config.Preferences{}, | ||
} | ||
ProcessHistoricalBalancesMode(&testscommon.LoggerStub{}, cfg) | ||
cfg.GeneralConfig.StoragePruning.AccountsTrieCleanOldEpochsData = true | ||
assert.False(t, IsInHistoricalBalancesMode(cfg)) | ||
}) | ||
t.Run("accounts state pruning enabled should return false", func(t *testing.T) { | ||
t.Parallel() | ||
|
||
cfg := &config.Configs{ | ||
GeneralConfig: &config.Config{}, | ||
PreferencesConfig: &config.Preferences{}, | ||
} | ||
ProcessHistoricalBalancesMode(&testscommon.LoggerStub{}, cfg) | ||
cfg.GeneralConfig.StateTriesConfig.AccountsStatePruningEnabled = true | ||
assert.False(t, IsInHistoricalBalancesMode(cfg)) | ||
}) | ||
t.Run("db lookup extension disabled should return false", func(t *testing.T) { | ||
t.Parallel() | ||
|
||
cfg := &config.Configs{ | ||
GeneralConfig: &config.Config{}, | ||
PreferencesConfig: &config.Preferences{}, | ||
} | ||
ProcessHistoricalBalancesMode(&testscommon.LoggerStub{}, cfg) | ||
cfg.GeneralConfig.DbLookupExtensions.Enabled = false | ||
assert.False(t, IsInHistoricalBalancesMode(cfg)) | ||
}) | ||
t.Run("not a full archive node should return false", func(t *testing.T) { | ||
t.Parallel() | ||
|
||
cfg := &config.Configs{ | ||
GeneralConfig: &config.Config{}, | ||
PreferencesConfig: &config.Preferences{}, | ||
} | ||
ProcessHistoricalBalancesMode(&testscommon.LoggerStub{}, cfg) | ||
cfg.PreferencesConfig.Preferences.FullArchive = false | ||
assert.False(t, IsInHistoricalBalancesMode(cfg)) | ||
}) | ||
t.Run("with historical balances config should return true", func(t *testing.T) { | ||
t.Parallel() | ||
|
||
cfg := &config.Configs{ | ||
GeneralConfig: &config.Config{}, | ||
PreferencesConfig: &config.Preferences{}, | ||
} | ||
ProcessHistoricalBalancesMode(&testscommon.LoggerStub{}, cfg) | ||
assert.True(t, IsInHistoricalBalancesMode(cfg)) | ||
}) | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.