stratisproject / StratisBitcoinFullNode

Bitcoin full node in C#
https://stratisplatform.com
MIT License
787 stars 312 forks source link

SBFN cannot sync from Bitcoin Core on Regtest due to problem with SegWit #2303

Open fshutdown opened 6 years ago

fshutdown commented 6 years ago

Setup FullNode connected to two Bitcoin Core 0.15.1 instances using -addnode commandline switch.

Problem SBFN is rejecting blocks generated by BitCoin Core after block 2. The problem has been found on the RegTest network but could impact other networks as well.

Quick hack As a temporary hack to get the code to wort I have added a check for the blockheight to decide whether the SegWit code branch should be executed. This is not a solution but rather an aid in helping to visualise a problem.

Stratis.Bitcoin.Features.Consensus.Rules.CommonRules.WitnessCommitmentsRule Change made to add additional condition for block height context.BlockValidationContext.ChainedBlock.Height >= 432 This fix addresses only SegWit on Regtest.

if (deploymentFlags.ScriptFlags.HasFlag(ScriptVerify.Witness) && context.BlockValidationContext.ChainedBlock.Height >= 432)

zeptin commented 6 years ago

Might be related to issue #1028

fshutdown commented 6 years ago

Looks similar but in the case I've described above the SegWit gets activated from block 3 which is causing the chain no to sync. This might be related to fact that I'm connecting to BitcoinCore rather than another SBFN node.

zeptin commented 6 years ago

Note that TestSegwit_MinedOnCore_ActivatedOn_StratisNode already implicitly tests what you are describing, although it is not an exhaustive test. Maybe we need to re-visit it, it is possible it does not adequately highlight potential Segwit rule issues.

fshutdown commented 6 years ago

In that case I would recommend this test to be reviewed as well. I found this problem when testing end-to-end with all nodes running as the end user would do.