# Why keep "\_\_Ownable\_init" beside "\_\_Ownable\_init\_unchained"?

**URL:** <https://forum.openzeppelin.com/t/why-keep-ownable-init-beside-ownable-init-unchained/25579>\
**Category:** Upgrades\
**Created:** [March 3, 2022, 12:23am UTC](https://forum.openzeppelin.com/t/why-keep-ownable-init-beside-ownable-init-unchained/25579 "2022-03-03T00:23:44Z")\
**Posts on this page:** 14\
**Page:** 1

<div class="post-metadata">

**Author:** ![PaulRBerg](https://sea2.discourse-cdn.com/flex022/user_avatar/forum.openzeppelin.com/paulrberg/32/14286_2.png) [@PaulRBerg](https://forum.openzeppelin.com/u/PaulRBerg)\
**Post date:** [March 3, 2022, 12:23am UTC](https://forum.openzeppelin.com/t/why-keep-ownable-init-beside-ownable-init-unchained/25579/1 "2022-03-03T00:23:44Z")

</div>

Hi, I was looking at the [\_\_Ownable\_init](https://github.com/OpenZeppelin/openzeppelin-contracts-upgradeable/blob/20380ee699406211ae88c4edd11b0af87c8abdd6/contracts/access/OwnableUpgradeable.sol#L29-L31) function defined in the `OwnableUpgradeable` contract, and I couldn't understand why it is needed at all.

As far as I can tell, only the `__Ownable_init_unchained` method is called in the other contracts that inherit from `OwnableUpgradeable` in this repository.

So why keep the other method in the contract? Backwards compatibility?

---

<div class="post-metadata">

**Author:** ![ericglau](https://sea2.discourse-cdn.com/flex022/user_avatar/forum.openzeppelin.com/ericglau/32/15149_2.png) [@ericglau](https://forum.openzeppelin.com/u/ericglau)\
**Post date:** [March 3, 2022, 4:19pm UTC](https://forum.openzeppelin.com/t/why-keep-ownable-init-beside-ownable-init-unchained/25579/2 "2022-03-03T16:19:21Z")

</div>

Hi @PaulRBerg, the `_init` functions have linearized calls to parent initializers, while `_init_unchained` functions do not. There is some documentation about this here: [https://docs.openzeppelin.com/contracts/4.x/upgradeable#multiple-inheritance](https://docs.openzeppelin.com/contracts/4.x/upgradeable#multiple-inheritance)

In the case of `OwnableUpgradable`, there just happens to be no parent initializers to call. But the expected convention is for developers to just use the `_init` functions in the libraries that they are using directly, and those will behave similar to constructors.

---

<div class="post-metadata">

**Author:** ![PaulRBerg](https://sea2.discourse-cdn.com/flex022/user_avatar/forum.openzeppelin.com/paulrberg/32/14286_2.png) [@PaulRBerg](https://forum.openzeppelin.com/u/PaulRBerg)\
**Post date:** [March 3, 2022, 5:31pm UTC](https://forum.openzeppelin.com/t/why-keep-ownable-init-beside-ownable-init-unchained/25579/3 "2022-03-03T17:31:48Z")

</div>

Great explanation, thanks @ericglau.

Now, just to double-check that I got this right. If `OwnableUpgradeable` had a parent initializer to call, it would call the `_init_unchained` function of that hypothetical parent contract, wouldn't it?

---

<div class="post-metadata">

**Author:** ![ericglau](https://sea2.discourse-cdn.com/flex022/user_avatar/forum.openzeppelin.com/ericglau/32/15149_2.png) [@ericglau](https://forum.openzeppelin.com/u/ericglau)\
**Post date:** [March 3, 2022, 7:10pm UTC](https://forum.openzeppelin.com/t/why-keep-ownable-init-beside-ownable-init-unchained/25579/4 "2022-03-03T19:10:06Z")

</div>

> [@PaulRBerg](#):
>
> If `OwnableUpgradeable` had a parent initializer to call, it would call the `_init_unchained` function of that hypothetical parent contract, wouldn't it?

Yes, the `_init` functions internally call `_init_unchained` functions.

---

<div class="post-metadata">

**Author:** ![maxareo](https://sea2.discourse-cdn.com/flex022/user_avatar/forum.openzeppelin.com/maxareo/32/11606_2.png) [@maxareo](https://forum.openzeppelin.com/u/maxareo)\
**Post date:** [April 11, 2022, 6:10am UTC](https://forum.openzeppelin.com/t/why-keep-ownable-init-beside-ownable-init-unchained/25579/5 "2022-04-11T06:10:37Z")

</div>

Hey @ericglau, I think I understand the paragraph in the link conceptually, but I don't find an example that `_init` does call parents' initializers. For example, for [this](https://github.com/OpenZeppelin/openzeppelin-contracts-upgradeable/blob/20380ee699406211ae88c4edd11b0af87c8abdd6/contracts/access/AccessControlUpgradeable.sol#L51) line in the contract `AccessControlUpgradeable`, the `__AccessControl_init` function does not call any other `_init` functions. Am I missing anything? Thanks.

---

<div class="post-metadata">

**Author:** ![ericglau](https://sea2.discourse-cdn.com/flex022/user_avatar/forum.openzeppelin.com/ericglau/32/15149_2.png) [@ericglau](https://forum.openzeppelin.com/u/ericglau)\
**Post date:** [April 11, 2022, 1:49pm UTC](https://forum.openzeppelin.com/t/why-keep-ownable-init-beside-ownable-init-unchained/25579/6 "2022-04-11T13:49:25Z")

</div>

Hi @maxareo, [here](https://github.com/OpenZeppelin/openzeppelin-contracts-upgradeable/blob/cf68a02973de4a8745dc457a82d48ce238419980/contracts/utils/escrow/RefundEscrowUpgradeable.sol#L38) is an example where an `_init` function calls `_init_unchained`. In this example it calls it's parent's parent's `_init_unchained` and then its own.

---

<div class="post-metadata">

**Author:** ![maxareo](https://sea2.discourse-cdn.com/flex022/user_avatar/forum.openzeppelin.com/maxareo/32/11606_2.png) [@maxareo](https://forum.openzeppelin.com/u/maxareo)\
**Post date:** [April 11, 2022, 2:32pm UTC](https://forum.openzeppelin.com/t/why-keep-ownable-init-beside-ownable-init-unchained/25579/7 "2022-04-11T14:32:46Z")

</div>

Thanks @ericglau. It seems a bit arbitrary to me. Is there any rules with `_init` functions? Please take a look at the snippet below. Should the `_init` functions for all inherited contracts be included in the `initialize()` function?

```auto
contract UpgradeableTestToken is ContextUpgradeable, OwnableUpgradeable, UUPSUpgradeable, ERC20Upgradeable {
    function initialize() external initializer {
        __Ownable_init_unchained();
        __UUPSUpgradeable_init();
        __ERC20_init("Test Token2", "TT2");
    }

    function _authorizeUpgrade(address newImplementation) internal override onlyOwner {}
}

```

---

<div class="post-metadata">

**Author:** ![kiko](https://sea2.discourse-cdn.com/flex022/user_avatar/forum.openzeppelin.com/kiko/32/13156_2.png) [@kiko](https://forum.openzeppelin.com/u/kiko)\
**Post date:** [April 11, 2022, 3:12pm UTC](https://forum.openzeppelin.com/t/why-keep-ownable-init-beside-ownable-init-unchained/25579/8 "2022-04-11T15:12:38Z")

</div>

Would also like to expand this discussion to the [DiamondStorage](https://github.com/GeniusVentures/openzeppelin-contracts-diamond/blob/main/contracts/access/OwnableUpgradeable.sol) equivalent (which will be used in 5.x I believe).

With this pattern, there is also no constructor, so initialize needs to be called manually. So if you wanted to make an upgradable Governor, would this be the appropriate thing to do:

```auto
// SPDX-License-Identifier: GPL-3.0-only
pragma solidity ^0.8.9;

import {ERC20Upgradeable} from "@gnus.ai/contracts-upgradeable-diamond/token/ERC20/ERC20Upgradeable.sol";
import {ERC20PermitUpgradeable} from "@gnus.ai/contracts-upgradeable-diamond/token/ERC20/extensions/draft-ERC20PermitUpgradeable.sol";
import {ERC20VotesUpgradeable} from "@gnus.ai/contracts-upgradeable-diamond/token/ERC20/extensions/ERC20VotesUpgradeable.sol";

/// @dev EIP-20 token name: "FUNToken"
/// @dev EIP-20 token symbol: "FUN"
/// @dev EIP-20 token decimals: 18
contract FUNTokenFacet is ERC20Upgradeable, ERC20PermitUpgradeable, ERC20VotesUpgradeable {
    function initialize() public payable {
        __ERC20_init("FUNToken", "FUN");
        __ERC20Permit_init("FUNToken");
        __ERC20Votes_init_unchained(); // Do we need this line?
    }

    function _afterTokenTransfer(
        address from,
        address to,
        uint256 amount
    ) internal override(ERC20Upgradeable, ERC20VotesUpgradeable) {
        super._afterTokenTransfer(from, to, amount);
    }

    function _mint(address to, uint256 amount)
        internal
        override(ERC20Upgradeable, ERC20VotesUpgradeable)
    {
        super._mint(to, amount);
    }

    function _burn(address account, uint256 amount)
        internal
        override(ERC20Upgradeable, ERC20VotesUpgradeable)
    {
        super._burn(account, amount);
    }
}

```

But it's also really not clear if `__ERC20Votes_init_unchained()` is needed here so would be great to get guidance there.

---

<div class="post-metadata">

**Author:** ![ericglau](https://sea2.discourse-cdn.com/flex022/user_avatar/forum.openzeppelin.com/ericglau/32/15149_2.png) [@ericglau](https://forum.openzeppelin.com/u/ericglau)\
**Post date:** [April 12, 2022, 3:45pm UTC](https://forum.openzeppelin.com/t/why-keep-ownable-init-beside-ownable-init-unchained/25579/9 "2022-04-12T15:45:49Z")

</div>

> [@maxareo](#):
>
> Thanks @ericglau. It seems a bit arbitrary to me. Is there any rules with `_init` functions? Please take a look at the snippet below. Should the `_init` functions for all inherited contracts be included in the `initialize()` function?
> 
> ```auto
> contract UpgradeableTestToken is ContextUpgradeable, OwnableUpgradeable, UUPSUpgradeable, ERC20Upgradeable {
> function initialize() external initializer {
> __Ownable_init_unchained();
> __UUPSUpgradeable_init();
> __ERC20_init("Test Token2", "TT2");
> }
> 
> function _authorizeUpgrade(address newImplementation) internal override onlyOwner {}
> }
> 
> ```

In general you should only need to call the `_init` functions, not `_init_unchained`. We recommend to call the `_init` functions of all direct parents. So in your example, use `__Ownable_init()`

---

<div class="post-metadata">

**Author:** ![ericglau](https://sea2.discourse-cdn.com/flex022/user_avatar/forum.openzeppelin.com/ericglau/32/15149_2.png) [@ericglau](https://forum.openzeppelin.com/u/ericglau)\
**Post date:** [April 12, 2022, 4:01pm UTC](https://forum.openzeppelin.com/t/why-keep-ownable-init-beside-ownable-init-unchained/25579/10 "2022-04-12T16:01:20Z")

</div>

> [@kiko](#):
>
> Would also like to expand this discussion to the [DiamondStorage](https://github.com/GeniusVentures/openzeppelin-contracts-diamond/blob/main/contracts/access/OwnableUpgradeable.sol) equivalent (which will be used in 5.x I believe).
> 
> With this pattern, there is also no constructor, so initialize needs to be called manually. So if you wanted to make an upgradable Governor, would this be the appropriate thing to do:
> 
> ```auto
> // SPDX-License-Identifier: GPL-3.0-only
> pragma solidity ^0.8.9;
> 
> import {ERC20Upgradeable} from "@gnus.ai/contracts-upgradeable-diamond/token/ERC20/ERC20Upgradeable.sol";
> import {ERC20PermitUpgradeable} from "@gnus.ai/contracts-upgradeable-diamond/token/ERC20/extensions/draft-ERC20PermitUpgradeable.sol";
> import {ERC20VotesUpgradeable} from "@gnus.ai/contracts-upgradeable-diamond/token/ERC20/extensions/ERC20VotesUpgradeable.sol";
> 
> /// @dev EIP-20 token name: "FUNToken"
> /// @dev EIP-20 token symbol: "FUN"
> /// @dev EIP-20 token decimals: 18
> contract FUNTokenFacet is ERC20Upgradeable, ERC20PermitUpgradeable, ERC20VotesUpgradeable {
> function initialize() public payable {
> __ERC20_init("FUNToken", "FUN");
> __ERC20Permit_init("FUNToken");
> __ERC20Votes_init_unchained(); // Do we need this line?
> }
> 
> function _afterTokenTransfer(
> address from,
> address to,
> uint256 amount
> ) internal override(ERC20Upgradeable, ERC20VotesUpgradeable) {
> super._afterTokenTransfer(from, to, amount);
> }
> 
> function _mint(address to, uint256 amount)
> internal
> override(ERC20Upgradeable, ERC20VotesUpgradeable)
> {
> super._mint(to, amount);
> }
> 
> function _burn(address account, uint256 amount)
> internal
> override(ERC20Upgradeable, ERC20VotesUpgradeable)
> {
> super._burn(account, amount);
> }
> }
> 
> ```
> 
> But it's also really not clear if `__ERC20Votes_init_unchained()` is needed here so would be great to get guidance there.

In this case that function is empty so it doesn't do anything.

If using openzeppelin-contracts-upgradeable, you could call `__ERC20Votes_init()` (which also doesn't do anything in this case either, but is provided for consistency)

---

<div class="post-metadata">

**Author:** ![maxareo](https://sea2.discourse-cdn.com/flex022/user_avatar/forum.openzeppelin.com/maxareo/32/11606_2.png) [@maxareo](https://forum.openzeppelin.com/u/maxareo)\
**Post date:** [April 13, 2022, 4:16am UTC](https://forum.openzeppelin.com/t/why-keep-ownable-init-beside-ownable-init-unchained/25579/11 "2022-04-13T04:16:19Z")

</div>

Thanks @ericglau. It would be great if OZ can make a blog post on this topic. Guidelines and advices on best practices given in an organized and systematic way can benefit the community greatly.

---

<div class="post-metadata">

**Author:** ![Mylifechangefast.eth](https://sea2.discourse-cdn.com/flex022/user_avatar/forum.openzeppelin.com/mylifechangefast.eth/32/18973_2.png) [@Mylifechangefast.eth](https://forum.openzeppelin.com/u/Mylifechangefast.eth)\
**Post date:** [May 5, 2024, 4:47pm UTC](https://forum.openzeppelin.com/t/why-keep-ownable-init-beside-ownable-init-unchained/25579/12 "2024-05-05T16:47:52Z")

</div>

If he doesn't use it, what can happen?

---

<div class="post-metadata">

**Author:** ![ericglau](https://sea2.discourse-cdn.com/flex022/user_avatar/forum.openzeppelin.com/ericglau/32/15149_2.png) [@ericglau](https://forum.openzeppelin.com/u/ericglau)\
**Post date:** [May 6, 2024, 2:15pm UTC](https://forum.openzeppelin.com/t/why-keep-ownable-init-beside-ownable-init-unchained/25579/13 "2024-05-06T14:15:00Z")

</div>

@Mylifechangefast.eth The need for this is explained in the second comment. If you don't call `_init` functions, then parent contracts would not be initialized.

---

<div class="post-metadata">

**Author:** ![ericglau](https://sea2.discourse-cdn.com/flex022/user_avatar/forum.openzeppelin.com/ericglau/32/15149_2.png) [@ericglau](https://forum.openzeppelin.com/u/ericglau)\
**Post date:** [May 22, 2024, 8:29pm UTC](https://forum.openzeppelin.com/t/why-keep-ownable-init-beside-ownable-init-unchained/25579/14 "2024-05-22T20:29:10Z")

</div>

Split this topic on May 22, 2024, 8:29pm UTC

5 posts were split to a new topic: [How to use Pausable in upgradeble contracts](https://forum.openzeppelin.com/t/how-to-use-pausable-in-upgradeble-contracts/40611)
