+
Skip to content

chore: use bitcoin::Network instead of wrapper enum #473

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

Merged

Conversation

luisschwab
Copy link
Contributor

@luisschwab luisschwab commented May 5, 2025

What is the purpose of this pull request?

  • Bug fix
  • Documentation update
  • New feature
  • Test
  • Other: code cleanup

Which crates are being modified?

  • floresta-chain
  • floresta-cli
  • floresta-common
  • floresta-compact-filters
  • floresta-electrum
  • floresta-watch-only
  • floresta-wire
  • floresta
  • florestad
  • Other:

Description

This PR swaps the crate's Network wrapper over bitcoin::Network in favor of using bitcoin::Network directly. Since bitcoin::Network does not implement Default, it was necessary to implement one for Config.

Handling errors caused by unsupported networks is outside of the scope of this PR. Cases where these need to be handled can be found via: rg --type rust '// TODO: handle possible Err'.

I also set the AssumeValid for Testnet4 as the hash of block 80_000: 0000000006af13c1117f3e2eb14f10eb9736e255713118cf7eb6659b1448efc1. Let me know if that's too recent so I can replace it with an older block.

Notes to the reviewers

I wasn't able to run integration tests locally, not even on master, so let's see what happens on CI.

Author Checklist

  • I've followed the contribution guidelines
  • I've verified one of the following:
    • Ran just pcc (recommended but slower)
    • Ran just lint-features '-- -D warnings' && cargo test --release
    • Confirmed CI passed on my fork
  • I've linked any related issue(s) in the sections above

Copy link
Contributor

@JoseSK999 JoseSK999 left a comment

Choose a reason for hiding this comment

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

Concept ACK. The only thing is that I think we should return error in case of an unsupported network, rather than panic.

Copy link
Member

@Davidson-Souza Davidson-Souza left a comment

Choose a reason for hiding this comment

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

Concept ACK. Just some small changes

@Davidson-Souza Davidson-Souza added dependencies Pull requests that update a dependency file chore Cleaning, refactoring, reducing complexity code quality Generally improves code readability and maintainability labels May 6, 2025
@luisschwab luisschwab force-pushed the chore/use-bitcoin-network branch from 101b351 to 314834a Compare May 7, 2025 15:50
@Davidson-Souza
Copy link
Member

Could you please squash it? The original commit structure was nice to review.

@luisschwab luisschwab force-pushed the chore/use-bitcoin-network branch from 314834a to f77c083 Compare May 7, 2025 17:40
@Davidson-Souza
Copy link
Member

@luisschwab this branch has a conflict with chainstate-builder.rs

@luisschwab luisschwab force-pushed the chore/use-bitcoin-network branch 2 times, most recently from c9c4704 to 7f68d27 Compare May 7, 2025 17:57
@luisschwab
Copy link
Contributor Author

Weird, it's failing the SSL test due to a timeout. @Davidson-Souza do you think this is related?

    main()
  File "/home/runner/work/Floresta/Floresta/./tests/run_tests.py", line 168, in main
    raise RuntimeError(f"Tests failed: {log_file.read()}")
RuntimeError: Tests failed: [TestSslInitialization 2025-05-07 18:03:48.389285] Created PKCS#8 key at /tmp/floresta-func-tests.fae515b/data/ssl/key.pem
[TestSslInitialization 2025-05-07 18:03:48.390980] Created self-signed certificate at /tmp/floresta-func-tests.fae515b/data/ssl/cert.pem
[FLORESTAD 2025-05-07 18:03:48.391434+00:00] Starting node 'florestad': /tmp/floresta-func-tests.fae515b/binaries/florestad --daemon --network=regtest --data-dir /tmp/floresta-func-tests.fae515b/data/TestSslInitialization --ssl-key-path /tmp/floresta-func-tests.fae515b/data/ssl/key.pem --ssl-cert-path /tmp/floresta-func-tests.fae515b/data/ssl/cert.pem
Traceback (most recent call last):
  File "/home/runner/work/Floresta/Floresta/tests/florestad/ssl-test.py", line 53, in <module>
    TestSslInitialization().main()
  File "/home/runner/work/Floresta/Floresta/tests/test_framework/__init__.py", line 192, in main
    self.run_test()
  File "/home/runner/work/Floresta/Floresta/tests/florestad/ssl-test.py", line 34, in run_test
    self.run_node(TestSslInitialization.nodes[0])
  File "/home/runner/work/Floresta/Floresta/tests/test_framework/__init__.py", line 350, in run_node
    node.rpc.wait_for_connections(opened=True)
  File "/home/runner/work/Floresta/Floresta/tests/test_framework/rpc/base.py", line 280, in wait_for_connections
    self.wait_for_connection(host, port, opened)
  File "/home/runner/work/Floresta/Floresta/tests/test_framework/rpc/base.py", line 274, in wait_for_connection
    raise TimeoutError(f"{host}:{port} not {state} after {timeout} seconds")
TimeoutError: 127.0.0.1:18442 not open after 10 seconds

@luisschwab luisschwab force-pushed the chore/use-bitcoin-network branch from 7f68d27 to b056516 Compare May 7, 2025 18:56
@luisschwab
Copy link
Contributor Author

Seems like it was a transient CI failure, it's passing now ✅.

Copy link
Member

@Davidson-Souza Davidson-Souza left a comment

Choose a reason for hiding this comment

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

Wow, there's a lot of places to handle errors 🥲

Some code quality nits and we should be ready.

@luisschwab
Copy link
Contributor Author

Oh, these got lost in rebase hell. Fixing it now.

@luisschwab luisschwab force-pushed the chore/use-bitcoin-network branch from b056516 to 647b1ff Compare May 7, 2025 21:55
@luisschwab luisschwab requested a review from Davidson-Souza May 8, 2025 00:48
Copy link
Contributor

@JoseSK999 JoseSK999 left a comment

Choose a reason for hiding this comment

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

Okay, checked everything and it's mostly fine.

The "only" suggested changes are mainly about removing the TODO and expect in tests where we know it can't fail. You can apply directly almost all the suggestions via GitHub.

@luisschwab
Copy link
Contributor Author

@JoseSK999 the commit history will get messy, I'll just make the changes locally and rebase.

@luisschwab
Copy link
Contributor Author

@JoseSK999 I left some comments on your reviews. Can you address them?

@JoseSK999
Copy link
Contributor

I think I did all

luisschwab and others added 8 commits May 8, 2025 14:05
Previously we were using `unwrap` for things like chainstore operations and `Option` values unwrapping.

I have replaced all unwraps in the file with proper error handling. Added the new `IncompleteTip` and `Database` error variants. Polished a bit the comments.

Also instead of implementing `From` ChainStateBuilder for Chainstate I implement `TryFrom` (it's fallible, failing if the chainstore and chain params are not set).
If a peer disconnects, we re-do all inflight requests that we had with
that peer. However, the code that does so may fail early if
`redo_inflight_request` return an error. It is the case if we request
for utreexo data or compact block filters without having a peer that
supports those requests. This commit adds an early check that makes
these functions act as a no-op in case we can't fulfill the request.

It is not a problem to not re-request stuff here, since we already have
some fallback logic that will try it again.
A couple of replacements of `unwrap` for `expect` with proper messages.

In partial_chain.rs `get_validation_flags` now takes the hash directly from the caller, avoiding the `unwrap` (exactly as we do for `get_validation_flags` in chain_state.rs).

In `get_leaf_hashes` (udata.rs) we instead take the TxOut directly. We also avoid computing the txid twice by passing it.
Add:
	A name for the CI functional workflow
	new check_installed function
	build flag to force florestad building
fix:
	the florestad symlink now its directly from the actual dir, as a absolute path. cargo
build will update the linked binary too.
	echoing the directory at the end so one just see the dir if the
script ran fine
@luisschwab luisschwab force-pushed the chore/use-bitcoin-network branch from a58b918 to 8ede946 Compare May 8, 2025 17:12
@luisschwab luisschwab requested a review from JoseSK999 May 8, 2025 17:23
Copy link
Contributor

@JoseSK999 JoseSK999 left a comment

Choose a reason for hiding this comment

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

Last few nits

@JoseSK999
Copy link
Contributor

Nice!

@Davidson-Souza you mentioned uniffi, does it work in this case without the florestad/src/cli.rs and florestad/src/lib.rs Network enums?

@luisschwab
Copy link
Contributor Author

Doesn't CI cover this?

@JoseSK999
Copy link
Contributor

Hm I don't think so

@Davidson-Souza
Copy link
Member

Nice!

@Davidson-Souza you mentioned uniffi, does it work in this case without the florestad/src/cli.rs and florestad/src/lib.rs Network enums?

We can do an enum for this in floresta-ffi. No reason to hold thins here only for that.

Copy link
Contributor

@JoseSK999 JoseSK999 left a comment

Choose a reason for hiding this comment

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

ACK 2fd6276

Copy link
Member

@Davidson-Souza Davidson-Souza left a comment

Choose a reason for hiding this comment

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

ACK 2fd6276

@Davidson-Souza Davidson-Souza merged commit 973ebba into vinteumorg:master May 9, 2025
10 checks passed
luisschwab added a commit to luisschwab/bdk-floresta that referenced this pull request May 10, 2025
@luisschwab luisschwab deleted the chore/use-bitcoin-network branch June 25, 2025 02:04
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
chore Cleaning, refactoring, reducing complexity code quality Generally improves code readability and maintainability dependencies Pull requests that update a dependency file
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants
点击 这是indexloc提供的php浏览器服务,不要输入任何密码和下载