-
Notifications
You must be signed in to change notification settings - Fork 1.2k
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
fix: rpc getblock and getblockstats for blocks with withdrawal transactions (asset unlock) #6336
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
ACK 6cd7490
src/rpc/blockchain.cpp
Outdated
if (const auto opt_assetUnlockTx = GetTxPayload<CAssetUnlockPayload>(*tx)) { | ||
txfee = opt_assetUnlockTx->getFee(); | ||
} else { | ||
txfee = 0; | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
if (const auto opt_assetUnlockTx = GetTxPayload<CAssetUnlockPayload>(*tx)) { | |
txfee = opt_assetUnlockTx->getFee(); | |
} else { | |
txfee = 0; | |
} | |
const auto opt_assetUnlockTx = GetTxPayload<CAssetUnlockPayload>(*tx); | |
CHECK_NONFATAL(opt_assetUnlockTx.has_value()); | |
txfee = opt_assetUnlockTx->getFee(); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Taking a step further... How about bc3a811?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks reasonable to me!
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
if (calculate_fee) {
CAmount fee = amt_total_in - amt_total_out;
if (tx.nType == TRANSACTION_ASSET_UNLOCK) {
fee = CHECK_NONFATAL(GetTxPayload<CAssetUnlockPayload>(tx))->getFee();
}
Need to call GetTxPayload
twice, I guess over-head is not huge?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
That's just reading/deserializing from datastream, no heavy ops. Should be fine imo.
diff --git a/src/rpc/masternode.cpp b/src/rpc/masternode.cpp
index 95487525e1..26604bc4c9 100644
--- a/src/rpc/masternode.cpp
+++ b/src/rpc/masternode.cpp
@@ -407,7 +407,9 @@ static RPCHelpMan masternode_payments()
if (tx->IsCoinBase()) {
continue;
}
- if (!tx->IsPlatformTransfer()) {
+ if (tx->IsPlatformTransfer()) {
+ nBlockFees += CHECK_NONFATAL(GetTxPayload<CAssetUnlockPayload>(*tx))->getFee();
+ } else {
CAmount nValueIn{0};
for (const auto& txin : tx->vin) {
uint256 blockHashTmp;
@@ -415,10 +417,6 @@ static RPCHelpMan masternode_payments()
nValueIn += txPrev->vout[txin.prevout.n].nValue;
}
nBlockFees += nValueIn - tx->GetValueOut();
- } else {
- if (const auto opt_assetUnlockTx = GetTxPayload<CAssetUnlockPayload>(*tx)) {
- nBlockFees += opt_assetUnlockTx->getFee();
- }
}
}
|
why? I submitted fix... though it requires new CI run and re-test that there's no silly bug introduced... |
no negative condition + |
f6169fa is even better 👍 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
ACK f6169fa
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
utACK b9a46f6
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
utACK b9a46f6
…th withdrawal transactions (asset unlock) b9a46f6 refactor: use IsPlatformTransfer in core_write and rpc/blockchain (Konstantin Akimov) f6169fa fix: make composite rpc 'masternode payments' to work with withdrawals (Konstantin Akimov) e498378 feat: add test for fee in getmempoolentry (Konstantin Akimov) b0d06f0 feat: add regression test for `getblock` and `getblockstats` for withdrawal fee calculation failure (Konstantin Akimov) ab7172b fix: getblockstats rpc to work with withdrawal transactions (Konstantin Akimov) 96c9b46 fix: getblock for withdrawal transaction if verbosity level is 2 (Konstantin Akimov) Pull request description: ## Issue being fixed or feature implemented dashpay#6335 ## What was done? Applied fixes for `getblock` rpc and `getblockstats` rpc to make them work with withdrawal transactions (asset unlock). ## How Has This Been Tested? Run updated functional test `feature_asset_locks.py` without the fix causes a failure: ``` 2024-10-22T12:01:35.902000Z TestFramework (ERROR): JSONRPC error Traceback (most recent call last): File "/home/knst/projects/dash-reviews/test/functional/test_framework/test_framework.py", line 160, in main self.run_test() File "/home/knst/projects/dash-reviews/test/functional/feature_asset_locks.py", line 273, in run_test self.test_asset_unlocks(node_wallet, node, pubkey) File "/home/knst/projects/dash-reviews/test/functional/feature_asset_locks.py", line 410, in test_asset_unlocks self.log.info(f"block info: {node.getblock(block_asset_unlock, 2)}") ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "/home/knst/projects/dash-reviews/test/functional/test_framework/coverage.py", line 49, in __call__ return_val = self.auth_service_proxy_instance.__call__(*args, **kwargs) ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "/home/knst/projects/dash-reviews/test/functional/test_framework/authproxy.py", line 148, in __call__ raise JSONRPCException(response['error'], status) test_framework.authproxy.JSONRPCException: Internal bug detected: "MoneyRange(fee)" core_write.cpp:338 (TxToUniv) Please report this issue here: https://github.com/dashpay/dash/issues (-1) ``` With patch functional test `feature_asset_locks.py` succeed. ## Breaking Changes N/A ## Checklist: - [x] I have performed a self-review of my own code - [x] I have commented my code, particularly in hard-to-understand areas - [x] I have added or updated relevant unit/integration/functional/e2e tests - [x] I have made corresponding changes to the documentation - [x] I have assigned this pull request to a milestone
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
utACK b9a46f6
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
utACK b9a46f6
…th withdrawal transactions (asset unlock) b9a46f6 refactor: use IsPlatformTransfer in core_write and rpc/blockchain (Konstantin Akimov) f6169fa fix: make composite rpc 'masternode payments' to work with withdrawals (Konstantin Akimov) e498378 feat: add test for fee in getmempoolentry (Konstantin Akimov) b0d06f0 feat: add regression test for `getblock` and `getblockstats` for withdrawal fee calculation failure (Konstantin Akimov) ab7172b fix: getblockstats rpc to work with withdrawal transactions (Konstantin Akimov) 96c9b46 fix: getblock for withdrawal transaction if verbosity level is 2 (Konstantin Akimov) Pull request description: ## Issue being fixed or feature implemented dashpay#6335 ## What was done? Applied fixes for `getblock` rpc and `getblockstats` rpc to make them work with withdrawal transactions (asset unlock). ## How Has This Been Tested? Run updated functional test `feature_asset_locks.py` without the fix causes a failure: ``` 2024-10-22T12:01:35.902000Z TestFramework (ERROR): JSONRPC error Traceback (most recent call last): File "/home/knst/projects/dash-reviews/test/functional/test_framework/test_framework.py", line 160, in main self.run_test() File "/home/knst/projects/dash-reviews/test/functional/feature_asset_locks.py", line 273, in run_test self.test_asset_unlocks(node_wallet, node, pubkey) File "/home/knst/projects/dash-reviews/test/functional/feature_asset_locks.py", line 410, in test_asset_unlocks self.log.info(f"block info: {node.getblock(block_asset_unlock, 2)}") ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "/home/knst/projects/dash-reviews/test/functional/test_framework/coverage.py", line 49, in __call__ return_val = self.auth_service_proxy_instance.__call__(*args, **kwargs) ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "/home/knst/projects/dash-reviews/test/functional/test_framework/authproxy.py", line 148, in __call__ raise JSONRPCException(response['error'], status) test_framework.authproxy.JSONRPCException: Internal bug detected: "MoneyRange(fee)" core_write.cpp:338 (TxToUniv) Please report this issue here: https://github.com/dashpay/dash/issues (-1) ``` With patch functional test `feature_asset_locks.py` succeed. ## Breaking Changes N/A ## Checklist: - [x] I have performed a self-review of my own code - [x] I have commented my code, particularly in hard-to-understand areas - [x] I have added or updated relevant unit/integration/functional/e2e tests - [x] I have made corresponding changes to the documentation - [x] I have assigned this pull request to a milestone ACKs for top commit: PastaPastaPasta: utACK b9a46f6 kwvg: utACK b9a46f6 UdjinM6: utACK b9a46f6 ogabrielides: utACK dashpay@b9a46f6 Tree-SHA512: e49cf73bff5fabc9463ae538c6c556d02b3f9e396e0353f5ea0661afa015259409cdada406d05b77bf0414761c76a013cd428ffc283cbdefbefe3384c9d6ccc5
d627a6e chore: bump version to 21.1.1 (pasta) 5f9700c docs: release notes for v21.1.1 (pasta) 1c00726 Merge #6277: chore: add builder key for kittywhiskers (pasta) a2bc0f1 Merge #6290: chore: update pasta gpg key to reflect new subkeys (pasta) 167608c Merge #6338: ci: attest results of guix builds (pasta) 6fb4e49 Merge #6197: ci: always build guix, save artifacts (pasta) c0ca93c Merge #6340: fix: make 6336 compile in v21.1.x branch, using older CHECK_NONFATAL functionality (pasta) bb96df4 Merge #6336: fix: rpc getblock and getblockstats for blocks with withdrawal transactions (asset unlock) (pasta) 8e70262 Merge #6131: feat: make a support of Qt app to show Platform transfer Tx (pasta) 80ed279 Merge #6328: backport: bitcoin#30131, bitcoin#23258, bitcoin#30504 - fix bild for Ubuntu 24.10 + clang (pasta) bd772fb Merge #6229: fix: `creditOutputs` in AssetLock tx json output should be an array of objects, not debug strings (pasta) 9bf39a9 Merge #6222: fix: adjust payee predictions after mn_rr activation, add tests (pasta) 87bebfc Merge #6219: fix: correct is_snapshot_cs in VerifyDB (pasta) a4e6b8a Merge #6208: fix: persist coinjoin denoms options from gui over restarts (pasta) Pull request description: ## Issue being fixed or feature implemented See commits, backports, release notes, version bump ## What was done? ## How Has This Been Tested? ## Breaking Changes ## Checklist: _Go over all the following points, and put an `x` in all the boxes that apply._ - [ ] I have performed a self-review of my own code - [ ] I have commented my code, particularly in hard-to-understand areas - [ ] I have added or updated relevant unit/integration/functional/e2e tests - [ ] I have made corresponding changes to the documentation - [ ] I have assigned this pull request to a milestone _(for repository code-owners and collaborators only)_ ACKs for top commit: knst: utACK d627a6e kwvg: ACK d627a6e UdjinM6: utACK d627a6e ogabrielides: utACK d627a6e Tree-SHA512: cde7e40760e16e9f48da8149c3742d18a34029b057405e4d55b87110da96acbcd19b47280451dd7b5ad1ccfc91fde655452cf5f0f0d1e01a41b4c685337c64b8
Issue being fixed or feature implemented
#6335
What was done?
Applied fixes for
getblock
rpc andgetblockstats
rpc to make them work with withdrawal transactions (asset unlock).How Has This Been Tested?
Run updated functional test
feature_asset_locks.py
without the fix causes a failure:With patch functional test
feature_asset_locks.py
succeed.Breaking Changes
N/A
Checklist: