Thx!
4 questions
1) Node and mainnet are not synchronized if I understand correctly. Can you tell me how to check this? And how to synchronize a node with Mainnet?
Run with -debug option and check startup log. Node should start syncing blockchain automatically (it should start in ~30 seconds from process start).
Check for messages like
2020-11-07T16:39:07Z New outbound peer connected: version: 70015, blocks=32570, peer=4 (full-relay)
2020-11-07T16:39:07Z New outbound peer connected: version: 70015, blocks=32570, peer=5 (full-relay)
2020-11-07T16:39:08Z New outbound peer connected: version: 70015, blocks=32570, peer=6 (full-relay)
2020-11-07T16:39:09Z New outbound peer connected: version: 70015, blocks=32570, peer=7 (full-relay)
2020-11-07T16:39:11Z New outbound peer connected: version: 70015, blocks=32570, peer=8 (block-relay)
It would mean it's reaching other peers and will sync block to max height (32570 in this example) available.
Messages should be present like these:
2020-11-06T04:57:20Z InitialBlockDownload is true: time of tip block is older than maximum tip age
2020-11-06T04:57:20Z UpdateTip: new best=0000000000000d48de44893c3a99a42cc2888cd3bc5d2338a52939fab8fce8a8 height=21576 version=0x20000000 log2_work=66.722153 tx=24542 date='2020-08-22T03:39:36Z' progress=1.000000 cache=3.1MiB(23652txo)
InitialBlockDownload is true would mean node is syncing and not ready yet. UpdateTip appears when blockchain chunk is synced. You can delete .BGL/blocks and .BGL/chainstate directories to resync the blockchain.
When BGLd is running and syncing, you can run some RPC commands to check the status, e.g.:
BGL-cli getblockchaininfo
{
"chain": "main",
"blocks": 28806,
"headers": 32572,
"bestblockhash": "000000000000032bbc4f2e93b781ce0745787a104e0a8fb63464ee110fe4c820",
"difficulty": 976588.2851135983,
"mediantime": 1602488499,
"verificationprogress": 1,
"initialblockdownload": true,
"chainwork": "0000000000000000000000000000000000000000000000089f89642c0349715c",
"size_on_disk": 35013606,
...
This displays blockchain state of current node. In this example it's still downloading blocks (on 28806 of 32572 currently).
2) How to request the last block in a node?
Please check 'blockchain' RPC section in Bitcoin Core reference:
https://bitcoin-rpc.github.io/en/doc/0.17.99/rpc/blockchain/getblock/For example:
BGL-cli getblockcount
32572
BGL-cli getblockhash 32572
0000000000000e6f72d79d245bdace554419707f916dd7e06b1e3a629e92cd2f
BGL-cli getblock 0000000000000e6f72d79d245bdace554419707f916dd7e06b1e3a629e92cd2f 1
{
"hash": "0000000000000e6f72d79d245bdace554419707f916dd7e06b1e3a629e92cd2f",
"confirmations": 1,
"strippedsize": 626,
"size": 989,
"weight": 2867,
"height": 32572,
"version": 536870912,
...
3) Is there a method to get the current block number?
I think the reasonably good approach will assume (or check) that the node is synced (initial block download = false) and getblockcount would return blockchain height. The currently mined block but not yet written block is the next integer.
4) how can i find out the last possible stop_height value for the method rescanblockchain?
For the purpose of initializing existing wallet balance, it most probably should be up to the last block, so the full scan from 0 to getblockcount, because at any arbitrary block there could be utxo present for some address. Maybe if more conditions is present, this could be narrowed down. BGL blockchain is very compact now so probably any optimizations regarding this may be not of a very high priority.
Hope this helps!