bitpay / bitcore

A full stack for bitcoin and blockchain-based applications
https://bitcore.io/
MIT License
4.88k stars 2.09k forks source link

Log more details #2701

Open maektwain opened 4 years ago

maektwain commented 4 years ago

I am using a PIVX (master branch ) version of blockchain for research purpose and validating the use case of Bitcore.

Using regtest as of now. When doing so, I was able to connect with the node Worker shows sync node log started

After finding out p2p libs are trying to getheaders and setting net debug enabled in the node I see a log which say limit to 500 Getblock 1 to 500

Now it seems like it's a limit on the node side

When I tried it with regtest bitcoin once after generation of 101 block I was able to see block sync in progress

So what I did is on the PIVX node side I change the nlimit to 60000 to see since this node has almost 60000 block

After doing so now I see Sending block to peer 2 (2) is bitcore peer.

I saw one issue stating its usually wait for the sync to finish but in my case sync is already finished. It should start ?

I am assuming does it collect all the blockheader or 500 ? And wait for another 500? Point me to a direction.

micahriggan commented 4 years ago

I think the 500 limit is to get 500 headers at a time. Have you tried generating a block while it's connected. If you're unable to connect to PIVX it may be network magic related,

https://github.com/bitpay/bitcore/blob/master/packages/bitcore-lib/lib/networks.js

Check and make sure PIVX doesn't have different network magic

maektwain commented 4 years ago

Network related settings was good since I could connect with the node through p2p, added commands also in p2p libs ,

I debugged it through line by line generation of coin , through bitcoin on regtest seems to be working fine where it instantly start picking up the block.

For PIVX using generate 1 , I see it will go to This worker is now the syncing node for PIVX mainnet","level":"info"} I don't see block sync like in case of the bitcoin regtest

Another interesting fact after debugging, like when in BTC regtest, it was able to fetch 2000 block header through this.getHeaders()and then reach to the

while (headers.length > 0 ) { inside p2p.ts in modules.

In case of PIVX its reading through the block headers but not able to reach to the sync of the block?

Could you please point me to a direction where after sending message for getting headers what does it look for ?

It should typically resolve here

return new Promise<Bitcoin.Block.HeaderObj[]>(async resolve => {
      this.events.once('headers', headers => {
        received = true;
        resolve(headers);
      });

though reaching at the bitcoin-lib where its processing the block by buffer means the block is getting processed but in between its missing something, @micahriggan you know better .

Thanks if you need more information please reach out to me.

maektwain commented 4 years ago

After turning on the debug logs on bitcore , I could see this.

,"hash":"b6a98024d982418df41dc4247932a15db684f3e7bc52b4fe0f6a1a4d9649d7d0","level":"debug","message":"peer block received"}

I think I am not receiving peer headers somehow

maektwain commented 4 years ago

Another update unlike bitcoin PIVX is a proof of stake so they have disabled getheaders instead they send block hashes, so obviously what needs to be done is

  1. Process block directly from block hashes
maektwain commented 4 years ago

Could you guide me some simpler way so that we can merge it also?

micahriggan commented 4 years ago

You could use RPC rather than getheaders, or you could find the peer messages you'd need to send for sync. For sync you'd need to implement

  1. MESSAGE FOR GET MISSING BLOCKS
  2. MESSAGE FOR FETCH BLOCK
  3. Save block to the database
  4. Listen for new blocks / mempool txs

I've been trying to get it to where new projects can be added by creating modules. Then anyone could publish a module to npm, and users could add custom modules through the config.

If you're interested in creating a PIVX module, I'd be interested in walking through that, so we could flesh the module system out and make it support that usecase

Arkham20 commented 4 years ago

Logcat@

maektwain commented 4 years ago

@micahriggan , sure we could do this, I was able to make this as a module , it took me few minutes to realise this, I think as of now to test the functionality I was able to use p2p provided in the bitcoin module. Now to begin with , I am getting blocks except headers, so when you send getheaders you would get blockhashes in return.

Maybe as you suggested we can start this way.

Lets start this asap.

Thanks