Skip to content

Commit

Permalink
Revert "Don't add transactions to a pool in non-validator nodes (#6713)"
Browse files Browse the repository at this point in the history
This reverts commit a361b25
  • Loading branch information
nikurt committed May 18, 2022
1 parent 8d2a9fe commit 9e7827c
Show file tree
Hide file tree
Showing 4 changed files with 8 additions and 30 deletions.
1 change: 0 additions & 1 deletion chain/chunks/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -491,7 +491,6 @@ impl ShardsManager {
network_adapter: Arc<dyn PeerManagerAdapter>,
rng_seed: RngSeed,
) -> Self {
TransactionPool::init_metrics();
Self {
me: me.clone(),
tx_pools: HashMap::new(),
Expand Down
5 changes: 2 additions & 3 deletions chain/client/src/client.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -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};
Expand Down
19 changes: 0 additions & 19 deletions chain/client/src/metrics.rs
Original file line number Diff line number Diff line change
Expand Up @@ -185,25 +185,6 @@ static NODE_BUILD_INFO: Lazy<IntCounterVec> = Lazy::new(|| {
.unwrap()
});

pub(crate) static TRANSACTION_RECEIVED_VALIDATOR: Lazy<IntGauge> = Lazy::new(|| {
try_create_int_gauge("near_transaction_received_validator", "Validator received a transaction")
.unwrap()
});
pub(crate) static TRANSACTION_RECEIVED_NON_VALIDATOR: Lazy<IntGauge> = 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<IntGauge> = 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
Expand Down
13 changes: 6 additions & 7 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.
transactions: BTreeMap<PoolKey, Vec<SignedTransaction>>,
pub transactions: BTreeMap<PoolKey, Vec<SignedTransaction>>,
/// Set of all hashes to quickly check if the given transaction is in the pool.
unique_transactions: HashSet<CryptoHash>,
pub 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,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);
Expand Down Expand Up @@ -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.
Expand Down

0 comments on commit 9e7827c

Please sign in to comment.