Open dmoka opened 1 week ago
User @dmoka, please sign the CLA here.
My labels are the following, kindly request to add them, thank you.
Since the unit type offers a default none behaviour, therefore no testing is required in polkadot-sdk. It has to be tested in the downstream parachains where custom logic might be added.
In the Hydration parachain, we want to inject custom functionalities into all utility batch calls, both before and after their execution.
Could you give some more details on what you are injecting?
In the Hydration parachain, we want to inject custom functionalities into all utility batch calls, both before and after their execution.
Could you give some more details on what you are injecting?
Within Hydration, we decided to implement a unified Swapped event emitted by all our AMMs. For each event, we need to understand its context—whether it originates from our DCA, Router, ICE, or Utility Batch. To achieve this, we need to track the context, and this tracking logic would be injected both before and after Utility batch calls.
Here is the exact code that we want to inject, we are already doing this in a PR with the fork of polkadot-sdk
Description
In the Hydration parachain, we want to inject custom functionalities into all utility batch calls, both before and after their execution. We believe this feature could be useful for other parachains as well, where, by default, no behavior exists for custom functionalities.
Integration
This PR introduces custom hooks to the Polkadot SDK, allowing parachains to configure and extend the SDK’s behavior according to their specific requirements. The changes include:
Custom Hook Integration:
Downstream projects can now define custom hooks for specific functionality within the SDK. These hooks can be registered during the initialization phase of the parachain.
Configuration Details:
Hooks should be defined in a configuration object and passed to the relevant utlity pallet config setup implementation.
Example usage:
Backward Compatibility:
These changes are fully backward compatible. Parachains that do not implement the new hooks will continue to operate as before without any modifications.
Testing Recommendations:
Projects should test their custom hooks thoroughly to ensure the expected behavior when integrated with the Polkadot SDK. By providing these hooks, parachains can gain finer control over SDK functionalities while maintaining flexibility for future updates.
Review Notes
The
BatchPreHook
is invoked before every batch call (batch, batch_all, and force_batch). It is triggered immediately after ensuring the origin.The
BatchPostHook
is invoked after every batch call (batch, batch_all, and force_batch). It is triggered right before collecting the weights to be returned.To establish a default behavior, one can set the unit type in the configuration, which simply returns an Ok result, so doing nothing:
Checklist
T
required)You can remove the "Checklist" section once all have been checked. Thank you for your contribution!
✄ -----------------------------------------------------------------------------