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

chore: propagate network primitives to on_command, on_network_event #13084

Merged
merged 1 commit into from
Dec 3, 2024
Merged
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
88 changes: 44 additions & 44 deletions crates/net/network/src/transactions/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1005,51 +1005,9 @@ where
let _ = response.send(Ok(resp));
}
}
}

impl<Pool> TransactionsManager<Pool>
where
Pool: TransactionPool + 'static,
Pool::Transaction:
PoolTransaction<Consensus = TransactionSigned, Pooled: Into<PooledTransactionsElement>>,
{
/// Handles dedicated transaction events related to the `eth` protocol.
fn on_network_tx_event(&mut self, event: NetworkTransactionEvent) {
match event {
NetworkTransactionEvent::IncomingTransactions { peer_id, msg } => {
// ensure we didn't receive any blob transactions as these are disallowed to be
// broadcasted in full

let has_blob_txs = msg.has_eip4844();

let non_blob_txs = msg
.0
.into_iter()
.map(PooledTransactionsElement::try_from_broadcast)
.filter_map(Result::ok)
.collect();

self.import_transactions(peer_id, non_blob_txs, TransactionSource::Broadcast);

if has_blob_txs {
debug!(target: "net::tx", ?peer_id, "received bad full blob transaction broadcast");
self.report_peer_bad_transactions(peer_id);
}
}
NetworkTransactionEvent::IncomingPooledTransactionHashes { peer_id, msg } => {
self.on_new_pooled_transaction_hashes(peer_id, msg)
}
NetworkTransactionEvent::GetPooledTransactions { peer_id, request, response } => {
self.on_get_pooled_transactions(peer_id, request, response)
}
NetworkTransactionEvent::GetTransactionsHandle(response) => {
let _ = response.send(Some(self.handle()));
}
}
}

/// Handles a command received from a detached [`TransactionsHandle`]
fn on_command(&mut self, cmd: TransactionsCommand) {
fn on_command(&mut self, cmd: TransactionsCommand<N>) {
match cmd {
TransactionsCommand::PropagateHash(hash) => {
self.on_new_pending_transactions(vec![hash])
Expand Down Expand Up @@ -1089,7 +1047,7 @@ where
}

/// Handles a received event related to common network events.
fn on_network_event(&mut self, event_result: NetworkEvent) {
fn on_network_event(&mut self, event_result: NetworkEvent<PeerRequest<N>>) {
match event_result {
NetworkEvent::SessionClosed { peer_id, .. } => {
// remove the peer
Expand Down Expand Up @@ -1141,6 +1099,48 @@ where
_ => {}
}
}
}

impl<Pool> TransactionsManager<Pool>
where
Pool: TransactionPool + 'static,
Pool::Transaction:
PoolTransaction<Consensus = TransactionSigned, Pooled: Into<PooledTransactionsElement>>,
{
/// Handles dedicated transaction events related to the `eth` protocol.
fn on_network_tx_event(&mut self, event: NetworkTransactionEvent) {
match event {
NetworkTransactionEvent::IncomingTransactions { peer_id, msg } => {
// ensure we didn't receive any blob transactions as these are disallowed to be
// broadcasted in full

let has_blob_txs = msg.has_eip4844();

let non_blob_txs = msg
.0
.into_iter()
.map(PooledTransactionsElement::try_from_broadcast)
.filter_map(Result::ok)
.collect();

self.import_transactions(peer_id, non_blob_txs, TransactionSource::Broadcast);

if has_blob_txs {
debug!(target: "net::tx", ?peer_id, "received bad full blob transaction broadcast");
self.report_peer_bad_transactions(peer_id);
}
}
NetworkTransactionEvent::IncomingPooledTransactionHashes { peer_id, msg } => {
self.on_new_pooled_transaction_hashes(peer_id, msg)
}
NetworkTransactionEvent::GetPooledTransactions { peer_id, request, response } => {
self.on_get_pooled_transactions(peer_id, request, response)
}
NetworkTransactionEvent::GetTransactionsHandle(response) => {
let _ = response.send(Some(self.handle()));
}
}
}

/// Starts the import process for the given transactions.
fn import_transactions(
Expand Down
Loading