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

bitcore-node does not seem to connect to eth node at all. #3337

Closed
swtrse opened this issue Feb 19, 2022 · 3 comments
Closed

bitcore-node does not seem to connect to eth node at all. #3337

swtrse opened this issue Feb 19, 2022 · 3 comments

Comments

@swtrse
Copy link

swtrse commented Feb 19, 2022

Hello,

I tried setup 2 machines one running bitcore-node (M-1) the other running an eth node (M-2).
When testing connection from M-1 to M-2 with curl I can see the connection in the log of the eth node.
I tried with bitcore and doge nodes too. They seem to work just fine.
I also checked if SELinux is blocking something but I did not found any indication that this was happening.

However when running bitcore-node I see no connection attempt in the eth node logs at all.
bitcore-node raises an exception

Feb 19 13:25:45 bneth.localnet node[30251]: Unhandled Rejection at: Error: Error: [number-to-bn] while converting number undefined to BN.js instance, error: invalid number value. Value must be an integer, hex string, BN or BigNumber instance. Note, decimals are not supported. Given value: "undefined"
Feb 19 13:25:45 bneth.localnet node[30251]:     at Object.toBN (/home/bitcore/bitcore/packages/bitcore-node/node_modules/crypto-rpc/node_modules/web3-utils/src/utils.js:65:15)
Feb 19 13:25:45 bneth.localnet node[30251]:     at outputBigNumberFormatter (/home/bitcore/bitcore/packages/bitcore-node/node_modules/crypto-rpc/node_modules/web3-core-helpers/src/formatters.js:41:18)
Feb 19 13:25:45 bneth.localnet node[30251]:     at Method.outputTransactionFormatter [as outputFormatter] (/home/bitcore/bitcore/packages/bitcore-node/node_modules/crypto-rpc/node_modules/web3-core-helpers/src/formatters.js:203:19)
Feb 19 13:25:45 bneth.localnet node[30251]:     at Method.formatOutput (/home/bitcore/bitcore/packages/bitcore-node/node_modules/crypto-rpc/node_modules/web3-core-method/src/index.js:165:54)
Feb 19 13:25:45 bneth.localnet node[30251]:     at sendTxCallback (/home/bitcore/bitcore/packages/bitcore-node/node_modules/crypto-rpc/node_modules/web3-core-method/src/index.js:540:33)
Feb 19 13:25:45 bneth.localnet node[30251]:     at Object.<anonymous> (/home/bitcore/bitcore/packages/bitcore-node/node_modules/crypto-rpc/node_modules/web3-core-requestmanager/src/index.js:147:9)
Feb 19 13:25:45 bneth.localnet node[30251]:     at /home/bitcore/bitcore/packages/bitcore-node/node_modules/crypto-rpc/node_modules/web3-providers-ws/src/index.js:127:44
Feb 19 13:25:45 bneth.localnet node[30251]:     at Array.forEach (<anonymous>)
Feb 19 13:25:45 bneth.localnet node[30251]:     at W3CWebSocket.WebsocketProvider.connection.onmessage (/home/bitcore/bitcore/packages/bitcore-node/node_modules/crypto-rpc/node_modules/web3-providers-ws/src/index.js:104:36)
Feb 19 13:25:45 bneth.localnet node[30251]:     at W3CWebSocket._dispatchEvent [as dispatchEvent] (/home/bitcore/bitcore/packages/bitcore-node/node_modules/yaeti/lib/EventTarget.js:107:17)
Feb 19 13:25:45 bneth.localnet node[30251]:     at W3CWebSocket.onMessage (/home/bitcore/bitcore/packages/bitcore-node/node_modules/@web3-js/websocket/lib/W3CWebSocket.js:234:14)
Feb 19 13:25:45 bneth.localnet node[30251]:     at WebSocketConnection.<anonymous> (/home/bitcore/bitcore/packages/bitcore-node/node_modules/@web3-js/websocket/lib/W3CWebSocket.js:205:19)
Feb 19 13:25:45 bneth.localnet node[30251]:     at WebSocketConnection.emit (events.js:198:13)
Feb 19 13:25:45 bneth.localnet node[30251]:     at WebSocketConnection.processFrame (/home/bitcore/bitcore/packages/bitcore-node/node_modules/@web3-js/websocket/lib/WebSocketConnection.js:554:26)
Feb 19 13:25:45 bneth.localnet node[30251]:     at /home/bitcore/bitcore/packages/bitcore-node/node_modules/@web3-js/websocket/lib/WebSocketConnection.js:323:40
Feb 19 13:25:45 bneth.localnet node[30251]:     at process._tickCallback (internal/process/next_tick.js:61:11)

Does any one have a similar issue and a solution?

@kajoseph
Copy link
Collaborator

kajoseph commented Feb 19, 2022

Are you using Geth? Bitcore-node was designed to sync with Parity/OpenEthereum and might not work with Geth out of the box. If you're using Parity/OE, what flags are you passing in?

@swtrse
Copy link
Author

swtrse commented Feb 19, 2022

Since OpenEthereum will run out of support and the devs moved on to Erigon I use erigon. I know that geth is missing some used functions so it can not be used.

I finally found the reason (and I start to dislike nodejs projects in general more and more just for the fact that debugging and finding an error is a pain in the ass).
The reason is bitcore-node uses a module crypto-rpc that module uses a module [email protected]. This module do not handle transactions where the gas price is not set correctly and throws an error in the outputTransactionFormatter function. However this was fixed in [email protected] so I think an update to at lest 1.5.0 is in order. I Created an Issue in the crypto-rpc project for this (bitpay/crypto-rpc#149).
For now I will fork bitcore-node and crypto-rpc to use a newer web3 version.

@swtrse swtrse closed this as completed Feb 19, 2022
@swtrse
Copy link
Author

swtrse commented Feb 21, 2022

Just to be complete.
The forked version of crypto-rpc can be found here https://www.npmjs.com/package/@swtrse/crypto-rpc. The only difference is the referenced web3 version.
I also forked this project to https://github.com/Cobra-Technologies-GmbH/bitcore and changed the package.json to use my version of crypto-rpc in the bitcore-node folder. I also added a reference to web3 in the same Version as crypto-rpc
and a reference to web3-core-helpers

"web3": "1.7.0",
"web3-core-helpers": "^1.7.0",

web3-core-helpers might not be necessary but I had to to it to be able to set breakpoints in the sourcecode and debug the function that has thrown the error in the old version in my VSCode environment.

Last but not least I got errors after a time that stop the bitcore-node process. The error was kind of cryptic in the logs. Using the debugger it was clear that the error happens if a block is greater that the given max blocksize of (maxReceivedFrameSize=1MiB and maxReceivedMessageSize = 8MiN) . Luckily that can be changed via the config file.
So my config file for ETH mainnet and ropsten looks like

{
    "bitcoreNode": {
        "dbHost": "mongo.locallan",
        "modules": [
            "./ethereum"
        ],
        "services": {
            "api": {
                "wallets": {
                    "allowCreationBeforeCompleteSync": true
                }
            },
            "socket": {
                "bwsKeys": [
                    "<generatedBwsKey>"
                ]
            }
        },
        "chains": {
            "ETH": {
                "mainnet": {
                    "chainSource": "p2p",
                    "trustedPeers": [
                        {
                            "host": "eth6.locallan",
                            "port": 30303
                        }
                    ],
                    "provider": {
                        "host": "eth.locallan",
                        "protocol": "ws",
                        "port": 8545,
                        "options": {
                            "clientConfig": {
                                "maxReceivedFrameSize": 100000000,
                                "maxReceivedMessageSize": 100000000
                            }
                        }
                    }
                },
                "testnet": {
                    "chainSource": "p2p",
                    "trustedPeers": [
                        {
                            "host": "eth6.locallan",
                            "port": 40303
                        }
                    ],
                    "provider": {
                        "host": "eth.locallan",
                        "protocol": "ws",
                        "port": 18545,
                        "options": {
                            "clientConfig": {
                                "maxReceivedFrameSize": 100000000,
                                "maxReceivedMessageSize": 100000000
                            }
                        }
                    }
                }
            }
        }
    }
}

So far syncing is running without errors using erigon as bitcore node. I rely on /etc/hosts for IP resolution hostnames ending with 6 are IPv6 addresses.

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

No branches or pull requests

2 participants