Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Don't add transactions to a pool in non-validator nodes #6713

Merged
merged 7 commits into from
May 2, 2022
Merged
Show file tree
Hide file tree
Changes from 3 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
1 change: 1 addition & 0 deletions chain/chunks/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -492,6 +492,7 @@ impl ShardsManager {
network_adapter: Arc<dyn PeerManagerAdapter>,
rng_seed: RngSeed,
) -> Self {
TransactionPool::init_metrics();
nikurt marked this conversation as resolved.
Show resolved Hide resolved
Self {
me: me.clone(),
tx_pools: HashMap::new(),
Expand Down
13 changes: 7 additions & 6 deletions chain/pool/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -17,9 +17,9 @@ pub struct TransactionPool {
/// Transactions are grouped by a pair of (account ID, signer public key).
/// NOTE: It's more efficient on average to keep transactions unsorted and with potentially
/// conflicting nonce than to create a BTreeMap for every transaction.
pub transactions: BTreeMap<PoolKey, Vec<SignedTransaction>>,
transactions: BTreeMap<PoolKey, Vec<SignedTransaction>>,
/// Set of all hashes to quickly check if the given transaction is in the pool.
pub unique_transactions: HashSet<CryptoHash>,
unique_transactions: HashSet<CryptoHash>,
/// A uniquely generated key seed to randomize PoolKey order.
key_seed: RngSeed,
/// The key after which the pool iterator starts. Doesn't have to be present in the pool.
Expand All @@ -36,6 +36,11 @@ impl TransactionPool {
}
}

pub fn init_metrics() {
// A `get()` call initializes a metric even if its value is zero.
metrics::TRANSACTION_POOL_TOTAL.get();
}

fn key(&self, account_id: &AccountId, public_key: &PublicKey) -> PoolKey {
let mut v = public_key.try_to_vec().unwrap();
v.extend_from_slice(&self.key_seed);
Expand Down Expand Up @@ -108,10 +113,6 @@ impl TransactionPool {
pub fn len(&self) -> usize {
self.unique_transactions.len()
}

pub fn is_empty(&self) -> bool {
self.unique_transactions.is_empty()
}
}

/// PoolIterator is a structure to pull transactions from the pool.
Expand Down