Skip to content

Commit 31741b3

Browse files
author
Tom Trevethan
committed
add allow any fee config
1 parent c4bc9fd commit 31741b3

15 files changed

+91
-17
lines changed

src/chainparams.cpp

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -898,6 +898,8 @@ 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+
901903
// Custom chains connect coinbase outputs to db by default
902904
consensus.connect_genesis_outputs = args.GetIntArg("-con_connect_genesis_outputs", true);
903905

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

1520+
consensus.allow_any_fee = args.GetBoolArg("-con_allow_any_fee", consensus.allow_any_fee);
1521+
15181522
consensus.connect_genesis_outputs = args.GetIntArg("-con_connect_genesis_outputs", consensus.connect_genesis_outputs);
15191523

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

src/chainparamsbase.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,7 @@ 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);
4849

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

src/confidential_validation.cpp

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -24,16 +24,20 @@ class CSecp256k1Init {
2424
static CSecp256k1Init instance_of_csecp256k1;
2525
}
2626

27-
bool HasValidFee(const CTransaction& tx) {
27+
bool HasValidFee(const CTransaction& tx, bool allow_any_fee) {
2828
CAmountMap totalFee;
2929
for (unsigned int i = 0; i < tx.vout.size(); i++) {
3030
CAmount fee = 0;
3131
if (tx.vout[i].IsFee()) {
3232
fee = tx.vout[i].nValue.GetAmount();
33-
if (fee == 0 || !MoneyRange(fee))
33+
if (!allow_any_fee && (fee == 0 || !MoneyRange(fee))) {
3434
return false;
35+
}
3536
totalFee[tx.vout[i].nAsset.GetAsset()] += fee;
36-
if (!MoneyRange(totalFee)) {
37+
if (!allow_any_fee && !MoneyRange(totalFee)) {
38+
return false;
39+
}
40+
if(allow_any_fee && fee < 0) {
3741
return false;
3842
}
3943
}

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);
18+
bool HasValidFee(const CTransaction& tx, bool allow_any_fee);
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: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -175,6 +175,7 @@ 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;
178179
};
179180

180181
} // namespace Consensus

src/consensus/tx_verify.cpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -192,7 +192,7 @@ int64_t GetTransactionSigOpCost(const CTransaction& tx, const CCoinsViewCache& i
192192
return nSigOps;
193193
}
194194

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)
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)
196196
{
197197
// are the actual inputs available?
198198
if (!inputs.HaveInputs(tx)) {
@@ -245,7 +245,7 @@ bool Consensus::CheckTxInputs(const CTransaction& tx, TxValidationState& state,
245245

246246
if (g_con_elementsmode) {
247247
// Tally transaction fees
248-
if (!HasValidFee(tx)) {
248+
if (!HasValidFee(tx, allow_any_fee)) {
249249
return state.Invalid(TxValidationResult::TX_CONSENSUS, "bad-txns-fee-outofrange");
250250
}
251251

@@ -254,7 +254,7 @@ bool Consensus::CheckTxInputs(const CTransaction& tx, TxValidationState& state,
254254
return state.Invalid(TxValidationResult::TX_CONSENSUS, "bad-txns-in-ne-out", "value in != value out");
255255
}
256256
fee_map += GetFeeMap(tx);
257-
if (!MoneyRange(fee_map)) {
257+
if (allow_any_fee && !MoneyRange(fee_map)) {
258258
return state.Invalid(TxValidationResult::TX_CONSENSUS, "bad-block-total-fee-outofrange");
259259
}
260260
} 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);
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);
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)) {
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)) {
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));
126+
BOOST_CHECK(Consensus::CheckTxInputs(tx, state, coins, 0, fee_map, setPeginsSpent, NULL, false, true, fedpegscripts, false));
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));
134+
BOOST_CHECK(!Consensus::CheckTxInputs(tx2, state, coins, 0, fee_map, setPeginsSpent, NULL, false, true, fedpegscripts, false));
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));
143+
BOOST_CHECK(!Consensus::CheckTxInputs(tx3, state, coins, 0, fee_map, setPeginsSpent, NULL, false, true, fedpegscripts, false));
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));
898+
assert(Consensus::CheckTxInputs(tx, dummy_state, mempoolDuplicate, spendheight, fee_map, setPeginsSpent, nullptr, cacheStore, fScriptChecks, fedpegscripts, Params().GetConsensus().allow_any_fee));
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)