From 5cdef3ae6c12986c07596c25ae8905948498274a Mon Sep 17 00:00:00 2001 From: ShengguangXiao Date: Wed, 22 Sep 2021 03:20:23 +0000 Subject: [PATCH 1/4] Including tx fee into block rewards --- src/miner.cpp | 2 +- test/functional/feature_block_reward.py | 41 +++++++++++++++++++++++++ test/functional/test_runner.py | 1 + 3 files changed, 43 insertions(+), 1 deletion(-) create mode 100644 test/functional/feature_block_reward.py diff --git a/src/miner.cpp b/src/miner.cpp index 044b2c8df7..16ec1b0fdc 100644 --- a/src/miner.cpp +++ b/src/miner.cpp @@ -239,7 +239,7 @@ std::unique_ptr BlockAssembler::CreateNewBlock(const CScript& sc coinbaseTx.vout.resize(2); // Explicitly set miner reward - coinbaseTx.vout[0].nValue = CalculateCoinbaseReward(blockReward, consensus.dist.masternode); + coinbaseTx.vout[0].nValue = nFees + CalculateCoinbaseReward(blockReward, consensus.dist.masternode); // Community payment always expected coinbaseTx.vout[1].scriptPubKey = consensus.foundationShareScript; diff --git a/test/functional/feature_block_reward.py b/test/functional/feature_block_reward.py new file mode 100644 index 0000000000..d40624652c --- /dev/null +++ b/test/functional/feature_block_reward.py @@ -0,0 +1,41 @@ +#!/usr/bin/env python3 +# Copyright (c) 2014-2019 The Bitcoin Core developers +# Copyright (c) DeFi Blockchain Developers +# Distributed under the MIT software license, see the accompanying +# file LICENSE or http://www.opensource.org/licenses/mit-license.php. +"""Test account mining behaviour""" + +from test_framework.test_framework import DefiTestFramework +from test_framework.authproxy import JSONRPCException +from test_framework.util import ( + assert_greater_than, + assert_equal +) +from decimal import Decimal + +class BlockRewardTest(DefiTestFramework): + def set_test_params(self): + self.num_nodes = 1 + self.setup_clean_chain = True + self.extra_args = [['-txnotokens=0', '-amkheight=50', '-eunosheight=100', '-eunosheight=100', '-subsidytest=1']] + + def run_test(self): + node = self.nodes[0] + node.generate(120) + + result = node.listaccounthistory("mine", {"depth":0}) + assert_equal(result[0]["amounts"][0], '134.99983200@DFI') + + account = node.getnewaddress() + txid = node.utxostoaccount({account: "1.1@0"}) + txid = node.utxostoaccount({account: "1.2@0"}) + txid = node.utxostoaccount({account: "1.3@0"}) + node.generate(1) + + result = node.listaccounthistory("mine", {"depth":0}) + for subResult in result: + if subResult["type"] == "blockReward": + assert_greater_than(subResult["amounts"][0], '134.99983200@DFI') + +if __name__ == '__main__': + BlockRewardTest().main () diff --git a/test/functional/test_runner.py b/test/functional/test_runner.py index e4acbe2ea0..77dd6a83cb 100755 --- a/test/functional/test_runner.py +++ b/test/functional/test_runner.py @@ -258,6 +258,7 @@ 'feature_burn_address.py', 'feature_eunos_balances.py', 'feature_sendutxosfrom.py', + 'feature_block_reward.py', # Don't append tests at the end to avoid merge conflicts # Put them in a random line within the section that fits their approximate run-time ] From 9516ae3f37fe9a367d43edf1f36c4fe80cee1f37 Mon Sep 17 00:00:00 2001 From: ShengguangXiao Date: Wed, 22 Sep 2021 03:57:21 +0000 Subject: [PATCH 2/4] Fix lint error --- test/functional/feature_block_reward.py | 8 +++----- 1 file changed, 3 insertions(+), 5 deletions(-) diff --git a/test/functional/feature_block_reward.py b/test/functional/feature_block_reward.py index d40624652c..4cb0986b2d 100644 --- a/test/functional/feature_block_reward.py +++ b/test/functional/feature_block_reward.py @@ -6,12 +6,10 @@ """Test account mining behaviour""" from test_framework.test_framework import DefiTestFramework -from test_framework.authproxy import JSONRPCException from test_framework.util import ( assert_greater_than, assert_equal ) -from decimal import Decimal class BlockRewardTest(DefiTestFramework): def set_test_params(self): @@ -27,9 +25,9 @@ def run_test(self): assert_equal(result[0]["amounts"][0], '134.99983200@DFI') account = node.getnewaddress() - txid = node.utxostoaccount({account: "1.1@0"}) - txid = node.utxostoaccount({account: "1.2@0"}) - txid = node.utxostoaccount({account: "1.3@0"}) + node.utxostoaccount({account: "1.1@0"}) + node.utxostoaccount({account: "1.2@0"}) + node.utxostoaccount({account: "1.3@0"}) node.generate(1) result = node.listaccounthistory("mine", {"depth":0}) From ea6f439619ea15625630ad1c218224775d3760e8 Mon Sep 17 00:00:00 2001 From: ShengguangXiao Date: Wed, 29 Sep 2021 14:24:56 +0000 Subject: [PATCH 3/4] Use defined number instead of magaic number result --- test/functional/feature_block_reward.py | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/test/functional/feature_block_reward.py b/test/functional/feature_block_reward.py index 4cb0986b2d..41b8c8542a 100644 --- a/test/functional/feature_block_reward.py +++ b/test/functional/feature_block_reward.py @@ -21,8 +21,12 @@ def run_test(self): node = self.nodes[0] node.generate(120) + newBaseBlockSubsidy = 405.0400 + masternodePortion = 0.3333 # 33.33% + mingBaseReward = newBaseBlockSubsidy * masternodePortion + result = node.listaccounthistory("mine", {"depth":0}) - assert_equal(result[0]["amounts"][0], '134.99983200@DFI') + assert_equal(result[0]["amounts"][0], f'{mingBaseReward:.8f}@DFI') account = node.getnewaddress() node.utxostoaccount({account: "1.1@0"}) @@ -33,7 +37,7 @@ def run_test(self): result = node.listaccounthistory("mine", {"depth":0}) for subResult in result: if subResult["type"] == "blockReward": - assert_greater_than(subResult["amounts"][0], '134.99983200@DFI') + assert_greater_than(subResult["amounts"][0], f'{mingBaseReward:.8f}@DFI') if __name__ == '__main__': BlockRewardTest().main () From 4e1f9c738e4f07243f0d93572301a59cded41778 Mon Sep 17 00:00:00 2001 From: ShengguangXiao Date: Thu, 30 Sep 2021 02:26:20 +0000 Subject: [PATCH 4/4] Addfork height check for including fees --- src/miner.cpp | 6 +++++- test/functional/feature_block_reward.py | 2 +- 2 files changed, 6 insertions(+), 2 deletions(-) diff --git a/src/miner.cpp b/src/miner.cpp index 16ec1b0fdc..db20e92f9b 100644 --- a/src/miner.cpp +++ b/src/miner.cpp @@ -239,7 +239,11 @@ std::unique_ptr BlockAssembler::CreateNewBlock(const CScript& sc coinbaseTx.vout.resize(2); // Explicitly set miner reward - coinbaseTx.vout[0].nValue = nFees + CalculateCoinbaseReward(blockReward, consensus.dist.masternode); + if (nHeight >= consensus.FortCanningHeight) { + coinbaseTx.vout[0].nValue = nFees + CalculateCoinbaseReward(blockReward, consensus.dist.masternode); + } else { + coinbaseTx.vout[0].nValue = CalculateCoinbaseReward(blockReward, consensus.dist.masternode); + } // Community payment always expected coinbaseTx.vout[1].scriptPubKey = consensus.foundationShareScript; diff --git a/test/functional/feature_block_reward.py b/test/functional/feature_block_reward.py index 41b8c8542a..8f0865061f 100644 --- a/test/functional/feature_block_reward.py +++ b/test/functional/feature_block_reward.py @@ -15,7 +15,7 @@ class BlockRewardTest(DefiTestFramework): def set_test_params(self): self.num_nodes = 1 self.setup_clean_chain = True - self.extra_args = [['-txnotokens=0', '-amkheight=50', '-eunosheight=100', '-eunosheight=100', '-subsidytest=1']] + self.extra_args = [['-txnotokens=0', '-amkheight=50', '-eunosheight=100', '-eunosheight=100', '-fortcanningheight=110', '-subsidytest=1']] def run_test(self): node = self.nodes[0]