Skip to content

Latest commit

 

History

History
78 lines (67 loc) · 3.59 KB

README.md

File metadata and controls

78 lines (67 loc) · 3.59 KB

Exploring different mempool listening methods

Different ways to listen to incoming mempool txs:

  • Filters (createFilter + poll it)
  • Subscriptions (push model)
  • Txpool api (probably useless since keep receiving same txs)
  • Graphql api (eip-1767, not thegraph! can subscribe + filter, as opposed to subscribe + querytx + filter locally with subscription model)

None of the free node providers have a graphql endpoint unfortunately. filters and txpools are only for one-off queries, so we will focus on subscriptions.

==================== Subscriptions ==================

There are 3 levels of subscription:

  1. receive all new pending txHashes (all providers, including alchemy)
  2. receive all new pending txs (only alchemy)
  3. received filtered pending txs (only alchemy) We will go through these one by one

1. txHashes only

> wscat -c $ALCHEMY_POLYGON_WSS_ENDPOINT
> {"jsonrpc":"2.0","id": 1, "method": "eth_subscribe", "params": ["newPendingTransactions"]}

2. full txs

> wscat -c $ALCHEMY_POLYGON_WSS_ENDPOINT
> {"jsonrpc":"2.0","id": 2, "method": "eth_subscribe", "params": ["alchemy_newFullPendingTransactions"]}

3. full filtered txs

Here we filter on quickswap's router

> wscat -c $ALCHEMY_POLYGON_WSS_ENDPOINT
> {"jsonrpc":"2.0","id": 1, "method": "eth_subscribe", "params": ["alchemy_filteredNewFullPendingTransactions", {"address": "0xa5E0829CaCEd8fFDD4De3c43696c57F7D7A678ff"}]}

We can get the same results in ts using alchemy's web3 extension

import { createAlchemyWeb3 } from "@alch/alchemy-web3";
const web3 = createAlchemyWeb3(process.env.ALCHEMY_POLYGON_WSS_ENDPOINT);
web3.eth.subscribe(
  "pendingTransactions", // or "alchemy_fullPendingTransactions" or "alchemy_filteredFullPendingTransactions"
  async function (error, tx) {
    // do something with tx
  })

==================== Benchmarks ==================

  1. setup
npm i
export ALCHEMY_WSS_ENDPOINT=...
  1. run Alchemy fullTxs api benchmark
> npx ts-node alchemyFullTxStats.ts

This prints summary statistics for how many (what %) of txs received from Alchemy were

  • already mined (numTxsAlreadyMined)
  • not found when queried a second time (numTxsNotFound)

RESULTS

// POLYGON MAINNET
numTxs: 1377, numTxsAlreadyMined: 340 (24.7%), numTxsNotFound: 484 (35.1%)
numTxs: 5053, numTxsAlreadyMined: 1253 (24.8%), numTxsNotFound: 1968 (38.9%)
// ETHEREUM MAINNET
numTxs: 3750, numTxsAlreadyMined: 0 (0.0%), numTxsNotFound: 2769 (73.8%)
numTxs: 8063, numTxsAlreadyMined: 0 (0.0%), numTxsNotFound: 6172 (76.5%)

FUTURE

It would be nice in the future to also reproduce these 2020 benchmarks:

  1. Blocknative's locally missed mempool txs benchmark

  1. Makerdao's mempool latency benchmark