Skip to content

Commit

Permalink
Tx weight limit fix (#1220)
Browse files Browse the repository at this point in the history
* Transaction rejected into mempool issue fixed

* Unifying tx weight number
  • Loading branch information
levonpetrosyan93 committed May 17, 2023
1 parent 2ed4bfa commit 1919d0b
Show file tree
Hide file tree
Showing 5 changed files with 6 additions and 9 deletions.
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() || tx->IsSparkSpend()) ? 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() || tx.IsSparkSpend()) ? 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 @@ -4314,7 +4314,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

0 comments on commit 1919d0b

Please sign in to comment.