Skip to content

Commit

Permalink
expose backfill to cli
Browse files Browse the repository at this point in the history
  • Loading branch information
Davidson-Souza committed Nov 23, 2024
1 parent ccaeb39 commit 68efee7
Show file tree
Hide file tree
Showing 4 changed files with 49 additions and 20 deletions.
51 changes: 32 additions & 19 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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.
Expand All @@ -163,41 +164,53 @@ 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

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

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 <command>
$ floresta-cli help <command>
```

### Wallet
Expand All @@ -209,21 +222,21 @@ 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
(about 11GB on mainnet) or, if you know the block range that you're interested in, you can download only the filters for that range
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.
Expand All @@ -235,15 +248,15 @@ 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

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:
Expand All @@ -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
Expand Down
10 changes: 9 additions & 1 deletion florestad/src/cli.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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<i32>,

#[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
Expand Down Expand Up @@ -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<String>,
#[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,
}
7 changes: 7 additions & 0 deletions florestad/src/florestad.rs
Original file line number Diff line number Diff line change
Expand Up @@ -157,6 +157,13 @@ pub struct Config {
pub ssl_key_path: Option<String>,
/// 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 {
Expand Down
1 change: 1 addition & 0 deletions florestad/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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)]
Expand Down

0 comments on commit 68efee7

Please sign in to comment.