-
Notifications
You must be signed in to change notification settings - Fork 149
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
refactor: make bitcoin implementation flexible #1092
Conversation
Codecov ReportAll modified and coverable lines are covered by tests ✅
Additional details and impacted files@@ Coverage Diff @@
## master #1092 +/- ##
=========================================
Coverage 100.00% 100.00%
=========================================
Files 152 154 +2
Lines 5547 5567 +20
Branches 1128 1129 +1
=========================================
+ Hits 5547 5567 +20 ☔ View full report in Codecov by Sentry. |
Hey @Abdulkbk thanks for opening this draft PR to show what you've implemented so far. I skimmed through the diff and so far it's looking fantastic! I'm pleasantly surprised to see the test coverage still at 100%. 👌 Please let me know if you have any questions or need any assistance moving forward with this. |
Hey @jamaljsr thanks for taking the time to skim through this.
Yes, I try to add test to all new code as I add them👌.
Of course I will. I've been thinking of the best way I should add the |
Hey @jamaljsr, I am currently facing two blockers. I figured out a way for the first but I am still figuring out the second. The first is that BTCD has wallet functionalities decoupled from chain functionalities, unlike The second blocker is that I would love to hear your thoughts as I continue to figure a way out. Thanks. |
Hi @Abdulkbk,
Oh wow, you are correct! I honestly don't have all the answers right now on how to implement this best, but I'm willing to work with you if you are still interested in pursuing this. My hunch is that there will be more challenges along the way. We'll likely need to split this up into multiple PRs so reviewing the updates won't be too difficult. Let me know if you'd like to continue with this. I'd totally understand if this feels like too large of a project to tackle at this time. |
I agree this will require much more effort.
I would like to take this further. I will perhaps start by modifying this PR to focus on refactoring the implementation of the Bitcoin nodes to use a factory. Once I’ve completed that, I will request a review. |
17f4abb
to
ea5950e
Compare
ea5950e
to
7cfbed7
Compare
Hey @jamaljsr, I think this PR is ready for review. Thanks |
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.
@Abdulkbk Thank you very much for the updates to this PR. This is very well done. I wouldn't have done it any different myself. I really appreciate this update. 🙏
This looks good to go with just one small interface to cleanup. I'll be happy to merge this after that change and a rebase on master
.
7cfbed7
to
5ca51f8
Compare
In this commit, we refactor the designer components to make it possible for us to introduce another bitcoin node implementation later.
5ca51f8
to
49c1e3d
Compare
// the types in the v5 release are missing many functions so we have to cast as `any` | ||
// to prevent TS errors. | ||
createClient(node: BitcoinNode): any { | ||
return new BitcoinCore({ | ||
host: `http://127.0.0.1:${node.ports.rpc}`, | ||
host: `127.0.0.1`, |
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 want also to inform you @jamaljsr that bitcoind
could not connect after this change until I made this modification.
Before:
return new BitcoinCore({
host: `http://127.0.0.1:${node.ports.rpc}`,
username: bitcoinCredentials.user,
password: bitcoinCredentials.pass,
logger: this.log(),
// use a long timeout due to the time it takes to mine a lot of blocks
timeout: 5 * 60 * 1000,
});
After:
return new BitcoinCore({
host: `127.0.0.1`,
port: node.ports.rpc,
username: bitcoinCredentials.user,
password: bitcoinCredentials.pass,
logger: this.log(),
// use a long timeout due to the time it takes to mine a lot of blocks
timeout: 5 * 60 * 1000,
});
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.
Yes, the bitcoin-core
package was updated to v5 by the bot in #1115. This was a breaking change that I fixed in master
by modifying the constructor args. You'll need to run yarn install
to ensure you have the latest package version after the rebase, which should fix the connection error without a code change.
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.
Yes, the
bitcoin-core
package was updated to v5 by the bot in #1115. This was a breaking change that I fixed inmaster
by modifying the constructor args. You'll need to runyarn install
to ensure you have the latest package version after the rebase, which should fix the connection error without a code change.
I just ran yarn install
after the rebase and the connection worked without the modification. I have removed this modification now.
In this commit, we refactor how bitcoind is implemented and used, and moved to using injected factory so that other node implementa tions can be added later.
In this commit, we refactor the test files to use the new bitcoin factory implementation. We also added a test for the newly created notImplemented service file for bitcoin nodes.
49c1e3d
to
703c234
Compare
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.
LGTM 💪
Description
This PR refactors the
bitcoin
implementation.Currently, the implementation only supports
bitcoind
, making it less flexible. This PR allows for the easy integration of otherbitcoin
implementations, such as BTCD, in the future.Approach:
The PR refactors the Bitcoin implementation to utilize
BitcoinFactory
, similar to the implementation for the Lightning network, which allows for various Lightning implementations in Polar. This change will also improve the flexibility of the Bitcoin implementation.Steps to Test
Since this is a refactor PR and does not change any behavior in Polar, you can test it normally by starting Polar and creating a network that involves
bitcoind
.Here are a few pointers to test:
bitcoind
nodes.bitcoind
backends for some Lightning nodes and perform various operations.