Zebra/zebra-network/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
..
address_book Security: Limit address book size to limit memory usage (#3162) 2021-12-06 16:09:10 -03:00
config Use the default port for configured listen addresses with no port (#2043) 2021-04-21 23:14:29 +00:00
isolated 2. Route peer requests based on missing inventory (#3465) 2022-02-08 01:16:41 +00:00
meta_addr Stop ignoring some peers when updating the address book (#3292) 2022-01-05 18:12:59 -05:00
peer Estimate network chain tip height based on local node time and current best tip (#3492) 2022-02-11 01:27:02 +00:00
peer_set Estimate network chain tip height based on local node time and current best tip (#3492) 2022-02-11 01:27:02 +00:00
protocol 1. Create an API for a missing inventory registry, but don't register any missing inventory yet (#3255) 2022-02-06 23:05:52 +00:00
address_book.rs 1. Fix some address crawler timing issues (#3293) 2022-01-04 18:43:30 -05:00
address_book_updater.rs feat(log): log the state tip height as part of sync progress logs (#3437) 2022-01-28 19:12:19 -03:00
config.rs T2. Add isolated Tor connection API, but don't enable it by default (#3303) 2022-01-25 01:46:31 +00:00
constants.rs fix(network): Add a send timeout to outbound peer messages (#3417) 2022-01-31 15:22:00 -03:00
isolated.rs T2. Add isolated Tor connection API, but don't enable it by default (#3303) 2022-01-25 01:46:31 +00:00
lib.rs T2. Add isolated Tor connection API, but don't enable it by default (#3303) 2022-01-25 01:46:31 +00:00
meta_addr.rs Stop ignoring some peers when updating the address book (#3292) 2022-01-05 18:12:59 -05:00
peer.rs Test for message broadcast to the right number of peers (#3284) 2021-12-31 00:26:50 +00:00
peer_set.rs 1. Create an API for a missing inventory registry, but don't register any missing inventory yet (#3255) 2022-02-06 23:05:52 +00:00
policies.rs Fix syncer download order and add sync tests (#3168) 2022-01-11 14:11:35 -03:00
protocol.rs Refactor protocol into internal, external modules. 2019-11-27 05:06:01 -05:00