-
Notifications
You must be signed in to change notification settings - Fork 38.6k
Policy: Create CPolicy interface and CStandardPolicy class implementing it #5595
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
Conversation
src/qt/coincontroldialog.cpp
Outdated
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nit: This should be moved to the core includes block :).
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Mhmm, I guess init should be with main and wallet as well...
|
Untested ACK |
|
@Diapolo Added a squashme commit to fix the include nit. |
|
Squashed @Diapolo's nit. Also rebased. |
|
ACK, although I don't think we ought to be claiming copyright on policy.h yet as it contains no copyrightable content. |
|
Thanks. |
|
Squashed to a single commit. |
0e28aef to
5f18826
Compare
|
I'm sorry for changing the PR again but the goal was always to find a common base and hopefully make later policy-code movements cleaner. |
|
Well, I'm sorry, the latest version is actually failing on windows... |
|
There was a bug in src/test/test_bitcoin.cpp. I updated the code and the initial description. |
|
Rebased on top of #5696 and updated the initial description adding new links to commits. |
f141dd0 to
d66803e
Compare
|
Updated with @luke-jr 's suggestions:
This is no longer a Proof of concept, this is ready to be merged. For more examples on how this will be used see #5768 |
src/policy/policy.h
Outdated
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This isn't policy.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
MANDATORY_SCRIPT_VERIFY_FLAGS isn't policy?
At first I put it in consensus, but @TheBlueMatt wasn't convinced that was consensus, and @sipa said it was policy in #5696 (or maybe #5669).
Ideally consensus should always use something like Consensus::GetFlags() (see jtimon@0779bbc)
Longer term, I think it should become an attribute of CStandardPolicy (see jtimon@d1fec10)
|
Fixed the redundancies but MANDATORY_SCRIPT_VERIFY_FLAGS remains in policy/policy.h |
|
As discussed on IRC, I'll just leave MANDATORY_SCRIPT_VERIFY_FLAGS in script/standard.h for now. |
7d48d38 to
9ddf5e5
Compare
|
ACK 9ddf5e5 |
|
Needed rebase. |
|
Closing until #5696 is resolved |
|
I'm sorry but I can't reopen this, more explanations and the rebased equivalent (needed rebase and it will also get slightly simpler after a reduced version of #5696 has been merged) to this PR in: #6068. I'm very sorry, @luke-jr when I created this PR competing with #5071 it wasn't my intention to slow things down with policy. |
First steps for encapsulating the policy code.
An interface (abstract class) CPolicy and a concrete implementation CStandardPolicy are created.
"Users" (people capable of modify and build Bitcoin core) can implement alternative policies and select them with the option -policy=<policy_name>. They can define new policy options and make their help messages be accesible to the users without having to touch init.cpp, only modifying policy.cpp is enough for all this. The help messages can also be accessed (per available policy) as a vector of string pairs to make it easier to implement a GUI to configure those options (although I don't plan to do that myself).
As more parts of the policy code move to policy.cpp, this encapsulation gets more useful.
To start using it. The function script/standard.o::IsStandard() is turned into a method: ApproveScript().
Many more policy-related improvements can be cleanly proposed after this first steps are merged.
OUTDATED:
This is an attempt to get a first commit for moving policy-related code together as proposed in #4943.
The main purpose of this PR is therefore discuss the commit "Policy: Create CPolicy interface and CStandardPolicy implemention" (jtimon@572f129) which may change with suggestions.
The commit "Policy: MOVEONLY: script/standard.o::IsStandard() -> CPolicy::ValidateScript()" (jtimon@9e99eba) acts as an example for adding a method to CPolicy.
The commit "Policy: Refactor: Move datacarrier policy logic to policy.o" (jtimon@f141dd0) is an example of adding an attribute to CStandardPolicy without exposing it on CPolicy or exposing CStandardPolicy itself.
An example of a crazy custom policy that a user could implement for its local node can be found in https://github.com/jtimon/bitcoin/compare/policy_example
The commit "Policy: Refactor: Move datacarrier policy logic to policy.o" may be considered too risky and may be left for later to avoid delaying the first step.
Maybe jtimon@a295463 is not welcomed. It is only necessary if you want to make InitPolicyFromArgs() and CPolicy::InitFromArgs() param mapArgs const and don't want to duplicate code.
I am very sorry for letting the ut acks rot.