LearnBitcoin

Bitcoin Dev Archive 2011

Transaction limit size in CWallet::CreateTransaction

2 messages, 3 Sep 2011. Started by Chris Double.

Chris Double (2)

Permalink Original thread on gnusha.org

Chris Double permalink original

In CWallet::CreateTransaction there is a call to 'GetSerializeSize' on line 979 (https://github.com/bitcoin/bitcoin/blob/master/src/wallet.cpp#L979). It looks like:

---------8<----------
unsigned int nBytes = ::GetSerializeSize(*(CTransaction*)&wtxNew, SER_NETWORK)
if (nBytes >= MAX_BLOCK_SIZE_GEN/5)
  return false;
dPriority /= nBytes;
---------8<----------

'wtxNew' is a CWalletTxn. So this gets the serialized size of the transaction, including all the extra data held in the wallet for that transaction, and uses that size for computation of priority. Is that correct? Should it be only the size of the CTransaction* part of the transaction that should be used?

It looks this was from the casting shenanigans but unless I'm mistaken, that casting doesn't actually do anything. We get a pointer to a CTransaction but then dereference it, so the template function 'GetSerializeSize' would get the most derived class, right?

So was the intent to use the CWalletTxn size, and the casting is superfluous, or was it supposed to be the CTransaction* portion and the cast is an incorrect way of doing that? Or am I suffering from late night programmer syndrome and reading it wrong?

Chris.

Chris Double in reply to Chris Double permalink original

On Sun, Sep 4, 2011 at 1:52 AM, Chris Double <chris.double@double•co•nz> wrote:

Quoted text (4 lines)
> So was the intent to use the CWalletTxn size, and the casting is
> superfluous, or was it supposed to be the CTransaction* portion and
> the cast is an incorrect way of doing that? Or am I suffering from
> late night programmer syndrome and reading it wrong?

After a discussion on #bitcoin-dev it is indeed the latter. I was under the mistaken believe that the GetSerializeSize method in CTransaction and CWalletTxn were virtual, which would result in the behavior I was thinking of. But they're not so it works. Please disregard!

Chris.