Skip to content

Commit f072e2a

Browse files
committed
fix: replace panic with graceful error handling on system time failure (#717)
1 parent 20769e2 commit f072e2a

File tree

5 files changed

+7
-7
lines changed

5 files changed

+7
-7
lines changed

core/src/client/node.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -135,7 +135,7 @@ impl<N: NetworkSpec, C: Consensus<N::BlockResponse>, E: ExecutionProvider<N>> No
135135
async fn check_head_age(&self) -> Result<(), ClientError> {
136136
let timestamp = SystemTime::now()
137137
.duration_since(UNIX_EPOCH)
138-
.unwrap_or_else(|_| panic!("unreachable"))
138+
.unwrap_or_default()
139139
.as_secs();
140140

141141
let tag = BlockNumberOrTag::Latest.into();

ethereum/consensus-core/src/consensus_core.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -386,7 +386,7 @@ pub fn force_update<S: ConsensusSpec>(store: &mut LightClientStore<S>, current_s
386386
pub fn expected_current_slot(now: SystemTime, genesis_time: u64) -> u64 {
387387
let now = now
388388
.duration_since(UNIX_EPOCH)
389-
.unwrap_or_else(|_| panic!("unreachable"))
389+
.unwrap_or_default()
390390
.as_secs();
391391

392392
let since_genesis = now - genesis_time;

ethereum/src/consensus.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -459,7 +459,7 @@ impl<S: ConsensusSpec, R: ConsensusRpc<S>> Inner<S, R> {
459459

460460
let now = SystemTime::now()
461461
.duration_since(UNIX_EPOCH)
462-
.unwrap_or_else(|_| panic!("unreachable"))
462+
.unwrap_or_default()
463463
.as_secs();
464464

465465
let time_to_next_slot = next_slot_timestamp - now;
@@ -577,9 +577,9 @@ impl<S: ConsensusSpec, R: ConsensusRpc<S>> Inner<S, R> {
577577
let expected_time = self.slot_timestamp(slot);
578578
let now = SystemTime::now()
579579
.duration_since(UNIX_EPOCH)
580-
.unwrap_or_else(|_| panic!("unreachable"));
580+
.unwrap_or_default();
581581

582-
let delay = now - std::time::Duration::from_secs(expected_time);
582+
let delay = now.saturating_sub(std::time::Duration::from_secs(expected_time));
583583
chrono::Duration::from_std(delay).unwrap()
584584
}
585585

linea/src/consensus.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -127,7 +127,7 @@ impl Inner {
127127
{
128128
let now = SystemTime::now()
129129
.duration_since(UNIX_EPOCH)
130-
.unwrap_or_else(|_| panic!("unreachable"));
130+
.unwrap_or_default();
131131

132132
let timestamp = Duration::from_secs(block.header.timestamp);
133133
let age = now.saturating_sub(timestamp);

opstack/src/consensus.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -143,7 +143,7 @@ impl Inner {
143143
{
144144
let now = SystemTime::now()
145145
.duration_since(UNIX_EPOCH)
146-
.unwrap_or_else(|_| panic!("unreachable"));
146+
.unwrap_or_default();
147147

148148
let timestamp = Duration::from_secs(payload.timestamp);
149149
let age = now.saturating_sub(timestamp);

0 commit comments

Comments
 (0)