From 96c9b469cad439f2e2489a2a15d30d7a02e195cd Mon Sep 17 00:00:00 2001 From: Konstantin Akimov Date: Tue, 22 Oct 2024 18:56:14 +0700 Subject: [PATCH 1/6] fix: getblock for withdrawal transaction if verbosity level is 2 --- src/core_write.cpp | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/src/core_write.cpp b/src/core_write.cpp index ffad7897ff..8999f9406f 100644 --- a/src/core_write.cpp +++ b/src/core_write.cpp @@ -334,7 +334,10 @@ void TxToUniv(const CTransaction& tx, const uint256& hashBlock, bool include_add } if (calculate_fee) { - const CAmount fee = amt_total_in - amt_total_out; + CAmount fee = amt_total_in - amt_total_out; + if (tx.nType == TRANSACTION_ASSET_UNLOCK) { + fee = CHECK_NONFATAL(GetTxPayload(tx))->getFee(); + } CHECK_NONFATAL(MoneyRange(fee)); entry.pushKV("fee", ValueFromAmount(fee)); } From ab7172bc8f0197d278ab1e4d94aa0dc66ef18f3a Mon Sep 17 00:00:00 2001 From: Konstantin Akimov Date: Tue, 22 Oct 2024 19:20:49 +0700 Subject: [PATCH 2/6] fix: getblockstats rpc to work with withdrawal transactions --- src/rpc/blockchain.cpp | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/src/rpc/blockchain.cpp b/src/rpc/blockchain.cpp index 411d6cb75d..fe44b5f2c3 100644 --- a/src/rpc/blockchain.cpp +++ b/src/rpc/blockchain.cpp @@ -49,6 +49,7 @@ #include #include +#include #include #include #include @@ -2450,6 +2451,11 @@ static RPCHelpMan getblockstats() } CAmount txfee = tx_total_in - tx_total_out; + + if (tx->nType == TRANSACTION_ASSET_UNLOCK) { + txfee = CHECK_NONFATAL(GetTxPayload(*tx))->getFee(); + } + CHECK_NONFATAL(MoneyRange(txfee)); if (do_medianfee) { fee_array.push_back(txfee); From b0d06f0b5fc8f23625dcc08aed839b58f4fac559 Mon Sep 17 00:00:00 2001 From: Konstantin Akimov Date: Tue, 22 Oct 2024 18:58:07 +0700 Subject: [PATCH 3/6] feat: add regression test for `getblock` and `getblockstats` for withdrawal fee calculation failure --- test/functional/feature_asset_locks.py | 3 +++ 1 file changed, 3 insertions(+) diff --git a/test/functional/feature_asset_locks.py b/test/functional/feature_asset_locks.py index f802edd056..45a1608958 100755 --- a/test/functional/feature_asset_locks.py +++ b/test/functional/feature_asset_locks.py @@ -407,6 +407,9 @@ class AssetLocksTest(DashTestFramework): self.mempool_size -= 2 self.check_mempool_size() block_asset_unlock = node.getrawtransaction(asset_unlock_tx.rehash(), 1)['blockhash'] + self.log.info("Checking rpc `getblock` and `getblockstats` succeeds as they use own fee calculation mechanism") + assert_equal(node.getblockstats(node.getblockcount())['maxfee'], tiny_amount) + node.getblock(block_asset_unlock, 2) self.send_tx(asset_unlock_tx, expected_error = "Transaction already in block chain", From e498378eb79332f576931c1ad06d3f42f3dc5c54 Mon Sep 17 00:00:00 2001 From: Konstantin Akimov Date: Tue, 22 Oct 2024 20:16:22 +0700 Subject: [PATCH 4/6] feat: add test for fee in getmempoolentry --- test/functional/feature_asset_locks.py | 1 + 1 file changed, 1 insertion(+) diff --git a/test/functional/feature_asset_locks.py b/test/functional/feature_asset_locks.py index 45a1608958..ff6ac61289 100755 --- a/test/functional/feature_asset_locks.py +++ b/test/functional/feature_asset_locks.py @@ -370,6 +370,7 @@ class AssetLocksTest(DashTestFramework): self.wait_for_sporks_same() txid = self.send_tx(asset_unlock_tx) + assert_equal(node.getmempoolentry(txid)['fee'], Decimal("0.0007")) is_id = node_wallet.sendtoaddress(node_wallet.getnewaddress(), 1) for node in self.nodes: self.wait_for_instantlock(is_id, node) From f6169fade4303284aa97aba7f3869c761e0ab242 Mon Sep 17 00:00:00 2001 From: Konstantin Akimov Date: Tue, 22 Oct 2024 20:40:50 +0700 Subject: [PATCH 5/6] fix: make composite rpc 'masternode payments' to work with withdrawals --- src/rpc/masternode.cpp | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/src/rpc/masternode.cpp b/src/rpc/masternode.cpp index ee5fcbdea0..cecaa6cbfb 100644 --- a/src/rpc/masternode.cpp +++ b/src/rpc/masternode.cpp @@ -3,6 +3,7 @@ // file COPYING or http://www.opensource.org/licenses/mit-license.php. #include +#include #include #include #include @@ -406,6 +407,11 @@ static RPCHelpMan masternode_payments() if (tx->IsCoinBase()) { continue; } + if (tx->IsPlatformTransfer()) { + nBlockFees += CHECK_NONFATAL(GetTxPayload(*tx))->getFee(); + continue; + } + CAmount nValueIn{0}; for (const auto& txin : tx->vin) { uint256 blockHashTmp; From b9a46f6d2c14a07803cc26cf79b3a0d97fe8e486 Mon Sep 17 00:00:00 2001 From: Konstantin Akimov Date: Tue, 22 Oct 2024 21:48:05 +0700 Subject: [PATCH 6/6] refactor: use IsPlatformTransfer in core_write and rpc/blockchain --- src/core_write.cpp | 2 +- src/rpc/blockchain.cpp | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/src/core_write.cpp b/src/core_write.cpp index 8999f9406f..2edee784bb 100644 --- a/src/core_write.cpp +++ b/src/core_write.cpp @@ -335,7 +335,7 @@ void TxToUniv(const CTransaction& tx, const uint256& hashBlock, bool include_add if (calculate_fee) { CAmount fee = amt_total_in - amt_total_out; - if (tx.nType == TRANSACTION_ASSET_UNLOCK) { + if (tx.IsPlatformTransfer()) { fee = CHECK_NONFATAL(GetTxPayload(tx))->getFee(); } CHECK_NONFATAL(MoneyRange(fee)); diff --git a/src/rpc/blockchain.cpp b/src/rpc/blockchain.cpp index fe44b5f2c3..409d24c879 100644 --- a/src/rpc/blockchain.cpp +++ b/src/rpc/blockchain.cpp @@ -2452,7 +2452,7 @@ static RPCHelpMan getblockstats() CAmount txfee = tx_total_in - tx_total_out; - if (tx->nType == TRANSACTION_ASSET_UNLOCK) { + if (tx->IsPlatformTransfer()) { txfee = CHECK_NONFATAL(GetTxPayload(*tx))->getFee(); }