-
Notifications
You must be signed in to change notification settings - Fork 89
/
handler.rs
55 lines (44 loc) · 1.8 KB
/
handler.rs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
use core::convert::Infallible;
use alloc::string::ToString;
use tendermint::abci::Event as TmEvent;
use tendermint_proto::abci::Event as ProtoEvent;
use crate::clients::ics07_tendermint::client_state::ClientState as TmClientState;
use crate::core::ics02_client::error::UpgradeClientError;
use crate::core::ics24_host::path::UpgradeClientPath;
use crate::hosts::tendermint::upgrade_proposal::UpgradeClientProposal;
use crate::hosts::tendermint::upgrade_proposal::UpgradeExecutionContext;
use crate::hosts::tendermint::upgrade_proposal::UpgradeProposal;
/// Handles an upgrade client proposal
///
/// It clears both IBC client and consensus states if a previous plan was set.
/// Then it will schedule an upgrade and finally set the upgraded client state
/// in upgrade store.
pub fn upgrade_client_proposal_handler<Ctx>(
ctx: &mut Ctx,
proposal: UpgradeProposal,
) -> Result<ProtoEvent, UpgradeClientError>
where
Ctx: UpgradeExecutionContext,
Ctx::AnyClientState: From<TmClientState>,
{
let plan = proposal.plan;
if ctx.upgrade_plan().is_ok() {
ctx.clear_upgrade_plan(plan.height)?;
}
let mut client_state =
TmClientState::try_from(proposal.upgraded_client_state).map_err(|e| {
UpgradeClientError::InvalidUpgradeProposal {
reason: e.to_string(),
}
})?;
client_state.zero_custom_fields();
ctx.schedule_upgrade(plan.clone())?;
let upgraded_client_state_path = UpgradeClientPath::UpgradedClientState(plan.height);
ctx.store_upgraded_client_state(upgraded_client_state_path, client_state.into())?;
let event = TmEvent::from(UpgradeClientProposal::new(proposal.title, plan.height))
.try_into()
.map_err(|e: Infallible| UpgradeClientError::Other {
reason: e.to_string(),
})?;
Ok(event)
}