Skip to content

Commit ed53667

Browse files
author
Naohiro Yoshida
committed
Fix S1
Signed-off-by: Naohiro Yoshida <naohiro.yoshida@datachain.jp>
1 parent ddfd92e commit ed53667

File tree

6 files changed

+32
-26
lines changed

6 files changed

+32
-26
lines changed

light-client/src/client.rs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -858,6 +858,9 @@ mod test {
858858
mock_consensus_state.insert(Height::new(0, input.trusted_height), trusted_cs.clone());
859859

860860
// Set fork spec boundary timestamp is all[1]
861+
// This indicates that target is the HEADER immediately before the HF occurs.
862+
// By setting the height of the HF to ClientState here, the next update_client will be able to validate headers after the HF.
863+
// In order to validate the header after HF, it is necessary to set the height at which HF occurs in ClientState in advance.
861864
let mut boundary_fs = fork_spec_after_lorentz();
862865
boundary_fs.height_or_timestamp =
863866
HeightOrTimestamp::Time(header.eth_header().all[1].milli_timestamp());

light-client/src/consensus_state.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ pub struct ConsensusState {
1818
/// the storage root of the IBC contract
1919
pub state_root: Hash,
2020
/// timestamp from execution payload
21+
/// After Lorentz HF, the unit is millisecond. Before that, it was seconds.
2122
pub timestamp: Time,
2223
pub current_validators_hash: Hash,
2324
pub previous_validators_hash: Hash,

light-client/src/fork_spec.rs

Lines changed: 27 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -9,10 +9,18 @@ pub enum HeightOrTimestamp {
99
Time(u64),
1010
}
1111

12+
/// ForkSpec defines different parameters for each HF.
13+
/// The ForkSpec of the supporting HF must be registered at CreateClient
14+
/// This is a data structure that does not exist in the BSC node and is designed uniquely for the light client.
1215
#[derive(Clone, Debug, PartialEq, serde::Serialize, serde::Deserialize)]
1316
pub struct ForkSpec {
17+
/// The timestamp or height at which the HF will occur.
18+
/// If you set the timestamp, you need to use the value described in bsc's ChainConfig.
19+
/// https://github.com/bnb-chain/bsc/blob/5735d8a56540e8f2fb26d5585de0fa3959bb17b4/params/config.go#L192C3-L192C14
1420
pub height_or_timestamp: HeightOrTimestamp,
1521
/// Items count after parent_beacon_root
22+
/// The number of headers prior to Pascal HF is set to 0.
23+
/// For example, the number of headers after Pascal HF is set to 1 because of the addition of the requestsHash.
1624
pub additional_header_item_count: u64,
1725
/// Block count in epoch
1826
pub epoch_length: u64,
@@ -28,34 +36,35 @@ impl ForkSpec {
2836
/// with the previous fork specification. It calculates the previous last epoch, the current
2937
/// first epoch, and any intermediate epochs between them.
3038
///
31-
/// first = previous last epoch
32-
/// last = current first epoch
39+
/// previous_last: refers to the previous epoch of the height
40+
/// current_first refers to the first epoch of the height divisible by the current fork epoch length.
41+
/// intermediates: refers to the epochs between the previous last and current first.
3342
///
3443
/// eg) height = 1501
35-
/// first = 1400
36-
/// mid = [1600, 1800]
37-
/// last = 2000
44+
/// previous_last = 1400
45+
/// intermediates = [1600, 1800]
46+
/// current_first = 2000
3847
///
3948
/// in Lorentz HF
4049
/// eg) height = 1600
41-
/// first = 1600
42-
/// mid = [1800]
43-
/// last = 2000
50+
/// previous_last = 1600
51+
/// intermediates = [1800]
52+
/// current_first = 2000
4453
///
4554
/// eg) height = 1601
46-
/// first = 1600
47-
/// mid = [1800]
48-
/// last = 2000
55+
/// previous_last = 1600
56+
/// intermediates = [1800]
57+
/// current_first = 2000
4958
///
5059
/// eg) height = 1800
51-
/// first = 1800
52-
/// mid = []
53-
/// last = 2000
60+
/// previous_last = 1800
61+
/// intermediates = []
62+
/// current_first = 2000
5463
///
5564
/// eg) height = 2000
56-
/// first = 2000
57-
/// mid = []
58-
/// last = 2000
65+
/// previous_last = 2000
66+
/// intermediates = []
67+
/// current_first = 2000
5968
pub fn boundary_epochs(&self, prev_fork_spec: &ForkSpec) -> Result<BoundaryEpochs, Error> {
6069
if let HeightOrTimestamp::Height(height) = self.height_or_timestamp {
6170
let prev_last = height - (height % prev_fork_spec.epoch_length);
@@ -137,12 +146,11 @@ impl BoundaryEpochs {
137146
if current_epoch_block_number == 0 {
138147
return 0;
139148
}
140-
// first or under
149+
// Before HF
141150
if current_epoch_block_number <= self.prev_last {
142151
return current_epoch_block_number - self.previous_fork_spec.epoch_length;
143152
}
144153

145-
// Hit mids eppchs
146154
for (i, mid) in self.intermediates.iter().enumerate() {
147155
if current_epoch_block_number == *mid {
148156
if i == 0 {
@@ -153,7 +161,6 @@ impl BoundaryEpochs {
153161
}
154162
}
155163

156-
// is just current HF first
157164
if current_epoch_block_number == self.current_first {
158165
if self.intermediates.is_empty() {
159166
return self.prev_last;
@@ -227,7 +234,6 @@ pub fn get_boundary_epochs(
227234
current_spec: &ForkSpec,
228235
fork_specs: &[ForkSpec],
229236
) -> Result<BoundaryEpochs, Error> {
230-
// find from last to first
231237
for (i, spec) in fork_specs.iter().enumerate() {
232238
if spec == current_spec {
233239
if i == 0 {

light-client/src/header/eth_header.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -402,7 +402,7 @@ impl TryFrom<RawETHHeader> for ETHHeader {
402402
type Error = Error;
403403

404404
/// This includes part of header verification.
405-
/// - verifyHeader: https://github.com/bnb-chain/bsc/blob/b4773e8b5080f37e1c65c083b543f60c895abb70/consensus/parlia/parlia.go#L324
405+
/// - verifyHeader: https://github.com/bnb-chain/bsc/blob/5735d8a56540e8f2fb26d5585de0fa3959bb17b4/consensus/parlia/parlia.go#L562
406406
fn try_from(value: RawETHHeader) -> Result<Self, Self::Error> {
407407
let mut rlp = RlpIterator::new(Rlp::new(value.header.as_slice()));
408408
let parent_hash: Vec<u8> = rlp.try_next_as_val()?;

proto/definitions/ibc/lightclients/parlia/v1/parlia.proto

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,8 +12,6 @@ message ForkSpec {
1212
uint64 height = 1;
1313
uint64 timestamp = 2;
1414
}
15-
// The number of headers prior to Pascal HF is set to 0.
16-
// For example, the number of headers before Pascal HF is set to 1 because of the addition of the requestsHash.
1715
uint64 additional_header_item_count = 3;
1816
uint64 epoch_length = 4;
1917
uint64 max_turn_length = 5;

proto/src/prost/ibc.lightclients.parlia.v1.rs

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,6 @@
11
#[allow(clippy::derive_partial_eq_without_eq)]
22
#[derive(Clone, PartialEq, ::prost::Message)]
33
pub struct ForkSpec {
4-
/// The number of headers prior to Pascal HF is set to 0.
5-
/// For example, the number of headers before Pascal HF is set to 1 because of the addition of the requestsHash.
64
#[prost(uint64, tag = "3")]
75
pub additional_header_item_count: u64,
86
#[prost(uint64, tag = "4")]

0 commit comments

Comments
 (0)