Skip to content

Conversation

@MuhtasimTanmoy
Copy link
Contributor

@MuhtasimTanmoy MuhtasimTanmoy commented Jan 3, 2026

What was wrong?

#886

How was it fixed?

#1104

To-Do

Review

@MuhtasimTanmoy
Copy link
Contributor Author

Screenshot 2026-01-03 at 10 18 28 AM

Comment on lines 712 to 715
let now = SystemTime::now()
.duration_since(UNIX_EPOCH)
.expect("System time is before UNIX epoch")
.as_secs();
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Isn't this expect() comment misleading?, I think we should avoid expect here, handle the exception intentionally and safely

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Referenced from here.

.expect("System time is before UNIX epoch")

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah I will be removing those in a PR I am working on

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

  let now = SystemTime::now()
                      .duration_since(UNIX_EPOCH)
                      .unwrap_or(Duration::MAX)// remaining <= 0 will be true if error
                      .as_secs();
        let remaining = lean_network_spec().genesis_time - now;

        if remaining <= 0 {
            info!("Genesis reached! Starting services...");
            break;
        }

Does this look ok? Or should safely log error for that specific case?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

let remaining = lean_network_spec().genesis_time.saturating_sub(now);

You should do a saturating sub then to avoid underflows

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

let now = SystemTime::now()
                      .duration_since(UNIX_EPOCH)
                      .unwrap_or(Duration::MAX)
                      .as_secs();
let remaining = lean_network_spec().genesis_time.saturating_sub(now);

if remaining == 0 {
    info!("Genesis reached! Starting services...");
    break;
}

If this looks okay, then will update the PR.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Remove the // remaining <= 0 will be true if error

also if now == Duration::MAX we should not print anything and just immediately break

So maybe do

 let now = match SystemTime::now()
                      .duration_since(UNIX_EPOCH) {
                           Ok(now) => now.as_secs(),
                           // The chain is already past genesis, we don't need a countdown
                           Err(_) => break,
                      };
                      
let remaining = lean_network_spec().genesis_time.saturating_sub(now);

if remaining == 0 {
    info!("Genesis reached! Starting services...");
    break;
}

^ so do something like this

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I didn't suggest that looking at the full context, so you might need to make further modifications

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I tested.

Comment on lines 714 to 725
let now = match SystemTime::now().duration_since(UNIX_EPOCH) {
Ok(now) => now.as_secs(),
// The chain is already past genesis, we don't need a countdown
Err(_) => break,
};

let remaining = lean_network_spec().genesis_time.saturating_sub(now);

if remaining == 0 {
info!("Genesis reached! Starting services...");
break;
}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
let now = match SystemTime::now().duration_since(UNIX_EPOCH) {
Ok(now) => now.as_secs(),
// The chain is already past genesis, we don't need a countdown
Err(_) => break,
};
let remaining = lean_network_spec().genesis_time.saturating_sub(now);
if remaining == 0 {
info!("Genesis reached! Starting services...");
break;
}
let now = SystemTime::now()
.duration_since(UNIX_EPOCH)
.unwrap_or(Duration::MAX)
.as_secs();
let genesis = lean_network_spec().genesis_time;
if now >= genesis {
if now <= genesis + 2 {
info!("Genesis reached! Starting services...");
}
break;
}

After reading the code a bit more, could you do this ^

@MuhtasimTanmoy MuhtasimTanmoy changed the title Add countdown log till genesis feat: add countdown log till genesis Jan 3, 2026
@KolbyML KolbyML merged commit 0761b0b into ReamLabs:master Jan 3, 2026
15 of 16 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants