@@ -47,8 +47,9 @@ pub enum ScriptContextError {
47
47
/// than `MAX_OPS_PER_SCRIPT`(201) opcodes.
48
48
MaxOpCountExceeded ,
49
49
/// 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 } ,
52
53
/// The Miniscript (under p2sh context) corresponding Script would be
53
54
/// larger than `MAX_SCRIPT_ELEMENT_SIZE` bytes.
54
55
MaxRedeemScriptSizeExceeded ,
@@ -81,7 +82,7 @@ impl error::Error for ScriptContextError {
81
82
| UncompressedKeysNotAllowed
82
83
| MaxWitnessItemssExceeded { .. }
83
84
| MaxOpCountExceeded
84
- | MaxWitnessScriptSizeExceeded
85
+ | MaxWitnessScriptSizeExceeded { .. }
85
86
| MaxRedeemScriptSizeExceeded
86
87
| MaxBareScriptSizeExceeded
87
88
| MaxScriptSigSizeExceeded
@@ -121,10 +122,11 @@ impl fmt::Display for ScriptContextError {
121
122
"At least one satisfaction path in the Miniscript fragment contains \
122
123
more than MAX_OPS_PER_SCRIPT opcodes."
123
124
) ,
124
- ScriptContextError :: MaxWitnessScriptSizeExceeded => write ! (
125
+ ScriptContextError :: MaxWitnessScriptSizeExceeded { max , got } => write ! (
125
126
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
128
130
) ,
129
131
ScriptContextError :: MaxRedeemScriptSizeExceeded => write ! (
130
132
f,
@@ -525,7 +527,10 @@ impl ScriptContext for Segwitv0 {
525
527
match node_checked {
526
528
Ok ( _) => {
527
529
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
+ } )
529
534
} else {
530
535
Ok ( ( ) )
531
536
}
@@ -550,7 +555,10 @@ impl ScriptContext for Segwitv0 {
550
555
ms : & Miniscript < Pk , Self > ,
551
556
) -> Result < ( ) , ScriptContextError > {
552
557
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
+ } ) ;
554
562
}
555
563
Ok ( ( ) )
556
564
}
@@ -644,7 +652,10 @@ impl ScriptContext for Tap {
644
652
// some guarantees are not easy to satisfy because of knapsack
645
653
// constraints
646
654
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
+ } )
648
659
} else {
649
660
Ok ( ( ) )
650
661
}
0 commit comments