Skip to content

Commit

Permalink
Merge pull request #3916 from ElrondNetwork/feat/release-2022-April
Browse files Browse the repository at this point in the history
Feat/release 2022 april
  • Loading branch information
LucianMincu committed Apr 23, 2022
2 parents b7668c2 + 49f8528 commit 668938b
Show file tree
Hide file tree
Showing 168 changed files with 4,287 additions and 1,525 deletions.
3 changes: 2 additions & 1 deletion .github/workflows/code-coverage.yml
Expand Up @@ -5,7 +5,8 @@ on:
branches:
- master
pull_request:
branches: [ master, development ]
branches: [ master, development, feat/*, rc/* ]

workflow_dispatch:

jobs:
Expand Down
3 changes: 2 additions & 1 deletion .github/workflows/golangci-lint.yml
Expand Up @@ -4,7 +4,8 @@ on:
branches:
- master
pull_request:
branches: [ master, development ]
branches: [ master, development, feat/*, rc/* ]

jobs:
golangci:
name: golangci linter
Expand Down
3 changes: 1 addition & 2 deletions README.md
Expand Up @@ -34,7 +34,6 @@ $ mkdir -p $GOPATH/src/github.com/ElrondNetwork
$ cd $GOPATH/src/github.com/ElrondNetwork
$ git clone https://github.com/ElrondNetwork/elrond-go
$ cd elrond-go && git checkout master
$ GO111MODULE=on go mod vendor
$ cd cmd/node && go build
```
The node depends on the Arwen Virtual Machine, which is automatically managed by the node.
Expand Down Expand Up @@ -170,6 +169,7 @@ docker run -d -v /absolute/path/to/config/:/data/ elrondnetwork/elrond-go-node:l
- [x] Testing
- [x] Automate tests with AWS
- [x] Nodes Monitoring
- [x] DEX integration

### In progress

Expand All @@ -181,7 +181,6 @@ docker run -d -v /absolute/path/to/config/:/data/ elrondnetwork/elrond-go-node:l
- [ ] Merging
- [ ] Redundancy
- [ ] Privacy
- [ ] DEX integration
- [ ] Interoperability
- [ ] Optimizations
- [ ] Smart Contract
Expand Down
21 changes: 16 additions & 5 deletions cmd/node/config/config.toml
Expand Up @@ -52,6 +52,20 @@
# Applicable only for observers
ObserverCleanOldEpochsData = false

# If this flag is set to false, the node won't delete the AccountsTrie database for old epochs
# Applicable for both observers and validators
# WARNING! Setting this to false will increase each epoch's directory size with the trie snapshot,
# which might easily cause the node to run out of disk space.
AccountsTrieCleanOldEpochsData = true

# AccountsTrieSkipRemovalCustomPattern represents the custom pattern that determines when AccountsTrie database
# doesn't have to be cleaned
# Format: %x,%y - if an epoch is divisible by x or by y, then the AccountsTrie database won't be removed
# If empty, then all databases will be removed
# If invalid format, then an error will be returned
# Applicable only if AccountsTrieCleanOldEpochsData is set to true
AccountsTrieSkipRemovalCustomPattern = "%50"

# NumEpochsToKeep - if the flag above is set to true, this will set the number of epochs to keep in the storage.
# Epochs older that (current epoch - NumOfEpochsToKeep) will be removed
NumEpochsToKeep = 4
Expand Down Expand Up @@ -588,10 +602,6 @@
# clutter the network exactly in the same moment
MaxDeviationTimeInMilliseconds = 25

[Logger]
Path = "logs"
StackTraceDepth = 2

[AddressPubkeyConverter]
Length = 32
Type = "bech32"
Expand Down Expand Up @@ -889,7 +899,8 @@
MaxOpenFiles = 10

[Logs]
LogFileLifeSpanInSec = 86400
LogFileLifeSpanInMB = 1024 # 1GB
LogFileLifeSpanInSec = 86400 # 1 day

[TrieSync]
NumConcurrentTrieSyncers = 200
Expand Down
4 changes: 2 additions & 2 deletions cmd/node/factory/interface.go
Expand Up @@ -53,13 +53,13 @@ type P2PAntifloodHandler interface {

// FileLoggingHandler will handle log file rotation
type FileLoggingHandler interface {
ChangeFileLifeSpan(newDuration time.Duration) error
ChangeFileLifeSpan(newDuration time.Duration, newSizeInMB uint64) error
Close() error
IsInterfaceNil() bool
}

// TODO: find a better naming
// StatusHandlersUtils provides some functionality for statusHandlers
// TODO: find a better naming
type StatusHandlersUtils interface {
StatusHandler() core.AppStatusHandler
Metrics() external.StatusMetricsHandler
Expand Down
12 changes: 10 additions & 2 deletions cmd/node/main.go
Expand Up @@ -97,7 +97,10 @@ func startNodeRunner(c *cli.Context, log logger.Logger, version string) error {
}

if !check.IfNil(fileLogging) {
err := fileLogging.ChangeFileLifeSpan(time.Second * time.Duration(cfgs.GeneralConfig.Logs.LogFileLifeSpanInSec))
timeLogLifeSpan := time.Second * time.Duration(cfgs.GeneralConfig.Logs.LogFileLifeSpanInSec)
sizeLogLifeSpanInMB := uint64(cfgs.GeneralConfig.Logs.LogFileLifeSpanInMB)

err := fileLogging.ChangeFileLifeSpan(timeLogLifeSpan, sizeLogLifeSpanInMB)
if err != nil {
return err
}
Expand Down Expand Up @@ -243,7 +246,12 @@ func attachFileLogger(log logger.Logger, flagsConfig *config.ContextFlagsConfig)
var fileLogging factory.FileLoggingHandler
var err error
if flagsConfig.SaveLogFile {
fileLogging, err = logging.NewFileLogging(flagsConfig.WorkingDir, defaultLogsPath, logFilePrefix)
args := logging.ArgsFileLogging{
WorkingDir: flagsConfig.WorkingDir,
DefaultLogsPath: defaultLogsPath,
LogFilePrefix: logFilePrefix,
}
fileLogging, err = logging.NewFileLogging(args)
if err != nil {
return nil, fmt.Errorf("%w creating a log file", err)
}
Expand Down
7 changes: 4 additions & 3 deletions cmd/seednode/config/config.toml
Expand Up @@ -4,8 +4,9 @@
# the reencoded version (in percents).
# 0 disables the feature.
[Marshalizer]
Type = "gogo protobuf"
SizeCheckDelta = 10
Type = "gogo protobuf"
SizeCheckDelta = 10

[Logs]
LogFileLifeSpanInSec = 86400
LogFileLifeSpanInMB = 1024 # 1GB
LogFileLifeSpanInSec = 86400 # 1 day
13 changes: 10 additions & 3 deletions cmd/seednode/main.go
Expand Up @@ -78,7 +78,7 @@ VERSION:
" log level.",
Value: "*:" + logger.LogInfo.String(),
}
//logFile is used when the log output needs to be logged in a file
// logFile is used when the log output needs to be logged in a file
logSaveFile = cli.BoolFlag{
Name: "log-save",
Usage: "Boolean option for enabling log saving. If set, it will automatically save all the logs into a file.",
Expand Down Expand Up @@ -151,12 +151,19 @@ func startNode(ctx *cli.Context) error {
var fileLogging factory.FileLoggingHandler
if withLogFile {
workingDir := getWorkingDir(log)
fileLogging, err = logging.NewFileLogging(workingDir, defaultLogsPath, logFilePrefix)
args := logging.ArgsFileLogging{
WorkingDir: workingDir,
DefaultLogsPath: defaultLogsPath,
LogFilePrefix: logFilePrefix,
}
fileLogging, err = logging.NewFileLogging(args)
if err != nil {
return fmt.Errorf("%w creating a log file", err)
}

err = fileLogging.ChangeFileLifeSpan(time.Second * time.Duration(generalConfig.Logs.LogFileLifeSpanInSec))
timeLogLifeSpan := time.Second * time.Duration(generalConfig.Logs.LogFileLifeSpanInSec)
sizeLogLifeSpanInMB := uint64(generalConfig.Logs.LogFileLifeSpanInMB)
err = fileLogging.ChangeFileLifeSpan(timeLogLifeSpan, sizeLogLifeSpanInMB)
if err != nil {
return err
}
Expand Down
66 changes: 18 additions & 48 deletions cmd/termui/presenter/instanceInfoGetters.go
@@ -1,14 +1,12 @@
package presenter

import (
"math/big"
"strconv"
"strings"

"github.com/ElrondNetwork/elrond-go/common"
)

const precisionRewards = 2

// GetAppVersion will return application version
func (psh *PresenterStatusHandler) GetAppVersion() string {
return psh.getFromCacheAsString(common.MetricAppVersion)
Expand All @@ -34,6 +32,23 @@ func (psh *PresenterStatusHandler) GetPublicKeyBlockSign() string {
return psh.getFromCacheAsString(common.MetricPublicKeyBlockSign)
}

// GetRedundancyLevel will return the redundancy level of the node
func (psh *PresenterStatusHandler) GetRedundancyLevel() int64 {
// redundancy level is sent as string as JSON unmarshal doesn't treat well the casting from interface{} to int64
redundancyLevelStr := psh.getFromCacheAsString(common.MetricRedundancyLevel)
i64Val, err := strconv.ParseInt(redundancyLevelStr, 10, 64)
if err != nil {
return 0
}

return i64Val
}

// GetRedundancyIsMainActive will return the info about redundancy main machine
func (psh *PresenterStatusHandler) GetRedundancyIsMainActive() string {
return psh.getFromCacheAsString(common.MetricRedundancyIsMainActive)
}

// GetShardId will return shard Id of node
func (psh *PresenterStatusHandler) GetShardId() uint64 {
return psh.getFromCacheAsUint64(common.MetricShardId)
Expand Down Expand Up @@ -81,48 +96,3 @@ func (psh *PresenterStatusHandler) GetNodeName() string {

return nodeName
}

// GetTotalRewardsValue will return total value of rewards and how the rewards were increased on every second
// Rewards estimation will be equal with :
// numSignedBlocks * denomination * Rewards
func (psh *PresenterStatusHandler) GetTotalRewardsValue() (string, string) {
numSignedBlocks := psh.getFromCacheAsUint64(common.MetricCountConsensusAcceptedBlocks)
rewardsInErd := psh.computeRewardsInErd()

totalRewardsFloat := big.NewFloat(float64(numSignedBlocks))
totalRewardsFloat.Mul(totalRewardsFloat, rewardsInErd)
difRewards := big.NewFloat(0).Sub(totalRewardsFloat, psh.totalRewardsOld)

defer func() {
psh.totalRewardsOld = totalRewardsFloat
}()

return psh.totalRewardsOld.Text('f', precisionRewards), difRewards.Text('f', precisionRewards)
}

// CalculateRewardsPerHour will return an approximation of how many ERDs a validator will earn per hour
// Rewards estimation per hour will be equals with :
// chanceToBeInConsensus * roundsPerHour * hitRate * denominationCoefficient * Rewards
func (psh *PresenterStatusHandler) CalculateRewardsPerHour() string {
chanceToBeInConsensus := psh.computeChanceToBeInConsensus()
roundsPerHourAccordingToHitRate := psh.computeRoundsPerHourAccordingToHitRate()
rewardsInErd := psh.computeRewardsInErd()
if chanceToBeInConsensus == 0 || roundsPerHourAccordingToHitRate == 0 || rewardsInErd.Cmp(big.NewFloat(0)) <= 0 {
return "0"
}

rewardsPerHourCoefficient := chanceToBeInConsensus * roundsPerHourAccordingToHitRate
totalRewardsPerHourFloat := big.NewFloat(rewardsPerHourCoefficient)
totalRewardsPerHourFloat.Mul(totalRewardsPerHourFloat, rewardsInErd)
return totalRewardsPerHourFloat.Text('f', precisionRewards)
}

// GetZeros will return a string with a specific number of zeros
func (psh *PresenterStatusHandler) GetZeros() string {
retValue := "." + strings.Repeat("0", precisionRewards)
if retValue == "." {
return ""
}

return retValue
}
76 changes: 11 additions & 65 deletions cmd/termui/presenter/instanceInfoGetters_test.go
@@ -1,11 +1,11 @@
package presenter

import (
"math/big"
"testing"

"github.com/ElrondNetwork/elrond-go/common"
"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"
)

func TestPresenterStatusHandler_GetAppVersion(t *testing.T) {
Expand Down Expand Up @@ -150,72 +150,18 @@ func TestPresenterStatusHandler_GetNodeName(t *testing.T) {
assert.Equal(t, nodeName, result)
}

func TestPresenterStatusHandler_CalculateRewardsTotal(t *testing.T) {
func TestPresenterStatusHandler_GetRedundancyLevel(t *testing.T) {
t.Parallel()

rewardsValue := "1000"

numSignedBlocks := uint64(50)

presenterStatusHandler := NewPresenterStatusHandler()
presenterStatusHandler.SetStringValue(common.MetricRewardsValue, rewardsValue)
presenterStatusHandler.SetUInt64Value(common.MetricCountConsensusAcceptedBlocks, numSignedBlocks)
presenterStatusHandler.SetUInt64Value(common.MetricDenomination, 4)
totalRewards, diff := presenterStatusHandler.GetTotalRewardsValue()
expectedDifValue := "5" + presenterStatusHandler.GetZeros()

assert.Equal(t, "0"+presenterStatusHandler.GetZeros(), totalRewards)
assert.Equal(t, expectedDifValue, diff)
}

func TestPresenterStatusHandler_CalculateRewardsTotalRewards(t *testing.T) {
t.Parallel()

rewardsValue := "1000"
numSignedBlocks := uint64(50000)

presenterStatusHandler := NewPresenterStatusHandler()
totalRewardsOld, _ := big.NewFloat(0).SetString(rewardsValue)
presenterStatusHandler.totalRewardsOld = big.NewFloat(0).Set(totalRewardsOld)
presenterStatusHandler.SetStringValue(common.MetricRewardsValue, rewardsValue)
presenterStatusHandler.SetUInt64Value(common.MetricCountConsensusAcceptedBlocks, numSignedBlocks)
presenterStatusHandler.SetUInt64Value(common.MetricDenomination, 4)
totalRewards, diff := presenterStatusHandler.GetTotalRewardsValue()
expectedDiffValue := "4000" + presenterStatusHandler.GetZeros()

assert.Equal(t, totalRewardsOld.Text('f', precisionRewards), totalRewards)
assert.Equal(t, expectedDiffValue, diff)
testRedundancyParsing(t, "-1", -1)
testRedundancyParsing(t, "0", 0)
testRedundancyParsing(t, "invalid", 0)
testRedundancyParsing(t, "1", 1)
}

func TestPresenterStatusHandler_CalculateRewardsPerHourReturnZero(t *testing.T) {
t.Parallel()

presenterStatusHandler := NewPresenterStatusHandler()
result := presenterStatusHandler.CalculateRewardsPerHour()

assert.Equal(t, "0", result)
}

func TestPresenterStatusHandler_CalculateRewardsPerHourShouldWork(t *testing.T) {
t.Parallel()

consensusGroupSize := uint64(50)
numValidators := uint64(100)
totalBlocks := uint64(1000)
totalRounds := uint64(1000)
roundTime := uint64(6)
rewardsValue := "10000"

presenterStatusHandler := NewPresenterStatusHandler()
presenterStatusHandler.SetUInt64Value(common.MetricConsensusGroupSize, consensusGroupSize)
presenterStatusHandler.SetUInt64Value(common.MetricNumValidators, numValidators)
presenterStatusHandler.SetUInt64Value(common.MetricProbableHighestNonce, totalBlocks)
presenterStatusHandler.SetStringValue(common.MetricRewardsValue, rewardsValue)
presenterStatusHandler.SetUInt64Value(common.MetricCurrentRound, totalRounds)
presenterStatusHandler.SetUInt64Value(common.MetricRoundTime, roundTime)
presenterStatusHandler.SetUInt64Value(common.MetricDenomination, 4)
expectedValue := "300" + presenterStatusHandler.GetZeros()

result := presenterStatusHandler.CalculateRewardsPerHour()
assert.Equal(t, expectedValue, result)
func testRedundancyParsing(t *testing.T, input string, desiredOutput int64) {
psh := NewPresenterStatusHandler()
psh.SetStringValue(common.MetricRedundancyLevel, input)
redLev := psh.GetRedundancyLevel()
require.Equal(t, desiredOutput, redLev)
}
6 changes: 2 additions & 4 deletions cmd/termui/view/interface.go
Expand Up @@ -5,6 +5,8 @@ type Presenter interface {
GetAppVersion() string
GetNodeName() string
GetPublicKeyBlockSign() string
GetRedundancyLevel() int64
GetRedundancyIsMainActive() string
GetShardId() uint64
GetNodeType() string
GetPeerType() string
Expand Down Expand Up @@ -55,10 +57,6 @@ type Presenter interface {
GetNetworkSentBytesInEpoch() uint64
GetNetworkReceivedBytesInEpoch() uint64

GetTotalRewardsValue() (string, string)
CalculateRewardsPerHour() string
GetZeros() string

InvalidateCache()
IsInterfaceNil() bool
}

0 comments on commit 668938b

Please sign in to comment.