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

Separate mempool indexer #650

Closed
wants to merge 8 commits into from
Closed

Conversation

nodech
Copy link
Member

@nodech nodech commented Dec 10, 2018

Check full details: bcoin-org/bcash#117

Related Issues in bcoin: #594 and #499.

Summary:
This separate coin/tx indexer from the mempool and moves to its separate file.

  • Separate mempool indexer from the mempool.
  • Fix mempool indexer issues on reorg
  • Fix mempool indexer issues when recovering from persistent storage.
  • Add view to the add entry event.

Other PRs:

use before and after for setting up.
remove unnecessary methods
When restoring mempool from db, it returns transactions
sorted by txid. But indexer logic depends on transactions being
in dependency orders, so it does not have to deal with the orphan
logic.
This will change load method to use proper orphan handling and
emit events in order even on load.
@codecov-io
Copy link

Codecov Report

Merging #650 into master will increase coverage by 1.21%.
The diff coverage is 86.32%.

Impacted file tree graph

@@            Coverage Diff             @@
##           master     #650      +/-   ##
==========================================
+ Coverage   53.33%   54.55%   +1.21%     
==========================================
  Files         104      105       +1     
  Lines       27676    27725      +49     
  Branches     4738     4744       +6     
==========================================
+ Hits        14762    15126     +364     
+ Misses      12914    12599     -315
Impacted Files Coverage Δ
lib/node/fullnode.js 53.48% <25%> (-1.45%) ⬇️
lib/mempool/mempool.js 64.21% <68.18%> (+20.78%) ⬆️
lib/mempool/indexer.js 92.69% <92.69%> (ø)
lib/coins/compress.js 55.06% <0%> (-1.27%) ⬇️
lib/primitives/block.js 66.33% <0%> (+0.98%) ⬆️
lib/blockchain/chain.js 62.59% <0%> (+2.03%) ⬆️
lib/mempool/mempoolentry.js 85.36% <0%> (+20.12%) ⬆️

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 0b70a94...811fc0d. Read the comment docs.

@pinheadmz pinheadmz added enhancement Improving a current feature tests Has tests for code change is just an addtional test labels Jan 23, 2019
@braydonf braydonf added indexer mempool Related to the mempool labels Mar 26, 2019
@braydonf
Copy link
Contributor

In regards to the fix for #499 and #594 here is the scenario that would cause the issue:

  • Tip block has tx A and outputs: A[0], A[1].
  • Mempool tx B spends A[0].
  • Tip block becomes unconfirmed and all txs are added to the mempool including tx A, this would call indexEntry (and addEntry in the refactor) that would add the coins back to the mempool.
  • Mempool tx B has spent those outputs, so the coins should not be added back to the mempool.
  • The fix is checking that the outputs are spent, and removing them in the unconfirmed function for MempoolIndexer. This is tested in the block for "should make unconfirmed coins available".

Thanks @nodar-chkuaselidze for explanation of the above scenario.

@braydonf braydonf added the ready for review Ready to be reviewed label Mar 27, 2019
@braydonf
Copy link
Contributor

braydonf commented Mar 27, 2019

Taking a look at the persistence issue for the mempool, and it's also related to the coin index. As described in the commit 66042d8 the coin index depends on the order, and thus there is an issue when restoring, if the order is not correct. I've applied to same test to the current master branch 01a7156 to demonstrate the issue, see braydonf@73fab1a. The test will fail at assertions of the coin index size, the test will pass without these assertions (lines 664 and 644), and will pass with the assertions for the tx address index.

/**
* Find all transactions pertaining to a certain address.
* Note: this does not accept multiple addresses.
* @param {Address} addrs
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why does this function accept addrs instead of addr and then place the single address into an array to iterate over if it only accepts a single address?

@tynes tynes added the waiting for rebase The PR needs to be updated before it can be merged label Apr 16, 2019
@tynes
Copy link
Member

tynes commented Apr 16, 2019

This could be exported in lib/bcoin{-browser}.js like https://github.com/bcoin-org/bcoin/pull/758/files#diff-303d6ea5bde0409e0d148f538471662aR58

* @alias module:mempool.MempoolIndexerOptions
*/

class MempoolIndexerOptions {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

These options don't seem necessary since there is really only 1 option that it sets

for (const addr of addrs) {
const items = this.index.get(addr);

assert(items);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

These assert statements could use messages

@@ -404,8 +417,12 @@ class FullNode extends Node {
*/

async getCoinsByAddress(addrs) {
const mempool = this.mempool.getCoinsByAddress(addrs);
if (!this.mempoolIndex)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why return early here when there is no mempoolIndex? Can't there be coins that are in the chain db still?

@braydonf braydonf removed the ready for review Ready to be reviewed label Apr 16, 2019
@braydonf
Copy link
Contributor

These updates are not necessary with #758 and have included other fixes and updates well. It may be nice to separate the indexer and combine with lib/indexers and some point, but it's fairly small so I think can stay in lib/mempool.

@braydonf braydonf removed the waiting for rebase The PR needs to be updated before it can be merged label Apr 16, 2019
@braydonf
Copy link
Contributor

I've incorporated tests from this PR into #758

@nodech nodech closed this Apr 18, 2019
@nodech nodech deleted the mempool/index branch June 28, 2019 08:26
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement Improving a current feature indexer mempool Related to the mempool tests Has tests for code change is just an addtional test
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants