send starting height to peers (#4904)

Co-authored-by: mergify[bot] <37929162+mergify[bot]@users.noreply.github.com>
This commit is contained in:
Alfredo Garcia 2022-08-29 03:58:30 -03:00 committed by GitHub
parent d78026466e
commit c76a954033
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 12 additions and 5 deletions

View File

@ -27,7 +27,6 @@ use tracing::{span, Level, Span};
use tracing_futures::Instrument; use tracing_futures::Instrument;
use zebra_chain::{ use zebra_chain::{
block,
chain_tip::{ChainTip, NoChainTip}, chain_tip::{ChainTip, NoChainTip},
parameters::Network, parameters::Network,
serialization::SerializationError, serialization::SerializationError,
@ -580,9 +579,7 @@ where
address_from: AddrInVersion::new(our_listen_addr, our_services), address_from: AddrInVersion::new(our_listen_addr, our_services),
nonce: local_nonce, nonce: local_nonce,
user_agent: user_agent.clone(), user_agent: user_agent.clone(),
// The protocol works fine if we don't reveal our current block height, start_height: minimum_peer_version.chain_tip_height(),
// and not sending it means we don't need to be connected to the chain state.
start_height: block::Height(0),
relay, relay,
}; };

View File

@ -1,6 +1,6 @@
//! Watches for chain tip height updates to determine the minimum supported peer protocol version. //! Watches for chain tip height updates to determine the minimum supported peer protocol version.
use zebra_chain::{chain_tip::ChainTip, parameters::Network}; use zebra_chain::{block::Height, chain_tip::ChainTip, parameters::Network};
use crate::protocol::external::types::Version; use crate::protocol::external::types::Version;
@ -66,6 +66,16 @@ where
self.has_changed = true; self.has_changed = true;
} }
} }
/// Return the current chain tip height.
///
/// If it is not available return height zero.
pub fn chain_tip_height(&self) -> Height {
match self.chain_tip.best_tip_height() {
Some(height) => height,
None => Height(0),
}
}
} }
/// A custom [`Clone`] implementation to ensure that the first call to /// A custom [`Clone`] implementation to ensure that the first call to