@@ -9,7 +9,7 @@ use ibc_union_light_client::{
9
9
ClientCreationResult , IbcClient , IbcClientCtx , IbcClientError , StateUpdate ,
10
10
} ;
11
11
use ibc_union_msg:: lightclient:: Status ;
12
- use ibc_union_spec:: path:: IBC_UNION_COSMWASM_COMMITMENT_PREFIX ;
12
+ use ibc_union_spec:: { path:: IBC_UNION_COSMWASM_COMMITMENT_PREFIX , Duration , Timestamp } ;
13
13
use ics23:: ibc_api:: SDK_SPECS ;
14
14
use unionlabs:: {
15
15
encoding:: Bincode ,
@@ -98,7 +98,7 @@ impl<T: ZkpVerifier> IbcClient for CometblsLightClient<T> {
98
98
. map_err ( Into :: < Error > :: into) ?)
99
99
}
100
100
101
- fn get_timestamp ( consensus_state : & Self :: ConsensusState ) -> u64 {
101
+ fn get_timestamp ( consensus_state : & Self :: ConsensusState ) -> Timestamp {
102
102
consensus_state. timestamp
103
103
}
104
104
@@ -123,7 +123,7 @@ impl<T: ZkpVerifier> IbcClient for CometblsLightClient<T> {
123
123
if is_client_expired (
124
124
consensus_state. timestamp ,
125
125
client_state. trusting_period ,
126
- ctx. env . block . time . nanos ( ) ,
126
+ Timestamp :: from_nanos ( ctx. env . block . time . nanos ( ) ) ,
127
127
) {
128
128
return Status :: Expired ;
129
129
}
@@ -203,7 +203,7 @@ fn verify_header<T: ZkpVerifier>(
203
203
204
204
let trusted_timestamp = consensus_state. timestamp ;
205
205
// Normalized to nanoseconds to follow tendermint convention
206
- let untrusted_timestamp = header. signed_header . time . as_unix_nanos ( ) ;
206
+ let untrusted_timestamp = Timestamp :: from_nanos ( header. signed_header . time . as_unix_nanos ( ) ) ;
207
207
208
208
if untrusted_timestamp <= trusted_timestamp {
209
209
return Err ( InvalidHeaderError :: SignedHeaderTimestampMustBeMoreRecent {
@@ -216,23 +216,19 @@ fn verify_header<T: ZkpVerifier>(
216
216
if is_client_expired (
217
217
trusted_timestamp,
218
218
client_state. trusting_period ,
219
- ctx. env . block . time . nanos ( ) ,
219
+ Timestamp :: from_nanos ( ctx. env . block . time . nanos ( ) ) ,
220
220
) {
221
221
return Err ( InvalidHeaderError :: HeaderExpired ( consensus_state. timestamp ) . into ( ) ) ;
222
222
}
223
223
224
- let max_clock_drift = ctx
225
- . env
226
- . block
227
- . time
228
- . nanos ( )
229
- . checked_add ( client_state. max_clock_drift )
224
+ let max_clock_drift_timestamp = Timestamp :: from_nanos ( ctx. env . block . time . nanos ( ) )
225
+ . plus_duration ( client_state. max_clock_drift )
230
226
. ok_or ( Error :: MathOverflow ) ?;
231
227
232
- if untrusted_timestamp >= max_clock_drift {
228
+ if untrusted_timestamp >= max_clock_drift_timestamp {
233
229
return Err ( InvalidHeaderError :: SignedHeaderCannotExceedMaxClockDrift {
234
230
signed_timestamp : untrusted_timestamp,
235
- max_clock_drift ,
231
+ max_clock_drift_timestamp ,
236
232
}
237
233
. into ( ) ) ;
238
234
}
@@ -301,7 +297,7 @@ fn update_state<T: ZkpVerifier>(
301
297
302
298
consensus_state. next_validators_hash = header. signed_header . next_validators_hash ;
303
299
// Normalized to nanoseconds to follow tendermint convention
304
- consensus_state. timestamp = header. signed_header . time . as_unix_nanos ( ) ;
300
+ consensus_state. timestamp = Timestamp :: from_nanos ( header. signed_header . time . as_unix_nanos ( ) ) ;
305
301
306
302
let state_update = StateUpdate :: new ( untrusted_height. height ( ) , consensus_state) ;
307
303
@@ -314,11 +310,11 @@ fn update_state<T: ZkpVerifier>(
314
310
}
315
311
316
312
fn is_client_expired (
317
- consensus_state_timestamp : u64 ,
318
- trusting_period : u64 ,
319
- current_block_time : u64 ,
313
+ consensus_state_timestamp : Timestamp ,
314
+ trusting_period : Duration ,
315
+ current_block_time : Timestamp ,
320
316
) -> bool {
321
- if let Some ( sum) = consensus_state_timestamp. checked_add ( trusting_period) {
317
+ if let Some ( sum) = consensus_state_timestamp. plus_duration ( trusting_period) {
322
318
sum < current_block_time
323
319
} else {
324
320
true
0 commit comments