]> Git Repo - VerusCoin.git/commitdiff
For ZEC-013. RPC createrawtransaction returns error if tx expiring soon.
authorSimon <[email protected]>
Wed, 7 Nov 2018 07:32:30 +0000 (23:32 -0800)
committerSimon <[email protected]>
Sat, 17 Nov 2018 17:02:10 +0000 (09:02 -0800)
qa/rpc-tests/wallet_overwintertx.py
src/rpc/rawtransaction.cpp

index ce2d41445cda5a1b15edfeeeb98201c4a85130c7..cb59f29fa52dbc62abd6f19837b356bebc883cb0 100755 (executable)
@@ -117,6 +117,11 @@ class WalletOverwinterTxTest (BitcoinTestFramework):
         except JSONRPCException,e:
             errorString = e.error['message']
         assert_equal("Invalid parameter, expiryheight must be nonnegative and less than 500000000" in errorString, True)
+        try:
+            self.nodes[0].createrawtransaction([], {}, 0, 200)
+        except JSONRPCException,e:
+            errorString = e.error['message']
+        assert_equal("Invalid parameter, expiryheight should be at least 203 to avoid transaction expiring soon" in errorString, True)
 
         # Node 0 sends transparent funds to Node 3
         tsendamount = Decimal('1.0')
index 7d3dcc705d6583075020eb0340dfbcd98a7e04b3..ac720a2dfda2820fb97641e2a584256c5b22a170 100644 (file)
@@ -476,7 +476,7 @@ UniValue createrawtransaction(const UniValue& params, bool fHelp)
             "      ,...\n"
             "    }\n"
             "3. locktime              (numeric, optional, default=0) Raw locktime. Non-0 value also locktime-activates inputs\n"
-            "4. expiryheight          (numeric, optional, default=" + strprintf("%d", DEFAULT_TX_EXPIRY_DELTA) + ") Expiry height of transaction (if Overwinter is active)\n"
+            "4. expiryheight          (numeric, optional, default=nextblockheight+" + strprintf("%d", DEFAULT_TX_EXPIRY_DELTA) + ") Expiry height of transaction (if Overwinter is active)\n"
             "\nResult:\n"
             "\"transaction\"            (string) hex string of the transaction\n"
 
@@ -510,6 +510,12 @@ UniValue createrawtransaction(const UniValue& params, bool fHelp)
             if (nExpiryHeight < 0 || nExpiryHeight >= TX_EXPIRY_HEIGHT_THRESHOLD) {
                 throw JSONRPCError(RPC_INVALID_PARAMETER, strprintf("Invalid parameter, expiryheight must be nonnegative and less than %d.", TX_EXPIRY_HEIGHT_THRESHOLD));
             }
+            // DoS mitigation: reject transactions expiring soon
+            if (nextBlockHeight + TX_EXPIRING_SOON_THRESHOLD > nExpiryHeight) {
+                throw JSONRPCError(RPC_INVALID_PARAMETER,
+                    strprintf("Invalid parameter, expiryheight should be at least %d to avoid transaction expiring soon",
+                    nextBlockHeight + TX_EXPIRING_SOON_THRESHOLD));
+            }
             rawTx.nExpiryHeight = nExpiryHeight;
         } else {
             throw JSONRPCError(RPC_INVALID_PARAMETER, "Invalid parameter, expiryheight can only be used if Overwinter is active when the transaction is mined");
This page took 0.029156 seconds and 4 git commands to generate.