-
Notifications
You must be signed in to change notification settings - Fork 199
Initializable to have onlyInitialized modifier and isInitialized function #1541
Comments
Hi @3sGgpQ8H ! Thanks for the suggestion, it is really appreciated. The project owner should review your suggestion during the next week. Please wait until we have discussed this idea before writing any code or submitting a Pull Request, so we can go through the design beforehand. We don’t want you to waste your time! |
Thank you for the suggestion @3sGgpQ8H. I'm not sure there exists a scenario where one would want to allow a function call before initialization. The way we currently enforce that no functions are called before initialization is that the initializer is called in the same transaction that creates the proxy. This is what we would recommend to anyone using proxies even if they don't use our tools specifically. In that scenario, manually adding the Can you share your specific use case so we can evaluate in context whether this is something that more people may find useful? So far I don't see us wanting to add the feature. |
If this is enforced by |
Interesting questions! For initializer functions I don't see how it would be possible for There is an alternative to initializer functions that can guarantee exactly-once initialization: initializer contracts, as I proposed them in my article Towards Frictionless Upgradeability. However, this idea was never implemented in practice (that I know of) because it's more complicated. The gist of the idea is that the constructor of I encourage you to experiment with the approach if you're interested. |
But Proxy anyway has to know initializer selector to be able to call it on deployment. |
Currently, storage variable
initialized
is declared asprivate
inInitializable
smart contract.It is common situation, that some functions of an initializable smart contract (probably all the function except for
initialize
) may only be called when smart contract is properly initialized. However, currently there is no easy way to enforce this. I suggest to add two things toInitializable
smart contract:onlyInitialized
modifier that will revert unless smart contract is initialized, and internal functionisInitialized
that will returntrue
in case smart contract is initialized, andfalse
otherwise.These simple improvements will make
Initializable
smart contract much more useful and should not break backward compatibility.The text was updated successfully, but these errors were encountered: