From 9e7827c64352dff84aa5cdbd2d001d9a5468ce6b Mon Sep 17 00:00:00 2001 From: Nikolay Kurtov Date: Wed, 18 May 2022 15:56:54 +0200 Subject: [PATCH] Revert "Don't add transactions to a pool in non-validator nodes (#6713)" This reverts commit a361b25e --- chain/chunks/src/lib.rs | 1 - chain/client/src/client.rs | 5 ++--- chain/client/src/metrics.rs | 19 ------------------- chain/pool/src/lib.rs | 13 ++++++------- 4 files changed, 8 insertions(+), 30 deletions(-) diff --git a/chain/chunks/src/lib.rs b/chain/chunks/src/lib.rs index 47f9a2a15ec..2869ab8c71e 100644 --- a/chain/chunks/src/lib.rs +++ b/chain/chunks/src/lib.rs @@ -491,7 +491,6 @@ impl ShardsManager { network_adapter: Arc, rng_seed: RngSeed, ) -> Self { - TransactionPool::init_metrics(); Self { me: me.clone(), tx_pools: HashMap::new(), diff --git a/chain/client/src/client.rs b/chain/client/src/client.rs index 530a070524e..f3e30a7286b 100644 --- a/chain/client/src/client.rs +++ b/chain/client/src/client.rs @@ -6,7 +6,7 @@ use std::sync::Arc; use std::time::{Duration, Instant}; use near_primitives::time::Clock; -use tracing::{debug, error, info, trace, warn}; +use tracing::{debug, error, info, warn, trace}; use near_chain::chain::{ ApplyStatePartsRequest, BlockCatchUpRequest, BlockMissingChunks, BlocksCatchUpState, @@ -15,8 +15,7 @@ use near_chain::chain::{ use near_chain::test_utils::format_hash; use near_chain::types::{AcceptedBlock, LatestKnown}; use near_chain::{ - BlockStatus, Chain, ChainGenesis, ChainStoreAccess, Doomslug, DoomslugThresholdMode, - Provenance, RuntimeAdapter, + BlockStatus, Chain, ChainGenesis, ChainStoreAccess, Doomslug, DoomslugThresholdMode, Provenance, RuntimeAdapter, }; use near_chain_configs::{ClientConfig, LogSummaryStyle}; use near_chunks::{ProcessPartialEncodedChunkResult, ShardsManager}; diff --git a/chain/client/src/metrics.rs b/chain/client/src/metrics.rs index 2b4bb0ef817..b6323b8fad0 100644 --- a/chain/client/src/metrics.rs +++ b/chain/client/src/metrics.rs @@ -185,25 +185,6 @@ static NODE_BUILD_INFO: Lazy = Lazy::new(|| { .unwrap() }); -pub(crate) static TRANSACTION_RECEIVED_VALIDATOR: Lazy = Lazy::new(|| { - try_create_int_gauge("near_transaction_received_validator", "Validator received a transaction") - .unwrap() -}); -pub(crate) static TRANSACTION_RECEIVED_NON_VALIDATOR: Lazy = Lazy::new(|| { - try_create_int_gauge( - "near_transaction_received_non_validator", - "Non-validator received a transaction", - ) - .unwrap() -}); -pub(crate) static TRANSACTION_RECEIVED_NON_VALIDATOR_FORWARDED: Lazy = Lazy::new(|| { - try_create_int_gauge( - "near_transaction_received_non_validator_forwarded", - "Non-validator received a forwarded transaction", - ) - .unwrap() -}); - /// Exports neard, protocol and database versions via Prometheus metrics. /// /// Sets metrics which export node’s max supported protocol version, used diff --git a/chain/pool/src/lib.rs b/chain/pool/src/lib.rs index 57565ffcd4c..b0d3d9dfabc 100644 --- a/chain/pool/src/lib.rs +++ b/chain/pool/src/lib.rs @@ -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. - transactions: BTreeMap>, + pub transactions: BTreeMap>, /// Set of all hashes to quickly check if the given transaction is in the pool. - unique_transactions: HashSet, + pub unique_transactions: HashSet, /// 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. @@ -36,11 +36,6 @@ 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); @@ -113,6 +108,10 @@ 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.