v29.4-roots.4 · Commit 3: [PATCH 03/37] policy: restore conservative relay and network controls
src/policy/policy.cpp
Before: src/policy/policy.cpp · After: src/policy/policy.cpp
File metadata
index 5942747d60999d761aa8ab14c7e8505499b3ac23..cc9c5432d52230bcf2657d81d4bb316c83c233d9 100644
Download original patch · Release notes
Diff rows 401–470 of 470. Line numbers refer to the original before/after files.
+ Added− RemovedUnmarked lines are context.
Scroll the code area horizontally to read long lines. The two line-number columns refer to before and after.
src/policy/policy.cpp
CHANGED
|
@@ -394,3 +529,97 @@ int64_t GetVirtualTransactionInputSize(const CTxIn& txin, int64_t nSigOpCost, un (continued)
|
|
|
556
|
+
|
|
557
|
+
Span stack{txin.scriptWitness.stack};
|
|
558
|
+
|
|
559
|
+
if (witnessversion == 0 && witnessprogram.size() == WITNESS_V0_SCRIPTHASH_SIZE) {
|
|
560
|
+
if (stack.empty()) return std::make_pair(CScript(), 0); // invalid
|
|
561
|
+
auto& script_data = stack.back();
|
|
562
|
+
prevScript = CScript(script_data.begin(), script_data.end());
|
|
563
|
+
return std::make_pair(prevScript, 1);
|
|
564
|
+
}
|
|
565
|
+
|
|
566
|
+
if (witnessversion == 1 && witnessprogram.size() == WITNESS_V1_TAPROOT_SIZE && !p2sh) {
|
|
567
|
+
if (stack.size() >= 2 && !stack.back().empty() && stack.back()[0] == ANNEX_TAG) {
|
|
568
|
+
SpanPopBack(stack);
|
|
569
|
+
}
|
|
570
|
+
if (stack.size() >= 2) {
|
|
571
|
+
SpanPopBack(stack); // Ignore control block
|
|
572
|
+
prevScript = CScript(stack.back().begin(), stack.back().end());
|
|
573
|
+
return std::make_pair(prevScript, 1);
|
|
574
|
+
}
|
|
575
|
+
}
|
|
576
|
+
|
|
577
|
+
return std::make_pair(CScript(), 0);
|
|
578
|
+
}
|
|
579
|
+
|
|
580
|
+
std::pair<size_t, size_t> DatacarrierBytes(const CTransaction& tx, const CCoinsViewCache& view)
|
|
581
|
+
{
|
|
582
|
+
std::pair<size_t, size_t> ret{0, 0};
|
|
583
|
+
|
|
584
|
+
for (const CTxIn& txin : tx.vin) {
|
|
585
|
+
const CTxOut &utxo = view.AccessCoin(txin.prevout).out;
|
|
586
|
+
auto[script, consensus_weight_per_byte] = GetScriptForTransactionInput(utxo.scriptPubKey, txin);
|
|
587
|
+
const auto dcb = script.DatacarrierBytes(0, &txin.scriptWitness);
|
|
588
|
+
ret.first += dcb.first;
|
|
589
|
+
ret.second += dcb.second;
|
|
590
|
+
}
|
|
591
|
+
for (size_t i{tx.vout.size()}; i; ) {
|
|
592
|
+
const CTxOut& txout = tx.vout[--i];
|
|
593
|
+
const auto dcb = txout.scriptPubKey.DatacarrierBytes(tx.vout.size() - i);
|
|
594
|
+
ret.first += dcb.first;
|
|
595
|
+
ret.second += dcb.second;
|
|
596
|
+
}
|
|
597
|
+
|
|
598
|
+
return ret;
|
|
599
|
+
}
|
|
600
|
+
|
|
601
|
+
int32_t CalculateExtraTxWeight(const CTransaction& tx, const CCoinsViewCache& view, const unsigned int weight_per_data_byte)
|
|
602
|
+
{
|
|
603
|
+
int64_t mod_weight{0};
|
|
604
|
+
|
|
605
|
+
// Add in any extra weight for data bytes
|
|
606
|
+
if (weight_per_data_byte > 1) {
|
|
607
|
+
for (const CTxIn& txin : tx.vin) {
|
|
608
|
+
const CTxOut &utxo = view.AccessCoin(txin.prevout).out;
|
|
609
|
+
auto[script, consensus_weight_per_byte] = GetScriptForTransactionInput(utxo.scriptPubKey, txin);
|
|
610
|
+
if (weight_per_data_byte > consensus_weight_per_byte) {
|
|
611
|
+
const auto dcb = script.DatacarrierBytes(0, &txin.scriptWitness);
|
|
612
|
+
mod_weight += int64_t(dcb.first + dcb.second) * (weight_per_data_byte - consensus_weight_per_byte);
|
|
613
|
+
}
|
|
614
|
+
}
|
|
615
|
+
if (weight_per_data_byte > WITNESS_SCALE_FACTOR) {
|
|
616
|
+
for (size_t i{tx.vout.size()}; i; ) {
|
|
617
|
+
const CTxOut& txout = tx.vout[--i];
|
|
618
|
+
const auto dcb = txout.scriptPubKey.DatacarrierBytes(tx.vout.size() - i);
|
|
619
|
+
mod_weight += int64_t(dcb.first + dcb.second) * (weight_per_data_byte - WITNESS_SCALE_FACTOR);
|
|
620
|
+
}
|
|
621
|
+
}
|
|
622
|
+
}
|
|
623
|
+
|
|
624
|
+
return int32_t(std::min(mod_weight, int64_t{std::numeric_limits<int32_t>::max()}));
|
|
625
|
+
}
|