From 7dbaeaafbafa9e7900fd76317b6e2b5c57f659d5 Mon Sep 17 00:00:00 2001 From: Peter Zhang Date: Fri, 28 Mar 2025 15:16:20 +0800 Subject: [PATCH] handle timestamp overflow --- Cargo.lock | 1 + node/pruner/Cargo.toml | 1 + node/pruner/src/lib.rs | 14 +++++++++++--- 3 files changed, 13 insertions(+), 3 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 1f9e39c..8d006c7 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -6425,6 +6425,7 @@ dependencies = [ "contract-interface", "ethereum-types 0.14.1", "ethers", + "ethers-core", "miner", "rand 0.8.5", "storage", diff --git a/node/pruner/Cargo.toml b/node/pruner/Cargo.toml index 9d033f4..8c84f7e 100644 --- a/node/pruner/Cargo.toml +++ b/node/pruner/Cargo.toml @@ -15,5 +15,6 @@ tracing = "0.1.40" ethereum-types = "0.14.1" contract-interface = { path = "../../common/contract-interface" } ethers = "^2" +ethers-core = { version = "^2" } zgs_spec = { path = "../../common/spec" } chrono = { version = "0.4", features = ["serde"] } diff --git a/node/pruner/src/lib.rs b/node/pruner/src/lib.rs index 09da3cc..bbba083 100644 --- a/node/pruner/src/lib.rs +++ b/node/pruner/src/lib.rs @@ -4,6 +4,7 @@ use contract_interface::ChunkLinearReward; use ethereum_types::Address; use ethers::prelude::{Http, Provider}; use ethers::providers::{HttpRateLimitRetryPolicy, RetryClient, RetryClientBuilder}; +use ethers_core::types::U256; use miner::MinerMessage; use rand::Rng; use std::cmp::Ordering; @@ -119,10 +120,17 @@ impl Pruner { // Check no reward chunks and prune. match self.reward_contract.first_rewardable_chunk().call().await { Ok((new_first_rewardable, chain_timestamp)) => { - if (Utc::now().timestamp() - (chain_timestamp.as_u64() as i64)).abs() > 60 * 60 - { + if chain_timestamp > U256::from(i64::MAX as u64) { + error!( + chain_timestamp = chain_timestamp.to_string(), + "chain timestamp is too large, skip pruning" + ); + continue; + } + let chain_ts = chain_timestamp.as_u64() as i64; + if (Utc::now().timestamp() - chain_ts).abs() > 60 * 60 { debug!( - chain_timestamp = chain_timestamp.as_u64(), + chain_timestamp = chain_ts, "chain timestamp is weird, skip pruning" ); continue;