From 68efee7698c169bc6a30c3ef6c79cfde5d310d0d Mon Sep 17 00:00:00 2001 From: Davidson Souza Date: Mon, 12 Aug 2024 14:09:55 -0300 Subject: [PATCH] expose backfill to cli --- README.md | 51 ++++++++++++++++++++++++-------------- florestad/src/cli.rs | 10 +++++++- florestad/src/florestad.rs | 7 ++++++ florestad/src/main.rs | 1 + 4 files changed, 49 insertions(+), 20 deletions(-) diff --git a/README.md b/README.md index c609e507..e573b78c 100644 --- a/README.md +++ b/README.md @@ -32,6 +32,7 @@ If you want to use `libfloresta` to build your own Bitcoin application, you can - [Building with Nix](#building-with-nix) - [Running](#running) - [Assume Utreexo](#assume-utreexo) + - [Backfill](#backfill) - [Compact Filters](#compact-filters) - [Getting Help](#getting-help) - [Wallet](#wallet) @@ -70,15 +71,15 @@ git clone https://github.com/vinteumorg/Floresta.git go to the Floresta directory ```bash -cd Floresta/ +$ cd Floresta/ ``` and build with cargo build ```bash -cargo build --release +$ cargo build --release # Optionally, you can add florestad to the path with -cargo install --path ./florestad +$ cargo install --path ./florestad ``` ### Instructions for macOS Users @@ -149,9 +150,9 @@ pkgs.floresta-node After building, florestad and floresta-cli will be available in the target directory. You can run the full node with ```bash -./target/release/florestad +$ ./target/release/florestad # or, if you installed it with cargo install -florestad +$ florestad ``` You may run it as a background process with the `--daemon` flag. @@ -163,20 +164,32 @@ florestad --daemon This will start the full node, and you can connect to it with an Electrum wallet or with the `floresta-cli` tool. ```bash -floresta-cli getblockchaininfo +$ floresta-cli getblockchaininfo ``` For more information on how to use the `floresta-cli` tool, you can check the [api documentation](https://github.com/vinteumorg/Floresta/blob/master/crates/floresta-cli/README.md). Before running you can create the SSL certificates. If you don't do it, it will display a logging `Failed to load SSL certificates, ignoring SSL`. However, it is not mandatory to have the certificates to run the full node. -### Assume Utreexo -If you want to skip the IBD process, you can use the `--assume-utreexo` flag. This flag will start the node at a given height, with the state +#### Assume Utreexo + +If you want to skip the IBD process, you can use the `--assumeutreexo` flag. This flag will start the node at a given height, with the state provided by this implementation. Therefore, you're trusting that we are giving you the correct state. Everything after that height will be verified by the node just like any other node. ```bash -florestad --assume-utreexo +$ florestad --assumeutreexo +``` + +#### Backfill + +If you want to get a node up and running in a few minutes, but still want to validate everything, you can start `florestad` with `assumeutreexo` and pass the `--backfill` flag. This will download the blocks from genesis to the assumed height, validate them and compare with the provided value, all in the background. This way, you can start using the node right away, and it will be fully validated in a few hours/days depending on your hardware. + +This is the default behavior of `florestad` if no flags are provided. + +```bash +$ florestad --assumeutreexo --backfill +>>>>>>> b1a3336 (update readme with the --backfill option) ``` ### Compact Filters @@ -184,7 +197,7 @@ florestad --assume-utreexo Floresta supports compact block filters, which can be used to scan for transactions in a block without downloading the entire block. You can start the node with the `--cfilters` flag to download the filters for the blocks that you're interested in. You can also use the `--filters-start-height` flag to specify the block height that you want to start downloading the filters from. This is useful if you want to download only the filters for a specific range of blocks. ```bash -florestad --cfilters --filters-start-height 800000 +$ florestad --cfilters --filters-start-height 800000 ``` ### Getting Help @@ -192,12 +205,12 @@ florestad --cfilters --filters-start-height 800000 You can get a list of all the available commands by running ```bash -floresta-cli help +$ floresta-cli help ``` and you can get the cli parameters by running ```bash -floresta-cli help +$ floresta-cli help ``` ### Wallet @@ -209,7 +222,7 @@ call the `rescan` rpc after adding the wallet. You can add new descriptors to the wallet with the `importdescriptor` rpc. ```bash -floresta-cli importdescriptor "wpkh(xpub6CFy3kRXorC3NMTt8qrsY9ucUfxVLXyFQ49JSLm3iEG5gfAmWewYFzjNYFgRiCjoB9WWEuJQiyYGCdZvUTwPEUPL9pPabT8bkbiD9Po47XG/<0;1>/*)" +$ floresta-cli importdescriptor "wpkh(xpub6CFy3kRXorC3NMTt8qrsY9ucUfxVLXyFQ49JSLm3iEG5gfAmWewYFzjNYFgRiCjoB9WWEuJQiyYGCdZvUTwPEUPL9pPabT8bkbiD9Po47XG/<0;1>/*)" ``` The rescan assumes that you have compact block filters for the blocks that you're scanning. You can either download all the filters @@ -217,13 +230,13 @@ The rescan assumes that you have compact block filters for the blocks that you'r using the `--filters-start-height` option. Let's you know that none of your wallets are older than block 800,000. Just start the node with. ```bash -./target/release/florestad --cfilters --filters-start-height 800000 +$ ./target/release/florestad --cfilters --filters-start-height 800000 ``` if you add a wallet and want to rescan the blocks from 800,000 to the current height, you can use the `rescan` rpc. ```bash -floresta-cli rescan 800000 +$ floresta-cli rescan 800000 ``` Once you have a transaction cached in your watch-only, you can use either the rpc or integrated electrum server to retrieve information about your wallet. You can use wallets like Electrum or Sparrow to connect to your node and retrieve information about your wallet. Just connect with the server running at `127.0.0.1:50001:t`. On electrum you may want to use the `--oneserver` flag to connect to a single server, for better privacy. @@ -235,7 +248,7 @@ Once you have a transaction cached in your watch-only, you can use either the rp The tests in `floresta-cli` depend on the compiled `florestad` binary. Make sure to build the entire project first by running: ```bash -cargo build +$ cargo build ``` ### Testing Options @@ -243,7 +256,7 @@ cargo build There's a set of tests that you can run with: ```bash -cargo test +$ cargo test ``` For the full test suite, including long-running tests, use: @@ -255,8 +268,8 @@ cargo test --release Additional functional tests are available. Install dependencies and run the test script with: ```bash -pip3 install -r tests/requirements.txt -python tests/run_tests.py +$ pip3 install -r tests/requirements.txt +$ python tests/run_tests.py ``` ## Running Benchmarks diff --git a/florestad/src/cli.rs b/florestad/src/cli.rs index d7e3a04d..e208ec1f 100644 --- a/florestad/src/cli.rs +++ b/florestad/src/cli.rs @@ -150,7 +150,7 @@ pub struct Cli { /// Download block filters starting at this height. Negative numbers are relative to the current tip. pub filters_start_height: Option, - #[arg(long)] + #[arg(long, default_value_t = true)] /// Whether we should assume a utreexo state for a given height /// /// This option will significantly speed up the initial block download, by skipping the @@ -184,4 +184,12 @@ pub struct Cli { /// write it to a file. This option should be an absolute path to a file. Usually, you'd /// write it to $DATA_DIR/florestad.pid pub pid_file: Option, + #[arg(long, default_value_t = true)] + /// Whehter we should backfill + /// + /// If we assumeutreexo or use pow fraud proofs, you have the option to download and validate + /// the blocks that were skipped. This will take a long time, but will run on the background + /// and won't affect the node's operation. You may notice that this will take a lot of CPU + /// and bandwidth to run. + pub backfill: bool, } diff --git a/florestad/src/florestad.rs b/florestad/src/florestad.rs index 1b7a4297..f5903f56 100644 --- a/florestad/src/florestad.rs +++ b/florestad/src/florestad.rs @@ -157,6 +157,13 @@ pub struct Config { pub ssl_key_path: Option, /// Whether to disable SSL for the Electrum server pub no_ssl: bool, + /// Whehter we should backfill + /// + /// If we assumeutreexo or use pow fraud proofs, you have the option to download and validate + /// the blocks that were skipped. This will take a long time, but will run on the background + /// and won't affect the node's operation. You may notice that this will take a lot of CPU + /// and bandwidth to run. + pub backfill: bool, } pub struct Florestad { diff --git a/florestad/src/main.rs b/florestad/src/main.rs index 27b929bf..1adce486 100644 --- a/florestad/src/main.rs +++ b/florestad/src/main.rs @@ -63,6 +63,7 @@ fn main() { ssl_cert_path: params.ssl_cert_path, ssl_key_path: params.ssl_key_path, no_ssl: params.no_ssl, + backfill: params.backfill, }; #[cfg(unix)]