Skip to content

Commit

Permalink
upgrade types to match version release-v9.10037.1 (#399)
Browse files Browse the repository at this point in the history
* upgrade types to match version release-v9.10037.1

* fmt
  • Loading branch information
blasrodri authored Aug 28, 2023
1 parent 9b34198 commit a9090e7
Show file tree
Hide file tree
Showing 10 changed files with 258 additions and 831 deletions.
14 changes: 9 additions & 5 deletions hyperspace/parachain/src/finality_protocol.rs
Original file line number Diff line number Diff line change
Expand Up @@ -404,9 +404,7 @@ where
let Some(block) = relay_client.rpc().block(Some(hash)).await? else {
return Ok(None)
};
let Some(justifications) = block.justifications else {
return Ok(None)
};
let Some(justifications) = block.justifications else { return Ok(None) };
for (id, justification) in justifications {
log::info!(target: "hyperspace", "Found closer justification at {height} (suggested {to})");
if id == GRANDPA_ENGINE_ID {
Expand Down Expand Up @@ -469,8 +467,14 @@ where
Error::Custom("Received an empty client state from counterparty".to_string())
})?;

let AnyClientState::Grandpa(client_state) = AnyClientState::decode_recursive(any_client_state, |c| matches!(c, AnyClientState::Grandpa(_)))
.ok_or_else(|| Error::Custom(format!("Could not decode client state")))? else { unreachable!() };
let AnyClientState::Grandpa(client_state) =
AnyClientState::decode_recursive(any_client_state, |c| {
matches!(c, AnyClientState::Grandpa(_))
})
.ok_or_else(|| Error::Custom(format!("Could not decode client state")))?
else {
unreachable!()
};

let prover = source.grandpa_prover();
// prove_finality will always give us the highest block finalized by the authority set for the
Expand Down
20 changes: 16 additions & 4 deletions hyperspace/parachain/src/light_client_sync.rs
Original file line number Diff line number Diff line change
Expand Up @@ -72,8 +72,14 @@ where
match self.finality_protocol {
FinalityProtocol::Grandpa => {
let prover = self.grandpa_prover();
let AnyClientState::Grandpa(client_state) = AnyClientState::decode_recursive(any_client_state, |c| matches!(c, AnyClientState::Grandpa(_)))
.ok_or_else(|| Error::Custom(format!("Could not decode client state")))? else { unreachable!() };
let AnyClientState::Grandpa(client_state) =
AnyClientState::decode_recursive(any_client_state, |c| {
matches!(c, AnyClientState::Grandpa(_))
})
.ok_or_else(|| Error::Custom(format!("Could not decode client state")))?
else {
unreachable!()
};

let latest_hash = self.relay_client.rpc().finalized_head().await?;
let finalized_head =
Expand Down Expand Up @@ -107,8 +113,14 @@ where

let (messages, events) = match self.finality_protocol {
FinalityProtocol::Grandpa => {
let AnyClientState::Grandpa(client_state) = AnyClientState::decode_recursive(any_client_state, |c| matches!(c, AnyClientState::Grandpa(_)))
.ok_or_else(|| Error::Custom(format!("Could not decode client state")))? else { unreachable!() };
let AnyClientState::Grandpa(client_state) =
AnyClientState::decode_recursive(any_client_state, |c| {
matches!(c, AnyClientState::Grandpa(_))
})
.ok_or_else(|| Error::Custom(format!("Could not decode client state")))?
else {
unreachable!()
};
let latest_hash = self.relay_client.rpc().finalized_head().await?;
let finalized_head =
self.relay_client.rpc().header(Some(latest_hash)).await?.ok_or_else(|| {
Expand Down
5 changes: 4 additions & 1 deletion hyperspace/primitives/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -759,7 +759,10 @@ pub async fn find_suitable_proof_height_for_client(
let temp_height = Height::new(start_height.revision_number, mid);
let consensus_state =
sink.query_client_consensus(at, client_id.clone(), temp_height).await.ok();
let Some(Ok(consensus_state)) = consensus_state.map(|x| x.consensus_state.map(AnyConsensusState::try_from)).flatten() else {
let Some(Ok(consensus_state)) = consensus_state
.map(|x| x.consensus_state.map(AnyConsensusState::try_from))
.flatten()
else {
start += 1;
continue
};
Expand Down
11 changes: 8 additions & 3 deletions hyperspace/testsuite/src/misbehaviour.rs
Original file line number Diff line number Diff line change
Expand Up @@ -58,9 +58,14 @@ where
let client_id = chain_b.client_id();
let latest_height = chain_a.latest_height_and_timestamp().await.unwrap().0;
let response = chain_a.query_client_state(latest_height, client_id).await.unwrap();
let AnyClientState::Grandpa(client_state) = AnyClientState::decode_recursive(response.client_state.unwrap(), |cs| {
matches!(cs, AnyClientState::Grandpa(_))
}).unwrap() else { unreachable!() };
let AnyClientState::Grandpa(client_state) =
AnyClientState::decode_recursive(response.client_state.unwrap(), |cs| {
matches!(cs, AnyClientState::Grandpa(_))
})
.unwrap()
else {
unreachable!()
};

let finality_event =
chain_b.finality_notifications().await.unwrap().next().await.expect("no event");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@ pub(crate) fn process<Ctx: ReaderContext>(
// set the counterparty channel id to verify against it
channel_end.set_counterparty_channel_id(msg.counterparty_channel_id);

//2. Verify proofs
// 2. Verify proofs
verify_channel_proofs::<Ctx>(
ctx,
msg.proofs.height(),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@ where
expected_connection_hops,
channel_end.version().clone(),
);
//2. Verify proofs
// 2. Verify proofs
verify_channel_proofs::<Ctx>(
ctx,
msg.proofs.height(),
Expand Down
6 changes: 3 additions & 3 deletions ibc/modules/src/core/ics04_channel/handler/chan_open_try.rs
Original file line number Diff line number Diff line change
Expand Up @@ -84,9 +84,9 @@ where
}

// Proof verification in two steps:
// 1. Setup: build the Channel as we expect to find it on the other party.
// the port should be identical with the port we're using; the channel id should not be set
// since the counterparty cannot know yet which ID did we choose.
// 1. Setup: build the Channel as we expect to find it on the other party. the port should be
// identical with the port we're using; the channel id should not be set since the
// counterparty cannot know yet which ID did we choose.
let expected_counterparty = Counterparty::new(msg.port_id.clone(), None);
let counterparty = conn.counterparty();
let ccid = counterparty.connection_id().ok_or_else(|| {
Expand Down
3 changes: 1 addition & 2 deletions ibc/modules/src/core/ics04_channel/packet.rs
Original file line number Diff line number Diff line change
Expand Up @@ -143,8 +143,7 @@ impl<'a> core::fmt::Debug for PacketData<'a> {
impl core::fmt::Debug for Packet {
fn fmt(&self, formatter: &mut core::fmt::Formatter<'_>) -> Result<(), core::fmt::Error> {
// Remember: if you alter the definition of `Packet`,
// 1. update the formatter debug struct builder calls (return object of
// this function)
// 1. update the formatter debug struct builder calls (return object of this function)
// 2. update this destructuring assignment accordingly
let Packet {
sequence: _,
Expand Down
Loading

0 comments on commit a9090e7

Please sign in to comment.