From 373ce4934e018852dcbc4d6690634a5136088568 Mon Sep 17 00:00:00 2001 From: aeryz Date: Mon, 25 Sep 2023 13:13:16 +0300 Subject: [PATCH] feat(ethereum-lc): use beacon height for all Signed-off-by: aeryz --- lib/ics-008-wasm-client/src/storage_utils.rs | 4 ++-- .../ethereum-light-client/src/client.rs | 24 +++++++------------ 2 files changed, 11 insertions(+), 17 deletions(-) diff --git a/lib/ics-008-wasm-client/src/storage_utils.rs b/lib/ics-008-wasm-client/src/storage_utils.rs index 4f7251978e..157c8f2af8 100644 --- a/lib/ics-008-wasm-client/src/storage_utils.rs +++ b/lib/ics-008-wasm-client/src/storage_utils.rs @@ -84,11 +84,11 @@ pub fn save_client_state( pub fn update_client_state( deps: DepsMut, mut wasm_client_state: wasm::client_state::ClientState, - latest_execution_height: u64, + latest_height: u64, ) { wasm_client_state.latest_height = Height { revision_number: 0, - revision_height: latest_execution_height, + revision_height: latest_height, }; save_client_state(deps, wasm_client_state); diff --git a/light-clients/ethereum-light-client/src/client.rs b/light-clients/ethereum-light-client/src/client.rs index 25669282d2..e0cc6805b5 100644 --- a/light-clients/ethereum-light-client/src/client.rs +++ b/light-clients/ethereum-light-client/src/client.rs @@ -219,6 +219,13 @@ impl IbcClient for EthereumLightClient { _ => {} } + // Some updates can be only for updating the sync committee, therefore the slot number can be + // smaller. We don't want to save a new state if this is the case. + let updated_height = core::cmp::max( + trusted_height.revision_height, + consensus_update.attested_header.beacon.slot, + ); + if consensus_update.attested_header.beacon.slot > consensus_state.data.slot { consensus_state.data.slot = consensus_update.attested_header.beacon.slot; @@ -238,29 +245,16 @@ impl IbcClient for EthereumLightClient { ); if client_state.data.latest_slot < consensus_update.attested_header.beacon.slot { client_state.data.latest_slot = consensus_update.attested_header.beacon.slot; + update_client_state(deps.branch(), client_state, updated_height); } } - // Some updates can be only for updating the sync committee, therefore the execution number can be - // smaller. We don't want to save a new state if this is the case. - let updated_execution_height = core::cmp::max( - trusted_height.revision_height, - consensus_update.attested_header.execution.block_number, - ); - - update_client_state( - deps.branch(), - client_state, - // wasm_client_state.data, - updated_execution_height, - ); save_consensus_state( deps, consensus_state, - // wasm_consensus_state.data, &Height { revision_number: trusted_height.revision_number, - revision_height: updated_execution_height, + revision_height: updated_height, }, );