@@ -1170,9 +1170,13 @@ uint256 GetOutputsHash(const CTransaction& txTo) {
1170
1170
1171
1171
PrecomputedTransactionData::PrecomputedTransactionData (const CTransaction& txTo)
1172
1172
{
1173
- hashPrevouts = GetPrevoutHash (txTo);
1174
- hashSequence = GetSequenceHash (txTo);
1175
- hashOutputs = GetOutputsHash (txTo);
1173
+ // Cache is calculated only for transactions with witness
1174
+ if (txTo.HasWitness ()) {
1175
+ hashPrevouts = GetPrevoutHash (txTo);
1176
+ hashSequence = GetSequenceHash (txTo);
1177
+ hashOutputs = GetOutputsHash (txTo);
1178
+ ready = true ;
1179
+ }
1176
1180
}
1177
1181
1178
1182
uint256 SignatureHash (const CScript& scriptCode, const CTransaction& txTo, unsigned int nIn, int nHashType, const CAmount& amount, SigVersion sigversion, const PrecomputedTransactionData* cache)
@@ -1181,18 +1185,19 @@ uint256 SignatureHash(const CScript& scriptCode, const CTransaction& txTo, unsig
1181
1185
uint256 hashPrevouts;
1182
1186
uint256 hashSequence;
1183
1187
uint256 hashOutputs;
1188
+ const bool cacheready = cache && cache->ready ;
1184
1189
1185
1190
if (!(nHashType & SIGHASH_ANYONECANPAY)) {
1186
- hashPrevouts = cache ? cache->hashPrevouts : GetPrevoutHash (txTo);
1191
+ hashPrevouts = cacheready ? cache->hashPrevouts : GetPrevoutHash (txTo);
1187
1192
}
1188
1193
1189
1194
if (!(nHashType & SIGHASH_ANYONECANPAY) && (nHashType & 0x1f ) != SIGHASH_SINGLE && (nHashType & 0x1f ) != SIGHASH_NONE) {
1190
- hashSequence = cache ? cache->hashSequence : GetSequenceHash (txTo);
1195
+ hashSequence = cacheready ? cache->hashSequence : GetSequenceHash (txTo);
1191
1196
}
1192
1197
1193
1198
1194
1199
if ((nHashType & 0x1f ) != SIGHASH_SINGLE && (nHashType & 0x1f ) != SIGHASH_NONE) {
1195
- hashOutputs = cache ? cache->hashOutputs : GetOutputsHash (txTo);
1200
+ hashOutputs = cacheready ? cache->hashOutputs : GetOutputsHash (txTo);
1196
1201
} else if ((nHashType & 0x1f ) == SIGHASH_SINGLE && nIn < txTo.vout .size ()) {
1197
1202
CHashWriter ss (SER_GETHASH, 0 );
1198
1203
ss << txTo.vout [nIn];
0 commit comments