diff --git a/.github/workflows/main.yml b/.github/workflows/main.yml index f5a86cdef0..bc40f5ad7d 100644 --- a/.github/workflows/main.yml +++ b/.github/workflows/main.yml @@ -38,7 +38,6 @@ jobs: -E makezero -E lll -E importas - -E ifshort -E gosec -E gofmt -E goconst diff --git a/Makefile b/Makefile index fbcdd016e1..190aa3b9f6 100644 --- a/Makefile +++ b/Makefile @@ -25,7 +25,7 @@ build: .PHONY: lint lint: golangci-lint run -E whitespace -E wsl -E wastedassign -E unconvert -E tparallel -E thelper -E stylecheck -E prealloc \ - -E predeclared -E nlreturn -E misspell -E makezero -E lll -E importas -E ifshort -E gosec -E gofmt -E goconst \ + -E predeclared -E nlreturn -E misspell -E makezero -E lll -E importas -E gosec -E gofmt -E goconst \ -E forcetypeassert -E dogsled -E dupl -E errname -E errorlint -E nolintlint --timeout 2m .PHONY: generate-bsd-licenses diff --git a/blockchain/blockchain.go b/blockchain/blockchain.go index 30763bfac2..7bb70716a4 100644 --- a/blockchain/blockchain.go +++ b/blockchain/blockchain.go @@ -90,7 +90,6 @@ type Verifier interface { PreStateCommit(header *types.Header, txn *state.Transition) error } -// TODO: this should be part of Verifier (consensus) type Executor interface { ProcessBlock(parentRoot types.Hash, block *types.Block, blockCreator types.Address) (*state.Transition, error) } @@ -106,7 +105,7 @@ func (b *Blockchain) updateGasPriceAvg(newValues []*big.Int) { b.gpAverage.Lock() defer b.gpAverage.Unlock() - // Sum the values for quick reference + // Sum the values for quick reference sum := big.NewInt(0) for _, val := range newValues { sum = sum.Add(sum, val) @@ -897,7 +896,7 @@ func (b *Blockchain) WriteBlock(block *types.Block, source string) error { return err } - // update snapshot + // update snapshot if err := b.consensus.ProcessHeaders([]*types.Header{header}); err != nil { return err } diff --git a/blockchain/blockchain_test.go b/blockchain/blockchain_test.go index e4f6ae2cca..23c1b7dfb3 100644 --- a/blockchain/blockchain_test.go +++ b/blockchain/blockchain_test.go @@ -3,11 +3,12 @@ package blockchain import ( "errors" "fmt" - "github.com/0xPolygon/polygon-edge/state" "math/big" "reflect" "testing" + "github.com/0xPolygon/polygon-edge/state" + "github.com/0xPolygon/polygon-edge/chain" "github.com/stretchr/testify/assert" diff --git a/blockchain/subscription.go b/blockchain/subscription.go index 713c2e0a77..e5d9702759 100644 --- a/blockchain/subscription.go +++ b/blockchain/subscription.go @@ -43,8 +43,6 @@ func (m *MockSubscription) GetEvent() *Event { func (m *MockSubscription) Close() { } -///////////////////////// - // subscription is the Blockchain event subscription object type subscription struct { updateCh chan void // Channel for update information diff --git a/blockchain/testing.go b/blockchain/testing.go index 0676fcc777..49a1efefdd 100644 --- a/blockchain/testing.go +++ b/blockchain/testing.go @@ -3,10 +3,11 @@ package blockchain import ( "errors" "fmt" - "github.com/0xPolygon/polygon-edge/blockchain/storage" "math/big" "testing" + "github.com/0xPolygon/polygon-edge/blockchain/storage" + "github.com/0xPolygon/polygon-edge/chain" "github.com/0xPolygon/polygon-edge/state" itrie "github.com/0xPolygon/polygon-edge/state/immutable-trie" diff --git a/command/backup/params.go b/command/backup/params.go index a048a2d68e..3686817be8 100644 --- a/command/backup/params.go +++ b/command/backup/params.go @@ -2,6 +2,7 @@ package backup import ( "errors" + "github.com/0xPolygon/polygon-edge/archive" "github.com/0xPolygon/polygon-edge/command" "github.com/0xPolygon/polygon-edge/command/helper" diff --git a/command/backup/result.go b/command/backup/result.go index b19979bdf4..b887ef8ebc 100644 --- a/command/backup/result.go +++ b/command/backup/result.go @@ -3,6 +3,7 @@ package backup import ( "bytes" "fmt" + "github.com/0xPolygon/polygon-edge/command/helper" ) diff --git a/command/common.go b/command/common.go index 4dfea3c4c7..323d08ebd7 100644 --- a/command/common.go +++ b/command/common.go @@ -2,6 +2,7 @@ package command import ( "errors" + "github.com/0xPolygon/polygon-edge/helper/common" ) diff --git a/command/genesis/genesis.go b/command/genesis/genesis.go index 716acc19b4..3afc94d4a2 100644 --- a/command/genesis/genesis.go +++ b/command/genesis/genesis.go @@ -2,6 +2,7 @@ package genesis import ( "fmt" + "github.com/0xPolygon/polygon-edge/command" "github.com/0xPolygon/polygon-edge/command/helper" "github.com/0xPolygon/polygon-edge/consensus/ibft" diff --git a/command/genesis/utils.go b/command/genesis/utils.go index 71f4551e3b..0a5c4fa6ad 100644 --- a/command/genesis/utils.go +++ b/command/genesis/utils.go @@ -2,15 +2,16 @@ package genesis import ( "fmt" + "io/ioutil" + "os" + "path/filepath" + "strings" + "github.com/0xPolygon/polygon-edge/chain" "github.com/0xPolygon/polygon-edge/command" "github.com/0xPolygon/polygon-edge/consensus/ibft" "github.com/0xPolygon/polygon-edge/crypto" "github.com/0xPolygon/polygon-edge/types" - "io/ioutil" - "os" - "path/filepath" - "strings" ) const ( diff --git a/command/ibft/candidates/ibft_candidates.go b/command/ibft/candidates/ibft_candidates.go index 8a1350ad38..78bf50f9ed 100644 --- a/command/ibft/candidates/ibft_candidates.go +++ b/command/ibft/candidates/ibft_candidates.go @@ -2,6 +2,7 @@ package candidates import ( "context" + "github.com/0xPolygon/polygon-edge/command" "github.com/0xPolygon/polygon-edge/command/helper" ibftOp "github.com/0xPolygon/polygon-edge/consensus/ibft/proto" diff --git a/command/ibft/candidates/result.go b/command/ibft/candidates/result.go index 7d89ae472d..8defcc2952 100644 --- a/command/ibft/candidates/result.go +++ b/command/ibft/candidates/result.go @@ -3,6 +3,7 @@ package candidates import ( "bytes" "fmt" + "github.com/0xPolygon/polygon-edge/command/helper" ibftHelper "github.com/0xPolygon/polygon-edge/command/ibft/helper" ibftOp "github.com/0xPolygon/polygon-edge/consensus/ibft/proto" diff --git a/command/ibft/propose/params.go b/command/ibft/propose/params.go index f1e5e064f4..35fa8f4823 100644 --- a/command/ibft/propose/params.go +++ b/command/ibft/propose/params.go @@ -3,6 +3,7 @@ package propose import ( "context" "errors" + ibftOp "github.com/0xPolygon/polygon-edge/consensus/ibft/proto" "github.com/0xPolygon/polygon-edge/command" diff --git a/command/ibft/quorum/params.go b/command/ibft/quorum/params.go index 9ddc270b84..4ad469d710 100644 --- a/command/ibft/quorum/params.go +++ b/command/ibft/quorum/params.go @@ -3,11 +3,12 @@ package quorum import ( "errors" "fmt" + "os" + "github.com/0xPolygon/polygon-edge/chain" "github.com/0xPolygon/polygon-edge/command" "github.com/0xPolygon/polygon-edge/command/helper" "github.com/0xPolygon/polygon-edge/helper/common" - "os" ) const ( diff --git a/command/ibft/quorum/result.go b/command/ibft/quorum/result.go index 30ba750da4..848fb9a3de 100644 --- a/command/ibft/quorum/result.go +++ b/command/ibft/quorum/result.go @@ -3,6 +3,7 @@ package quorum import ( "bytes" "fmt" + "github.com/0xPolygon/polygon-edge/command/helper" "github.com/0xPolygon/polygon-edge/helper/common" ) diff --git a/command/ibft/snapshot/params.go b/command/ibft/snapshot/params.go index 3f4a54596e..3a5a6192ec 100644 --- a/command/ibft/snapshot/params.go +++ b/command/ibft/snapshot/params.go @@ -2,6 +2,7 @@ package snapshot import ( "context" + "github.com/0xPolygon/polygon-edge/command" "github.com/0xPolygon/polygon-edge/command/helper" ibftOp "github.com/0xPolygon/polygon-edge/consensus/ibft/proto" diff --git a/command/ibft/snapshot/result.go b/command/ibft/snapshot/result.go index 7ccefa0b47..e65c3896dc 100644 --- a/command/ibft/snapshot/result.go +++ b/command/ibft/snapshot/result.go @@ -3,6 +3,7 @@ package snapshot import ( "bytes" "fmt" + "github.com/0xPolygon/polygon-edge/command/helper" ibftHelper "github.com/0xPolygon/polygon-edge/command/ibft/helper" ibftOp "github.com/0xPolygon/polygon-edge/consensus/ibft/proto" diff --git a/command/ibft/status/ibft_status.go b/command/ibft/status/ibft_status.go index 5b50f9b2f0..ba55b81104 100644 --- a/command/ibft/status/ibft_status.go +++ b/command/ibft/status/ibft_status.go @@ -2,6 +2,7 @@ package status import ( "context" + "github.com/0xPolygon/polygon-edge/command" "github.com/0xPolygon/polygon-edge/command/helper" ibftOp "github.com/0xPolygon/polygon-edge/consensus/ibft/proto" diff --git a/command/ibft/status/result.go b/command/ibft/status/result.go index 661edd8a66..64f018b576 100644 --- a/command/ibft/status/result.go +++ b/command/ibft/status/result.go @@ -3,6 +3,7 @@ package status import ( "bytes" "fmt" + "github.com/0xPolygon/polygon-edge/command/helper" ) diff --git a/command/ibft/switch/params.go b/command/ibft/switch/params.go index 6ec5f57b90..b504b6d398 100644 --- a/command/ibft/switch/params.go +++ b/command/ibft/switch/params.go @@ -3,13 +3,14 @@ package ibftswitch import ( "errors" "fmt" + "os" + "github.com/0xPolygon/polygon-edge/chain" "github.com/0xPolygon/polygon-edge/command" "github.com/0xPolygon/polygon-edge/command/helper" "github.com/0xPolygon/polygon-edge/consensus/ibft" "github.com/0xPolygon/polygon-edge/helper/common" "github.com/0xPolygon/polygon-edge/types" - "os" ) const ( diff --git a/command/ibft/switch/result.go b/command/ibft/switch/result.go index 731416a299..e830822c29 100644 --- a/command/ibft/switch/result.go +++ b/command/ibft/switch/result.go @@ -3,6 +3,7 @@ package ibftswitch import ( "bytes" "fmt" + "github.com/0xPolygon/polygon-edge/command/helper" "github.com/0xPolygon/polygon-edge/consensus/ibft" "github.com/0xPolygon/polygon-edge/helper/common" diff --git a/command/license/result.go b/command/license/result.go index bc5f84baa5..76fe9423e5 100644 --- a/command/license/result.go +++ b/command/license/result.go @@ -3,6 +3,7 @@ package license import ( "bytes" "fmt" + "github.com/0xPolygon/polygon-edge/licenses" ) diff --git a/command/loadbot/duration.go b/command/loadbot/duration.go index 34169b789f..a1e062c61e 100644 --- a/command/loadbot/duration.go +++ b/command/loadbot/duration.go @@ -1,10 +1,11 @@ package loadbot import ( - "github.com/umbracle/ethgo" "sync" "sync/atomic" "time" + + "github.com/umbracle/ethgo" ) type ExecDuration struct { diff --git a/command/loadbot/execution.go b/command/loadbot/execution.go index 23907cd2c2..e19a683b5e 100644 --- a/command/loadbot/execution.go +++ b/command/loadbot/execution.go @@ -4,12 +4,13 @@ import ( "context" "crypto/ecdsa" "fmt" - "github.com/umbracle/ethgo" "math/big" "sync" "sync/atomic" "time" + "github.com/umbracle/ethgo" + "github.com/0xPolygon/polygon-edge/command/loadbot/generator" "github.com/0xPolygon/polygon-edge/helper/tests" txpoolOp "github.com/0xPolygon/polygon-edge/txpool/proto" diff --git a/command/loadbot/generator/contract_txn_generator.go b/command/loadbot/generator/contract_txn_generator.go index f608fa1f03..d5036d98fa 100644 --- a/command/loadbot/generator/contract_txn_generator.go +++ b/command/loadbot/generator/contract_txn_generator.go @@ -19,12 +19,12 @@ type ContractTxnsGenerator struct { failedContractTxnsLock sync.RWMutex } -// Returns contract deployment tx if contractAddress is empty, otherwise returns -// a token transfer tx +// Returns contract deployment tx if contractAddress is empty, otherwise returns +// a token transfer tx func (gen *ContractTxnsGenerator) GetExampleTransaction() (*types.Transaction, error) { if gen.contractAddress == nil { - // contract not deployed yet - // generate contract deployment tx + // contract not deployed yet + // generate contract deployment tx return gen.signer.SignTx(&types.Transaction{ From: gen.params.SenderAddress, Value: big.NewInt(0), @@ -34,7 +34,7 @@ func (gen *ContractTxnsGenerator) GetExampleTransaction() (*types.Transaction, e }, gen.params.SenderKey) } - // return token transfer tx + // return token transfer tx return gen.signer.SignTx(&types.Transaction{ From: gen.params.SenderAddress, To: gen.contractAddress, @@ -49,8 +49,8 @@ func (gen *ContractTxnsGenerator) GenerateTransaction() (*types.Transaction, err newNextNonce := atomic.AddUint64(&gen.params.Nonce, 1) if gen.contractAddress == nil { - // contract not deployed yet - // generate contract deployment tx + // contract not deployed yet + // generate contract deployment tx return gen.signer.SignTx(&types.Transaction{ From: gen.params.SenderAddress, Value: big.NewInt(0), @@ -62,7 +62,7 @@ func (gen *ContractTxnsGenerator) GenerateTransaction() (*types.Transaction, err }, gen.params.SenderKey) } - // return token transfer tx + // return token transfer tx return gen.signer.SignTx(&types.Transaction{ From: gen.params.SenderAddress, To: gen.contractAddress, diff --git a/command/loadbot/generator/generator.go b/command/loadbot/generator/generator.go index d1ae2d5dd3..232e0f348d 100644 --- a/command/loadbot/generator/generator.go +++ b/command/loadbot/generator/generator.go @@ -3,10 +3,11 @@ package generator import ( "crypto/ecdsa" "encoding/json" - "github.com/umbracle/ethgo" "io/ioutil" "math/big" + "github.com/umbracle/ethgo" + "github.com/0xPolygon/polygon-edge/types" "github.com/umbracle/ethgo/abi" ) diff --git a/command/loadbot/helper.go b/command/loadbot/helper.go index 44def2ab0b..f10430fc5f 100644 --- a/command/loadbot/helper.go +++ b/command/loadbot/helper.go @@ -2,11 +2,12 @@ package loadbot import ( "fmt" - "github.com/umbracle/ethgo" "math/big" "sync" "time" + "github.com/umbracle/ethgo" + "github.com/0xPolygon/polygon-edge/types" "github.com/umbracle/ethgo/jsonrpc" ) diff --git a/command/loadbot/result.go b/command/loadbot/result.go index ee18346bec..5a90b2d606 100644 --- a/command/loadbot/result.go +++ b/command/loadbot/result.go @@ -3,10 +3,11 @@ package loadbot import ( "bytes" "fmt" - "github.com/umbracle/ethgo" "math" "sort" + "github.com/umbracle/ethgo" + "github.com/0xPolygon/polygon-edge/command/helper" "github.com/0xPolygon/polygon-edge/command/loadbot/generator" "github.com/0xPolygon/polygon-edge/helper/common" @@ -139,7 +140,6 @@ func (lr *LoadbotResult) initDetailedErrors(gen generator.TransactionGenerator) } func (lr *LoadbotResult) writeBlockData(buffer *bytes.Buffer) { - //nolint: ifshort blockData := &lr.BlockData buffer.WriteString("\n\n[BLOCK DATA]\n") diff --git a/command/monitor/monitor.go b/command/monitor/monitor.go index b29f95005f..af36e033a5 100644 --- a/command/monitor/monitor.go +++ b/command/monitor/monitor.go @@ -4,10 +4,11 @@ import ( "context" "errors" "fmt" + "io" + "github.com/0xPolygon/polygon-edge/command" "github.com/0xPolygon/polygon-edge/helper/common" "github.com/spf13/cobra" - "io" "github.com/0xPolygon/polygon-edge/command/helper" "github.com/0xPolygon/polygon-edge/server/proto" diff --git a/command/monitor/result.go b/command/monitor/result.go index 1d9e5dcfd6..88d06d389a 100644 --- a/command/monitor/result.go +++ b/command/monitor/result.go @@ -3,6 +3,7 @@ package monitor import ( "bytes" "fmt" + "github.com/0xPolygon/polygon-edge/command/helper" "github.com/0xPolygon/polygon-edge/server/proto" ) diff --git a/command/peers/add/params.go b/command/peers/add/params.go index fb05bb51e6..5f410e584b 100644 --- a/command/peers/add/params.go +++ b/command/peers/add/params.go @@ -3,6 +3,7 @@ package add import ( "context" "errors" + "github.com/0xPolygon/polygon-edge/command" "github.com/0xPolygon/polygon-edge/command/helper" "github.com/0xPolygon/polygon-edge/server/proto" diff --git a/command/peers/add/result.go b/command/peers/add/result.go index 77a523e878..bf5e458cde 100644 --- a/command/peers/add/result.go +++ b/command/peers/add/result.go @@ -3,6 +3,7 @@ package add import ( "bytes" "fmt" + "github.com/0xPolygon/polygon-edge/command/helper" ) diff --git a/command/peers/list/peers_list.go b/command/peers/list/peers_list.go index 9b35244cf9..410fc7dabf 100644 --- a/command/peers/list/peers_list.go +++ b/command/peers/list/peers_list.go @@ -2,6 +2,7 @@ package list import ( "context" + "github.com/0xPolygon/polygon-edge/command" "github.com/0xPolygon/polygon-edge/command/helper" "github.com/0xPolygon/polygon-edge/server/proto" diff --git a/command/peers/list/result.go b/command/peers/list/result.go index a4bb85edd3..0c2b1103aa 100644 --- a/command/peers/list/result.go +++ b/command/peers/list/result.go @@ -3,6 +3,7 @@ package list import ( "bytes" "fmt" + "github.com/0xPolygon/polygon-edge/command/helper" "github.com/0xPolygon/polygon-edge/server/proto" ) diff --git a/command/peers/status/params.go b/command/peers/status/params.go index 98ffaeb9ad..3d299775fa 100644 --- a/command/peers/status/params.go +++ b/command/peers/status/params.go @@ -2,6 +2,7 @@ package status import ( "context" + "github.com/0xPolygon/polygon-edge/command" "github.com/0xPolygon/polygon-edge/command/helper" "github.com/0xPolygon/polygon-edge/server/proto" diff --git a/command/peers/status/result.go b/command/peers/status/result.go index 58be40daab..9622bf4fd2 100644 --- a/command/peers/status/result.go +++ b/command/peers/status/result.go @@ -3,6 +3,7 @@ package status import ( "bytes" "fmt" + "github.com/0xPolygon/polygon-edge/command/helper" ) diff --git a/command/root/root.go b/command/root/root.go index 0f5a2106d5..ea5962b22d 100644 --- a/command/root/root.go +++ b/command/root/root.go @@ -2,6 +2,8 @@ package root import ( "fmt" + "os" + "github.com/0xPolygon/polygon-edge/command/backup" "github.com/0xPolygon/polygon-edge/command/genesis" "github.com/0xPolygon/polygon-edge/command/helper" @@ -16,7 +18,6 @@ import ( "github.com/0xPolygon/polygon-edge/command/txpool" "github.com/0xPolygon/polygon-edge/command/version" "github.com/spf13/cobra" - "os" ) type RootCommand struct { diff --git a/command/secrets/generate/result.go b/command/secrets/generate/result.go index a09271adea..30dd6a7b20 100644 --- a/command/secrets/generate/result.go +++ b/command/secrets/generate/result.go @@ -3,6 +3,7 @@ package generate import ( "bytes" "fmt" + "github.com/0xPolygon/polygon-edge/command/helper" ) diff --git a/command/secrets/init/params.go b/command/secrets/init/params.go index 8fd00027fb..313068e15e 100644 --- a/command/secrets/init/params.go +++ b/command/secrets/init/params.go @@ -3,6 +3,7 @@ package init import ( "crypto/ecdsa" "errors" + "github.com/0xPolygon/polygon-edge/command" "github.com/0xPolygon/polygon-edge/crypto" "github.com/0xPolygon/polygon-edge/secrets" diff --git a/command/secrets/init/result.go b/command/secrets/init/result.go index bebd95239a..6a14cdb3e7 100644 --- a/command/secrets/init/result.go +++ b/command/secrets/init/result.go @@ -3,6 +3,7 @@ package init import ( "bytes" "fmt" + "github.com/0xPolygon/polygon-edge/command/helper" "github.com/0xPolygon/polygon-edge/types" ) diff --git a/command/server/config/config.go b/command/server/config/config.go index 8a80de2f21..9afd418caa 100644 --- a/command/server/config/config.go +++ b/command/server/config/config.go @@ -114,7 +114,7 @@ func DefaultConfig() *Config { // ReadConfigFile reads the config file from the specified path, builds a Config object // and returns it. // -//Supported file types: .json, .hcl, .yaml, .yml +// Supported file types: .json, .hcl, .yaml, .yml func ReadConfigFile(path string) (*Config, error) { data, err := ioutil.ReadFile(path) if err != nil { diff --git a/command/server/export/export.go b/command/server/export/export.go index d5c9d25b4c..57c99093c0 100644 --- a/command/server/export/export.go +++ b/command/server/export/export.go @@ -4,11 +4,12 @@ import ( "encoding/json" "errors" "fmt" + "os" + "github.com/0xPolygon/polygon-edge/command" "github.com/0xPolygon/polygon-edge/command/server/config" "github.com/spf13/cobra" "gopkg.in/yaml.v3" - "os" ) func GetCommand() *cobra.Command { diff --git a/command/status/result.go b/command/status/result.go index 3b3c58d3df..433227f5bc 100644 --- a/command/status/result.go +++ b/command/status/result.go @@ -3,6 +3,7 @@ package status import ( "bytes" "fmt" + "github.com/0xPolygon/polygon-edge/command/helper" ) diff --git a/command/status/status.go b/command/status/status.go index aa01d361e4..31058e2f6b 100644 --- a/command/status/status.go +++ b/command/status/status.go @@ -2,6 +2,7 @@ package status import ( "context" + "github.com/0xPolygon/polygon-edge/command" "github.com/golang/protobuf/ptypes/empty" "github.com/spf13/cobra" diff --git a/command/txpool/status/result.go b/command/txpool/status/result.go index caed0ca866..b7aa309bcc 100644 --- a/command/txpool/status/result.go +++ b/command/txpool/status/result.go @@ -3,6 +3,7 @@ package status import ( "bytes" "fmt" + "github.com/0xPolygon/polygon-edge/command/helper" ) diff --git a/command/txpool/status/txpool_status.go b/command/txpool/status/txpool_status.go index 37c6b7ade6..ac8e530122 100644 --- a/command/txpool/status/txpool_status.go +++ b/command/txpool/status/txpool_status.go @@ -2,6 +2,7 @@ package status import ( "context" + "github.com/0xPolygon/polygon-edge/command" "github.com/0xPolygon/polygon-edge/command/helper" "github.com/spf13/cobra" diff --git a/command/txpool/subscribe/result.go b/command/txpool/subscribe/result.go index b7dfda4eef..9305d3ec64 100644 --- a/command/txpool/subscribe/result.go +++ b/command/txpool/subscribe/result.go @@ -3,6 +3,7 @@ package subscribe import ( "bytes" "fmt" + "github.com/0xPolygon/polygon-edge/command/helper" txpoolProto "github.com/0xPolygon/polygon-edge/txpool/proto" ) diff --git a/command/txpool/subscribe/txpool_subscribe.go b/command/txpool/subscribe/txpool_subscribe.go index 8aae6b6269..8f33092d8d 100644 --- a/command/txpool/subscribe/txpool_subscribe.go +++ b/command/txpool/subscribe/txpool_subscribe.go @@ -4,12 +4,13 @@ import ( "context" "errors" "fmt" + "io" + "github.com/0xPolygon/polygon-edge/command" "github.com/0xPolygon/polygon-edge/command/helper" "github.com/0xPolygon/polygon-edge/helper/common" txpoolProto "github.com/0xPolygon/polygon-edge/txpool/proto" "github.com/spf13/cobra" - "io" ) func GetCommand() *cobra.Command { diff --git a/consensus/dev/dev.go b/consensus/dev/dev.go index fd521fe228..210eee981f 100644 --- a/consensus/dev/dev.go +++ b/consensus/dev/dev.go @@ -125,9 +125,9 @@ func (d *Dev) writeTransactions(gasLimit uint64, transition transitionInterface) } if err := transition.Write(tx); err != nil { - if _, ok := err.(*state.GasLimitReachedTransitionApplicationError); ok { // nolint:errorlint + if _, ok := err.(*state.GasLimitReachedTransitionApplicationError); ok { //nolint:errorlint break - } else if appErr, ok := err.(*state.TransitionApplicationError); ok && appErr.IsRecoverable { // nolint:errorlint + } else if appErr, ok := err.(*state.TransitionApplicationError); ok && appErr.IsRecoverable { //nolint:errorlint d.txpool.Demote(tx) } else { d.txpool.Drop(tx) diff --git a/consensus/ibft/consensus.go b/consensus/ibft/consensus.go index 419d5ba674..74bcd03461 100644 --- a/consensus/ibft/consensus.go +++ b/consensus/ibft/consensus.go @@ -2,8 +2,9 @@ package ibft import ( "context" - "github.com/0xPolygon/go-ibft/core" "sync" + + "github.com/0xPolygon/go-ibft/core" ) // IBFTConsensus is a convenience wrapper for the go-ibft package @@ -49,7 +50,7 @@ func (c *IBFTConsensus) runSequence(height uint64) <-chan struct{} { return done } -// stopSequence terminates the running IBFT sequence gracefully and waits for it to return +// stopSequence terminates the running IBFT sequence gracefully and waits for it to return func (c *IBFTConsensus) stopSequence() { c.cancelSequence() c.wg.Wait() diff --git a/consensus/ibft/consensus_backend.go b/consensus/ibft/consensus_backend.go index e617e4e2b3..46cd875643 100644 --- a/consensus/ibft/consensus_backend.go +++ b/consensus/ibft/consensus_backend.go @@ -247,11 +247,11 @@ func (i *backendIBFT) writeTransactions( return default: if stopExecution { - // wait for the timer to expire + // wait for the timer to expire continue } - // execute transactions one by one + // execute transactions one by one result, ok := i.writeTransaction( i.txpool.Peek(), transition, @@ -300,15 +300,15 @@ func (i *backendIBFT) writeTransaction( ) } - // continue processing + // continue processing return &txExeResult{tx, fail}, true } if err := transition.Write(tx); err != nil { - if _, ok := err.(*state.GasLimitReachedTransitionApplicationError); ok { // nolint:errorlint - // stop processing + if _, ok := err.(*state.GasLimitReachedTransitionApplicationError); ok { //nolint:errorlint + // stop processing return nil, false - } else if appErr, ok := err.(*state.TransitionApplicationError); ok && appErr.IsRecoverable { // nolint:errorlint + } else if appErr, ok := err.(*state.TransitionApplicationError); ok && appErr.IsRecoverable { //nolint:errorlint i.txpool.Demote(tx) return &txExeResult{tx, skip}, true diff --git a/consensus/ibft/ibft.go b/consensus/ibft/ibft.go index b03bfc4f54..16b081d596 100644 --- a/consensus/ibft/ibft.go +++ b/consensus/ibft/ibft.go @@ -5,9 +5,10 @@ import ( "encoding/json" "errors" "fmt" + "time" + "github.com/0xPolygon/polygon-edge/blockchain" "github.com/0xPolygon/polygon-edge/consensus" - "time" "github.com/0xPolygon/polygon-edge/consensus/ibft/proto" "github.com/0xPolygon/polygon-edge/crypto" @@ -83,7 +84,7 @@ type backendIBFT struct { // Factory implements the base consensus Factory method func Factory(params *consensus.Params) (consensus.Consensus, error) { - // defaults for user set fields in genesis + // defaults for user set fields in genesis var ( epochSize = uint64(DefaultEpochSize) quorumSizeBlockNum = uint64(0) @@ -100,7 +101,7 @@ func Factory(params *consensus.Params) (consensus.Consensus, error) { } if rawBlockNum, ok := params.Config.Config["quorumSizeBlockNum"]; ok { - // Block number specified for quorum size switch + // Block number specified for quorum size switch readBlockNum, ok := rawBlockNum.(float64) if !ok { return nil, errors.New("invalid type assertion") @@ -193,7 +194,7 @@ func (i *backendIBFT) Initialize() error { i, ) - // Ensure consensus takes into account user configured block production time + // Ensure consensus takes into account user configured block production time i.consensus.ExtendRoundTimeout(i.blockTime) // Set up the snapshots @@ -211,7 +212,7 @@ func (i *backendIBFT) Initialize() error { return nil } -// sync runs the syncer in the background to receive blocks from advanced peers +// sync runs the syncer in the background to receive blocks from advanced peers func (i *backendIBFT) startSyncing() { callInsertBlockHook := func(blockNumber uint64) { if err := i.runHook(InsertBlockHook, blockNumber, blockNumber); err != nil { @@ -238,7 +239,7 @@ func (i *backendIBFT) Start() error { return err } - // Start syncing blocks from other peers + // Start syncing blocks from other peers go i.startSyncing() // Start the actual consensus protocol @@ -289,7 +290,7 @@ func GetIBFTForks(ibftConfig map[string]interface{}) ([]IBFTFork, error) { return nil, errors.New("current IBFT type not found") } -// setupTransport read current mechanism in params and sets up consensus mechanism +// setupMechanism reads the current mechanism in params and sets up consensus mechanism func (i *backendIBFT) setupMechanism() error { ibftForks, err := GetIBFTForks(i.config.Config) if err != nil { @@ -356,9 +357,9 @@ func (i *backendIBFT) startConsensus() { syncerBlockCh = make(chan struct{}) ) - // Receive a notification every time syncer manages - // to insert a valid block. Used for cancelling active consensus - // rounds for a specific height + // Receive a notification every time syncer manages + // to insert a valid block. Used for cancelling active consensus + // rounds for a specific height go func() { for { if ev := <-newBlockSub.GetEventCh(); ev.Source == "syncer" { @@ -384,20 +385,20 @@ func (i *backendIBFT) startConsensus() { i.updateActiveValidatorSet(latest) if !i.isActiveValidator() { - // we are not participating in consensus for this height + // we are not participating in consensus for this height continue } select { case <-i.consensus.runSequence(pending): - // consensus inserted block + // consensus inserted block continue case <-syncerBlockCh: - // syncer inserted block -> stop running consensus + // syncer inserted block -> stop running consensus i.consensus.stopSequence() i.logger.Info("canceled sequence", "sequence", pending) case <-i.closeCh: - // IBFT consensus stopped + // IBFT consensus stopped i.consensus.stopSequence() return @@ -414,7 +415,7 @@ func (i *backendIBFT) updateActiveValidatorSet(latestHeight uint64) { i.activeValidatorSet = snap.Set - //Update the No.of validator metric + // Update the No.of validator metric i.metrics.Validators.Set(float64(len(snap.Set))) } @@ -439,14 +440,14 @@ func (i *backendIBFT) updateMetrics(block *types.Block) { parentTime := time.Unix(int64(prvHeader.Timestamp), 0) headerTime := time.Unix(int64(block.Header.Timestamp), 0) - //Update the block interval metric + // Update the block interval metric if block.Number() > 1 { i.metrics.BlockInterval.Set( headerTime.Sub(parentTime).Seconds(), ) } - //Update the Number of transactions in the block metric + // Update the Number of transactions in the block metric i.metrics.NumTxs.Set(float64(len(block.Body().Transactions))) } @@ -519,9 +520,9 @@ func (i *backendIBFT) VerifyHeader(header *types.Header) error { return nil } -// quorumSize returns a callback that when executed on a ValidatorSet computes -// number of votes required to reach quorum based on the size of the set. -// The blockNumber argument indicates which formula was used to calculate the result (see PRs #513, #549) +// quorumSize returns a callback that when executed on a ValidatorSet computes +// number of votes required to reach quorum based on the size of the set. +// The blockNumber argument indicates which formula was used to calculate the result (see PRs #513, #549) func (i *backendIBFT) quorumSize(blockNumber uint64) QuorumImplementation { if blockNumber < i.quorumSizeBlockNum { return LegacyQuorumSize diff --git a/consensus/ibft/operator_service_test.go b/consensus/ibft/operator_service_test.go index 6fb1099029..a88dabd687 100644 --- a/consensus/ibft/operator_service_test.go +++ b/consensus/ibft/operator_service_test.go @@ -2,9 +2,10 @@ package ibft import ( "context" - "github.com/0xPolygon/polygon-edge/consensus" "testing" + "github.com/0xPolygon/polygon-edge/consensus" + "github.com/0xPolygon/polygon-edge/blockchain" "github.com/0xPolygon/polygon-edge/consensus/ibft/proto" "github.com/0xPolygon/polygon-edge/types" diff --git a/consensus/ibft/pos.go b/consensus/ibft/pos.go index 6ab1e0ced9..83a857c164 100644 --- a/consensus/ibft/pos.go +++ b/consensus/ibft/pos.go @@ -3,6 +3,7 @@ package ibft import ( "errors" "fmt" + "github.com/0xPolygon/polygon-edge/contracts/staking" stakingHelper "github.com/0xPolygon/polygon-edge/helper/staking" "github.com/0xPolygon/polygon-edge/state" diff --git a/consensus/ibft/sign.go b/consensus/ibft/sign.go index 09ad5dd0ec..2a6a8e40e4 100644 --- a/consensus/ibft/sign.go +++ b/consensus/ibft/sign.go @@ -210,8 +210,8 @@ func verifyCommittedFields( } // Valid committed seals must be at least 2F+1 - // 2F is the required number of honest validators who provided the committed seals - // +1 is the proposer + // 2F is the required number of honest validators who provided the committed seals + // +1 is the proposer if validSeals := len(visited); validSeals < quorumSizeFn(snap.Set) { return fmt.Errorf("not enough seals to seal block") } diff --git a/consensus/ibft/snapshot.go b/consensus/ibft/snapshot.go index 5c31d4d523..6e7d6145fa 100644 --- a/consensus/ibft/snapshot.go +++ b/consensus/ibft/snapshot.go @@ -4,7 +4,6 @@ import ( "encoding/json" "errors" "fmt" - lru "github.com/hashicorp/golang-lru" "io/ioutil" "os" "path/filepath" @@ -12,6 +11,8 @@ import ( "sync" "sync/atomic" + lru "github.com/hashicorp/golang-lru" + "github.com/0xPolygon/polygon-edge/consensus/ibft/proto" "github.com/0xPolygon/polygon-edge/types" "github.com/hashicorp/go-hclog" @@ -213,7 +214,7 @@ func (i *backendIBFT) getSnapshotMetadata() *snapshotMetadata { // getSnapshot returns the snapshot at the specified block height func (i *backendIBFT) getSnapshot(num uint64) *Snapshot { - // get it from the snapshot first + // get it from the snapshot first raw, ok := i.store.cache.Get(num) if ok { snap, _ := raw.(*Snapshot) @@ -221,11 +222,11 @@ func (i *backendIBFT) getSnapshot(num uint64) *Snapshot { return snap } - // find it in the store + // find it in the store snap := i.store.find(num) if snap != nil { - // add it to cache for future reference if found + // add it to cache for future reference if found i.store.cache.Add(snap.Number, snap) } diff --git a/consensus/ibft/snapshot_test.go b/consensus/ibft/snapshot_test.go index 538a13de38..44a9932c36 100644 --- a/consensus/ibft/snapshot_test.go +++ b/consensus/ibft/snapshot_test.go @@ -2,12 +2,13 @@ package ibft import ( "crypto/ecdsa" - "github.com/0xPolygon/polygon-edge/consensus" "io/ioutil" "os" "strconv" "testing" + "github.com/0xPolygon/polygon-edge/consensus" + "github.com/0xPolygon/polygon-edge/blockchain" "github.com/0xPolygon/polygon-edge/chain" "github.com/0xPolygon/polygon-edge/crypto" diff --git a/consensus/ibft/state.go b/consensus/ibft/state.go index d73813d02e..bfd1a510c5 100644 --- a/consensus/ibft/state.go +++ b/consensus/ibft/state.go @@ -97,7 +97,7 @@ func (v *ValidatorSet) MaxFaultyNodes() int { type QuorumImplementation func(ValidatorSet) int -// LegacyQuorumSize returns the legacy quorum size for the given validator set +// LegacyQuorumSize returns the legacy quorum size for the given validator set func LegacyQuorumSize(set ValidatorSet) int { // According to the IBFT spec, the number of valid messages // needs to be 2F + 1 @@ -106,8 +106,8 @@ func LegacyQuorumSize(set ValidatorSet) int { // OptimalQuorumSize returns the optimal quorum size for the given validator set func OptimalQuorumSize(set ValidatorSet) int { - // if the number of validators is less than 4, - // then the entire set is required + // if the number of validators is less than 4, + // then the entire set is required if set.MaxFaultyNodes() == 0 { /* N: 1 -> Q: 1 diff --git a/consensus/ibft/state_test.go b/consensus/ibft/state_test.go index a6de5706f6..4b5c141c7f 100644 --- a/consensus/ibft/state_test.go +++ b/consensus/ibft/state_test.go @@ -28,8 +28,8 @@ func TestState_FaultyNodes(t *testing.T) { } } -// TestNumValid checks if the quorum size is calculated -// correctly based on number of validators (network size). +// TestNumValid checks if the quorum size is calculated +// correctly based on number of validators (network size). func TestNumValid(t *testing.T) { cases := []struct { Network, Quorum uint64 diff --git a/consensus/ibft/verifier.go b/consensus/ibft/verifier.go index b25f343baf..20b50cd388 100644 --- a/consensus/ibft/verifier.go +++ b/consensus/ibft/verifier.go @@ -4,11 +4,12 @@ import ( "bytes" "errors" "fmt" + protoIBFT "github.com/0xPolygon/go-ibft/messages/proto" "github.com/0xPolygon/polygon-edge/types" ) -// Verifier impl for go-ibft +// Verifier impl for go-ibft func (i *backendIBFT) IsValidBlock(proposal []byte) bool { var ( @@ -54,7 +55,7 @@ func (i *backendIBFT) IsValidBlock(proposal []byte) bool { } if err := i.runHook(VerifyBlockHook, newBlock.Number(), newBlock); err != nil { - // nolint:govet + //nolint:govet if errors.As(err, &errBlockVerificationFailed) { i.logger.Error("block verification fail, block at the end of epoch has transactions") } else { @@ -81,12 +82,12 @@ func (i *backendIBFT) IsValidSender(msg *protoIBFT.Message) bool { return false } - // verify the signature came from the sender + // verify the signature came from the sender if !bytes.Equal(msg.From, validatorAddress.Bytes()) { return false } - // verify the sender is in the active validator set + // verify the sender is in the active validator set return i.activeValidatorSet.Includes(validatorAddress) } @@ -117,7 +118,7 @@ func (i *backendIBFT) IsValidProposalHash(proposal, hash []byte) bool { } func (i *backendIBFT) IsValidCommittedSeal(proposalHash, seal []byte) bool { - // seal was generated based on the proposal hash + // seal was generated based on the proposal hash validator, err := ecrecoverImpl(seal, wrapCommitHash(proposalHash)) if err != nil { i.logger.Error("unable to recover seal", "err", err) @@ -134,7 +135,7 @@ func (i *backendIBFT) IsValidCommittedSeal(proposalHash, seal []byte) bool { return true } -// helpers +// helpers func extractProposer(header *types.Header) types.Address { if header.Number == 0 { diff --git a/consensus/metrics.go b/consensus/metrics.go index 63dc680fcb..5957f0758d 100644 --- a/consensus/metrics.go +++ b/consensus/metrics.go @@ -16,7 +16,7 @@ type Metrics struct { // No.of transactions in the block NumTxs metrics.Gauge - //Time between current block and the previous block in seconds + // Time between current block and the previous block in seconds BlockInterval metrics.Gauge } diff --git a/contracts/staking/query.go b/contracts/staking/query.go index b7265b896c..c14d819403 100644 --- a/contracts/staking/query.go +++ b/contracts/staking/query.go @@ -2,9 +2,10 @@ package staking import ( "errors" - "github.com/umbracle/ethgo" "math/big" + "github.com/umbracle/ethgo" + "github.com/0xPolygon/polygon-edge/contracts/abis" "github.com/0xPolygon/polygon-edge/state/runtime" "github.com/0xPolygon/polygon-edge/types" diff --git a/e2e/genesis_test.go b/e2e/genesis_test.go index 6fda5398f0..6f135af18e 100644 --- a/e2e/genesis_test.go +++ b/e2e/genesis_test.go @@ -2,10 +2,11 @@ package e2e import ( "context" - "github.com/0xPolygon/polygon-edge/command" "testing" "time" + "github.com/0xPolygon/polygon-edge/command" + "github.com/0xPolygon/polygon-edge/e2e/framework" "github.com/0xPolygon/polygon-edge/helper/tests" "github.com/stretchr/testify/assert" diff --git a/e2e/ibft_test.go b/e2e/ibft_test.go index e5834806e1..59a19993ec 100644 --- a/e2e/ibft_test.go +++ b/e2e/ibft_test.go @@ -16,10 +16,8 @@ import ( "github.com/stretchr/testify/assert" ) -/** - TestIbft_Transfer sends a transfer transaction (EOA -> EOA) - and verifies it was mined -**/ +// TestIbft_Transfer sends a transfer transaction (EOA -> EOA) +// and verifies it was mined func TestIbft_Transfer(t *testing.T) { testCases := []struct { name string @@ -77,7 +75,7 @@ func TestIbft_Transfer(t *testing.T) { ctxForTx, cancelTx := context.WithTimeout(context.Background(), txTimeout) defer cancelTx() - // send tx and wait for receipt + // send tx and wait for receipt receipt, err := ibftManager. GetServer(0). SendRawTx(ctxForTx, txn, senderKey) diff --git a/e2e/logs_test.go b/e2e/logs_test.go index 98e0ec857e..99162331c4 100644 --- a/e2e/logs_test.go +++ b/e2e/logs_test.go @@ -2,11 +2,12 @@ package e2e import ( "context" - "github.com/umbracle/ethgo" "math/big" "testing" "time" + "github.com/umbracle/ethgo" + "github.com/0xPolygon/polygon-edge/e2e/framework" "github.com/0xPolygon/polygon-edge/helper/hex" "github.com/0xPolygon/polygon-edge/helper/tests" @@ -134,15 +135,15 @@ func TestNewFilter_Block(t *testing.T) { func TestFilterValue(t *testing.T) { // Scenario : // - // 1. Deploy a smart contract which is able to emit an event when calling a method. - // The event will contain a data, the number 42. + // 1. Deploy a smart contract which is able to emit an event when calling a method. + // The event will contain a data, the number 42. // - // 1a. Create a filter which will only register a specific event ( - // MyEvent) emitted by the previously deployed contract. + // 1a. Create a filter which will only register a specific event ( + // MyEvent) emitted by the previously deployed contract. // - // 2. Call the smart contract method and wait for the block. + // 2. Call the smart contract method and wait for the block. // - // 3. Query the block's bloom filter to make sure the data has been properly inserted. + // 3. Query the block's bloom filter to make sure the data has been properly inserted. // key, addr := tests.GenerateKeyAndAddr(t) diff --git a/e2e/pos_test.go b/e2e/pos_test.go index 5a47236f01..b0fac56ea0 100644 --- a/e2e/pos_test.go +++ b/e2e/pos_test.go @@ -4,13 +4,14 @@ import ( "context" "crypto/ecdsa" "fmt" - ibftOp "github.com/0xPolygon/polygon-edge/consensus/ibft/proto" - "github.com/umbracle/ethgo" "math/big" "strconv" "testing" "time" + ibftOp "github.com/0xPolygon/polygon-edge/consensus/ibft/proto" + "github.com/umbracle/ethgo" + "github.com/0xPolygon/polygon-edge/contracts/staking" "github.com/0xPolygon/polygon-edge/crypto" "github.com/0xPolygon/polygon-edge/e2e/framework" diff --git a/e2e/transaction_test.go b/e2e/transaction_test.go index 2e61955cd4..c0d4b1b073 100644 --- a/e2e/transaction_test.go +++ b/e2e/transaction_test.go @@ -6,13 +6,14 @@ import ( "encoding/hex" "errors" "fmt" - "github.com/umbracle/ethgo" "math/big" "strconv" "sync" "testing" "time" + "github.com/umbracle/ethgo" + "github.com/0xPolygon/polygon-edge/contracts/abis" "github.com/0xPolygon/polygon-edge/crypto" "github.com/0xPolygon/polygon-edge/e2e/framework" diff --git a/e2e/txpool_test.go b/e2e/txpool_test.go index 3e1e62cbf4..5d151cc5bb 100644 --- a/e2e/txpool_test.go +++ b/e2e/txpool_test.go @@ -4,12 +4,13 @@ import ( "context" "crypto/ecdsa" "errors" - "github.com/0xPolygon/polygon-edge/txpool" - "github.com/umbracle/ethgo" "math/big" "testing" "time" + "github.com/0xPolygon/polygon-edge/txpool" + "github.com/umbracle/ethgo" + "github.com/0xPolygon/polygon-edge/crypto" "github.com/0xPolygon/polygon-edge/e2e/framework" "github.com/0xPolygon/polygon-edge/helper/tests" diff --git a/e2e/websocket_test.go b/e2e/websocket_test.go index bdc521939e..53c92fad29 100644 --- a/e2e/websocket_test.go +++ b/e2e/websocket_test.go @@ -3,13 +3,14 @@ package e2e import ( "context" "encoding/json" + "math/big" + "testing" + "github.com/0xPolygon/polygon-edge/e2e/framework" "github.com/0xPolygon/polygon-edge/jsonrpc" "github.com/0xPolygon/polygon-edge/types" "github.com/gorilla/websocket" "github.com/stretchr/testify/assert" - "math/big" - "testing" ) type testWSRequest struct { diff --git a/helper/hex/hex_test.go b/helper/hex/hex_test.go index 805ac78ef3..9010181ddc 100644 --- a/helper/hex/hex_test.go +++ b/helper/hex/hex_test.go @@ -2,8 +2,9 @@ package hex import ( "fmt" - "github.com/stretchr/testify/assert" "testing" + + "github.com/stretchr/testify/assert" ) // TestDecodeUint64 verifies that uint64 values diff --git a/helper/tests/testing.go b/helper/tests/testing.go index f526976422..3c5cad4281 100644 --- a/helper/tests/testing.go +++ b/helper/tests/testing.go @@ -5,15 +5,16 @@ import ( "crypto/ecdsa" "errors" "fmt" + "math/big" + "net" + "testing" + "time" + "github.com/golang/protobuf/ptypes/any" libp2pCrypto "github.com/libp2p/go-libp2p-core/crypto" "github.com/libp2p/go-libp2p-core/peer" "github.com/multiformats/go-multiaddr" "github.com/umbracle/ethgo" - "math/big" - "net" - "testing" - "time" "github.com/0xPolygon/polygon-edge/crypto" txpoolOp "github.com/0xPolygon/polygon-edge/txpool/proto" @@ -144,16 +145,16 @@ func WaitForNonce( resObj, err := RetryUntilTimeout(ctx, func() (interface{}, bool) { nonce, err := ethClient.GetNonce(addr, ethgo.Latest) if err != nil { - // error -> stop retrying + // error -> stop retrying return result{nonce, err}, false } if nonce >= expectedNonce { - // match -> return result + // match -> return result return result{nonce, nil}, false } - // continue retrying + // continue retrying return nil, true }) diff --git a/jsonrpc/codec_test.go b/jsonrpc/codec_test.go index ddcc2c0078..2b1c221929 100644 --- a/jsonrpc/codec_test.go +++ b/jsonrpc/codec_test.go @@ -1,9 +1,10 @@ package jsonrpc import ( + "testing" + "github.com/0xPolygon/polygon-edge/types" "github.com/stretchr/testify/assert" - "testing" ) func TestBlockNumberOrHash_UnmarshalJSON(t *testing.T) { diff --git a/jsonrpc/errors.go b/jsonrpc/errors.go index bb2458be93..486c0b2bc6 100644 --- a/jsonrpc/errors.go +++ b/jsonrpc/errors.go @@ -3,6 +3,7 @@ package jsonrpc import ( "errors" "fmt" + "github.com/0xPolygon/polygon-edge/state/runtime" "github.com/umbracle/ethgo/abi" ) diff --git a/jsonrpc/eth_blockchain_test.go b/jsonrpc/eth_blockchain_test.go index da55c182c2..4beb1fd27a 100644 --- a/jsonrpc/eth_blockchain_test.go +++ b/jsonrpc/eth_blockchain_test.go @@ -123,7 +123,7 @@ func TestEth_GetTransactionByHash(t *testing.T) { assert.NoError(t, err) assert.NotNil(t, res) - // nolint:forcetypeassert + //nolint:forcetypeassert foundTxn := res.(*transaction) assert.Equal(t, argUint64(testTxn.Nonce), foundTxn.Nonce) assert.Equal(t, argUint64(block.Number()), *foundTxn.BlockNumber) @@ -148,7 +148,7 @@ func TestEth_GetTransactionByHash(t *testing.T) { assert.NoError(t, err) assert.NotNil(t, res) - // nolint:forcetypeassert + //nolint:forcetypeassert foundTxn := res.(*transaction) assert.Equal(t, argUint64(testTxn.Nonce), foundTxn.Nonce) assert.Nil(t, foundTxn.BlockNumber) @@ -209,7 +209,7 @@ func TestEth_GetTransactionReceipt(t *testing.T) { assert.NoError(t, err) assert.NotNil(t, res) - // nolint:forcetypeassert + //nolint:forcetypeassert response := res.(*receipt) assert.Equal(t, txn.Hash, response.TxHash) assert.Equal(t, block.Hash(), response.BlockHash) @@ -229,7 +229,7 @@ func TestEth_Syncing(t *testing.T) { assert.NoError(t, err) assert.NotNil(t, res) - // nolint:forcetypeassert + //nolint:forcetypeassert response := res.(progression) assert.NotEqual(t, progress.ChainSyncBulk, response.Type) assert.Equal(t, fmt.Sprintf("0x%x", 1), response.StartingBlock) diff --git a/jsonrpc/eth_endpoint.go b/jsonrpc/eth_endpoint.go index 379a8e7b73..edc4c63628 100644 --- a/jsonrpc/eth_endpoint.go +++ b/jsonrpc/eth_endpoint.go @@ -3,6 +3,8 @@ package jsonrpc import ( "errors" "fmt" + "math/big" + "github.com/0xPolygon/polygon-edge/chain" "github.com/0xPolygon/polygon-edge/helper/common" "github.com/0xPolygon/polygon-edge/helper/hex" @@ -12,7 +14,6 @@ import ( "github.com/0xPolygon/polygon-edge/types" "github.com/hashicorp/go-hclog" "github.com/umbracle/fastrlp" - "math/big" ) type ethTxPoolStore interface { @@ -83,7 +84,7 @@ var ( ) // ChainId returns the chain id of the client -//nolint:stylecheck +//nolint:stylecheck, gofmt func (e *Eth) ChainId() (interface{}, error) { return argUintPtr(e.chainID), nil } @@ -403,7 +404,7 @@ func (e *Eth) GetStorageAt( // Get the storage for the passed in location result, err := e.store.GetStorage(header.StateRoot, address, index) if err != nil { - // nolint:govet + //nolint:govet if errors.As(err, &ErrStateNotFound) { return argBytesPtr(types.ZeroHash[:]), nil } @@ -536,7 +537,7 @@ func (e *Eth) EstimateGas(arg *txnArgs, rawNum *BlockNumber) (interface{}, error accountBalance := big.NewInt(0) acc, err := e.store.GetAccount(header.StateRoot, transaction.From) - // nolint:govet + //nolint:govet if err != nil && !errors.As(err, &ErrStateNotFound) { // An unrelated error occurred, return it return nil, err @@ -580,7 +581,7 @@ func (e *Eth) EstimateGas(arg *txnArgs, rawNum *BlockNumber) (interface{}, error // Checks if executor level valid gas errors occurred isGasApplyError := func(err error) bool { // Not linting this as the underlying error is actually wrapped - // nolint:govet + //nolint:govet return errors.As(err, &state.ErrNotEnoughIntrinsicGas) } @@ -707,7 +708,7 @@ func (e *Eth) GetBalance(address types.Address, filter BlockNumberOrHash) (inter // Extract the account balance acc, err := e.store.GetAccount(header.StateRoot, address) - // nolint:govet + //nolint:govet if errors.As(err, &ErrStateNotFound) { // Account not found, return an empty account return argUintPtr(0), nil @@ -774,7 +775,7 @@ func (e *Eth) GetCode(address types.Address, filter BlockNumberOrHash) (interfac emptySlice := []byte{} acc, err := e.store.GetAccount(header.StateRoot, address) - // nolint:govet + //nolint:govet if errors.As(err, &ErrStateNotFound) { // If the account doesn't exist / is not initialized yet, // return the default value @@ -863,7 +864,7 @@ func (e *Eth) getNextNonce(address types.Address, number BlockNumber) (uint64, e acc, err := e.store.GetAccount(header.StateRoot, address) - // nolint:govet + //nolint:govet if errors.As(err, &ErrStateNotFound) { // If the account doesn't exist / isn't initialized, // return a nonce value of 0 diff --git a/jsonrpc/filter_manager.go b/jsonrpc/filter_manager.go index 275e29b980..f26a1db2c5 100644 --- a/jsonrpc/filter_manager.go +++ b/jsonrpc/filter_manager.go @@ -461,7 +461,7 @@ func (f *FilterManager) getLogsFromBlocks(query *LogQuery) ([]*Log, error) { // GetLogsForQuery return array of logs for given query func (f *FilterManager) GetLogsForQuery(query *LogQuery) ([]*Log, error) { if query.BlockHash != nil { - // BlockHash is set -> fetch logs from this block only + // BlockHash is set -> fetch logs from this block only block, ok := f.store.GetBlockByHash(*query.BlockHash, true) if !ok { return nil, ErrBlockNotFound @@ -475,7 +475,7 @@ func (f *FilterManager) GetLogsForQuery(query *LogQuery) ([]*Log, error) { return f.getLogsFromBlock(query, block) } - // gets logs from a range of blocks + // gets logs from a range of blocks return f.getLogsFromBlocks(query) } @@ -487,7 +487,7 @@ func (f *FilterManager) getFilterByID(filterID string) filter { return f.filters[filterID] } -//GetLogFilterFromID return log filter for given filterID +// GetLogFilterFromID return log filter for given filterID func (f *FilterManager) GetLogFilterFromID(filterID string) (*logFilter, error) { filterRaw := f.getFilterByID(filterID) diff --git a/jsonrpc/jsonrpc_test.go b/jsonrpc/jsonrpc_test.go index 9828560281..a793c37f83 100644 --- a/jsonrpc/jsonrpc_test.go +++ b/jsonrpc/jsonrpc_test.go @@ -1,10 +1,11 @@ package jsonrpc import ( - "github.com/0xPolygon/polygon-edge/helper/tests" "net" "testing" + "github.com/0xPolygon/polygon-edge/helper/tests" + "github.com/hashicorp/go-hclog" ) diff --git a/jsonrpc/mocks_test.go b/jsonrpc/mocks_test.go index 0c5ef06a51..704b197449 100644 --- a/jsonrpc/mocks_test.go +++ b/jsonrpc/mocks_test.go @@ -2,11 +2,12 @@ package jsonrpc import ( "errors" + "math/big" + "sync" + "github.com/0xPolygon/polygon-edge/blockchain" "github.com/0xPolygon/polygon-edge/state" "github.com/0xPolygon/polygon-edge/types" - "math/big" - "sync" ) type mockAccount struct { diff --git a/jsonrpc/txpool_endpoint_test.go b/jsonrpc/txpool_endpoint_test.go index e45b383f5f..6db457d07f 100644 --- a/jsonrpc/txpool_endpoint_test.go +++ b/jsonrpc/txpool_endpoint_test.go @@ -1,11 +1,12 @@ package jsonrpc import ( - "github.com/0xPolygon/polygon-edge/types" "math/big" "strconv" "testing" + "github.com/0xPolygon/polygon-edge/types" + "github.com/stretchr/testify/assert" ) @@ -19,7 +20,7 @@ func TestContentEndpoint(t *testing.T) { txPoolEndpoint := &TxPool{mockStore} result, _ := txPoolEndpoint.Content() - // nolint:forcetypeassert + //nolint:forcetypeassert response := result.(ContentResponse) assert.True(t, mockStore.includeQueued) @@ -27,7 +28,7 @@ func TestContentEndpoint(t *testing.T) { assert.Equal(t, 0, len(response.Queued)) }) - // nolint:dupl + //nolint:dupl t.Run("returns correct data for pending transaction", func(t *testing.T) { t.Parallel() @@ -38,7 +39,7 @@ func TestContentEndpoint(t *testing.T) { txPoolEndpoint := &TxPool{mockStore} result, _ := txPoolEndpoint.Content() - // nolint:forcetypeassert + //nolint:forcetypeassert response := result.(ContentResponse) assert.Equal(t, 1, len(response.Pending)) @@ -57,7 +58,7 @@ func TestContentEndpoint(t *testing.T) { assert.Equal(t, nil, txData.TxIndex) }) - // nolint:dupl + //nolint:dupl t.Run("returns correct data for queued transaction", func(t *testing.T) { t.Parallel() @@ -68,7 +69,7 @@ func TestContentEndpoint(t *testing.T) { txPoolEndpoint := &TxPool{mockStore} result, _ := txPoolEndpoint.Content() - // nolint:forcetypeassert + //nolint:forcetypeassert response := result.(ContentResponse) assert.Equal(t, 0, len(response.Pending)) @@ -105,7 +106,7 @@ func TestContentEndpoint(t *testing.T) { txPoolEndpoint := &TxPool{mockStore} result, _ := txPoolEndpoint.Content() - // nolint:forcetypeassert + //nolint:forcetypeassert response := result.(ContentResponse) assert.True(t, mockStore.includeQueued) @@ -127,7 +128,7 @@ func TestInspectEndpoint(t *testing.T) { txPoolEndpoint := &TxPool{mockStore} result, _ := txPoolEndpoint.Inspect() - // nolint:forcetypeassert + //nolint:forcetypeassert response := result.(InspectResponse) assert.True(t, mockStore.includeQueued) @@ -148,7 +149,7 @@ func TestInspectEndpoint(t *testing.T) { txPoolEndpoint := &TxPool{mockStore} result, _ := txPoolEndpoint.Inspect() - // nolint:forcetypeassert + //nolint:forcetypeassert response := result.(InspectResponse) assert.Equal(t, 0, len(response.Pending)) @@ -171,7 +172,7 @@ func TestInspectEndpoint(t *testing.T) { txPoolEndpoint := &TxPool{mockStore} result, _ := txPoolEndpoint.Inspect() - // nolint:forcetypeassert + //nolint:forcetypeassert response := result.(InspectResponse) assert.Equal(t, 1, len(response.Pending)) @@ -194,7 +195,7 @@ func TestStatusEndpoint(t *testing.T) { txPoolEndpoint := &TxPool{mockStore} result, _ := txPoolEndpoint.Status() - // nolint:forcetypeassert + //nolint:forcetypeassert response := result.(StatusResponse) assert.Equal(t, uint64(0), response.Pending) @@ -219,7 +220,7 @@ func TestStatusEndpoint(t *testing.T) { txPoolEndpoint := &TxPool{mockStore} result, _ := txPoolEndpoint.Status() - // nolint:forcetypeassert + //nolint:forcetypeassert response := result.(StatusResponse) assert.Equal(t, uint64(3), response.Pending) @@ -242,7 +243,7 @@ func newMockTxPoolStore() *mockTxPoolStore { } } -// nolint:lll +//nolint:lll func (s *mockTxPoolStore) GetTxs(inclQueued bool) (map[types.Address][]*types.Transaction, map[types.Address][]*types.Transaction) { s.includeQueued = inclQueued diff --git a/main.go b/main.go index e918bbf12b..1c9793d60e 100644 --- a/main.go +++ b/main.go @@ -2,6 +2,7 @@ package main import ( _ "embed" + "github.com/0xPolygon/polygon-edge/command/root" "github.com/0xPolygon/polygon-edge/licenses" ) diff --git a/network/bootnodes.go b/network/bootnodes.go index f73176371f..f67a937671 100644 --- a/network/bootnodes.go +++ b/network/bootnodes.go @@ -1,8 +1,9 @@ package network import ( - "github.com/libp2p/go-libp2p-core/peer" "sync/atomic" + + "github.com/libp2p/go-libp2p-core/peer" ) type bootnodesWrapper struct { diff --git a/network/common/common.go b/network/common/common.go index 6c88993747..e2f2e9bd69 100644 --- a/network/common/common.go +++ b/network/common/common.go @@ -3,10 +3,11 @@ package common import ( "errors" "fmt" - "github.com/libp2p/go-libp2p-core/peer" - "github.com/multiformats/go-multiaddr" "regexp" "strings" + + "github.com/libp2p/go-libp2p-core/peer" + "github.com/multiformats/go-multiaddr" ) type DialPriority uint64 diff --git a/network/config.go b/network/config.go index 4d2a88f187..f5c751f96e 100644 --- a/network/config.go +++ b/network/config.go @@ -1,10 +1,11 @@ package network import ( + "net" + "github.com/0xPolygon/polygon-edge/chain" "github.com/0xPolygon/polygon-edge/secrets" "github.com/multiformats/go-multiaddr" - "net" ) // Config details the params for the base networking server diff --git a/network/connections.go b/network/connections.go index bce75dc6de..d4a951c397 100644 --- a/network/connections.go +++ b/network/connections.go @@ -1,8 +1,9 @@ package network import ( - "github.com/libp2p/go-libp2p-core/network" "sync/atomic" + + "github.com/libp2p/go-libp2p-core/network" ) // ConnectionInfo keeps track of current connection information diff --git a/network/dial/dial_queue.go b/network/dial/dial_queue.go index bf0d3d51c3..1dca699cb2 100644 --- a/network/dial/dial_queue.go +++ b/network/dial/dial_queue.go @@ -2,9 +2,10 @@ package dial import ( "container/heap" - "github.com/0xPolygon/polygon-edge/network/common" "sync" + "github.com/0xPolygon/polygon-edge/network/common" + "github.com/libp2p/go-libp2p-core/peer" ) diff --git a/network/discovery/discovery.go b/network/discovery/discovery.go index 45464ff329..4a06aed6b1 100644 --- a/network/discovery/discovery.go +++ b/network/discovery/discovery.go @@ -4,11 +4,12 @@ import ( "context" "errors" "fmt" + "time" + "github.com/0xPolygon/polygon-edge/network/common" "github.com/0xPolygon/polygon-edge/network/event" "github.com/hashicorp/go-hclog" "github.com/libp2p/go-libp2p-core/network" - "time" "github.com/0xPolygon/polygon-edge/network/grpc" "github.com/0xPolygon/polygon-edge/network/proto" diff --git a/network/discovery/discovery_test.go b/network/discovery/discovery_test.go index e8cee93d81..1e03a701a0 100644 --- a/network/discovery/discovery_test.go +++ b/network/discovery/discovery_test.go @@ -3,6 +3,9 @@ package discovery import ( "context" "errors" + "testing" + "time" + "github.com/0xPolygon/polygon-edge/helper/tests" "github.com/0xPolygon/polygon-edge/network/common" "github.com/0xPolygon/polygon-edge/network/proto" @@ -12,8 +15,6 @@ import ( kb "github.com/libp2p/go-libp2p-kbucket" "github.com/stretchr/testify/assert" "google.golang.org/grpc" - "testing" - "time" ) // newDiscoveryService creates a new discovery service instance diff --git a/network/grpc/grpc.go b/network/grpc/grpc.go index f20f27f63d..0146796351 100644 --- a/network/grpc/grpc.go +++ b/network/grpc/grpc.go @@ -3,10 +3,11 @@ package grpc import ( "context" "errors" - "google.golang.org/grpc/credentials/insecure" "io" "net" + "google.golang.org/grpc/credentials/insecure" + manet "github.com/multiformats/go-multiaddr/net" "github.com/libp2p/go-libp2p-core/network" diff --git a/network/identity/identity.go b/network/identity/identity.go index 81cc7bf4b4..126020df0a 100644 --- a/network/identity/identity.go +++ b/network/identity/identity.go @@ -4,9 +4,10 @@ import ( "context" "errors" "fmt" + "sync" + "github.com/0xPolygon/polygon-edge/network/event" "github.com/hashicorp/go-hclog" - "sync" "github.com/0xPolygon/polygon-edge/network/proto" "github.com/libp2p/go-libp2p-core/network" diff --git a/network/identity/identity_test.go b/network/identity/identity_test.go index 2904465179..fc80b6f651 100644 --- a/network/identity/identity_test.go +++ b/network/identity/identity_test.go @@ -2,6 +2,8 @@ package identity import ( "context" + "testing" + "github.com/0xPolygon/polygon-edge/network/proto" networkTesting "github.com/0xPolygon/polygon-edge/network/testing" "github.com/hashicorp/go-hclog" @@ -9,7 +11,6 @@ import ( "github.com/libp2p/go-libp2p-core/peer" "github.com/stretchr/testify/assert" "google.golang.org/grpc" - "testing" ) // newIdentityService creates a new identity service instance diff --git a/network/identity_e2e_test.go b/network/identity_e2e_test.go index 564e4090ef..46e34e5a02 100644 --- a/network/identity_e2e_test.go +++ b/network/identity_e2e_test.go @@ -2,10 +2,11 @@ package network import ( "context" - "github.com/0xPolygon/polygon-edge/chain" - "github.com/stretchr/testify/assert" "testing" "time" + + "github.com/0xPolygon/polygon-edge/chain" + "github.com/stretchr/testify/assert" ) func TestIdentityHandshake(t *testing.T) { diff --git a/network/server.go b/network/server.go index 424354495b..a1f7681aa8 100644 --- a/network/server.go +++ b/network/server.go @@ -329,7 +329,7 @@ func (s *Server) checkPeerConnections() { if s.numPeers() < MinimumPeerConnections { if s.config.NoDiscover || !s.bootnodes.hasBootnodes() { - //TODO: dial peers from the peerstore + // TODO: dial peers from the peerstore } else { randomNode := s.GetRandomBootnode() s.addToDialQueue(randomNode, common.PriorityRandomDial) diff --git a/network/server_test.go b/network/server_test.go index e94d6f0ce6..f464090207 100644 --- a/network/server_test.go +++ b/network/server_test.go @@ -3,13 +3,14 @@ package network import ( "context" "fmt" - "github.com/0xPolygon/polygon-edge/network/common" - peerEvent "github.com/0xPolygon/polygon-edge/network/event" "net" "strconv" "testing" "time" + "github.com/0xPolygon/polygon-edge/network/common" + peerEvent "github.com/0xPolygon/polygon-edge/network/event" + "github.com/0xPolygon/polygon-edge/helper/tests" "github.com/libp2p/go-libp2p-core/crypto" diff --git a/network/testing/testing.go b/network/testing/testing.go index 9fd7fc5c5f..15329f4333 100644 --- a/network/testing/testing.go +++ b/network/testing/testing.go @@ -2,12 +2,13 @@ package testing import ( "context" + "time" + "github.com/0xPolygon/polygon-edge/network/event" "github.com/0xPolygon/polygon-edge/network/proto" "github.com/libp2p/go-libp2p-core/network" "github.com/libp2p/go-libp2p-core/peer" "google.golang.org/grpc" - "time" ) type MockNetworkingServer struct { diff --git a/secrets/awsssm/aws_ssm.go b/secrets/awsssm/aws_ssm.go index 08c948c9b7..51d444f03b 100644 --- a/secrets/awsssm/aws_ssm.go +++ b/secrets/awsssm/aws_ssm.go @@ -42,7 +42,7 @@ func SecretsManagerFactory( return nil, errors.New("required extra map containing 'region' and 'ssm-parameter-path' not found for aws-ssm") } - /// Set up the base object + // / Set up the base object awsSsmManager := &AwsSsmManager{ logger: params.Logger.Named(string(secrets.AWSSSM)), region: fmt.Sprintf("%v", config.Extra["region"]), diff --git a/secrets/gcpssm/gcp_ssm.go b/secrets/gcpssm/gcp_ssm.go index 51d11ccac7..9d114adff1 100644 --- a/secrets/gcpssm/gcp_ssm.go +++ b/secrets/gcpssm/gcp_ssm.go @@ -3,9 +3,10 @@ package gcpssm import ( "context" "fmt" + "os" + "github.com/0xPolygon/polygon-edge/secrets" "github.com/hashicorp/go-hclog" - "os" sm "cloud.google.com/go/secretmanager/apiv1" smpb "google.golang.org/genproto/googleapis/cloud/secretmanager/v1" diff --git a/secrets/hashicorpvault/hashicorp_vault.go b/secrets/hashicorpvault/hashicorp_vault.go index b2ded27339..1d55aba152 100644 --- a/secrets/hashicorpvault/hashicorp_vault.go +++ b/secrets/hashicorpvault/hashicorp_vault.go @@ -122,8 +122,8 @@ func (v *VaultSecretsManager) GetSecret(name string) ([]byte, error) { // KV-2 (versioned key-value storage) in Vault stores data in the following format: // { // "data": { - // key: value - // } + // key: value + // } // } data, ok := secret.Data["data"] if !ok { diff --git a/state/executor.go b/state/executor.go index 00caa51837..744fc7dbdb 100644 --- a/state/executor.go +++ b/state/executor.go @@ -332,7 +332,7 @@ func (t *Transition) GetTxnHash() types.Hash { // Apply applies a new transaction func (t *Transition) Apply(msg *types.Transaction) (*runtime.ExecutionResult, error) { - s := t.state.Snapshot() //nolint:ifshort + s := t.state.Snapshot() result, err := t.apply(msg) if err != nil { @@ -559,7 +559,6 @@ func (t *Transition) applyCall( } } - //nolint:ifshort snapshot := t.state.Snapshot() t.state.TouchAccount(c.Address) diff --git a/state/immutable-trie/encoding_test.go b/state/immutable-trie/encoding_test.go index a7ba9bf540..e33c242926 100644 --- a/state/immutable-trie/encoding_test.go +++ b/state/immutable-trie/encoding_test.go @@ -1,8 +1,9 @@ package itrie import ( - "github.com/stretchr/testify/assert" "testing" + + "github.com/stretchr/testify/assert" ) func TestEncoding_HasTermSymbol(t *testing.T) { @@ -121,7 +122,7 @@ func TestEncoding_KeyBytesToHexNibbles(t *testing.T) { func TestEncoding_HexCompact(t *testing.T) { // As per the official spec: - // nolint:lll + //nolint:lll // https://eth.wiki/en/fundamentals/patricia-tree#specification-compact-encoding-of-hex-sequence-with-optional-terminator // hex char bits | node type partial path length // ---------------------------------------------------------- diff --git a/state/immutable-trie/storage.go b/state/immutable-trie/storage.go index 8807741e10..1172d4719d 100644 --- a/state/immutable-trie/storage.go +++ b/state/immutable-trie/storage.go @@ -188,8 +188,7 @@ func decodeNode(v *fastrlp.Value, s Storage) (Node, error) { var err error - // TODO remove this once 1.0.4 of ifshort is merged in golangci-lint - ll := v.Elems() //nolint:ifshort + ll := v.Elems() if ll == 2 { key := v.Get(0) if key.Type() != fastrlp.TypeBytes { diff --git a/state/runtime/evm/evm.go b/state/runtime/evm/evm.go index 4a3131662c..937c4aab1e 100644 --- a/state/runtime/evm/evm.go +++ b/state/runtime/evm/evm.go @@ -2,6 +2,7 @@ package evm import ( "errors" + "github.com/0xPolygon/polygon-edge/chain" "github.com/0xPolygon/polygon-edge/state/runtime" ) diff --git a/state/runtime/evm/instructions.go b/state/runtime/evm/instructions.go index 8d2a6cf18f..cba7e5f578 100644 --- a/state/runtime/evm/instructions.go +++ b/state/runtime/evm/instructions.go @@ -1,4 +1,4 @@ -//nolint:ifshort, forcetypeassert +//nolint:forcetypeassert package evm import ( diff --git a/state/runtime/precompiled/base.go b/state/runtime/precompiled/base.go index c3a232c3ee..0cf93d77a2 100644 --- a/state/runtime/precompiled/base.go +++ b/state/runtime/precompiled/base.go @@ -2,9 +2,10 @@ package precompiled import ( "crypto/sha256" - "golang.org/x/crypto/ripemd160" //nolint:staticcheck "math/big" + "golang.org/x/crypto/ripemd160" //nolint:staticcheck + "github.com/0xPolygon/polygon-edge/chain" "github.com/0xPolygon/polygon-edge/crypto" "github.com/0xPolygon/polygon-edge/helper/keccak" diff --git a/state/runtime/precompiled/base_test.go b/state/runtime/precompiled/base_test.go index 616ccd7a15..1901c53569 100644 --- a/state/runtime/precompiled/base_test.go +++ b/state/runtime/precompiled/base_test.go @@ -1,4 +1,4 @@ -//nolint: lll +//nolint: lll,gofmt package precompiled import ( diff --git a/syncer/client.go b/syncer/client.go index d63a944f9c..4f51ca2456 100644 --- a/syncer/client.go +++ b/syncer/client.go @@ -29,9 +29,9 @@ type syncPeerClient struct { network Network // reference to the network module blockchain Blockchain // reference to the blockchain module - subscription blockchain.Subscription //reference to the blockchain subscription - topic *network.Topic //reference to the network topic - id string //node id + subscription blockchain.Subscription // reference to the blockchain subscription + topic *network.Topic // reference to the network topic + id string // node id peerStatusUpdateCh chan *NoForkPeer // peer status update channel peerConnectionUpdateCh chan *event.PeerEvent // peer connection update channel diff --git a/syncer/client_test.go b/syncer/client_test.go index 4eea8917a7..268918d9c6 100644 --- a/syncer/client_test.go +++ b/syncer/client_test.go @@ -371,7 +371,7 @@ func TestPeerConnectionUpdateEventCh(t *testing.T) { // Make sure the peer shouldn't emit status if the shouldEmitBlocks flag is set. // The subtests cannot contain t.Parallel() due to how // the test is organized -// nolint:tparallel +//nolint:tparallel, gofmt func Test_shouldEmitBlocks(t *testing.T) { t.Parallel() diff --git a/syncer/syncer.go b/syncer/syncer.go index 33d963fad3..d5df3b4554 100644 --- a/syncer/syncer.go +++ b/syncer/syncer.go @@ -164,7 +164,7 @@ func (s *syncer) Sync(callback func(*types.Block) bool) error { skipList := make(map[peer.ID]bool) for { - //Wait for a new event to arrive + // Wait for a new event to arrive <-s.newStatusCh // fetch local latest block diff --git a/txpool/account.go b/txpool/account.go index 237bf68536..cb1af5e5ab 100644 --- a/txpool/account.go +++ b/txpool/account.go @@ -17,7 +17,7 @@ type accountsMap struct { // Intializes an account for the given address. func (m *accountsMap) initOnce(addr types.Address, nonce uint64) *account { a, _ := m.LoadOrStore(addr, &account{}) - newAccount := a.(*account) // nolint:forcetypeassert + newAccount := a.(*account) //nolint:forcetypeassert // run only once newAccount.init.Do(func() { // create queues @@ -139,8 +139,8 @@ func (m *accountsMap) allTxs(includeEnqueued bool) ( // transactions from a specific address. The nextNonce // field is what separates the enqueued from promoted transactions: // -// 1. enqueued - transactions higher than the nextNonce -// 2. promoted - transactions lower than the nextNonce +// 1. enqueued - transactions higher than the nextNonce +// 2. promoted - transactions lower than the nextNonce // // If an enqueued transaction matches the nextNonce, // a promoteRequest is signaled for this account @@ -163,10 +163,10 @@ func (a *account) setNonce(nonce uint64) { atomic.StoreUint64(&a.nextNonce, nonce) } -// reset aligns the account with the new nonce -// by pruning all transactions with nonce lesser than new. -// After pruning, a promotion may be signaled if the first -// enqueued transaction matches the new nonce. +// reset aligns the account with the new nonce +// by pruning all transactions with nonce lesser than new. +// After pruning, a promotion may be signaled if the first +// enqueued transaction matches the new nonce. func (a *account) reset(nonce uint64, promoteCh chan<- promoteRequest) ( prunedPromoted, prunedEnqueued []*types.Transaction, @@ -174,7 +174,7 @@ func (a *account) reset(nonce uint64, promoteCh chan<- promoteRequest) ( a.promoted.lock(true) defer a.promoted.unlock() - // prune the promoted txs + // prune the promoted txs prunedPromoted = append( prunedPromoted, a.promoted.prune(nonce)..., @@ -188,18 +188,18 @@ func (a *account) reset(nonce uint64, promoteCh chan<- promoteRequest) ( a.enqueued.lock(true) defer a.enqueued.unlock() - // prune the enqueued txs + // prune the enqueued txs prunedEnqueued = append( prunedEnqueued, a.enqueued.prune(nonce)..., ) - // update nonce expected for this account + // update nonce expected for this account a.setNonce(nonce) - // it is important to signal promotion while - // the locks are held to ensure no other - // handler will mutate the account + // it is important to signal promotion while + // the locks are held to ensure no other + // handler will mutate the account if first := a.enqueued.peek(); first != nil && first.Nonce == nonce { // first enqueued tx is expected -> signal promotion @@ -239,7 +239,7 @@ func (a *account) promote() []*types.Transaction { a.promoted.unlock() }() - // sanity check + // sanity check currentNonce := a.getNonce() if a.enqueued.length() == 0 || a.enqueued.peek().Nonce > currentNonce { @@ -250,8 +250,8 @@ func (a *account) promote() []*types.Transaction { promoted := make([]*types.Transaction, 0) nextNonce := a.enqueued.peek().Nonce - // move all promotable txs (enqueued txs that are sequential in nonce) - // to the account's promoted queue + // move all promotable txs (enqueued txs that are sequential in nonce) + // to the account's promoted queue for { tx := a.enqueued.peek() if tx == nil || diff --git a/txpool/event_manager.go b/txpool/event_manager.go index c921b3855e..c2e4dad907 100644 --- a/txpool/event_manager.go +++ b/txpool/event_manager.go @@ -2,12 +2,13 @@ package txpool import ( "fmt" + "sync" + "sync/atomic" + "github.com/0xPolygon/polygon-edge/txpool/proto" "github.com/0xPolygon/polygon-edge/types" "github.com/google/uuid" "github.com/hashicorp/go-hclog" - "sync" - "sync/atomic" ) type eventManager struct { diff --git a/txpool/event_manager_test.go b/txpool/event_manager_test.go index 9caf149289..0f3331483a 100644 --- a/txpool/event_manager_test.go +++ b/txpool/event_manager_test.go @@ -1,13 +1,14 @@ package txpool import ( + "sync" + "testing" + "time" + "github.com/0xPolygon/polygon-edge/txpool/proto" "github.com/0xPolygon/polygon-edge/types" "github.com/hashicorp/go-hclog" "github.com/stretchr/testify/assert" - "sync" - "testing" - "time" ) func TestEventManager_SubscribeCancel(t *testing.T) { diff --git a/txpool/event_queue.go b/txpool/event_queue.go index 62726e7794..a647b26f23 100644 --- a/txpool/event_queue.go +++ b/txpool/event_queue.go @@ -1,8 +1,9 @@ package txpool import ( - "github.com/0xPolygon/polygon-edge/txpool/proto" "sync" + + "github.com/0xPolygon/polygon-edge/txpool/proto" ) type eventQueue struct { diff --git a/txpool/event_subscription_test.go b/txpool/event_subscription_test.go index 3633f44079..3bc839ee4f 100644 --- a/txpool/event_subscription_test.go +++ b/txpool/event_subscription_test.go @@ -3,16 +3,17 @@ package txpool import ( "context" "crypto/rand" - "github.com/0xPolygon/polygon-edge/helper/tests" - "github.com/0xPolygon/polygon-edge/txpool/proto" - "github.com/0xPolygon/polygon-edge/types" - "github.com/stretchr/testify/assert" "math/big" mathRand "math/rand" "sync" "sync/atomic" "testing" "time" + + "github.com/0xPolygon/polygon-edge/helper/tests" + "github.com/0xPolygon/polygon-edge/txpool/proto" + "github.com/0xPolygon/polygon-edge/types" + "github.com/stretchr/testify/assert" ) func shuffleTxPoolEvents( diff --git a/txpool/txpool.go b/txpool/txpool.go index 457d641d22..5d2e28cbe1 100644 --- a/txpool/txpool.go +++ b/txpool/txpool.go @@ -20,11 +20,11 @@ import ( const ( txSlotSize = 32 * 1024 // 32kB - txMaxSize = 128 * 1024 //128Kb + txMaxSize = 128 * 1024 // 128Kb topicNameV1 = "txpool/0.1" - // maximum allowed number of times an account - // was excluded from block building (ibft.writeTransactions) + // maximum allowed number of times an account + // was excluded from block building (ibft.writeTransactions) maxAccountDemotions = uint(10) ) @@ -99,13 +99,13 @@ type enqueueRequest struct { // is eligible for promotion. This request is signaled // on 2 occasions: // -// 1. When an enqueued transaction's nonce is -// not greater than the expected (account's nextNonce). -// == nextNonce - transaction is expected (addTx) -// < nextNonce - transaction was demoted (Demote) +// 1. When an enqueued transaction's nonce is +// not greater than the expected (account's nextNonce). +// == nextNonce - transaction is expected (addTx) +// < nextNonce - transaction was demoted (Demote) // -// 2. When an account's nextNonce is updated (during ResetWithHeader) -// and the first enqueued transaction matches the new nonce. +// 2. When an account's nextNonce is updated (during ResetWithHeader) +// and the first enqueued transaction matches the new nonce. type promoteRequest struct { account types.Address } @@ -113,9 +113,9 @@ type promoteRequest struct { // TxPool is a module that handles pending transactions. // All transactions are handled within their respective accounts. // An account contains 2 queues a transaction needs to go through: -// - 1. Enqueued (entry point) -// - 2. Promoted (exit point) -// (both queues are min nonce ordered) +// - 1. Enqueued (entry point) +// - 2. Promoted (exit point) +// (both queues are min nonce ordered) // // When consensus needs to process promoted transactions, // the pool generates a queue of "executable" transactions. These @@ -322,7 +322,7 @@ func (p *TxPool) Pop(tx *types.Transaction) { // pop the top most promoted tx account.promoted.pop() - // successfully popping an account resets its demotions count to 0 + // successfully popping an account resets its demotions count to 0 account.demotions = 0 // update state @@ -386,9 +386,9 @@ func (p *TxPool) Drop(tx *types.Transaction) { ) } -// Demote excludes an account from being further processed during block building -// due to a recoverable error. If an account has been demoted too many times (maxAccountDemotions), -// it is Dropped instead. +// Demote excludes an account from being further processed during block building +// due to a recoverable error. If an account has been demoted too many times (maxAccountDemotions), +// it is Dropped instead. func (p *TxPool) Demote(tx *types.Transaction) { account := p.accounts.get(tx.From) if account.demotions == maxAccountDemotions { @@ -399,7 +399,7 @@ func (p *TxPool) Demote(tx *types.Transaction) { p.Drop(tx) - // reset the demotions counter + // reset the demotions counter account.demotions = 0 return @@ -602,7 +602,7 @@ func (p *TxPool) addTx(origin txOrigin, tx *types.Transaction) error { tx.ComputeHash() - // add to index + // add to index if ok := p.index.add(tx); !ok { return ErrAlreadyKnown } @@ -719,7 +719,7 @@ func (p *TxPool) resetAccounts(stateNonces map[types.Address]uint64) { allPrunedEnqueued []*types.Transaction ) - // clear all accounts of stale txs + // clear all accounts of stale txs for addr, newNonce := range stateNonces { if !p.accounts.exists(addr) { // no updates for this account @@ -729,21 +729,21 @@ func (p *TxPool) resetAccounts(stateNonces map[types.Address]uint64) { account := p.accounts.get(addr) prunedPromoted, prunedEnqueued := account.reset(newNonce, p.promoteReqCh) - // append pruned + // append pruned allPrunedPromoted = append(allPrunedPromoted, prunedPromoted...) allPrunedEnqueued = append(allPrunedEnqueued, prunedEnqueued...) - // new state for account -> demotions are reset to 0 + // new state for account -> demotions are reset to 0 account.demotions = 0 } - // pool cleanup callback + // pool cleanup callback cleanup := func(stale ...*types.Transaction) { p.index.remove(stale...) p.gauge.decrease(slotsRequired(stale...)) } - // prune pool state + // prune pool state if len(allPrunedPromoted) > 0 { cleanup(allPrunedPromoted...) p.eventManager.signalEvent( @@ -781,7 +781,7 @@ func (p *TxPool) Length() uint64 { return p.accounts.promoted() } -// toHash returns the hash(es) of given transaction(s) +// toHash returns the hash(es) of given transaction(s) func toHash(txs ...*types.Transaction) (hashes []types.Hash) { for _, tx := range txs { hashes = append(hashes, tx.Hash) diff --git a/txpool/txpool_test.go b/txpool/txpool_test.go index c6dd8af61a..3661f4b89b 100644 --- a/txpool/txpool_test.go +++ b/txpool/txpool_test.go @@ -1085,12 +1085,12 @@ func TestDemote(t *testing.T) { t.Run("Demote increments counter", func(t *testing.T) { t.Parallel() - // create pool + // create pool pool, err := newTestPool() assert.NoError(t, err) pool.SetSigner(&mockSigner{}) - // send tx + // send tx go func() { err := pool.addTx(local, newTx(addr1, 0, 1)) assert.NoError(t, err) @@ -1103,7 +1103,7 @@ func TestDemote(t *testing.T) { assert.Equal(t, uint64(1), pool.accounts.get(addr1).promoted.length()) assert.Equal(t, uint(0), pool.accounts.get(addr1).demotions) - // call demote + // call demote pool.Prepare() tx := pool.Peek() pool.Demote(tx) @@ -1112,19 +1112,19 @@ func TestDemote(t *testing.T) { assert.Equal(t, uint64(1), pool.accounts.get(addr1).getNonce()) assert.Equal(t, uint64(1), pool.accounts.get(addr1).promoted.length()) - // assert counter was incremented + // assert counter was incremented assert.Equal(t, uint(1), pool.accounts.get(addr1).demotions) }) t.Run("Demote calls Drop", func(t *testing.T) { t.Parallel() - // create pool + // create pool pool, err := newTestPool() assert.NoError(t, err) pool.SetSigner(&mockSigner{}) - // send tx + // send tx go func() { err := pool.addTx(local, newTx(addr1, 0, 1)) assert.NoError(t, err) @@ -1136,20 +1136,20 @@ func TestDemote(t *testing.T) { assert.Equal(t, uint64(1), pool.accounts.get(addr1).getNonce()) assert.Equal(t, uint64(1), pool.accounts.get(addr1).promoted.length()) - // set counter to max allowed demotions + // set counter to max allowed demotions pool.accounts.get(addr1).demotions = maxAccountDemotions - // call demote + // call demote pool.Prepare() tx := pool.Peek() pool.Demote(tx) - // account was dropped + // account was dropped assert.Equal(t, uint64(0), pool.gauge.read()) assert.Equal(t, uint64(0), pool.accounts.get(addr1).getNonce()) assert.Equal(t, uint64(0), pool.accounts.get(addr1).promoted.length()) - // demotions are reset to 0 + // demotions are reset to 0 assert.Equal(t, uint(0), pool.accounts.get(addr1).demotions) }) } @@ -1306,7 +1306,7 @@ func TestResetAccounts_Promoted(t *testing.T) { }, addr4: { - // all txs will be pruned + // all txs will be pruned eoa4.signTx(newTx(addr4, 0, 1), signerEIP155), // will be pruned eoa4.signTx(newTx(addr4, 1, 1), signerEIP155), // will be pruned eoa4.signTx(newTx(addr4, 2, 1), signerEIP155), // will be pruned diff --git a/types/header_test.go b/types/header_test.go index d88f99bcf1..78b540d9bd 100644 --- a/types/header_test.go +++ b/types/header_test.go @@ -2,9 +2,10 @@ package types import ( "encoding/json" - "github.com/stretchr/testify/assert" "regexp" "testing" + + "github.com/stretchr/testify/assert" ) // TestHeader_JSON makes sure the Header is properly @@ -13,7 +14,7 @@ func TestHeader_JSON(t *testing.T) { t.Parallel() var ( - // nolint:lll + //nolint:lll headerJSON = `{ "parentHash": "0x0100000000000000000000000000000000000000000000000000000000000000", "sha3Uncles" : "0x0200000000000000000000000000000000000000000000000000000000000000",