Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(network): send height to peers #4904

Merged
merged 5 commits into from
Aug 29, 2022
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 1 addition & 4 deletions zebra-network/src/peer/handshake.rs
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,6 @@ use tracing::{span, Level, Span};
use tracing_futures::Instrument;

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

Expand Down
12 changes: 11 additions & 1 deletion zebra-network/src/peer/minimum_peer_version.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
//! 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;

Expand Down Expand Up @@ -66,6 +66,16 @@ where
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
Expand Down