Skip to content

Commit

Permalink
Merge pull request #2609 from ElrondNetwork/EN-8515-linter-checks-fixes
Browse files Browse the repository at this point in the history
EN-8515: Linter issues
  • Loading branch information
LucianMincu committed Dec 19, 2020
2 parents 41898dd + 6840d07 commit a6ec73a
Show file tree
Hide file tree
Showing 107 changed files with 272 additions and 331 deletions.
2 changes: 1 addition & 1 deletion api/transaction/routes.go
Original file line number Diff line number Diff line change
Expand Up @@ -415,7 +415,7 @@ func GetTransaction(c *gin.Context) {
http.StatusBadRequest,
shared.GenericAPIResponse{
Data: nil,
Error: fmt.Sprintf("%s", errors.ErrValidation.Error()),
Error: errors.ErrValidation.Error(),
Code: shared.ReturnCodeRequestError,
},
)
Expand Down
3 changes: 2 additions & 1 deletion cmd/storer2elastic/dataprocessor/dataReplayer.go
Original file line number Diff line number Diff line change
Expand Up @@ -315,7 +315,8 @@ func (dr *dataReplayer) processMetaBlock(

shardsHeaderData := make(map[uint32][]*storer2ElasticData.HeaderData)
for _, shardInfo := range metaBlock.ShardInfo {
shardHdrData, errProcessShardInfo := dr.processShardInfo(dbsInfo, &shardInfo, metaBlock.Epoch, shardPersisters[shardInfo.ShardID])
shardInfoCopy := shardInfo
shardHdrData, errProcessShardInfo := dr.processShardInfo(dbsInfo, &shardInfoCopy, metaBlock.Epoch, shardPersisters[shardInfo.ShardID])
if errProcessShardInfo != nil {
log.Warn("cannot process shard info", "error", errProcessShardInfo)
return nil, errProcessShardInfo
Expand Down
4 changes: 2 additions & 2 deletions config/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -205,7 +205,7 @@ type ValidatorStatisticsConfig struct {
CacheRefreshIntervalInSec uint32
}

// ChangeMaxNodesConfig defines a config change tuple, with a maximum number enabled in a certain epoch number
// MaxNodesChangeConfig defines a config change tuple, with a maximum number enabled in a certain epoch number
type MaxNodesChangeConfig struct {
EpochEnable uint32
MaxNumNodes uint32
Expand Down Expand Up @@ -339,8 +339,8 @@ type VirtualMachineServicesConfig struct {

// VirtualMachineConfig holds configuration for a Virtual Machine service
type VirtualMachineConfig struct {
OutOfProcessEnabled bool
OutOfProcessConfig VirtualMachineOutOfProcessConfig
OutOfProcessEnabled bool
WarmInstanceEnabled bool
}

Expand Down
6 changes: 3 additions & 3 deletions config/systemSmartContractsConfig.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,13 +17,13 @@ type StakingSystemSCConfig struct {
UnJailValue string
MinStepValue string
UnBondPeriod uint64
StakingV2Epoch uint32
StakeEnableEpoch uint32
DoubleKeyProtectionEnableEpoch uint32
NumRoundsWithoutBleed uint64
MaximumPercentageToBleed float64
BleedPercentagePerRound float64
MaxNumberOfNodesForStake uint64
StakingV2Epoch uint32
StakeEnableEpoch uint32
DoubleKeyProtectionEnableEpoch uint32
ActivateBLSPubKeyMessageVerification bool
}

Expand Down
4 changes: 2 additions & 2 deletions consensus/broadcast/commonMessenger.go
Original file line number Diff line number Diff line change
Expand Up @@ -193,8 +193,8 @@ func (cm *commonMessenger) extractMetaMiniBlocksAndTransactions(
transactions map[string][][]byte,
) (map[uint32][]byte, map[string][][]byte) {

metaMiniBlocks := make(map[uint32][]byte, 0)
metaTransactions := make(map[string][][]byte, 0)
metaMiniBlocks := make(map[uint32][]byte)
metaTransactions := make(map[string][][]byte)

for shardID, mbsMarshalized := range miniBlocks {
if shardID != core.MetachainShardId {
Expand Down
1 change: 1 addition & 0 deletions consensus/broadcast/export.go
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@ func CreateDelayBroadcastDataForValidator(
}
}

// CreateValidatorHeaderBroadcastData creates a validatorHeaderBroadcastData object from the given parameters
func CreateValidatorHeaderBroadcastData(
headerHash []byte,
header data.HeaderHandler,
Expand Down
4 changes: 2 additions & 2 deletions consensus/spos/worker.go
Original file line number Diff line number Diff line change
Expand Up @@ -114,7 +114,7 @@ func NewWorker(args *WorkerArgs) (*Worker, error) {
ChainID: args.ChainID,
}

consensusMessageValidator, err := NewConsensusMessageValidator(argsConsensusMessageValidator)
consensusMessageValidatorObj, err := NewConsensusMessageValidator(argsConsensusMessageValidator)
if err != nil {
return nil, err
}
Expand All @@ -141,7 +141,7 @@ func NewWorker(args *WorkerArgs) (*Worker, error) {
poolAdder: args.PoolAdder,
}

wrk.consensusMessageValidator = consensusMessageValidator
wrk.consensusMessageValidator = consensusMessageValidatorObj
wrk.executeMessageChannel = make(chan *consensus.Message)
wrk.receivedMessagesCalls = make(map[consensus.MessageType]func(*consensus.Message) bool)
wrk.receivedHeadersHandlers = make([]func(data.HeaderHandler), 0)
Expand Down
4 changes: 2 additions & 2 deletions core/counting/concurrentShardedCounts.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,14 +9,14 @@ import (

var _ Counts = (*ConcurrentShardedCounts)(nil)

// ShardedCounts keeps counts for a sharded data structure
// ConcurrentShardedCounts keeps counts for a sharded data structure
// This implementation is concurrently safe
type ConcurrentShardedCounts struct {
mutex sync.RWMutex
byShard map[string]int64
}

// NewShardedCounts creates a new ShardedCounts
// NewConcurrentShardedCounts creates a new ConcurrentShardedCounts
func NewConcurrentShardedCounts() *ConcurrentShardedCounts {
return &ConcurrentShardedCounts{
byShard: make(map[string]int64),
Expand Down
2 changes: 1 addition & 1 deletion core/dblookupext/errors.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ package dblookupext
import (
"encoding/hex"
"errors"
fmt "fmt"
"fmt"
)

var errCannotCastToBlockBody = errors.New("cannot cast to block body")
Expand Down
4 changes: 2 additions & 2 deletions core/dblookupext/eventsHashesByTxHashIndex.go
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ func (eht *eventsHashesByTxHash) groupSmartContractResults(
epoch uint32,
scrResults map[string]data.TransactionHandler,
) map[string]*ResultsHashesByTxHash {
resultsHashesMap := make(map[string]*ResultsHashesByTxHash, 0)
resultsHashesMap := make(map[string]*ResultsHashesByTxHash)
for scrHash, scrHandler := range scrResults {
scrResult, ok := scrHandler.(*smartContractResult.SmartContractResult)
if !ok {
Expand All @@ -80,7 +80,7 @@ func (eht *eventsHashesByTxHash) groupSmartContractResults(

originalTxHash := string(scrResult.OriginalTxHash)

if _, ok := resultsHashesMap[originalTxHash]; !ok {
if _, hashExists := resultsHashesMap[originalTxHash]; !hashExists {
resultsHashesMap[originalTxHash] = &ResultsHashesByTxHash{
ScResultsHashesAndEpoch: []*ScResultsHashesAndEpoch{
{
Expand Down
9 changes: 5 additions & 4 deletions core/dblookupext/historyRepository.go
Original file line number Diff line number Diff line change
Expand Up @@ -181,9 +181,9 @@ func (hr *historyRepository) recordMiniblock(blockHeaderHash []byte, blockHeader
hr.markMiniblockMetadataAsRecentlyInserted(miniblockHash, epoch)

for _, txHash := range miniblock.TxHashes {
err := hr.miniblockHashByTxHashIndex.Put(txHash, miniblockHash)
if err != nil {
log.Warn("miniblockHashByTxHashIndex.Put()", "txHash", txHash, "err", err)
errPut := hr.miniblockHashByTxHashIndex.Put(txHash, miniblockHash)
if errPut != nil {
log.Warn("miniblockHashByTxHashIndex.Put()", "txHash", txHash, "err", errPut)
continue
}
}
Expand Down Expand Up @@ -278,7 +278,8 @@ func (hr *historyRepository) OnNotarizedBlocks(shardID uint32, headers []data.He
}

for _, shardData := range metaBlock.ShardInfo {
hr.onNotarizedInMetaBlock(headerHandler.GetNonce(), headerHash, &shardData)
shardDataCopy := shardData
hr.onNotarizedInMetaBlock(headerHandler.GetNonce(), headerHash, &shardDataCopy)
}
} else {
log.Error("onNotarizedBlocks(): unexpected type of header", "type", fmt.Sprintf("%T", headerHandler))
Expand Down
21 changes: 1 addition & 20 deletions core/indexer/elasticProcessor.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@ import (
"math/big"
"time"

"github.com/ElrondNetwork/elrond-go/config"
"github.com/ElrondNetwork/elrond-go/core"
"github.com/ElrondNetwork/elrond-go/core/check"
"github.com/ElrondNetwork/elrond-go/core/indexer/workItems"
Expand All @@ -32,7 +31,6 @@ type elasticProcessor struct {
accountsDB state.AccountsAdapter
dividerForDenomination float64
balancePrecision float64
feeConfig config.FeeSettings
}

// NewElasticProcessor creates an elasticsearch es and handles saving
Expand Down Expand Up @@ -113,7 +111,7 @@ func checkArgElasticProcessor(arguments ArgElasticProcessor) error {
return nil
}

func (ei *elasticProcessor) initWithKibana(indexTemplates, indexPolicies map[string]*bytes.Buffer) error {
func (ei *elasticProcessor) initWithKibana(indexTemplates, _ map[string]*bytes.Buffer) error {
err := ei.createOpenDistroTemplates(indexTemplates)
if err != nil {
return err
Expand Down Expand Up @@ -167,23 +165,6 @@ func (ei *elasticProcessor) initNoKibana(indexTemplates map[string]*bytes.Buffer
return nil
}

func (ei *elasticProcessor) createIndexPolicies(indexPolicies map[string]*bytes.Buffer) error {

indexesPolicies := []string{txPolicy, blockPolicy, miniblocksPolicy, ratingPolicy, roundPolicy, validatorsPolicy, accountsHistoryPolicy}
for _, indexPolicyName := range indexesPolicies {
indexPolicy := getTemplateByName(indexPolicyName, indexPolicies)
if indexPolicy != nil {
err := ei.elasticClient.CheckAndCreatePolicy(indexPolicyName, indexPolicy)
if err != nil {
log.Error("check and create policy", "policy", indexPolicy, "err", err)
return err
}
}
}

return nil
}

func (ei *elasticProcessor) createOpenDistroTemplates(indexTemplates map[string]*bytes.Buffer) error {
opendistroTemplate := getTemplateByName("opendistro", indexTemplates)
if opendistroTemplate != nil {
Expand Down
8 changes: 4 additions & 4 deletions core/indexer/processTransactions.go
Original file line number Diff line number Diff line change
Expand Up @@ -180,7 +180,7 @@ func isScResultSuccessful(scResultData []byte) bool {
}

func findAllChildScrResults(hash string, scrs map[string]*smartContractResult.SmartContractResult) map[string]*smartContractResult.SmartContractResult {
scrResults := make(map[string]*smartContractResult.SmartContractResult, 0)
scrResults := make(map[string]*smartContractResult.SmartContractResult)
for scrHash, scr := range scrs {
if string(scr.OriginalTxHash) == hash {
scrResults[scrHash] = scr
Expand Down Expand Up @@ -222,9 +222,9 @@ func isSCRForSenderWithGasUsed(dbScResult ScResult, tx *Transaction) bool {
isForSender := dbScResult.Receiver == tx.Sender
isRightNonce := dbScResult.Nonce == tx.Nonce+1
isFromCurrentTx := dbScResult.PreTxHash == tx.Hash
isDataOk := isDataOk(dbScResult.Data)
isScrDataOk := isDataOk(dbScResult.Data)

return isFromCurrentTx && isForSender && isRightNonce && isDataOk
return isFromCurrentTx && isForSender && isRightNonce && isScrDataOk
}

func isDataOk(data []byte) bool {
Expand Down Expand Up @@ -363,7 +363,7 @@ func addToAlteredAddresses(
}

func groupSmartContractResults(txPool map[string]data.TransactionHandler) map[string]*smartContractResult.SmartContractResult {
scResults := make(map[string]*smartContractResult.SmartContractResult, 0)
scResults := make(map[string]*smartContractResult.SmartContractResult)
for hash, tx := range txPool {
scResult, ok := tx.(*smartContractResult.SmartContractResult)
if !ok {
Expand Down
1 change: 1 addition & 0 deletions core/libLocator/vmLocator_linux.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import (

const libName = "libhera.so"

// WASMLibLocation defines the wasm library location
func WASMLibLocation() string {
usr, err := user.Current()
if err != nil {
Expand Down
1 change: 1 addition & 0 deletions core/mock/alarmSchedulerStub.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import (
"time"
)

// AlarmSchedulerStub -
type AlarmSchedulerStub struct {
AddCalled func(func(alarmID string), time.Duration, string)
CancelCalled func(string)
Expand Down
1 change: 1 addition & 0 deletions core/mock/nodesCoordinatorMock.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package mock

import (
"bytes"

"github.com/ElrondNetwork/elrond-go/core"
"github.com/ElrondNetwork/elrond-go/data/state"
"github.com/ElrondNetwork/elrond-go/sharding"
Expand Down
2 changes: 1 addition & 1 deletion core/parsers/callArgsParser.go
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ func (parser *callArgsParser) parseFunction(tokens []string) (string, error) {
return "", ErrNilFunction
}

function := string(tokens[indexOfFunction])
function := tokens[indexOfFunction]
return function, nil
}

Expand Down
8 changes: 4 additions & 4 deletions core/statistics/tpsBenchmark.go
Original file line number Diff line number Diff line change
Expand Up @@ -250,15 +250,15 @@ func (s *TpsBenchmark) updateStatistics(header *block.MetaBlock) error {
return ErrInvalidShardId
}

totalTxsForTPS, totalTxsForCount := getNumTxsFromMiniblocksWithoutPeerTxsAndSCRs(shardInfo.ShardID, shardInfo.ShardMiniBlockHeaders)
shardTotalTxsForTPS, shardTotalTxsForCount := getNumTxsFromMiniblocksWithoutPeerTxsAndSCRs(shardInfo.ShardID, shardInfo.ShardMiniBlockHeaders)

shardPeakTPS := shardStat.PeakTPS()
currentShardTPS := float64(totalTxsForTPS / s.roundTime)
currentShardTPS := float64(shardTotalTxsForTPS / s.roundTime)
if currentShardTPS > shardStat.PeakTPS() {
shardPeakTPS = currentShardTPS
}

bigTxCount := big.NewInt(0).SetUint64(totalTxsForCount)
bigTxCount := big.NewInt(0).SetUint64(shardTotalTxsForCount)
newTotalProcessedTxCount := big.NewInt(0).Add(shardStat.TotalProcessedTxCount(), bigTxCount)
roundsPassed := big.NewInt(int64(header.Round))
newAverageTPS := big.NewInt(0).Quo(newTotalProcessedTxCount, roundsPassed)
Expand All @@ -271,7 +271,7 @@ func (s *TpsBenchmark) updateStatistics(header *block.MetaBlock) error {

averageTPS: newAverageTPS,
peakTPS: shardPeakTPS,
lastBlockTxCount: uint32(totalTxsForTPS),
lastBlockTxCount: uint32(shardTotalTxsForTPS),
}

log.Debug("TpsBenchmark.updateStatistics",
Expand Down
7 changes: 2 additions & 5 deletions core/stopWatch_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,12 @@ import (
"github.com/stretchr/testify/assert"
)

const identifier = "identifier"

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

sw := NewStopWatch()
identifier := "identifier"

sw.Start(identifier)

Expand Down Expand Up @@ -41,7 +42,6 @@ func TestStopWatch_StopNoStartShouldNotAddDuration(t *testing.T) {
t.Parallel()

sw := NewStopWatch()
identifier := "identifier"

sw.Stop(identifier)

Expand All @@ -54,7 +54,6 @@ func TestStopWatch_StopWithStartShouldAddDuration(t *testing.T) {
t.Parallel()

sw := NewStopWatch()
identifier := "identifier"

sw.Start(identifier)
sw.Stop(identifier)
Expand All @@ -68,7 +67,6 @@ func TestStopWatch_GetMeasurementsNotFinishedShouldOmit(t *testing.T) {
t.Parallel()

sw := NewStopWatch()
identifier := "identifier"

sw.Start(identifier)

Expand All @@ -82,7 +80,6 @@ func TestStopWatch_GetMeasurementsShouldWork(t *testing.T) {
t.Parallel()

sw := NewStopWatch()
identifier := "identifier"

sw.Start(identifier)
sw.Stop(identifier)
Expand Down
3 changes: 2 additions & 1 deletion crypto/mock/suite.go
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,7 @@ func (s *SuiteMock) CreatePoint() crypto.Point {
return nil
}

// CreatePointForScalar -
func (s *SuiteMock) CreatePointForScalar(scalar crypto.Scalar) (crypto.Point, error) {
if s.CreatePointForScalarStub != nil {
return s.CreatePointForScalarStub(scalar)
Expand Down Expand Up @@ -90,7 +91,7 @@ func (s *SuiteMock) CreateKeyPair() (crypto.Scalar, crypto.Point) {
return nil, nil
}

// IsPointValid -
// CheckPointValid -
func (s *SuiteMock) CheckPointValid(pointBytes []byte) error {
if s.IsPointValidStub != nil {
return s.IsPointValidStub(pointBytes)
Expand Down
2 changes: 1 addition & 1 deletion crypto/signing/mcl/suiteBLS12_381.go
Original file line number Diff line number Diff line change
Expand Up @@ -137,7 +137,7 @@ func (s *SuiteBLS12) GetUnderlyingSuite() interface{} {
return s
}

// IsPointValid returns error if the point is not valid (zero is also not valid), otherwise nil
// CheckPointValid returns error if the point is not valid (zero is also not valid), otherwise nil
func (s *SuiteBLS12) CheckPointValid(pointBytes []byte) error {
if len(pointBytes) != s.PointLen() {
return crypto.ErrInvalidParam
Expand Down

0 comments on commit a6ec73a

Please sign in to comment.