Skip to content

Conversation

@jtimon
Copy link
Contributor

@jtimon jtimon commented Jan 3, 2015

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.

Copy link

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 :).

Copy link
Contributor Author

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...

@sipa
Copy link
Member

sipa commented Jan 4, 2015

Untested ACK

@jtimon
Copy link
Contributor Author

jtimon commented Jan 4, 2015

@Diapolo Added a squashme commit to fix the include nit.

@jtimon
Copy link
Contributor Author

jtimon commented Jan 7, 2015

Squashed @Diapolo's nit. Also rebased.
Does people agree that InitPolicyFromCommandLine() is a good idea to squash its commit?
@luke-jr ?
Now there's 3 more commits from #5180 that I think you can agree with. You also moved main::IsStandardTx() and main::AreInputsStandard() in the more advanced policy branch you showed me (luke-jr/nodepolicy2).
The difference is that I'm also moving some constants/globals they use to policy.o at the same time and that I'm moving things to InitPolicyFromCommandLine() from init.cpp.
Well, and that I'm moving these two functions before creating the class, while you create 4 new functions/methods when you create the class.
Our main disagreements seem to be in the way we access the class and the abstract class/interface, as well as on policy.o depending on main.o.
But since this PR is about an uncontroversial start on policy.o, I think I could extend this PR with those movements and it will still make #5114, #5180, a rebased version of #5071 and any other policy-related PR easier to review.
What do you think, should I bring more commits from #5180 here?

@luke-jr
Copy link
Member

luke-jr commented Jan 8, 2015

ACK, although I don't think we ought to be claiming copyright on policy.h yet as it contains no copyrightable content.

@jtimon jtimon mentioned this pull request Jan 8, 2015
@jtimon
Copy link
Contributor Author

jtimon commented Jan 8, 2015

Thanks.
Well, making later commits smaller is the whole point and putting the copyright text already serves that purpose.
Should I squash the second commit then?

@jtimon
Copy link
Contributor Author

jtimon commented Jan 10, 2015

Squashed to a single commit.

@jtimon jtimon force-pushed the policy branch 2 times, most recently from 0e28aef to 5f18826 Compare January 21, 2015 01:44
@jtimon
Copy link
Contributor Author

jtimon commented Jan 21, 2015

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.
I think IsStandard(CStript) with luke's commits is a good example that will likely be easy to maintain.
All those functions and interfaces like Policy("standard") allow you to easily create your own crazy policy and activate it with -policy=custom as shown in the example (jtimon@1a5a191) without causing the tests to fail .

@jtimon jtimon changed the title Policy: Create policy.o with global minRelayTxFee from main.o Policy: Create CPolicy interface and CStandardPolicy class implementing it Jan 21, 2015
@jtimon
Copy link
Contributor Author

jtimon commented Jan 21, 2015

Well, I'm sorry, the latest version is actually failing on windows...
EDIT: found the bug: https://travis-ci.org/bitcoin/bitcoin/builds/47773190
Now squashing and updating the initial description.

@jtimon
Copy link
Contributor Author

jtimon commented Jan 21, 2015

There was a bug in src/test/test_bitcoin.cpp. I updated the code and the initial description.

@jtimon
Copy link
Contributor Author

jtimon commented Jan 23, 2015

Rebased on top of #5696 and updated the initial description adding new links to commits.

@jtimon
Copy link
Contributor Author

jtimon commented Mar 26, 2015

Updated with @luke-jr 's suggestions:

  1. Replace ValidateX with ApproveX
  2. Added a method std::vector<std::pair<std::string, std::string> > GetOptionsHelp() to the CPolicy interface to make GUI-based policy configuration easier.

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

@jtimon jtimon changed the title PoC: Policy: Create CPolicy interface and CStandardPolicy class implementing it Policy: Create CPolicy interface and CStandardPolicy class implementing it Mar 26, 2015
Copy link
Member

Choose a reason for hiding this comment

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

This isn't policy.

Copy link
Contributor Author

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)

@jtimon
Copy link
Contributor Author

jtimon commented Apr 1, 2015

Fixed the redundancies but MANDATORY_SCRIPT_VERIFY_FLAGS remains in policy/policy.h
@luke-jr is that a nack for you?

@jtimon
Copy link
Contributor Author

jtimon commented Apr 13, 2015

As discussed on IRC, I'll just leave MANDATORY_SCRIPT_VERIFY_FLAGS in script/standard.h for now.
I believe all the nits have been solved now.

@jtimon jtimon force-pushed the policy branch 2 times, most recently from 7d48d38 to 9ddf5e5 Compare April 13, 2015 22:19
@luke-jr
Copy link
Member

luke-jr commented Apr 13, 2015

ACK 9ddf5e5

@jtimon
Copy link
Contributor Author

jtimon commented Apr 20, 2015

Needed rebase.

@jtimon
Copy link
Contributor Author

jtimon commented Apr 23, 2015

Closing until #5696 is resolved

@jtimon
Copy link
Contributor Author

jtimon commented Apr 26, 2015

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.

@bitcoin bitcoin locked as resolved and limited conversation to collaborators Sep 8, 2021
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

7 participants