Skip to content

Conversation

lucash-dev
Copy link
Contributor

This PR creates a common interface for CMutableTransaction and CTransaction as the template class CBaseTransaction<T>. This base class uses the CRTP (curiously recurring template pattern) in order to achieve static polymorphism. This way this change shouldn't have any effect on behaviour or runtime performance (though compilation performance is of course worse).

Rationale:

  • Creates a common, explicit interface type for CTransaction and CMutableTransaction.
  • Makes explicit common elements between two classes.
  • Functions that accept have a better option than accepting an unrestricted typename T.
  • Better than proliferating custom static_assert or enable_if with different, obscure error messages when the template is applied to the wrong types.

PS: This PR shouldn't affect performance or behaviour, but please review thoroughly as it touches consensus-sensitive code.

    Created a base interface for both transaction types, using CRTP for static resolution.
    A previous refactor allowed functions and classes in this unit to accept both CMutableTransaction and CTransaction, but left the template argument unrestricted.
    This change makes use of the new CBaseTransaction<T> template class to restrict the use to the classes defined in transaction.h.
@DrahtBot
Copy link
Contributor

DrahtBot commented Sep 27, 2018

Reviewers, this pull request conflicts with the following ones:

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.

@DrahtBot
Copy link
Contributor

Coverage Change (pull 14337) Reference (master)
Lines -0.0830 % 87.0361 %
Functions +0.0495 % 84.1130 %
Branches -0.0921 % 51.5451 %

@gmaxwell
Copy link
Contributor

The PR description doesn't seem to state why this would be a benefit for users of the system, only why it wouldn't be a disaster. As a result, this does not appear to justify the effort to review it for safety.

@lucash-dev
Copy link
Contributor Author

@gmaxwell I understand your concerns. This PR is about code maintainability and extensibility, which is beneficial to the user in the long run (if it’s a good refactoring).

But It’s hard for me to judge the effort required of others to review it

@@ -388,15 +444,6 @@ struct CMutableTransaction
*/
uint256 GetHash() const;

Copy link
Contributor

@practicalswift practicalswift Sep 29, 2018

Choose a reason for hiding this comment

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

Nit: Remove blank line at the end of the code block :-)

@lucash-dev
Copy link
Contributor Author

@gmaxwell after a bit more thought, I actually agree with you. Closing the PR.
Thank you very much for taking the time to look at it and sharing your insights.

@lucash-dev lucash-dev closed this Oct 6, 2018
@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.

5 participants