Remove caching for node connections (#10143)
This commit is contained in:
parent
589083ad7a
commit
696dc05dda
@ -39,9 +39,6 @@ extern crate log;
|
|||||||
|
|
||||||
use std::sync::Weak;
|
use std::sync::Weak;
|
||||||
|
|
||||||
use lru_cache::LruCache;
|
|
||||||
use parking_lot::Mutex;
|
|
||||||
|
|
||||||
use ethcore::client::{BlockChainClient, BlockId};
|
use ethcore::client::{BlockChainClient, BlockId};
|
||||||
use ethereum_types::{H256, Address};
|
use ethereum_types::{H256, Address};
|
||||||
use ethabi::FunctionOutputDecoder;
|
use ethabi::FunctionOutputDecoder;
|
||||||
@ -50,13 +47,10 @@ use devp2p::NodeId;
|
|||||||
|
|
||||||
use_contract!(peer_set, "res/peer_set.json");
|
use_contract!(peer_set, "res/peer_set.json");
|
||||||
|
|
||||||
const MAX_CACHE_SIZE: usize = 4096;
|
|
||||||
|
|
||||||
/// Connection filter that uses a contract to manage permissions.
|
/// Connection filter that uses a contract to manage permissions.
|
||||||
pub struct NodeFilter {
|
pub struct NodeFilter {
|
||||||
client: Weak<BlockChainClient>,
|
client: Weak<BlockChainClient>,
|
||||||
contract_address: Address,
|
contract_address: Address,
|
||||||
permission_cache: Mutex<LruCache<(H256, NodeId), bool>>,
|
|
||||||
}
|
}
|
||||||
|
|
||||||
impl NodeFilter {
|
impl NodeFilter {
|
||||||
@ -65,7 +59,6 @@ impl NodeFilter {
|
|||||||
NodeFilter {
|
NodeFilter {
|
||||||
client,
|
client,
|
||||||
contract_address,
|
contract_address,
|
||||||
permission_cache: Mutex::new(LruCache::new(MAX_CACHE_SIZE)),
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -77,18 +70,6 @@ impl ConnectionFilter for NodeFilter {
|
|||||||
None => return false,
|
None => return false,
|
||||||
};
|
};
|
||||||
|
|
||||||
let block_hash = match client.block_hash(BlockId::Latest) {
|
|
||||||
Some(block_hash) => block_hash,
|
|
||||||
None => return false,
|
|
||||||
};
|
|
||||||
|
|
||||||
let key = (block_hash, *connecting_id);
|
|
||||||
|
|
||||||
let mut cache = self.permission_cache.lock();
|
|
||||||
if let Some(res) = cache.get_mut(&key) {
|
|
||||||
return *res;
|
|
||||||
}
|
|
||||||
|
|
||||||
let address = self.contract_address;
|
let address = self.contract_address;
|
||||||
let own_low = H256::from_slice(&own_id[0..32]);
|
let own_low = H256::from_slice(&own_id[0..32]);
|
||||||
let own_high = H256::from_slice(&own_id[32..64]);
|
let own_high = H256::from_slice(&own_id[32..64]);
|
||||||
@ -103,7 +84,6 @@ impl ConnectionFilter for NodeFilter {
|
|||||||
false
|
false
|
||||||
});
|
});
|
||||||
|
|
||||||
cache.insert(key, allowed);
|
|
||||||
allowed
|
allowed
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user