Skip to content

Commit

Permalink
fix(voyager): use heights correctly (#615)
Browse files Browse the repository at this point in the history
We were incorrectly using beacon and execution heights at some places,
this fixes those.
  • Loading branch information
aeryz authored Sep 2, 2023
2 parents 8d5f9a2 + c24f060 commit 17e9d8b
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 37 deletions.
66 changes: 30 additions & 36 deletions voyager/src/chain/evm.rs
Original file line number Diff line number Diff line change
Expand Up @@ -719,6 +719,8 @@ impl<C: ChainSpec> LightClient for Cometbls<C> {
.make_height(tx_rcp.block_number.unwrap().as_u64());

(
// TODO(aeryz): we are returning the execution height here but since we are not using the height anywhere
// or calling this function from the main execution, I didn't touch it.
event_height,
#[allow(deprecated)]
UpdateClient {
Expand Down Expand Up @@ -780,9 +782,10 @@ impl<C: ChainSpec> Connect<Ethereum<C>> for Cometbls<C> {
.wait_for_execution_block(tx_rcp.block_number.unwrap())
.await;

let beacon_height = self.chain.query_latest_height().await;

(
self.chain
.make_height(tx_rcp.block_number.unwrap().as_u64()),
beacon_height,
ConnectionOpenInit {
connection_id,
client_id: msg.client_id,
Expand Down Expand Up @@ -816,9 +819,10 @@ impl<C: ChainSpec> Connect<Ethereum<C>> for Cometbls<C> {
.wait_for_execution_block(tx_rcp.block_number.unwrap())
.await;

let beacon_height = self.chain.query_latest_height().await;

(
self.chain
.make_height(tx_rcp.block_number.unwrap().as_u64()),
beacon_height,
ConnectionOpenTry {
connection_id,
client_id: msg.client_id,
Expand Down Expand Up @@ -863,21 +867,19 @@ impl<C: ChainSpec> Connect<Ethereum<C>> for Cometbls<C> {
.wait_for_execution_block(tx_rcp.block_number.unwrap())
.await;

let event_height = self
.chain
.make_height(tx_rcp.block_number.unwrap().as_u64());
let beacon_height = self.chain.query_latest_height().await;

let connection_end = IbcStateRead::<Self::CounterpartyChain, _>::state_proof(
self.chain(),
ConnectionPath {
connection_id: msg.connection_id.clone(),
},
event_height,
beacon_height,
)
.await;

(
event_height,
beacon_height,
ConnectionOpenAck {
connection_id: msg.connection_id,
client_id: connection_end.state.client_id,
Expand Down Expand Up @@ -908,21 +910,19 @@ impl<C: ChainSpec> Connect<Ethereum<C>> for Cometbls<C> {
.wait_for_execution_block(tx_rcp.block_number.unwrap())
.await;

let event_height = self
.chain
.make_height(tx_rcp.block_number.unwrap().as_u64());
let beacon_height = self.chain.query_latest_height().await;

let connection_end = IbcStateRead::<Self::CounterpartyChain, _>::state_proof(
self.chain(),
ConnectionPath {
connection_id: msg.connection_id.clone(),
},
event_height,
beacon_height,
)
.await;

(
event_height,
beacon_height,
ConnectionOpenConfirm {
connection_id: msg.connection_id,
client_id: connection_end.state.client_id,
Expand Down Expand Up @@ -955,22 +955,20 @@ impl<C: ChainSpec> Connect<Ethereum<C>> for Cometbls<C> {
.wait_for_execution_block(tx_rcp.block_number.unwrap())
.await;

let event_height = self
.chain
.make_height(tx_rcp.block_number.unwrap().as_u64());
let beacon_height = self.chain.query_latest_height().await;

let channel_end = IbcStateRead::<Self::CounterpartyChain, _>::state_proof(
self.chain(),
ChannelEndPath {
port_id: msg.port_id.clone(),
channel_id: channel_id.clone(),
},
event_height,
beacon_height,
)
.await;

(
event_height,
beacon_height,
ChannelOpenInit {
port_id: msg.port_id,
channel_id,
Expand Down Expand Up @@ -1004,22 +1002,20 @@ impl<C: ChainSpec> Connect<Ethereum<C>> for Cometbls<C> {
.wait_for_execution_block(tx_rcp.block_number.unwrap())
.await;

let event_height = self
.chain
.make_height(tx_rcp.block_number.unwrap().as_u64());
let beacon_height = self.chain.query_latest_height().await;

let channel_end = IbcStateRead::<Self::CounterpartyChain, _>::state_proof(
self.chain(),
ChannelEndPath {
port_id: msg.port_id.clone(),
channel_id: channel_id.clone(),
},
event_height,
beacon_height,
)
.await;

(
event_height,
beacon_height,
ChannelOpenTry {
port_id: msg.port_id,
channel_id,
Expand Down Expand Up @@ -1053,22 +1049,20 @@ impl<C: ChainSpec> Connect<Ethereum<C>> for Cometbls<C> {
.wait_for_execution_block(tx_rcp.block_number.unwrap())
.await;

let event_height = self
.chain
.make_height(tx_rcp.block_number.unwrap().as_u64());
let beacon_height = self.chain.query_latest_height().await;

let channel_end = IbcStateRead::<Self::CounterpartyChain, _>::state_proof(
self.chain(),
ChannelEndPath {
port_id: msg.port_id.clone(),
channel_id: msg.channel_id.clone(),
},
event_height,
beacon_height,
)
.await;

(
event_height,
beacon_height,
ChannelOpenAck {
port_id: msg.port_id,
channel_id: msg.channel_id.clone(),
Expand Down Expand Up @@ -1101,22 +1095,20 @@ impl<C: ChainSpec> Connect<Ethereum<C>> for Cometbls<C> {
.wait_for_execution_block(tx_rcp.block_number.unwrap())
.await;

let event_height = self
.chain
.make_height(tx_rcp.block_number.unwrap().as_u64());
let beacon_height = self.chain.query_latest_height().await;

let channel_end = IbcStateRead::<Self::CounterpartyChain, _>::state_proof(
self.chain(),
ChannelEndPath {
port_id: msg.port_id.clone(),
channel_id: msg.channel_id.clone(),
},
event_height,
beacon_height,
)
.await;

(
event_height,
beacon_height,
ChannelOpenConfirm {
port_id: msg.port_id,
channel_id: msg.channel_id.clone(),
Expand Down Expand Up @@ -1218,6 +1210,8 @@ impl<C: ChainSpec> Connect<Ethereum<C>> for Cometbls<C> {
.make_finality_update(
finality_update.data,
TrustedSyncCommittee {
// NOTE(aeryz): this has to be the execution height because this height is used for verifying
// the state proofs, which are always taken at the execution height
trusted_height: execution_height,
sync_committee: bootstrap.data.current_sync_committee,
is_next: false,
Expand Down Expand Up @@ -1376,7 +1370,7 @@ impl<C: ChainSpec> Cometbls<C> {
trusted_sync_committee: TrustedSyncCommittee<C>,
) -> wasm::header::Header<ethereum::header::Header<C>> {
let execution_block_number = light_client_update.attested_header.execution.block_number;
let updated_height = self.chain.make_height(execution_block_number);
let updated_execution_height = self.chain.make_height(execution_block_number);

let account_update = self
.chain
Expand All @@ -1391,7 +1385,7 @@ impl<C: ChainSpec> Cometbls<C> {
.unwrap();

wasm::header::Header {
height: updated_height,
height: updated_execution_height,
data: ethereum::header::Header {
consensus_update: light_client_update,
trusted_sync_committee,
Expand Down
2 changes: 1 addition & 1 deletion voyager/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1113,7 +1113,7 @@ where

lc2.recv_packet(MsgRecvPacket {
packet,
proof_height: lc1_updated_to,
proof_height: lc1.process_height_for_counterparty(lc1_updated_to).await,
proof_commitment: commitment_proof.proof,
})
.await;
Expand Down

0 comments on commit 17e9d8b

Please sign in to comment.