Skip to content

Commit

Permalink
Merge pull request #6015 from multiversx/merge-rc-v1.6.next1-rc-v1.7.…
Browse files Browse the repository at this point in the history
…0-2024.03.05

Merge rc v1.6.next1 rc v1.7.0 2024.03.05
  • Loading branch information
iulianpascalau authored Mar 5, 2024
2 parents 64154cd + 36603dd commit 0a6277c
Show file tree
Hide file tree
Showing 7 changed files with 384 additions and 452 deletions.
25 changes: 2 additions & 23 deletions cmd/node/flags.go
Original file line number Diff line number Diff line change
Expand Up @@ -633,7 +633,8 @@ func applyCompatibleConfigs(log logger.Logger, configs *config.Configs) error {

isInHistoricalBalancesMode := operationmodes.SliceContainsElement(operationModes, operationmodes.OperationModeHistoricalBalances)
if isInHistoricalBalancesMode {
processHistoricalBalancesMode(log, configs)
// TODO move all operation modes settings in the common/operationmodes package and add tests
operationmodes.ProcessHistoricalBalancesMode(log, configs)
}

isInDbLookupExtensionMode := operationmodes.SliceContainsElement(operationModes, operationmodes.OperationModeDbLookupExtension)
Expand All @@ -649,28 +650,6 @@ func applyCompatibleConfigs(log logger.Logger, configs *config.Configs) error {
return nil
}

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,
)
}

func processDbLookupExtensionMode(log logger.Logger, configs *config.Configs) {
configs.GeneralConfig.DbLookupExtensions.Enabled = true
configs.GeneralConfig.StoragePruning.Enabled = true
Expand Down
41 changes: 41 additions & 0 deletions common/operationmodes/historicalBalances.go
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
}
141 changes: 141 additions & 0 deletions common/operationmodes/historicalBalances_test.go
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))
})

}
1 change: 1 addition & 0 deletions common/operationmodes/operationmodes.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import (
"strings"
)

// constants that define the operation mode of the node
const (
OperationModeFullArchive = "full-archive"
OperationModeDbLookupExtension = "db-lookup-extension"
Expand Down
Loading

0 comments on commit 0a6277c

Please sign in to comment.