ZcashFoundation / zebra

Zcash - Financial Privacy in Rust 🦓
https://zfnd.org/zebra/
Apache License 2.0
404 stars 96 forks source link

Start disconnecting from outdated peers a few days before network upgrade activation #4545

Open teor2345 opened 2 years ago

teor2345 commented 2 years ago

Motivation

To avoid Zcash peer connection storms, we want to start disconnecting from outdated peers before network upgrade activation.

Specifications

Here is what zcashd does: https://zips.z.cash/zip-0201#network-coalescence

Designs

  1. If Zebra is close to a network upgrade, at regular intervals, randomly choose an outdated peer, and disconnect from it. This will make Zebra automatically reconnect to another peer in its address book.

Optional:

  1. 1875 might be needed to make sure we don't just reconnect to the same peer

  2. We might be able to re-use the ChangePeerConnections request from #7822, but add an "outdated peers only" filter to it.

Possible Implementation

Launch a peer set background task that waits until the block height has changed, checks if it is near a network upgrade, then sends a ChangePeerConnections { disconnect_outdated: true } request.

Then sleep until the next request could be sent, whether a request was sent or not. This avoids locking the state watch channel too much.

Out of Scope

optional changes 5. When connecting to peers, randomly choose a peer from `reconnection_peers`, rather than always choosing the first one. To prefer peers that are more likely to reconnect, randomly select two peer indexes using [sample](https://docs.rs/rand/latest/rand/seq/index/fn.sample.html), then return the peer at the lower index.

Compatibility

Here are the zcashd parameters:

For Zebra, we could use:

This makes the number of disconnections 2-6 times the peer set size. (The peer limits are 75 outbound and 125 inbound peers.) So if half the peers on the network are upgraded, Zebra should be connected to 75% - 98% upgraded peers when the network upgrade activates.

mpguerra commented 1 year ago

Hey team! Please add your planning poker estimate with Zenhub @arya2 @conradoplg @dconnolly @oxarbitrage @teor2345 @upbqdn

mpguerra commented 2 months ago

We might be able to defer this issue until after testnet activation, although we might also want to test it first on testnet...

oxarbitrage commented 1 month ago

After internal discussions and feedback from @str4d, we have concluded the following:

Therefore, we have decided to implement this feature, but it is not critical for NU6 development.