uaktags / explorer

An open source block explorer
BSD 3-Clause "New" or "Revised" License
6 stars 8 forks source link

sync.js #27

Closed spy0012 closed 5 years ago

spy0012 commented 5 years ago

Hi me again

just a quick one, i am running sync.js and get the following error

/usr/bin/nodejs scripts/sync.js index update /var/www/vhosts/explorer/node_modules/bitcoin-core/dist/src/index.js:33 function source(...args) { ^^^

SyntaxError: Unexpected token ... at exports.runInThisContext (vm.js:53:16) at Module._compile (module.js:374:25) at Object.Module._extensions..js (module.js:417:10) at Module.load (module.js:344:32) at Function.Module._load (module.js:301:12) at Module.require (module.js:354:17) at require (internal/module.js:12:17) at Object. (/var/www/vhosts/explorer/lib/explorer.js:9:16) at Module._compile (module.js:410:26) at Object.Module._extensions..js (module.js:417:10) at Module.load (module.js:344:32) at Function.Module._load (module.js:301:12) at Module.require (module.js:354:17) at require (internal/module.js:12:17) at Object. (/var/www/vhosts/explorer/lib/database.js:11:11) at Module._compile (module.js:410:26)

seems to be bitcoin-core module related, just wondered if you could help

uaktags commented 5 years ago

I need to know a few things: Which branch are you using, was there any output before this occurred (made it X blocks before error), can you run sync.js index update and it continue from that point without issue?

Not too much we can do if bitcoin-core was broken, but if it was broken, I think there'd be a wider issue, so I need to try to figure out what is going on at the time of this occurring.

spy0012 commented 5 years ago

I am using master branch, which you made changes to before for me.

When i run sync.js index update no blocks have synced this was a new install

I am going to try and backup my other explorer and try that one on the new and see what happens as it's the same branch.

It could be the daemon as it's pivx based with zerocoin privacy not sure if that's the issue or not

uaktags commented 5 years ago

Alright, cool. Least I know what branch to pull. Let me write some edits for you to test to just see if we can get something more verbose

uaktags commented 5 years ago

If you're comfortable with Mongo, please get coinstats.last for your coin and let me know what that number is.

If not, add this inbetween here: https://github.com/uaktags/explorer/blob/8ed38ea51b23a9d466bf41d0c5705fbbf869392d/scripts/sync.js#L185-L186

console.log("Last: %s, Count: %s", stats.last, stats.count);

so it should look like this:

} else if (mode == 'update') {
                    console.log("Last: %s, Count: %s", stats.last, stats.count);
                    db.update_tx_db(settings.coin, stats.last, stats.count, settings.update_timeout, function(){

Now when you run sync.js index update, before it errors out, it should give you "Last X, Count Y" output. count SHOULD be the most recent block from the daemon, and Last should be something greater than 0 but less than Count.

If Last is greater than 0, then awesome, we have a good starting point, continue below, if it doesn't, then just update me with the output.

If greater than 0: Update the following: https://github.com/uaktags/explorer/blob/8ed38ea51b23a9d466bf41d0c5705fbbf869392d/lib/database.js#L792-L800

It should end up looking like this: lib.get_blockhash(start + x, function(blockhash){ console.log("Blockhash for %s incoming:", start + x); console.log(blockhash); if (blockhash) { lib.get_block(blockhash, function(block) { console.log("Block incoming:"); console.log(block) if (block && block.name != "RpcError") { //console.log("Block: %s has %s txes", block.height, block.tx.length); lib.syncLoop(block.tx.length, function (subloop) { var i = subloop.iteration(); Tx.findOne({txid: block.tx[i]}, function(err, tx) { if(tx) {


What this is going to give me is information about what the getBlockHash from the Daemon is saying as well as what getBlock is saying. Basically we should expect that get_BlockHash will return an object that has the block's hash (converted from the height of stats.last's number). Then once we see that's valid, we should get a valid object of what the block itself looks like.

THEN!, I want you to compare these results with your daemon.
$ ./bitcoind-cli getBlockHash 10000                replace 10000 with whatever the blockheight was
$ ./bitcoind-cli getBlock <blockhash>             replace <blockhash> iwth whatever the hash was we got.

These results should be the same, if not, post them please.
spy0012 commented 5 years ago

Okay i never got that far, added the sync.js change and i still get the same error without any other details. However i did run npm start and refreshed the explorer and get the following output from console

GET /api/getmasternodecount 200 19.681 ms - 39 Error: OperationalError: no auth mechanism defined

i am going to assume it's not connecting to the daemon? could be wrong

Found the above issue, incorrect label for wallet connection has user instead of username, checking sync now

uaktags commented 5 years ago

That's what it sounds like hmm

spy0012 commented 5 years ago

the user / username was my mistake, but still not fixed sync.js i think it's a modules problem, going to upload my modules folder from a working explorer and see what happens

uaktags commented 5 years ago

I'd be quite surprised to hear that something is broken with the module, but let me know how it turns out. I was planning on stripping away the bitcore module in the future anyhow for something more lightweight (with true promises made rather than using requests).

spy0012 commented 5 years ago

Yes your right does not seems to be modules, i have connection to daemon now, i have used an exact copy of a working explorer but still the same error.

going to start again with the explorer and see were i end up

Still the same, i am totally lost here

spy0012 commented 5 years ago

the .jade version of the explorer works perfectly as i tried this before going to .pug only because i uploaded wrong version :) So i know the explorer works with the daemon as it was updating blocks as it should do.

i don't know why an exact copy will not work either, unless it's something in the vps environment causing issues but again why would the old version work fine.

Also the old .jade explorer had the option to pick coin type so i set pivx, i am wondering if the sync is sending the correct command? maybe

uaktags commented 5 years ago

So that's where i need the debugging I posted. What's the stats.last/count, and then we can start hitting the database.js and explorer.js until we find your issue. Also, you're able to do the curl commands from your VPS to the daemon? (Daemon is remote, not local i'm presuming?)

spy0012 commented 5 years ago

Added console.log("Last: %s, Count: %s", stats.last, stats.count); to sync.js when i run /usr/bin/nodejs scripts/sync.js index update i just get the error in first post

when i run nodejs sync.js index update from the scripts folder i get

No settings file found. Continuing using defaults! /var/www/vhosts/explorer/node_modules/bitcoin-core/dist/src/index.js:33 function source(...args) { ^^^ and the rest of the error in post 1

The explorer and daemon are local No other output in the error regarding last x, not connecting to daemon? seems to be the issue the database has no transactions

uaktags commented 5 years ago

Right, you can't run it from the scripts folder. You have to be within /path/to/explorer. So

$ cd /path/to/explorer
$ /usr/bin/nodejs ./scripts/sync.js index update

That's the only way it'll work because of the relative file paths used. You can try reindexing, but bitcoin-core shouldn't even be getting called yet until after the console.log, if it was put in correctly. You can try going to: https://github.com/uaktags/explorer/blob/8ed38ea51b23a9d466bf41d0c5705fbbf869392d/scripts/sync.js#L141 and adding our console.log for last information. Or just console.log(stats) at that point.

db.get_stats(settings.coin, function(stats){
                  console.log(stats);
                  if (settings.heavy == true) {

Hmm, you can also try doing this: add this to package.json

    "bitcoin-core": "^2.0.0",

under dependencies. So mine looks like this:

"dependencies": {
    "big-integer": "^1.6.40",
    "bignumber": "^1.1.0",
    "bitcoin-core": "^2.0.0",
    "bitcoin-node-api": "git+http://git@github.com/uaktags/Bitcoin-Node-Api.git",

or giving the cluster-sync branch a try. But I'd only do that on a fresh directory. It can use the same database and whatnot, but a number of files have changed, and if you have any customization done, they will get lost. Realize that cluster-sync is an even more unstable (but more updated) branch than master, if you chose to even try that. I'm working on the pullrequest to bring it to master soon though.

spy0012 commented 5 years ago

I am not getting any output from console when running sync.js except for the error as normal i also do run it as you stated /usr/bin/nodejs etc just tried from scripts to see if anything different showed.

i will give your cluster branch a go

uaktags commented 5 years ago

Okay, but just to confirm, what parts of the very last comment that I posted...did you do? Because I'm posting a bit of info and getting nothing back really so I can't help unless I know what you did exactly.

I.E. "After making xyz edits, I deleted the tmp/index.pid and reran the sync index update command. Here's the complete output

Then I also gave reindex a try, heres the complete output.

I then tried adding the dependency and reran npm update, and the sync. Heres the complete output."

If you just throw your hands up and move on, were not really learning much of anything about the problem.

spy0012 commented 5 years ago

I added console.log(stats); to sync.js and added "bitcoin-core": "^2.0.0", to package.json and ran npm install --production within explorer folder

spy0012 commented 5 years ago

just installed cluster version and no luck there either

explorer# /usr/bin/nodejs ./scripts/sync.js index update /var/www/vhosts/explorer/scripts/sync.js:230 for (let wt = startAtBlock; wt <= end; wt++) { ^^^

SyntaxError: Block-scoped declarations (let, const, function, class) not yet supported outside strict mode at exports.runInThisContext (vm.js:53:16) at Module._compile (module.js:374:25) at Object.Module._extensions..js (module.js:417:10) at Module.load (module.js:344:32) at Function.Module._load (module.js:301:12) at Function.Module.runMain (module.js:442:10) at startup (node.js:136:18) at node.js:966:3

uaktags commented 5 years ago

Where's the rest of the output? There's a crap-ton of messages that's suppose to come before 230? Check ./logs as well. There should be both a Master log and a sync.log.

spy0012 commented 5 years ago

That is all the error outputs on screen. i have tried numerous times but same output, also log folder has sync.log and it's empty

/var/www/vhosts/explorer# /usr/bin/nodejs ./scripts/sync.js index update /var/www/vhosts/explorer/scripts/sync.js:230 for (let wt = startAtBlock; wt <= end; wt++) { ^^^

SyntaxError: Block-scoped declarations (let, const, function, class) not yet supported outside strict mode at exports.runInThisContext (vm.js:53:16) at Module._compile (module.js:374:25) at Object.Module._extensions..js (module.js:417:10) at Module.load (module.js:344:32) at Function.Module._load (module.js:301:12) at Function.Module.runMain (module.js:442:10) at startup (node.js:136:18) at node.js:966:3 root@vmi254103:/var/www/vhosts/explorer#

That is the complete error from when i sent the command to when it finished

uaktags commented 5 years ago

Then I haven't a clue how to help you. You're literally missing some of the most basic aspects of Nodejs which is console.log'ing. So something appears severely broken or outdated about your environment that can't be reproduced. Your system is obviously not executing console.logs which is a very simple thing to do. But this has been missed both times to prove the point:

create_lock(function() {
                logger.info("script launched with pid:" + process.pid);
create_lock(function() {
                console.log("script launched with pid:" + process.pid);

So by your output above, you're not hitting the VERY FIRST thing that should be hit which is to create the lock and output that the script launched.

Unfortunately, I can't help you at this point.

spy0012 commented 5 years ago

Thanks for your help.

It seems it was the server, i reinstalled Ubuntu 18.04 and then setup master again and now syncing

Closing