Skip to content
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

backport: merge bitcoin#22689, #23381, #22674, #23804, #24310, #24537, #24582, #24404, #25013, #25029, #25254, #25388 (mempool backports) #6499

Merged
merged 12 commits into from
Dec 30, 2024

Conversation

kwvg
Copy link
Collaborator

@kwvg kwvg commented Dec 20, 2024

Additional Information

  • bitcoin#23694 (backported in dash#6256) was backported before bitcoin#22689 and therefore, the formatting changes in the former were not incorporated in the backport. This has been resolved by accommodating them in the latter.

  • The fields deprecated in bitcoin#22689 were originally deprecated in bitcoin#12240 but not gated behind runtime arguments, the backport does so.

  • This pull request includes multiple backports that include code specific to RBF (BIP 125) and SegWit, which have been removed due to Dash Core not supporting them, comments and documentation (like doc/policy/packages.md) have been amended to reflect this accordingly.

  • When backporting bitcoin#22674, a new constructor was introduced for submitting MEMPOOL_ENTRY ResultType, upstream this can be done trivially as it uses function overloading (source) but as Dash Core doesn't accept
    replaced_txns, there is no opportunity to differentiate arguments.

    • This was resolved by accepting ResultType as an argument but always passing MEMPOOL_ENTRY as the argument (source)
  • Unit tests like package_witness_swap_tests (introduced in bitcoin#23804) have been omitted due to functionality tested not being implemented in Dash Core. Subsequent backports that include modifications to these tests have mirrored similar omissions.

Breaking Changes

  • The top-level fee fields fee, modifiedfee, ancestorfees and descendantfees returned by RPCs getmempoolentry,getrawmempool(verbose=true), getmempoolancestors(verbose=true) and getmempooldescendants(verbose=true) are deprecated and will be removed in the next major version (use -deprecated=fees if needed in this version). The same fee fields can be accessed through the fees object in the result.

    WARNING: deprecated fields ancestorfees and descendantfees are denominated in sats, whereas all fields in the fees object are denominated in DASH.

Checklist

  • 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)

@kwvg kwvg added this to the 22.1 milestone Dec 20, 2024
@kwvg kwvg marked this pull request as ready for review December 24, 2024 11:23
Copy link

coderabbitai bot commented Dec 24, 2024

Walkthrough

This pull request introduces significant changes to the Dash Core codebase, focusing on transaction package management, mempool operations, and RPC command restructuring. The modifications include the addition of new documentation about transaction relay policies, implementation of package acceptance rules for transactions, and comprehensive updates to RPC commands related to mempool interactions.

Key areas of change include the introduction of new methods for handling transaction packages, refactoring of mempool acceptance logic, and the deprecation of certain fee-related fields in RPC responses. The changes enhance the robustness of transaction validation, provide more detailed fee information, and improve the overall transaction processing capabilities of the Dash Core implementation.

The pull request also includes extensive test coverage for the new functionality, with new test cases specifically designed to validate the package transaction validation, mempool entry fee field changes, and RPC command behaviors. These modifications represent a significant evolution in the transaction processing and mempool management strategies of the Dash Core software.

Tip

CodeRabbit's docstrings feature is now available as part of our Early Access Program! Simply use the command @coderabbitai generate docstrings to have CodeRabbit automatically generate docstrings for your pull request. We would love to hear your feedback on Discord.


Thank you for using CodeRabbit. We offer it for free to the OSS community and would appreciate your support in helping us grow. If you find it useful, would you consider giving us a shout-out on your favorite social media?

❤️ Share
🪧 Tips

Chat

There are 3 ways to chat with CodeRabbit:

  • Review comments: Directly reply to a review comment made by CodeRabbit. Example:
    • I pushed a fix in commit <commit_id>, please review it.
    • Generate unit testing code for this file.
    • Open a follow-up GitHub issue for this discussion.
  • Files and specific lines of code (under the "Files changed" tab): Tag @coderabbitai in a new review comment at the desired location with your query. Examples:
    • @coderabbitai generate unit testing code for this file.
    • @coderabbitai modularize this function.
  • PR comments: Tag @coderabbitai in a new PR comment to ask questions about the PR branch. For the best results, please provide a very specific query, as very limited context is provided in this mode. Examples:
    • @coderabbitai gather interesting stats about this repository and render them as a table. Additionally, render a pie chart showing the language distribution in the codebase.
    • @coderabbitai read src/utils.ts and generate unit testing code.
    • @coderabbitai read the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.
    • @coderabbitai help me debug CodeRabbit configuration file.

Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments.

CodeRabbit Commands (Invoked using PR comments)

  • @coderabbitai pause to pause the reviews on a PR.
  • @coderabbitai resume to resume the paused reviews.
  • @coderabbitai review to trigger an incremental review. This is useful when automatic reviews are disabled for the repository.
  • @coderabbitai full review to do a full review from scratch and review all the files again.
  • @coderabbitai summary to regenerate the summary of the PR.
  • @coderabbitai generate docstrings to generate docstrings for this PR. (Beta)
  • @coderabbitai resolve resolve all the CodeRabbit review comments.
  • @coderabbitai configuration to show the current CodeRabbit configuration for the repository.
  • @coderabbitai help to get help.

Other keywords and placeholders

  • Add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.
  • Add @coderabbitai summary to generate the high-level summary at a specific location in the PR description.
  • Add @coderabbitai anywhere in the PR title to generate the title automatically.

CodeRabbit Configuration File (.coderabbit.yaml)

  • You can programmatically configure CodeRabbit by adding a .coderabbit.yaml file to the root of your repository.
  • Please see the configuration documentation for more information.
  • If your editor has YAML language server enabled, you can add the path at the top of this file to enable auto-completion and validation: # yaml-language-server: $schema=https://coderabbit.ai/integrations/schema.v2.json

Documentation and Community

  • Visit our Documentation for detailed information on how to use CodeRabbit.
  • Join our Discord Community to get help, request features, and share feedback.
  • Follow us on X/Twitter for updates and announcements.

Copy link

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

edited to be empty to avoid spamming the commit log

Comment on lines +209 to +274
RPCHelpMan getmempoolancestors()
{
return RPCHelpMan{"getmempoolancestors",
"\nIf txid is in the mempool, returns all in-mempool ancestors.\n",
{
{"txid", RPCArg::Type::STR_HEX, RPCArg::Optional::NO, "The transaction id (must be in mempool)"},
{"verbose", RPCArg::Type::BOOL, RPCArg::Default{false}, "True for a json object, false for array of transaction ids"},
},
{
RPCResult{"for verbose = false",
RPCResult::Type::ARR, "", "",
{{RPCResult::Type::STR_HEX, "", "The transaction id of an in-mempool ancestor transaction"}}},
RPCResult{"for verbose = true",
RPCResult::Type::OBJ_DYN, "", "",
{
{RPCResult::Type::OBJ, "transactionid", "", MempoolEntryDescription()},
}},
},
RPCExamples{
HelpExampleCli("getmempoolancestors", "\"mytxid\"")
+ HelpExampleRpc("getmempoolancestors", "\"mytxid\"")
},
[&](const RPCHelpMan& self, const JSONRPCRequest& request) -> UniValue
{
bool fVerbose = false;
if (!request.params[1].isNull())
fVerbose = request.params[1].get_bool();

uint256 hash(ParseHashV(request.params[0], "parameter 1"));

const NodeContext& node = EnsureAnyNodeContext(request.context);

const CTxMemPool& mempool = EnsureMemPool(node);
LOCK(mempool.cs);

CTxMemPool::txiter it = mempool.mapTx.find(hash);
if (it == mempool.mapTx.end()) {
throw JSONRPCError(RPC_INVALID_ADDRESS_OR_KEY, "Transaction not in mempool");
}

CTxMemPool::setEntries setAncestors;
uint64_t noLimit = std::numeric_limits<uint64_t>::max();
std::string dummy;
mempool.CalculateMemPoolAncestors(*it, setAncestors, noLimit, noLimit, noLimit, noLimit, dummy, false);

if (!fVerbose) {
UniValue o(UniValue::VARR);
for (CTxMemPool::txiter ancestorIt : setAncestors) {
o.push_back(ancestorIt->GetTx().GetHash().ToString());
}
return o;
} else {
UniValue o(UniValue::VOBJ);
const LLMQContext& llmq_ctx = EnsureLLMQContext(node);
for (CTxMemPool::txiter ancestorIt : setAncestors) {
const CTxMemPoolEntry &e = *ancestorIt;
const uint256& _hash = e.GetTx().GetHash();
UniValue info(UniValue::VOBJ);
entryToJSON(mempool, info, e, llmq_ctx.isman);
o.pushKV(_hash.ToString(), info);
}
return o;
}
},
};
}
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🛠️ Refactor suggestion

Check for ancestor-limit edge cases.
When calling CalculateMemPoolAncestors, ensure the method handles near-max-ancestor scenarios gracefully. A thorough test verifying behavior around boundary conditions is advisable.

Comment on lines +433 to +466
RPCHelpMan savemempool()
{
return RPCHelpMan{"savemempool",
"\nDumps the mempool to disk. It will fail until the previous dump is fully loaded.\n",
{},
RPCResult{
RPCResult::Type::OBJ, "", "",
{
{RPCResult::Type::STR, "filename", "the directory and file where the mempool was saved"},
}},
RPCExamples{
HelpExampleCli("savemempool", "")
+ HelpExampleRpc("savemempool", "")
},
[&](const RPCHelpMan& self, const JSONRPCRequest& request) -> UniValue
{
const ArgsManager& args{EnsureAnyArgsman(request.context)};
const CTxMemPool& mempool = EnsureAnyMemPool(request.context);

if (!mempool.IsLoaded()) {
throw JSONRPCError(RPC_MISC_ERROR, "The mempool was not loaded yet");
}

if (!DumpMempool(mempool)) {
throw JSONRPCError(RPC_MISC_ERROR, "Unable to dump mempool to disk");
}

UniValue ret(UniValue::VOBJ);
ret.pushKV("filename", fs::path((args.GetDataDirNet() / "mempool.dat")).u8string());

return ret;
},
};
}
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🛠️ Refactor suggestion

Handle race condition on shutdown.
savemempool writes the mempool to disk. If the node is shutting down or reloading, carefully ensure that the file is not corrupted. Possibly handle partial writes more robustly.

Comment on lines +20 to +21
/** A fee rate smaller than this is considered zero fee (for relaying, mining and transaction creation) */
extern CFeeRate minRelayTxFee;
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🛠️ Refactor suggestion

Declare minRelayTxFee as an external variable

Introducing minRelayTxFee helps unify zero-fee behaviors across relaying, mining, and transaction creation. Confirm it remains in sync with other fee rate changes (e.g., dustRelayFee, incrementalRelayFee) and that any future configuration changes apply consistently.

Copy link

@UdjinM6 UdjinM6 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

utACK 578be36

Copy link
Member

@PastaPastaPasta PastaPastaPasta left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

utACK 578be36

@PastaPastaPasta PastaPastaPasta merged commit a5787c9 into dashpay:develop Dec 30, 2024
25 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants