nervosnetwork / ckb

The Nervos CKB is a public permissionless blockchain, and the layer 1 of Nervos network.
https://www.nervos.org
MIT License
1.15k stars 228 forks source link

Print duration needed to reach assume_valid_target in the Header Sync phase. #4437

Closed eval-exec closed 4 months ago

eval-exec commented 4 months ago

What problem does this PR solve?

This PR let CKB print duration needed to reach to DEFAULT_ASSUME_VALID_TARGET in log

2024-04-28 06:12:02.343 +00:00 BlockDownload INFO ckb_sync::synchronizer  best known header number: 8760000, hash: Byte32(0x323b52e2309b15bb5d1bc0e3497da2905b14e2014313e1d01c8cea816b55e361), CKB is reaching the assume valid target: Byte32(0xc394fa4c5e5032c49f3502d4fd8054ead76ff693a54ac90757e441b5119afcaf) Please wait. It will take about 7.7 minutes to reach the assume valid target
2024-04-28 06:12:03.727 +00:00 BlockDownload INFO ckb_sync::synchronizer  best known header number: 8770000, hash: Byte32(0xd383dacd15a1db0b746f1af2c20b845cc89222485f975a4084990c74da6904af), CKB is reaching the assume valid target: Byte32(0xc394fa4c5e5032c49f3502d4fd8054ead76ff693a54ac90757e441b5119afcaf) Please wait. It will take about 7.6 minutes to reach the assume valid target
2024-04-28 06:12:05.104 +00:00 BlockDownload INFO ckb_sync::synchronizer  best known header number: 8780000, hash: Byte32(0x1e16b3079422c122acd30eaef0525a17f9828be5a3ceba79c72e9c7d69b75245), CKB is reaching the assume valid target: Byte32(0xc394fa4c5e5032c49f3502d4fd8054ead76ff693a54ac90757e441b5119afcaf) Please wait. It will take about 7.5 minutes to reach the assume valid target

https://github.com/nervosnetwork/ckb/pull/4254#issuecomment-1840263490

print duration need to reach DEFAULT_ASSUME_VALID_TARGET in Header Sync phase

If ckb run is specified with a custom --assume-valid-target, the corresponding height of this target is not known temporarily, so it is currently not possible to calculate the time needed to reach this target.

Related changes

Check List

Tests

Side effects

Release note

None: Exclude this PR from the release note.
eval-exec commented 4 months ago

Propose a new approach: Calculate Header Sync progress and "time remaining to sync to the highest tip Header" using the timestamps of the genesis block and the latest tip header.