Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 8 additions & 7 deletions src/core/chain.rs
Original file line number Diff line number Diff line change
Expand Up @@ -143,7 +143,7 @@ impl Chain {
let height = self.block_number + 1;

let (tx_hash_list, quota) = {
let mut pool = self.pool.write().await;
let pool = self.pool.read().await;
let ret = pool.package();
let (pool_len, pool_quota) = pool.pool_status();
info!(
Expand Down Expand Up @@ -301,8 +301,8 @@ impl Chain {
if let Some(Tx::UtxoTx(utxo_tx)) = raw_tx.tx.clone() {
let res = {
let mut auditor = self.auditor.write().await;
auditor.update_system_config(&utxo_tx);
let mut pool = self.pool.write().await;
auditor.update_system_config(&utxo_tx);
pool.update_system_config(&utxo_tx)
};
if res {
Expand All @@ -322,11 +322,12 @@ impl Chain {

let tx_hash_list =
get_tx_hash_list(block.body.as_ref().ok_or(StatusCodeEnum::NoneBlockBody)?)?;
self.auditor
.write()
.await
.insert_tx_hash(block_height, tx_hash_list.clone());
self.pool.write().await.remove(&tx_hash_list, block_height);
{
let mut auditor = self.auditor.write().await;
let mut pool = self.pool.write().await;
auditor.insert_tx_hash(block_height, tx_hash_list.clone());
pool.remove(&tx_hash_list, block_height);
}
info!(
"update auditor and pool, tx_hash_list len {}",
tx_hash_list.len()
Expand Down
10 changes: 3 additions & 7 deletions src/core/controller.rs
Original file line number Diff line number Diff line change
Expand Up @@ -237,16 +237,12 @@ impl Controller {
broadcast: bool,
) -> Result<Vec<u8>, StatusCodeEnum> {
let tx_hash = get_tx_hash(&raw_tx)?.to_vec();

{
let auditor = self.auditor.read().await;
auditor.auditor_check(&raw_tx)?;
}

crypto_check_async(Arc::new(raw_tx.clone())).await?;

let res = {
let auditor = self.auditor.read().await;
let mut pool = self.pool.write().await;
auditor.auditor_check(&raw_tx)?;
pool.insert(raw_tx.clone())
};
if res {
Expand Down Expand Up @@ -295,8 +291,8 @@ impl Controller {
let mut hashes = Vec::new();
{
let auditor = self.auditor.read().await;
auditor.auditor_check_batch(&raw_txs)?;
let mut pool = self.pool.write().await;
auditor.auditor_check_batch(&raw_txs)?;
for raw_tx in raw_txs.body.clone() {
let hash = get_tx_hash(&raw_tx)?.to_vec();
if pool.insert(raw_tx) {
Expand Down
6 changes: 3 additions & 3 deletions src/core/pool.rs
Original file line number Diff line number Diff line change
Expand Up @@ -135,7 +135,7 @@ impl Pool {
});
}

pub fn package(&mut self) -> (Vec<Vec<u8>>, u64) {
pub fn package(&self) -> (Vec<Vec<u8>>, u64) {
let system_config = &self.sys_config;
let mut quota_limit = system_config.quota_limit;
let mut pack_tx = vec![];
Expand Down Expand Up @@ -174,8 +174,8 @@ fn tx_is_valid(sys_config: &SystemConfig, raw_tx: &RawTransaction, height: u64)
match &raw_tx.tx {
Some(Tx::NormalTx(ref normal_tx)) => match normal_tx.transaction {
Some(ref tx) => {
height < tx.valid_until_block
&& tx.valid_until_block <= height + sys_config.block_limit
height <= tx.valid_until_block
&& tx.valid_until_block < height + sys_config.block_limit
}
None => false,
},
Expand Down
Loading