Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

chain: remove redundant Add(tx) in zmq event #877

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

yyforyongyu
Copy link
Collaborator

This commit removes adding tx to mempool when received from rawtx zmq to prevent the same tx gets to be added multiple times since it will be notified multiple times. This also means we need to send the new tx in mempoolPoller to make sure the subscriber won't miss the event.

In details, when we subscribe to an input spend via NotifySpent, we do two things,

  1. register it via channel rescanUpdate,
  2. a quick lookup in our local mempool, if found return it

Meanwhile, filterTx has two relevant logic steps that,

  1. when an unconfirmed tx is received multiple times, only the first one will be processed.
  2. when processing the tx, it will notify if the tx is relevant, meaning it's registered via rescanUpdate.

In our second good case, if the tx is received via rawtx, then it will be sent to filterTx, but not registered via rescanUpdate. However, as long as the mempool poller also receives it and saves it to the local mempool, by the time we subscribe it, it will be found via step 2 in NotifySpent.

As in our bad case, when the tx is processed by filterTx, it won't be notified due to it's not registered, so not relevant. Then we subscribe, which registers it. However, by the time the mempool sees the tx and sends it to filterTx again, it will be ignored because filterTx has already seen it.

This commit removes adding tx to mempool when received from `rawtx` zmq
to prevent the same tx gets to be added multiple times since it will be
notified multiple times. This also means we need to send the new tx in
`mempoolPoller` to make sure the subscriber won't miss the event.

The two good cases,
1. subscribe the input, `LookupInputSpend` return false
2. tx seen by `rawtx` or mempool poller
3. notified in `filterTx`

1. tx seen by `rawtx` or mempool poller
2. subscribe the input
3. will be notified via `LookupInputSpend`

The bad case is,
1. sent by `rawtx`, which marks the tx as seen in `filterTx`
2. subscribe the input, `LoopupInputSpend` return false
3. sent by the mempool poller, `filterTx` will ignore this tx, thus the
   subscriber won't be notified
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

1 participant