Skip to content

Commit

Permalink
Merge pull request #4077 from ElrondNetwork/update-master-rc-2022-may
Browse files Browse the repository at this point in the history
Update master rc 2022 may
  • Loading branch information
iulianpascalau committed May 13, 2022
2 parents 5c3bc83 + f12e872 commit 8a47315
Show file tree
Hide file tree
Showing 8 changed files with 33 additions and 81 deletions.
4 changes: 4 additions & 0 deletions .github/workflows/create_release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,10 @@ on:
- main
workflow_dispatch:

permissions:
contents: write
pull-requests: write

jobs:
build:
strategy:
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
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
1 change: 1 addition & 0 deletions vm/interface.go
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,7 @@ type ContextHandler interface {
AddCode(addr []byte, code []byte)
AddTxValueToSmartContract(value *big.Int, scAddress []byte)
SetGasProvided(gasProvided uint64)
GetReturnMessage() string
}

// MessageSignVerifier is used to verify if message was signed with given public key
Expand Down
5 changes: 5 additions & 0 deletions vm/mock/systemEIStub.go
Original file line number Diff line number Diff line change
Expand Up @@ -222,6 +222,11 @@ func (s *SystemEIStub) AddReturnMessage(msg string) {
}
}

// GetReturnMessage -
func (s *SystemEIStub) GetReturnMessage() string {
return s.ReturnMessage
}

// GetStorage -
func (s *SystemEIStub) GetStorage(key []byte) []byte {
if s.GetStorageCalled != nil {
Expand Down
13 changes: 12 additions & 1 deletion vm/process/systemVM.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package process

import (
"math/big"
"sync"

"github.com/ElrondNetwork/elrond-go-core/core"
Expand Down Expand Up @@ -118,7 +119,17 @@ func (s *systemVM) RunSmartContractCall(input *vmcommon.ContractCallInput) (*vmc
}

returnCode := contract.Execute(input)
vmOutput := s.systemEI.CreateVMOutput()
var vmOutput *vmcommon.VMOutput
if returnCode == vmcommon.Ok {
vmOutput = s.systemEI.CreateVMOutput()
} else {
vmOutput = &vmcommon.VMOutput{
GasRemaining: 0,
GasRefund: big.NewInt(0),
ReturnMessage: s.systemEI.GetReturnMessage(),
}
}

vmOutput.ReturnCode = returnCode

return vmOutput, nil
Expand Down
5 changes: 5 additions & 0 deletions vm/systemSmartContracts/eei.go
Original file line number Diff line number Diff line change
Expand Up @@ -448,6 +448,11 @@ func (host *vmContext) AddReturnMessage(message string) {
host.returnMessage += "@" + message
}

// GetReturnMessage will return the accumulated return message
func (host *vmContext) GetReturnMessage() string {
return host.returnMessage
}

// AddLogEntry will add a log entry
func (host *vmContext) AddLogEntry(entry *vmcommon.LogEntry) {
host.logs = append(host.logs, entry)
Expand Down

0 comments on commit 8a47315

Please sign in to comment.