lbryio / lbcd

An alternative full node implementation of LBRY's blockchain written in Go (golang)
https://lbry.com/
ISC License
38 stars 25 forks source link

Make `getblock` return orphan blocks with `confirmation: -1` #90

Closed roylee17 closed 2 years ago

roylee17 commented 2 years ago

Currently, orphan blocks and transactions are kept in the block database, but not available for query.

 lbcctl getblock 09555f547a4065b36561fbc3887023b3c97c592f6b77c5d9cb8adfbd0095eea8

-32603: block 09555f547a4065b36561fbc3887023b3c97c592f6b77c5d9cb8adfbd0095eea8 is not in the main chain

Some software like yiimp relies on this information to handle reorgs properly.

I don't have a orphan block at hand, but got a sample from other bitcoind-alike coin:

$ ./bin/DGB-cli getblock 4ad54d7ac4b421188085f029abd65ede86e94e83f73f35d69366c7cef9cecae7
{
  "hash": "4ad54d7ac4b421188085f029abd65ede86e94e83f73f35d69366c7cef9cecae7",
  "confirmations": -1,
  "strippedsize": 194,
  "size": 194,
  "weight": 776,
  "height": 15673117,
  "version": 536872962,
  "versionHex": "20000802",
  "pow_algo_id": 4,
  "pow_algo": "qubit",
  "pow_hash": "00000000000004b4de8617ec23ae5b41414c447e21bd28f96372d92e7cc25f04",
  "merkleroot": "4fc2feb6643fb003641979cd44fe55e6d1de6925d98465eb96092e4a6230d8b8",
  "tx": [
    "4fc2feb6643fb003641979cd44fe55e6d1de6925d98465eb96092e4a6230d8b8"
  ],
  "time": 1661833543,
  "mediantime": 1661833518,
  "nonce": 1676480887,
  "bits": "1a15fca8",
  "difficulty": 763042.1132930262,
  "chainwork": "0000000000000000000000000000000000000000000fcce720fc57df108155cc",
  "nTx": 1,
  "previousblockhash": "e81750620337f26d3c05cf0e064b4d3e2da6b98a6c05320b2c42477582d0ec09"
}

Making the orphan blocks returned with confirmation: -1 should make it compatible.