bitcoin-elixir icon indicating copy to clipboard operation
bitcoin-elixir copied to clipboard

When using :testnet network the app crashes after trying to store block 542

Open RadekMolenda opened this issue 7 years ago • 3 comments

I have the following issue when trying to start the node using :testnet network

10:36:33.653 [info]  Storing block 542 {{:error, {:sig_script, "c5d4b73af6eed28798473b05d2b227edd4f285069629843e899b52c2d1c165b7", 10}}, 0} | 0000000083c1f82cf72c6724f7a31732
5806384b06408bce7a4327f418dfd5ad| vt: 0.04s st: 0.0s tx: 4                                                                                                                    
                                                                                                                                                                              
10:36:33.657 [error] GenServer Bitcoin.Node.Inventory terminating                                                                                                             
** (CaseClauseError) no case clause matching: {{:error, {:sig_script, "c5d4b73af6eed28798473b05d2b227edd4f285069629843e899b52c2d1c165b7", 10}}, 0}                            
    (bitcoin) lib/bitcoin/node/inventory.ex:136: Bitcoin.Node.Inventory.handle_cast/2    

Was trying to debug this but I'm afraid my bitcoin foo is still to low to tackle this issue. Any help would be much appreciated.

The app is configured to use postgres as a Storage

RadekMolenda avatar Jan 10 '18 10:01 RadekMolenda

It's due to unfinished script engine. I haven't touched the project in a while so I don't remember how far it was syncing on testnet (it's full of edge cases, which is nice). I plan to get back to it soon to try to implement segwit, so I'll make sure to keep info about sync progress in the README.

If you are not using libsecp256k1, then definitely try with it. Although if all tests are passing then it's "just" another script bug that needs to be fixed.

Script compatibility is crucial and very hard. I'm too busy to currently dive into this issue right away, sorry. If you feel like poking around then I'm happy to answer any questions. If not I'll update the ticket when I get back to the project.

comboy avatar Jan 11 '18 01:01 comboy

Okay - the issue was in the Interperter.ex file here: https://github.com/comboy/bitcoin-elixir/blob/develop/lib/bitcoin/script/interpreter.ex#L169 and here: https://github.com/comboy/bitcoin-elixir/blob/develop/lib/bitcoin/script/interpreter.ex#L175

opts is a Map not a Keyword thus - the script was failing. I would like to provide a PR for fixing the issue, but I don't know how to write a proper test case for that. Any guides where I could find a crash course on how to write proper Bitcoin scripts?

RadekMolenda avatar Jan 11 '18 12:01 RadekMolenda

Wow, great job! Sorry about the late answer. I'll definitely dive back a bit into the project this week.

Yeah, I couldn't decide between Keyword and Map. I settled on Map eventually because function matching works with it unlike Keyword.

Check this setting: https://github.com/comboy/bitcoin-elixir/blob/develop/config/dev.exs#L7

When you run test node in dev env, and this is set to true, test/data/auto/testnet directory will appear and you should have a ready test case with the failing transaction there. It should be enough to add it to test/data/tx_valid.json

If you feel like diving into script I mostly used bitcoin wiki, there is now newer developer guide but I still trust wiki more.

Awesome that you've spent time on finding that.

comboy avatar Jan 13 '18 10:01 comboy