Skip to content

Commit 15d09d0

Browse files
author
Tom Trevethan
committed
remove config option and apply for policy asset
1 parent 9c5271e commit 15d09d0

12 files changed

+20
-26
lines changed

src/chainparams.cpp

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -898,8 +898,6 @@ class CCustomParams : public CRegTestParams {
898898
std::vector<unsigned char> man_bytes = ParseHex(args.GetArg("-con_mandatorycoinbase", ""));
899899
consensus.mandatory_coinbase_destination = CScript(man_bytes.begin(), man_bytes.end()); // Blank script allows any coinbase destination
900900

901-
consensus.allow_any_fee = args.GetBoolArg("-con_allow_any_fee", consensus.allow_any_fee);
902-
903901
// Custom chains connect coinbase outputs to db by default
904902
consensus.connect_genesis_outputs = args.GetIntArg("-con_connect_genesis_outputs", true);
905903

@@ -1517,8 +1515,6 @@ class CLiquidV1TestParams : public CLiquidV1Params {
15171515
consensus.mandatory_coinbase_destination = CScript(man_bytes.begin(), man_bytes.end()); // Blank script allows any coinbase destination
15181516
}
15191517

1520-
consensus.allow_any_fee = args.GetBoolArg("-con_allow_any_fee", consensus.allow_any_fee);
1521-
15221518
consensus.connect_genesis_outputs = args.GetIntArg("-con_connect_genesis_outputs", consensus.connect_genesis_outputs);
15231519

15241520
initialFreeCoins = args.GetIntArg("-initialfreecoins", initialFreeCoins);

src/chainparamsbase.cpp

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,6 @@ void SetupChainParamsBaseOptions(ArgsManager& argsman)
4545
argsman.AddArg("-con_signed_blocks", "Signed blockchain. Uses input of `-signblockscript` to define what signatures are necessary to solve it.", ArgsManager::ALLOW_ANY, OptionsCategory::CHAINPARAMS);
4646
argsman.AddArg("-signblockscript", "Signed blockchain enumberance. Only active when `-con_signed_blocks` set to true.", ArgsManager::ALLOW_ANY, OptionsCategory::CHAINPARAMS);
4747
argsman.AddArg("-con_max_block_sig_size", "Max allowed witness data for the signed block header.", ArgsManager::ALLOW_ANY, OptionsCategory::CHAINPARAMS);
48-
argsman.AddArg("-con_allow_any_fee", "Allow any fee value for any asset", ArgsManager::ALLOW_ANY, OptionsCategory::CHAINPARAMS);
4948

5049
argsman.AddArg("-con_has_parent_chain", "Whether or not there is a parent chain.", ArgsManager::ALLOW_ANY, OptionsCategory::CHAINPARAMS);
5150
argsman.AddArg("-parentgenesisblockhash", "The genesis blockhash of the parent chain.", ArgsManager::ALLOW_ANY, OptionsCategory::CHAINPARAMS);

src/confidential_validation.cpp

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11

2+
#include <chainparams.h>
23
#include <confidential_validation.h>
34
#include <issuance.h>
45
#include <pegins.h>
@@ -24,20 +25,20 @@ class CSecp256k1Init {
2425
static CSecp256k1Init instance_of_csecp256k1;
2526
}
2627

27-
bool HasValidFee(const CTransaction& tx, bool allow_any_fee) {
28+
bool HasValidFee(const CTransaction& tx) {
2829
CAmountMap totalFee;
2930
for (unsigned int i = 0; i < tx.vout.size(); i++) {
3031
CAmount fee = 0;
31-
if (tx.vout[i].IsFee()) {
32+
if (tx.vout[i].IsFee() && tx.vout[i].nAsset.GetAsset() == Params().GetConsensus().pegged_asset) {
3233
fee = tx.vout[i].nValue.GetAmount();
33-
if (!allow_any_fee && (fee == 0 || !MoneyRange(fee))) {
34+
if (fee == 0 || !MoneyRange(fee)) {
3435
return false;
3536
}
3637
totalFee[tx.vout[i].nAsset.GetAsset()] += fee;
37-
if (!allow_any_fee && !MoneyRange(totalFee)) {
38+
if (!MoneyRange(totalFee)) {
3839
return false;
3940
}
40-
if(allow_any_fee && fee < 0) {
41+
if(fee < 0) {
4142
return false;
4243
}
4344
}

src/confidential_validation.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@
1515

1616

1717
// Check if explicit TX fees overflow or are negative
18-
bool HasValidFee(const CTransaction& tx, bool allow_any_fee);
18+
bool HasValidFee(const CTransaction& tx);
1919

2020
// Compute the fee from the explicit fee outputs. Must call HasValidFee first
2121
CAmountMap GetFeeMap(const CTransaction& tx);

src/consensus/params.h

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -175,7 +175,6 @@ struct Params {
175175
size_t total_valid_epochs = 1;
176176
bool elements_mode = false;
177177
bool start_p2wsh_script = false;
178-
bool allow_any_fee = false;
179178
};
180179

181180
} // namespace Consensus

src/consensus/tx_verify.cpp

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414
#include <script/interpreter.h>
1515
#include <script/pegins.h>
1616
#include <util/moneystr.h>
17+
#include <chainparams.h>
1718

1819
bool IsFinalTx(const CTransaction &tx, int nBlockHeight, int64_t nBlockTime)
1920
{
@@ -192,7 +193,7 @@ int64_t GetTransactionSigOpCost(const CTransaction& tx, const CCoinsViewCache& i
192193
return nSigOps;
193194
}
194195

195-
bool Consensus::CheckTxInputs(const CTransaction& tx, TxValidationState& state, const CCoinsViewCache& inputs, int nSpendHeight, CAmountMap& fee_map, std::set<std::pair<uint256, COutPoint>>& setPeginsSpent, std::vector<CCheck*> *pvChecks, const bool cacheStore, bool fScriptChecks, const std::vector<std::pair<CScript, CScript>>& fedpegscripts, bool allow_any_fee)
196+
bool Consensus::CheckTxInputs(const CTransaction& tx, TxValidationState& state, const CCoinsViewCache& inputs, int nSpendHeight, CAmountMap& fee_map, std::set<std::pair<uint256, COutPoint>>& setPeginsSpent, std::vector<CCheck*> *pvChecks, const bool cacheStore, bool fScriptChecks, const std::vector<std::pair<CScript, CScript>>& fedpegscripts)
196197
{
197198
// are the actual inputs available?
198199
if (!inputs.HaveInputs(tx)) {
@@ -245,7 +246,7 @@ bool Consensus::CheckTxInputs(const CTransaction& tx, TxValidationState& state,
245246

246247
if (g_con_elementsmode) {
247248
// Tally transaction fees
248-
if (!HasValidFee(tx, allow_any_fee)) {
249+
if (!HasValidFee(tx)) {
249250
return state.Invalid(TxValidationResult::TX_CONSENSUS, "bad-txns-fee-outofrange");
250251
}
251252

@@ -254,7 +255,7 @@ bool Consensus::CheckTxInputs(const CTransaction& tx, TxValidationState& state,
254255
return state.Invalid(TxValidationResult::TX_CONSENSUS, "bad-txns-in-ne-out", "value in != value out");
255256
}
256257
fee_map += GetFeeMap(tx);
257-
if (allow_any_fee && !MoneyRange(fee_map)) {
258+
if (!MoneyRange(fee_map[::Params().GetConsensus().pegged_asset])) {
258259
return state.Invalid(TxValidationResult::TX_CONSENSUS, "bad-block-total-fee-outofrange");
259260
}
260261
} else {

src/consensus/tx_verify.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ namespace Consensus {
2828
* @param[out] fee_map Set to the transaction fee if successful.
2929
* Preconditions: tx.IsCoinBase() is false.
3030
*/
31-
[[nodiscard] ]bool CheckTxInputs(const CTransaction& tx, TxValidationState& state, const CCoinsViewCache& inputs, int nSpendHeight, CAmountMap& fee_map, std::set<std::pair<uint256, COutPoint>>& setPeginsSpent, std::vector<CCheck*> *pvChecks, const bool cacheStore, bool fScriptChecks, const std::vector<std::pair<CScript, CScript>>& fedpegscripts, bool allow_any_fee);
31+
[[nodiscard] ]bool CheckTxInputs(const CTransaction& tx, TxValidationState& state, const CCoinsViewCache& inputs, int nSpendHeight, CAmountMap& fee_map, std::set<std::pair<uint256, COutPoint>>& setPeginsSpent, std::vector<CCheck*> *pvChecks, const bool cacheStore, bool fScriptChecks, const std::vector<std::pair<CScript, CScript>>& fedpegscripts);
3232
} // namespace Consensus
3333

3434
/** Auxiliary functions for transaction validation (ideally should not be exposed) */

src/test/fuzz/coins_view.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -252,7 +252,7 @@ FUZZ_TARGET_INIT(coins_view, initialize_coins_view)
252252
}
253253
std::vector<std::pair<CScript, CScript>> fedpegscripts; // ELEMENTS: we ought to populate this and have a more useful fuzztest
254254
std::set<std::pair<uint256, COutPoint> > setPeginsSpent;
255-
if (Consensus::CheckTxInputs(transaction, state, coins_view_cache, fuzzed_data_provider.ConsumeIntegralInRange<int>(0, std::numeric_limits<int>::max()), tx_fee_map, setPeginsSpent, NULL, false, true, fedpegscripts, false)) {
255+
if (Consensus::CheckTxInputs(transaction, state, coins_view_cache, fuzzed_data_provider.ConsumeIntegralInRange<int>(0, std::numeric_limits<int>::max()), tx_fee_map, setPeginsSpent, NULL, false, true, fedpegscripts)) {
256256
assert(MoneyRange(tx_fee_map));
257257
}
258258
},

src/test/pegin_witness_tests.cpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -123,15 +123,15 @@ BOOST_AUTO_TEST_CASE(witness_valid)
123123
CCoinsViewCache coins(&coinsDummy);
124124
// Get the latest block index to look up fedpegscripts
125125
// For these tests, should be genesis-block-hardcoded consensus.fedpegscript
126-
BOOST_CHECK(Consensus::CheckTxInputs(tx, state, coins, 0, fee_map, setPeginsSpent, NULL, false, true, fedpegscripts, false));
126+
BOOST_CHECK(Consensus::CheckTxInputs(tx, state, coins, 0, fee_map, setPeginsSpent, NULL, false, true, fedpegscripts));
127127
BOOST_CHECK(setPeginsSpent.size() == 1);
128128
setPeginsSpent.clear();
129129

130130
// Strip pegin_witness
131131
CMutableTransaction mtxn(tx);
132132
mtxn.witness.vtxinwit[0].m_pegin_witness.SetNull();
133133
CTransaction tx2(mtxn);
134-
BOOST_CHECK(!Consensus::CheckTxInputs(tx2, state, coins, 0, fee_map, setPeginsSpent, NULL, false, true, fedpegscripts, false));
134+
BOOST_CHECK(!Consensus::CheckTxInputs(tx2, state, coins, 0, fee_map, setPeginsSpent, NULL, false, true, fedpegscripts));
135135
BOOST_CHECK(setPeginsSpent.empty());
136136

137137
// Invalidate peg-in (and spending) authorization by pegin marker.
@@ -140,7 +140,7 @@ BOOST_AUTO_TEST_CASE(witness_valid)
140140
CMutableTransaction mtxn2(tx);
141141
mtxn2.vin[0].m_is_pegin = false;
142142
CTransaction tx3(mtxn2);
143-
BOOST_CHECK(!Consensus::CheckTxInputs(tx3, state, coins, 0, fee_map, setPeginsSpent, NULL, false, true, fedpegscripts, false));
143+
BOOST_CHECK(!Consensus::CheckTxInputs(tx3, state, coins, 0, fee_map, setPeginsSpent, NULL, false, true, fedpegscripts));
144144
BOOST_CHECK(setPeginsSpent.empty());
145145

146146

src/txmempool.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -895,7 +895,7 @@ void CTxMemPool::check(const CBlockIndex* active_chain_tip, const CCoinsViewCach
895895
const auto& fedpegscripts = GetValidFedpegScripts(active_chain_tip, Params().GetConsensus(), true /* nextblock_validation */);
896896
bool cacheStore = true;
897897
bool fScriptChecks = true;
898-
assert(Consensus::CheckTxInputs(tx, dummy_state, mempoolDuplicate, spendheight, fee_map, setPeginsSpent, nullptr, cacheStore, fScriptChecks, fedpegscripts, Params().GetConsensus().allow_any_fee));
898+
assert(Consensus::CheckTxInputs(tx, dummy_state, mempoolDuplicate, spendheight, fee_map, setPeginsSpent, nullptr, cacheStore, fScriptChecks, fedpegscripts));
899899
for (const auto& input: tx.vin) mempoolDuplicate.SpendCoin(input.prevout);
900900
AddCoins(mempoolDuplicate, tx, std::numeric_limits<int>::max());
901901
}

0 commit comments

Comments
 (0)