Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

stuff #3472

Merged
merged 2 commits into from
Jan 9, 2025
Merged

stuff #3472

Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
23 changes: 17 additions & 6 deletions evm/contracts/clients/CometblsClient.sol
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand All @@ -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(
Expand Down
23 changes: 17 additions & 6 deletions evm/contracts/clients/StateLensIcs23Ics23Client.sol
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
);
}

/*
Expand Down
23 changes: 17 additions & 6 deletions evm/contracts/clients/StateLensIcs23MptClient.sol
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
);
}

/*
Expand Down
14 changes: 10 additions & 4 deletions evm/contracts/core/02-client/IBCClient.sol
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
Expand Down Expand Up @@ -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;
}

Expand Down
7 changes: 6 additions & 1 deletion evm/contracts/core/02-client/ILightClient.sol
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
2 changes: 1 addition & 1 deletion evm/tests/src/02-client/IBCClient.t.sol
Original file line number Diff line number Diff line change
Expand Up @@ -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_);
}
Expand Down
21 changes: 15 additions & 6 deletions evm/tests/src/02-client/StateLensIcs23Ics23Client.t.sol
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand Down
21 changes: 15 additions & 6 deletions evm/tests/src/core/LightClient.sol
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand Down
2 changes: 1 addition & 1 deletion lib/ibc-solidity/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
14 changes: 13 additions & 1 deletion voyager/modules/state/ethereum/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -350,7 +350,19 @@ impl StateModuleServer<IbcUnion> for Module {
#[instrument(skip_all, fields(chain_id = %self.chain_id))]
async fn client_info(&self, _: &Extensions, client_id: u32) -> RpcResult<ClientInfo> {
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),
Expand Down
10 changes: 1 addition & 9 deletions voyager/plugins/event-source/ethereum/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -272,14 +272,6 @@ impl PluginServer<ModuleCall, ModuleCallback> for Module {
.client_info::<IbcUnion>(self.chain_id.clone(), raw_event.client_id)
.await?;

let client_meta = voyager_client
.client_meta::<IbcUnion>(
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(),
Expand All @@ -291,7 +283,7 @@ impl PluginServer<ModuleCall, ModuleCallback> 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,
Expand Down
Loading