-
Notifications
You must be signed in to change notification settings - Fork 102
feat: chain source rest sync #526
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
base: main
Are you sure you want to change the base?
Conversation
Adds: - Sync client configuration with RPC (default) and REST variants - Extend the ChainSource::Bitcoind configuration options - Preliminary implementation for BitcoindSyncClient in RPC mode
Additionally adds the BlockSource implementation for BitcoindSyncClient
👋 Thanks for assigning @tnull as a reviewer! |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for looking into this! Before I get into more detailed review, I want to note two things on the chosen approach that stood out to me from a first look:
- I'm not quite convinced we should rename the
BitcoindRpc
client. Wouldn't it be cleaner to just add a (granted, rather duplicative)BitcoindRest
variant side-by-side, and then in a second step maybe see how we can DRY up the code. Mushing both variants together seems to result in a rather confusing API and code structure. - I'm a bit confused why we'd now still have RPC credentials on
set_chain_source_bitcoind
(and elsewhere in downstream from that), even if we want to use the REST backend? Is there any operation that still requires RPC access? Can't we just rely on REST alone?
Thanks for the early feedback.
I understand your concerns about the name and API changes I have introduced but here is a bit of context. Adding a
|
Aaah, okay, then the proposed approach makes more sense. I think it's still a bit awkward to have the mandatory RPC credentials on the While it then makes sense to reuse the client internally, it might be simpler to just keep the original |
- Adds set_chain_source_bitcoind_rest to configure REST synchronization. - Update docs to reflect the configuration order if REST sync is preferred. - Simplify the configuration object to capture only REST-related fields.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looking into this PR has helped me gain a good understanding of how chain sourcing works. I think introducing BitcoindSyncClient
is a good idea as the user can still carry out syncing operations using the REST API while the RPC Client is still maintained to carry out operations not supported by the REST API. I have just a few suggestions with regards to error handling.
9b07570
to
a28d28f
Compare
@enigbe Please let me know when this is ready for a second look. |
Thanks for the feedback @tnull. I revisited this last week and addressed concerns raised here.
This has been removed and we just keep a config for REST sync.
Agreed! This seems like a cleaner split. I've added a If you'd still prefer we pass RPC parameters as a required input for the REST variant, happy to adjust. |
Thanks for looking at this. I've rebased and have just the CLN integration tests failing. I tried reproducing the failing test locally but couldn't. I should give it another go today. |
Yes, I think this is unrelated, so feel free to ignore the flaky CI in this PR. Fixing it is really an unrelated task. |
Thanks for the review. Added the suggestions recommended for error handling. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hmm, tbh. I still dislike the current refactorings as they make the codepaths unnecessarily confusing and duplicative. Why keep a BitcoindRpcClient
around side-by-side with the new BitcoindSyncClient
that could also be an RPC client? If you maintain that merging in the REST codepaths with the RPC client is the way to go, why not extend the enum BitcoindSyncClient
variants so that one would only hold the RPC client and the other the RPC and REST clients, which would allow us to add an fn rpc_client
accessor that we can use everywhere, i.e., hence would allow us to drop the bitcoind_rpc_client
field?
/// | ||
/// ## Parameters: | ||
/// * `rest_host`, `rest_port` - Required parameters for the Bitcoin Core REST connection. | ||
pub fn set_chain_source_bitcoind_rest( |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hmm, I really dislike this API design introducing a separate chain source setter here. Basically, the fact that you had to introduce two new error variants to handle the cases where users misuse this API call already tells you that there is room for improvement here. Why not just have an entirely separate set_chain_source_bitcoind_rest
call that take all the necessary fields, including the RPC configs?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'll refactor to include the recommended changes . I thought having to pass RPC config for REST would be confusing but I now agree that it would be clearer and less likely to misuse.
rpc_port: u16, | ||
rpc_user: String, | ||
rpc_password: String, | ||
sync_client_config: Option<BitcoindRestSyncClientConfig>, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Mhh, let's name this rest_client_config
then.
@@ -186,6 +190,52 @@ impl ElectrumRuntimeStatus { | |||
} | |||
} | |||
|
|||
pub(crate) enum BitcoindSyncClient { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm not sure why this was added here vs bitcoind_rpc.rs
.
What this PR does
This PR introduces chain source synchronization with Bitcoin Core's REST API. To do so, it explicitly distinguishes between the
bitcoind_rpc_client
and the newly introducedbitcoind_sync_client
that can sync either via the RPC or REST APIs.BitcoindRpcClient
is maintained and the distinction created because the REST interface exposed by Bitcoin Core is not as robust as the RPC interface. This makes it impossible to send POST request to broadcast a transaction for example.Related Issues
Fixes #496
cc @tnull @joostjager