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

Enable the RpcClient to send requests to Bitcoin Core over a Unix socket. #2168

Merged
merged 1 commit into from
Jun 26, 2024

Conversation

robertmin1
Copy link
Contributor

Enable the RpcClient to send requests to Bitcoin Core over a Unix socket.
Issue #2149

@robertmin1 robertmin1 changed the title Unix Enable the RpcClient able to send requests to Bitcoin Core over a Unix socket. Apr 15, 2024
@robertmin1 robertmin1 changed the title Enable the RpcClient able to send requests to Bitcoin Core over a Unix socket. Enable the RpcClient to send requests to Bitcoin Core over a Unix socket. Apr 15, 2024
Copy link
Contributor

@SulaimanAminuBarkindo SulaimanAminuBarkindo left a comment

Choose a reason for hiding this comment

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

Thanks for this pull request!
Overall, this pull request looks good and seems like a valuable addition to btcd. To further improve its usability and clarity, I have a couple of suggestions:

Example Usage: It would be helpful to add some example usage demonstrations in the examples folder for the rpcclient with this new functionality. This would make it easier for users to understand how to use the new feature in practice.

Testing: To further improve the clarity of the pull request, consider adding some steps to the PR description outlining how to test the newly implemented functionality with Unix sockets. This would be beneficial for both reviewers and future users.

@robertmin1
Copy link
Contributor Author

Great! I've included an example that should clarify how to test it further. The only tricky part is that a host needs to be passed to avoid raising errors. The value doesn't matter as long as it's valid. If the client has a default value, this shouldn't be a problem. Perhaps when setting the DialContext, we can hard code a value like localhostunix.

Copy link
Contributor

@SulaimanAminuBarkindo SulaimanAminuBarkindo left a comment

Choose a reason for hiding this comment

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

Thank you for providing the example files.

LGTM

@robertmin1
Copy link
Contributor Author

Updated the code. I didn't set a default port when calling ParseAddressString since the host doesn't seem to have one.
Additionally, I used ParseAddressString to set a placeholder for Unix sockets in handleSendPostMessage in a cleaner way

@coveralls
Copy link

coveralls commented Apr 25, 2024

Pull Request Test Coverage Report for Build 8907194933

Warning: This coverage report may be inaccurate.

This pull request's base commit is no longer the HEAD commit of its target branch. This means it includes changes from outside the original pull request, including, potentially, unrelated coverage changes.

Details

  • 28 of 70 (40.0%) changed or added relevant lines in 1 file are covered.
  • No unchanged relevant lines lost coverage.
  • Overall coverage decreased (-0.007%) to 56.865%

Changes Missing Coverage Covered Lines Changed/Added Lines %
rpcclient/infrastructure.go 28 70 40.0%
Totals Coverage Status
Change from base Build 8881487645: -0.007%
Covered Lines: 29482
Relevant Lines: 51846

💛 - Coveralls

Copy link
Collaborator

@guggero guggero left a comment

Choose a reason for hiding this comment

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

Thanks for the updates. Looks better now, but still got a couple of asks.

rpcclient/examples/bitcoincoreunixsocket/README.md Outdated Show resolved Hide resolved
rpcclient/examples/bitcoincoreunixsocket/main.go Outdated Show resolved Hide resolved
rpcclient/examples/bitcoincoreunixsocket/main.go Outdated Show resolved Hide resolved
rpcclient/infrastructure.go Outdated Show resolved Hide resolved
rpcclient/infrastructure.go Outdated Show resolved Hide resolved
rpcclient/infrastructure.go Outdated Show resolved Hide resolved
Sending RPC requests through unix sockets
@robertmin1
Copy link
Contributor Author

Great! Thank you for reviewing. I've implemented the suggested changes.

@robertmin1
Copy link
Contributor Author

Any update on this? @guggero

Copy link
Member

@jcvernaleo jcvernaleo left a comment

Choose a reason for hiding this comment

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

OK

@jcvernaleo jcvernaleo merged commit 1396690 into btcsuite:master Jun 26, 2024
3 checks passed
@robertmin1 robertmin1 deleted the unix branch June 27, 2024 09:38
torkelrogstad added a commit to barebitcoin/btcd that referenced this pull request Sep 19, 2024
btcfind pushed a commit to btcfind/btcd that referenced this pull request Sep 26, 2024
Sending RPC requests through unix sockets
same-id added a commit to same-id/btcd that referenced this pull request Oct 27, 2024
A fix for a bug introduced by btcsuite#2168

Previously, config.Host worked in the following way:
1. Documented as supporting ip addresses only
2. In fact supported "host/path" syntax
3. Did not support "scheme" prefixes, i.e. https://

Not sure this is the desired approach, probably the best thing would
have been to extend config to contain "Scheme" and "Path" fields as well.

However, this was the way it worked.

1. Now Host can contain scheme prefixes "unix://..."
2. Host can no longer contain ".../path"

This PR solves this behavior while maintaining support of the "unix://" flow
as well.

For some reason, "scheme" is named "network" in btcsuite#2168 - I did not change that.
same-id added a commit to same-id/btcd that referenced this pull request Oct 27, 2024
A fix for a bug introduced by btcsuite#2168

Previously, config.Host worked in the following way:
1. Documented as supporting ip addresses only
2. In fact supported "host/path" syntax
3. Did not support "scheme" prefixes, i.e. https://

Not sure this is the desired approach, probably the best thing would
have been to extend config to contain "Scheme" and "Path" fields as well.

However, this was the way it worked.

1. Now Host can contain scheme prefixes "unix://..."
2. Host can no longer contain ".../path"

This PR solves this behavior while maintaining support of the "unix://" flow
as well.

For some reason, "scheme" is named "network" in btcsuite#2168 - I did not change that.

Also remove disambiguation in "network:address:port", where it parsed
"myhost:8888" as network:address instead address:port.
same-id added a commit to same-id/btcd that referenced this pull request Oct 28, 2024
A fix for a bug introduced by btcsuite#2168

Previously, config.Host worked in the following way:
1. Documented as supporting ip addresses only
2. In fact supported "host/path" syntax
3. Did not support "scheme" prefixes, i.e. https://

Not sure this is the desired approach, probably the best thing would
have been to extend config to contain "Scheme" and "Path" fields as well.

However, this was the way it worked.

1. Now Host can contain scheme prefixes "unix://..."
2. Host can no longer contain ".../path"

This PR solves this behavior while maintaining support of the "unix://" flow
as well.

For some reason, "scheme" is named "network" in btcsuite#2168 - I did not change that.

Also remove disambiguation in "network:address:port", where it parsed
"myhost:8888" as network:address instead address:port.
same-id added a commit to same-id/btcd that referenced this pull request Oct 28, 2024
A fix for a bug introduced by btcsuite#2168

Previously, config.Host worked in the following way:
1. Documented as supporting ip addresses only
2. In fact supported "host/path" syntax
3. Did not support "scheme" prefixes, i.e. https://

Not sure this is the desired approach, probably the best thing would
have been to extend config to contain "Scheme" and "Path" fields as well.

However, this was the way it worked.

1. Now Host can contain scheme prefixes "unix://..."
2. Host can no longer contain ".../path"

This PR solves this behavior while maintaining support of the "unix://" flow
as well.

For some reason, "scheme" is named "network" in btcsuite#2168 - I did not change that.

Also remove disambiguation in "network:address:port", where it parsed
"myhost:8888" as network:address instead address:port.
same-id added a commit to same-id/btcd that referenced this pull request Oct 28, 2024
A fix for a bug introduced by btcsuite#2168

Previously, config.Host worked in the following way:
1. Documented as supporting ip addresses only
2. In fact supported "host/path" syntax
3. Did not support "scheme" prefixes, i.e. https://

Not sure this is the desired approach, probably the best thing would
have been to extend config to contain "Scheme" and "Path" fields as well.

However, this was the way it worked.

1. Now Host can contain scheme prefixes "unix://..."
2. Host can no longer contain ".../path"

This PR solves this behavior while maintaining support of the "unix://" flow
as well.

For some reason, "scheme" is named "network" in btcsuite#2168 - I did not change that.

Also remove disambiguation in "network:address:port", where it parsed
"myhost:8888" as network:address instead address:port.
same-id added a commit to same-id/btcd that referenced this pull request Oct 28, 2024
A fix for a bug introduced by btcsuite#2168

Previously, config.Host worked in the following way:
1. Documented as supporting ip addresses only
2. In fact supported "host/path" syntax
3. Did not support "scheme" prefixes, i.e. https://

Not sure this is the desired approach, probably the best thing would
have been to extend config to contain "Scheme" and "Path" fields as well.

However, this was the way it worked.

1. Now Host can contain scheme prefixes "unix://..."
2. Host can no longer contain ".../path"

This PR solves this behavior while maintaining support of the "unix://" flow
as well.

For some reason, "scheme" is named "network" in btcsuite#2168 - I did not change that.

Also remove disambiguation in "network:address:port", where it parsed
"myhost:8888" as network:address instead address:port.
same-id added a commit to same-id/btcd that referenced this pull request Oct 29, 2024
A fix for a bug introduced by btcsuite#2168

Previously, config.Host worked in the following way:
1. Documented as supporting ip addresses only
2. In fact supported "host/path" syntax
3. Did not support "scheme" prefixes, i.e. https://

Not sure this is the desired approach, probably the best thing would
have been to extend config to contain "Scheme" and "Path" fields as well.

However, this was the way it worked.

1. Now Host can contain scheme prefixes "unix://..."
2. Host can no longer contain ".../path"

This PR solves this behavior while maintaining support of the "unix://" flow
as well.

For some reason, "scheme" is named "network" in btcsuite#2168 - I did not change that.

Also remove disambiguation in "network:address:port", where it parsed
"myhost:8888" as network:address instead address:port.
same-id added a commit to same-id/btcd that referenced this pull request Nov 8, 2024
A fix for a bug introduced by btcsuite#2168

Previously, config.Host worked in the following way:
1. Documented as supporting ip addresses only
2. In fact supported "host/path" syntax
3. Did not support "scheme" prefixes, i.e. https://

Not sure this is the desired approach, probably the best thing would
have been to extend config to contain "Scheme" and "Path" fields as well.

However, this was the way it worked.

1. Now Host can contain scheme prefixes "unix://..."
2. Host can no longer contain ".../path"

This PR solves this behavior while maintaining support of the "unix://" flow
as well.

For some reason, "scheme" is named "network" in btcsuite#2168 - I did not change that.

Also remove disambiguation in "network:address:port", where it parsed
"myhost:8888" as network:address instead address:port.
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.

5 participants