lnd: [bug]: Fail to chain sync on `testnet3` & `mainnet` errors relating to: script witness item is larger than the max allowed size

Background

Fail to chain sync on testnet3. The node does show it is up to the tip of the chain , but remains unsynced due to errors

2022-10-09 18:42:39.886 [ERR] LNWL: Unable to process chain reorg: unable to get block 0000000000000032fcf519b61aad2b966348e3f2d27687b26277933cc9881965: readScript: script witness item is larger than the max allowed size [count 396669, max 11000]
....
2022-10-09 18:46:18.715 [ERR] LNWL: Unable to complete chain rescan: readScript: script witness item is larger than the max allowed size [count 396669, max 11000]
...

2022-10-09 21:36:23.272 [ERR] LNWL: Unable to process chain reorg: unable to get block 0000000000000014820a254fbcdccce582df2194014c1e3b3f5ecd9259fce663: readScript: script witness item is larger than the max allowed size [count 33970, max 11000]

Your environment

  • 0.15.0-beta commit=v0.15.0-beta
  • Linux ip-10-21-2-70 5.13.0-1031-aws #35~20.04.1-Ubuntu SMP Mon Jun 13 22:30:30 UTC 2022 x86_64 x86_64 x86_64 GNU/Linux
  • backend bitcoind v23.0.0

Steps to reproduce

Unknown

Expected behaviour

“synced_to_chain”: true

Actual behaviour

“synced_to_chain”: false with following errors in logs:

2022-10-09 18:42:39.886 [ERR] LNWL: Unable to process chain reorg: unable to get block 0000000000000032fcf519b61aad2b966348e3f2d27687b26277933cc9881965: readScript: script witness item is larger than the max allowed size [count 396669, max 11000]
....
2022-10-09 18:46:18.715 [ERR] LNWL: Unable to complete chain rescan: readScript: script witness item is larger than the max allowed size [count 396669, max 11000]
...

2022-10-09 21:36:23.272 [ERR] LNWL: Unable to process chain reorg: unable to get block 0000000000000014820a254fbcdccce582df2194014c1e3b3f5ecd9259fce663: readScript: script witness item is larger than the max allowed size [count 33970, max 11000]

About this issue

  • Original URL
  • State: closed
  • Created 2 years ago
  • Reactions: 6
  • Comments: 24 (9 by maintainers)

Commits related to this issue

Most upvoted comments

Hey y’all, thanks for bringing this to our attention. I’ve identified the issue in the btcd wire parsing library, which led to this incident.

AFAICT, the consensus code wasn’t the issue here, it was instead that the wire parsing library was erroneously still enforcing a prior check to limit witness sizing left over from segwit v0.

I am surprised this wasn’t caught by tests. Are they not using the static test vectors?

btcd is/was using this test vectors. The issue here is that the code the parsed the witnesses for these test vectors isn’t the same code that’s used to read blocks off the wire. When a new block comes in, we fetch the raw block then attempt to decode it, which triggered this issue.

The fix to the btcd wire parsing logic can be found here: https://github.com/btcsuite/btcd/pull/1896

This should be safe to apply to those running btcd nodes, which’ll allow them to resume validating the main chain (the block was accepted as this wasn’t a consensus issue persay).

Once this passes CI and a few more sniff checks, we’ll issue a hotfix release for lnd: 0.15.2. This release will only contain the dependency update to the wire parsing library.

Looks like lnd/btcd has a bug in their taproot implementation. In BIP342:

Script size limit The maximum script size of 10000 bytes does not apply. Their size is only implicitly bounded by the block weight limit.[9]

I am surprised this wasn’t caught by tests. Are they not using the static test vectors?

Having this with LND Version v0.15.1 on mainnet:

2022-10-10 10:27:48.835 [INF] LTND: Waiting for chain backend to finish sync, start_height=757924
2022-10-10 10:27:49.535 [ERR] LNWL: Unable to complete chain rescan: readScript: script witness item is larger than the max allowed size [count 33970, max 11000]

I also also seeing on mainnet v0.15.0:

2022-10-09 21:56:48.549 [ERR] LNWL: Unable to process chain reorg: unable to get block 0000000000000000000400a35a007e223a7fb8a622dc7b5aa5eaace6824291fb: readScript: script witness item is larger than the max allowed size [count 33970, max 11000]

See this on v0.15.1/mainnet


2022-10-09 21:56:55.488 [ERR] LNWL: Unable to process chain reorg: unable to get block 0000000000000000000400a35a007e223a7fb8a622dc7b5aa5eaace6824291fb: readScript: script witness item is larger than the max allowed size [count 33970, max 11000]

Got the same error on mainnet:

2022-10-09 16:56:50.707 [ERR] LNWL: Unable to process chain reorg: unable to get block 0000000000000000000400a35a007e223a7fb8a622dc7b5aa5eaace6824291fb: readScript: script witness item is larger than the max allowed size [count 33970, max 11000]