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: Add TrackBeforeSend , BlockBeforeSend hooks. Deprecate BeforeSend hook #421

Merged
merged 2 commits into from
Mar 9, 2023

Conversation

mattverse
Copy link
Member

What is the purpose of the change

This PR adds TrackBeforeSend hook and BlockBeforeSend hook, and deprecates BeforeSend hook.
Each hook, respectively would call the hook that has been registered from a different module.
The difference between the two new hooks being introduced is that TrackBeforesend hook does not have the ability to cause any effect, as it does not emit errors. Meanwhile, BlockBeforeSend does emit errors, allowing connected hooks to stop and block the send.

Additional method SendCoinsWithoutBlockHook has also been added along with the two hooks, as for module <> module transfers, we want to ensure it does not get blocked by external hooks.

Brief Changelog

Add TrackBeforeSend , BlockBeforeSend hooks. Deprecate BeforeSend hook

Testing and Verifying

This change adds tests

Documentation and Release Note

  • Does this pull request introduce a new feature or user-facing behavior changes? (yes / no)
  • Is a relevant changelog entry added to the Unreleased section in CHANGELOG.md? (yes / no)
  • How is the feature or change documented? (not applicable / specification (x/<module>/spec/) / Osmosis docs repo / not documented)

@mattverse mattverse requested review from a team and nicolaslara March 7, 2023 08:02
@mattverse mattverse changed the title Add TrackBeforeSend , BlockBeforeSend hooks. Deprecate BeforeSend hook feat: Add TrackBeforeSend , BlockBeforeSend hooks. Deprecate BeforeSend hook Mar 7, 2023
x/bank/keeper/hooks.go Outdated Show resolved Hide resolved
@@ -237,12 +238,14 @@ func (k BaseKeeper) UndelegateCoins(ctx sdk.Context, moduleAccAddr, delegatorAdd
return sdkerrors.Wrap(sdkerrors.ErrInvalidCoins, amt.String())
}

// call the BeforeSend hooks
err := k.BeforeSend(ctx, moduleAccAddr, delegatorAddr, amt)
// call the TrackBeforeSend hooks and the BlockBeforeSend hooks

Choose a reason for hiding this comment

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

Q unrelated to this PR: Do we know why Delegate/UndelegateCoins manages the coins directly instead of using SendCoins under the hood? Seems like it would be a better abstraction and the hooks could just be in SendCoins

Copy link
Member Author

Choose a reason for hiding this comment

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

potentially because of security issue, I have no ide. Good point tho

Copy link

@nicolaslara nicolaslara left a comment

Choose a reason for hiding this comment

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

left some minor comments, but this LGTM. I'm not a fan of the imperative in the function names here ("track", "block") as it seems like we're doing the action when that gets called, but couldn't come up with good alternatives. My best idea is "tracking" and "blocking" but still not great

@mattverse mattverse merged commit 489745d into osmosis-main Mar 9, 2023
@mattverse mattverse deleted the mattverse/bank-hooks branch March 9, 2023 09:00
mattverse added a commit that referenced this pull request Mar 13, 2023
…oreSend` hook (#421)

* Add separated hooks for bank send

* Update x/bank/keeper/hooks.go

Co-authored-by: Nicolas Lara <[email protected]>

---------

Co-authored-by: Nicolas Lara <[email protected]>
czarcas7ic pushed a commit that referenced this pull request Oct 4, 2023
…oreSend` hook (#421)

* Add separated hooks for bank send

* Update x/bank/keeper/hooks.go

Co-authored-by: Nicolas Lara <[email protected]>

---------

Co-authored-by: Nicolas Lara <[email protected]>
czarcas7ic pushed a commit that referenced this pull request Oct 30, 2023
…oreSend` hook (#421)

* Add separated hooks for bank send

* Update x/bank/keeper/hooks.go

Co-authored-by: Nicolas Lara <[email protected]>

---------

Co-authored-by: Nicolas Lara <[email protected]>
czarcas7ic pushed a commit that referenced this pull request Nov 7, 2023
…oreSend` hook (#421)

* Add separated hooks for bank send

* Update x/bank/keeper/hooks.go

Co-authored-by: Nicolas Lara <[email protected]>

---------

Co-authored-by: Nicolas Lara <[email protected]>
czarcas7ic pushed a commit that referenced this pull request May 9, 2024
…oreSend` hook (#421)

* Add separated hooks for bank send

* Update x/bank/keeper/hooks.go

Co-authored-by: Nicolas Lara <[email protected]>

---------

Co-authored-by: Nicolas Lara <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
Status: Done
Development

Successfully merging this pull request may close these issues.

2 participants