Zebra/zebra-state/src
Janito Vaqueiro Ferreira Filho eb98b7a4b2
Estimate network chain tip height based on local node time and current best tip (#3492)
* Remove redundant documentation

The documentation was exactly the same as the documentation from the
trait.

* Calculate a mock time block delta for tests

Simulate a block being added to the chain with a random block time based
on the previous block time and the target spacing time.

* Add a `time` field to `ChainTipBlock`

Store the block time so that it's ready for a future chain that allows
obtaining the chain tip's block time.

* Add `ChainTip::best_tip_block_time` method

Allow obtaining the bes chain tip's block time.

* Add method to obtain both height and block time

Prevent any data races by returning both values so that they refer to
the same chain tip.

* Add `NetworkUpgrade::all_target_spacings` method

Returns all the target spacings defined for a network.

* Create a `NetworkChainTipEstimator` helper type

Isolate the code to calculate the height estimation in a new type, so
that it's easier to understand and doesn't decrease the readability of
the `chain_tip.rs` file.

* Add `ChainTip::estimate_network_chain_tip_height`

This is more of an extension method than a trait method. It uses the
`NetworkChainTipHeightEstimator` to actually perform the estimation, but
obtains the initial information from the current best chain tip.

* Fix typo in documentation

There was an extra closing bracket in the summary line.

* Refactor `MockChainTipSender` into a separate type

Prepare to allow mocking the block time of the best tip as well as the
block height.

* Allow sending mock best tip block times

Add a separate `watch` channel to send the best tip block times from a
`MockChainTipSender` to a `MockChainTip`.

The `best_tip_height_and_block_time` implementation will only return a
value if there's a height and a block time value for the best tip.

* Fix off-by-one height estimation error

Use Euclidean division to force the division result to round down
instead of rounding towards zero. This fixes an off-by-one error when
estimating a height that is lower than the current height, because the
fractionary result was being discarded, and it should have forced the
height to go one block back.

* Fix panics on local times very far in the past

Detect situations that might cause the block height estimate to
underflow, and return the genesis height instead.

* Fix another off-by-one height estimation error

The implementation of `chrono::Duration::num_seconds` adds one to the
number of seconds if it's negative. This breaks the division
calculation, so it has to be compensated for.

* Test network chain tip height estimation

Generate pairs of block heights and check that it's possible to estimate
the larger height from the smaller height and a displaced time
difference.
2022-02-11 01:27:02 +00:00
..
service Estimate network chain tip height based on local node time and current best tip (#3492) 2022-02-11 01:27:02 +00:00
tests Validate transaction lock times (#3060) 2021-11-23 05:53:53 +00:00
arbitrary.rs Estimate network chain tip height based on local node time and current best tip (#3492) 2022-02-11 01:27:02 +00:00
config.rs Replace `tempdir` dependency with `tempfile` (#3337) 2022-01-14 15:11:23 +00:00
constants.rs Fix interstitial sprout anchors check (#3283) 2022-01-18 20:18:49 +00:00
error.rs Validate sapling, orchard anchors (#3084) 2021-11-30 16:05:35 +00:00
lib.rs Consolidate standard lints into a cargo config file (#3386) 2022-01-24 16:25:06 +00:00
request.rs Stop calculating transaction hashes twice in the checkpoint verifier (#2696) 2021-08-31 10:55:39 +10:00
response.rs move `Utxo` type to zebra-chain (#2481) 2021-07-12 12:49:33 +10:00
service.rs feat(log): log the state tip height as part of sync progress logs (#3437) 2022-01-28 19:12:19 -03:00
tests.rs ZIP-221 and ZIP-244 commitment validation in non-finalized state (#2609) 2021-08-17 11:49:27 -03:00
util.rs feat(log): log the state tip height as part of sync progress logs (#3437) 2022-01-28 19:12:19 -03:00