Example Question: Cannot Create IBC Channel

Context:
I’m working on an asset transfer dApp between Optimism and Base and I’m trying to establish an IBC channel between the two.

Description:
Each time I try to create an IBC channel, the channel gets stuck in the STATE_INIT stage (see screenshot). This persists through multiple attempts.

How to Reproduce:

  • Deploy a contract with my included channel functions
  • Call the connectChannel Function
  • Debug with IBC Exploerer

Additional Details:

function createChannel(
        bool feeEnabled,
        string[] calldata connectionHops,
        CounterParty calldata counterparty,
        Proof calldata proof
    ) external {
        dispatcher.openIbcChannel(
            IbcReceiver(address(this)),
            supportedVersions[0],
            ChannelOrder.UNORDERED,
            feeEnabled,
            connectionHops,
            counterparty,
            proof
        );
    }

function onOpenIbcChannel(
        string calldata version,
        ChannelOrder ordering,
        bool feeEnabled,
        string[] calldata connectionHops,
        string calldata counterpartyPortId,
        bytes32 counterpartyChannelId,
        string calldata counterpartyVersion
    ) external view returns (string memory selectedVersion) {
        if (bytes(counterpartyPortId).length <= 8) {
            revert invalidCounterPartyPortId();
        }
        bool foundVersion = false;
        selectedVersion = keccak256(abi.encodePacked(version)) ==
            keccak256(abi.encodePacked(""))
            ? counterpartyVersion
            : version;
        for (uint i = 0; i < supportedVersions.length; i++) {
            if (
                keccak256(abi.encodePacked(selectedVersion)) ==
                keccak256(abi.encodePacked(supportedVersions[i]))
            ) {
                foundVersion = true;
                break;
            }
        }
        require(foundVersion, "Unsupported version");

        return selectedVersion;
    }

    function onConnectIbcChannel(
        bytes32 channelId,
        bytes32 counterpartyChannelId,
        string calldata counterpartyVersion
    ) external {
        // ensure negotiated version is supported
        bool foundVersion = false;
        for (uint i = 0; i < supportedVersions.length; i++) {
            if (
                keccak256(abi.encodePacked(counterpartyVersion)) ==
                keccak256(abi.encodePacked(supportedVersions[i]))
            ) {
                foundVersion = true;
                break;
            }
        }
        require(foundVersion, "Unsupported version");
        connectedChannels.push(channelId);
    }

Screenshot 2024-01-18 at 8.27.53 AM

4 Likes