handle timestamp overflow

This commit is contained in:
Peter Zhang 2025-03-28 15:16:20 +08:00
parent be14ba647d
commit 7dbaeaafba
3 changed files with 13 additions and 3 deletions

1
Cargo.lock generated
View File

@ -6425,6 +6425,7 @@ dependencies = [
"contract-interface",
"ethereum-types 0.14.1",
"ethers",
"ethers-core",
"miner",
"rand 0.8.5",
"storage",

View File

@ -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"] }

View File

@ -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;