diff --git a/evm/contracts/clients/CometblsClient.sol b/evm/contracts/clients/CometblsClient.sol index 3bef82c91b..cb18e226f3 100644 --- a/evm/contracts/clients/CometblsClient.sol +++ b/evm/contracts/clients/CometblsClient.sol @@ -207,7 +207,15 @@ contract CometblsClient is uint32 clientId, bytes calldata clientStateBytes, bytes calldata consensusStateBytes - ) external override onlyIBC returns (ConsensusStateUpdate memory update) { + ) + external + override + onlyIBC + returns ( + ConsensusStateUpdate memory update, + string memory counterpartyChainId + ) + { ClientState calldata clientState = clientStateBytes.decodeClientState(); ConsensusState calldata consensusState = consensusStateBytes.decodeConsensusState(); @@ -216,11 +224,14 @@ contract CometblsClient is } clientStates[clientId] = clientState; consensusStates[clientId][clientState.latestHeight] = consensusState; - return ConsensusStateUpdate({ - clientStateCommitment: clientState.commit(), - consensusStateCommitment: consensusState.commit(), - height: clientState.latestHeight - }); + return ( + ConsensusStateUpdate({ + clientStateCommitment: clientState.commit(), + consensusStateCommitment: consensusState.commit(), + height: clientState.latestHeight + }), + string(abi.encodePacked(clientState.chainId)) + ); } function misbehaviour( diff --git a/evm/contracts/clients/StateLensIcs23Ics23Client.sol b/evm/contracts/clients/StateLensIcs23Ics23Client.sol index dd43acedbe..e05318491c 100644 --- a/evm/contracts/clients/StateLensIcs23Ics23Client.sol +++ b/evm/contracts/clients/StateLensIcs23Ics23Client.sol @@ -110,7 +110,15 @@ contract StateLensIcs23Ics23Client is uint32 clientId, bytes calldata clientStateBytes, bytes calldata consensusStateBytes - ) external override onlyIBC returns (ConsensusStateUpdate memory update) { + ) + external + override + onlyIBC + returns ( + ConsensusStateUpdate memory update, + string memory counterpartyChainId + ) + { ClientState calldata clientState; assembly { clientState := clientStateBytes.offset @@ -129,11 +137,14 @@ contract StateLensIcs23Ics23Client is timestamp: block.timestamp * 1e9, height: block.number }); - return ConsensusStateUpdate({ - clientStateCommitment: clientState.commit(), - consensusStateCommitment: consensusState.commit(), - height: clientState.l2LatestHeight - }); + return ( + ConsensusStateUpdate({ + clientStateCommitment: clientState.commit(), + consensusStateCommitment: consensusState.commit(), + height: clientState.l2LatestHeight + }), + clientState.l2ChainId + ); } /* diff --git a/evm/contracts/clients/StateLensIcs23MptClient.sol b/evm/contracts/clients/StateLensIcs23MptClient.sol index b5335c04eb..42922a2453 100644 --- a/evm/contracts/clients/StateLensIcs23MptClient.sol +++ b/evm/contracts/clients/StateLensIcs23MptClient.sol @@ -113,7 +113,15 @@ contract StateLensIcs23MptClient is uint32 clientId, bytes calldata clientStateBytes, bytes calldata consensusStateBytes - ) external override onlyIBC returns (ConsensusStateUpdate memory update) { + ) + external + override + onlyIBC + returns ( + ConsensusStateUpdate memory update, + string memory counterpartyChainId + ) + { ClientState calldata clientState; assembly { clientState := clientStateBytes.offset @@ -135,11 +143,14 @@ contract StateLensIcs23MptClient is clientState.l2ChainId ); - return ConsensusStateUpdate({ - clientStateCommitment: clientState.commit(), - consensusStateCommitment: consensusState.commit(), - height: clientState.l2LatestHeight - }); + return ( + ConsensusStateUpdate({ + clientStateCommitment: clientState.commit(), + consensusStateCommitment: consensusState.commit(), + height: clientState.l2LatestHeight + }), + clientState.l2ChainId + ); } /* diff --git a/evm/contracts/core/02-client/IBCClient.sol b/evm/contracts/core/02-client/IBCClient.sol index d2ad9aa05c..94a6ebc6a5 100644 --- a/evm/contracts/core/02-client/IBCClient.sol +++ b/evm/contracts/core/02-client/IBCClient.sol @@ -8,7 +8,9 @@ import "../02-client/IIBCClient.sol"; library IBCClientLib { event RegisterClient(string clientType, address clientAddress); - event CreateClient(string clientType, uint32 clientId); + event CreateClient( + string clientType, uint32 clientId, string counterpartyChainId + ); event UpdateClient(uint32 clientId, uint64 height); event Misbehaviour(uint32 clientId); } @@ -44,14 +46,18 @@ abstract contract IBCClient is IBCStore, IIBCClient { uint32 clientId = generateClientIdentifier(); clientTypes[clientId] = msg_.clientType; clientImpls[clientId] = clientImpl; - ConsensusStateUpdate memory update = ILightClient(clientImpl) - .createClient(clientId, msg_.clientStateBytes, msg_.consensusStateBytes); + (ConsensusStateUpdate memory update, string memory counterpartyChainId) + = ILightClient(clientImpl).createClient( + clientId, msg_.clientStateBytes, msg_.consensusStateBytes + ); commitments[IBCCommitment.clientStateCommitmentKey(clientId)] = update.clientStateCommitment; commitments[IBCCommitment.consensusStateCommitmentKey( clientId, update.height )] = update.consensusStateCommitment; - emit IBCClientLib.CreateClient(msg_.clientType, clientId); + emit IBCClientLib.CreateClient( + msg_.clientType, clientId, counterpartyChainId + ); return clientId; } diff --git a/evm/contracts/core/02-client/ILightClient.sol b/evm/contracts/core/02-client/ILightClient.sol index 26abd13c04..ea21cdebfd 100644 --- a/evm/contracts/core/02-client/ILightClient.sol +++ b/evm/contracts/core/02-client/ILightClient.sol @@ -21,7 +21,12 @@ interface ILightClient { uint32 clientId, bytes calldata clientStateBytes, bytes calldata consensusStateBytes - ) external returns (ConsensusStateUpdate memory update); + ) + external + returns ( + ConsensusStateUpdate memory update, + string memory counterpartyChainId + ); /** * @dev getTimestampAtHeight returns the timestamp of the consensus state at the given height. diff --git a/evm/tests/src/02-client/IBCClient.t.sol b/evm/tests/src/02-client/IBCClient.t.sol index d9079998a5..9d18cea88b 100644 --- a/evm/tests/src/02-client/IBCClient.t.sol +++ b/evm/tests/src/02-client/IBCClient.t.sol @@ -43,7 +43,7 @@ contract IBCClientTests is Test { vm.pauseGasMetering(); handler.registerClient(msg_.clientType, lightClient); vm.expectEmit(); - emit IBCClientLib.CreateClient(msg_.clientType, 0); + emit IBCClientLib.CreateClient(msg_.clientType, 0, ""); vm.resumeGasMetering(); handler.createClient(msg_); } diff --git a/evm/tests/src/02-client/StateLensIcs23Ics23Client.t.sol b/evm/tests/src/02-client/StateLensIcs23Ics23Client.t.sol index 953c3e29ed..5f70cb6555 100644 --- a/evm/tests/src/02-client/StateLensIcs23Ics23Client.t.sol +++ b/evm/tests/src/02-client/StateLensIcs23Ics23Client.t.sol @@ -28,12 +28,21 @@ contract MockLightClient is ILightClient { uint32 clientId, bytes calldata clientStateBytes, bytes calldata consensusStateBytes - ) external returns (ConsensusStateUpdate memory update) { - return ConsensusStateUpdate({ - clientStateCommitment: bytes32(0), - consensusStateCommitment: bytes32(0), - height: 0 - }); + ) + external + returns ( + ConsensusStateUpdate memory update, + string memory counterpartyChainId + ) + { + return ( + ConsensusStateUpdate({ + clientStateCommitment: bytes32(0), + consensusStateCommitment: bytes32(0), + height: 0 + }), + "" + ); } function getClientState( diff --git a/evm/tests/src/core/LightClient.sol b/evm/tests/src/core/LightClient.sol index f4d3d4a24e..35059c773b 100644 --- a/evm/tests/src/core/LightClient.sol +++ b/evm/tests/src/core/LightClient.sol @@ -56,16 +56,25 @@ contract TestLightClient is ILightClient { uint32, bytes calldata clientStateBytes, bytes calldata consensusStateBytes - ) external returns (ConsensusStateUpdate memory) { + ) + external + returns ( + ConsensusStateUpdate memory, + string memory counterpartyClientId + ) + { if (revertCreate) { revert(); } clientState = clientStateBytes; - return ConsensusStateUpdate({ - clientStateCommitment: keccak256(clientStateBytes), - consensusStateCommitment: keccak256(consensusStateBytes), - height: latestHeight - }); + return ( + ConsensusStateUpdate({ + clientStateCommitment: keccak256(clientStateBytes), + consensusStateCommitment: keccak256(consensusStateBytes), + height: latestHeight + }), + "" + ); } function getTimestampAtHeight( diff --git a/lib/ibc-solidity/src/lib.rs b/lib/ibc-solidity/src/lib.rs index a9b86a1f8f..5dcdf677f6 100644 --- a/lib/ibc-solidity/src/lib.rs +++ b/lib/ibc-solidity/src/lib.rs @@ -151,7 +151,7 @@ maybe_sol_attr! { feature = "serde", derive(serde::Serialize, serde::Deserialize), serde(deny_unknown_fields) )] - event CreateClient(string clientType, uint32 client_id); + event CreateClient(string client_type, uint32 client_id, string counterparty_chain_id); #[cfg_attr( feature = "serde", derive(serde::Serialize, serde::Deserialize), serde(deny_unknown_fields) diff --git a/voyager/modules/state/ethereum/src/main.rs b/voyager/modules/state/ethereum/src/main.rs index dd65fd1f05..c85d1d068e 100644 --- a/voyager/modules/state/ethereum/src/main.rs +++ b/voyager/modules/state/ethereum/src/main.rs @@ -350,7 +350,19 @@ impl StateModuleServer for Module { #[instrument(skip_all, fields(chain_id = %self.chain_id))] async fn client_info(&self, _: &Extensions, client_id: u32) -> RpcResult { let ibc_handler = self.ibc_handler(); - let client_type = ibc_handler.clientTypes(client_id).call().await.unwrap()._0; + let client_type = ibc_handler + .clientTypes(client_id) + .call() + .await + .map_err(|e| { + ErrorObject::owned( + -1, + format!("error fetching client info: {}", ErrorReporter(e)), + None::<()>, + ) + })? + ._0; + Ok(ClientInfo { client_type: ClientType::new(client_type), ibc_interface: IbcInterface::new(IbcInterface::IBC_SOLIDITY), diff --git a/voyager/plugins/event-source/ethereum/src/main.rs b/voyager/plugins/event-source/ethereum/src/main.rs index aa36262895..04c72eb627 100644 --- a/voyager/plugins/event-source/ethereum/src/main.rs +++ b/voyager/plugins/event-source/ethereum/src/main.rs @@ -272,14 +272,6 @@ impl PluginServer for Module { .client_info::(self.chain_id.clone(), raw_event.client_id) .await?; - let client_meta = voyager_client - .client_meta::( - self.chain_id.clone(), - provable_height.into(), - raw_event.client_id, - ) - .await?; - let event = CreateClient { client_id: raw_event.client_id, client_type: client_info.client_type.clone(), @@ -291,7 +283,7 @@ impl PluginServer for Module { Ok(data(ChainEvent { chain_id: self.chain_id.clone(), client_info: client_info.clone(), - counterparty_chain_id: client_meta.chain_id, + counterparty_chain_id: ChainId::new(raw_event.counterparty_chain_id), tx_hash, provable_height, ibc_spec_id: IbcUnion::ID,