Bitcoin Core version: v0.17.99.0-d6e700e40 running on OSX
I'm testing a client against reorgs from a Bitcoin Core node in regtest. To create a reorg I generate some blocks, then use invalidateblock and generatetoaddress again to create a fork. The pattern works fine as long as the regtest blockchain is not too long.
I'm not sure the exact threshold where it stops working, but it's somewhere between 50 - 64 blocks.
The error is "AcceptBlockHeader [hash] is marked invalid" but that invalid header should be long gone -- I'm generating a brand new block now...?
I guess bitcoind is probably re-generating the exact same block the second time, but not sure why the error only comes up on longer chains.
To reproduce:
Short chains, behaves as expected:
bitcoind -regtest
bitcoin-cli generatetoaddress 50 mfWxJ45yp2SFn7UciZyNpvDKrzbhyfKrY8
bitcoin-cli invalidateblock <one of the hashes returned from previous command>
bitcoin-cli generatetoaddress 1 mfWxJ45yp2SFn7UciZyNpvDKrzbhyfKrY8
Result:
2019-04-26T22:56:11Z InvalidChainFound: invalid block=37337d435262823883a7864536c08b06b07fe61205f02a404ec050e51a794191 height=49 log2_work=6.6438562 date=2019-04-26T22:56:13Z
2019-04-26T22:56:11Z InvalidChainFound: current best=725a7df044bc3b1bbb0e103749470d345aea0cdbfc2629c31818cedd45b20b46 height=48 log2_work=6.6147098 date=2019-04-26T22:56:13Z
2019-04-26T22:56:15Z CreateNewBlock(): block weight: 900 txs: 0 fees: 0 sigops 400
2019-04-26T22:56:15Z UpdateTip: new best=6f87e7f8d16404d8387d194e585d0b0e3b285a4cee9df76e4967783421b092c2 height=49 version=0x20000000 log2_work=6.6438562 tx=50 date='2019-04-26T22:56:15Z' progress=1.000000 cache=0.0MiB(50txo)
Slightly longer chains, unable to proceed:
bitcoind -regtest
bitcoin-cli generatetoaddress 64 mfWxJ45yp2SFn7UciZyNpvDKrzbhyfKrY8
bitcoin-cli invalidateblock <one of the hashes returned from previous command>
bitcoin-cli generatetoaddress 1 mfWxJ45yp2SFn7UciZyNpvDKrzbhyfKrY8
Result:
2019-04-26T22:56:42Z InvalidChainFound: invalid block=6d73a1240616f89d2b382534edd543d0aa91321d850bcc0210547cfb174f1c92 height=62 log2_work=6.9772799 date=2019-04-26T22:56:45Z
2019-04-26T22:56:42Z InvalidChainFound: current best=5317e42ded19040fc71f33a3db275abdd393c7cad1044d7f482c6c6f8b8925ff height=61 log2_work=6.9541963 date=2019-04-26T22:56:44Z
2019-04-26T22:56:44Z CreateNewBlock(): block weight: 900 txs: 0 fees: 0 sigops 400
2019-04-26T22:56:44Z ERROR: AcceptBlockHeader: block 6d73a1240616f89d2b382534edd543d0aa91321d850bcc0210547cfb174f1c92 is marked invalid
2019-04-26T22:56:44Z ERROR: ProcessNewBlock: AcceptBlock FAILED (duplicate (code 0))