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

feat: v0.45.16 send restriction #173

Merged
merged 9 commits into from
Sep 11, 2024

Conversation

poorphd
Copy link

@poorphd poorphd commented Sep 4, 2024

Description

This PR contains send restriction features which can be enabled when initialize BankKeeper.
The basic functionality is implemented exactly as in Cosmos SDK v0.50, but while the existing implementation only applied restrictions to SendCoins, this PR has been modified to apply restrictions to DelegateCoins and UndelegateCoins as well.

Closes: #XXXX


Author Checklist

All items are required. Please add a note to the item if the item is not applicable and
please add links to any relevant follow up issues.

I have...

  • included the correct type prefix in the PR title, you can find examples of the prefixes below:
  • confirmed ! in the type prefix if API or client breaking change
  • targeted the correct branch (see PR Targeting)
  • provided a link to the relevant issue or specification
  • reviewed "Files changed" and left comments if necessary
  • included the necessary unit and integration tests
  • added a changelog entry to CHANGELOG.md
  • updated the relevant documentation or specification, including comments for documenting Go code
  • confirmed all CI checks have passed

Reviewers Checklist

All items are required. Please add a note if the item is not applicable and please add
your handle next to the items reviewed if you only reviewed selected items.

Please see Pull Request Reviewer section in the contributing guide for more information on how to review a pull request.

I have...

  • confirmed the correct type prefix in the PR title
  • confirmed all author checklist items have been addressed
  • reviewed state machine logic, API design and naming, documentation is accurate, tests and test coverage

@poorphd poorphd changed the title V0.45.16 send restriction feat: v0.45.16 send restriction Sep 4, 2024
@poorphd poorphd self-assigned this Sep 9, 2024
@poorphd poorphd marked this pull request as ready for review September 9, 2024 01:55
@@ -105,6 +115,15 @@ func (k BaseSendKeeper) InputOutputCoins(ctx sdk.Context, inputs []types.Input,
return err
}

for _, in := range inputs {
Copy link
Member

Choose a reason for hiding this comment

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

This could be inefficient with a nested for-loop. If the checks for the from and to addresses in sendCoinsRestrictionFn are independent, wouldn't it be possible to simplify it into a one-dimensional check by validating only the from address for inputs and only the to address for outputs?

(need to check if it is possible to handle an empty "from" or "to" address without errors, and add unit tests accordingly)

Copy link
Author

Choose a reason for hiding this comment

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

Due to the bypass functionality for module accounts, it is deemed difficult to independently assess input addresses and output addresses.
However, an incorrect logic has been discovered in the current code where the restriction application is determined after subUnlockedCoins, so I will modify that part.

x/bank/keeper/keeper.go Show resolved Hide resolved
Copy link

@zsystm zsystm left a comment

Choose a reason for hiding this comment

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

@poorphd
I have left comments only for test code.
Core logics look great to me.

x/bank/keeper/keeper_test.go Outdated Show resolved Hide resolved
x/bank/keeper/keeper_test.go Outdated Show resolved Hide resolved
x/bank/keeper/keeper_test.go Outdated Show resolved Hide resolved
x/bank/keeper/keeper_test.go Outdated Show resolved Hide resolved
@zsystm
Copy link

zsystm commented Sep 9, 2024

@poorphd

  • Please fix the CI error also.

@poorphd
Copy link
Author

poorphd commented Sep 10, 2024

@poorphd

  • Please fix the CI error also.

The existing codebase had broken CI. This should be fixed in a separate PR.

Copy link

@zsystm zsystm left a comment

Choose a reason for hiding this comment

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

LGTM

}

// Check restrictions between the input address and the output address
outAddress, err = k.sendCoinsRestrictionFn(ctx, inAddress, outAddress, out.Coins)
Copy link
Member

Choose a reason for hiding this comment

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

The sum of the coins in the inputs and the sum of the coins in the outputs are equal, but each Coins in the input and output is independent. Therefore, using output.Coins as it is now leads to validation against an unintended amount.

Currently, we do not plan to deeply use the amount in the restriction function, so it's not a major issue. However, in the future, if we do use it, it may behave differently from what was intended. It might be a good idea to leave a TODO or comment in the code as a reminder.

Copy link
Author

Choose a reason for hiding this comment

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

Added TODO in the code.

Copy link
Collaborator

Choose a reason for hiding this comment

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

[Suggestion] How about seperate SendFromRestrictionFn and SendToRestrictionFn ?
Considering InputOutputCoins, it looks better logic to apply "from restriction" and "to restriction".

In minting case, it is better to use existing MintingRestrictionFn.

In burning case, it is allowed regardless of from or to.

If it is required to block a specific sender from sending to a specific receiver, I thnik that restriction function should not be applied to the InputOutputCoins function.

@dongsam
Copy link
Member

dongsam commented Sep 10, 2024

I remember hearing that in the previous localnet end-to-end test, even when restrictions occurred, errors were not exposed. Do you know if that issue has been resolved? Regardless of whether it's been fixed, it would be ideal if the test code could verify the occurrence of errors.

@poorphd
Copy link
Author

poorphd commented Sep 11, 2024

I remember hearing that in the previous localnet end-to-end test, even when restrictions occurred, errors were not exposed. Do you know if that issue has been resolved? Regardless of whether it's been fixed, it would be ideal if the test code could verify the occurrence of errors.

The issue is resolved. If the transaction failed due to the restriction, the raw_log contains the error message.
Latest test codes already check expected errors. https://github.com/b-harvest/cosmos-sdk/blob/v0.45.16/SendRestiction/x/bank/keeper/keeper_test.go#L1273-L1277

@poorphd poorphd merged commit 531d7ff into basechain/abci1.0/develop Sep 11, 2024
24 of 30 checks passed
@@ -1231,6 +1231,475 @@ func (suite *IntegrationTestSuite) TestMintCoinRestrictions() {
}
}

func (suite *IntegrationTestSuite) TestSendRestrictions() {
type BankSendRestrictionFn func(ctx sdk.Context, fromAddr, toAddr sdk.AccAddress, amt sdk.Coins) (sdk.AccAddress, error)
Copy link
Collaborator

Choose a reason for hiding this comment

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

[Suggestion] How about using existing type SendRestrictionFn in keeper.go

Is there any reason to define same type in test code?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants