Skip to content

Commit d4f7410

Browse files
committed
tendermint-lc: remove some validations
Signed-off-by: Jun Kimura <jun.kimura@datachain.jp>
1 parent efbbf26 commit d4f7410

File tree

2 files changed

+1
-143
lines changed

2 files changed

+1
-143
lines changed

modules/tendermint-lc/src/client.rs

Lines changed: 1 addition & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,7 @@ use light_client::{
3636
LightClientRegistry, UpdateClientResult, VerifyMembershipResult,
3737
};
3838
use light_client::{MisbehaviourData, UpdateStateData, VerifyNonMembershipResult};
39+
#[allow(unused_imports)]
3940
use log::*;
4041

4142
#[derive(Default)]
@@ -239,37 +240,6 @@ impl TendermintLightClient {
239240
.into());
240241
}
241242

242-
// Read consensus state from the host chain store.
243-
let latest_consensus_state: ConsensusState = ctx
244-
.consensus_state(&client_id, &client_state.latest_height().into())
245-
.map_err(|_| {
246-
Error::ics02(ICS02Error::ConsensusStateNotFound {
247-
client_id: client_id.clone().into(),
248-
height: client_state.latest_height(),
249-
})
250-
})?
251-
.try_into()?;
252-
253-
debug!("latest consensus state: {:?}", latest_consensus_state);
254-
255-
let now = ctx.host_timestamp();
256-
let duration = now
257-
.duration_since(latest_consensus_state.timestamp().into_tm_time().unwrap())
258-
.map_err(|_| {
259-
Error::ics02(ICS02Error::InvalidConsensusStateTimestamp {
260-
time1: latest_consensus_state.timestamp(),
261-
time2: now.into(),
262-
})
263-
})?;
264-
265-
if client_state.expired(duration) {
266-
return Err(Error::ics02(ICS02Error::HeaderNotWithinTrustPeriod {
267-
latest_time: latest_consensus_state.timestamp(),
268-
update_time: header.timestamp(),
269-
})
270-
.into());
271-
}
272-
273243
let height = header.height().into();
274244
let header_timestamp: Time = header.timestamp().into();
275245

modules/tendermint-lc/src/verifier.rs

Lines changed: 0 additions & 112 deletions
Original file line numberDiff line numberDiff line change
@@ -29,25 +29,6 @@ pub(crate) fn check_header_and_update_state(
2929
client_id: ClientId,
3030
header: Any,
3131
) -> Result<UpdatedState, ClientError> {
32-
fn maybe_consensus_state(
33-
ctx: &dyn ValidationContext,
34-
client_cons_state_path: &ClientConsensusStatePath,
35-
) -> Result<Option<Box<dyn ConsensusState>>, ClientError> {
36-
match ctx.consensus_state(client_cons_state_path) {
37-
Ok(cs) => Ok(Some(cs)),
38-
Err(e) => match e {
39-
ContextError::ClientError(ClientError::ConsensusStateNotFound {
40-
client_id: _,
41-
height: _,
42-
}) => Ok(None),
43-
ContextError::ClientError(e) => Err(e),
44-
_ => Err(ClientError::Other {
45-
description: e.to_string(),
46-
}),
47-
},
48-
}
49-
}
50-
5132
let client_state = downcast_tm_client_state(client_state)?.clone();
5233
let header = TmHeader::try_from(header)?;
5334

@@ -61,28 +42,6 @@ pub(crate) fn check_header_and_update_state(
6142
});
6243
}
6344

64-
// Check if a consensus state is already installed; if so it should
65-
// match the untrusted header.
66-
let header_consensus_state = TmConsensusState::from(header.clone());
67-
let client_cons_state_path = ClientConsensusStatePath::new(&client_id, &header.height());
68-
let existing_consensus_state = match maybe_consensus_state(ctx, &client_cons_state_path)? {
69-
Some(cs) => {
70-
let cs = downcast_tm_consensus_state(cs.as_ref())?;
71-
// If this consensus state matches, skip verification
72-
// (optimization)
73-
if cs == header_consensus_state {
74-
// Header is already installed and matches the incoming
75-
// header (already verified)
76-
return Ok(UpdatedState {
77-
client_state: client_state.into_box(),
78-
consensus_state: cs.into_box(),
79-
});
80-
}
81-
Some(cs)
82-
}
83-
None => None,
84-
};
85-
8645
let trusted_client_cons_state_path =
8746
ClientConsensusStatePath::new(&client_id, &header.trusted_height);
8847
let trusted_consensus_state = downcast_tm_consensus_state(
@@ -137,77 +96,6 @@ pub(crate) fn check_header_and_update_state(
13796
Verdict::Invalid(detail) => Err(Error::VerificationError { detail }),
13897
}?;
13998

140-
// If the header has verified, but its corresponding consensus state
141-
// differs from the existing consensus state for that height, freeze the
142-
// client and return the installed consensus state.
143-
if let Some(cs) = existing_consensus_state {
144-
if cs != header_consensus_state {
145-
return Ok(UpdatedState {
146-
client_state: client_state.with_frozen_height(header.height()).into_box(),
147-
consensus_state: cs.into_box(),
148-
});
149-
}
150-
}
151-
152-
// Monotonicity checks for timestamps for in-the-middle updates
153-
// (cs-new, cs-next, cs-latest)
154-
if header.height() < client_state.latest_height() {
155-
let maybe_next_cs = ctx
156-
.next_consensus_state(&client_id, &header.height())
157-
.map_err(|e| match e {
158-
ContextError::ClientError(e) => e,
159-
_ => ClientError::Other {
160-
description: e.to_string(),
161-
},
162-
})?
163-
.as_ref()
164-
.map(|cs| downcast_tm_consensus_state(cs.as_ref()))
165-
.transpose()?;
166-
167-
if let Some(next_cs) = maybe_next_cs {
168-
// New (untrusted) header timestamp cannot occur after next
169-
// consensus state's height
170-
if header.signed_header.header().time > next_cs.timestamp {
171-
return Err(ClientError::ClientSpecific {
172-
description: Error::HeaderTimestampTooHigh {
173-
actual: header.signed_header.header().time.to_string(),
174-
max: next_cs.timestamp.to_string(),
175-
}
176-
.to_string(),
177-
});
178-
}
179-
}
180-
}
181-
182-
// (cs-trusted, cs-prev, cs-new)
183-
if header.trusted_height < header.height() {
184-
let maybe_prev_cs = ctx
185-
.prev_consensus_state(&client_id, &header.height())
186-
.map_err(|e| match e {
187-
ContextError::ClientError(e) => e,
188-
_ => ClientError::Other {
189-
description: e.to_string(),
190-
},
191-
})?
192-
.as_ref()
193-
.map(|cs| downcast_tm_consensus_state(cs.as_ref()))
194-
.transpose()?;
195-
196-
if let Some(prev_cs) = maybe_prev_cs {
197-
// New (untrusted) header timestamp cannot occur before the
198-
// previous consensus state's height
199-
if header.signed_header.header().time < prev_cs.timestamp {
200-
return Err(ClientError::ClientSpecific {
201-
description: Error::HeaderTimestampTooLow {
202-
actual: header.signed_header.header().time.to_string(),
203-
min: prev_cs.timestamp.to_string(),
204-
}
205-
.to_string(),
206-
});
207-
}
208-
}
209-
}
210-
21199
Ok(UpdatedState {
212100
client_state: client_state.with_header(header.clone())?.into_box(),
213101
consensus_state: TmConsensusState::from(header).into_box(),

0 commit comments

Comments
 (0)