Description
Previously raised here: paritytech/polkadot-sdk#3473
Motivation
Was looking for a subscription (websocket pubsub) to monitor the live txpool/mempool for incoming extrinsics.
There is the author_pendingExtrinsics
RPC; but this gives a snapshot view of the txpool upon request.
Request
A new RPC endpoint which should simply allow a caller to subscribe to all incoming pending extrinsics.
Once a user subscribes, the RPC endpoint will stream out live incoming transactions (type Extrinsic
) in the Ready
state.
The transactions do not need to be finalized - as that defeats the purpose since the state has already been set.
Solution
A new subscription in the client/rpc-api/src/author/mod.rs
file.
Something like so:
/// Watch transaction txpool.
#[subscription(
name = "author_watchTxpool" => "author_txpoolUpdate",
unsubscribe = "author_unwatchTxpool",
item = sp_runtime::OpaqueExtrinsic, // Transaction (scale-encoded-extrinsic)
)]
fn watch_txpool(&self);
This should be fairly simple to implement (already have a local implementation building/streaming out to WS connection).
Example response (scale encoded extrinsic):
{"jsonrpc":"2.0","method":"author_txpoolUpdate","params":{"subscription":"GcJD5bwBSSzLMNIK","result":"0x8d018425451a4de12dccc2d166922fa938e900fcc4ed244f7826dbd9e7984784cd33ea3c23f24509fa4f77bf56c509692c4d1e20c7541d62677cf055d32e078d2b38a30cd2ab244cbde87b3ab88fcc8997da043e770a760186010031110001147375702032"}}
Potential concerns
If there are issues (DoS, etc.); maybe this could be put behind feature flags - similar to what's done in frontier for the ethereum txpool subscriptions.
Are you willing to help with this request?
Yes!