diff --git a/.github/workflows/lint.yml b/.github/workflows/lint.yml index 95b5f8999..1f2f63502 100644 --- a/.github/workflows/lint.yml +++ b/.github/workflows/lint.yml @@ -14,16 +14,15 @@ jobs: runs-on: ubuntu-latest timeout-minutes: 6 steps: - - uses: actions/checkout@v2 - - uses: technote-space/get-diff-action@v4 + - uses: actions/checkout@v4 + - uses: technote-space/get-diff-action@v6 with: - SUFFIX_FILTER: | - .go - .mod - .sum - - uses: golangci/golangci-lint-action@v2 + PATTERNS: | + **/*.go + **/*.mod + **/*.sum + - uses: golangci/golangci-lint-action@v7 with: - version: v1.28 + version: v2.3.0 args: --timeout 10m - github-token: ${{ secrets.GITHUB_TOKEN }} - if: "env.GIT_DIFF != ''" + if: env.GIT_DIFF != '' diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index 4e4180075..e9aa543d3 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -14,21 +14,21 @@ jobs: - uses: rokroskar/workflow-run-cleanup-action@master env: GITHUB_TOKEN: "${{ secrets.GITHUB_TOKEN }}" - if: "!startsWith(github.ref, 'refs/tags/') && github.ref != 'refs/heads/master'" + if: '!startsWith(github.ref, ''refs/tags/'') && github.ref != ''refs/heads/master''' Unit-tests: runs-on: ubuntu-latest timeout-minutes: 10 steps: - name: Checkout - uses: actions/checkout@v2 + uses: actions/checkout@v4 - name: Setup Go - uses: actions/setup-go@v2 + uses: actions/setup-go@v4 with: - go-version: 1.15 + go-version: '1.23' - name: Test & Create coverage report run: make install test-unit stop-docker-test - - name: Upload cove coverage - uses: codecov/codecov-action@v1.0.7 + - name: Upload code coverage + uses: codecov/codecov-action@v3 with: file: ./coverage.txt diff --git a/.golangci.old.yaml b/.golangci.old.yaml new file mode 100644 index 000000000..a9a80c2eb --- /dev/null +++ b/.golangci.old.yaml @@ -0,0 +1,70 @@ +run: + tests: false +# # timeout for analysis, e.g. 30s, 5m, default is 1m +# timeout: 5m + +linters: + disable-all: true + enable: + - bodyclose + - deadcode + - dogsled + - gocritic + - gofmt + - goimports + - golint + - gosec + - gosimple + - govet + - ineffassign + - maligned + - misspell + - nakedret + - scopelint + - staticcheck + - structcheck + - stylecheck + - typecheck + - unconvert + - unused + - unparam + - misspell + - nolintlint + +issues: + exclude-rules: + - text: "Use of weak random number generator" + linters: + - gosec + - text: "comment on exported var" + linters: + - golint + - text: "don't use an underscore in package name" + linters: + - golint + - text: "ST1003:" + linters: + - stylecheck + # FIXME: Disabled until golangci-lint updates stylecheck with this fix: + # https://github.com/dominikh/go-tools/issues/389 + - text: "ST1016:" + linters: + - stylecheck + # Disable until Msg-based gov proposals are fully implemented + - text: "SA1019:" + linters: + - staticcheck + max-issues-per-linter: 10000 + max-same-issues: 10000 + +linters-settings: + dogsled: + max-blank-identifiers: 3 + maligned: + # print struct with more effective memory layout or not, false by default + suggest-new: true + nolintlint: + allow-unused: false + allow-leading-space: true + require-explanation: false + require-specific: false diff --git a/.golangci.yaml b/.golangci.yaml index a9a80c2eb..3257cae5b 100644 --- a/.golangci.yaml +++ b/.golangci.yaml @@ -1,70 +1,69 @@ +version: "2" run: tests: false -# # timeout for analysis, e.g. 30s, 5m, default is 1m -# timeout: 5m - linters: - disable-all: true + default: none enable: - bodyclose - - deadcode - dogsled - gocritic - - gofmt - - goimports - - golint - gosec - - gosimple - govet - ineffassign - - maligned - misspell - nakedret - - scopelint + - nolintlint - staticcheck - - structcheck - - stylecheck - - typecheck - unconvert - - unused - unparam - - misspell - - nolintlint - + - unused + settings: + dogsled: + max-blank-identifiers: 3 + nolintlint: + require-explanation: false + require-specific: false + allow-unused: false + exclusions: + generated: lax + presets: + - comments + - common-false-positives + - legacy + - std-error-handling + rules: + - linters: + - gosec + text: Use of weak random number generator + - linters: + - golint + text: comment on exported var + - linters: + - golint + text: don't use an underscore in package name + - linters: + - staticcheck + text: 'ST1003:' + - linters: + - staticcheck + text: 'ST1016:' + - linters: + - staticcheck + text: 'SA1019:' + paths: + - third_party$ + - builtin$ + - examples$ issues: - exclude-rules: - - text: "Use of weak random number generator" - linters: - - gosec - - text: "comment on exported var" - linters: - - golint - - text: "don't use an underscore in package name" - linters: - - golint - - text: "ST1003:" - linters: - - stylecheck - # FIXME: Disabled until golangci-lint updates stylecheck with this fix: - # https://github.com/dominikh/go-tools/issues/389 - - text: "ST1016:" - linters: - - stylecheck - # Disable until Msg-based gov proposals are fully implemented - - text: "SA1019:" - linters: - - staticcheck max-issues-per-linter: 10000 max-same-issues: 10000 - -linters-settings: - dogsled: - max-blank-identifiers: 3 - maligned: - # print struct with more effective memory layout or not, false by default - suggest-new: true - nolintlint: - allow-unused: false - allow-leading-space: true - require-explanation: false - require-specific: false +formatters: + enable: + - gofmt + - goimports + exclusions: + generated: lax + paths: + - third_party$ + - builtin$ + - examples$ diff --git a/modules/gov/handle_msg.go b/modules/gov/handle_msg.go index 09df71260..3729926b5 100644 --- a/modules/gov/handle_msg.go +++ b/modules/gov/handle_msg.go @@ -169,6 +169,15 @@ func (m *Module) handleSubmitProposalEvent(tx *juno.Transaction, proposer string return fmt.Errorf("error while saving proposal: %s", err) } + // Update staking pool snapshot immediately for the new proposal + err = m.UpdateSingleProposalStakingPoolSnapshot(int64(tx.Height), proposal.Id) + if err != nil { + log.Error().Err(err). + Uint64("proposal_id", proposal.Id). + Uint64("height", tx.Height). + Msg("failed to update staking pool snapshot for new proposal") + } + // Submit proposal must have a deposit event with depositor equal to the proposer return m.handleDepositEvent(tx, proposer, events) } diff --git a/modules/gov/utils_proposal.go b/modules/gov/utils_proposal.go index d24842750..b5d0da69b 100644 --- a/modules/gov/utils_proposal.go +++ b/modules/gov/utils_proposal.go @@ -100,6 +100,19 @@ func (m *Module) UpdateProposalStakingPoolSnapshot(height int64, proposalID uint ) } +// UpdateSingleProposalStakingPoolSnapshot updates the staking pool snapshot for a single proposal +// This is an optimized version of UpdateProposalStakingPoolSnapshot for handling newly created proposals +func (m *Module) UpdateSingleProposalStakingPoolSnapshot(height int64, proposalID uint64) error { + pool, err := m.stakingModule.GetStakingPoolSnapshot(height) + if err != nil { + return fmt.Errorf("error while getting staking pool: %s", err) + } + + return m.db.SaveProposalStakingPoolSnapshot( + types.NewProposalStakingPoolSnapshot(proposalID, pool), + ) +} + // updateDeletedProposalStatus updates the proposal having the given id by setting its status // to the one that represents a deleted proposal func (m *Module) updateDeletedProposalStatus(id uint64) error {