diff --git a/.github/workflows/pr-go-mod-tidy-mocks.yml b/.github/workflows/pr-go-mod-tidy-mocks.yml index c1891099e074..30f4a697385f 100644 --- a/.github/workflows/pr-go-mod-tidy-mocks.yml +++ b/.github/workflows/pr-go-mod-tidy-mocks.yml @@ -1,6 +1,8 @@ -name: 'Checks dependencies and mocks generation' +name: "Checks dependencies and mocks generation" on: + merge_group: pull_request: + push: branches: - main diff --git a/.golangci.yml b/.golangci.yml index 20fadf26179f..fc4dd038ba30 100644 --- a/.golangci.yml +++ b/.golangci.yml @@ -1,19 +1,8 @@ run: tests: true timeout: 15m - sort-results: true allow-parallel-runners: true - exclude-dir: testutil/testdata - skip-files: - - server/grpc/gogoreflection/fix_registration.go - - "fix_registration.go" - - ".*\\.pb\\.go$" - - ".*\\.pb\\.gw\\.go$" - - ".*\\.pulsar\\.go$" - - crypto/keys/secp256k1/internal/* - - types/coin_regex.go - -build-tags: + build-tags: - e2e - ledger - test_ledger_mock @@ -46,6 +35,16 @@ linters: - unused issues: + exclude-dirs: + - testutil/testdata + exclude-files: + - server/grpc/gogoreflection/fix_registration.go + - "fix_registration.go" + - ".*\\.pb\\.go$" + - ".*\\.pb\\.gw\\.go$" + - ".*\\.pulsar\\.go$" + - crypto/keys/secp256k1/internal/* + - types/coin_regex.go exclude-rules: - text: "Use of weak random number generator" linters: @@ -141,11 +140,8 @@ linters-settings: extra-rules: true dogsled: max-blank-identifiers: 6 - maligned: - suggest-new: true nolintlint: allow-unused: false - allow-leading-space: true require-explanation: true require-specific: false gosimple: diff --git a/server/v2/cometbft/client/rpc/block.go b/server/v2/cometbft/client/rpc/block.go index ead230b16b87..47ff2a081c28 100644 --- a/server/v2/cometbft/client/rpc/block.go +++ b/server/v2/cometbft/client/rpc/block.go @@ -55,7 +55,7 @@ func QueryBlocks(ctx context.Context, rpcClient CometRPC, page, limit int, query return result, nil } -// get block by height +// GetBlockByHeight gets block by height func GetBlockByHeight(ctx context.Context, rpcClient CometRPC, height *int64) (*v11.Block, error) { // header -> BlockchainInfo // header, tx -> Block @@ -76,6 +76,7 @@ func GetBlockByHeight(ctx context.Context, rpcClient CometRPC, height *int64) (* return out, nil } +// GetBlockByHash gets block by hash func GetBlockByHash(ctx context.Context, rpcClient CometRPC, hashHexString string) (*v11.Block, error) { hash, err := hex.DecodeString(hashHexString) if err != nil { @@ -89,8 +90,6 @@ func GetBlockByHash(ctx context.Context, rpcClient CometRPC, hashHexString strin } else if resBlock.Block == nil { return nil, fmt.Errorf("block not found with hash: %s", hashHexString) } - - // TODO: Also move NewResponseResultBlock somewhere around this package out, err := NewResponseResultBlock(resBlock) if err != nil { return nil, err diff --git a/server/v2/cometbft/client/rpc/utils.go b/server/v2/cometbft/client/rpc/utils.go index c41542c9734c..6dfac989b9a1 100644 --- a/server/v2/cometbft/client/rpc/utils.go +++ b/server/v2/cometbft/client/rpc/utils.go @@ -61,7 +61,7 @@ func NewResponseResultBlock(res *coretypes.ResultBlock) (*v11.Block, error) { return blk, nil } -// calculate total pages in an overflow safe manner +// calcTotalPages calculates total pages in an overflow safe manner func calcTotalPages(totalCount, limit int64) int64 { totalPages := int64(0) if totalCount != 0 && limit != 0 { diff --git a/sonar-project.properties b/sonar-project.properties index 816abe8a8c79..95bd2b396fa3 100644 --- a/sonar-project.properties +++ b/sonar-project.properties @@ -5,8 +5,8 @@ sonar.projectName=Cosmos SDK sonar.project.monorepo.enabled=true sonar.sources=. -sonar.exclusions=**/*_test.go,**/*.pb.go,**/*.pulsar.go,**/*.pb.gw.go -sonar.coverage.exclusions=**/*_test.go,**/testutil/**,**/*.pb.go,**/*.pb.gw.go,**/*.pulsar.go,test_helpers.go,docs/** +sonar.exclusions=**/*_test.go,**/*.pb.go,**/*.pulsar.go,**/*.pb.gw.go,*.java +sonar.coverage.exclusions=**/*_test.go,**/testutil/**,**/*.pb.go,**/*.pb.gw.go,**/*.pulsar.go,docs/**,server/v2/**,store/v2/**,x/tx/**,tools/**,simapp/**,testutil/**,test_helpers.go,tests/**,test_helpers.go,docs/**,store/**,tests/**,orm/**,client/v2/**,runtime/v2/**,core/**,store/**,x/evidence,x/feegrant,x/authz,x/auth,x/bank,api,x/gov,x/staking,x/group,x/nft sonar.tests=. sonar.test.inclusions=**/*_test.go,tests/**,**/testutil/** sonar.go.coverage.reportPaths=coverage.out,*profile.out diff --git a/x/bank/CHANGELOG.md b/x/bank/CHANGELOG.md index 9d5a91718557..22f1637fbfb7 100644 --- a/x/bank/CHANGELOG.md +++ b/x/bank/CHANGELOG.md @@ -33,6 +33,7 @@ Ref: https://keepachangelog.com/en/1.0.0/ ### Improvements * [#18636](https://github.com/cosmos/cosmos-sdk/pull/18636) `SendCoinsFromModuleToAccount`, `SendCoinsFromModuleToModule`, `SendCoinsFromAccountToModule`, `DelegateCoinsFromAccountToModule`, `UndelegateCoinsFromModuleToAccount`, `MintCoins` and `BurnCoins` methods now returns an error instead of panicking if any module accounts does not exist or unauthorized. +* [#20517](https://github.com/cosmos/cosmos-sdk/pull/20517) `SendCoins` now checks for `SendRestrictions` before instead of after deducting coins using `subUnlockedCoins`. ### API Breaking Changes diff --git a/x/bank/README.md b/x/bank/README.md index 3bee1e5022a4..5a660c019d2f 100644 --- a/x/bank/README.md +++ b/x/bank/README.md @@ -275,7 +275,7 @@ Both functions compose the provided restriction with any previously provided res `PrependSendRestriction` adds the restriction to be run before any previously provided send restrictions. The composition will short-circuit when an error is encountered. I.e. if the first one returns an error, the second is not run. -During `SendCoins`, the send restriction is applied after coins are removed from the from address, but before adding them to the to address. +During `SendCoins`, the send restriction is applied before coins are removed from the from address and adding them to the to address. During `InputOutputCoins`, the send restriction is applied after the input coins are removed and once for each output before the funds are added. A send restriction function should make use of a custom value in the context to allow bypassing that specific restriction. diff --git a/x/bank/keeper/keeper_test.go b/x/bank/keeper/keeper_test.go index 47b75f02915e..5820d9542284 100644 --- a/x/bank/keeper/keeper_test.go +++ b/x/bank/keeper/keeper_test.go @@ -1180,7 +1180,7 @@ func (suite *KeeperTestSuite) TestSendCoinsWithRestrictions() { }, expErr: "test restriction error", expBals: expBals{ - from: sdk.NewCoins(newFooCoin(885), newBarCoin(273)), + from: sdk.NewCoins(newFooCoin(985), newBarCoin(473)), to1: sdk.NewCoins(newFooCoin(15)), to2: sdk.NewCoins(newBarCoin(27)), }, @@ -1194,12 +1194,9 @@ func (suite *KeeperTestSuite) TestSendCoinsWithRestrictions() { actualRestrictionArgs = nil suite.bankKeeper.SetSendRestriction(tc.fn) ctx := suite.ctx - if len(tc.expErr) > 0 { - suite.authKeeper.EXPECT().GetAccount(ctx, fromAddr).Return(fromAcc) - } else { + if len(tc.expErr) == 0 { suite.mockSendCoins(ctx, fromAcc, tc.finalAddr) } - var err error testFunc := func() { err = suite.bankKeeper.SendCoins(ctx, fromAddr, tc.toAddr, tc.amt) diff --git a/x/bank/keeper/send.go b/x/bank/keeper/send.go index 47321da51b60..31354c1b8566 100644 --- a/x/bank/keeper/send.go +++ b/x/bank/keeper/send.go @@ -189,12 +189,12 @@ func (k BaseSendKeeper) SendCoins(ctx context.Context, fromAddr, toAddr sdk.AccA } var err error - err = k.subUnlockedCoins(ctx, fromAddr, amt) + toAddr, err = k.sendRestriction.apply(ctx, fromAddr, toAddr, amt) if err != nil { return err } - toAddr, err = k.sendRestriction.apply(ctx, fromAddr, toAddr, amt) + err = k.subUnlockedCoins(ctx, fromAddr, amt) if err != nil { return err }