Skip to content

Commit

Permalink
refactor: ChainState use tx_pool_config.txs_verify_cache_size
Browse files Browse the repository at this point in the history
  • Loading branch information
jjyr committed Apr 7, 2019
1 parent 61855c6 commit ec08b01
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 20 deletions.
9 changes: 2 additions & 7 deletions shared/src/chain_state.rs
Expand Up @@ -36,12 +36,7 @@ pub struct ChainState<CI> {
}

impl<CI: ChainIndex> ChainState<CI> {
pub fn new(
store: &Arc<CI>,
consensus: Arc<Consensus>,
txs_verify_cache_size: usize,
tx_pool_config: TxPoolConfig,
) -> Self {
pub fn new(store: &Arc<CI>, consensus: Arc<Consensus>, tx_pool_config: TxPoolConfig) -> Self {
// check head in store or save the genesis block as head
let tip_header = {
let genesis = consensus.genesis_block();
Expand All @@ -54,8 +49,8 @@ impl<CI: ChainIndex> ChainState<CI> {
}
};

let txs_verify_cache = LruCache::new(tx_pool_config.txs_verify_cache_size);
let tx_pool = TxPool::new(tx_pool_config);
let txs_verify_cache = LruCache::new(txs_verify_cache_size);

let tip_number = tip_header.number();
let proposal_window = consensus.tx_proposal_window();
Expand Down
15 changes: 2 additions & 13 deletions shared/src/shared.rs
Expand Up @@ -38,19 +38,13 @@ impl<CI: ChainIndex> ::std::clone::Clone for Shared<CI> {
}

impl<CI: ChainIndex> Shared<CI> {
pub fn new(
store: CI,
consensus: Consensus,
txs_verify_cache_size: usize,
tx_pool_config: TxPoolConfig,
) -> Self {
pub fn new(store: CI, consensus: Consensus, tx_pool_config: TxPoolConfig) -> Self {
let store = Arc::new(store);
let consensus = Arc::new(consensus);
let chain_state = {
Arc::new(Mutex::new(ChainState::new(
&store,
Arc::clone(&consensus),
txs_verify_cache_size,
tx_pool_config,
)))
};
Expand Down Expand Up @@ -299,11 +293,6 @@ impl<DB: 'static + KeyValueDB> SharedBuilder<DB> {
let store = ChainKVStore::new(self.db.unwrap());
let consensus = self.consensus.unwrap_or_else(Consensus::default);
let tx_pool_config = self.tx_pool_config.unwrap_or_else(Default::default);
Shared::new(
store,
consensus,
tx_pool_config.txs_verify_cache_size,
tx_pool_config,
)
Shared::new(store, consensus, tx_pool_config)
}
}

0 comments on commit ec08b01

Please sign in to comment.