block-core / blockcore

Open source .NET Core Bitcoin based blockchain node in C#
https://www.blockcore.net
224 stars 91 forks source link

Bug: failed partial validation with error: 'bad-witness-nonce-size : invalid witness nonce size'. #320

Closed sondreb closed 3 years ago

sondreb commented 3 years ago

When Segwit has been enabled on the network through BIP9 flags, neither the peer or the node will announce it supports Segwit as a feature. This will force the node to strip Segwit data and send that to the peer, even though the peer supports Segwit. This will cause the peer to log the following errors:

warn: Blockcore.Features.Consensus.Rules.PosConsensusRuleEngine[0] Block '46-bd16c243b1a9e67baeb9bca6da07d6a9bc0206109e8f8b9e50e7882338926672-HeaderValidated - PH' failed partial validation with error: 'bad-witness-nonce-size : invalid witness nonce size'.

warn: Blockcore.Consensus.ConsensusManager[0] Downloading block for '46-bd16c243b1a9e67baeb9bca6da07d6a9bc0206109e8f8b9e50e7882338926672-HeaderValidated - PH' had missing services NODE_WITNESS, it will be enqueued again.

dangershony commented 3 years ago

After using VS live share and peer programing with @sondreb I came to the conclusion that a peer should always signal what it support even if it's not activated yet, the segwit flag activation is signaled by looking at the block headers however once activated a peer needs to let another peer know it can receive segwit blocks this can be done either by sending a notification once segwit is activated (for example the payload HaveWitness) or by letting the peer know on version handshake that the peer supports segwit.

It seems easier and more intuitive to use the second approach.