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

Problem: channel handshake open ack failed due signature verification error #98

Merged
merged 3 commits into from
Oct 16, 2024
Merged
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
10 changes: 0 additions & 10 deletions solo-machine-core/src/model/ibc.rs
Original file line number Diff line number Diff line change
Expand Up @@ -58,16 +58,6 @@ pub async fn add_tendermint_consensus_state<'e>(
add(executor, path.get_key(0).unwrap(), &data).await
}

/// Fetches tendermint consensus state from database
pub async fn get_tendermint_consensus_state<'e>(
executor: impl Executor<'e, Database = Db>,
client_id: &ClientId,
height: &Height,
) -> Result<Option<TendermintConsensusState>> {
let path = ConsensusStatePath::new(client_id, height);
get(executor, path.get_key(0).unwrap()).await
}

/// Adds connection to database
pub async fn add_connection<'e>(
executor: impl Executor<'e, Database = Db>,
Expand Down
101 changes: 3 additions & 98 deletions solo-machine-core/src/transaction_builder.rs
Original file line number Diff line number Diff line change
Expand Up @@ -69,8 +69,7 @@ use crate::{
ics24_host::{
identifier::{ChainId, ChannelId, ClientId, ConnectionId, Identifier},
path::{
ChannelPath, ClientStatePath, ConnectionPath, ConsensusStatePath,
PacketAcknowledgementPath, PacketCommitmentPath,
ChannelPath, ConnectionPath, PacketAcknowledgementPath, PacketCommitmentPath,
},
},
},
Expand Down Expand Up @@ -262,25 +261,8 @@ pub async fn msg_connection_open_ack(
.await?;
*chain = chain::increment_sequence(&mut **transaction, &chain.id).await?;

let proof_client = get_client_proof(
&mut **transaction,
&signer,
chain,
tendermint_client_id,
request_id,
)
.await?;
*chain = chain::increment_sequence(&mut **transaction, &chain.id).await?;

let proof_consensus = get_consensus_proof(
&mut *transaction,
&signer,
chain,
tendermint_client_id,
request_id,
)
.await?;
*chain = chain::increment_sequence(&mut **transaction, &chain.id).await?;
let proof_client: Vec<u8> = Vec::new();
let proof_consensus: Vec<u8> = Vec::new();

let message = MsgConnectionOpenAck {
connection_id: solo_machine_connection_id.to_string(),
Expand Down Expand Up @@ -892,83 +874,6 @@ async fn get_connection_proof<'e>(
timestamped_sign(signer, chain, sign_bytes, request_id).await
}

async fn get_client_proof<'e>(
executor: impl Executor<'e, Database = Db>,
signer: impl Signer,
chain: &Chain,
client_id: &ClientId,
request_id: Option<&str>,
) -> Result<Vec<u8>> {
let client_state = ibc_handler::get_tendermint_client_state(executor, client_id)
.await?
.ok_or_else(|| anyhow!("client with id {} not found", client_id))?;

let mut client_state_path = ClientStatePath::new(client_id);
client_state_path.apply_prefix("ibc")?;

let client_state_bytes = proto_encode(&client_state.to_any()?)?;

let sign_bytes = SignBytes {
sequence: chain.sequence.into(),
timestamp: to_u64_timestamp(chain.consensus_timestamp)?,
diversifier: chain.config.diversifier.to_owned(),
path: client_state_path
.get_key(1)
.ok_or_else(|| anyhow!("invalid path {:?}", client_state_path))?
.as_bytes()
.to_vec(),
data: client_state_bytes,
};

timestamped_sign(signer, chain, sign_bytes, request_id).await
}

async fn get_consensus_proof(
transaction: &mut Transaction<'_, Db>,
signer: impl Signer,
chain: &Chain,
client_id: &ClientId,
request_id: Option<&str>,
) -> Result<Vec<u8>> {
let client_state = ibc_handler::get_tendermint_client_state(&mut **transaction, client_id)
.await?
.ok_or_else(|| anyhow!("client with id {} not found", client_id))?;

let height = client_state
.latest_height
.ok_or_else(|| anyhow!("client state does not contain latest height"))?;

let consensus_state =
ibc_handler::get_tendermint_consensus_state(&mut **transaction, client_id, &height)
.await?
.ok_or_else(|| {
anyhow!(
"consensus state with id {} and height {} not found",
client_id,
height.to_string(),
)
})?;

let mut consensus_state_path = ConsensusStatePath::new(client_id, &height);
consensus_state_path.apply_prefix("ibc")?;

let consensus_state_bytes = proto_encode(&consensus_state.to_any()?)?;

let sign_bytes = SignBytes {
sequence: chain.sequence.into(),
timestamp: to_u64_timestamp(chain.consensus_timestamp)?,
diversifier: chain.config.diversifier.to_owned(),
path: consensus_state_path
.get_key(1)
.ok_or_else(|| anyhow!("invalid path {:?}", consensus_state_path))?
.as_bytes()
.to_vec(),
data: consensus_state_bytes,
};

timestamped_sign(signer, chain, sign_bytes, request_id).await
}

async fn get_header_proof(
signer: impl Signer,
chain: &Chain,
Expand Down
Loading