mirror of
https://github.com/hl-archive-node/nanoreth.git
synced 2025-12-06 10:59:55 +00:00
small refactoring (#6531)
This commit is contained in:
@ -97,10 +97,7 @@ impl BlockBuffer {
|
||||
parent_hash: &BlockHash,
|
||||
) -> Vec<SealedBlockWithSenders> {
|
||||
// remove parent block if present
|
||||
let mut removed = Vec::new();
|
||||
if let Some(block) = self.remove_block(parent_hash) {
|
||||
removed.push(block);
|
||||
}
|
||||
let mut removed = self.remove_block(parent_hash).into_iter().collect::<Vec<_>>();
|
||||
|
||||
removed.extend(self.remove_children(vec![*parent_hash]));
|
||||
self.metrics.blocks.set(self.blocks.len() as f64);
|
||||
@ -157,14 +154,11 @@ impl BlockBuffer {
|
||||
/// The block might be missing from other collections, the method will only ensure that it has
|
||||
/// been removed.
|
||||
fn remove_block(&mut self, hash: &BlockHash) -> Option<SealedBlockWithSenders> {
|
||||
if let Some(block) = self.blocks.remove(hash) {
|
||||
self.remove_from_earliest_blocks(block.number, hash);
|
||||
self.remove_from_parent(block.parent_hash, hash);
|
||||
self.lru.pop(hash);
|
||||
Some(block)
|
||||
} else {
|
||||
None
|
||||
}
|
||||
let block = self.blocks.remove(hash)?;
|
||||
self.remove_from_earliest_blocks(block.number, hash);
|
||||
self.remove_from_parent(block.parent_hash, hash);
|
||||
self.lru.pop(hash);
|
||||
Some(block)
|
||||
}
|
||||
|
||||
/// Remove all children and their descendants for the given blocks and return them.
|
||||
|
||||
@ -224,12 +224,14 @@ impl BlockIndices {
|
||||
/// Remove chain from indices and return dependent chains that need to be removed.
|
||||
/// Does the cleaning of the tree and removing blocks from the chain.
|
||||
pub fn remove_chain(&mut self, chain: &Chain) -> BTreeSet<BlockChainId> {
|
||||
let mut lose_chains = BTreeSet::new();
|
||||
for (block_number, block) in chain.blocks().iter() {
|
||||
let block_hash = block.hash();
|
||||
lose_chains.extend(self.remove_block(*block_number, block_hash))
|
||||
}
|
||||
lose_chains
|
||||
chain
|
||||
.blocks()
|
||||
.iter()
|
||||
.flat_map(|(block_number, block)| {
|
||||
let block_hash = block.hash();
|
||||
self.remove_block(*block_number, block_hash)
|
||||
})
|
||||
.collect()
|
||||
}
|
||||
|
||||
/// Remove Blocks from indices.
|
||||
|
||||
@ -22,6 +22,7 @@
|
||||
// FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
|
||||
// DEALINGS IN THE SOFTWARE.
|
||||
|
||||
use crate::stream::HasRemoteAddr;
|
||||
use std::{
|
||||
convert::TryFrom as _,
|
||||
io,
|
||||
@ -38,8 +39,6 @@ use tokio::{
|
||||
net::TcpStream,
|
||||
};
|
||||
|
||||
use crate::stream::HasRemoteAddr;
|
||||
|
||||
/// Meters bandwidth usage of streams
|
||||
#[derive(Debug)]
|
||||
struct BandwidthMeterInner {
|
||||
|
||||
@ -128,12 +128,7 @@ impl<Client, Pool, Tasks, Builder> BasicPayloadJobGenerator<Client, Pool, Tasks,
|
||||
/// Returns the pre-cached reads for the given parent block if it matches the cached state's
|
||||
/// block.
|
||||
fn maybe_pre_cached(&self, parent: B256) -> Option<CachedReads> {
|
||||
let pre_cached = self.pre_cached.as_ref()?;
|
||||
if pre_cached.block == parent {
|
||||
Some(pre_cached.cached.clone())
|
||||
} else {
|
||||
None
|
||||
}
|
||||
self.pre_cached.as_ref().filter(|pc| pc.block == parent).map(|pc| pc.cached.clone())
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@ -74,10 +74,7 @@ impl TransportReceiverT for Receiver {
|
||||
|
||||
/// Returns a Future resolving when the server sent us something back.
|
||||
async fn receive(&mut self) -> Result<ReceivedMessage, Self::Error> {
|
||||
match self.inner.next().await {
|
||||
None => Err(IpcError::Closed),
|
||||
Some(val) => Ok(ReceivedMessage::Text(val?)),
|
||||
}
|
||||
self.inner.next().await.map_or(Err(IpcError::Closed), |val| Ok(ReceivedMessage::Text(val?)))
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@ -35,11 +35,10 @@ where
|
||||
|
||||
/// Polls to accept a new incoming connection to the endpoint.
|
||||
pub(crate) fn poll_accept(&mut self, cx: &mut Context<'_>) -> Poll<<Self as Stream>::Item> {
|
||||
let res = match ready!(self.poll_next_unpin(cx)) {
|
||||
None => Err(io::Error::new(io::ErrorKind::ConnectionAborted, "ipc connection closed")),
|
||||
Some(conn) => conn,
|
||||
};
|
||||
Poll::Ready(res)
|
||||
Poll::Ready(ready!(self.poll_next_unpin(cx)).map_or(
|
||||
Err(io::Error::new(io::ErrorKind::ConnectionAborted, "ipc connection closed")),
|
||||
|conn| conn,
|
||||
))
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user