@@ -47,8 +47,9 @@ pub enum ScriptContextError {
4747 /// than `MAX_OPS_PER_SCRIPT`(201) opcodes.
4848 MaxOpCountExceeded ,
4949 /// The Miniscript(under segwit context) corresponding
50- /// Script would be larger than `MAX_STANDARD_P2WSH_SCRIPT_SIZE` bytes.
51- MaxWitnessScriptSizeExceeded ,
50+ /// Script would be larger than `MAX_STANDARD_P2WSH_SCRIPT_SIZE`,
51+ /// `MAX_SCRIPT_SIZE` or `MAX_BLOCK`(`Tap`) bytes.
52+ MaxWitnessScriptSizeExceeded { max : usize , got : usize } ,
5253 /// The Miniscript (under p2sh context) corresponding Script would be
5354 /// larger than `MAX_SCRIPT_ELEMENT_SIZE` bytes.
5455 MaxRedeemScriptSizeExceeded ,
@@ -81,7 +82,7 @@ impl error::Error for ScriptContextError {
8182 | UncompressedKeysNotAllowed
8283 | MaxWitnessItemssExceeded { .. }
8384 | MaxOpCountExceeded
84- | MaxWitnessScriptSizeExceeded
85+ | MaxWitnessScriptSizeExceeded { .. }
8586 | MaxRedeemScriptSizeExceeded
8687 | MaxBareScriptSizeExceeded
8788 | MaxScriptSigSizeExceeded
@@ -121,10 +122,11 @@ impl fmt::Display for ScriptContextError {
121122 "At least one satisfaction path in the Miniscript fragment contains \
122123 more than MAX_OPS_PER_SCRIPT opcodes."
123124 ) ,
124- ScriptContextError :: MaxWitnessScriptSizeExceeded => write ! (
125+ ScriptContextError :: MaxWitnessScriptSizeExceeded { max , got } => write ! (
125126 f,
126- "The Miniscript corresponding Script would be larger than \
127- MAX_STANDARD_P2WSH_SCRIPT_SIZE bytes."
127+ "The Miniscript corresponding Script cannot be larger than \
128+ {} bytes, but got {} bytes.",
129+ max, got
128130 ) ,
129131 ScriptContextError :: MaxRedeemScriptSizeExceeded => write ! (
130132 f,
@@ -525,7 +527,10 @@ impl ScriptContext for Segwitv0 {
525527 match node_checked {
526528 Ok ( _) => {
527529 if ms. ext . pk_cost > MAX_SCRIPT_SIZE {
528- Err ( ScriptContextError :: MaxWitnessScriptSizeExceeded )
530+ Err ( ScriptContextError :: MaxWitnessScriptSizeExceeded {
531+ max : MAX_SCRIPT_SIZE ,
532+ got : ms. ext . pk_cost ,
533+ } )
529534 } else {
530535 Ok ( ( ) )
531536 }
@@ -550,7 +555,10 @@ impl ScriptContext for Segwitv0 {
550555 ms : & Miniscript < Pk , Self > ,
551556 ) -> Result < ( ) , ScriptContextError > {
552557 if ms. ext . pk_cost > MAX_STANDARD_P2WSH_SCRIPT_SIZE {
553- return Err ( ScriptContextError :: MaxWitnessScriptSizeExceeded ) ;
558+ return Err ( ScriptContextError :: MaxWitnessScriptSizeExceeded {
559+ max : MAX_STANDARD_P2WSH_SCRIPT_SIZE ,
560+ got : ms. ext . pk_cost ,
561+ } ) ;
554562 }
555563 Ok ( ( ) )
556564 }
@@ -644,7 +652,10 @@ impl ScriptContext for Tap {
644652 // some guarantees are not easy to satisfy because of knapsack
645653 // constraints
646654 if ms. ext . pk_cost as u64 > Weight :: MAX_BLOCK . to_wu ( ) {
647- Err ( ScriptContextError :: MaxWitnessScriptSizeExceeded )
655+ Err ( ScriptContextError :: MaxWitnessScriptSizeExceeded {
656+ max : Weight :: MAX_BLOCK . to_wu ( ) as usize ,
657+ got : ms. ext . pk_cost ,
658+ } )
648659 } else {
649660 Ok ( ( ) )
650661 }
0 commit comments