Skip to content

Commit

Permalink
fix to reduce unnecessary unwrap
Browse files Browse the repository at this point in the history
Signed-off-by: Jun Kimura <[email protected]>
  • Loading branch information
bluele committed Nov 3, 2024
1 parent c50d370 commit e8fe5ae
Showing 1 changed file with 14 additions and 16 deletions.
30 changes: 14 additions & 16 deletions crates/ibc/src/update.rs
Original file line number Diff line number Diff line change
Expand Up @@ -43,27 +43,25 @@ pub fn apply_updates<const SYNC_COMMITTEE_SIZE: usize, C: ChainContext>(
next_sync_committee: trusted_consensus_state.state.next_sync_committee.clone(),
}
} else if store_period + 1 == update_period {
let next_sync_committee = consensus_update
.next_sync_committee
.as_ref()
.map(|c| c.0.aggregate_pubkey.clone());
if next_sync_committee.is_none() {
if let Some((next_sync_committee, _)) = consensus_update.next_sync_committee {
ConsensusState {
slot: update_slot,
storage_root: account_update.account_storage_root.0.to_vec().into(),
timestamp: wrap_compute_timestamp_at_slot(ctx, update_slot)?,
// unwrap is safe because the consensus update validation has passed
current_sync_committee: trusted_consensus_state
.next_sync_committee()
.unwrap()
.aggregate_pubkey
.clone(),
next_sync_committee: next_sync_committee.aggregate_pubkey,
}
} else {
return Err(Error::NoNextSyncCommitteeInConsensusUpdate(
store_period.into(),
update_period.into(),
));
}
ConsensusState {
slot: update_slot,
storage_root: account_update.account_storage_root.0.to_vec().into(),
timestamp: wrap_compute_timestamp_at_slot(ctx, update_slot)?,
current_sync_committee: trusted_consensus_state
.next_sync_committee()
.unwrap()
.aggregate_pubkey
.clone(),
next_sync_committee: next_sync_committee.unwrap(),
}
} else {
// store_period + 1 < update_period
return Err(Error::FuturePeriodError(store_period, update_period));
Expand Down

0 comments on commit e8fe5ae

Please sign in to comment.