File tree Expand file tree Collapse file tree 2 files changed +16
-6
lines changed Expand file tree Collapse file tree 2 files changed +16
-6
lines changed Original file line number Diff line number Diff line change 1010
1111from test_framework .descriptors import descsum_create
1212from test_framework .key import ECKey
13+ from test_framework .messages import (
14+ ser_compact_size ,
15+ WITNESS_SCALE_FACTOR ,
16+ )
1317from test_framework .test_framework import BitcoinTestFramework
1418from test_framework .util import (
1519 assert_approx ,
@@ -655,10 +659,11 @@ def test_psbt_input_keys(psbt_input, keys):
655659 break
656660 psbt_in = dec ["inputs" ][input_idx ]
657661 # Calculate the input weight
658- # (prevout + sequence + length of scriptSig + 2 bytes buffer) * 4 + len of scriptwitness
662+ # (prevout + sequence + length of scriptSig + scriptsig + 1 byte buffer) * WITNESS_SCALE_FACTOR + num scriptWitness stack items + (length of stack item + stack item) * N stack items + 1 byte buffer
659663 len_scriptsig = len (psbt_in ["final_scriptSig" ]["hex" ]) // 2 if "final_scriptSig" in psbt_in else 0
660- len_scriptwitness = len (psbt_in ["final_scriptwitness" ]["hex" ]) // 2 if "final_scriptwitness" in psbt_in else 0
661- input_weight = ((41 + len_scriptsig + 2 ) * 4 ) + len_scriptwitness
664+ len_scriptsig += len (ser_compact_size (len_scriptsig )) + 1
665+ len_scriptwitness = (sum ([(len (x ) // 2 ) + len (ser_compact_size (len (x ) // 2 )) for x in psbt_in ["final_scriptwitness" ]]) + len (psbt_in ["final_scriptwitness" ]) + 1 ) if "final_scriptwitness" in psbt_in else 0
666+ input_weight = ((40 + len_scriptsig ) * WITNESS_SCALE_FACTOR ) + len_scriptwitness
662667 low_input_weight = input_weight // 2
663668 high_input_weight = input_weight * 2
664669
Original file line number Diff line number Diff line change 1010from test_framework .authproxy import JSONRPCException
1111from test_framework .descriptors import descsum_create
1212from test_framework .key import ECKey
13+ from test_framework .messages import (
14+ ser_compact_size ,
15+ WITNESS_SCALE_FACTOR ,
16+ )
1317from test_framework .test_framework import BitcoinTestFramework
1418from test_framework .util import (
1519 assert_equal ,
@@ -526,10 +530,11 @@ def run_test(self):
526530 break
527531 psbt_in = dec ["inputs" ][input_idx ]
528532 # Calculate the input weight
529- # (prevout + sequence + length of scriptSig + 2 bytes buffer) * 4 + len of scriptwitness
533+ # (prevout + sequence + length of scriptSig + scriptsig + 1 byte buffer) * WITNESS_SCALE_FACTOR + num scriptWitness stack items + (length of stack item + stack item) * N stack items + 1 byte buffer
530534 len_scriptsig = len (psbt_in ["final_scriptSig" ]["hex" ]) // 2 if "final_scriptSig" in psbt_in else 0
531- len_scriptwitness = len (psbt_in ["final_scriptwitness" ]["hex" ]) // 2 if "final_scriptwitness" in psbt_in else 0
532- input_weight = ((41 + len_scriptsig + 2 ) * 4 ) + len_scriptwitness
535+ len_scriptsig += len (ser_compact_size (len_scriptsig )) + 1
536+ len_scriptwitness = (sum ([(len (x ) // 2 ) + len (ser_compact_size (len (x ) // 2 )) for x in psbt_in ["final_scriptwitness" ]]) + len (psbt_in ["final_scriptwitness" ]) + 1 ) if "final_scriptwitness" in psbt_in else 0
537+ input_weight = ((40 + len_scriptsig ) * WITNESS_SCALE_FACTOR ) + len_scriptwitness
533538
534539 # Input weight error conditions
535540 assert_raises_rpc_error (
You can’t perform that action at this time.
0 commit comments