@@ -82,7 +82,6 @@ impl ClientState {
82
82
proof_specs : ProofSpecs ,
83
83
upgrade_path : Vec < String > ,
84
84
allow_update : AllowUpdate ,
85
- frozen_height : Option < Height > ,
86
85
) -> Result < ClientState , Error > {
87
86
if chain_id. as_str ( ) . len ( ) > MaxChainIdLen {
88
87
return Err ( Error :: ChainIdTooLong {
@@ -172,7 +171,7 @@ impl ClientState {
172
171
proof_specs,
173
172
upgrade_path,
174
173
allow_update,
175
- frozen_height,
174
+ frozen_height : None ,
176
175
verifier : ProdVerifier :: default ( ) ,
177
176
} )
178
177
}
@@ -704,9 +703,6 @@ impl Ics2ClientState for ClientState {
704
703
let upgraded_tm_client_state = TmClientState :: try_from ( upgraded_client_state) ?;
705
704
let upgraded_tm_cons_state = TmConsensusState :: try_from ( upgraded_consensus_state) ?;
706
705
707
- // Frozen height is set to None fo the new client state
708
- let new_frozen_height = None ;
709
-
710
706
// Construct new client state and consensus state relayer chosen client
711
707
// parameters are ignored. All chain-chosen parameters come from
712
708
// committed client, all client-chosen parameters come from current
@@ -721,7 +717,6 @@ impl Ics2ClientState for ClientState {
721
717
upgraded_tm_client_state. proof_specs ,
722
718
upgraded_tm_client_state. upgrade_path ,
723
719
self . allow_update ,
724
- new_frozen_height,
725
720
) ?;
726
721
727
722
// The new consensus state is merely used as a trusted kernel against
@@ -860,9 +855,13 @@ impl TryFrom<RawTmClientState> for ClientState {
860
855
// In `RawClientState`, a `frozen_height` of `0` means "not frozen".
861
856
// See:
862
857
// https://github.com/cosmos/ibc-go/blob/8422d0c4c35ef970539466c5bdec1cd27369bab3/modules/light-clients/07-tendermint/types/client_state.go#L74
863
- let frozen_height = raw
858
+ if raw
864
859
. frozen_height
865
- . and_then ( |raw_height| raw_height. try_into ( ) . ok ( ) ) ;
860
+ . and_then ( |h| Height :: try_from ( h) . ok ( ) )
861
+ . is_some ( )
862
+ {
863
+ return Err ( Error :: FrozenHeightNotAllowed ) ;
864
+ }
866
865
867
866
// We use set this deprecated field just so that we can properly convert
868
867
// it back in its raw form
@@ -882,7 +881,6 @@ impl TryFrom<RawTmClientState> for ClientState {
882
881
raw. proof_specs . into ( ) ,
883
882
raw. upgrade_path ,
884
883
allow_update,
885
- frozen_height,
886
884
) ?;
887
885
888
886
Ok ( client_state)
@@ -951,16 +949,20 @@ impl From<ClientState> for Any {
951
949
952
950
#[ cfg( test) ]
953
951
mod tests {
952
+ use crate :: clients:: ics07_tendermint:: header:: test_util:: get_dummy_tendermint_header;
954
953
use crate :: prelude:: * ;
955
954
use crate :: Height ;
956
955
use core:: time:: Duration ;
957
956
use test_log:: test;
958
957
958
+ use ibc_proto:: google:: protobuf:: Any ;
959
+ use ibc_proto:: ibc:: core:: client:: v1:: Height as RawHeight ;
959
960
use ibc_proto:: ics23:: ProofSpec as Ics23ProofSpec ;
960
961
961
962
use crate :: clients:: ics07_tendermint:: client_state:: {
962
963
AllowUpdate , ClientState as TmClientState ,
963
964
} ;
965
+ use crate :: clients:: ics07_tendermint:: error:: Error ;
964
966
use crate :: core:: ics02_client:: client_state:: ClientState ;
965
967
use crate :: core:: ics02_client:: trust_threshold:: TrustThreshold ;
966
968
use crate :: core:: ics23_commitment:: specs:: ProofSpecs ;
@@ -1133,7 +1135,6 @@ mod tests {
1133
1135
p. proof_specs ,
1134
1136
p. upgrade_path ,
1135
1137
p. allow_update ,
1136
- None ,
1137
1138
) ;
1138
1139
1139
1140
assert_eq ! (
@@ -1199,7 +1200,6 @@ mod tests {
1199
1200
p. proof_specs ,
1200
1201
p. upgrade_path ,
1201
1202
p. allow_update ,
1202
- None ,
1203
1203
)
1204
1204
. unwrap ( ) ;
1205
1205
let client_state = match test. setup {
@@ -1218,6 +1218,48 @@ mod tests {
1218
1218
) ;
1219
1219
}
1220
1220
}
1221
+
1222
+ #[ test]
1223
+ fn tm_client_state_conversions_healthy ( ) {
1224
+ // check client state creation path from a proto type
1225
+ let tm_client_state_from_raw = TmClientState :: new_dummy_from_raw ( RawHeight {
1226
+ revision_number : 0 ,
1227
+ revision_height : 0 ,
1228
+ } ) ;
1229
+ assert ! ( tm_client_state_from_raw. is_ok( ) ) ;
1230
+
1231
+ let any_from_tm_client_state =
1232
+ Any :: from ( tm_client_state_from_raw. as_ref ( ) . unwrap ( ) . clone ( ) ) ;
1233
+ let tm_client_state_from_any = TmClientState :: try_from ( any_from_tm_client_state) ;
1234
+ assert ! ( tm_client_state_from_any. is_ok( ) ) ;
1235
+ assert_eq ! (
1236
+ tm_client_state_from_raw. unwrap( ) ,
1237
+ tm_client_state_from_any. unwrap( )
1238
+ ) ;
1239
+
1240
+ // check client state creation path from a tendermint header
1241
+ let tm_header = get_dummy_tendermint_header ( ) ;
1242
+ let tm_client_state_from_header = TmClientState :: new_dummy_from_header ( tm_header) ;
1243
+ let any_from_header = Any :: from ( tm_client_state_from_header. clone ( ) ) ;
1244
+ let tm_client_state_from_any = TmClientState :: try_from ( any_from_header) ;
1245
+ assert ! ( tm_client_state_from_any. is_ok( ) ) ;
1246
+ assert_eq ! (
1247
+ tm_client_state_from_header,
1248
+ tm_client_state_from_any. unwrap( )
1249
+ ) ;
1250
+ }
1251
+
1252
+ #[ test]
1253
+ fn tm_client_state_malformed_with_frozen_height ( ) {
1254
+ let tm_client_state_from_raw = TmClientState :: new_dummy_from_raw ( RawHeight {
1255
+ revision_number : 0 ,
1256
+ revision_height : 10 ,
1257
+ } ) ;
1258
+ match tm_client_state_from_raw {
1259
+ Err ( Error :: FrozenHeightNotAllowed ) => { }
1260
+ _ => panic ! ( "Expected to fail with FrozenHeightNotAllowed error" ) ,
1261
+ }
1262
+ }
1221
1263
}
1222
1264
1223
1265
#[ cfg( all( test, feature = "serde" ) ) ]
@@ -1249,29 +1291,58 @@ pub mod test_util {
1249
1291
use tendermint:: block:: Header ;
1250
1292
1251
1293
use crate :: clients:: ics07_tendermint:: client_state:: { AllowUpdate , ClientState } ;
1294
+ use crate :: clients:: ics07_tendermint:: error:: Error ;
1252
1295
use crate :: core:: ics02_client:: height:: Height ;
1296
+ use crate :: core:: ics23_commitment:: specs:: ProofSpecs ;
1253
1297
use crate :: core:: ics24_host:: identifier:: ChainId ;
1298
+ use ibc_proto:: ibc:: core:: client:: v1:: Height as RawHeight ;
1299
+ use ibc_proto:: ibc:: lightclients:: tendermint:: v1:: { ClientState as RawTmClientState , Fraction } ;
1254
1300
1255
- pub fn get_dummy_tendermint_client_state ( tm_header : Header ) -> ClientState {
1256
- ClientState :: new (
1257
- ChainId :: from ( tm_header. chain_id . clone ( ) ) ,
1258
- Default :: default ( ) ,
1259
- Duration :: from_secs ( 64000 ) ,
1260
- Duration :: from_secs ( 128000 ) ,
1261
- Duration :: from_millis ( 3000 ) ,
1262
- Height :: new (
1263
- ChainId :: chain_version ( tm_header. chain_id . as_str ( ) ) ,
1264
- u64:: from ( tm_header. height ) ,
1301
+ impl ClientState {
1302
+ pub fn new_dummy_from_raw ( frozen_height : RawHeight ) -> Result < Self , Error > {
1303
+ ClientState :: try_from ( get_dummy_raw_tm_client_state ( frozen_height) )
1304
+ }
1305
+
1306
+ pub fn new_dummy_from_header ( tm_header : Header ) -> ClientState {
1307
+ ClientState :: new (
1308
+ tm_header. chain_id . clone ( ) . into ( ) ,
1309
+ Default :: default ( ) ,
1310
+ Duration :: from_secs ( 64000 ) ,
1311
+ Duration :: from_secs ( 128000 ) ,
1312
+ Duration :: from_millis ( 3000 ) ,
1313
+ Height :: new (
1314
+ ChainId :: chain_version ( tm_header. chain_id . as_str ( ) ) ,
1315
+ u64:: from ( tm_header. height ) ,
1316
+ )
1317
+ . unwrap ( ) ,
1318
+ Default :: default ( ) ,
1319
+ Default :: default ( ) ,
1320
+ AllowUpdate {
1321
+ after_expiry : false ,
1322
+ after_misbehaviour : false ,
1323
+ } ,
1265
1324
)
1266
- . unwrap ( ) ,
1267
- Default :: default ( ) ,
1268
- Default :: default ( ) ,
1269
- AllowUpdate {
1270
- after_expiry : false ,
1271
- after_misbehaviour : false ,
1272
- } ,
1273
- None ,
1274
- )
1275
- . unwrap ( )
1325
+ . unwrap ( )
1326
+ }
1327
+ }
1328
+
1329
+ pub fn get_dummy_raw_tm_client_state ( frozen_height : RawHeight ) -> RawTmClientState {
1330
+ #[ allow( deprecated) ]
1331
+ RawTmClientState {
1332
+ chain_id : ChainId :: new ( "ibc" . to_string ( ) , 0 ) . to_string ( ) ,
1333
+ trust_level : Some ( Fraction {
1334
+ numerator : 1 ,
1335
+ denominator : 3 ,
1336
+ } ) ,
1337
+ trusting_period : Some ( Duration :: from_secs ( 64000 ) . into ( ) ) ,
1338
+ unbonding_period : Some ( Duration :: from_secs ( 128000 ) . into ( ) ) ,
1339
+ max_clock_drift : Some ( Duration :: from_millis ( 3000 ) . into ( ) ) ,
1340
+ latest_height : Some ( Height :: new ( 0 , 10 ) . unwrap ( ) . into ( ) ) ,
1341
+ proof_specs : ProofSpecs :: default ( ) . into ( ) ,
1342
+ upgrade_path : Default :: default ( ) ,
1343
+ frozen_height : Some ( frozen_height) ,
1344
+ allow_update_after_expiry : false ,
1345
+ allow_update_after_misbehaviour : false ,
1346
+ }
1276
1347
}
1277
1348
}
0 commit comments