less txhashset locking (#2163)
* less txhashset locking * rework server stats a bit
This commit is contained in:
@@ -260,6 +260,9 @@ impl p2p::ChainAdapter for NetToChainAdapter {
|
||||
|
||||
let max_height = self.chain().header_head().unwrap().height;
|
||||
|
||||
let txhashset = self.chain().txhashset();
|
||||
let txhashset = txhashset.read();
|
||||
|
||||
// looks like we know one, getting as many following headers as allowed
|
||||
let hh = header.height;
|
||||
let mut headers = vec![];
|
||||
@@ -268,7 +271,7 @@ impl p2p::ChainAdapter for NetToChainAdapter {
|
||||
break;
|
||||
}
|
||||
|
||||
if let Ok(header) = self.chain().get_header_by_height(h) {
|
||||
if let Ok(header) = txhashset.get_header_by_height(h) {
|
||||
headers.push(header);
|
||||
} else {
|
||||
error!("Failed to locate headers successfully.");
|
||||
@@ -399,9 +402,12 @@ impl NetToChainAdapter {
|
||||
|
||||
// Find the first locator hash that refers to a known header on our main chain.
|
||||
fn find_common_header(&self, locator: &[Hash]) -> Option<BlockHeader> {
|
||||
let txhashset = self.chain().txhashset();
|
||||
let txhashset = txhashset.read();
|
||||
|
||||
for hash in locator {
|
||||
if let Ok(header) = self.chain().get_block_header(&hash) {
|
||||
if let Ok(header_at_height) = self.chain().get_header_by_height(header.height) {
|
||||
if let Ok(header_at_height) = txhashset.get_header_by_height(header.height) {
|
||||
if header.hash() == header_at_height.hash() {
|
||||
return Some(header);
|
||||
}
|
||||
|
||||
@@ -374,6 +374,9 @@ impl Server {
|
||||
let tip_height = self.chain.head().unwrap().height as i64;
|
||||
let mut height = tip_height as i64 - last_blocks.len() as i64 + 1;
|
||||
|
||||
let txhashset = self.chain.txhashset();
|
||||
let txhashset = txhashset.read();
|
||||
|
||||
let diff_entries: Vec<DiffBlock> = last_blocks
|
||||
.windows(2)
|
||||
.map(|pair| {
|
||||
@@ -385,7 +388,7 @@ impl Server {
|
||||
// Use header hash if real header.
|
||||
// Default to "zero" hash if synthetic header_info.
|
||||
let hash = if height >= 0 {
|
||||
if let Ok(header) = self.chain.get_header_by_height(height as u64) {
|
||||
if let Ok(header) = txhashset.get_header_by_height(height as u64) {
|
||||
header.hash()
|
||||
} else {
|
||||
ZERO_HASH
|
||||
|
||||
Reference in New Issue
Block a user