Skip to content

add -maxrelaytxfee option #107

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

Draft
wants to merge 1 commit into
base: 28.x-knots
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions src/init.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -703,6 +703,8 @@ void SetupServerArgs(ArgsManager& argsman)
OptionsCategory::NODE_RELAY);
argsman.AddArg("-minrelaytxfee=<amt>", strprintf("Fees (in %s/kvB) smaller than this are considered zero fee for relaying, mining and transaction creation (default: %s)",
CURRENCY_UNIT, FormatMoney(DEFAULT_MIN_RELAY_TX_FEE)), ArgsManager::ALLOW_ANY, OptionsCategory::NODE_RELAY);
argsman.AddArg("-maxrelaytxfee=<amt>", strprintf("Fees (in %s/kvB) bigger than this are considered zero fee for relaying, mining and transaction creation (set to 0 to disable) (default: %s)",
CURRENCY_UNIT, DEFAULT_MAX_RELAY_TX_FEE), ArgsManager::ALLOW_ANY, OptionsCategory::NODE_RELAY);
argsman.AddArg("-rejectparasites", strprintf("Refuse to relay or mine parasitic overlay protocols (default: %u)", DEFAULT_REJECT_PARASITES), ArgsManager::ALLOW_ANY, OptionsCategory::NODE_RELAY);
argsman.AddArg("-rejecttokens",
strprintf("Refuse to relay or mine transactions involving non-bitcoin tokens (default: %u)",
Expand Down
3 changes: 3 additions & 0 deletions src/interfaces/chain.h
Original file line number Diff line number Diff line change
Expand Up @@ -295,6 +295,9 @@ class Chain
//! Relay incremental fee setting (-incrementalrelayfee), reflecting cost of relay.
virtual CFeeRate relayIncrementalFee() = 0;

//! Relay current maximum fee.
virtual CFeeRate relayMaxFee() = 0;

//! Relay dust fee setting (-dustrelayfee), reflecting lowest rate it's economical to spend.
virtual CFeeRate relayDustFee() = 0;

Expand Down
1 change: 1 addition & 0 deletions src/kernel/mempool_options.h
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,7 @@ struct MemPoolOptions {
CFeeRate incremental_relay_feerate{DEFAULT_INCREMENTAL_RELAY_FEE};
/** A fee rate smaller than this is considered zero fee (for relaying, mining and transaction creation) */
CFeeRate min_relay_feerate{DEFAULT_MIN_RELAY_TX_FEE};
CFeeRate max_relay_feerate{DEFAULT_MAX_RELAY_TX_FEE};
CFeeRate dust_relay_feerate{DUST_RELAY_TX_FEE};
CFeeRate dust_relay_feerate_floor{DUST_RELAY_TX_FEE};
/** Negative for a target number of blocks, positive for target kB into current mempool. */
Expand Down
5 changes: 5 additions & 0 deletions src/node/interfaces.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -779,6 +779,11 @@ class ChainImpl : public Chain
if (!m_node.mempool) return CFeeRate{DEFAULT_INCREMENTAL_RELAY_FEE};
return m_node.mempool->m_opts.incremental_relay_feerate;
}
CFeeRate relayMaxFee() override
{
if (!m_node.mempool) return CFeeRate{DEFAULT_MAX_RELAY_TX_FEE};
return m_node.mempool->m_opts.max_relay_feerate;
}
CFeeRate relayDustFee() override
{
if (!m_node.mempool) return CFeeRate{DUST_RELAY_TX_FEE};
Expand Down
8 changes: 8 additions & 0 deletions src/node/mempool_args.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -122,6 +122,14 @@ util::Result<void> ApplyArgsManOptions(const ArgsManager& argsman, const CChainP
LogPrintf("Increasing minrelaytxfee to %s to match incrementalrelayfee\n", mempool_opts.min_relay_feerate.ToString());
}

if (argsman.IsArgSet("-maxrelaytxfee")) {
if (std::optional<CAmount> max_relay_feerate = ParseMoney(argsman.GetArg("-maxrelaytxfee", ""))) {
mempool_opts.max_relay_feerate = CFeeRate{max_relay_feerate.value()};
} else {
return util::Error{AmountErrMsg("maxrelayfee", argsman.GetArg("-maxrelaytxfee", ""))};
}
}

// Feerate used to define dust. Shouldn't be changed lightly as old
// implementations may inadvertently create non-standard transactions
if (argsman.IsArgSet("-dustrelayfee")) {
Expand Down
2 changes: 2 additions & 0 deletions src/policy/policy.h
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,8 @@ static const int DEFAULT_DUST_RELAY_MULTIPLIER{3'000};
static const std::string DEFAULT_SPKREUSE{"allow"};
/** Default for -minrelaytxfee, minimum relay fee for transactions */
static constexpr unsigned int DEFAULT_MIN_RELAY_TX_FEE{1000};
/** Default for -maxrelaytxfee, minimum relay fee for transactions */
static constexpr unsigned int DEFAULT_MAX_RELAY_TX_FEE{0};
/** Default for -limitancestorcount, max number of in-mempool ancestors */
static constexpr unsigned int DEFAULT_ANCESTOR_LIMIT{25};
/** Default for -limitancestorsize, maximum kilobytes of tx + all in-mempool ancestors */
Expand Down
6 changes: 6 additions & 0 deletions src/validation.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1086,6 +1086,12 @@ bool MemPoolAccept::PreChecks(ATMPArgs& args, Workspace& ws)
// feerate later.
if (!args.m_package_feerates && !CheckFeeRate(ws.m_vsize, ws.m_modified_fees, state, args.m_ignore_rejects)) return false;


if ((ws.m_ptx->version != TRUC_VERSION || m_pool.m_opts.truc_policy != TRUCPolicy::Enforce) && ws.m_modified_fees > m_pool.m_opts.max_relay_feerate.GetFee(ws.m_vsize) && m_pool.m_opts.max_relay_feerate != CFeeRate{0}) {
return state.Invalid(TxValidationResult::TX_MEMPOOL_POLICY, "max relay fee met",
strprintf("%d < %d", ws.m_modified_fees, m_pool.m_opts.max_relay_feerate.GetFee(ws.m_vsize)));
}

std::set<Txid> conflicts_as_a_set;
std::transform(ws.m_conflicts_incl_policy.begin(), ws.m_conflicts_incl_policy.end(),
std::inserter(conflicts_as_a_set, conflicts_as_a_set.end()),
Expand Down