Skip to content

Commit

Permalink
chore!: cleanup & lints (#78)
Browse files Browse the repository at this point in the history
* 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
  • Loading branch information
Reecepbcups authored Nov 26, 2023
1 parent 8e64622 commit 07541f7
Show file tree
Hide file tree
Showing 57 changed files with 1,808 additions and 1,583 deletions.
3 changes: 0 additions & 3 deletions .github/CODEOWNERS

This file was deleted.

4 changes: 2 additions & 2 deletions .github/dependabot.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@ updates:
- package-ecosystem: "gomod"
directory: "/"
schedule:
interval: "daily"
interval: "weekly"
- package-ecosystem: "github-actions"
directory: "/"
schedule:
interval: "daily"
interval: "monthly"
18 changes: 9 additions & 9 deletions .github/workflows/e2e.yaml
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
name: e2e
on:
on:
push:
branches:
- main
Expand All @@ -8,7 +8,7 @@ on:
env:
LINT_VERSION: v1.52
GO_VERSION: 1.21.0

TAR_PATH: /tmp/poa.tar
IMAGE_NAME: poa
DOCKER_TAG: poa:local
Expand All @@ -23,14 +23,14 @@ jobs:
- name: Setup Go ${{ env.GO_VERSION }}
uses: actions/setup-go@v4
with:
go-version: ${{ env.GO_VERSION }}
go-version: ${{ env.GO_VERSION }}

- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v3

- name: Build and export
uses: docker/build-push-action@v5
with:
with:
tags: ${{ env.DOCKER_TAG }}
outputs: type=docker,dest=${{ env.TAR_PATH }}

Expand All @@ -44,16 +44,16 @@ jobs:
needs: build-docker
runs-on: ubuntu-latest
strategy:
matrix:
matrix:
test:
- "ictest-poa"
- "ictest-poa"
fail-fast: false

steps:
- name: Set up Go ${{ env.GO_VERSION }}
uses: actions/setup-go@v4
with:
go-version: ${{ env.GO_VERSION }}
go-version: ${{ env.GO_VERSION }}

- name: checkout chain
uses: actions/checkout@v4
Expand All @@ -66,7 +66,7 @@ jobs:

- name: Load Docker Image
run: |
docker image load -i ${{ env.TAR_PATH }}
docker image load -i ${{ env.TAR_PATH }}
docker image ls -a
- name: Run Test
Expand Down
3 changes: 2 additions & 1 deletion .github/workflows/title-format.yml
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,8 @@ on:
permissions:
contents: read
jobs:
lint:
lint-title:
name: Lint PR Title
permissions:
pull-requests: read
statuses: write
Expand Down
68 changes: 68 additions & 0 deletions .golangci.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,68 @@
run:
timeout: 10m
tests: true

linters:
disable-all: true
enable:
- asciicheck
- bidichk
- bodyclose
- decorder
- dupl
- dupword
- errcheck
- errchkjson
- errname
- exhaustive
- exportloopref
- forbidigo
- gci
- goconst
- goconst
- gocritic
- gofmt
- gosec
- gosec
- gosimple
- gosmopolitan
- govet
- grouper
- ineffassign
- loggercheck
- misspell
- nilerr
- nilnil
- noctx
- stylecheck
- testifylint
- thelper
- tparallel
- typecheck
- unconvert
- unconvert
- unparam
- unused
- usestdlibvars
- wastedassign
- whitespace

linters-settings:
gci:
custom-order: true
sections:
- standard # Standard section: captures all standard packages.
- default # Default section: contains all imports that could not be matched to another section type.
- blank # blank imports
- dot # dot imports
- prefix(github.com/cometbft/cometbft)
- prefix(github.com/cosmos)
- prefix(github.com/cosmos/cosmos-sdk)
- prefix(cosmossdk.io)
- prefix(github.com/strangelove-ventures/poa)
gosec:
excludes:
- G404

issues:
max-issues-per-linter: 0
11 changes: 10 additions & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,15 @@ DOCKER := $(shell which docker)

export GO111MODULE = on

####################
### Building ####
####################

include simapp/Makefile

install:
$(MAKE) -C simapp/ install

####################
### Testing ####
####################
Expand Down Expand Up @@ -52,7 +61,7 @@ proto-lint:
##################

golangci_lint_cmd=golangci-lint
golangci_version=v1.51.2
golangci_version=v1.55.2

lint:
@echo "--> Running linter"
Expand Down
12 changes: 8 additions & 4 deletions ante/ante_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,15 @@ import (
"fmt"
"testing"

"cosmossdk.io/math"
"github.com/stretchr/testify/require"
protov2 "google.golang.org/protobuf/proto"

sdk "github.com/cosmos/cosmos-sdk/types"
stakingtypes "github.com/cosmos/cosmos-sdk/x/staking/types"

"cosmossdk.io/math"

"github.com/strangelove-ventures/poa"
"github.com/stretchr/testify/require"
protov2 "google.golang.org/protobuf/proto"
)

var (
Expand Down Expand Up @@ -112,7 +115,7 @@ func TestAnteCommissionRanges(t *testing.T) {

func TestAnteStakingFilter(t *testing.T) {
ctx := sdk.Context{}
sf := NewPOAStakingFilterDecorator()
sf := NewPOADisableStakingDecorator()

blockedMsgs := map[string]sdk.Msg{
"CreateStakingValidator": &stakingtypes.MsgCreateValidator{},
Expand Down Expand Up @@ -149,6 +152,7 @@ func TestAnteStakingFilter(t *testing.T) {
func setBlockHeader(ctx sdk.Context, height uint64) sdk.Context {
h := ctx.BlockHeader()
h.Height = int64(height)

return ctx.WithBlockHeader(h)
}

Expand Down
22 changes: 19 additions & 3 deletions ante/commission_limit.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,12 @@ package poaante
import (
"fmt"

"cosmossdk.io/math"
sdk "github.com/cosmos/cosmos-sdk/types"
"github.com/cosmos/cosmos-sdk/x/authz"
stakingtypes "github.com/cosmos/cosmos-sdk/x/staking/types"

"cosmossdk.io/math"

"github.com/strangelove-ventures/poa"
)

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

func (mcl MsgCommissionLimiterDecorator) hasInvalidCommissionRange(msgs []sdk.Msg) error {
for _, msg := range msgs {
// authz nested message check (recursive)
if execMsg, ok := msg.(*authz.MsgExec); ok {
msgs, err := execMsg.GetMessages()
if err != nil {
return err
}

err = mcl.hasInvalidCommissionRange(msgs)
if err != nil {
return err
}
}

switch msg := msg.(type) {
// Create Validator POA wrapper
case *poa.MsgCreateValidator:
return rateCheck(msg.Commission.Rate, mcl.RateFloor, mcl.RateCeil)
// editing the validator through staking (no POA edit)
// Editing the validator through staking (no POA edit)
case *stakingtypes.MsgEditValidator:
return rateCheck(*msg.CommissionRate, mcl.RateFloor, mcl.RateCeil)
}

}

return nil
}

Expand Down
42 changes: 27 additions & 15 deletions ante/disable_staking.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,15 +2,16 @@ package poaante

import (
sdk "github.com/cosmos/cosmos-sdk/types"
"github.com/strangelove-ventures/poa"

"github.com/cosmos/cosmos-sdk/x/authz"
stakingtypes "github.com/cosmos/cosmos-sdk/x/staking/types"

"github.com/strangelove-ventures/poa"
)

type MsgStakingFilterDecorator struct {
}

func NewPOAStakingFilterDecorator() MsgStakingFilterDecorator {
func NewPOADisableStakingDecorator() MsgStakingFilterDecorator {
return MsgStakingFilterDecorator{}
}

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

func (msfd MsgStakingFilterDecorator) hasInvalidStakingMsg(msgs []sdk.Msg) bool {
for _, msg := range msgs {
// authz nested message check (recursive)
if execMsg, ok := msg.(*authz.MsgExec); ok {
msgs, err := execMsg.GetMessages()
if err != nil {
return true
}

if msfd.hasInvalidStakingMsg(msgs) {
return true
}
}

switch msg.(type) {
case *stakingtypes.MsgBeginRedelegate:
// POA wrapped messages
case *stakingtypes.MsgCreateValidator, *stakingtypes.MsgUpdateParams:
return true
case *stakingtypes.MsgCancelUnbondingDelegation:
return true
case *stakingtypes.MsgCreateValidator: // POA wraps this message.
return true
case *stakingtypes.MsgDelegate:
return true
// case *stakingtypes.MsgEditValidator: // Allowed
// return true
case *stakingtypes.MsgUndelegate:
return true
case *stakingtypes.MsgUpdateParams: // POA wraps this message.

// Blocked entirely when POA is enabled
case *stakingtypes.MsgBeginRedelegate,
*stakingtypes.MsgCancelUnbondingDelegation,
*stakingtypes.MsgDelegate,
*stakingtypes.MsgUndelegate:
return true
}

// stakingtypes.MsgEditValidator is the only allowed message. We do not need to check for it.
}

return false
}
Loading

0 comments on commit 07541f7

Please sign in to comment.