go-ethereum/common
Mars 0e69530c6e
Some checks are pending
/ Linux Build (push) Waiting to run
/ Linux Build (arm) (push) Waiting to run
/ Windows Build (push) Waiting to run
/ Docker Image (push) Waiting to run
all: improve ETA calculation across all progress indicators (#32521)
### Summary
Fixes long-standing ETA calculation errors in progress indicators that
have been present since February 2021. The current implementation
produces increasingly inaccurate estimates due to integer division
precision loss.

### Problem

3aeccadd04/triedb/pathdb/history_indexer.go (L541-L553)
The ETA calculation has two critical issues:
1. **Integer division precision loss**: `speed` is calculated as
`uint64`
2. **Off-by-one**: `speed` uses `+ 1`(2 times) to avoid division by
zero, however it makes mistake in the final calculation

This results in wildly inaccurate time estimates that don't improve as
progress continues.

### Example
Current output during state history indexing:
```
lvl=info msg="Indexing state history" processed=16858580 left=41802252 elapsed=18h22m59.848s eta=11h36m42.252s
```

**Expected calculation:**
- Speed: 16858580 ÷ 66179848ms = 0.255 blocks/ms  
- ETA: 41802252 ÷ 0.255 = ~45.6 hours

**Current buggy calculation:**
- Speed: rounds to 1 block/ms
- ETA: 41802252 ÷ 1 = ~11.6 hours 

### Solution
- Created centralized `CalculateETA()` function in common package
- Replaced all 8 duplicate code copies across the codebase

### Testing
Verified accurate ETA calculations during archive node reindexing with
significantly improved time estimates.
2025-09-01 13:47:02 +08:00
..
bitutil accounts/usbwallet, common/bitutil: fix broken links in docs (#29078) 2024-03-13 07:54:40 +01:00
compiler common/compiler: json unmarshalling error checks (#25449) 2022-08-01 13:47:21 +02:00
fdlimit fix: linter warning (#25192) 2022-06-29 10:54:57 +02:00
hexutil common, common/hexutil: use reflect.TypeFor (#32321) 2025-08-07 14:30:03 +02:00
lru core/rawdb: integrate eradb backend for RPC (#31604) 2025-06-03 10:47:38 +02:00
math all: use fmt.Appendf instead of fmt.Sprintf where possible (#31301) 2025-03-25 14:53:02 +01:00
mclock common/mclock: add Alarm (#26333) 2023-01-03 12:10:48 +01:00
prque common/prque: fix godoc comments (#29460) 2024-04-06 11:09:30 +02:00
big.go all: use uint256 in state (#28598) 2024-01-23 14:51:58 +01:00
bytes.go internal/ethapi: add db operations to api (#24739) 2022-04-27 08:37:48 +02:00
bytes_test.go all: simplify and fix database iteration with prefix/start (#20808) 2020-04-15 14:08:53 +03:00
debug.go common: rename unused function with typo (#23025) 2021-06-10 10:53:23 +03:00
eta.go all: improve ETA calculation across all progress indicators (#32521) 2025-09-01 13:47:02 +08:00
eta_test.go all: improve ETA calculation across all progress indicators (#32521) 2025-09-01 13:47:02 +08:00
format.go common: improve pretty duration regex (#25073) 2022-06-14 14:08:43 +02:00
path.go build: get rid of ci.go -> common direct dependency (#30637) 2024-10-20 14:54:06 +03:00
range.go eth/filters: implement log filter using new log index (#31080) 2025-03-17 18:59:04 +01:00
range_test.go eth/filters: implement log filter using new log index (#31080) 2025-03-17 18:59:04 +01:00
size.go core, cmd, vendor: fixes and database inspection tool (#15) 2019-05-16 10:39:34 +03:00
size_test.go common: increase StorageSize test coverage (#25188) 2022-06-29 12:13:00 +02:00
test_utils.go all: replace uses of ioutil with io and os (#24869) 2022-05-16 11:59:35 +02:00
types.go common, common/hexutil: use reflect.TypeFor (#32321) 2025-08-07 14:30:03 +02:00
types_test.go common: using ParseUint instead of ParseInt (#30020) 2024-06-19 11:06:52 +02:00