bcoin-org / bcoin

Javascript bitcoin library for node.js and browsers
https://bcoin.io
Other
2.98k stars 811 forks source link

Adds Neutrino Client #1163

Open manavdesai27 opened 1 year ago

manavdesai27 commented 1 year ago

This pr implements neutrino client mode. This has the commit history cleaned for better reviewing.

  1. Added Neutrino node which will communicate with the network.

  2. Added

    • sendGetCFilters - Gets compact filters from peer.
    • sendGetCFHeaders - Gets Compact filter headers from peer.
    • sendGetCFCheckpt - Gets Filters using checkpoints
  3. Added saveFilter and saveFilterHeader methods in filterIndexer. While saving filterHeader I am keeping the filter field empty.

  4. Added NeutrinoState which helps to keep track of the filterHeaderHeight and the filterHeight

  5. Added

    • Headers-sync: This skips downloading the blocks and instead saves the block headers and once filter headers are synced, emits event called headersFull, which indicates that we can start fetching filter headers
    • Filter Headers Sync: Syncs filter headers and saves them after certain assertions. After all cfheaders are synced we emit cfheaders event, which indicates that we can start fetching filters.
    • Filters Sync: Syncs filters and saves them after certain assertions. After saving the filter, we emit cfilter event, which sends the filter to the wallet and marks beginning of filter matching for the particular filter.
  6. Added checkFilter: Checks the filter against all address hashes in the wallet db. Address hashes are first converted to output scripts and that is then matched against the filter.

  7. Added getBlockFromNode and getBlockPeer: These methods help the client to download a particular block when any filter matches on the wallet side.

  8. Added RPC methods:

    • getfiltercount: Gets the filter height in NeutrinoState
    • getfilterheadercount: Gets the filter header height in NeutrinoState
    • getblockfilterheader: Retrieves filter header for a particular block
codecov[bot] commented 1 year ago

Codecov Report

Patch coverage: 76.47% and project coverage change: +0.49 :tada:

Comparison is base (a4bf281) 70.26% compared to head (8e0bec0) 70.75%.

Additional details and impacted files ```diff @@ Coverage Diff @@ ## master #1163 +/- ## ========================================== + Coverage 70.26% 70.75% +0.49% ========================================== Files 174 175 +1 Lines 27367 27833 +466 ========================================== + Hits 19229 19693 +464 - Misses 8138 8140 +2 ``` | [Impacted Files](https://app.codecov.io/gh/bcoin-org/bcoin/pull/1163?src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=bcoin-org) | Coverage Δ | | |---|---|---| | [lib/bcoin-browser.js](https://app.codecov.io/gh/bcoin-org/bcoin/pull/1163?src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=bcoin-org#diff-bGliL2Jjb2luLWJyb3dzZXIuanM=) | `0.00% <0.00%> (ø)` | | | [lib/bcoin.js](https://app.codecov.io/gh/bcoin-org/bcoin/pull/1163?src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=bcoin-org#diff-bGliL2Jjb2luLmpz) | `0.00% <0.00%> (ø)` | | | [lib/blockchain/layout.js](https://app.codecov.io/gh/bcoin-org/bcoin/pull/1163?src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=bcoin-org#diff-bGliL2Jsb2NrY2hhaW4vbGF5b3V0Lmpz) | `100.00% <ø> (ø)` | | | [lib/client/node.js](https://app.codecov.io/gh/bcoin-org/bcoin/pull/1163?src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=bcoin-org#diff-bGliL2NsaWVudC9ub2RlLmpz) | `25.86% <0.00%> (-1.42%)` | :arrow_down: | | [lib/node/fullnode.js](https://app.codecov.io/gh/bcoin-org/bcoin/pull/1163?src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=bcoin-org#diff-bGliL25vZGUvZnVsbG5vZGUuanM=) | `85.42% <ø> (+0.88%)` | :arrow_up: | | [lib/protocol/networks.js](https://app.codecov.io/gh/bcoin-org/bcoin/pull/1163?src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=bcoin-org#diff-bGliL3Byb3RvY29sL25ldHdvcmtzLmpz) | `100.00% <ø> (ø)` | | | [lib/wallet/client.js](https://app.codecov.io/gh/bcoin-org/bcoin/pull/1163?src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=bcoin-org#diff-bGliL3dhbGxldC9jbGllbnQuanM=) | `0.00% <0.00%> (ø)` | | | [lib/wallet/nullclient.js](https://app.codecov.io/gh/bcoin-org/bcoin/pull/1163?src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=bcoin-org#diff-bGliL3dhbGxldC9udWxsY2xpZW50Lmpz) | `87.50% <ø> (ø)` | | | [lib/node/http.js](https://app.codecov.io/gh/bcoin-org/bcoin/pull/1163?src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=bcoin-org#diff-bGliL25vZGUvaHR0cC5qcw==) | `58.20% <12.50%> (-1.74%)` | :arrow_down: | | [lib/node/rpc.js](https://app.codecov.io/gh/bcoin-org/bcoin/pull/1163?src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=bcoin-org#diff-bGliL25vZGUvcnBjLmpz) | `42.04% <52.00%> (+0.17%)` | :arrow_up: | | ... and [10 more](https://app.codecov.io/gh/bcoin-org/bcoin/pull/1163?src=pr&el=tree-more&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=bcoin-org) | | ... and [4 files with indirect coverage changes](https://app.codecov.io/gh/bcoin-org/bcoin/pull/1163/indirect-changes?src=pr&el=tree-more&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=bcoin-org)

:umbrella: View full report in Codecov by Sentry.
:loudspeaker: Do you have feedback about the report comment? Let us know in this issue.