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

First implementation of services #2

Merged
merged 25 commits into from
Mar 2, 2022

Conversation

louisinger
Copy link
Collaborator

@louisinger louisinger commented Jan 5, 2022

This PR proposes the first implementation of NodeService and ScannerService.

The terminology of services and methods can differ from the ones discussed in #1. I finally splited the code into two services:

  • NodeService which basically aims to be a full elements node syncing block headers and block compact filters.
  • ScannerService which is the former "UtxoService", responsible of resolving "ScanRequest".

Elements Full node (NodeService)

  • Re-implement the tinybit architecture for elements node.
  • Sync block headers
  • Sync compact block filters
  • Use FilterRepository and BlockHeaderRepository to fill headers and filters databases.
  • the node does not check block signatures (or any equivalent of PoW checks)
  • the node does not check Merkle root of blocks
  • the node handles the inv messages but uses BIP0130 to sync headers (low bandwidth nodes)

Scanner service (BIP158)

  • ScannerService fetches block headers and compact filters via FilterRepository and BlockHeaderRepository interfaces.
  • It uses a neutrino-like interface to "watch" blocks: user can use Watch method to send ScanRequest, then the scanner will return a SpendReport as soon as it finds the WatchItem using filters.
  • I reused the same algorithm of neutrino to handle requests (see the requestWorker function).

How to quick test

This PR provides a simple CLI using to test this POC full node + filter scanner, u can run the following:

go run ./cmd start 

(or build the binary)

The start command lets u run a full node which will sync with your nigiri instance. It also silently run a ScannerService and sends a ScanRequest on the following address:

el1qq2enu72g3m306antkz6az3r8qklsjt62p2vt3mlfyaxmc9mwg4cl24hvzq5sfkv45ef9ahnyrr6rnr2vr63tzl5l3jpy950z7

As soon as you faucet this address, the scanner will log a report with txid.

PS: Note that this "WatchItem" is an AddressWatchItem, we can also watch for outpoint to be spent with OutpointWatchItem or whatever implementing WatchItem interface.

About WASM

  • I'm not sure we need to compile the ScannerService, it should be easy to reimplement it for browser using Javascript. This good article from Trezor's blog demonstrates it.
  • About the NodeService, the hard part is the communication with peers. That's why node pkg never handles directly TCP streams, the peer pkg is here to abstract this. The idea could be to rewrite a browser-compatible Peer.

it closes #1

@tiero @altafan please, can u review this (consider this as a proof of concept, not a polished work I think the full node needs extra work to be a "real" full node for instance)

Copy link
Collaborator

@altafan altafan left a comment

Choose a reason for hiding this comment

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

All repositories' methods should expect a first arg context.Context.

pkg/scanner/scanner.go Outdated Show resolved Hide resolved
@tiero tiero merged commit beeb0cb into vulpemventures:master Mar 2, 2022
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.

Discuss architecture
3 participants