never speak of the verifier cache again (#3628)

This commit is contained in:
Antioch Peverell
2021-04-01 15:04:53 +01:00
committed by GitHub
parent cccaf98493
commit f6ec77a592
37 changed files with 189 additions and 735 deletions
+9 -23
View File
@@ -18,11 +18,9 @@
use self::core::core::hash::{Hash, Hashed};
use self::core::core::id::{ShortId, ShortIdentifiable};
use self::core::core::transaction;
use self::core::core::verifier_cache::VerifierCache;
use self::core::core::{
Block, BlockHeader, BlockSums, Committed, OutputIdentifier, Transaction, TxKernel, Weighting,
};
use self::util::RwLock;
use crate::types::{BlockChain, PoolEntry, PoolError};
use grin_core as core;
use grin_util as util;
@@ -31,29 +29,25 @@ use std::collections::{HashMap, HashSet};
use std::sync::Arc;
use util::static_secp_instance;
pub struct Pool<B, V>
pub struct Pool<B>
where
B: BlockChain,
V: VerifierCache,
{
/// Entries in the pool (tx + info + timer) in simple insertion order.
pub entries: Vec<PoolEntry>,
/// The blockchain
pub blockchain: Arc<B>,
pub verifier_cache: Arc<RwLock<V>>,
pub name: String,
}
impl<B, V> Pool<B, V>
impl<B> Pool<B>
where
B: BlockChain,
V: VerifierCache + 'static,
{
pub fn new(chain: Arc<B>, verifier_cache: Arc<RwLock<V>>, name: String) -> Self {
pub fn new(chain: Arc<B>, name: String) -> Self {
Pool {
entries: vec![],
blockchain: chain,
verifier_cache,
name,
}
}
@@ -162,11 +156,7 @@ where
// Validate the single aggregate transaction "as pool", not subject to tx weight limits.
let header = self.blockchain.chain_head()?;
tx.validate(
Weighting::NoLimit,
self.verifier_cache.clone(),
header.height,
)?;
tx.validate(Weighting::NoLimit, header.height)?;
Ok(Some(tx))
}
@@ -234,7 +224,7 @@ where
) -> Result<BlockSums, PoolError> {
// Validate the tx, conditionally checking against weight limits,
// based on weight verification type.
tx.validate(weighting, self.verifier_cache.clone(), header.height)?;
tx.validate(weighting, header.height)?;
// Validate the tx against current chain state.
// Check all inputs are in the current UTXO set.
@@ -414,12 +404,9 @@ where
// Otherwise discard and let the next block pick this tx up.
let bucket = &tx_buckets[pos];
if let Ok(new_bucket) = bucket.aggregate_with_tx(
entry.tx.clone(),
weighting,
self.verifier_cache.clone(),
height,
) {
if let Ok(new_bucket) =
bucket.aggregate_with_tx(entry.tx.clone(), weighting, height)
{
if new_bucket.fee_rate >= bucket.fee_rate {
// Only aggregate if it would not reduce the fee_rate ratio.
tx_buckets[pos] = new_bucket;
@@ -536,13 +523,12 @@ impl Bucket {
&self,
new_tx: Transaction,
weighting: Weighting,
verifier_cache: Arc<RwLock<dyn VerifierCache>>,
height: u64,
) -> Result<Bucket, PoolError> {
let mut raw_txs = self.raw_txs.clone();
raw_txs.push(new_tx);
let agg_tx = transaction::aggregate(&raw_txs)?;
agg_tx.validate(weighting, verifier_cache, height)?;
agg_tx.validate(weighting, height)?;
Ok(Bucket {
fee_rate: agg_tx.fee_rate(height),
raw_txs: raw_txs,
+10 -32
View File
@@ -19,7 +19,6 @@
use self::core::core::hash::{Hash, Hashed};
use self::core::core::id::ShortId;
use self::core::core::verifier_cache::VerifierCache;
use self::core::core::{
transaction, Block, BlockHeader, HeaderVersion, OutputIdentifier, Transaction, Weighting,
};
@@ -34,51 +33,38 @@ use std::collections::VecDeque;
use std::sync::Arc;
/// Transaction pool implementation.
pub struct TransactionPool<B, P, V>
pub struct TransactionPool<B, P>
where
B: BlockChain,
P: PoolAdapter,
V: VerifierCache,
{
/// Pool Config
pub config: PoolConfig,
/// Our transaction pool.
pub txpool: Pool<B, V>,
pub txpool: Pool<B>,
/// Our Dandelion "stempool".
pub stempool: Pool<B, V>,
pub stempool: Pool<B>,
/// Cache of previous txs in case of a re-org.
pub reorg_cache: Arc<RwLock<VecDeque<PoolEntry>>>,
/// The blockchain
pub blockchain: Arc<B>,
pub verifier_cache: Arc<RwLock<V>>,
/// The pool adapter
pub adapter: Arc<P>,
}
impl<B, P, V> TransactionPool<B, P, V>
impl<B, P> TransactionPool<B, P>
where
B: BlockChain,
P: PoolAdapter,
V: VerifierCache + 'static,
{
/// Create a new transaction pool
pub fn new(
config: PoolConfig,
chain: Arc<B>,
verifier_cache: Arc<RwLock<V>>,
adapter: Arc<P>,
) -> Self {
pub fn new(config: PoolConfig, chain: Arc<B>, adapter: Arc<P>) -> Self {
TransactionPool {
config,
txpool: Pool::new(chain.clone(), verifier_cache.clone(), "txpool".to_string()),
stempool: Pool::new(
chain.clone(),
verifier_cache.clone(),
"stempool".to_string(),
),
txpool: Pool::new(chain.clone(), "txpool".to_string()),
stempool: Pool::new(chain.clone(), "stempool".to_string()),
reorg_cache: Arc::new(RwLock::new(VecDeque::new())),
blockchain: chain,
verifier_cache,
adapter,
}
}
@@ -193,12 +179,8 @@ where
// Make sure the transaction is valid before anything else.
// Validate tx accounting for max tx weight.
tx.validate(
Weighting::AsTransaction,
self.verifier_cache.clone(),
header.height,
)
.map_err(PoolError::InvalidTx)?;
tx.validate(Weighting::AsTransaction, header.height)
.map_err(PoolError::InvalidTx)?;
// Check the tx lock_time is valid based on current chain state.
self.blockchain.verify_tx_lock_height(tx)?;
@@ -279,11 +261,7 @@ where
// Validate the tx to ensure our converted inputs are correct.
let header = self.chain_head()?;
tx.validate(
Weighting::AsTransaction,
self.verifier_cache.clone(),
header.height,
)?;
tx.validate(Weighting::AsTransaction, header.height)?;
Ok(PoolEntry::new(tx, entry.src))
}