From 2da01b0d88df993a0ba54942cb2cf0b547e4d853 Mon Sep 17 00:00:00 2001 From: Andrei Kashin Date: Mon, 24 Apr 2023 17:38:25 +0200 Subject: [PATCH] Only store transactions on validator nodes (#8965) At the moment transactions are indefinitely stored on RPC nodes that are not validators (https://github.com/near/nearcore/issues/8878, https://github.com/near/nearcore/pull/6713). After this commit, nodes without validator keys will not store transactions in the transaction pool at all. --- chain/client/src/client.rs | 14 ++++++-------- 1 file changed, 6 insertions(+), 8 deletions(-) diff --git a/chain/client/src/client.rs b/chain/client/src/client.rs index e8885cac80c..788ab27fe4b 100644 --- a/chain/client/src/client.rs +++ b/chain/client/src/client.rs @@ -2006,20 +2006,18 @@ impl Client { } else if check_only { Ok(ProcessTxResponse::ValidTx) } else { - let active_validator = self.active_validator(shard_id)?; - - // TODO #6713: Transactions don't need to be recorded if the node is not a validator - // for the shard. - // If I'm not an active validator I should forward tx to next validators. - self.sharded_tx_pool.insert_transaction(shard_id, tx.clone()); - trace!(target: "client", shard_id, "Recorded a transaction."); + // Transactions only need to be recorded if the node is a validator. + if me.is_some() { + self.sharded_tx_pool.insert_transaction(shard_id, tx.clone()); + trace!(target: "client", shard_id, "Recorded a transaction."); + } // Active validator: // possibly forward to next epoch validators // Not active validator: // forward to current epoch validators, // possibly forward to next epoch validators - if active_validator { + if self.active_validator(shard_id)? { trace!(target: "client", account = ?me, shard_id, is_forwarded, "Recording a transaction."); metrics::TRANSACTION_RECEIVED_VALIDATOR.inc();