Skip to content

Conversation

maflcko
Copy link
Member

@maflcko maflcko commented May 31, 2018

When serializing a transaction for the wallet or rpc, it shouldn't matter if the type is CTransaction or CMutableTransaction. (See the code for SerializeTransaction, which is a template on TxType)

Thus, we can avoid a call to a CTransaction constructor by templating various helper methods similar to #13309 (Directly operate with CMutableTransaction in SignSignature)

@Empact
Copy link
Contributor

Empact commented Jun 1, 2018

How about using something like typename std::enable_if<std::is_same<T, CTransaction>::value || std::is_same<T, CMutableTransaction>::value>::type in place of static_assert? I haven't tested this but I think it could be defined as an abstract transaction template type and then used to restrain the type of each such template.

Example use here: https://github.com/bitcoin/bitcoin/pull/13076/files#diff-4a0cb5ad5e93d187a1b065a99bbae143

@promag
Copy link
Contributor

promag commented Jun 1, 2018

Could remove the following in a separate commit?

int64_t CalculateMaximumSignedTxSize(const CTransaction &tx, const CWallet *wallet, const std::vector<CTxOut>& txouts)

@ghost
Copy link

ghost commented Jun 3, 2018

Is this mining bitcoin

@Empact
Copy link
Contributor

Empact commented Jun 5, 2018

@pawan17kumar yes we are hard at work swinging pick-axes into keyboards.

@laanwj
Copy link
Member

laanwj commented Jun 5, 2018

utACK faadf51

Is this mining bitcoin

if only mining was proof-of-open-source-development...

@maflcko maflcko force-pushed the Mf1806-avoidTxConstuctor branch from faadf51 to fa7ae60 Compare September 6, 2018 15:25
@maflcko maflcko changed the title wallet: Directly operate with CMutableTransaction Directly operate with CMutableTransaction Sep 6, 2018
@maflcko maflcko removed the Wallet label Sep 6, 2018
@maflcko maflcko force-pushed the Mf1806-avoidTxConstuctor branch from fa7ae60 to fa1b4e9 Compare September 6, 2018 15:42
@maflcko maflcko force-pushed the Mf1806-avoidTxConstuctor branch from fa1b4e9 to fa25e2e Compare September 6, 2018 16:46
@DrahtBot
Copy link
Contributor

DrahtBot commented Sep 7, 2018

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

{
static_assert(std::is_same<T, CTransaction>::value || std::is_same<T, CMutableTransaction>::value, "no need to allow other types");
Copy link

Choose a reason for hiding this comment

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

it might be nicer to have this function not participate in overload resolution (i.e. enable_if) when these conditions are not met, rather than being triggering a static assert.

Copy link
Contributor

Choose a reason for hiding this comment

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

Downside of using enable_if is that the resulting compiler error message will probably be more ambiguous and harder to understand.

Copy link
Contributor

Choose a reason for hiding this comment

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

Either way, I think there should be a standard logic for checking whether a type is a transaction type -- provided by transaction.h, thus preserving encapsulation.

@@ -4,15 +4,18 @@

#include <policy/rbf.h>

bool SignalsOptInRBF(const CTransaction &tx)
template <typename T>
bool SignalsOptInRBF(const T& tx)
Copy link

Choose a reason for hiding this comment

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

this template should probably constrain T as well

@DrahtBot
Copy link
Contributor

Needs rebase

Copy link
Contributor

@ryanofsky ryanofsky left a comment

Choose a reason for hiding this comment

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

utACK fa25e2e

{
static_assert(std::is_same<T, CTransaction>::value || std::is_same<T, CMutableTransaction>::value, "no need to allow other types");
Copy link
Contributor

Choose a reason for hiding this comment

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

Downside of using enable_if is that the resulting compiler error message will probably be more ambiguous and harder to understand.

@maflcko maflcko closed this Oct 1, 2018
@maflcko maflcko deleted the Mf1806-avoidTxConstuctor branch October 1, 2018 02:02
@ryanofsky
Copy link
Contributor

Why was this closed?

@maflcko
Copy link
Member Author

maflcko commented Nov 11, 2019

Why was this closed?

It needs benchmarks, to justify the use of C++11, which is less common in this project (enable_if or static_assert)

@bitcoin bitcoin locked as resolved and limited conversation to collaborators Dec 16, 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.

9 participants