Middleware Wiring Improvements #5814
Labels
30-middleware
change: api breaking
Issues or PRs that break Go API (need to be release in a new major version)
core
needs discussion
Issues that need discussion before they can be worked on
Milestone
Summary
The proposed changes aim to simplify the middleware wiring process significantly, making it more intuitive and less error-prone, thereby improving the overall reliability and security of IBC middleware integration. The proposal recommends introducing a new helper called
IBCStackBuilder
.Problem
The current mechanism for integrating IBC middleware is complex and prone to errors, leading to difficulties in understanding the middleware stack, which subsequently results in bugs and security vulnerabilities. This complexity stems from the need to intertwine two distinct stacks: the IBC module stack and the ICS4Wrapper stack. The latter is often managed by a module's keeper rather than the module itself, complicating the integration process. Furthermore, the necessity to wire these stacks in reverse order complicates their integration during module initialization.
Proposal
This proposal suggests a syntactic enhancement aimed at simplifying the wiring process of IBC middlewares without altering their underlying architecture. It introduces a new construct, the
IBCStackBuilder
, designed to streamline the middleware integration process. The proposed API enables a straightforward layering of middlewares, culminating in the base application, as demonstrated below:To facilitate this approach, several API modifications are proposed:
IBCModule
andIBCMiddleware
interfaces to accept anICS4Wrapper
during initialization, which eliminates circular dependencies. Instead, aSetICS4Wrapper
method will be added to theIBCModule
interface, allowing for the post-initialization setting of the middleware. (Alternatively, this could be an optional interface that the module can implement to be middleware compatible.)This will allow the
IBCStackBuilder
to wire the ICS4Wrapper after the IBC module has been initialized.SetUnderlyingModule
method to theIBCMiddleware
interface. This allows for the setting of the underlying application post-initialization, thus supporting middleware initializayion without the underlying application.IBCStackBuilder
is provided, outlining methods for adding middlewares, setting the base module, and building the final IBC module stack. This builder pattern facilitates a clear and orderly assembly of the middleware stack.ICS4Wrapper
from the constructors of keepers and modules, streamlining their instantiation and enhancing maintainability. For instance, see the proposed changes to theNewKeeper
function in thetransfer
module:The text was updated successfully, but these errors were encountered: