Skip to content

Commit

Permalink
Merge pull request #6115 from multiversx/merge-rc/v1.7.0-in-rc/v1.7.n…
Browse files Browse the repository at this point in the history
…ext1-12apr

Merge rc/v1.7.0 in rc/v1.7.next1 12apr
  • Loading branch information
iulianpascalau authored Apr 15, 2024
2 parents d2ae491 + d9412ac commit 5232e1e
Show file tree
Hide file tree
Showing 39 changed files with 1,509 additions and 441 deletions.
1 change: 1 addition & 0 deletions .github/workflows/golangci-lint.yml
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ on:
- master
pull_request:
branches: [ master, feat/*, rc/* ]
workflow_dispatch:

permissions:
contents: read
Expand Down
3 changes: 2 additions & 1 deletion cmd/node/config/prefs.toml
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,8 @@
# The Path indicates what value to change, while Value represents the new value. The node operator must make sure
# to follow the same type of the original value (ex: uint32: 37, float32: 37.0, bool: true)
# Also, the Value can be a struct (ex: { StartEpoch = 0, Version = "1.5" }) or an array (ex: [{ StartEpoch = 0, Version = "1.4" }, { StartEpoch = 1, Version = "1.5" }])
# File represents the file name that holds the configuration. Currently, the supported files are: config.toml, external.toml, p2p.toml, enableEpochs.toml and fullArchiveP2P.toml
# File represents the file name that holds the configuration. Currently, the supported files are:
# api.toml, config.toml, economics.toml, enableEpochs.toml, enableRounds.toml, external.toml, fullArchiveP2P.toml, p2p.toml, ratings.toml, systemSmartContractsConfig.toml
# -------------------------------
# Un-comment and update the following section in order to enable config values overloading
# -------------------------------
Expand Down
3 changes: 3 additions & 0 deletions common/constants.go
Original file line number Diff line number Diff line change
Expand Up @@ -100,6 +100,9 @@ const MetricCurrentRound = "erd_current_round"
// MetricNonce is the metric for monitoring the nonce of a node
const MetricNonce = "erd_nonce"

// MetricBlockTimestamp is the metric for monitoring the timestamp of the last synchronized block
const MetricBlockTimestamp = "erd_block_timestamp"

// MetricProbableHighestNonce is the metric for monitoring the max speculative nonce received by the node by listening on the network
const MetricProbableHighestNonce = "erd_probable_highest_nonce"

Expand Down
43 changes: 35 additions & 8 deletions config/overridableConfig/configOverriding.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,33 +10,60 @@ import (
)

const (
apiTomlFile = "api.toml"
configTomlFile = "config.toml"
economicsTomlFile = "economics.toml"
enableEpochsTomlFile = "enableEpochs.toml"
p2pTomlFile = "p2p.toml"
fullArchiveP2PTomlFile = "fullArchiveP2P.toml"
enableRoundsTomlFile = "enableRounds.toml"
externalTomlFile = "external.toml"
fullArchiveP2PTomlFile = "fullArchiveP2P.toml"
p2pTomlFile = "p2p.toml"
ratingsTomlFile = "ratings.toml"
systemSCTomlFile = "systemSmartContractsConfig.toml"
)

var (
availableConfigFilesForOverriding = []string{configTomlFile, enableEpochsTomlFile, p2pTomlFile, externalTomlFile}
log = logger.GetOrCreate("config")
availableConfigFilesForOverriding = []string{
apiTomlFile,
configTomlFile,
economicsTomlFile,
enableEpochsTomlFile,
enableRoundsTomlFile,
externalTomlFile,
fullArchiveP2PTomlFile,
p2pTomlFile,
ratingsTomlFile,
systemSCTomlFile,
}
log = logger.GetOrCreate("config")
)

// OverrideConfigValues will override config values for the specified configurations
func OverrideConfigValues(newConfigs []config.OverridableConfig, configs *config.Configs) error {
var err error
for _, newConfig := range newConfigs {
switch newConfig.File {
case apiTomlFile:
err = reflectcommon.AdaptStructureValueBasedOnPath(configs.ApiRoutesConfig, newConfig.Path, newConfig.Value)
case configTomlFile:
err = reflectcommon.AdaptStructureValueBasedOnPath(configs.GeneralConfig, newConfig.Path, newConfig.Value)
case economicsTomlFile:
err = reflectcommon.AdaptStructureValueBasedOnPath(configs.EconomicsConfig, newConfig.Path, newConfig.Value)
case enableEpochsTomlFile:
err = reflectcommon.AdaptStructureValueBasedOnPath(configs.EpochConfig, newConfig.Path, newConfig.Value)
case p2pTomlFile:
err = reflectcommon.AdaptStructureValueBasedOnPath(configs.MainP2pConfig, newConfig.Path, newConfig.Value)
case fullArchiveP2PTomlFile:
err = reflectcommon.AdaptStructureValueBasedOnPath(configs.FullArchiveP2pConfig, newConfig.Path, newConfig.Value)
case enableRoundsTomlFile:
err = reflectcommon.AdaptStructureValueBasedOnPath(configs.RoundConfig, newConfig.Path, newConfig.Value)
case externalTomlFile:
err = reflectcommon.AdaptStructureValueBasedOnPath(configs.ExternalConfig, newConfig.Path, newConfig.Value)
case fullArchiveP2PTomlFile:
err = reflectcommon.AdaptStructureValueBasedOnPath(configs.FullArchiveP2pConfig, newConfig.Path, newConfig.Value)
case p2pTomlFile:
err = reflectcommon.AdaptStructureValueBasedOnPath(configs.MainP2pConfig, newConfig.Path, newConfig.Value)
case ratingsTomlFile:
err = reflectcommon.AdaptStructureValueBasedOnPath(configs.RatingsConfig, newConfig.Path, newConfig.Value)
case systemSCTomlFile:
err = reflectcommon.AdaptStructureValueBasedOnPath(configs.SystemSCConfig, newConfig.Path, newConfig.Value)

default:
err = fmt.Errorf("invalid config file <%s>. Available options are %s", newConfig.File, strings.Join(availableConfigFilesForOverriding, ","))
}
Expand Down
56 changes: 55 additions & 1 deletion config/overridableConfig/configOverriding_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,8 @@ func TestOverrideConfigValues(t *testing.T) {
t.Parallel()

err := OverrideConfigValues([]config.OverridableConfig{{File: "invalid.toml"}}, &config.Configs{})
require.Equal(t, "invalid config file <invalid.toml>. Available options are config.toml,enableEpochs.toml,p2p.toml,external.toml", err.Error())
availableOptionsString := "api.toml,config.toml,economics.toml,enableEpochs.toml,enableRounds.toml,external.toml,fullArchiveP2P.toml,p2p.toml,ratings.toml,systemSmartContractsConfig.toml"
require.Equal(t, "invalid config file <invalid.toml>. Available options are "+availableOptionsString, err.Error())
})

t.Run("nil config, should error", func(t *testing.T) {
Expand Down Expand Up @@ -82,6 +83,59 @@ func TestOverrideConfigValues(t *testing.T) {
require.Equal(t, uint32(37), configs.EpochConfig.EnableEpochs.ESDTMetadataContinuousCleanupEnableEpoch)
})

t.Run("should work for api.toml", func(t *testing.T) {
t.Parallel()

configs := &config.Configs{ApiRoutesConfig: &config.ApiRoutesConfig{}}

err := OverrideConfigValues([]config.OverridableConfig{{Path: "Logging.LoggingEnabled", Value: true, File: "api.toml"}}, configs)
require.NoError(t, err)
require.True(t, configs.ApiRoutesConfig.Logging.LoggingEnabled)
})

t.Run("should work for economics.toml", func(t *testing.T) {
t.Parallel()

configs := &config.Configs{EconomicsConfig: &config.EconomicsConfig{}}

err := OverrideConfigValues([]config.OverridableConfig{{Path: "GlobalSettings.GenesisTotalSupply", Value: "37", File: "economics.toml"}}, configs)
require.NoError(t, err)
require.Equal(t, "37", configs.EconomicsConfig.GlobalSettings.GenesisTotalSupply)
})

t.Run("should work for enableRounds.toml", func(t *testing.T) {
// TODO: fix this test
t.Skip("skipped, as this test requires the fix from this PR: https://github.com/multiversx/mx-chain-go/pull/5851")

t.Parallel()

configs := &config.Configs{RoundConfig: &config.RoundConfig{}}

err := OverrideConfigValues([]config.OverridableConfig{{Path: "RoundActivations.DisableAsyncCallV1.Round", Value: "37", File: "enableRounds.toml"}}, configs)
require.NoError(t, err)
require.Equal(t, uint32(37), configs.RoundConfig.RoundActivations["DisableAsyncCallV1"])
})

t.Run("should work for ratings.toml", func(t *testing.T) {
t.Parallel()

configs := &config.Configs{RatingsConfig: &config.RatingsConfig{}}

err := OverrideConfigValues([]config.OverridableConfig{{Path: "General.StartRating", Value: 37, File: "ratings.toml"}}, configs)
require.NoError(t, err)
require.Equal(t, uint32(37), configs.RatingsConfig.General.StartRating)
})

t.Run("should work for systemSmartContractsConfig.toml", func(t *testing.T) {
t.Parallel()

configs := &config.Configs{SystemSCConfig: &config.SystemSmartContractsConfig{}}

err := OverrideConfigValues([]config.OverridableConfig{{Path: "StakingSystemSCConfig.UnBondPeriod", Value: 37, File: "systemSmartContractsConfig.toml"}}, configs)
require.NoError(t, err)
require.Equal(t, uint64(37), configs.SystemSCConfig.StakingSystemSCConfig.UnBondPeriod)
})

t.Run("should work for go struct overwrite", func(t *testing.T) {
t.Parallel()

Expand Down
1 change: 1 addition & 0 deletions dataRetriever/blockchain/blockchain.go
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,7 @@ func (bc *blockChain) SetCurrentBlockHeaderAndRootHash(header data.HeaderHandler

bc.appStatusHandler.SetUInt64Value(common.MetricNonce, h.GetNonce())
bc.appStatusHandler.SetUInt64Value(common.MetricSynchronizedRound, h.GetRound())
bc.appStatusHandler.SetUInt64Value(common.MetricBlockTimestamp, h.GetTimeStamp())

bc.mut.Lock()
bc.currentBlockHeader = h.ShallowClone()
Expand Down
1 change: 1 addition & 0 deletions dataRetriever/blockchain/metachain.go
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,7 @@ func (mc *metaChain) SetCurrentBlockHeaderAndRootHash(header data.HeaderHandler,

mc.appStatusHandler.SetUInt64Value(common.MetricNonce, currHead.Nonce)
mc.appStatusHandler.SetUInt64Value(common.MetricSynchronizedRound, currHead.Round)
mc.appStatusHandler.SetUInt64Value(common.MetricBlockTimestamp, currHead.GetTimeStamp())

mc.mut.Lock()
mc.currentBlockHeader = currHead.ShallowClone()
Expand Down
4 changes: 1 addition & 3 deletions docker/node/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -10,12 +10,10 @@ RUN go build -v -ldflags="-X main.appVersion=$(git describe --tags --long --dirt
RUN cp /go/pkg/mod/github.com/multiversx/$(cat /go/mx-chain-go/go.mod | grep mx-chain-vm-v | sort -n | tail -n -1| awk -F '/' '{print$3}'| sed 's/ /@/g')/wasmer/libwasmer_linux_amd64.so /lib/libwasmer_linux_amd64.so
RUN cp /go/pkg/mod/github.com/multiversx/$(cat /go/mx-chain-go/go.mod | grep mx-chain-vm-go | sort -n | tail -n -1| awk -F '/' '{print$3}'| sed 's/ /@/g')/wasmer2/libvmexeccapi.so /lib/libvmexeccapi.so

WORKDIR /go/mx-chain-go/cmd/node

# ===== SECOND STAGE ======
FROM ubuntu:22.04
RUN apt-get update && apt-get upgrade -y
COPY --from=builder "/go/mx-chain-go/cmd/node" "/go/mx-chain-go/cmd/node/"
COPY --from=builder "/go/mx-chain-go/cmd/node/node" "/go/mx-chain-go/cmd/node/"
COPY --from=builder "/lib/libwasmer_linux_amd64.so" "/lib/libwasmer_linux_amd64.so"
COPY --from=builder "/lib/libvmexeccapi.so" "/lib/libvmexeccapi.so"
WORKDIR /go/mx-chain-go/cmd/node/
Expand Down
1 change: 1 addition & 0 deletions integrationTests/chainSimulator/interface.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,4 +21,5 @@ type ChainSimulator interface {
GenerateAndMintWalletAddress(targetShardID uint32, value *big.Int) (dtos.WalletAddress, error)
GetInitialWalletKeys() *dtos.InitialWalletKeys
GetAccount(address dtos.WalletAddress) (api.AccountResponse, error)
ForceResetValidatorStatisticsCache() error
}
133 changes: 133 additions & 0 deletions integrationTests/chainSimulator/staking/common.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,133 @@
package staking

import (
"encoding/hex"
"math/big"
"testing"

"github.com/multiversx/mx-chain-core-go/core"
"github.com/multiversx/mx-chain-core-go/data/transaction"
chainSimulatorIntegrationTests "github.com/multiversx/mx-chain-go/integrationTests/chainSimulator"
"github.com/multiversx/mx-chain-go/node/chainSimulator/configs"
"github.com/multiversx/mx-chain-go/node/chainSimulator/dtos"
chainSimulatorProcess "github.com/multiversx/mx-chain-go/node/chainSimulator/process"
"github.com/multiversx/mx-chain-go/process"
"github.com/multiversx/mx-chain-go/vm"
"github.com/stretchr/testify/require"
)

const (
minGasPrice = 1000000000
txVersion = 1
mockTxSignature = "sig"

// OkReturnCode the const for the ok return code
OkReturnCode = "ok"
// MockBLSSignature the const for a mocked bls signature
MockBLSSignature = "010101"
// GasLimitForStakeOperation the const for the gas limit value for the stake operation
GasLimitForStakeOperation = 50_000_000
// GasLimitForUnBond the const for the gas limit value for the unBond operation
GasLimitForUnBond = 12_000_000
// MaxNumOfBlockToGenerateWhenExecutingTx the const for the maximum number of block to generate when execute a transaction
MaxNumOfBlockToGenerateWhenExecutingTx = 7

// QueuedStatus the const for the queued status of a validators
QueuedStatus = "queued"
// StakedStatus the const for the staked status of a validators
StakedStatus = "staked"
// NotStakedStatus the const for the notStaked status of a validators
NotStakedStatus = "notStaked"
// AuctionStatus the const for the action status of a validators
AuctionStatus = "auction"
// UnStakedStatus the const for the unStaked status of a validators
UnStakedStatus = "unStaked"
)

var (
// ZeroValue the variable for the zero big int
ZeroValue = big.NewInt(0)
// OneEGLD the variable for one egld value
OneEGLD = big.NewInt(1000000000000000000)
//InitialDelegationValue the variable for the initial delegation value
InitialDelegationValue = big.NewInt(0).Mul(OneEGLD, big.NewInt(1250))
// MinimumStakeValue the variable for the minimum stake value
MinimumStakeValue = big.NewInt(0).Mul(OneEGLD, big.NewInt(2500))
)

// GetNonce will return the nonce of the provided address
func GetNonce(t *testing.T, cs chainSimulatorIntegrationTests.ChainSimulator, address dtos.WalletAddress) uint64 {
account, err := cs.GetAccount(address)
require.Nil(t, err)

return account.Nonce
}

// GenerateTransaction will generate a transaction based on input data
func GenerateTransaction(sender []byte, nonce uint64, receiver []byte, value *big.Int, data string, gasLimit uint64) *transaction.Transaction {
return &transaction.Transaction{
Nonce: nonce,
Value: value,
SndAddr: sender,
RcvAddr: receiver,
Data: []byte(data),
GasLimit: gasLimit,
GasPrice: minGasPrice,
ChainID: []byte(configs.ChainID),
Version: txVersion,
Signature: []byte(mockTxSignature),
}
}

// GetBLSKeyStatus will return the bls key status
func GetBLSKeyStatus(t *testing.T, metachainNode chainSimulatorProcess.NodeHandler, blsKey []byte) string {
scQuery := &process.SCQuery{
ScAddress: vm.StakingSCAddress,
FuncName: "getBLSKeyStatus",
CallerAddr: vm.StakingSCAddress,
CallValue: big.NewInt(0),
Arguments: [][]byte{blsKey},
}
result, _, err := metachainNode.GetFacadeHandler().ExecuteSCQuery(scQuery)
require.Nil(t, err)
require.Equal(t, OkReturnCode, result.ReturnCode)

return string(result.ReturnData[0])
}

// GetAllNodeStates will return the status of all the nodes that belong to the provided address
func GetAllNodeStates(t *testing.T, metachainNode chainSimulatorProcess.NodeHandler, address []byte) map[string]string {
scQuery := &process.SCQuery{
ScAddress: address,
FuncName: "getAllNodeStates",
CallerAddr: vm.StakingSCAddress,
CallValue: big.NewInt(0),
}
result, _, err := metachainNode.GetFacadeHandler().ExecuteSCQuery(scQuery)
require.Nil(t, err)
require.Equal(t, OkReturnCode, result.ReturnCode)

m := make(map[string]string)
status := ""
for _, resultData := range result.ReturnData {
if len(resultData) != 96 {
// not a BLS key
status = string(resultData)
continue
}

m[hex.EncodeToString(resultData)] = status
}

return m
}

// CheckValidatorStatus will compare the status of the provided bls key with the provided expected status
func CheckValidatorStatus(t *testing.T, cs chainSimulatorIntegrationTests.ChainSimulator, blsKey string, expectedStatus string) {
err := cs.ForceResetValidatorStatisticsCache()
require.Nil(t, err)

validatorsStatistics, err := cs.GetNodeHandler(core.MetachainShardId).GetFacadeHandler().ValidatorStatisticsApi()
require.Nil(t, err)
require.Equal(t, expectedStatus, validatorsStatistics[blsKey].ValidatorStatus)
}
Loading

0 comments on commit 5232e1e

Please sign in to comment.