Skip to content

Commit a554d8d

Browse files
committedMay 8, 2020
Don't broadcast orphan messages
Broadcasting orphan messages provides a spam attack vector where it's simple to create signed txs with invalid inputs and have nodes rebroadcast spam on your behalf. This PR prevents orphan transactions being broadcast. In a subsequent PR, we should broadcast orphns that get promoted to the unconfirmed pool if intermediate txs in a chain do arrive in the mempool.
1 parent 60e142a commit a554d8d

File tree

2 files changed

+11
-12
lines changed

2 files changed

+11
-12
lines changed
 

‎base_layer/core/src/mempool/service/inbound_handlers.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -135,7 +135,7 @@ where T: BlockchainBackend + 'static
135135
);
136136
let propagate = match tx_storage {
137137
TxStorageResponse::UnconfirmedPool => true,
138-
TxStorageResponse::OrphanPool => true,
138+
TxStorageResponse::OrphanPool => false,
139139
TxStorageResponse::PendingPool => true,
140140
TxStorageResponse::ReorgPool => false,
141141
TxStorageResponse::NotStored => false,

‎base_layer/core/tests/mempool.rs

+10-11
Original file line numberDiff line numberDiff line change
@@ -664,31 +664,30 @@ fn receive_and_propagate_transaction() {
664664
interval = Duration::from_millis(1000)
665665
);
666666
async_assert_eventually!(
667-
bob_node
667+
carol_node
668668
.mempool
669-
.has_tx_with_excess_sig(orphan_excess_sig.clone())
669+
.has_tx_with_excess_sig(tx_excess_sig.clone())
670670
.unwrap(),
671-
expect = TxStorageResponse::OrphanPool,
672-
max_attempts = 10,
673-
interval = Duration::from_millis(1000)
671+
expect = TxStorageResponse::PendingPool
674672
);
673+
// Carol got sent the orphan tx directly, so it will be in her mempool
675674
async_assert_eventually!(
676675
carol_node
677676
.mempool
678-
.has_tx_with_excess_sig(tx_excess_sig.clone())
677+
.has_tx_with_excess_sig(orphan_excess_sig.clone())
679678
.unwrap(),
680-
expect = TxStorageResponse::PendingPool,
679+
expect = TxStorageResponse::OrphanPool,
681680
max_attempts = 10,
682681
interval = Duration::from_millis(1000)
683682
);
683+
// It's difficult to test a negative here, but let's at least make sure that the orphan TX was not propagated
684+
// by the time we check it
684685
async_assert_eventually!(
685-
carol_node
686+
bob_node
686687
.mempool
687688
.has_tx_with_excess_sig(orphan_excess_sig.clone())
688689
.unwrap(),
689-
expect = TxStorageResponse::OrphanPool,
690-
max_attempts = 10,
691-
interval = Duration::from_millis(1000)
690+
expect = TxStorageResponse::NotStored,
692691
);
693692

694693
alice_node.comms.shutdown().await;

0 commit comments

Comments
 (0)