Skip to content

Commit e7e4f31

Browse files
committed
Merge remote-tracking branch 'origin/ics07-tendermint-zk-wrapper' into vmarkushin/refactor-tendermint+zk
# Conflicts: # config/ethereum-local.toml # hyperspace/cosmos/src/client.rs # hyperspace/cosmos/src/provider.rs # hyperspace/ethereum/src/ibc_provider.rs # hyperspace/testsuite/tests/ethereum_cosmos.rs
2 parents d47840c + d75fab8 commit e7e4f31

27 files changed

+1266
-291
lines changed

Cargo.lock

+27-6
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

contracts/pallet-ibc/Cargo.toml

+1
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,7 @@ ics08-wasm = { path = "../../light-clients/ics08-wasm", default-features = false
4242
ics10-grandpa = { path = "../../light-clients/ics10-grandpa", default-features = false }
4343
ics11-beefy = { path = "../../light-clients/ics11-beefy", default-features = false }
4444
ics07-tendermint = { path = "../../light-clients/ics07-tendermint", default-features = false }
45+
ics07-tendermint-zk = { path = "../../light-clients/ics07-tendermint-zk", default-features = false }
4546
icsxx-ethereum = { path = "../../light-clients/icsxx-ethereum", default-features = false, optional = true }
4647
hex = { version = "0.4.3", default-features = false }
4748
# local deps

contracts/pallet-ibc/src/light_clients.rs

+38-1
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,13 @@ use ics07_tendermint::{
2424
client_state::TENDERMINT_CLIENT_STATE_TYPE_URL,
2525
consensus_state::TENDERMINT_CONSENSUS_STATE_TYPE_URL,
2626
};
27+
use ics07_tendermint_zk::{
28+
client_message::{
29+
TENDERMINT_CLIENT_MESSAGE_TYPE_URL as TENDERMINT_CLIENT_MESSAGE_ZK_TYPE_URL,
30+
TENDERMINT_HEADER_TYPE_URL as TENDERMINT_HEADER_ZK_TYPE_URL,
31+
TENDERMINT_MISBEHAVIOUR_TYPE_URL as TENDERMINT_MISBEHAVIOUR_ZK_TYPE_URL,
32+
},
33+
};
2734
use ics08_wasm::{
2835
client_message::{
2936
WASM_CLIENT_MESSAGE_TYPE_URL, WASM_HEADER_TYPE_URL, WASM_MISBEHAVIOUR_TYPE_URL,
@@ -349,7 +356,12 @@ pub enum AnyClientMessage {
349356
#[ibc(proto_url = "BEEFY_CLIENT_MESSAGE_TYPE_URL")]
350357
Beefy(ics11_beefy::client_message::ClientMessage),
351358
#[ibc(proto_url = "TENDERMINT_CLIENT_MESSAGE_TYPE_URL")]
352-
Tendermint(ics07_tendermint::client_message::ClientMessage),
359+
Tendermint(ics07_tendermint::client_message::ClientMessage), // or use the new wrapper crate here
360+
#[ibc(proto_url = "TENDERMINT_CLIENT_MESSAGE_ZK_TYPE_URL")]
361+
TendermintZk(ics07_tendermint_zk::client_message::ZkClientMessage), // or use the new wrapper crate here
362+
//todo probably need to add ethereum client message with zk ^
363+
// #[ibc(proto_url = "TENDERMINT_CLIENT_MESSAGE_TYPE_URL")]
364+
// TendermintZk(ics07_new_blabla::client_message::ClientMessageWithZkProof),
353365
#[cfg(feature = "ethereum")]
354366
#[ibc(proto_url = "ETHEREUM_CLIENT_MESSAGE_TYPE_URL")]
355367
Ethereum(icsxx_ethereum::client_message::ClientMessage),
@@ -367,6 +379,10 @@ impl AnyClientMessage {
367379
ics07_tendermint::client_message::ClientMessage::Header(h) => Some(h.height()),
368380
ics07_tendermint::client_message::ClientMessage::Misbehaviour(_) => None,
369381
},
382+
Self::TendermintZk(inner) => match inner {
383+
ics07_tendermint_zk::client_message::ZkClientMessage::Header(h) => Some(h.height()),
384+
ics07_tendermint_zk::client_message::ZkClientMessage::Misbehaviour(_) => None,
385+
},
370386
Self::Beefy(inner) => match inner {
371387
ics11_beefy::client_message::ClientMessage::Header(_) =>
372388
unimplemented!("beefy header height"),
@@ -475,6 +491,23 @@ impl TryFrom<Any> for AnyClientMessage {
475491
ics07_tendermint::client_message::Misbehaviour::decode_vec(&value.value)
476492
.map_err(ics02_client::error::Error::decode_raw_header)?,
477493
))),
494+
495+
TENDERMINT_CLIENT_MESSAGE_ZK_TYPE_URL => Ok(Self::TendermintZk(
496+
ics07_tendermint_zk::client_message::ZkClientMessage::decode_vec(&value.value)
497+
.map_err(ics02_client::error::Error::decode_raw_header)?,
498+
)),
499+
TENDERMINT_HEADER_ZK_TYPE_URL =>
500+
Ok(Self::TendermintZk(ics07_tendermint_zk::client_message::ZkClientMessage::Header(
501+
ics07_tendermint_zk::client_message::ZkHeader::decode_vec(&value.value)
502+
.map_err(ics02_client::error::Error::decode_raw_header)?,
503+
))),
504+
TENDERMINT_MISBEHAVIOUR_ZK_TYPE_URL =>
505+
Ok(Self::TendermintZk(ics07_tendermint_zk::client_message::ZkClientMessage::Misbehaviour(
506+
ics07_tendermint::client_message::Misbehaviour::decode_vec(&value.value)
507+
.map_err(ics02_client::error::Error::decode_raw_header)?,
508+
))),
509+
510+
478511
#[cfg(feature = "ethereum")]
479512
ETHEREUM_CLIENT_MESSAGE_TYPE_URL => Ok(Self::Ethereum(
480513
icsxx_ethereum::client_message::ClientMessage::decode_vec(&value.value)
@@ -542,6 +575,10 @@ impl From<AnyClientMessage> for Any {
542575
type_url: TENDERMINT_CLIENT_MESSAGE_TYPE_URL.to_string(),
543576
value: msg.encode_vec().expect("encode_vec failed"),
544577
},
578+
AnyClientMessage::TendermintZk(msg) => Any {
579+
type_url: TENDERMINT_CLIENT_MESSAGE_ZK_TYPE_URL.to_string(),
580+
value: msg.encode_vec().expect("encode_vec failed"),
581+
},
545582
#[cfg(feature = "ethereum")]
546583
AnyClientMessage::Ethereum(msg) => match msg {
547584
icsxx_ethereum::client_message::ClientMessage::Header(h) => Any {

hyperspace/core/src/lib.rs

+18-14
Original file line numberDiff line numberDiff line change
@@ -217,10 +217,11 @@ async fn process_some_finality_event<A: Chain, B: Chain>(
217217
mode: Option<Mode>,
218218
finality_event: <A as IbcProvider>::FinalityEvent,
219219
) -> anyhow::Result<()> {
220+
let name_n = source.name().to_string();
220221
let updates = source
221222
.query_latest_ibc_events(finality_event, &*sink)
222223
.await
223-
.map_err(|e| anyhow!("Failed to fetch IBC events for finality event {e}"))?;
224+
.map_err(|e| anyhow!("Failed to fetch IBC events from {name_n} for finality event {e}"))?;
224225
log::trace!(target: "hyperspace", "Received updates count: {}", updates.len());
225226
// query packets that can now be sent, at this sink height because of connection
226227
// delay.
@@ -272,20 +273,20 @@ async fn process_updates<A: Chain, B: Chain>(
272273
msgs: &mut Vec<Any>,
273274
) -> anyhow::Result<()> {
274275
// for timeouts we need both chains to be up to date
275-
let sink_has_undelivered_acks = sink.has_undelivered_sequences(UndeliveredType::Recvs) ||
276+
let sink_has_undelivered_acks = sink.has_undelivered_sequences(UndeliveredType::Recvs) ||
276277
sink.has_undelivered_sequences(UndeliveredType::Acks) ||
277278
sink.has_undelivered_sequences(UndeliveredType::Timeouts);
278279

279280
let need_to_update = sink_has_undelivered_acks;
280-
log::info!(target: "hyperspace", "Received {} client updates from {}", updates.len(), source.name(),);
281+
log::error!(target: "hyperspace", "Received {} client updates from {}", updates.len(), source.name(),);
281282

282283
let common_state = source.common_state();
283284
let skip_optional_updates = common_state.skip_optional_client_updates;
284285
let has_events = updates.iter().any(|(_, _, events, ..)| !events.is_empty());
285286
let mut mandatory_updates = updates
286287
.iter()
287288
.filter(|(_, h, _, update_type)| {
288-
log::info!(
289+
log::error!(
289290
"Received updated from {} at {}, is_mandatory: {}",
290291
source.name(),
291292
h.revision_height,
@@ -308,14 +309,14 @@ async fn process_updates<A: Chain, B: Chain>(
308309
);
309310
if let Some(not_updated_during) = Timestamp::now().duration_since(&update_time) {
310311
if not_updated_during < source.common_state().client_update_interval {
311-
log::debug!(target: "hyperspace", "Sending only mandatory updates, not updated during {} seconds, need {}", not_updated_during.as_secs(), sink.common_state().client_update_interval.as_secs());
312+
log::error!(target: "hyperspace", "Sending only mandatory updates, not updated during {} seconds, need {}", not_updated_during.as_secs(), sink.common_state().client_update_interval.as_secs());
312313
update_delay_passed = false;
313314
}
314315
} else {
315-
log::warn!(target: "hyperspace", "Update time is from the future: {}", update_time);
316+
log::error!(target: "hyperspace", "Update time is from the future: {}", update_time);
316317
}
317318

318-
log::debug!(target: "hyperspace", "Received' {} client updates from {}", mandatory_updates.len(), source.name(),);
319+
log::error!(target: "hyperspace", "Received' {} client updates from {}", mandatory_updates.len(), source.name(),);
319320

320321
let ibc_events = updates
321322
.iter()
@@ -338,12 +339,11 @@ async fn process_updates<A: Chain, B: Chain>(
338339
)
339340
});
340341

341-
log::debug!(target: "hyperspace", "Received'' {}, has_instant_events = {has_instant_events}, update_delay_passed = {update_delay_passed}, need_to_update = {need_to_update}", mandatory_updates.len(), );
342-
342+
343343
if !updates.is_empty() &&
344344
(mandatory_updates.is_empty() && update_delay_passed && need_to_update) ||
345345
has_instant_events
346-
{
346+
{
347347
let (forced_update, height) = updates.last().map(|(msg, h, ..)| (msg.clone(), h)).unwrap();
348348
if !mandatory_updates.is_empty() {
349349
let (_, last_height) =
@@ -355,19 +355,21 @@ async fn process_updates<A: Chain, B: Chain>(
355355
mandatory_updates.push((forced_update, *height));
356356
}
357357
}
358+
359+
log::error!(target: "hyperspace", "Received finalized events from: {} {event_types:#?}", source.name());
358360
if mandatory_updates.is_empty() && !has_events {
359-
log::info!(target: "hyperspace", "No messages to send");
361+
log::error!(target: "hyperspace", "No messages to send");
360362
return Ok(())
361363
}
362364

363365
let latest_update_height = if !mandatory_updates.is_empty() {
364366
mandatory_updates.last().map(|(_, height)| *height).unwrap()
365367
} else {
366-
log::warn!(target: "hyperspace", "Expected at least one update");
368+
log::error!(target: "hyperspace", "Expected at least one update");
367369
return Ok(())
368370
};
369371

370-
log::info!(target: "hyperspace", "Received finalized events from: {} {event_types:#?}", source.name());
372+
log::error!(target: "hyperspace", "Received finalized events from: {} {event_types:#?}", source.name());
371373
let mut new_height = source.get_proof_height(latest_update_height).await;
372374
if new_height != latest_update_height {
373375
new_height.revision_height -=
@@ -380,7 +382,9 @@ async fn process_updates<A: Chain, B: Chain>(
380382
.map_err(|e| anyhow!("Failed to parse events: {:?}", e))?;
381383
let (latest_height, _) = source.latest_height_and_timestamp().await?;
382384
for (msg_update_client, h) in mandatory_updates {
383-
log::debug!(target: "hyperspace", "Received client update message for {}: {}, latest height: {latest_height}", source.name(), h);
385+
log::error!(target: "hyperspace", "Received client update message for {}: {}, latest height: {latest_height}", source.name(), h);
386+
// log::error!(target: "hyperspace", "___________________________________________________________________________________________");
387+
// log::error!(target: "hyperspace", "Received client update message for {}: {}, latest height: {latest_height}", source.name(), h);
384388
msgs.push(msg_update_client);
385389
}
386390

hyperspace/core/src/packets.rs

+6-2
Original file line numberDiff line numberDiff line change
@@ -255,6 +255,7 @@ pub async fn query_ready_and_timed_out_packets(
255255
{
256256
proof_height
257257
} else {
258+
//todo!!! but with a loop zk relayer proably because of this
258259
timeout_packets_count.fetch_add(1, Ordering::SeqCst);
259260
log::trace!(target: "hyperspace", "Skipping packet as no timeout proof height could be found: {:?}", packet);
260261
return Ok(None)
@@ -311,7 +312,8 @@ pub async fn query_ready_and_timed_out_packets(
311312
// If sink does not have a client height that is equal to or greater than the packet
312313
// creation height, we can't send it yet, packet_info.height should represent the packet
313314
// creation height on source chain
314-
if packet_height > latest_source_height_on_sink.revision_height {
315+
316+
if source.get_proof_height(Height::new(source_height.revision_number, packet_height)).await.revision_height > latest_source_height_on_sink.revision_height {
315317
// Sink does not have client update required to prove recv packet message
316318
log::debug!(target: "hyperspace", "Skipping packet as sink does not have client update required to prove recv packet message: {:?}", packet);
317319
recv_packets_count.fetch_add(1, Ordering::SeqCst);
@@ -439,7 +441,9 @@ pub async fn query_ready_and_timed_out_packets(
439441
let ack_height = acknowledgement.height.ok_or_else(|| {
440442
Error::Custom(format!("Packet height not found for packet {packet:?}"))
441443
})?;
442-
if ack_height > latest_source_height_on_sink.revision_height {
444+
445+
if source.get_proof_height(Height::new(source_height.revision_number, ack_height)).await.revision_height > latest_source_height_on_sink.revision_height {
446+
// if ack_height > latest_source_height_on_sink.revision_height {
443447
// Sink does not have client update required to prove acknowledgement packet message
444448
log::trace!(target: "hyperspace", "Skipping acknowledgement for packet {:?} as sink does not have client update required to prove acknowledgement packet message", packet);
445449
acks_packets_count.fetch_add(1, Ordering::SeqCst);

hyperspace/cosmos/Cargo.toml

+2
Original file line numberDiff line numberDiff line change
@@ -35,12 +35,14 @@ ripemd = "0.1.3"
3535
digest = "0.10.6"
3636
quick_cache = "0.3.0"
3737
rand = "0.8.5"
38+
ureq = {version = "2.9.1", features = ["json"] }
3839

3940
# composable
4041
ibc = { path = "../../ibc/modules", features = [] }
4142
ibc-proto = { path = "../../ibc/proto" }
4243
ibc-primitives = { path = "../../contracts/pallet-ibc/primitives" }
4344
ics07-tendermint = { path = "../../light-clients/ics07-tendermint" }
45+
ics07-tendermint-zk = { path = "../../light-clients/ics07-tendermint-zk" }
4446
ics08-wasm = { path = "../../light-clients/ics08-wasm" }
4547
ibc-rpc = { path = "../../contracts/pallet-ibc/rpc" }
4648
pallet-ibc = { path = "../../contracts/pallet-ibc" }

hyperspace/cosmos/src/chain.rs

+2
Original file line numberDiff line numberDiff line change
@@ -133,6 +133,8 @@ where
133133
}
134134

135135
async fn submit(&self, messages: Vec<Any>) -> Result<Self::TransactionId, Error> {
136+
log::error!(target: "hyperspace_cosmos", "all messages ____________________________________________");
137+
log::error!(target: "hyperspace_cosmos", "Submitting messages to ethereum: {:?}", messages.iter().map(|x| x.type_url.clone()).collect::<Vec<_>>().join(", "));
136138
let hash = self.submit_call(messages).await?;
137139
log::debug!(target: "hyperspace_cosmos", "Submitted. Tx hash: {}", hash);
138140
Ok(Self::TransactionId { hash })

0 commit comments

Comments
 (0)