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

feat: use get_pooled_transaction_elements in network manager #4329

Merged
merged 1 commit into from
Aug 23, 2023
Merged
Show file tree
Hide file tree
Changes from all 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
22 changes: 11 additions & 11 deletions crates/net/network/src/transactions.rs
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,8 @@ use reth_primitives::{
};
use reth_rlp::Encodable;
use reth_transaction_pool::{
error::PoolResult, PoolTransaction, PropagateKind, PropagatedTransactions, TransactionPool,
ValidPoolTransaction,
error::PoolResult, GetPooledTransactionLimit, PoolTransaction, PropagateKind,
PropagatedTransactions, TransactionPool, ValidPoolTransaction,
};
use std::{
collections::{hash_map::Entry, HashMap},
Expand All @@ -52,6 +52,10 @@ const MAX_FULL_TRANSACTIONS_PACKET_SIZE: usize = 100 * 1024;
/// <https://github.com/ethereum/devp2p/blob/master/caps/eth.md#newpooledtransactionhashes-0x08>
const GET_POOLED_TRANSACTION_SOFT_LIMIT_NUM_HASHES: usize = 256;

/// Softlimit for the response size of a GetPooledTransactions message (2MB)
const GET_POOLED_TRANSACTION_SOFT_LIMIT_SIZE: GetPooledTransactionLimit =
GetPooledTransactionLimit::SizeSoftLimit(2 * 1024 * 1024);

/// The future for inserting a function into the pool
pub type PoolImportFuture = Pin<Box<dyn Future<Output = PoolResult<TxHash>> + Send + 'static>>;

Expand Down Expand Up @@ -182,19 +186,15 @@ where
response: oneshot::Sender<RequestResult<PooledTransactions>>,
) {
if let Some(peer) = self.peers.get_mut(&peer_id) {
// TODO softResponseLimit 2 * 1024 * 1024
let transactions = self
.pool
.get_all(request.0)
.into_iter()
.map(|tx| tx.transaction.to_recovered_transaction().into_signed())
.collect::<Vec<_>>();
.get_pooled_transaction_elements(request.0, GET_POOLED_TRANSACTION_SOFT_LIMIT_SIZE);

// we sent a response at which point we assume that the peer is aware of the transaction
peer.transactions.extend(transactions.iter().map(|tx| tx.hash()));
// we sent a response at which point we assume that the peer is aware of the
// transactions
peer.transactions.extend(transactions.iter().map(|tx| *tx.hash()));

// TODO: remove this! this will be different when we introduce the blobpool
let resp = PooledTransactions(transactions.into_iter().map(Into::into).collect());
let resp = PooledTransactions(transactions);
let _ = response.send(Ok(resp));
}
}
Expand Down
11 changes: 4 additions & 7 deletions crates/transaction-pool/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -165,10 +165,7 @@ use std::{
use tokio::sync::mpsc::Receiver;
use tracing::{instrument, trace};

use crate::{
blobstore::{BlobStore, BlobStoreError},
traits::GetPooledTransactionLimit,
};
use crate::blobstore::{BlobStore, BlobStoreError};
pub use crate::{
config::{
PoolConfig, PriceBumpConfig, SubPoolLimit, DEFAULT_PRICE_BUMP, REPLACE_BLOB_PRICE_BUMP,
Expand All @@ -183,9 +180,9 @@ pub use crate::{
},
traits::{
AllPoolTransactions, BestTransactions, BlockInfo, CanonicalStateUpdate, ChangedAccount,
EthPooledTransaction, NewTransactionEvent, PendingTransactionListenerKind, PoolSize,
PoolTransaction, PropagateKind, PropagatedTransactions, TransactionOrigin, TransactionPool,
TransactionPoolExt,
EthPooledTransaction, GetPooledTransactionLimit, NewTransactionEvent,
PendingTransactionListenerKind, PoolSize, PoolTransaction, PropagateKind,
PropagatedTransactions, TransactionOrigin, TransactionPool, TransactionPoolExt,
},
validate::{
EthTransactionValidator, TransactionValidationOutcome, TransactionValidationTaskExecutor,
Expand Down
Loading