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(bank): send-hooks #14660

Closed
wants to merge 5 commits into from

Conversation

neverDefined
Copy link

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...

  • included the correct type prefix in the PR title
  • added ! to 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
  • followed the guidelines for building modules
  • included the necessary unit and integration tests
  • added a changelog entry to CHANGELOG.md
  • included comments for documenting Go code
  • updated the relevant documentation or specification
  • reviewed "Files changed" and left comments if necessary
  • 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.

I have...

  • confirmed the correct type prefix in the PR title
  • confirmed ! in the type prefix if API or client breaking change
  • confirmed all author checklist items have been addressed
  • reviewed state machine logic
  • reviewed API design and naming
  • reviewed documentation is accurate
  • reviewed tests and test coverage
  • manually tested (if applicable)

@neverDefined neverDefined changed the title send-hooks feat(bank): send-hooks Jan 17, 2023
@alexanderbez
Copy link
Contributor

Is there an issue that describes the who/what/why?

@neverDefined
Copy link
Author

neverDefined commented Jan 19, 2023

Hey Alexander,

Who:
Im a developer on Berachain and some other defi DAOS.

Why:

  • Hooks at the bank level are the only way that App-chain developers can listen in on sendCoins actions and preform actions. By using the same light implementations as the staking-module its a no-op for developers that don't need them and makes the development of ones that need them much easier.

How:

  • Devs can implement the SendHooks interface in any other module, and register it using the bank.SetHooks method. The slice of sendHooks then will be ran after every sendCoins call.

@@ -301,6 +301,11 @@ func NewSimApp(
BlockedAddresses(),
authtypes.NewModuleAddress(govtypes.ModuleName).String(),
)
app.BankKeeper.SetHooks(
Copy link
Member

@julienrbrt julienrbrt Jan 19, 2023

Choose a reason for hiding this comment

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

Copy link
Author

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.

Copy link
Member

@julienrbrt julienrbrt Jan 19, 2023

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 :)

Copy link
Author

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

@alexanderbez
Copy link
Contributor

@neverDefined can you please open that in an issue :p

@neverDefined
Copy link
Author

@neverDefined can you please open that in an issue :p

made an issue: #14701

@SpicyLemon
Copy link
Collaborator

This looks related: #14224

@neverDefined
Copy link
Author

This looks related: #14224

Would it make sense to merge the features, and run them right after the restrictions.

@SpicyLemon
Copy link
Collaborator

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 {
Copy link
Collaborator

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.

Copy link
Author

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

@tac0turtle
Copy link
Member

talked with @ValarDragon and there are edge cases to think through here. Osmosis did an audit on this work but never merged it

@itsdevbear
Copy link
Contributor

@neverDefined follow up Q's

@neverDefined
Copy link
Author

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.

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.

  • re the sepiration of the hooks, for sure in most use cases, post send hooks make the most sense, but could be some niche use cases, such as a module needing to "deregister" from a service, creating a better binding from sender to logic.

@neverDefined
Copy link
Author

l ,

talked with @ValarDragon and there are edge cases to think through here. Osmosis did an audit on this work but never merged it

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.

@itsdevbear
Copy link
Contributor

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.

@tac0turtle
Copy link
Member

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.

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

Successfully merging this pull request may close these issues.

6 participants