Skip to content

Commit

Permalink
fix golangci.yml and some warnings (#70)
Browse files Browse the repository at this point in the history
update go version to 1.21 and use go mod tidy;
fix golangci.yml and some warnings related to property changes;
add other paths for exclusion rules and make the line length 120 and add the output configuration;
fix and add the lint, ci, build, and test workflows;
fetch-depth is used to not doing a shallow checkout which avoids diff error for the linked revision;
remove the sonar token to avoid the usage of the sonar's analyses;
remove the race and shuffle flags from the make test command;
optimize the TestThrottling test;
set a separate statusCh variable to store the peer client and remove the t.Skip() from the TestStatusPubSub test;
optimize the codebase based on the golintci issues;
change DefaultChainID to 8844;
change error string to start with small letter in order to follow the golang conventions;
actions/setup-go must be done after actions/setup-checkout for cache optimizations.
updated the version of the actions;
add submodules: recursive in the checkout action;

* chore: fix linting (#72)

* chore: fix linting
* fix: invalid nolint directives
* fix: actions/upload-artifact

---------

Co-authored-by: Ludovic Fernandez <[email protected]>
  • Loading branch information
Vitomir2 and ldez committed Nov 15, 2024
1 parent cc62de4 commit 9c01a41
Show file tree
Hide file tree
Showing 52 changed files with 358 additions and 236 deletions.
44 changes: 24 additions & 20 deletions .github/paused-workflows/build.yml → .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -11,37 +11,39 @@ on: # yamllint disable-line rule:truthy

jobs:
go_build:
name: Polygon Edge
name: HydraGon
runs-on: ubuntu-latest
outputs:
build_output_failure: ${{ steps.edge_build_failure.outputs.build_output }}
build_output_failure: ${{ steps.hydra_build_failure.outputs.build_output }}
steps:
- name: Checkout code
uses: actions/checkout@v3
uses: actions/checkout@v4
with:
ref: ${{ github.head_ref }}

- name: Setup Go environment
uses: actions/setup-go@v3
uses: actions/setup-go@v5
with:
go-version: 1.20.x
go-version: 1.21.x

- name: Build Polygon Edge
run: go build -tags netgo -ldflags="-s -w -linkmode external -extldflags "-static" -X \"github.com/0xPolygon/polygon-edge/versioning.Version=${GITHUB_REF_NAME}\" -X \"github.com/0xPolygon/polygon-edge/versioning.Commit=${GITHUB_SHA}\"" && tar -czvf polygon-edge.tar.gz polygon-edge
- name: Build HydraGon
run: go build -tags netgo -o hydra -a -installsuffix cgo -ldflags="-s -w -linkmode external -extldflags \"-static\" -X \"github.com/Hydra-Chain/hydragon-node/versioning.Version=${GITHUB_REF_NAME}\" -X \"github.com/Hydra-Chain/hydragon-node/versioning.Commit=${GITHUB_SHA}\"" main.go && tar -czvf hydra.tar.gz hydra
env:
CC: gcc
CXX: g++
GOARC: amd64
GOOS: linux

- name: Build Polygon Edge Failed
- name: Build HydraGon Failed
if: failure()
id: edge_build_failure
id: hydra_build_failure
run: echo "build_output=false" >> $GITHUB_OUTPUT

- name: 'Upload Artifact'
uses: actions/upload-artifact@v3
uses: actions/upload-artifact@v4
with:
name: polygon-edge
path: polygon-edge.tar.gz
name: hydra
path: hydra.tar.gz
retention-days: 3

go_build_reproducibility:
Expand All @@ -50,21 +52,23 @@ jobs:
continue-on-error: true
steps:
- name: Checkout code
uses: actions/checkout@v3
uses: actions/checkout@v4
with:
ref: ${{ github.head_ref }}

- name: Setup Go environment
uses: actions/setup-go@v3
uses: actions/setup-go@v5
with:
go-version: 1.20.x
go-version: 1.21.x

- name: 'Reproduce builds'
continue-on-error: true
run: |
go build -o ./edge-1 -trimpath -buildvcs=false
go build -o ./edge-2 -trimpath -buildvcs=false
go build -o ./hydra-1 -trimpath -buildvcs=false
go build -o ./hydra-2 -trimpath -buildvcs=false
buildsha1=$(shasum -a256 ./edge-1 | awk '{print $1}')
buildsha2=$(shasum -a256 ./edge-2 | awk '{print $1}')
buildsha1=$(shasum -a256 ./hydra-1 | awk '{print $1}')
buildsha2=$(shasum -a256 ./hydra-2 | awk '{print $1}')
echo "Build 1 SHA: $buildsha1"
echo "Build 2 SHA: $buildsha2"
Expand All @@ -74,4 +78,4 @@ jobs:
exit 1
else
echo "Build artifact matches original"
fi
fi
2 changes: 0 additions & 2 deletions .github/paused-workflows/ci.yml → .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -13,5 +13,3 @@ jobs:
name: Test
uses: ./.github/workflows/test.yml
needs: build
secrets:
SONAR_TOKEN: ${{ secrets.SONAR_TOKEN }}
18 changes: 12 additions & 6 deletions .github/workflows/lint.yml
Original file line number Diff line number Diff line change
Expand Up @@ -21,15 +21,21 @@ jobs:
golangci_lint:
runs-on: ubuntu-latest
steps:
- name: Install Go
uses: actions/setup-go@v3
- name: Checkout code
uses: actions/checkout@v4
with:
go-version: 1.20.x
ref: ${{ github.head_ref }}
fetch-depth: 0
submodules: recursive

- name: Checkout code
uses: actions/checkout@v3

- name: Install Go
uses: actions/setup-go@v5
with:
go-version: 1.21.x

- name: Lint
uses: golangci/golangci-lint-action@v3
uses: golangci/golangci-lint-action@v6
with:
args: --timeout 10m --verbose
version: v1.61
16 changes: 8 additions & 8 deletions .github/paused-workflows/test.yml → .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -13,22 +13,22 @@ on: # yamllint disable-line rule:truthy

jobs:
go_test:
name: Polygon Edge
name: HydraGon
runs-on: ubuntu-latest
outputs:
test_output_failure: ${{ steps.run_tests_failure.outputs.test_output }}
steps:
- name: Setup Go
uses: actions/setup-go@v3
with:
go-version: 1.20.x

- name: Checkout Code
uses: actions/checkout@v3
uses: actions/checkout@v4
with:
submodules: recursive
fetch-depth: 0 # Shallow clones should be disabled for a better relevancy of analysis

- name: Setup Go
uses: actions/setup-go@v5
with:
go-version: 1.21.x

- name: Install Dependencies
run: ./setup-ci.sh

Expand All @@ -46,4 +46,4 @@ jobs:
env:
HAVE_SONAR_TOKEN: ${{ secrets.SONAR_TOKEN != '' }}
GITHUB_TOKEN: ${{secrets.GITHUB_TOKEN }}
SONAR_TOKEN: ${{ secrets.SONAR_TOKEN }}
SONAR_TOKEN: ${{ secrets.SONAR_TOKEN }}
58 changes: 49 additions & 9 deletions .golangci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,14 +3,6 @@
run:
timeout: 3m
tests: true
# default is true. Enables skipping of directories:
# vendor$, third_party$, testdata$, examples$, Godeps$, builtin$
skip-dirs-use-default: true
skip-dirs:
- tests

service:
golangci-lint-version: 1.49.0

linters:
disable-all: true
Expand Down Expand Up @@ -55,23 +47,71 @@ linters-settings:
settings:
ruleguard:
rules: "./gorules/rules.go"
lll:
line-length: 120

issues:
new-from-rev: origin/develop # report only new issues with reference to develop branch
# report only new issues with reference to the selected revision
new-from-rev: d27793e73eb22c4464711b187b8c98f14f7b8b17
whole-files: true
exclude-dirs:
- archive
- blockchain
- command/bridge
- command/ibft
- command/rootchain
- consensus/dev
- consensus/ibft
- crypto
- gasprice
- helper/keccak
- helper/predeployment
- helper/staking
- jsonrpc
- state/immutable-trie
- state/runtime
- syncer
- tests
- tracker
- txpool
- types
exclude-rules:
- path: testing\.go
linters:
- gosec
- unparam
- lll
- path: _test\.go
linters:
- gosec
- gocritic
- unparam
- wsl
- lll
- predeclared
- wastedassign
- nolintlint
- forcetypeassert
- path: gen_sc_data\.go
linters:
- wsl
- lll
- stylecheck
- path: system_service\.go
linters:
- gosec
- path: proposer_calculator\.go
linters:
- predeclared
include:
- EXC0012 # Exported (.+) should have comment( \(or a comment on this block\))? or be unexported
- EXC0013 # Package comment should be of the form "(.+)...
- EXC0014 # Comment on exported (.+) should be of the form "(.+)..."
- EXC0015 # Should have a package comment

output:
sort-results: true
show-stats: true
sort-order:
- linter
- file
2 changes: 1 addition & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ generate-bsd-licenses: check-git

.PHONY: test
test: check-go
go test -race -shuffle=on -coverprofile coverage.out -timeout 20m `go list ./... | grep -v e2e`
go test -coverprofile coverage.out -timeout 20m `go list ./... | grep -v e2e`

.PHONY: fuzz-test
fuzz-test: check-go
Expand Down
2 changes: 1 addition & 1 deletion command/default.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ import (
const (
DefaultGenesisFileName = "genesis.json"
DefaultChainName = "hydra-chain"
DefaultChainID = 187
DefaultChainID = 8844
DefaultConsensus = server.PolyBFTConsensus
DefaultGenesisGasUsed = 458752 // 0x70000
DefaultGenesisGasLimit = 5242880 // 0x500000
Expand Down
4 changes: 2 additions & 2 deletions command/genesis/params.go
Original file line number Diff line number Diff line change
Expand Up @@ -321,7 +321,7 @@ func (p *genesisParams) initValidatorSet() error {
}

func (p *genesisParams) isValidatorNumberValid() bool {
return p.ibftValidators == nil || uint64(p.ibftValidators.Len()) <= p.maxNumValidators
return p.ibftValidators == nil || uint64(p.ibftValidators.Len()) <= p.maxNumValidators //nolint:gosec
}

func (p *genesisParams) initIBFTExtraData() {
Expand Down Expand Up @@ -410,7 +410,7 @@ func (p *genesisParams) initGenesisConfig() error {
GasUsed: command.DefaultGenesisGasUsed,
},
Params: &chain.Params{
ChainID: int64(p.chainID),
ChainID: int64(p.chainID), //nolint:gosec
Forks: enabledForks,
Engine: p.consensusEngineConfig,
},
Expand Down
7 changes: 2 additions & 5 deletions command/genesis/polybft_params.go
Original file line number Diff line number Diff line change
Expand Up @@ -148,7 +148,7 @@ func (p *genesisParams) generatePolyBftChainConfig(o command.OutputFormatter) er
chainConfig := &chain.Chain{
Name: p.name,
Params: &chain.Params{
ChainID: int64(p.chainID),
ChainID: int64(p.chainID), //nolint:gosec
Forks: enabledForks,
Engine: map[string]interface{}{
string(server.PolyBFTConsensus): polyBftConfig,
Expand All @@ -157,8 +157,6 @@ func (p *genesisParams) generatePolyBftChainConfig(o command.OutputFormatter) er
Bootnodes: p.bootnodes,
}

burnContractAddr := types.ZeroAddress

if p.isBurnContractEnabled() {
chainConfig.Params.BurnContract = make(map[uint64]types.Address, 1)

Expand All @@ -169,8 +167,7 @@ func (p *genesisParams) generatePolyBftChainConfig(o command.OutputFormatter) er

if !p.nativeTokenConfig.IsMintable {
// burn contract can be specified on arbitrary address for non-mintable native tokens
burnContractAddr = burnContractInfo.Address
chainConfig.Params.BurnContract[burnContractInfo.BlockNumber] = burnContractAddr
chainConfig.Params.BurnContract[burnContractInfo.BlockNumber] = burnContractInfo.Address
chainConfig.Params.BurnContractDestinationAddress = burnContractInfo.DestinationAddress
} else {
// burnt funds are sent to zero address when dealing with mintable native tokens
Expand Down
1 change: 1 addition & 0 deletions command/genesis/utils.go
Original file line number Diff line number Diff line change
Expand Up @@ -342,6 +342,7 @@ func getCGPricesData(apiKey string, precision int) (*PricesDataCoinGecko, error)
}

var pricesData *PricesDataCoinGecko

err = json.Unmarshal(body, &pricesData)
if err != nil {
return nil, fmt.Errorf("failed to unmarshal response: %w", err)
Expand Down
5 changes: 3 additions & 2 deletions command/polybft/polybft_command.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,9 @@ import (

func GetCommand() *cobra.Command {
polybftCmd := &cobra.Command{
Use: "hydragon",
Short: "Executes HydraChain's Hydragon consensus commands, including staking, unstaking, rewards management, and validator operations.",
Use: "hydragon",
Short: "Executes HydraChain's Hydragon consensus commands, including staking, unstaking, rewards management, " +
"and validator operations.",
}

// Hydra modification: modify sidechain commands and remove rootchain commands
Expand Down
12 changes: 6 additions & 6 deletions command/polybftsecrets/params.go
Original file line number Diff line number Diff line change
Expand Up @@ -156,12 +156,14 @@ func (ip *initParams) setFlags(cmd *cobra.Command) {
// num flag should be used with data-dir flag only so it should not be used with config flag.
cmd.MarkFlagsMutuallyExclusive(numFlag, AccountConfigFlag)

// Encryptedlocal secrets manager with preset keys can be setup for a single bunch of secrets only, so num flag is not allowed.
// Encryptedlocal secrets manager with preset keys can be setup for a single bunch of secrets only,
// so num flag is not allowed.
cmd.MarkFlagsMutuallyExclusive(numFlag, networkKeyFlag)
cmd.MarkFlagsMutuallyExclusive(numFlag, blsKeyFlag)
cmd.MarkFlagsMutuallyExclusive(numFlag, ecdsaKeyFlag)

// network-key, ecdsa-key and bls-key flags should be used with data-dir flag only because they are related to local FS.
// network-key, ecdsa-key and bls-key flags should be used with data-dir flag only because they are related
// to local FS.
cmd.MarkFlagsMutuallyExclusive(AccountConfigFlag, networkKeyFlag)
cmd.MarkFlagsMutuallyExclusive(AccountConfigFlag, blsKeyFlag)
cmd.MarkFlagsMutuallyExclusive(AccountConfigFlag, ecdsaKeyFlag)
Expand Down Expand Up @@ -218,10 +220,8 @@ func (ip *initParams) initKeys(secretsManager secrets.SecretsManager) ([]string,
}

generated = append(generated, secrets.NetworkKey)
} else {
if ip.networkKey != "" {
return generated, fmt.Errorf("network-key already exists")
}
} else if ip.networkKey != "" {
return generated, fmt.Errorf("network-key already exists")
}
}

Expand Down
6 changes: 3 additions & 3 deletions command/secrets/init/params.go
Original file line number Diff line number Diff line change
Expand Up @@ -96,9 +96,9 @@ func (ip *initParams) parseConfig() error {

func (ip *initParams) initLocalSecretsManager() error {
if !ip.insecureLocalStore {
//Storing secrets on a local file system should only be allowed with --insecure flag,
//to raise awareness that it should be only used in development/testing environments.
//Production setups should use one of the supported secrets managers
// Storing secrets on a local file system should only be allowed with --insecure flag,
// to raise awareness that it should be only used in development/testing environments.
// Production setups should use one of the supported secrets managers
return errSecureLocalStoreNotImplemented
}

Expand Down
Loading

0 comments on commit 9c01a41

Please sign in to comment.