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

bcli: Bitcoin backend assumes Linux-style newlines #4001

Closed
cdecker opened this issue Aug 31, 2020 · 0 comments · Fixed by #4502
Closed

bcli: Bitcoin backend assumes Linux-style newlines #4001

cdecker opened this issue Aug 31, 2020 · 0 comments · Fixed by #4502
Labels
good first issue good for onboarding windows

Comments

@cdecker
Copy link
Member

cdecker commented Aug 31, 2020

A user reported this error on [reddit]:

So I have confirmed that the bitcoin-cli.exe is being invoked, with the arguments shown. But I am not sure why this error is coming up. If I run bitcoin-cli.exe from command line, I can easily get replies for command like getblockchaininfo, which confirms that bitcoind is running.

Here is what I get as output of lightningd command:

2020-08-30T17:35:53.634Z INFO plugin-bcli: bitcoin-cli initialized and connected to bitcoind.
/usr/local/bin/../libexec/c-lightning/plugins/bcli error: bad response to getrawblockbyheight (bad 'result' field), response was {"jsonrpc":"2.0","id":8,"error":{"code":400,"message":"bitcoin-cli.exe -datadir=G:\\\\.bitcoin -rpcconnect=127.0.0.1 -rpcport=8332 -rpcuser=... -rpcpassword=... getblockhash 646000: bad JSON: bad blockhash (00000000000000000001ef19be9c9879c6e9aa6241a096f543109e2a34397936\r\n)"} }

Not sure why I am seeing this problem.

Update: I got it running. Now I see this

2020-08-30T23:45:47.611Z INFO plugin-bcli: bitcoin-cli initialized and connected to bitcoind.
2020-08-30T23:45:48.728Z INFO lightningd: --------------------------------------------------
2020-08-30T23:45:48.729Z INFO lightningd: Server started with public key 03c7505d1ac56441f234025cd348743cddff147f9356e6296820d5e95d1a56b29d, alias GREENTOLL (color #03c750) and lightningd v0.9.0-197-gdd8cd81-modded

I've no clue what I am doing, but will continue digging more.

From the datadir specified in the bitcoin-cli call it seems like this is
running on Windows (cygwin or MingW), and the error message seems to indicate
like it got a windows-style \r\n newline rather than the \n newline we
expect:

lightning/plugins/bcli.c

Lines 657 to 662 in 71e713c

/* `-1` to strip the newline character. */
stash->block_hash = tal_strndup(stash, bcli->output,
bcli->output_bytes-1);
if (!stash->block_hash || strlen(stash->block_hash) != 64) {
return command_err_bcli_badjson(bcli, "bad blockhash");
}

We should likely strip whitespace at the end in a more reliable fashion.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
good first issue good for onboarding windows
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants