Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Tx weight limit fix #1220

Merged
merged 2 commits into from
Dec 15, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 1 addition & 2 deletions src/net_processing.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -639,8 +639,7 @@ bool AddOrphanTx(const CTransactionRef& tx, NodeId peer) EXCLUSIVE_LOCKS_REQUIRE
// 100 orphans, each of which is at most 99,999 bytes big is
// at most 10 megabytes of orphans and somewhat more byprev index (in the worst case):
unsigned int sz = GetTransactionWeight(*tx);
unsigned int szLimit = tx->IsLelantusJoinSplit() ? MAX_LELANTUS_TX_WEIGHT : MAX_STANDARD_TX_WEIGHT;
if (sz >= szLimit)
if (sz >= MAX_NEW_TX_WEIGHT)
{
LogPrint("mempool", "ignoring large orphan tx (size: %u, hash: %s)\n", sz, hash.ToString());
return false;
Expand Down
3 changes: 1 addition & 2 deletions src/policy/policy.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -68,8 +68,7 @@ bool IsStandardTx(const CTransaction& tx, std::string& reason, const bool witnes
// computing signature hashes is O(ninputs*txsize). Limiting transactions
// to MAX_STANDARD_TX_WEIGHT mitigates CPU exhaustion attacks.
unsigned int sz = GetTransactionWeight(tx);
unsigned int szLimit = tx.IsLelantusJoinSplit() ? MAX_LELANTUS_TX_WEIGHT : MAX_STANDARD_TX_WEIGHT;
if (sz >= szLimit) {
if (sz >= MAX_NEW_TX_WEIGHT) {
reason = "tx-size";
return false;
}
Expand Down
4 changes: 2 additions & 2 deletions src/policy/policy.h
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,8 @@ static const unsigned int DEFAULT_BLOCK_MAX_WEIGHT = 3000000;
static const unsigned int DEFAULT_BLOCK_MIN_TX_FEE = 1000;
/** The maximum weight for transactions we're willing to relay/mine */
static const unsigned int MAX_STANDARD_TX_WEIGHT = 400000;
/** The maximum weight for Lelantus joinsplit transactions we're willing to relay/mine */
static const unsigned int MAX_LELANTUS_TX_WEIGHT = 520000;
/** The new maximum weight for transactions we're willing to relay/mine */
static const unsigned int MAX_NEW_TX_WEIGHT = 520000;
/** Maximum number of signature check operations in an IsStandard() P2SH script */
static const unsigned int MAX_P2SH_SIGOPS = 15;
/** The maximum number of sigops we're willing to relay/mine in a single tx */
Expand Down
3 changes: 1 addition & 2 deletions src/wallet/lelantusjoinsplitbuilder.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -316,8 +316,7 @@ CWalletTx LelantusJoinSplitBuilder::Build(
// check fee
result.SetTx(MakeTransactionRef(tx));

unsigned int szLimit = (chainActive.Height() >= Params().GetConsensus().nLelantusV3PayloadStartBlock) ? MAX_LELANTUS_TX_WEIGHT : MAX_STANDARD_TX_WEIGHT;
if (GetTransactionWeight(tx) >= szLimit) {
if (GetTransactionWeight(tx) >= MAX_NEW_TX_WEIGHT) {
throw std::runtime_error(_("Transaction too large"));
}

Expand Down
2 changes: 1 addition & 1 deletion src/wallet/wallet.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -4258,7 +4258,7 @@ bool CWallet::CreateTransaction(const std::vector<CRecipient>& vecSend, CWalletT
nBytes += GetSizeOfCompactSize(nExtraPayloadSize) + nExtraPayloadSize;
}

if (nBytes > MAX_STANDARD_TX_SIZE) {
if (GetTransactionWeight(txNew) >= MAX_STANDARD_TX_WEIGHT) {
// Do not create oversized transactions (bad-txns-oversize).
strFailReason = _("Transaction too large");
return false;
Expand Down