Skip to content

Commit 07541f7

Browse files
authored
chore!: cleanup & lints (#78)
* use `Validators` instead of `PendingValidators` proto * CI cleanup (fmt, title, etc) * authz nested message check (recursive) * add x/POA logger * add linter settings * golangci_version=v1.55.2 * Add proto comments * rm codeowners for now * disable staking: recursive authz check * make install in root dir * params ErrMustProvideAtLeastOneAddress * validate cachedPower != 0 at a height > 1 * rm migration code * use single errorsmod * comments * keeper test: abstract core setup * msg_server test tweaks * add TestRegisterLegacyAminoCodec * comments * lint * minor touch ups * fix: `BeginBlock` (was modified to sdk.Context) * move priv msg_server funcs -> dedicated file * lint * simplify pending type to ConvertStakingToPOA * lint
1 parent 8e64622 commit 07541f7

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

57 files changed

+1808
-1583
lines changed

Diff for: .github/CODEOWNERS

-3
This file was deleted.

Diff for: .github/dependabot.yml

+2-2
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,8 @@ updates:
33
- package-ecosystem: "gomod"
44
directory: "/"
55
schedule:
6-
interval: "daily"
6+
interval: "weekly"
77
- package-ecosystem: "github-actions"
88
directory: "/"
99
schedule:
10-
interval: "daily"
10+
interval: "monthly"

Diff for: .github/workflows/e2e.yaml

+9-9
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
name: e2e
2-
on:
2+
on:
33
push:
44
branches:
55
- main
@@ -8,7 +8,7 @@ on:
88
env:
99
LINT_VERSION: v1.52
1010
GO_VERSION: 1.21.0
11-
11+
1212
TAR_PATH: /tmp/poa.tar
1313
IMAGE_NAME: poa
1414
DOCKER_TAG: poa:local
@@ -23,14 +23,14 @@ jobs:
2323
- name: Setup Go ${{ env.GO_VERSION }}
2424
uses: actions/setup-go@v4
2525
with:
26-
go-version: ${{ env.GO_VERSION }}
26+
go-version: ${{ env.GO_VERSION }}
2727

2828
- name: Set up Docker Buildx
2929
uses: docker/setup-buildx-action@v3
30-
30+
3131
- name: Build and export
3232
uses: docker/build-push-action@v5
33-
with:
33+
with:
3434
tags: ${{ env.DOCKER_TAG }}
3535
outputs: type=docker,dest=${{ env.TAR_PATH }}
3636

@@ -44,16 +44,16 @@ jobs:
4444
needs: build-docker
4545
runs-on: ubuntu-latest
4646
strategy:
47-
matrix:
47+
matrix:
4848
test:
49-
- "ictest-poa"
49+
- "ictest-poa"
5050
fail-fast: false
5151

5252
steps:
5353
- name: Set up Go ${{ env.GO_VERSION }}
5454
uses: actions/setup-go@v4
5555
with:
56-
go-version: ${{ env.GO_VERSION }}
56+
go-version: ${{ env.GO_VERSION }}
5757

5858
- name: checkout chain
5959
uses: actions/checkout@v4
@@ -66,7 +66,7 @@ jobs:
6666

6767
- name: Load Docker Image
6868
run: |
69-
docker image load -i ${{ env.TAR_PATH }}
69+
docker image load -i ${{ env.TAR_PATH }}
7070
docker image ls -a
7171
7272
- name: Run Test

Diff for: .github/workflows/title-format.yml

+2-1
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,8 @@ on:
88
permissions:
99
contents: read
1010
jobs:
11-
lint:
11+
lint-title:
12+
name: Lint PR Title
1213
permissions:
1314
pull-requests: read
1415
statuses: write

Diff for: .golangci.yml

+68
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,68 @@
1+
run:
2+
timeout: 10m
3+
tests: true
4+
5+
linters:
6+
disable-all: true
7+
enable:
8+
- asciicheck
9+
- bidichk
10+
- bodyclose
11+
- decorder
12+
- dupl
13+
- dupword
14+
- errcheck
15+
- errchkjson
16+
- errname
17+
- exhaustive
18+
- exportloopref
19+
- forbidigo
20+
- gci
21+
- goconst
22+
- goconst
23+
- gocritic
24+
- gofmt
25+
- gosec
26+
- gosec
27+
- gosimple
28+
- gosmopolitan
29+
- govet
30+
- grouper
31+
- ineffassign
32+
- loggercheck
33+
- misspell
34+
- nilerr
35+
- nilnil
36+
- noctx
37+
- stylecheck
38+
- testifylint
39+
- thelper
40+
- tparallel
41+
- typecheck
42+
- unconvert
43+
- unconvert
44+
- unparam
45+
- unused
46+
- usestdlibvars
47+
- wastedassign
48+
- whitespace
49+
50+
linters-settings:
51+
gci:
52+
custom-order: true
53+
sections:
54+
- standard # Standard section: captures all standard packages.
55+
- default # Default section: contains all imports that could not be matched to another section type.
56+
- blank # blank imports
57+
- dot # dot imports
58+
- prefix(github.com/cometbft/cometbft)
59+
- prefix(github.com/cosmos)
60+
- prefix(github.com/cosmos/cosmos-sdk)
61+
- prefix(cosmossdk.io)
62+
- prefix(github.com/strangelove-ventures/poa)
63+
gosec:
64+
excludes:
65+
- G404
66+
67+
issues:
68+
max-issues-per-linter: 0

Diff for: Makefile

+10-1
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,15 @@ DOCKER := $(shell which docker)
44

55
export GO111MODULE = on
66

7+
####################
8+
### Building ####
9+
####################
10+
11+
include simapp/Makefile
12+
13+
install:
14+
$(MAKE) -C simapp/ install
15+
716
####################
817
### Testing ####
918
####################
@@ -52,7 +61,7 @@ proto-lint:
5261
##################
5362

5463
golangci_lint_cmd=golangci-lint
55-
golangci_version=v1.51.2
64+
golangci_version=v1.55.2
5665

5766
lint:
5867
@echo "--> Running linter"

Diff for: ante/ante_test.go

+8-4
Original file line numberDiff line numberDiff line change
@@ -4,12 +4,15 @@ import (
44
"fmt"
55
"testing"
66

7-
"cosmossdk.io/math"
7+
"github.com/stretchr/testify/require"
8+
protov2 "google.golang.org/protobuf/proto"
9+
810
sdk "github.com/cosmos/cosmos-sdk/types"
911
stakingtypes "github.com/cosmos/cosmos-sdk/x/staking/types"
12+
13+
"cosmossdk.io/math"
14+
1015
"github.com/strangelove-ventures/poa"
11-
"github.com/stretchr/testify/require"
12-
protov2 "google.golang.org/protobuf/proto"
1316
)
1417

1518
var (
@@ -112,7 +115,7 @@ func TestAnteCommissionRanges(t *testing.T) {
112115

113116
func TestAnteStakingFilter(t *testing.T) {
114117
ctx := sdk.Context{}
115-
sf := NewPOAStakingFilterDecorator()
118+
sf := NewPOADisableStakingDecorator()
116119

117120
blockedMsgs := map[string]sdk.Msg{
118121
"CreateStakingValidator": &stakingtypes.MsgCreateValidator{},
@@ -149,6 +152,7 @@ func TestAnteStakingFilter(t *testing.T) {
149152
func setBlockHeader(ctx sdk.Context, height uint64) sdk.Context {
150153
h := ctx.BlockHeader()
151154
h.Height = int64(height)
155+
152156
return ctx.WithBlockHeader(h)
153157
}
154158

Diff for: ante/commission_limit.go

+19-3
Original file line numberDiff line numberDiff line change
@@ -3,9 +3,12 @@ package poaante
33
import (
44
"fmt"
55

6-
"cosmossdk.io/math"
76
sdk "github.com/cosmos/cosmos-sdk/types"
7+
"github.com/cosmos/cosmos-sdk/x/authz"
88
stakingtypes "github.com/cosmos/cosmos-sdk/x/staking/types"
9+
10+
"cosmossdk.io/math"
11+
912
"github.com/strangelove-ventures/poa"
1013
)
1114

@@ -44,16 +47,29 @@ func (mcl MsgCommissionLimiterDecorator) AnteHandle(ctx sdk.Context, tx sdk.Tx,
4447

4548
func (mcl MsgCommissionLimiterDecorator) hasInvalidCommissionRange(msgs []sdk.Msg) error {
4649
for _, msg := range msgs {
50+
// authz nested message check (recursive)
51+
if execMsg, ok := msg.(*authz.MsgExec); ok {
52+
msgs, err := execMsg.GetMessages()
53+
if err != nil {
54+
return err
55+
}
56+
57+
err = mcl.hasInvalidCommissionRange(msgs)
58+
if err != nil {
59+
return err
60+
}
61+
}
62+
4763
switch msg := msg.(type) {
4864
// Create Validator POA wrapper
4965
case *poa.MsgCreateValidator:
5066
return rateCheck(msg.Commission.Rate, mcl.RateFloor, mcl.RateCeil)
51-
// editing the validator through staking (no POA edit)
67+
// Editing the validator through staking (no POA edit)
5268
case *stakingtypes.MsgEditValidator:
5369
return rateCheck(*msg.CommissionRate, mcl.RateFloor, mcl.RateCeil)
5470
}
55-
5671
}
72+
5773
return nil
5874
}
5975

Diff for: ante/disable_staking.go

+27-15
Original file line numberDiff line numberDiff line change
@@ -2,15 +2,16 @@ package poaante
22

33
import (
44
sdk "github.com/cosmos/cosmos-sdk/types"
5-
"github.com/strangelove-ventures/poa"
6-
5+
"github.com/cosmos/cosmos-sdk/x/authz"
76
stakingtypes "github.com/cosmos/cosmos-sdk/x/staking/types"
7+
8+
"github.com/strangelove-ventures/poa"
89
)
910

1011
type MsgStakingFilterDecorator struct {
1112
}
1213

13-
func NewPOAStakingFilterDecorator() MsgStakingFilterDecorator {
14+
func NewPOADisableStakingDecorator() MsgStakingFilterDecorator {
1415
return MsgStakingFilterDecorator{}
1516
}
1617

@@ -31,22 +32,33 @@ func (msfd MsgStakingFilterDecorator) AnteHandle(ctx sdk.Context, tx sdk.Tx, sim
3132

3233
func (msfd MsgStakingFilterDecorator) hasInvalidStakingMsg(msgs []sdk.Msg) bool {
3334
for _, msg := range msgs {
35+
// authz nested message check (recursive)
36+
if execMsg, ok := msg.(*authz.MsgExec); ok {
37+
msgs, err := execMsg.GetMessages()
38+
if err != nil {
39+
return true
40+
}
41+
42+
if msfd.hasInvalidStakingMsg(msgs) {
43+
return true
44+
}
45+
}
46+
3447
switch msg.(type) {
35-
case *stakingtypes.MsgBeginRedelegate:
48+
// POA wrapped messages
49+
case *stakingtypes.MsgCreateValidator, *stakingtypes.MsgUpdateParams:
3650
return true
37-
case *stakingtypes.MsgCancelUnbondingDelegation:
38-
return true
39-
case *stakingtypes.MsgCreateValidator: // POA wraps this message.
40-
return true
41-
case *stakingtypes.MsgDelegate:
42-
return true
43-
// case *stakingtypes.MsgEditValidator: // Allowed
44-
// return true
45-
case *stakingtypes.MsgUndelegate:
46-
return true
47-
case *stakingtypes.MsgUpdateParams: // POA wraps this message.
51+
52+
// Blocked entirely when POA is enabled
53+
case *stakingtypes.MsgBeginRedelegate,
54+
*stakingtypes.MsgCancelUnbondingDelegation,
55+
*stakingtypes.MsgDelegate,
56+
*stakingtypes.MsgUndelegate:
4857
return true
4958
}
59+
60+
// stakingtypes.MsgEditValidator is the only allowed message. We do not need to check for it.
5061
}
62+
5163
return false
5264
}

0 commit comments

Comments
 (0)