Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: changed the data type for FeePayer and FeeGranter #16272

Merged
merged 25 commits into from
Jul 11, 2023
Merged
Show file tree
Hide file tree
Changes from 15 commits
Commits
Show all changes
25 commits
Select commit Hold shift + click to select a range
d6a5778
changed the data type for FeePayer and FeeGranter
vishal-kanna May 24, 2023
db85847
Merge branch 'main' into typechange
vishal-kanna May 24, 2023
5722e74
uncommented the log
vishal-kanna May 24, 2023
ab71c8d
Merge branch 'typechange' of https://github.com/vishal-kanna/cosmos-s…
vishal-kanna May 24, 2023
9c5a899
Merge branch 'main' of https://github.com/vishal-kanna/cosmos-sdk int…
vishal-kanna May 30, 2023
1f239a5
fix: solved the error in test files
vishal-kanna May 30, 2023
4ca085f
Merge branch 'main' into typechange
atheeshp Jun 5, 2023
4cdb162
Merge branch 'main' of https://github.com/cosmos/cosmos-sdk into type…
vishal-kanna Jul 7, 2023
2af76ce
change added in changelog
vishal-kanna Jul 7, 2023
072c86f
mentioned the change in changelog under the API breaking changes
vishal-kanna Jul 7, 2023
616030b
Revert "mentioned the change in changelog under the API breaking chan…
vishal-kanna Jul 7, 2023
40cccf1
mentioned the change in changelog under the API breaking changes
vishal-kanna Jul 7, 2023
eb5bcc2
changed name of the variable and used the Equalfold method
vishal-kanna Jul 7, 2023
717a478
used the strings.EqualFold method
vishal-kanna Jul 7, 2023
3ed1d9d
mades changes as per request
vishal-kanna Jul 7, 2023
56d10d2
removed the extra line in the changelog
vishal-kanna Jul 7, 2023
6d609fa
Update CHANGELOG.md
likhita-809 Jul 7, 2023
40c8d4f
made changes as per the review
vishal-kanna Jul 7, 2023
465261c
Merge branch 'typechange' of https://github.com/vishal-kanna/cosmos-s…
vishal-kanna Jul 7, 2023
9fd6586
Merge branch 'main' into typechange
vishal-kanna Jul 11, 2023
ee10450
removed the extra variable
vishal-kanna Jul 11, 2023
5eaca40
Merge branch 'typechange' of https://github.com/vishal-kanna/cosmos-s…
vishal-kanna Jul 11, 2023
7037cae
reverted the variable
vishal-kanna Jul 11, 2023
d0093c8
removed the variable
vishal-kanna Jul 11, 2023
5142197
made suggested change in the changelog
vishal-kanna Jul 11, 2023
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ Ref: https://keepachangelog.com/en/1.0.0/

### Features


likhita-809 marked this conversation as resolved.
Show resolved Hide resolved
### Improvements

* (all) [#16537](https://github.com/cosmos/cosmos-sdk/pull/16537) Properly propagated fmt.Errorf errors + using errors.New where appropriate.
Expand All @@ -50,7 +51,7 @@ Ref: https://keepachangelog.com/en/1.0.0/
* (x/bank) [#16841](https://github.com/cosmos/cosmos-sdk/pull/16841) correctly process legacy `DenomAddressIndex` values.

### API Breaking Changes

* (types) [#16272](https://github.com/cosmos/cosmos-sdk/pull/16272) From now the `FeeGranter` in the `FeeTx` interface takes the byte types instead of string.
likhita-809 marked this conversation as resolved.
Show resolved Hide resolved
vishal-kanna marked this conversation as resolved.
Show resolved Hide resolved
* (types/math) [#16040](https://github.com/cosmos/cosmos-sdk/pull/16798) Remove aliases in `types/math.go` (part 2).
* (x/distribution) [#16440](https://github.com/cosmos/cosmos-sdk/pull/16440) use collections for `DelegatorWithdrawAddresState`:
* remove `Keeper`: `SetDelegatorWithdrawAddr`, `DeleteDelegatorWithdrawAddr`, `IterateDelegatorWithdrawAddrs`.
Expand Down
2 changes: 1 addition & 1 deletion types/tx_msg.go
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ type (
GetGas() uint64
GetFee() Coins
FeePayer() []byte
FeeGranter() string
FeeGranter() []byte
}

// TxWithMemo must have GetMemo() method to use ValidateMemoDecorator
Expand Down
7 changes: 2 additions & 5 deletions x/auth/ante/fee.go
Original file line number Diff line number Diff line change
Expand Up @@ -86,11 +86,8 @@ func (dfd DeductFeeDecorator) checkDeductFee(ctx sdk.Context, sdkTx sdk.Tx, fee

// if feegranter set deduct fee from feegranter account.
// this works with only when feegrant enabled.
if feeGranter != "" {
feeGranterAddr, err := sdk.AccAddressFromBech32(feeGranter)
if err != nil {
return err
}
if feeGranter != nil {
feeGranterAddr := sdk.AccAddress(feeGranter)

if dfd.feegrantKeeper == nil {
return sdkerrors.ErrInvalidRequest.Wrap("fee grants are not enabled")
Expand Down
6 changes: 3 additions & 3 deletions x/auth/tx/builder.go
Original file line number Diff line number Diff line change
Expand Up @@ -210,12 +210,12 @@ func (w *wrapper) FeePayer() []byte {
return signers[0]
}

func (w *wrapper) FeeGranter() string {
func (w *wrapper) FeeGranter() []byte {
feeGranter := w.tx.AuthInfo.Fee.Granter
if feeGranter != "" {
return feeGranter
return sdk.MustAccAddressFromBech32(feeGranter)
}
return ""
return nil
}

func (w *wrapper) GetTip() *tx.Tip {
Expand Down
2 changes: 1 addition & 1 deletion x/auth/tx/builder_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -317,5 +317,5 @@ func TestBuilderFeeGranter(t *testing.T) {

// set fee granter
txBuilder.SetFeeGranter(addr1)
require.Equal(t, addr1.String(), txBuilder.GetTx().FeeGranter())
require.Equal(t, addr1.String(), sdk.AccAddress(txBuilder.GetTx().FeeGranter()).String())
}
15 changes: 6 additions & 9 deletions x/auth/tx/direct_aux.go
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
package tx

import (
"bytes"
"fmt"
"strings"

errorsmod "cosmossdk.io/errors"

Expand Down Expand Up @@ -52,17 +52,14 @@ func (signModeDirectAuxHandler) GetSignBytes(
return nil, errorsmod.Wrapf(sdkerrors.ErrInvalidRequest, "got empty address in %s handler", signingtypes.SignMode_SIGN_MODE_DIRECT_AUX)
}

feePayer := protoTx.FeePayer()
payer := protoTx.FeePayer()

feepayer := sdk.AccAddress(payer)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: for simplicity, we could just do sdk.AccAddress(payer).String() below and revert the variable change above.


// Fee payer cannot use SIGN_MODE_DIRECT_AUX, because SIGN_MODE_DIRECT_AUX
// does not sign over fees, which would create malleability issues.
addrBz, err := sdk.AccAddressFromBech32(data.Address)
if err != nil {
return nil, err
}

if bytes.Equal(feePayer, addrBz) {
return nil, sdkerrors.ErrUnauthorized.Wrapf("fee payer %s cannot sign with %s", feePayer, signingtypes.SignMode_SIGN_MODE_DIRECT_AUX)
if strings.EqualFold(feepayer.String(), data.Address) {
return nil, sdkerrors.ErrUnauthorized.Wrapf("fee payer %s cannot sign with %s", feepayer, signingtypes.SignMode_SIGN_MODE_DIRECT_AUX)
}

signDocDirectAux := types.SignDocDirectAux{
Expand Down
2 changes: 1 addition & 1 deletion x/auth/tx/direct_aux_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@ func TestDirectAuxHandler(t *testing.T) {

t.Log("verify fee payer cannot use SIGN_MODE_DIRECT_AUX")
_, err = modeHandler.GetSignBytes(signingtypes.SignMode_SIGN_MODE_DIRECT_AUX, feePayerSigningData, txBuilder.GetTx())
require.EqualError(t, err, fmt.Sprintf("fee payer %s cannot sign with %s: unauthorized", []byte(feePayerAddr), signingtypes.SignMode_SIGN_MODE_DIRECT_AUX))
require.EqualError(t, err, fmt.Sprintf("fee payer %s cannot sign with %s: unauthorized", feePayerAddr.String(), signingtypes.SignMode_SIGN_MODE_DIRECT_AUX))

t.Log("verify GetSignBytes with generating sign bytes by marshaling signDocDirectAux")
signBytes, err := modeHandler.GetSignBytes(signingtypes.SignMode_SIGN_MODE_DIRECT_AUX, signingData, txBuilder.GetTx())
Expand Down