Wrap Blocks in Arc throughout codebase

This commit is contained in:
Jane Lusby 2020-06-04 16:31:48 -07:00 committed by Deirdre Connolly
parent 18b4dbc16c
commit 9bcda0f9c7
5 changed files with 9 additions and 10 deletions

View File

@ -33,7 +33,7 @@ pub(super) enum Handler {
GetPeers,
GetBlocksByHash {
hashes: HashSet<BlockHeaderHash>,
blocks: Vec<Block>,
blocks: Vec<Arc<Block>>,
},
FindBlocks,
}
@ -72,7 +72,7 @@ impl Handler {
Message::Block(block),
) => {
if hashes.remove(&BlockHeaderHash::from(block.as_ref())) {
blocks.push(*block);
blocks.push(block);
if hashes.is_empty() {
Finished(Ok(Response::Blocks(blocks)))
} else {
@ -435,7 +435,7 @@ where
Response::Blocks(blocks) => {
// Generate one block message per block.
for block in blocks.into_iter() {
if let Err(e) = self.peer_tx.send(Message::Block(Box::new(block))).await {
if let Err(e) = self.peer_tx.send(Message::Block(block)).await {
self.fail_with(e.into());
}
}

View File

@ -451,7 +451,7 @@ impl Codec {
}
fn read_block<R: Read>(&self, reader: R) -> Result<Message, Error> {
Ok(Message::Block(Box::new(Block::zcash_deserialize(reader)?)))
Ok(Message::Block(Block::zcash_deserialize(reader)?.into()))
}
fn read_getblocks<R: Read>(&self, mut reader: R) -> Result<Message, Error> {
@ -498,7 +498,7 @@ impl Codec {
}
fn read_tx<R: Read>(&self, rdr: R) -> Result<Message, Error> {
Ok(Message::Tx(Box::new(Transaction::zcash_deserialize(rdr)?)))
Ok(Message::Tx(Transaction::zcash_deserialize(rdr)?.into()))
}
fn read_mempool<R: Read>(&self, mut _reader: R) -> Result<Message, Error> {

View File

@ -1,7 +1,7 @@
//! Definitions of network messages.
use std::error::Error;
use std::net;
use std::{net, sync::Arc};
use chrono::{DateTime, Utc};
@ -132,7 +132,7 @@ pub enum Message {
/// A `block` message.
///
/// [Bitcoin reference](https://en.bitcoin.it/wiki/Protocol_documentation#block)
Block(Box<Block>),
Block(Arc<Block>),
/// A `getblocks` message.
///

View File

@ -2,6 +2,7 @@
use zebra_chain::block::{Block, BlockHeaderHash};
use crate::meta_addr::MetaAddr;
use std::sync::Arc;
/// A response to a network request, represented in internal format.
#[derive(Clone, Debug)]
@ -13,7 +14,7 @@ pub enum Response {
Peers(Vec<MetaAddr>),
/// A list of blocks.
Blocks(Vec<Block>),
Blocks(Vec<Arc<Block>>),
/// A list of block hashes.
BlockHeaderHashes(Vec<BlockHeaderHash>),

View File

@ -132,7 +132,6 @@ impl ConnectCmd {
Some(Ok(zebra_network::Response::Blocks(blocks))) => {
for block in blocks {
downloaded_block_heights.insert(block.coinbase_height().unwrap());
let block = block.into();
state
.ready_and()
.await
@ -153,7 +152,6 @@ impl ConnectCmd {
while let Some(Ok(zebra_network::Response::Blocks(blocks))) = block_requests.next().await {
for block in blocks {
downloaded_block_heights.insert(block.coinbase_height().unwrap());
let block = block.into();
state
.ready_and()
.await