Skip to content

Commit 5276792

Browse files
authored
fix: replace panic with graceful error handling on system time failure (#724)
1 parent e1f9a50 commit 5276792

File tree

5 files changed

+7
-10
lines changed

5 files changed

+7
-10
lines changed

core/src/client/node.rs

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

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

ethereum/consensus-core/src/consensus_core.rs

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -384,10 +384,7 @@ pub fn force_update<S: ConsensusSpec>(store: &mut LightClientStore<S>, current_s
384384
}
385385

386386
pub fn expected_current_slot(now: SystemTime, genesis_time: u64) -> u64 {
387-
let now = now
388-
.duration_since(UNIX_EPOCH)
389-
.unwrap_or_else(|_| panic!("unreachable"))
390-
.as_secs();
387+
let now = now.duration_since(UNIX_EPOCH).unwrap_or_default().as_secs();
391388

392389
let since_genesis = now - genesis_time;
393390

ethereum/src/consensus.rs

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

490490
let now = SystemTime::now()
491491
.duration_since(UNIX_EPOCH)
492-
.unwrap_or_else(|_| panic!("unreachable"))
492+
.unwrap_or_default()
493493
.as_secs();
494494

495495
let time_to_next_slot = next_slot_timestamp - now;
@@ -607,9 +607,9 @@ impl<S: ConsensusSpec, R: ConsensusRpc<S>> Inner<S, R> {
607607
let expected_time = self.slot_timestamp(slot);
608608
let now = SystemTime::now()
609609
.duration_since(UNIX_EPOCH)
610-
.unwrap_or_else(|_| panic!("unreachable"));
610+
.unwrap_or_default();
611611

612-
let delay = now - std::time::Duration::from_secs(expected_time);
612+
let delay = now.saturating_sub(std::time::Duration::from_secs(expected_time));
613613
chrono::Duration::from_std(delay).unwrap()
614614
}
615615

linea/src/consensus.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -133,7 +133,7 @@ impl Inner {
133133
{
134134
let now = SystemTime::now()
135135
.duration_since(UNIX_EPOCH)
136-
.unwrap_or_else(|_| panic!("unreachable"));
136+
.unwrap_or_default();
137137

138138
let timestamp = Duration::from_secs(block.header.timestamp);
139139
let age = now.saturating_sub(timestamp);

opstack/src/consensus.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -149,7 +149,7 @@ impl Inner {
149149
{
150150
let now = SystemTime::now()
151151
.duration_since(UNIX_EPOCH)
152-
.unwrap_or_else(|_| panic!("unreachable"));
152+
.unwrap_or_default();
153153

154154
let timestamp = Duration::from_secs(payload.timestamp);
155155
let age = now.saturating_sub(timestamp);

0 commit comments

Comments
 (0)