mirror of
https://github.com/Retropex/bitcoin.git
synced 2025-06-03 07:52:33 +02:00
policy: Add CalculateExtraTxWeight to increase weight for datacarrier bytes
This commit is contained in:
parent
bd069a768c
commit
eefda851c5
@ -429,3 +429,26 @@ size_t DatacarrierBytes(const CTransaction& tx, const CCoinsViewCache& view)
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
||||
int32_t CalculateExtraTxWeight(const CTransaction& tx, const CCoinsViewCache& view, const unsigned int weight_per_data_byte)
|
||||
{
|
||||
int32_t mod_weight{0};
|
||||
|
||||
// Add in any extra weight for data bytes
|
||||
if (weight_per_data_byte > 1) {
|
||||
for (const CTxIn& txin : tx.vin) {
|
||||
const CTxOut &utxo = view.AccessCoin(txin.prevout).out;
|
||||
auto[script, consensus_weight_per_byte] = GetScriptForTransactionInput(utxo.scriptPubKey, txin);
|
||||
if (weight_per_data_byte > consensus_weight_per_byte) {
|
||||
mod_weight += script.DatacarrierBytes() * (weight_per_data_byte - consensus_weight_per_byte);
|
||||
}
|
||||
}
|
||||
if (weight_per_data_byte > WITNESS_SCALE_FACTOR) {
|
||||
for (const CTxOut& txout : tx.vout) {
|
||||
mod_weight += txout.scriptPubKey.DatacarrierBytes() * (weight_per_data_byte - WITNESS_SCALE_FACTOR);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return mod_weight;
|
||||
}
|
||||
|
@ -195,4 +195,6 @@ std::pair<CScript, unsigned int> GetScriptForTransactionInput(CScript prevScript
|
||||
|
||||
size_t DatacarrierBytes(const CTransaction& tx, const CCoinsViewCache& view);
|
||||
|
||||
int32_t CalculateExtraTxWeight(const CTransaction& tx, const CCoinsViewCache& view, const unsigned int weight_per_data_byte);
|
||||
|
||||
#endif // BITCOIN_POLICY_POLICY_H
|
||||
|
Loading…
Reference in New Issue
Block a user