Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Definition of Transaction Gossip Disabling
Tx gossip disabling means there is no p2p communication related with transactions. More specifically, there must be no broadcasting and announcement. See ethereum/EIPs#2465 for more details about broadcasting and announcement. This is not erigon specifc, but an Ethereum spec.
Erigon-lib Txpool Implementation Structure
One liner:
fetch
➡️pool
➡️send
.Txpool must
txpool/fetch.go::handleInboundMessage
method.Fetch
struct is initialized.txpool/pool.go::AddRemoteTxs
method defined atPool
interface.newTxs <-
) for local tx. Done attxpool/pool.go::AddLocalTxs
method.sendTransaction
RPC is called.newTxs <-
) for remote transaction. Done attxpool/pool.go::processRemoteTxs
method.case <-processRemoteTxsEvery.C
) when txpool'sMainLoop
method is activated. It checks if there are received remote transactions at step 1.txpool/send.go::BroadcastPooledTxs
,txpool.send.go::AnnouncePooledTxs
.MainLoop
method is activated and announcements are ready from channel(case announcements := <-newTxs
).txpool/send.go::PropagatePooledTxsToPeersList
.Adding Disable Tx Gossip Option
To disable tx gossiping, I must turn off Step 1, 4, 5; to not listen remote tx and stop outbound p2p traffic.
To achieve this, I added field
NoTxGossip
boolean attxpoolCfg
struct.This value will be injected from initializing txpool by calling
txpool/txpooluitl/all_components.go::AllComponents
.When
NoTxGossip
flag is on,Pool
interface will be initialized using newly addedTxPoolDropRemote
struct.TxPoolDropRemote
inheritsTxPool
but overridesAddRemoteTxs
.AddRemoteTxs
method fromTxPool
implementation fills inunprocessedRemoteByHash
,unprocessedRemoteTx
. This unprocessed remote information will be consumed atprocessRemoteTxs
method.Stop Digesting Remote Transactions: Disabling Step 1 and Step 3
I disabled
AddRemoteTxs
to do nothing(empty implementation). ThereforeunprocessedRemoteByHash
,unprocessedRemoteTx
will be never filled. So even if we callprocessRemoteTxs
intxpool/pool.go::MainLoop
, it will have no effect. This change explicitly stops step 1, and implicitly stops step 3. There is no remote transactions stacked so no remote transactions to be processed.Stop Outbound P2P Traffic: Disabling Step 4
I patched
txpool/pool.go::MainLoop
to avoid callingtxpool/send.go::BroadcastPooledTxs
,txpool.send.go::AnnouncePooledTxs
when announcement was generated. By this way,newTx
channel will be emptied, not stacked forever. Even though I disabled announcement creation for remote transactions, there will be announcements created when callingAddLocalTx
method so emptying is necessary.Stop Outbound P2P Traffic: Disabling Step 5
I patched not to call
txpool/send.go::PropagatePooledTxsToPeersList
. We must clean new peers, sorecentlyConnectedPeers.GetAndClean
method must be called first.Testing
Added
txpool/pool_test.go::TestDropRemote
. It initializesTxPoolDropRemote
struct and checks below two conditions:AddRemoteTxs
method to do nothing.