Skip to content

Commit 40e1d86

Browse files
author
Naohiro Yoshida
committed
fix conflict
Signed-off-by: Naohiro Yoshida <naohiro.yoshida@datachain.jp>
2 parents fab3599 + b83c842 commit 40e1d86

File tree

11 files changed

+223
-133
lines changed

11 files changed

+223
-133
lines changed

.github/workflows/ci.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ jobs:
1515
with:
1616
ref: ${{ github.event.pull_request.head.ref }}
1717
repository: ${{github.event.pull_request.head.repo.full_name}}
18-
- uses: actions/cache@v2
18+
- uses: actions/cache@v4
1919
with:
2020
path: |
2121
~/.cargo/registry

light-client/src/client.rs

Lines changed: 48 additions & 31 deletions
Large diffs are not rendered by default.

light-client/src/client_state.rs

Lines changed: 64 additions & 42 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,6 @@ use prost::Message as _;
88
use parlia_ibc_proto::google::protobuf::Any as IBCAny;
99
use parlia_ibc_proto::ibc::lightclients::parlia::v1::ClientState as RawClientState;
1010

11-
use crate::commitment::resolve_account;
1211
use crate::consensus_state::ConsensusState;
1312
use crate::errors::Error;
1413
use crate::fork_spec::ForkSpec;
@@ -68,18 +67,8 @@ impl ClientState {
6867
new_client_state.latest_height = header_height;
6968
}
7069

71-
// Ensure world state is valid
72-
let account = resolve_account(
73-
header.state_root(),
74-
&header.account_proof()?,
75-
&new_client_state.ibc_store_address,
76-
)?;
77-
7870
let new_consensus_state = ConsensusState {
79-
state_root: account
80-
.storage_root
81-
.try_into()
82-
.map_err(Error::UnexpectedStorageRoot)?,
71+
state_root: *header.state_root(),
8372
timestamp: header.timestamp()?,
8473
current_validators_hash: header.current_epoch_validators_hash(),
8574
previous_validators_hash: header.previous_epoch_validators_hash(),
@@ -341,7 +330,6 @@ mod test {
341330
previous_validators_hash: hp.previous_epoch_header().epoch.unwrap().hash(),
342331
};
343332
let header = Header::new(
344-
vec![1],
345333
ETHHeaders {
346334
target: hp.epoch_header(),
347335
all: vec![],
@@ -364,34 +352,6 @@ mod test {
364352
}
365353
err => unreachable!("{:?}", err),
366354
}
367-
368-
// fail: resolve_account
369-
let header = Header::new(
370-
vec![1],
371-
ETHHeaders {
372-
target: hp.epoch_header(),
373-
all: vec![
374-
hp.epoch_header(),
375-
hp.epoch_header_plus_1(),
376-
hp.epoch_header_plus_2(),
377-
],
378-
},
379-
Height {
380-
revision_number: 0,
381-
revision_height: h.number - 1,
382-
},
383-
hp.previous_epoch_header().epoch.unwrap(),
384-
hp.epoch_header().epoch.unwrap(),
385-
);
386-
let err = cs
387-
.check_header_and_update_state(now, &cons_state, header)
388-
.unwrap_err();
389-
match err {
390-
Error::InvalidProofFormatError(value) => {
391-
assert_eq!(value, vec![1]);
392-
}
393-
err => unreachable!("{:?}", err),
394-
}
395355
}
396356

397357
#[rstest]
@@ -405,7 +365,6 @@ mod test {
405365
let raw = RawHeader {
406366
headers: vec![EthHeader { header: h_rlp }],
407367
trusted_height: Some(trusted_height),
408-
account_proof: vec![],
409368
current_validators: if h.is_epoch() {
410369
h.epoch.clone().unwrap().validators().clone()
411370
} else {
@@ -722,4 +681,67 @@ mod test {
722681
panic!("expected error");
723682
}
724683
}
684+
#[cfg(feature = "dev")]
685+
mod dev_test_min {
686+
use crate::client_state::ClientState;
687+
use crate::consensus_state::ConsensusState;
688+
use crate::errors::Error;
689+
use crate::fixture::localnet;
690+
use crate::header::constant::{MINIMUM_HEIGHT_SUPPORTED, MINIMUM_TIMESTAMP_SUPPORTED};
691+
use crate::header::eth_headers::ETHHeaders;
692+
use crate::header::Header;
693+
use crate::misc::new_timestamp;
694+
use parlia_ibc_proto::ibc::core::client::v1::Height;
695+
696+
#[test]
697+
fn test_supported_timestamp() {
698+
let header = Header::new(
699+
ETHHeaders {
700+
target: localnet().previous_epoch_header(),
701+
all: vec![],
702+
},
703+
Height::default(),
704+
localnet().previous_epoch_header().epoch.unwrap(),
705+
localnet().epoch_header().epoch.unwrap(),
706+
);
707+
let cs = ClientState::default();
708+
let cons_state = ConsensusState::default();
709+
let err = cs
710+
.check_header(new_timestamp(0).unwrap(), &cons_state, &header)
711+
.unwrap_err();
712+
match err {
713+
Error::UnsupportedMinimumTimestamp(e1) => {
714+
assert_eq!(e1, header.timestamp().unwrap());
715+
}
716+
err => unreachable!("{:?}", err),
717+
}
718+
}
719+
720+
#[test]
721+
fn test_supported_height() {
722+
let mut header = Header::new(
723+
ETHHeaders {
724+
target: localnet().previous_epoch_header(),
725+
all: vec![],
726+
},
727+
Height::default(),
728+
localnet().previous_epoch_header().epoch.unwrap(),
729+
localnet().epoch_header().epoch.unwrap(),
730+
);
731+
header.eth_header_mut().target.timestamp = MINIMUM_TIMESTAMP_SUPPORTED;
732+
header.eth_header_mut().target.number = MINIMUM_HEIGHT_SUPPORTED - 1;
733+
734+
let cs = ClientState::default();
735+
let cons_state = ConsensusState::default();
736+
let err = cs
737+
.check_header(new_timestamp(0).unwrap(), &cons_state, &header)
738+
.unwrap_err();
739+
match err {
740+
Error::UnsupportedMinimumHeight(e1) => {
741+
assert_eq!(e1, header.height());
742+
}
743+
err => unreachable!("{:?}", err),
744+
}
745+
}
746+
}
725747
}

light-client/src/errors.rs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@ pub enum Error {
2525
UnknownMisbehaviourType(String),
2626
UnexpectedClientType(String),
2727
LCPCommitmentError(CommitmentError),
28+
VerifyAccountError(alloc::boxed::Box<Error>),
2829

2930
// ClientState error
3031
MissingLatestHeight,
@@ -430,6 +431,9 @@ impl core::fmt::Display for Error {
430431
Error::UnsupportedMinimumHeightForkSpec(e1) => {
431432
write!(f, "UnsupportedMinimumHeightForkSpec : {}", e1)
432433
}
434+
Error::VerifyAccountError(e1) => {
435+
write!(f, "VerifyAccountError : {}", e1)
436+
}
433437
}
434438
}
435439
}

0 commit comments

Comments
 (0)