2

In outer node, i want to create a node that does not listen to gossiped transaction or in other words the transaction pool should not add any transaction from other peers, the only way to add transactions is done by the local node himself using pool.submit_one() method.

PS: even when closing all the rpc ports, its still adds transactions and i assume its low level using libp2p.

1 Answer 1

2

Yes, transactions are gossiped via libp2p networking. If you don't want to receive/send transactions via libp2p networking you need to change the following code:

let (network, system_rpc_tx, tx_handler_controller, network_starter, sync_service) =
        sc_service::build_network(sc_service::BuildNetworkParams {
        config: &config,
        client: client.clone(),
        transaction_pool: transaction_pool.clone(),
        spawn_handle: task_manager.spawn_handle(),
        import_queue,
        block_announce_validator_builder: None,
        warp_sync_params: Some(WarpSyncParams::WithProvider(warp_sync)),
    })?;

transaction_pool is the thing you need to change. You will need to provide your own implementation of the TransactionPool trait:

struct DummyTxPool;

impl<B> sc_network_transactions::config::TransactionPool<Block::Hash, B>
    for DummyTxPool
where
    B: BlockT,
{
    fn transactions(&self) -> Vec<(H, B::Extrinsic)> {
        // Don't propagate any transactions
        vec![]
    }

    fn hash_of(&self, tx: &B::Extrinsic) -> H {
        sp_runtime::traits::HashFor::<B>::hash_of(tx)
    }

    fn import(&self, _: B::Extrinsic) -> TransactionImportFuture {
        // We just ignore the import request.
        async { TransactionImport::None }.boxed()
    }

    fn on_broadcasted(&self, _: HashMap<H, Vec<String>>) {}

    fn transaction(&self, _: &H) -> Option<B::Extrinsic> {
        None
    }
}

Then you need to set transaction_pool to DummyTxPool. If you maybe want to still propagate your own local transactions, you need to modify transactions to return the ones you want to propagate.

6
  • so i should i use the old transaction pool everywhere else except when building the network paramters i should i pass my custom pool ? and this way i'll avoid libp2p gossiped messages
    – dadzerlaze
    Apr 18, 2023 at 13:55
  • Yes exactly that is the way.
    – bkchr
    Apr 18, 2023 at 13:59
  • it does not work, BuildNetworkParams does not require the pool to implement sc_network_transactions::config::TransactionPool, so none of those methods are actually called
    – dadzerlaze
    Apr 19, 2023 at 14:59
  • sorry i meant build_network() function not BuildNetworkParams
    – dadzerlaze
    Apr 19, 2023 at 15:07
  • You are right, the MaintainedTransactionPool bound is wrong. maintained_pool could be implemented right now by doing nothing. However, I also opened a pr to use the correct bound: github.com/paritytech/substrate/pull/13959
    – bkchr
    Apr 20, 2023 at 8:22

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.