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

feat: wait for bitcoind to accept RPC calls #76

Merged
merged 2 commits into from
Nov 9, 2022

Conversation

theborakompanioni
Copy link
Collaborator

@theborakompanioni theborakompanioni commented Nov 2, 2022

Resolves #75.

This PR enables waiting for the backing Bitcoin Core instance to be ready and accept RPC requests.

This is done by making a getblockchaininfo request before starting any services, as this is the first request JM will be performing during initialization. Also, as a by-product, the response is used to wait for >= 100 blocks to be reported - thereby making the image regtest-compatible without further adaptions.

This behaviour can be disabled by setting env var WAIT_FOR_BITCOIND to false. Default value is true.

Please see this as a quick bugfix and not the final solution. Ideally, only service sjmwalletd and ob-watcher are waiting. Other services (such as nginx and tor) could already be started.

How to test?

Please see joinmarket-webui/jam#559 and follow the instructions.

@theborakompanioni theborakompanioni added the bug Something isn't working label Nov 2, 2022
@theborakompanioni theborakompanioni self-assigned this Nov 2, 2022
@theborakompanioni
Copy link
Collaborator Author

Converted to draft again: Does not handle if bitcoind is completely down yet.

@theborakompanioni
Copy link
Collaborator Author

Converted to draft again: Does not handle if bitcoind is completely down yet.

Should be working as expected now.

@theborakompanioni theborakompanioni marked this pull request as ready for review November 4, 2022 11:24
Copy link
Contributor

@dergigi dergigi left a comment

Choose a reason for hiding this comment

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

Nice! Looks good to me. I tested everything as detailed in joinmarket-webui/jam#559

  • npm run regtest:up ✔️
  • npm run regtest:init ✔️
  • Observe successful init ✔️
  • See getblockchaininfo calls from jm_regtest_joinmarket2 every 5 seconds if MINE_BLOCKS < 99 ✔️

tACK ✅

Expand to **show test logs**

Test Run 1 (MINE_BLOCKS = 101)

jm_regtest_bitcoind                   | 2022-11-09T10:35:00.507818Z UpdateTip: new best=61d6c7fb76afef78a30edf3fe57f26d8dd98f82f44e3cab98a571d023c16636c height=101 version=0x20000000 log2_work=7.672425 tx=102 date='2022-11-09T10:35:18Z' progress=1.000000 cache=0.0MiB(101txo)
jm_regtest_bitcoind_initializer       | Successfully mined 101 blocks to address bcrt1qrnz0thqslhxu86th069r9j6y7ldkgs2tzgf5wx.
jm_regtest_bitcoind_initializer       | Waiting for bitcoind to report at least 101 blocks...
jm_regtest_bitcoind                   | 2022-11-09T10:35:00.514505Z ThreadRPCServer method=getblockchaininfo user=regtest
jm_regtest_bitcoind                   | 2022-11-09T10:35:00.515490Z Adding fixed seeds as -dnsseed=0, -addnode is not provided and all -seednode(s) attempted
jm_regtest_bitcoind_initializer       | Successfully waited for 101 blocks to be reported.
jm_regtest_bitcoind_initializer       | Creating /root/.regtest-initializer/btc_fully_synched...
jm_regtest_bitcoind_initializer       | Created /root/.regtest-initializer/btc_fully_synched.
jm_regtest_bitcoind_initializer exited with code 0
jm_regtest_joinmarket3                | ........................................................................................................................................................................................................................++++
jm_regtest_joinmarket3                | writing new private key to 'key.pem'
jm_regtest_joinmarket3                | -----
jm_regtest_joinmarket3                | /src/scripts
jm_regtest_joinmarket3                | Waiting for file /root/.regtest-initializer/btc_fully_synched to be created...
jm_regtest_joinmarket3                | Successfully waited for file /root/.regtest-initializer/btc_fully_synched to be created.
jm_regtest_joinmarket3                | Creating wallet jm_tertiary if missing...
jm_regtest_bitcoind                   | 2022-11-09T10:35:00.820983Z ThreadRPCServer method=createwallet user=joinmarket3
jm_regtest_bitcoind                   | 2022-11-09T10:35:00.823014Z Using BerkeleyDB version Berkeley DB 4.8.30: (April  9, 2010)
jm_regtest_bitcoind                   | 2022-11-09T10:35:00.823030Z Using wallet /walletdata/regtest/jm_tertiary/wallet.dat
jm_regtest_bitcoind                   | 2022-11-09T10:35:00.823122Z BerkeleyEnvironment::Open: LogDir=/walletdata/regtest/jm_tertiary/database ErrorFile=/walletdata/regtest/jm_tertiary/db.log
jm_regtest_bitcoind                   | 2022-11-09T10:35:00.832304Z init message: Loading wallet…
jm_regtest_bitcoind                   | 2022-11-09T10:35:00.838134Z [jm_tertiary] Wallet File Version = 10500
jm_regtest_bitcoind                   | 2022-11-09T10:35:00.838151Z [jm_tertiary] Keys: 0 plaintext, 0 encrypted, 0 w/ metadata, 0 total. Unknown wallet records: 0
jm_regtest_joinmarket                 | The chain is fully synched

Test Run 2 (MINE_BLOCKS = 99)

jm_regtest_irc                        | 2022-11-09T10:46:41.646Z : info  : connect    : Client connected [J58suVvpzpmvYyXN] [u:~u] [r:None]
jm_regtest_joinmarket                 | 2022-11-09 10:46:41,673 INFO spawned: 'jmwalletd' with pid 37
jm_regtest_joinmarket                 | 2022-11-09 10:46:41,676 INFO spawned: 'ob-watcher' with pid 38
jm_regtest_joinmarket                 | 2022-11-09 10:46:41,688 INFO spawned: 'tor' with pid 39
jm_regtest_bitcoind                   | 2022-11-09T10:46:42.073941Z ThreadRPCServer method=getblockchaininfo user=joinmarket
jm_regtest_bitcoind                   | 2022-11-09T10:46:42.074108Z ThreadRPCServer method=getblockchaininfo user=joinmarket
jm_regtest_bitcoind                   | 2022-11-09T10:46:42.074669Z ThreadRPCServer method=listwallets user=joinmarket
jm_regtest_bitcoind                   | 2022-11-09T10:46:42.074934Z ThreadRPCServer method=listwallets user=joinmarket
jm_regtest_bitcoind                   | 2022-11-09T10:46:42.075106Z ThreadRPCServer method=getwalletinfo user=joinmarket
jm_regtest_bitcoind                   | 2022-11-09T10:46:42.075601Z ThreadRPCServer method=getwalletinfo user=joinmarket
jm_regtest_bitcoind                   | 2022-11-09T10:46:42.081518Z ThreadRPCServer method=getnewaddress user=joinmarket
jm_regtest_bitcoind                   | 2022-11-09T10:46:42.081551Z ThreadRPCServer method=getnewaddress user=joinmarket
jm_regtest_bitcoind                   | 2022-11-09T10:46:42.081637Z [jm_primary] keypool reserve 1
jm_regtest_bitcoind                   | 2022-11-09T10:46:42.084259Z [jm_primary] keypool keep 1
jm_regtest_bitcoind                   | 2022-11-09T10:46:42.085510Z [jm_primary] keypool added 1 keys (0 internal), size=2000 (1000 internal)
jm_regtest_bitcoind                   | 2022-11-09T10:46:42.086358Z [jm_primary] keypool reserve 2
jm_regtest_bitcoind                   | 2022-11-09T10:46:42.086998Z [jm_primary] keypool keep 2
jm_regtest_irc                        | 2022-11-09T10:46:42.094Z : info  : connect-ip : Client connecting: real IP 172.19.0.8, proxied IP <nil>
jm_regtest_joinmarket                 | 2022-11-09 10:46:43,090 INFO success: jmwalletd entered RUNNING state, process has stayed up for > than 1 seconds (startsecs)
jm_regtest_joinmarket                 | 2022-11-09 10:46:43,090 INFO success: ob-watcher entered RUNNING state, process has stayed up for > than 1 seconds (startsecs)
jm_regtest_joinmarket                 | 2022-11-09 10:46:43,090 INFO success: tor entered RUNNING state, process has stayed up for > than 1 seconds (startsecs)
jm_regtest_irc                        | 2022-11-09T10:46:43.397Z : info  : connect    : Client connected [J59gGSirLH6S3XBg] [u:~u] [r:None]
jm_regtest_bitcoind                   | 2022-11-09T10:46:43.332430Z ThreadRPCServer method=getblockchaininfo user=joinmarket2
jm_regtest_bitcoind                   | 2022-11-09T10:46:48.396127Z ThreadRPCServer method=getblockchaininfo user=joinmarket2
jm_regtest_bitcoind                   | 2022-11-09T10:46:53.470755Z ThreadRPCServer method=getblockchaininfo user=joinmarket2
jm_regtest_bitcoind                   | 2022-11-09T10:46:58.532004Z ThreadRPCServer method=getblockchaininfo user=joinmarket2
jm_regtest_bitcoind                   | 2022-11-09T10:47:03.614934Z ThreadRPCServer method=getblockchaininfo user=joinmarket2
jm_regtest_bitcoind                   | 2022-11-09T10:47:08.675009Z ThreadRPCServer method=getblockchaininfo user=joinmarket2
jm_regtest_bitcoind                   | 2022-11-09T10:47:13.745799Z ThreadRPCServer method=getblockchaininfo user=joinmarket2
jm_regtest_bitcoind                   | 2022-11-09T10:47:18.804808Z ThreadRPCServer method=getblockchaininfo user=joinmarket2
jm_regtest_bitcoind                   | 2022-11-09T10:47:23.865400Z ThreadRPCServer method=getblockchaininfo user=joinmarket2
jm_regtest_bitcoind                   | 2022-11-09T10:47:28.938202Z ThreadRPCServer method=getblockchaininfo user=joinmarket2
jm_regtest_bitcoind                   | 2022-11-09T10:47:34.005230Z ThreadRPCServer method=getblockchaininfo user=joinmarket2
jm_regtest_bitcoind                   | 2022-11-09T10:47:39.051904Z ThreadRPCServer method=getblockchaininfo user=joinmarket2
jm_regtest_bitcoind                   | 2022-11-09T10:47:44.105837Z ThreadRPCServer method=getblockchaininfo user=joinmarket2
jm_regtest_bitcoind                   | 2022-11-09T10:47:49.139792Z ThreadRPCServer method=getblockchaininfo user=joinmarket2
jm_regtest_bitcoind                   | 2022-11-09T10:47:54.179530Z ThreadRPCServer method=getblockchaininfo user=joinmarket2
jm_regtest_bitcoind                   | 2022-11-09T10:47:59.234546Z ThreadRPCServer method=getblockchaininfo user=joinmarket2

@theborakompanioni theborakompanioni merged commit e71c73a into master Nov 9, 2022
@theborakompanioni theborakompanioni deleted the wait-for-bitcoind branch November 9, 2022 11:06
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Delay starting services till bitcoind is ready
2 participants