{"record":{"id":"46935283d2970b51","repo":"nautechsystems/nautilus_trader","slug":"finalized-block-timestamp-overflows-nanoseconds","errorCode":null,"errorMessage":"Finalized block timestamp overflows nanoseconds","messagePattern":"Finalized block timestamp overflows nanoseconds","errorType":"exception","errorClass":"anyhow::Error","httpStatus":null,"severity":"error","filePath":"crates/adapters/blockchain/src/execution/client.rs","lineNumber":2269,"sourceCode":"        \"Finalized Swap input {base_amount} does not match the persisted amount {}\",\n        plan.amount_in\n    );\n\n    let block = executor\n        .http_rpc_client\n        .block_by_number(included.block_number, false)\n        .await?;\n    anyhow::ensure!(\n        block.hash == included.receipt.block_hash,\n        \"Finalized block {} changed from {} to {} before fill emission\",\n        included.block_number,\n        included.receipt.block_hash,\n        block.hash\n    );\n    let timestamp_ns = block\n        .timestamp\n        .checked_mul(NANOSECONDS_IN_SECOND)\n        .ok_or_else(|| anyhow::anyhow!(\"Finalized block timestamp overflows nanoseconds\"))?;\n    let mut swap = event.to_pool_swap(\n        plan.pool.chain.clone(),\n        plan.instrument_id,\n        plan.pool.pool_identifier,\n        UnixNanos::from(timestamp_ns),\n    );\n    swap.calculate_trade_info(&plan.pool.token0, &plan.pool.token1, None)?;\n    let trade = swap\n        .trade_info\n        .as_ref()\n        .ok_or_else(|| anyhow::anyhow!(\"Finalized Swap has no calculated trade information\"))?;\n    anyhow::ensure!(\n        trade.order_side == OrderSide::Sell,\n        \"Finalized Swap side {} does not match Sell order\",\n        trade.order_side\n    );\n    let gas_cost = included\n        .receipt","sourceCodeStart":2251,"sourceCodeEnd":2287,"githubUrl":"https://github.com/nautechsystems/nautilus_trader/blob/2114cf6f761429e0adb5ca9596fcd7b895b16011/crates/adapters/blockchain/src/execution/client.rs#L2251-L2287","documentation":"Emitted when block.timestamp.checked_mul(NANOSECONDS_IN_SECOND) overflows while converting the finalized block's timestamp to nanoseconds for the fill's ts_event. A compliant EVM node reports timestamps in seconds, which cannot overflow a u64 when scaled by 1e9; overflow therefore indicates the node reported the timestamp in non-second units (e.g., milliseconds) or returned garbage.","triggerScenarios":"RPC node or proxy reporting block timestamps in milliseconds/microseconds instead of seconds; a misbehaving or malicious endpoint returning near-u64::MAX timestamps; custom chains that overload the timestamp field with non-second semantics.","commonSituations":"L2 nodes or gateway providers with non-standard timestamp units; test stubs generating block fixtures with arbitrary large timestamp values.","solutions":["Fetch the block with eth_getBlockByNumber and inspect the timestamp magnitude: seconds since epoch should be ~1.7e9; ~1.7e12 means milliseconds.","Switch to a consensus-compliant endpoint that reports seconds.","If you control the fixture/stub, generate timestamps in seconds.","Report non-second timestamps to the node operator as a spec violation."],"exampleFix":null,"handlingStrategy":"validation","validationCode":"const MIN_TS: u64 = 1_430_000_000;  // ~2015, post-genesis sanity floor\nconst MAX_TS: u64 = 4_102_444_800;  // year 2100\nfn timestamp_is_seconds(ts: u64) -> bool { (MIN_TS..=MAX_TS).contains(&ts) }","typeGuard":"fn block_timestamp_is_plausible(block: &RpcBlock) -> bool {\n    timestamp_is_seconds(block.timestamp)\n}","tryCatchPattern":"Catch the overflow, log the raw block.timestamp value, and treat the endpoint as non-compliant until its timestamp units are fixed; do not divide ad hoc to 'recover'.","preventionTips":["Monitor block timestamps from your RPC endpoints and alert when the magnitude leaves the seconds range.","Prefer nodes you control or reputable providers over custom gateways for execution."],"tags":["blockchain","block-timestamp","rpc","arithmetic-overflow"],"backgroundTag":"timestamp-unit-overflow","analyzedSha":"2114cf6f761429e0adb5ca9596fcd7b895b16011","analyzedAt":"2026-08-21T11:28:30.864Z","schemaVersion":2},"datasetVersion":"2026-08-22T09:17:25.309Z"}