From 103bda558ed7dfdd9da13356f8821bcfc7b0e41a Mon Sep 17 00:00:00 2001 From: robertsasu Date: Tue, 10 May 2022 12:24:33 +0300 Subject: [PATCH 1/4] create vmOutput if error on system vm --- vm/interface.go | 1 + vm/mock/systemEIStub.go | 5 +++++ vm/process/systemVM.go | 14 +++++++++++++- vm/systemSmartContracts/eei.go | 5 +++++ 4 files changed, 24 insertions(+), 1 deletion(-) diff --git a/vm/interface.go b/vm/interface.go index b1384bbf7f4..7265b02f875 100644 --- a/vm/interface.go +++ b/vm/interface.go @@ -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 diff --git a/vm/mock/systemEIStub.go b/vm/mock/systemEIStub.go index 8b6d2d0ad37..bfdb74ce898 100644 --- a/vm/mock/systemEIStub.go +++ b/vm/mock/systemEIStub.go @@ -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 { diff --git a/vm/process/systemVM.go b/vm/process/systemVM.go index 0599965261e..52c83a409d3 100644 --- a/vm/process/systemVM.go +++ b/vm/process/systemVM.go @@ -1,6 +1,7 @@ package process import ( + "math/big" "sync" "github.com/ElrondNetwork/elrond-go-core/core" @@ -118,7 +119,18 @@ func (s *systemVM) RunSmartContractCall(input *vmcommon.ContractCallInput) (*vmc } returnCode := contract.Execute(input) - vmOutput := s.systemEI.CreateVMOutput() + vmOutput := &vmcommon.VMOutput{} + if returnCode == vmcommon.Ok { + vmOutput = s.systemEI.CreateVMOutput() + } else { + vmOutput = &vmcommon.VMOutput{ + GasRemaining: 0, + GasRefund: big.NewInt(0), + ReturnCode: returnCode, + ReturnMessage: s.systemEI.GetReturnMessage(), + } + } + vmOutput.ReturnCode = returnCode return vmOutput, nil diff --git a/vm/systemSmartContracts/eei.go b/vm/systemSmartContracts/eei.go index 631101321c1..5cb8abf3391 100644 --- a/vm/systemSmartContracts/eei.go +++ b/vm/systemSmartContracts/eei.go @@ -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) From dc8904fb92ae3830eeab66e5a1d0b012f1fcbed0 Mon Sep 17 00:00:00 2001 From: robertsasu Date: Tue, 10 May 2022 13:09:13 +0300 Subject: [PATCH 2/4] fix after review --- vm/process/systemVM.go | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/vm/process/systemVM.go b/vm/process/systemVM.go index 52c83a409d3..346c5961ed2 100644 --- a/vm/process/systemVM.go +++ b/vm/process/systemVM.go @@ -119,14 +119,13 @@ func (s *systemVM) RunSmartContractCall(input *vmcommon.ContractCallInput) (*vmc } returnCode := contract.Execute(input) - vmOutput := &vmcommon.VMOutput{} + var vmOutput *vmcommon.VMOutput if returnCode == vmcommon.Ok { vmOutput = s.systemEI.CreateVMOutput() } else { vmOutput = &vmcommon.VMOutput{ GasRemaining: 0, GasRefund: big.NewInt(0), - ReturnCode: returnCode, ReturnMessage: s.systemEI.GetReturnMessage(), } } From 3486dccd1d54ccbe392dccaceb55f1a0e936700c Mon Sep 17 00:00:00 2001 From: Iulian Pascalau Date: Fri, 13 May 2022 11:51:40 +0300 Subject: [PATCH 3/4] - fixed create release workflow --- .github/workflows/create_release.yml | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/.github/workflows/create_release.yml b/.github/workflows/create_release.yml index eb617a59d09..64d69891305 100644 --- a/.github/workflows/create_release.yml +++ b/.github/workflows/create_release.yml @@ -7,6 +7,10 @@ on: - main workflow_dispatch: +permissions: + contents: write + pull-requests: write + jobs: build: strategy: From f12e872ee99039b2aaf086d348accb60b354268c Mon Sep 17 00:00:00 2001 From: Iulian Pascalau Date: Fri, 13 May 2022 12:54:27 +0300 Subject: [PATCH 4/4] - linter fixes --- cmd/termui/presenter/common.go | 71 ------------------- .../termuic/termuiRenders/widgetsRender.go | 12 ++-- consensus/spos/bls/subroundBlock_test.go | 3 - 3 files changed, 6 insertions(+), 80 deletions(-) diff --git a/cmd/termui/presenter/common.go b/cmd/termui/presenter/common.go index eaf06a7c8e7..8678a23f21d 100644 --- a/cmd/termui/presenter/common.go +++ b/cmd/termui/presenter/common.go @@ -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 { @@ -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 -} diff --git a/cmd/termui/view/termuic/termuiRenders/widgetsRender.go b/cmd/termui/view/termuic/termuiRenders/widgetsRender.go index 0bcc478948e..b025f038e3e 100644 --- a/cmd/termui/view/termuic/termuiRenders/widgetsRender.go +++ b/cmd/termui/view/termuic/termuiRenders/widgetsRender.go @@ -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 @@ -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) @@ -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) @@ -138,7 +138,7 @@ func (wr *WidgetsRender) prepareInstanceInfo() { fmt.Sprintf("Node name: %s (Shard %s - %s)", nodeName, shardIdStr, - strings.Title(nodeTypeAndListDisplay), + nodeTypeAndListDisplay, ), } @@ -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) @@ -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) diff --git a/consensus/spos/bls/subroundBlock_test.go b/consensus/spos/bls/subroundBlock_test.go index 8241c6bc3be..21130cb280b 100644 --- a/consensus/spos/bls/subroundBlock_test.go +++ b/consensus/spos/bls/subroundBlock_test.go @@ -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) {