8000 add RPC (-regtest only) for testing package policy by glozow · Pull Request #24836 · bitcoin/bitcoin · GitHub
[go: up one dir, main page]
More Web Proxy on the site http://driver.im/
Skip to content

add RPC (-regtest only) for testing package policy #24836

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

Merged
merged 2 commits into from
Jun 30, 2022

Conversation

glozow
Copy link
Member
@glozow glozow commented Apr 12, 2022

It would be nice for LN/wallet/app devs to test out package policy, package RBF, etc., but the only interface to do so right now is through unit tests. This PR adds a -regtest only RPC interface so people can test by submitting raw transaction data. It is regtest-only, as it would be unsafe/confusing to create an actual mainnet interface while package relay doesn't exist.

Note that the functional tests are there to ensure the RPC interface is working properly; they aren't for testing policy itself. See src/test/txpackage_tests.cpp.

@glozow
Copy link
Member Author
glozow commented Apr 12, 2022

TODOs (probably for future PRs):

  • Automatically build the package using the child transaction, i.e. when we already have unconfirmed parents in the mempool or mapWallet. I expect to have this before package relay (users shouldn't be expected to construct packages themselves imo), but just haven't implemented it yet. LMK if this is something you want now.
  • Add maxfeerate to allow users to set a maximum package feerate. This just requires adding a TestPackage codepath separate from testmempoolaccept so we can say "just kidding" if the validation succeeds.

@luke-jr
Copy link
Member
luke-jr commented Apr 13, 2022

It could be unsafe/confusing to create an actual mainnet interface while package relay doesn't exist.

How so?

However, it's currently very inconvenient for wallet/application devs to try to test current package policies.

They shouldn't need to. No assumptions should be made about user package policies...

Copy link
Member
@maflcko maflcko left a comment

Choose a reason for hiding this comment

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

only nits

@glozow
Copy link
Member Author
glozow commented Apr 13, 2022

It could be unsafe/confusing to create an actual mainnet interface while package relay doesn't exist.

How so?

Until package relay, it's unreasonable to assume that anything submitted to the mempool this way will propagate. For example, package cpfp allows 0-fee transactions to be accepted to the mempool if they have a high-fee child. But this likely won't go much further than the user's mempool, since most nodes will reject 0-fee transactions.

However, it's currently very inconvenient for wallet/application devs to try to test current package policies.

They shouldn't need to. No assumptions should be made about user package policies...

The point here is to encourage testing. Even if they aren't supposed to rely on the interface, the reality is that most nodes run bitcoind and don't configure their nodes differently, it's a good idea for wallet/application devs to write a test suite for what their expectations are. I would also prefer to know as early as possible (i.e. PR comment or in RC testing, not catastrophic bug after release) if we're going to accidentally harm LN tx propagation with a policy restriction, as >$100million of the network is in it.

Copy link
@ariard ariard left a comment

Choose a reason for hiding this comment

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

Minors, otherwise SGTM.

@ariard
Copy link
ariard commented Apr 13, 2022

They shouldn't need to. No assumptions should be made about user package policies...

Why no assumptions should be made about user package policies ? Could you layout the reasoning underpinning that statement ?

I believe to be of a contrary position. I think the default core policy should be designed to be compatible with miner incentives. In the present case, accepting relayed packages should increase your mining fee reward. If we assume that the majority of users are economically rational, they aim for their mempools contents to reflect the state of the next blocks and thus they should relay packages. Under this assumption concerning the base layer, I think an upper layer like LN can expect a policy like package relay to be widely supported.

@luke-jr
Copy link
Member
luke-jr commented Apr 13, 2022

Until package relay, it's unreasonable to assume that anything submitted to the mempool this way will propagate. For example, package cpfp allows 0-fee transactions to be accepted to the mempool if they have a high-fee child. But this likely won't go much further than the user's mempool, since most nodes will reject 0-fee transactions.

Propagation isn't a guarantee made by sendrawtransaction either, and could very well be in the same situation if node policies don't align.

Seems like this PR should just be a modification to sendrawtransaction IMO. (If there's a reason to make it regtest-only, that can still be done without a new RPC method)

Why no assumptions should be made about user package policies ?

Users should ideally decide their own policies. This is especially true when consideration is being made for security purposes.

I think the default core policy should be designed to be compatible with miner incentives.

That's illogical. Most nodes aren't miners, and don't benefit from miner incentives. They create miner incentives, by deciding their own policies (blocks which don't match the node policy will relay slower).

If we assume that the majority of users are economically rational, they aim for their mempools contents to reflect the state of the next blocks and thus they should relay packages.

There is no economically rational reason for this. Miners have a reason to match node policies, but nodes do not really benefit from matching miners.

Under this assumption concerning the base layer, I think an upper layer like LN can expect a policy like package relay to be widely supported.

It presently isn't...

@glozow glozow force-pushed the client-submitpackage branch from f091063 to 04bb600 Compare April 13, 2022 17:35
@glozow
Copy link
Member Author
glozow commented Apr 13, 2022

Addressed comments from @MarcoFalke and @ariard. Also renamed s/submitrawpackage/submitpackage because I don't think we'd ever submit non-raw packages.

Copy link
@ariard ariard left a comment

Choose a reason for hiding this comment

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

Code Review ACK 04bb600

@ariard
Copy link
ariard commented Apr 15, 2022

Users should ideally decide their own policies. This is especially true when consideration is being made for security purposes.

Users deciding their own policies doesn't mean they won't spontaneously converge towards few common policies per type of bitcoin applications/hosts.

They create miner incentives, by deciding their own policies (blocks which don't match the node policy will relay slower).

If we define further miner incentives as optimizing block fee reward, i don't think node policies creates them. Nodes policies (full-rbf, package relay) are just means to achieve the incentives. I'm not sure it's a sane node policy to reject consensus-valid blocks.

There is no economically rational reason for this. Miners have a reason to match node policies, but nodes do not really benefit from matching miners.

If users decide their own policies with a high degree of arbitrary of miners can expect to match the node policies ? At the contrary, node benefit from their policies matching the miners to improve their visibility of the future blockchain state and block space demand. I think restrictions, which can be motivated for security reasons or host perfomances or whatever, comes with the trade-off of a worsen view of the blockchain.

@ghost
Copy link
ghost commented Apr 15, 2022

They shouldn't need to. No assumptions should be made about user package policies.

@luke-jr Agree. Any application assuming mempool policies is vulnerable. Although this RPC could be helpful for testing in general.

@DrahtBot
Copy link
Contributor
DrahtBot commented Apr 25, 2022

The following sections might be updated with supplementary metadata relevant to reviewers and maintainers.

Conflicts

Reviewers, this pull request conflicts with the following ones:

  • #25434 (mempool: Add option to bypass contextual timelocks in testmempoolaccept by w0xlt)
  • #25038 (BIP125-based Package RBF by glozow)

If you consider this pull request important, please also help to review the conflicting pull requests. Ideally, start with the one that should be merged first.

Copy link
Member
@maflcko maflcko left a comment

Choose a reason for hiding this comment

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

left some nits, since you requested a review (not sure if you wanted that kind of review)

@michaelfolkson
Copy link
michaelfolkson commented Apr 30, 2022

Seems like this PR should just be a modification to sendrawtransaction IMO. (If there's a reason to make it regtest-only, that can still be done without a new RPC method)

But regardless, the regtest check can be part of the existing RPC too. (I don't think it'd be the first case of such either IIRC)

For the benefit of other reviewers this seems on the face of it to be a reasonable counter-suggestion to what this PR is doing that is worth exploring.

The rest of the conversation seems to be a rehashing of the "Lightning security ideally wouldn't rely on mempool policy" and "One of the motivations for having a mempool is having a set of already validated transactions that the node expects to be mined in an upcoming block"

edit: This is good from the PR author on why it makes sense for the user to care about miner incentives.

Copy link
Contributor
@jnewbery jnewbery left a comment

Choose a reason for hiding this comment

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

Concept and approach ACK. Just some minor style comments.

This could definitely have more extensive testing (eg submitting packages with entries already in the mempool, invalid package topologies, packages containing invalid transactions, etc), but it's fine to leave that for a follow-up PR. It looks like some of the test code has been written with that flexibility in mind, which I think can be removed if it's not actually being used yet.

@glozow glozow force-pushed the client-submitpackage branch 2 times, most recently from 62994ee to 411cc6e Compare May 30, 2022 22:52
@glozow
Copy link
Member Author
glozow commented May 30, 2022

Rebased to use NONFATAL_UNREACHABLE

@glozow
Copy link
Member Author
glozow commented May 31, 2022

Thanks @MarcoFalke @jnewbery, took your comments

Copy link
@ariard ariard left a comment

Choose a reason for hiding this comment

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

For the benefit of other reviewers this seems on the face of it to be a reasonable counter-suggestion to what this PR is doing that is worth exploring.

FWIW, one argument can be made that make it easier to refine a new dedicated interface for future package issuer step by step as we experiment it. Of course, I think we could also extend sendrawtransaction with a regtest flag and package-only arguments. But that starts to be messy and we have more odds to interfere with sendrawtransaction usage, likely one of the most used RPC call across the Bitcoin ecosystem

@instagibbs
Copy link
Member

concept ACK

Copy link
Contributor
@w0xlt w0xlt left a comment

Choose a reason for hiding this comment

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

Tested ACK fbc6b86

@glozow glozow force-pushed the client-submitpackage branch from fbc6b86 to 9804649 Compare June 20, 2022 08:42
@glozow
Copy link
Member Author
glozow commented Jun 20, 2022

Last push

Copy link
Contributor
@t-bast t-bast left a comment

Choose a reason for hiding this comment

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

Tested ACK 9804649

I modified eclair to use 0-fee commitment transactions and verified that I could use this RPC to submit packages containing a commitment transaction and a child anchor transaction. The RPC is easy to use and the data it returns is helpful.

Seems like this PR should just be a modification to sendrawtransaction IMO.

I think this is a good point given the restrictions made to the topology of allowed packages. Because we're only considering packages of 1 child with multiple parents, we could use sendrawtransaction with the serialized child transaction and a new argument containing the package parents.

For now, a separate RPC that's regtest-only (and can thus be replaced / updated without caring too much about backwards-compatibility) is likely a better choice, but when the time comes to expose a mainnet RPC it could make sense to revisit that.

Copy link
@ariard ariard left a comment

Choose a reason for hiding this comment

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

Code Review ACK 9804649

Changes since last review :

  • RPCHelpMan updates to warn about the lack of package propagation
  • RPCResult updates around "wtxid" and "other-wtxid"
  • HelpExampleCli updates from "submitrawtransaction" to "sendrawtransaction"
  • re-add the BroadcastTransaction (would be nice to test coverage as suggested)
  • rpc_package.py comments and logs corrections

Edit: I checked my previous reviews, effectively BroadcastTransaction() wasn't present. From my understanding, without p2p packages, the odds of low-fee parent package propagating are low, so it didn't really matter if a BroadcastTransaction() call wasn't present or not. As this RPC is -regtest only and there is already a warning about expected lack of propagation, I think it doesn't matter if we introduce BroadcastTransaction() in this RPC now or latter.

}
}
}
tx_result_map.pushKV(tx->GetWitnessHash().GetHex(), result_inner);
Copy link
Member

Choose a reason for hiding this comment

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

some places we're using wtxid for indexing, others txid(replaced txns), is there a guiding principle here?

Copy link
Member Author

Choose a reason for hiding this comment

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

I think wtxids would be better in general. Txids for replaced txns is basically a legacy thing, it's just using what's returned in MempoolAcceptResult which is also used in testmempoolaccept. It would be impossible to have multiple replaced transactions with the same txids since they must have all been in mempool at the start. Perhaps one day we can change this for both RPCs?

Wtxids for indexing into the map because (1) it's more precise and (2) there actually is a possibility of same-txid-different-witness, i.e. see the "other-wtixd" result.

glozow added 2 commits June 23, 2022 14:35
It could be unsafe/confusing to create an actual mainnet interface while
package relay doesn't exist. However, a regtest-only interface allows
wallet/application devs to test current package policies.
@glozow glozow force-pushed the client-submitpackage branch from 9804649 to e866f0d Compare June 23, 2022 13:40
@glozow
Copy link
Member Author
glozow commented Jun 27, 2022

Last push:

thanks @t-bast @ariard @instagibbs !

Copy link
Contributor
@t-bast t-bast left a comment

Choose a reason for hiding this comment

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

Tested ACK against eclair e866f0d

Copy link
@ariard ariard left a comment

Choose a reason for hiding this comment

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

Code Review ACK e866f0d

Changes since last review:

  • updates sendrawtransaction to submitpackage in HelpExampleCli
  • yield a JSON rpc error with the number of transaction in package
  • few functional test updates, notably adding a test_submit_cpfp case

@fanquake fanquake requested review from instagibbs and darosior June 30, 2022 08:45
Copy link
Member
@instagibbs instagibbs left a comment

Choose a reason for hiding this comment

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

code review ACK e866f0d

code changes as expected pert: #24836 (comment)

assert "package-feerate" in submitpackage_result
assert_fee_amount(DEFAULT_FEE, rich_parent_result["vsize"] + child_result["vsize"], submitpackage_result["package-feerate"])

# The node will broadcast each transaction, still abiding by its peer's fee filter
Copy link
Member
@instagibbs instagibbs Jun 30, 2022

Choose a reason for hiding this comment

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

future work: would be nice if "abiding by its peer's fee filter" had test coverage rather than a comment to prevent future regressions

@fanquake fanquake merged commit 6adae27 into bitcoin:master Jun 30, 2022
sidhujag pushed a commit to syscoin/syscoin that referenced this pull request Jun 30, 2022
e866f0d [functional test] submitrawpackage RPC (glozow)
fa07651 [rpc] add new submitpackage RPC (glozow)

Pull request description:

  It would be nice for LN/wallet/app devs to test out package policy, package RBF, etc., but the only interface to do so right now is through unit tests. This PR adds a `-regtest` only RPC interface so people can test by submitting raw transaction data. It is regtest-only, as it would be unsafe/confusing to create an actual mainnet interface while package relay doesn't exist.

  Note that the functional tests are there to ensure the RPC interface is working properly; they aren't for testing policy itself. See src/test/txpackage_tests.cpp.

ACKs for top commit:
  t-bast:
    Tested ACK against eclair bitcoin@e866f0d
  ariard:
    Code Review ACK e866f0d
  instagibbs:
    code review ACK e866f0d

Tree-SHA512: 824a26b10d2240e0fd85e5dd25bf499ee3dd9ba8ef4f522533998fcf767ddded9f001f7a005fe3ab07ec95e696448484e26599803e6034ed2733125c8c376c84
@glozow glozow mentioned this pull request Apr 21, 2023
59 tasks
@bitcoin bitcoin locked and limited conversation to collaborators Jun 30, 2023
@glozow glozow deleted the client-submitpackage branch February 27, 2024 14:13
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
Development

Successfully merging this pull request may close these issues.

0