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

Using btc.startheight on a block lower than the pruned node #252

Open
bitcoinbrisbane opened this issue Apr 8, 2020 · 2 comments
Open

Comments

@bitcoinbrisbane
Copy link
Contributor

bitcoinbrisbane commented Apr 8, 2020

If running a pruned node, and the last block stored on disk is lower than the setting btc.startheight, the index behaves strangely, as you would expect, but does not give the operator much indication as to what went wrong.

One solution could be to:

  1. Do an RPC call getblockchaininfo
  2. Get the value from the property pruneheight
  3. Compare with btc.startheight
  4. Display a better log, such as `Your nodes oldest block is higher than the target. Please change target to 621006

I'll try make a PR for this soon. Just a reminder to myself. :)

Example json return object from getblockchaininfo

{
  "chain": "main",
  "blocks": 624959,
  "headers": 624959,
  "bestblockhash": "0000000000000000000c799dc0e36302db7fbb471711f140dc308508ef19e343",
  "difficulty": 13912524048945.91,
  "mediantime": 1586333371,
  "verificationprogress": 0.9999971825740865,
  "initialblockdownload": false,
  "chainwork": "00000000000000000000000000000000000000000e4c955dbc140174f247f260",
  "size_on_disk": 5089213233,
  "pruned": true,
  "pruneheight": 621006,
  "automatic_pruning": true,
  "prune_target_size": 5242880000,
  "softforks": {
    "bip34": {
      "type": "buried",
      "active": true,
      "height": 227931
    },
    "bip66": {
      "type": "buried",
      "active": true,
      "height": 363725
    },
    "bip65": {
      "type": "buried",
      "active": true,
      "height": 388381
    },
    "csv": {
      "type": "buried",
      "active": true,
      "height": 419328
    },
    "segwit": {
      "type": "buried",
      "active": true,
      "height": 481824
    }
  },
  "warnings": ""
}
@bitcoinbrisbane
Copy link
Contributor Author

bitcoinbrisbane commented Jun 17, 2024

Geez, where did that 4 years go! Need to get the pruneheight on the rpc call and check.

Note, the pruneheight property doesnt seem to exist on the blockchaininfo class
https://github.com/MetacoSA/NBitcoin/blob/master/NBitcoin/RPC/RPCClient.cs#L2545-L2582

		async Task<SlimChainedBlock> SeemsStuck(CancellationToken cancellationToken)
		{
			if (State is not (BitcoinDWaiterState.NBXplorerSynching or BitcoinDWaiterState.Ready) ||
						lastIndexedBlock is not { } lastBlock ||
						GetConnectedClient() is not RPCClient rpc)
			{
				return null;
			}

			var blockchainInfo = await rpc.GetBlockchainInfoAsyncEx(cancellationToken);
			return blockchainInfo.BestBlockHash != lastBlock.Hash ? lastBlock : null;
		}

@bitcoinbrisbane
Copy link
Contributor Author

Needs this merged and released to Nuget MetacoSA/NBitcoin#1214

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

1 participant