Skip to content

Commit 4a57acf

Browse files
author
Naohiro Yoshida
committed
fix conflict
Signed-off-by: Naohiro Yoshida <naohiro.yoshida@datachain.jp>
2 parents 4689816 + b9685da commit 4a57acf

File tree

5 files changed

+28
-23
lines changed

5 files changed

+28
-23
lines changed

README.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -25,5 +25,5 @@ Parameters can be specified to check for acceptable headers at build time.
2525

2626
| Name | Description |
2727
| --- |------------------------------------------------------------------------------------------------------------------------------|
28-
| `MINIMUM_TIMESTAMP_SUPPORTED` | Timestamp(millisecond) of the lowest header this light client will accept. All the ForkSpec must be greater than this value. |
29-
| `MINIMUM_HEIGHT_SUPPORTED` | Height of the lowest header this light client will accept. All the ForkSpec must be greater than this value. |
28+
| `MINIMUM_TIMESTAMP_SUPPORTED` | Timestamp(millisecond) of the lowest header this light client will accept. All the ForkSpec must be greater than or equal to this value. |
29+
| `MINIMUM_HEIGHT_SUPPORTED` | Height of the lowest header this light client will accept. All the ForkSpec must be greater than or equal to this value. |

light-client/src/client.rs

Lines changed: 20 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -150,6 +150,8 @@ impl LightClient for ParliaLightClient {
150150
}
151151
}
152152

153+
const NANO_TO_MILLIS: u128 = 1_000_000;
154+
153155
struct InnerLightClient;
154156

155157
impl InnerLightClient {
@@ -166,7 +168,7 @@ impl InnerLightClient {
166168

167169
let height = client_state.latest_height;
168170
let timestamp = consensus_state.timestamp;
169-
let milli_timestamp = (timestamp.as_unix_timestamp_nanos() / 1_000_000) as u64;
171+
let milli_timestamp = (timestamp.as_unix_timestamp_nanos() / NANO_TO_MILLIS) as u64;
170172

171173
#[allow(clippy::absurd_extreme_comparisons)]
172174
if milli_timestamp < MINIMUM_TIMESTAMP_SUPPORTED {
@@ -187,21 +189,20 @@ impl InnerLightClient {
187189

188190
verify_sorted_asc(&client_state.fork_specs)?;
189191

190-
for spec in &client_state.fork_specs {
191-
match spec.height_or_timestamp {
192-
HeightOrTimestamp::Height(height) =>
193-
{
194-
#[allow(clippy::absurd_extreme_comparisons)]
195-
if height < MINIMUM_HEIGHT_SUPPORTED {
196-
return Err(Error::UnsupportedMinimumHeightForkSpec(height));
197-
}
192+
let first = client_state.fork_specs.first().unwrap();
193+
match first.height_or_timestamp {
194+
HeightOrTimestamp::Height(height) =>
195+
{
196+
#[allow(clippy::absurd_extreme_comparisons)]
197+
if height < MINIMUM_HEIGHT_SUPPORTED {
198+
return Err(Error::UnsupportedMinimumHeightForkSpec(height));
198199
}
199-
HeightOrTimestamp::Time(time) =>
200-
{
201-
#[allow(clippy::absurd_extreme_comparisons)]
202-
if time < MINIMUM_TIMESTAMP_SUPPORTED {
203-
return Err(Error::UnsupportedMinimumTimestampForkSpec(time));
204-
}
200+
}
201+
HeightOrTimestamp::Time(time) =>
202+
{
203+
#[allow(clippy::absurd_extreme_comparisons)]
204+
if time < MINIMUM_TIMESTAMP_SUPPORTED {
205+
return Err(Error::UnsupportedMinimumTimestampForkSpec(time));
205206
}
206207
}
207208
}
@@ -519,7 +520,7 @@ mod test {
519520
use rstest::rstest;
520521
use time::macros::datetime;
521522

522-
use crate::client::ParliaLightClient;
523+
use crate::client::{ParliaLightClient, NANO_TO_MILLIS};
523524
use crate::client_state::ClientState;
524525
use crate::consensus_state::ConsensusState;
525526

@@ -636,12 +637,12 @@ mod test {
636637

637638
let cs = ConsensusState::try_from(any_consensus_state).unwrap();
638639
assert_eq!(
639-
(data.timestamp.as_unix_timestamp_nanos() / 1_000_000) as u64,
640+
(data.timestamp.as_unix_timestamp_nanos() / NANO_TO_MILLIS) as u64,
640641
timestamp
641642
);
642643
assert_eq!(
643-
data.timestamp.as_unix_timestamp_nanos() / 1_000_000,
644-
cs.timestamp.as_unix_timestamp_nanos() / 1_000_000
644+
data.timestamp.as_unix_timestamp_nanos() / NANO_TO_MILLIS,
645+
cs.timestamp.as_unix_timestamp_nanos() / NANO_TO_MILLIS
645646
);
646647
assert_eq!(data.emitted_states[0].0, result.height);
647648
assert_eq!(data.emitted_states[0].1, any_client_state);

light-client/src/fork_spec.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -234,8 +234,8 @@ pub fn get_boundary_epochs(
234234

235235
/// Verifies that the given list of `ForkSpec` is sorted in ascending order.
236236
///
237-
/// This function checks that the `ForkSpec` list is sorted by either height or timestamp
238-
/// in ascending order. If the list is not sorted correctly, it returns an error.
237+
/// HEIGHT should be sorted by HEIGHT and TIMESTAMP should be sorted by TIMESTAMP.
238+
/// As an operational constraint, ForkSpec should be submitted in HF order
239239
pub fn verify_sorted_asc(fork_specs: &[ForkSpec]) -> Result<(), Error> {
240240
let mut last_height: Option<u64> = None;
241241
let mut last_timestamp: Option<u64> = None;

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

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,8 @@ 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.
1517
uint64 additional_header_item_count = 3;
1618
uint64 epoch_length = 4;
1719
uint64 max_turn_length = 5;

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

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
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.
46
#[prost(uint64, tag = "3")]
57
pub additional_header_item_count: u64,
68
#[prost(uint64, tag = "4")]

0 commit comments

Comments
 (0)