@@ -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 ) ]
1316pub 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 {
0 commit comments