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

Replace Insight with Bitcoin Core in BlockchainWriter #408

Merged
merged 22 commits into from
Sep 11, 2018

Conversation

lautarodragan
Copy link
Member

@lautarodragan lautarodragan commented Sep 6, 2018

PR Process - PR Review Checklist

Fixes #24
Fixes #93
Partly addresses #293
needed-by #22
needed-by #25
needed-by #27

Release

Semantic release is enabled for this repository. Make sure you follow the right commit message convention.
We're using semantic-release's default — Angular Commit Message Conventions.

Description of Changes

This PR replaces the Insight API dependency of the BlockchainWriter module with the Bitcoin Core Wallet, finishing the migration.

Docker Compose

  • A service for regtest was added.
  • The testnet service was renamed and its ports were fixed

Dependencies

bitcore-lib and @types/bitcore-lib were uninstalled.

Deleted Tests

Placeholder tests that were introduced to bypass an error in coverage were deleted.

Rename

This PR started replacing timestamp with anchor. See #293.

Configuration

Fee Estimation

The previous could would always send a fee of 0.001. This new code is using the fundrawtransaction RPC, which estimates fees based on recent blocks.

How to Test

This is how I tested this change:

  • sudo docker-compose up -d bitcoin-regtest
  • db.dropDatabase()
  • npm run build
  • npm start
  • npm run test:integration
  • GET http://localhost:18080/works
  • Verify that response contains a few items.
  • After a configured amount of time these items should show timestamp.ipfsFileHash, timestamp.ipfsDirectoryHash and transactionId. These three properties will appear one by one. Keep refreshing until the show.
  • bitcoin-cli generate 1
  • Wait the configured amount of time until BlockchainReader picks up the generated block
  • GET http://localhost:18080/works again
  • The works in the response should now contain a full timestamp, with blockHash, blockHeight, etc.

I ran this test both in regtest and testnet.

One ideal test I haven't done is node syncing: deploy this code and the dependencies to two different machines and confirm they sync correctly.

Things Being Left Out

I'm leaving out of this PR a few things since it's actually working as it is and it's blocking several other PRs.


if (!utxo || !utxo.length)
throw new Error(`Wallet seems to be empty. Check funds for ${this.configuration.bitcoinAddress}`)
private anchorData = async (data: string) => {
Copy link
Member Author

Choose a reason for hiding this comment

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

I experimented with pipeP for this but decided not to use it yet.

I've left the experiments in another branch.

Copy link
Contributor

Choose a reason for hiding this comment

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

Agreed, it probably requires to much refactoring to use it nicely atm.

@@ -0,0 +1,2 @@
export const getData = (prefix: string, version: ReadonlyArray<number>) => (message: string) =>
Copy link
Contributor

Choose a reason for hiding this comment

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

Can/Should this be unit tested?

Copy link
Member Author

Choose a reason for hiding this comment

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

Yes. Will add in other PR

Copy link
Contributor

@kennylavender kennylavender left a comment

Choose a reason for hiding this comment

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

  • Tested changes manually
  • Checked accidental architectural/style changes
  • Reviewed entire diff
  • Unit tests
  • Documentation
  • Filenames and locations

Missing 1 unit test possibly above src/BlockchainWriter/Bitcoind.ts

I was unable to manually test, I was getting Insufficient Funds when trying to use regtest mode to manually test transactions.

Could use some documentation on adding funds to the regest docker container and anything else that needs to be done with regtest to successfully read/write.

Remaining code changes look good. Il will take a second look soon to make sure I didn't miss anything.

@lautarodragan
Copy link
Member Author

Will add proper docs in a new PR.

For now: in regtest, generate should give you funds. Remember to generate at least 101 blocks since mined/coinbase bitcoins cannot be used until they have 100 confirmations.

@@ -41,21 +41,30 @@ services:
sleep 10;
npm start;
"
poet-bitcoind:
bitcoin-testnet:
Copy link
Contributor

Choose a reason for hiding this comment

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

I don't see the need to stand up a testnet docker instance anymore now that we are using regtest. If that is correct, can we either comment this out or remove it? Otherwise when I run docker up --build I am starting up a testnet instance and syncing with the testnet blockchain, thus using up bandwidth and storage for no real reason.

Copy link
Contributor

Choose a reason for hiding this comment

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

Good point @geoffturk. I can't think of a situation that I would still want a testnet docker instance locally.

Copy link
Contributor

Choose a reason for hiding this comment

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

Actually, now that I thought about it more, I think we do want a mainnet/testnet instance actually for people to run the node on their machines. Maybe we just need a simpler way of expressing which instance we run instead of running all of them, but that can be tackled in a future PR.

Copy link
Member Author

Choose a reason for hiding this comment

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

That's correct, I'll split it apart in different docker-compose files. We still want to test stuff in testnet if possible, but docker up shouldn't cause you to download the whole testnet.

Copy link
Contributor

@kennylavender kennylavender left a comment

Choose a reason for hiding this comment

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

  • Tested changes manually
  • Checked accidental architectural/style changes
  • Reviewed entire diff
  • Unit tests
  • Filenames and locations

N/A

  • Documentation

Just succesfully manual tested 2 claims from write to read! Just the unit test.

Copy link
Contributor

@kennylavender kennylavender left a comment

Choose a reason for hiding this comment

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

Approving so you can add the unit tests then merge tonight hopefully.

@@ -36,27 +36,20 @@ services:
- poet-mongo
- poet-rabbit
- poet-ipfs
- bitcoin
Copy link
Contributor

Choose a reason for hiding this comment

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

should this be bitcoin-regtest?

Copy link
Member Author

Choose a reason for hiding this comment

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

yes! good catch.

Copy link
Member Author

Choose a reason for hiding this comment

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

fixed!

@lautarodragan
Copy link
Member Author

@kennylavender @geoffturk @jwicks31 merging now not to block other PRs. I think I've addressed your reviews, but please reach out / raise issues if there's changes you think should be done to this PR.

@lautarodragan lautarodragan merged commit 6547ee4 into master Sep 11, 2018
@lautarodragan lautarodragan deleted the bitcoin-core-writer branch September 11, 2018 03:03
@poet-ci
Copy link

poet-ci commented Sep 11, 2018

🎉 This PR is included in version 1.2.0 🎉

The release is available on:

Your semantic-release bot 📦🚀

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.

Purify Code in BlockchainWriter Use bitcoind + bitcoinjs-lib
5 participants