comit-network / xmr-btc-swap

Bitcoin–Monero Cross-chain Atomic Swap
GNU General Public License v3.0
633 stars 78 forks source link

`asb` hangs at "Opening Bitcoin wallet" #1043

Closed icy-ux closed 1 year ago

icy-ux commented 2 years ago

Describe the bug My asb instance has been running for a while. Recently, without any apparent changes on my part, it has ceased being able to start. It simply hangs at "Opening Bitcoin wallet".

This also happens when I try to run asb with commands that access the wallet, such as showing the wallet descriptor or current balances.

The logs for electrs and bitcoind don't show anything unusual. The wallet files appear to have correct permissions.

Lost/trapped Funds Yes, it looks like the Bitcoin in my asb wallet are inaccessible.

Debug logs

{"timestamp":"2022-06-27 20:54:51","level":"INFO","fields":{"message":"Initialized tracing","level":"debug"}}                                                
{"timestamp":"2022-06-27 20:54:51","level":"INFO","fields":{"message":"Reading config file","path":"/etc/asb/config.toml"}}                                  
{"timestamp":"2022-06-27 20:54:51","level":"DEBUG","fields":{"message":"Using existing sqlite database."}}                                                   
{"timestamp":"2022-06-27 20:54:51","level":"DEBUG","fields":{"message":"Reading in seed from /etc/asb/seed.pem"}}                                            
{"timestamp":"2022-06-27 20:54:51","level":"DEBUG","fields":{"message":"Opening Bitcoin wallet"}}   

Platform (please complete the following information):

delta1 commented 2 years ago

No error message of any sort?

delta1 commented 2 years ago

You might have to use strace to see where it’s getting stuck on that file

https://strace.io/

I will look into the code after that last debug message to see if some additional info can be added to debug.

delta1 commented 2 years ago

It looks to me like it is probably trying to sync the wallet after opening it.

https://github.com/comit-network/xmr-btc-swap/blob/3ce4dffb84d0c2e01b011864cd36dabc64faf25c/swap/src/bin/asb.rs#L328

If there were an earlier error it would have exited. I'd suggest making sure that your electrum_rpc_url config is connectable and responding to queries, and then try start the asb and just give it a good amount of time to sync or see if some error occurs.

icy-ux commented 2 years ago

On Mon, Jun 27, 2022 at 10:33:37PM -0700, Byron Hambly wrote:

No error message of any sort?

None that I can see.

delta1 commented 2 years ago

@icy-ux have you tried asb withdraw-btc ?

icy-ux commented 2 years ago

On Tue, Jun 28, 2022 at 02:37:42AM -0700, Byron Hambly wrote:

If there were an earlier error it would have exited. I'd suggest making sure that your electrum_rpc_url config is connectable and responding to queries, and then try start the asb and just give it a good amount of time to sync or see if some error occurs.

Turns out the electrum server had crashed.

Suggestion: the asb instance shouldn't lock up if the electrum server stops responding. The asb binary should exit with an error code, or keep retrying but log error messages.

Steps to troubleshoot:

It had been hanging at "Opening Bitcoin wallet" for almost 24 hours now, with no change. There were also no new messages in the electrs journalctl log.

Try checking the local electrum instance:

$ sudo cat config.toml | grep electrum_rpc_url
electrum_rpc_url = "localhost:50001"

$ sudo netstat -tulpn | grep 50001
tcp        0      0 127.0.0.1:50001         0.0.0.0:*               LISTEN      34390/electrs

$ echo '{"id": 1, "method": "blockchain.address.get_balance", "params": ["1BWwXJH3q6PRsizBkSGm2Uw4Sz1urZ5sCj"]}' | nc -i 1 localhost 50001

[...and it hangs]

Okay, so the elctrum server has crashed. Restart electrs and it works:

$ echo '{"id": 1, "method": "blockchain.address.get_balance", "params": ["1BWwXJH3q6PRsizBkSGm2Uw4Sz1urZ5sCj"]}' | nc -i 1 localhost 50001
{"error":{"code":-32601,"message":"method not found"},"id":1,"jsonrpc":"2.0"}

Now after restarting asb the electrs server log is full of these messages:

Jun 28 18:57:49 blu2128 electrs[2900780]: [2022-06-28T18:57:49.484Z INFO  electrs::electrum] your wallet uses less efficient method of querying electrs, consider contacting the developer of your wallet. Reason: blockchain.scripthash.get_history called for unsubscribed scripthash: f00bar

And the asb binary runs again!

delta1 commented 2 years ago

Okay nice find! I’ll make a new issue about that message, glad you’ve got it sorted.

delta1 commented 2 years ago

I see you actually mentioned this in #865 ! Thanks for reporting