Skip to content

Commit

Permalink
feat(ethereum-lc): use beacon height for all
Browse files Browse the repository at this point in the history
Signed-off-by: aeryz <abdullaheryz@protonmail.com>
  • Loading branch information
aeryz committed Sep 25, 2023
1 parent 95ec2e0 commit 373ce49
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 17 deletions.
4 changes: 2 additions & 2 deletions lib/ics-008-wasm-client/src/storage_utils.rs
Original file line number Diff line number Diff line change
Expand Up @@ -84,11 +84,11 @@ pub fn save_client_state<C: CustomQuery, CS: IntoProto>(
pub fn update_client_state<C: CustomQuery, CS: IntoProto>(
deps: DepsMut<C>,
mut wasm_client_state: wasm::client_state::ClientState<CS>,
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);
Expand Down
24 changes: 9 additions & 15 deletions light-clients/ethereum-light-client/src/client.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand All @@ -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,
},
);

Expand Down

0 comments on commit 373ce49

Please sign in to comment.