track opts when requesting blocks (not just if we requested them) (#3089)
This commit is contained in:
@@ -118,7 +118,7 @@ impl p2p::ChainAdapter for NetToChainAdapter {
|
||||
&self,
|
||||
b: core::Block,
|
||||
peer_info: &PeerInfo,
|
||||
was_requested: bool,
|
||||
opts: chain::Options,
|
||||
) -> Result<bool, chain::Error> {
|
||||
if self.chain().block_exists(b.hash())? {
|
||||
return Ok(true);
|
||||
@@ -132,7 +132,7 @@ impl p2p::ChainAdapter for NetToChainAdapter {
|
||||
b.outputs().len(),
|
||||
b.kernels().len(),
|
||||
);
|
||||
self.process_block(b, peer_info, was_requested)
|
||||
self.process_block(b, peer_info, opts)
|
||||
}
|
||||
|
||||
fn compact_block_received(
|
||||
@@ -165,7 +165,7 @@ impl p2p::ChainAdapter for NetToChainAdapter {
|
||||
hook.on_block_received(&block, &peer_info.addr);
|
||||
}
|
||||
}
|
||||
self.process_block(block, peer_info, false)
|
||||
self.process_block(block, peer_info, chain::Options::NONE)
|
||||
}
|
||||
Err(e) => {
|
||||
debug!("Invalid hydrated block {}: {:?}", cb_hash, e);
|
||||
@@ -176,7 +176,7 @@ impl p2p::ChainAdapter for NetToChainAdapter {
|
||||
// check at least the header is valid before hydrating
|
||||
if let Err(e) = self
|
||||
.chain()
|
||||
.process_block_header(&cb.header, self.chain_opts(false))
|
||||
.process_block_header(&cb.header, chain::Options::NONE)
|
||||
{
|
||||
debug!("Invalid compact block header {}: {:?}", cb_hash, e.kind());
|
||||
return Ok(!e.is_bad_data());
|
||||
@@ -220,11 +220,11 @@ impl p2p::ChainAdapter for NetToChainAdapter {
|
||||
.is_ok()
|
||||
{
|
||||
debug!("successfully hydrated block from tx pool!");
|
||||
self.process_block(block, peer_info, false)
|
||||
self.process_block(block, peer_info, chain::Options::NONE)
|
||||
} else {
|
||||
if self.sync_state.status() == SyncStatus::NoSync {
|
||||
debug!("adapter: block invalid after hydration, requesting full block");
|
||||
self.request_block(&cb.header, peer_info);
|
||||
self.request_block(&cb.header, peer_info, chain::Options::NONE);
|
||||
Ok(true)
|
||||
} else {
|
||||
debug!("block invalid after hydration, ignoring it, cause still syncing");
|
||||
@@ -255,9 +255,7 @@ impl p2p::ChainAdapter for NetToChainAdapter {
|
||||
|
||||
// pushing the new block header through the header chain pipeline
|
||||
// we will go ask for the block if this is a new header
|
||||
let res = self
|
||||
.chain()
|
||||
.process_block_header(&bh, self.chain_opts(false));
|
||||
let res = self.chain().process_block_header(&bh, chain::Options::NONE);
|
||||
|
||||
if let Err(e) = res {
|
||||
debug!(
|
||||
@@ -298,7 +296,7 @@ impl p2p::ChainAdapter for NetToChainAdapter {
|
||||
}
|
||||
|
||||
// try to add headers to our header chain
|
||||
match self.chain().sync_block_headers(bhs, self.chain_opts(true)) {
|
||||
match self.chain().sync_block_headers(bhs, chain::Options::SYNC) {
|
||||
Ok(_) => Ok(true),
|
||||
Err(e) => {
|
||||
debug!("Block headers refused by chain: {:?}", e);
|
||||
@@ -533,7 +531,7 @@ impl NetToChainAdapter {
|
||||
&self,
|
||||
b: core::Block,
|
||||
peer_info: &PeerInfo,
|
||||
was_requested: bool,
|
||||
opts: chain::Options,
|
||||
) -> Result<bool, chain::Error> {
|
||||
// We cannot process blocks earlier than the horizon so check for this here.
|
||||
{
|
||||
@@ -549,10 +547,7 @@ impl NetToChainAdapter {
|
||||
let bhash = b.hash();
|
||||
let previous = self.chain().get_previous_header(&b.header);
|
||||
|
||||
match self
|
||||
.chain()
|
||||
.process_block(b, self.chain_opts(was_requested))
|
||||
{
|
||||
match self.chain().process_block(b, opts) {
|
||||
Ok(_) => {
|
||||
self.validate_chain(bhash);
|
||||
self.check_compact();
|
||||
@@ -571,7 +566,7 @@ impl NetToChainAdapter {
|
||||
&& !self.sync_state.is_syncing()
|
||||
{
|
||||
debug!("process_block: received an orphan block, checking the parent: {:}", previous.hash());
|
||||
self.request_block_by_hash(previous.hash(), peer_info)
|
||||
self.request_block(&previous, peer_info, chain::Options::NONE)
|
||||
}
|
||||
}
|
||||
Ok(true)
|
||||
@@ -646,12 +641,10 @@ impl NetToChainAdapter {
|
||||
// it into a full block then fallback to requesting the full block
|
||||
// from the same peer that gave us the compact block
|
||||
// consider additional peers for redundancy?
|
||||
fn request_block(&self, bh: &BlockHeader, peer_info: &PeerInfo) {
|
||||
self.request_block_by_hash(bh.hash(), peer_info)
|
||||
}
|
||||
|
||||
fn request_block_by_hash(&self, h: Hash, peer_info: &PeerInfo) {
|
||||
self.send_block_request_to_peer(h, peer_info, |peer, h| peer.send_block_request(h))
|
||||
fn request_block(&self, bh: &BlockHeader, peer_info: &PeerInfo, opts: Options) {
|
||||
self.send_block_request_to_peer(bh.hash(), peer_info, |peer, h| {
|
||||
peer.send_block_request(h, opts)
|
||||
})
|
||||
}
|
||||
|
||||
// After we have received a block header in "header first" propagation
|
||||
@@ -703,16 +696,6 @@ impl NetToChainAdapter {
|
||||
),
|
||||
}
|
||||
}
|
||||
|
||||
/// Prepare options for the chain pipeline
|
||||
fn chain_opts(&self, was_requested: bool) -> chain::Options {
|
||||
let opts = if was_requested {
|
||||
chain::Options::SYNC
|
||||
} else {
|
||||
chain::Options::NONE
|
||||
};
|
||||
opts
|
||||
}
|
||||
}
|
||||
|
||||
/// Implementation of the ChainAdapter for the network. Gets notified when the
|
||||
|
||||
@@ -138,7 +138,7 @@ impl BodySync {
|
||||
let mut peers_iter = peers.iter().cycle();
|
||||
for hash in hashes_to_get.clone() {
|
||||
if let Some(peer) = peers_iter.next() {
|
||||
if let Err(e) = peer.send_block_request(*hash) {
|
||||
if let Err(e) = peer.send_block_request(*hash, chain::Options::SYNC) {
|
||||
debug!("Skipped request to {}: {:?}", peer.info.addr, e);
|
||||
peer.stop();
|
||||
} else {
|
||||
|
||||
Reference in New Issue
Block a user