Skip to content

Commit

Permalink
Merge pull request #4016 from ElrondNetwork/rc/2022-may
Browse files Browse the repository at this point in the history
RC/2022 may
  • Loading branch information
iulianpascalau authored May 19, 2022
2 parents 2a92e67 + 8a47315 commit 0c156ea
Show file tree
Hide file tree
Showing 37 changed files with 974 additions and 722 deletions.
8 changes: 4 additions & 4 deletions api/logs/logSender_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ func createMockLogSender() (*logs.LogSender, *mock.WsConnStub, io.Writer) {
return lsender, conn, ls.Writer()
}

//------- NewLogSender
// ------- NewLogSender

func TestNewLogSender_NilMarshalizerShouldErr(t *testing.T) {
t.Parallel()
Expand Down Expand Up @@ -82,7 +82,7 @@ func TestNewLogSender_ShouldWork(t *testing.T) {
removeWriterFromLogSubsystem(ls.Writer())
}

//------- StartSendingBlocking
// ------- StartSendingBlocking

func TestLogSender_StartSendingBlockingConnReadMessageErrShouldCloseConn(t *testing.T) {
t.Parallel()
Expand Down Expand Up @@ -144,7 +144,7 @@ func TestLogSender_StartSendingBlockingSendsMessage(t *testing.T) {
})

go func() {
//watchdog function
// watchdog function
time.Sleep(time.Millisecond * 10)

_ = ls.Writer().Close()
Expand All @@ -169,7 +169,7 @@ func TestLogSender_StartSendingBlockingSendsMessageAndStopsWhenReadClose(t *test
})

go func() {
//watchdog function
// watchdog function
time.Sleep(time.Millisecond * 10)

conn.SetReadMessageHandler(func() (messageType int, p []byte, err error) {
Expand Down
36 changes: 22 additions & 14 deletions api/mock/loggerStub.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,56 +4,64 @@ import logger "github.com/ElrondNetwork/elrond-go-logger"

// LoggerStub -
type LoggerStub struct {
LogCalled func(level string, message string, args ...interface{})
LogCalled func(level logger.LogLevel, message string, args ...interface{})
LogLineCalled func(line *logger.LogLine)
SetLevelCalled func(logLevel logger.LogLevel)
}

// Log -
func (l *LoggerStub) Log(logLevel logger.LogLevel, message string, args ...interface{}) {
if l.LogCalled != nil {
l.LogCalled(logLevel, message, args...)
}
}

// LogLine -
func (l *LoggerStub) LogLine(line *logger.LogLine) {
if l.LogLineCalled != nil {
l.LogLineCalled(line)
}
}

// Trace -
func (l *LoggerStub) Trace(message string, args ...interface{}) {
if l.LogCalled != nil {
l.LogCalled("TRACE", message, args...)
l.LogCalled(logger.LogTrace, message, args...)
}
}

// Debug -
func (l *LoggerStub) Debug(message string, args ...interface{}) {
if l.LogCalled != nil {
l.LogCalled("DEBUG", message, args...)
l.LogCalled(logger.LogDebug, message, args...)
}
}

// Info -
func (l *LoggerStub) Info(message string, args ...interface{}) {
if l.LogCalled != nil {
l.LogCalled("INFO", message, args...)
l.LogCalled(logger.LogInfo, message, args...)
}
}

// Warn -
func (l *LoggerStub) Warn(message string, args ...interface{}) {
if l.LogCalled != nil {
l.LogCalled("WARN", message, args...)
l.LogCalled(logger.LogWarning, message, args...)
}
}

// Error -
func (l *LoggerStub) Error(message string, args ...interface{}) {
if l.LogCalled != nil {
l.LogCalled("ERROR", message, args...)
l.LogCalled(logger.LogError, message, args...)
}
}

// LogIfError -
func (l *LoggerStub) LogIfError(err error, args ...interface{}) {
if l.LogCalled != nil && err != nil {
l.LogCalled("ERROR", err.Error(), args...)
}
}

// Log -
func (l *LoggerStub) Log(line *logger.LogLine) {
if l.LogCalled != nil {
l.LogCalled("Log", "line", line)
l.LogCalled(logger.LogError, err.Error(), args...)
}
}

Expand Down
12 changes: 6 additions & 6 deletions cmd/logviewer/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -69,25 +69,25 @@ VERSION:
Value: "*:" + logger.LogInfo.String(),
Destination: &argsConfig.logLevel,
}
//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.",
Destination: &argsConfig.logSave,
}
//useWss is used when the user require connection through wss
// useWss is used when the user require connection through wss
useWss = cli.BoolFlag{
Name: "use-wss",
Usage: "Will use wss instead of ws when creating the web socket",
Destination: &argsConfig.useWss,
}
//logWithCorrelation is used to enable log correlation elements
// logWithCorrelation is used to enable log correlation elements
logWithCorrelation = cli.BoolFlag{
Name: "log-correlation",
Usage: "Boolean option for enabling log correlation elements.",
Destination: &argsConfig.logWithCorrelation,
}
//logWithLoggerName is used to enable log correlation elements
// logWithLoggerName is used to enable log correlation elements
logWithLoggerName = cli.BoolFlag{
Name: "log-logger-name",
Usage: "Boolean option for logger name in the logs.",
Expand Down Expand Up @@ -209,7 +209,7 @@ func startLogViewer(ctx *cli.Context) error {
}
}()

//set this log's level to the lowest desired log level that matches received logs from elrond-go
// set this log's level to the lowest desired log level that matches received logs from elrond-go
lowestLogLevel := getLowestLogLevel(logLevels)
log.SetLevel(lowestLogLevel)

Expand Down Expand Up @@ -337,5 +337,5 @@ func outputMessage(message []byte) {
recoveredLogLine.Args[i] = str
}

log.Log(recoveredLogLine)
log.LogLine(recoveredLogLine)
}
3 changes: 3 additions & 0 deletions cmd/node/config/enableEpochs.toml
Original file line number Diff line number Diff line change
Expand Up @@ -190,6 +190,9 @@
# SCRSizeInvariantOnBuiltInResultEnableEpoch represents the epoch when scr size invariant on built in result is enabled
SCRSizeInvariantOnBuiltInResultEnableEpoch = 1

# CheckCorrectTokenIDForTransferRoleEnableEpoch represents the epoch when the correct token ID check is applied for transfer role verification
CheckCorrectTokenIDForTransferRoleEnableEpoch = 2

# MaxNodesChangeEnableEpoch holds configuration for changing the maximum number of nodes and the enabling epoch
MaxNodesChangeEnableEpoch = [
{ EpochEnable = 0, MaxNumNodes = 36, NodesToShufflePerShard = 4 },
Expand Down
6 changes: 3 additions & 3 deletions cmd/node/config/external.toml
Original file line number Diff line number Diff line change
Expand Up @@ -6,14 +6,14 @@
#Strongly suggested to activate this on a regular observer node.
Enabled = false
IndexerCacheSize = 0
BulkRequestMaxSizeInBytes = 4194304 # 4MB
URL = "http://localhost:9200"
UseKibana = false
Username = ""
Password = ""
# EnabledIndexes represents a slice of indexes that will be enabled for indexing. Full list is:
# ["tps", "rating", "transactions", "blocks", "validators", "miniblocks", "rounds", "accounts", "accountshistory", "receipts", "scresults", "accountsesdt", "accountsesdthistory", "epochinfo", "scdeploys", "tokens", "tags", "logs", "delegators"]
EnabledIndexes = ["tps", "rating", "transactions", "blocks", "validators", "miniblocks", "rounds", "accounts", "accountshistory", "receipts", "scresults", "accountsesdt", "accountsesdthistory", "epochinfo", "scdeploys", "tokens", "tags", "logs", "delegators"]

# ["rating", "transactions", "blocks", "validators", "miniblocks", "rounds", "accounts", "accountshistory", "receipts", "scresults", "accountsesdt", "accountsesdthistory", "epochinfo", "scdeploys", "tokens", "tags", "logs", "delegators", "operations"]
EnabledIndexes = ["rating", "transactions", "blocks", "validators", "miniblocks", "rounds", "accounts", "accountshistory", "receipts", "scresults", "accountsesdt", "accountsesdthistory", "epochinfo", "scdeploys", "tokens", "tags", "logs", "delegators", "operations"]
# EventNotifierConnector defines settings needed to configure and launch the event notifier component
[EventNotifierConnector]
# Enabled will turn on or off the event notifier connector
Expand Down
71 changes: 0 additions & 71 deletions cmd/termui/presenter/common.go
Original file line number Diff line number Diff line change
@@ -1,12 +1,5 @@
package presenter

import (
"math"
"math/big"

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

const metricNotAvailable = "N/A"

func (psh *PresenterStatusHandler) getFromCacheAsUint64(metric string) uint64 {
Expand Down Expand Up @@ -42,67 +35,3 @@ func (psh *PresenterStatusHandler) getFromCacheAsString(metric string) string {

return valStr
}

func (psh *PresenterStatusHandler) getBigIntFromStringMetric(metric string) *big.Int {
stringValue := psh.getFromCacheAsString(metric)
bigIntValue, ok := big.NewInt(0).SetString(stringValue, 10)
if !ok {
return big.NewInt(0)
}

return bigIntValue
}

func areEqualWithZero(parameters ...uint64) bool {
for _, param := range parameters {
if param == 0 {
return true
}
}

return false
}

func (psh *PresenterStatusHandler) computeChanceToBeInConsensus() float64 {
consensusGroupSize := psh.getFromCacheAsUint64(common.MetricConsensusGroupSize)
numValidators := psh.getFromCacheAsUint64(common.MetricNumValidators)
isChanceZero := areEqualWithZero(consensusGroupSize, numValidators)
if isChanceZero {
return 0
}

return float64(consensusGroupSize) / float64(numValidators)
}

func (psh *PresenterStatusHandler) computeRoundsPerHourAccordingToHitRate() float64 {
totalBlocks := psh.GetProbableHighestNonce()
rounds := psh.GetCurrentRound()
roundDuration := psh.GetRoundTime()
secondsInAnHour := uint64(3600)
isRoundsPerHourZero := areEqualWithZero(totalBlocks, rounds, roundDuration)
if isRoundsPerHourZero {
return 0
}

hitRate := float64(totalBlocks) / float64(rounds)
roundsPerHour := float64(secondsInAnHour) / float64(roundDuration)
return hitRate * roundsPerHour
}

func (psh *PresenterStatusHandler) computeRewardsInErd() *big.Float {
rewardsValue := psh.getBigIntFromStringMetric(common.MetricRewardsValue)
denomination := psh.getFromCacheAsUint64(common.MetricDenomination)
denominationCoefficientFloat := 1.0
if denomination > 0 {
denominationCoefficientFloat /= math.Pow10(int(denomination))
}

denominationCoefficient := big.NewFloat(denominationCoefficientFloat)

if rewardsValue.Cmp(big.NewInt(0)) <= 0 {
return big.NewFloat(0)
}

rewardsInErd := big.NewFloat(0).Mul(big.NewFloat(0).SetInt(rewardsValue), denominationCoefficient)
return rewardsInErd
}
12 changes: 6 additions & 6 deletions cmd/termui/view/termuic/termuiRenders/widgetsRender.go
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ type WidgetsRender struct {
presenter view.Presenter
}

//NewWidgetsRender method will create new WidgetsRender that display termui console
// NewWidgetsRender method will create new WidgetsRender that display termui console
func NewWidgetsRender(presenter view.Presenter, grid *DrawableContainer) (*WidgetsRender, error) {
if presenter == nil || presenter.IsInterfaceNil() {
return nil, view.ErrNilPresenterInterface
Expand Down Expand Up @@ -106,7 +106,7 @@ func (wr *WidgetsRender) setGrid() {
wr.container.SetBottom(gridBottom)
}

//RefreshData method is used to prepare data that are displayed on container
// RefreshData method is used to prepare data that are displayed on container
func (wr *WidgetsRender) RefreshData(numMillisecondsRefreshTime int) {
wr.prepareInstanceInfo()
wr.prepareChainInfo(numMillisecondsRefreshTime)
Expand All @@ -116,7 +116,7 @@ func (wr *WidgetsRender) RefreshData(numMillisecondsRefreshTime int) {
}

func (wr *WidgetsRender) prepareInstanceInfo() {
//8 rows and one column
// 8 rows and one column
numRows := 8
rows := make([][]string, numRows)

Expand All @@ -138,7 +138,7 @@ func (wr *WidgetsRender) prepareInstanceInfo() {
fmt.Sprintf("Node name: %s (Shard %s - %s)",
nodeName,
shardIdStr,
strings.Title(nodeTypeAndListDisplay),
nodeTypeAndListDisplay,
),
}

Expand Down Expand Up @@ -174,7 +174,7 @@ func (wr *WidgetsRender) prepareInstanceInfo() {
}

func (wr *WidgetsRender) prepareChainInfo(numMillisecondsRefreshTime int) {
//10 rows and one column
// 10 rows and one column
numRows := 10
rows := make([][]string, numRows)

Expand Down Expand Up @@ -266,7 +266,7 @@ func computeRedundancyStr(redundancyLevel int64, redundancyIsMainActive string)
}

func (wr *WidgetsRender) prepareBlockInfo() {
//7 rows and one column
// 7 rows and one column
numRows := 8
rows := make([][]string, numRows)

Expand Down
1 change: 1 addition & 0 deletions config/epochConfig.go
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,7 @@ type EnableEpochs struct {
DoNotReturnOldBlockInBlockchainHookEnableEpoch uint32
AddFailedRelayedTxToInvalidMBsDisableEpoch uint32
SCRSizeInvariantOnBuiltInResultEnableEpoch uint32
CheckCorrectTokenIDForTransferRoleEnableEpoch uint32
}

// GasScheduleByEpochs represents a gas schedule toml entry that will be applied from the provided epoch
Expand Down
15 changes: 8 additions & 7 deletions config/externalConfig.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,13 +9,14 @@ type ExternalConfig struct {

// ElasticSearchConfig will hold the configuration for the elastic search
type ElasticSearchConfig struct {
Enabled bool
IndexerCacheSize int
URL string
UseKibana bool
Username string
Password string
EnabledIndexes []string
Enabled bool
IndexerCacheSize int
BulkRequestMaxSizeInBytes int
URL string
UseKibana bool
Username string
Password string
EnabledIndexes []string
}

// EventNotifierConfig will hold the configuration for the events notifier driver
Expand Down
3 changes: 0 additions & 3 deletions consensus/spos/bls/subroundBlock_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -998,9 +998,6 @@ func TestSubroundBlock_CallFuncRemainingTimeWithStructShouldWork(t *testing.T) {

time.Sleep(200 * time.Millisecond)
assert.True(t, remainingTimeInCurrentRound() < 0)

roundStartTime = roundStartTime.Add(500 * time.Millisecond)
assert.True(t, remainingTimeInCurrentRound() < 0)
}

func TestSubroundBlock_CallFuncRemainingTimeWithStructShouldNotWork(t *testing.T) {
Expand Down
4 changes: 2 additions & 2 deletions consensus/spos/scheduledProcessor_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -148,10 +148,10 @@ func TestScheduledProcessorWrapper_IsProcessedInProgressStartingInFuture(t *test

sp.setStatus(inProgress)
startTime := time.Now()
sp.startTime = startTime.Add(10 * time.Millisecond)
sp.startTime = startTime.Add(500 * time.Millisecond)
require.False(t, sp.IsProcessedOKWithTimeout())
endTime := time.Now()
require.Less(t, endTime.Sub(startTime), time.Millisecond)
require.Less(t, endTime.Sub(startTime), time.Millisecond*100)
}

func TestScheduledProcessorWrapper_IsProcessedInProgressEarlyCompletion(t *testing.T) {
Expand Down
Loading

0 comments on commit 0c156ea

Please sign in to comment.