-
Notifications
You must be signed in to change notification settings - Fork 3.7k
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(bank): send-hooks #14660
feat(bank): send-hooks #14660
Conversation
Is there an issue that describes the who/what/why? |
Hey Alexander, Who: Why:
How:
|
@@ -301,6 +301,11 @@ func NewSimApp( | |||
BlockedAddresses(), | |||
authtypes.NewModuleAddress(govtypes.ModuleName).String(), | |||
) | |||
app.BankKeeper.SetHooks( |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If this proposal is accepted, the app wiring configuration should be done for bank hooks.
You can look at staking for guidance:
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
sounds good wanted to get the teams opinion on the changes first. implementing that now.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Of course, this is why I commented:
If this proposal is accepted
Don't do it already, just in case :)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
lmk when and if the team is looking to move forward with this ser. Have a good weekend sers
@neverDefined can you please open that in an issue :p |
made an issue: #14701 |
This looks related: #14224 |
Would it make sense to merge the features, and run them right after the restrictions. |
I haven't really looked into this PR, but on the surface, this one and that one heavily overlap and have the same goal. The SDK team is having some discussions related to these things, but I'm not privy to them. #14224 is awaiting some decisions from those discussion. What's a use case for needing separate pre and post send hooks? A failure from either would prevent the send. #14224 is analogous to the pre-send hooks in here. I know that a lot of optimization has gone into bank sends since it's a crucial and often-used blockchain feature; keeping gas costs (and what they represent) low is desirable. It'd be good to keep things a simple as possible. |
@@ -141,6 +163,11 @@ func (k BaseSendKeeper) InputOutputCoins(ctx sdk.Context, inputs []types.Input, | |||
return err | |||
} | |||
|
|||
// Run send hooks if present. | |||
if err := k.Hooks().BeforeSendCoins(ctx, inAddress, inAddress, in.Coins); err != nil { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Providing the same to and from addresses like this, is not desirable. Same goes for the outputs loop below.
At best, the hook will think nothing is happening, but these calls are also telling lies. This call is telling the hook that in.Coins
is going to be added to inAddress
. In the outputs loop, it tells the hook that out.Coins
is being removed from the outAddress
. Neither are true.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
yup first implem was to get the conversation going, probably need to sync the loop from the same index so you have n instead of 2n
talked with @ValarDragon and there are edge cases to think through here. Osmosis did an audit on this work but never merged it |
@neverDefined follow up Q's |
The real reason for send hooks is as you said, sending coins is one of the most used methods in the sdk, hence having a simple api to run logic that is closely tied with that feature could make sense.
|
l ,
yea definitely touches the core the of the sdk. But think the use for other app chains like perp-exchanges, dex's can really help with integrating some interesting features cleanly. |
Not having an "ontransfer" makes it difficult for using native coins for defi type composability, and forces chain developers to use non native solutions to implement this, causing additional complexity and eventually token / liquidity fragmentation. Our main use case is to allow for rewards to be streamed to the tokenized vaults, in which our receipt tokens are actually native denoms. (We have a vault module that effectively wraps a token factory). For passive accounting to work, if a user transfers the receipt token to another address, we need to trigger them claiming any pending rewards from the vault. This is a very common use case in Ethereum DeFi. |
we need more discussion on this and most likely a design doc. I talked with osmosis about this change and they said there some gotchas with adding this feature. We should document and make sure the trade offs are something we are willing to accept. Lets continue the discussion in the issue. #14701. Also would love to bring this discussion to the next community call. |
Description
This PR implements before/after send hooks to the BaseSendKeeper. Other modules will be able to register hooks to this module.
Closes: #XXXX
x/bank/send.go
x/bank/types/hooks.go
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...
!
to the type prefix if API or client breaking changeCHANGELOG.md
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.
I have...
!
in the type prefix if API or client breaking change